home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / KBANDATA / PINELEM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-23  |  5.2 KB  |  221 lines

  1. // the implementation of class PIN_ELEMENT
  2. // Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  3.  
  4. #include "../common/bool.h"
  5. #include "../kbandef.h"
  6.  
  7. #include "pinelem.h"
  8.  
  9. XY PIN_ELEMENT::get_max() const
  10. {
  11.   XY ac_max;
  12.  
  13.   switch(apt().type()) {
  14.     case APERTURE::APT_ROUND :
  15.     case APERTURE::APT_SQUARE : {
  16.       ac_max = ac() + apt().width() / 2;
  17.       break;
  18.     }
  19.     case APERTURE::APT_OBLONG :
  20.     case APERTURE::APT_RECTANGLE : {
  21.       ac_max = ac() + XY(apt().width() / 2, apt().height() / 2);
  22.       break;
  23.     }
  24.     default : {
  25.       ac_max = ac();
  26.       break;
  27.     }
  28.   }
  29.   return ac_max;
  30. }
  31.  
  32. XY PIN_ELEMENT::get_min() const
  33. {
  34.   XY ac_min;
  35.  
  36.   switch(apt().type()) {
  37.     case APERTURE::APT_ROUND :
  38.     case APERTURE::APT_SQUARE : {
  39.       ac_min = ac() - apt().width() / 2;
  40.       break;
  41.     }
  42.     case APERTURE::APT_OBLONG :
  43.     case APERTURE::APT_RECTANGLE : {
  44.       ac_min = ac() - XY(apt().width() / 2, apt().height() / 2);
  45.       break;
  46.     }
  47.     default : {
  48.       ac_min = ac();
  49.       break;
  50.     }
  51.   }
  52.   return ac_min;
  53. }
  54.  
  55. uint PIN_ELEMENT::is_inside(const XY& ac_target)
  56. {
  57.   uint retval;
  58.  
  59.   switch(apt().type()) {
  60.     case APERTURE::APT_ROUND : {
  61.       retval = compare_distance_lt(ac_target, ac(), apt().width() / 2);
  62.       break;
  63.     }
  64.     case APERTURE::APT_SQUARE : {
  65.       XY p = get_min();
  66.       XY q = get_max();
  67.       retval = ac_target.is_in_box(p, q);
  68.       break;
  69.     }
  70.     case APERTURE::APT_OBLONG : {
  71.       // This case needs more developmenmt.
  72.       if(apt().width() < apt().height()) {
  73.         // vertically long
  74.         int r = apt().width() / 2;
  75.         int y1 = ac().y() - apt().height() / 2 + r;
  76.         int y2 = ac().y() + apt().height() / 2 - r;
  77.         XY p(ac().x() - r, y1);
  78.         XY q(ac().x() + r, y2);
  79.         XY ac_lower(ac().x(), y1);
  80.         XY ac_upper(ac().x(), y2);
  81.         retval = ac_target.is_in_box(p, q)
  82.               || compare_distance_lt(ac_target, ac_lower, r)
  83.               || compare_distance_lt(ac_target, ac_upper, r);
  84.       } else {
  85.         // horizontally long
  86.         int r = apt().height() / 2;
  87.         int x1 = ac().x() - apt().width() / 2 + r;
  88.         int x2 = ac().x() + apt().width() / 2 - r;
  89.         XY p(x1, ac().y() - r);
  90.         XY q(x2, ac().y() + r);
  91.         XY ac_left (x1, ac().y());
  92.         XY ac_right(x2, ac().y());
  93.         retval = ac_target.is_in_box(p, q)
  94.               || compare_distance_lt(ac_target, ac_left , r)
  95.               || compare_distance_lt(ac_target, ac_right, r);
  96.       }
  97.       break;
  98.     }
  99.     case APERTURE::APT_RECTANGLE : {
  100.       XY p = get_min();
  101.       XY q = get_max();
  102.       retval = ac_target.is_in_box(p, q);
  103.       break;
  104.     }
  105.     default : {
  106.       retval = false;
  107.     }
  108.   }
  109.   return retval;
  110. }
  111.  
  112. void PIN_ELEMENT::load_170_core(const char *str)
  113. {
  114.   XYT x, y;
  115.   uint type, width, drill, no;
  116.   sscanf(str, "%d %d %d %d %d %d", &x, &y, &type, &width, &drill, &no);
  117.   x = x * 25400 / 300;
  118.   y = y * 25400 / 300;
  119.   width = width * 25400 / 1000;
  120.   drill = drill * 25400 / 1000;
  121.   set_ac(XY(x, y));
  122.   set_apt(APERTURE(type, width, 0, drill));
  123.   set_number(no);
  124. }
  125.  
  126. void PIN_ELEMENT::load_primitive_170(const char *str)
  127. {
  128.   load_170_core(str);
  129.   XY ac_new = XY(ac().x(), Y_V1TOV2 - ac().y());
  130.   set_ac(ac_new);
  131. }
  132.  
  133. void PIN_ELEMENT::load_component_170(const char *str)
  134. {
  135.   load_170_core(str);
  136.   XY ac_new = XY(ac().x(), - ac().y());
  137.   set_ac(ac_new);
  138. }
  139.  
  140. int PIN_ELEMENT::unit_change_micron2kban(int micron)
  141. {
  142.   return micron * DIS_MICRON;
  143. }
  144.  
  145. // x y type width drill number
  146.  
  147. void PIN_ELEMENT::load_200a8(const char *str)
  148. {
  149.   XYT x, y;
  150.   uint type, width, drill, no;
  151.   sscanf(str, "%d %d %d %d %d %d", &x, &y, &type, &width, &drill, &no);
  152.   x     = unit_change_micron2kban(x);
  153.   y     = unit_change_micron2kban(y);
  154.   width = unit_change_micron2kban(width);
  155.   drill = unit_change_micron2kban(drill);
  156.   XY ac(x, y);
  157.   set_ac(ac);
  158.   set_apt(APERTURE(type, width, 0, drill));
  159.   set_number(no);
  160. }
  161.  
  162. // x y type width height drill number
  163.  
  164. void PIN_ELEMENT::load_200b0(const char *str)
  165. {
  166.   XYT x, y;
  167.   uint type, width, height, drill, no;
  168.   sscanf(str, "%d %d %d %d %d %d %d", &x, &y, &type, &width, &height, &drill, &no);
  169.   x      = unit_change_micron2kban(x);
  170.   y      = unit_change_micron2kban(y);
  171.   width  = unit_change_micron2kban(width);
  172.   height = unit_change_micron2kban(height);
  173.   drill  = unit_change_micron2kban(drill);
  174.   XY ac(x, y);
  175.   set_ac(ac);
  176.   set_apt(APERTURE(type, width, height, drill));
  177.   set_number(no);
  178. }
  179.  
  180. #if 0
  181. void PIN_ELEMENT::save_200a8(FILE_NEW& fp) const
  182. {
  183.   fi.printf("%d %d %d %d %d %d\n",
  184.     ac().x(),
  185.     ac().y(),
  186.     apt().type(),
  187.     apt().width(),
  188.     apt().drill(),
  189.     number()
  190.   );
  191. }
  192. #endif
  193.  
  194. // x y type width height drill number
  195.  
  196. void PIN_ELEMENT::save_200b0(FILE_NEW& fp) const
  197. {
  198.   fp.printf("%d %d %d %d %d %d %d\n",
  199.     ac().x(),
  200.     ac().y(),
  201.     apt().type(),
  202.     apt().width(),
  203.     apt().height(),
  204.     apt().drill(),
  205.     number()
  206.   );
  207. }
  208.  
  209. void PIN_ELEMENT::rotate_90()
  210. {
  211.   m_ac .rotate_90();
  212.   m_apt.rotate_90();
  213. }
  214.  
  215. void PIN_ELEMENT::limit_drill_size(uint drill)
  216. {
  217.   APERTURE temp = apt();
  218.   temp.set_drill(minimum(temp.drill(), drill));
  219.   set_apt(temp);
  220. }
  221.