home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / KBANDATA / PRIM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-07  |  9.9 KB  |  370 lines

  1. /*
  2.  * the class PRIMITIVE
  3.  * Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  4.  */
  5.  
  6. #include "../finfo.h"
  7. #include "../intstr.h"
  8. #include "../kbandef.h"
  9.  
  10. #include "prim.h"
  11.  
  12. PRIMITIVE::PRIMITIVE(const PRIMITIVE& src)
  13.   : m_layer(src.m_layer),
  14.     m_ac   (src.m_ac   )
  15. {
  16.   strcpy(m_component_name, src.m_component_name);
  17.   strcpy(m_designator    , src.m_designator    );
  18. }
  19.  
  20. void PRIMITIVE::operator=(const PRIMITIVE& src)
  21. {
  22.   m_ac = src.m_ac;
  23.   strcpy(m_component_name, src.m_component_name);
  24.   strcpy(m_designator    , src.m_designator    );
  25.   m_layer = src.m_layer;
  26. }
  27.  
  28. void PRIMITIVE::operator+=(const PRIMITIVE& target)
  29. {
  30.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  31.     layer(i) += target.layer(i);
  32.   }
  33. }
  34.  
  35. void PRIMITIVE::clear(void)
  36. {
  37.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  38.     layer(i).clear();
  39.   }
  40. }
  41.  
  42. XY PRIMITIVE::get_max(void) const
  43. {
  44.   XY ac_max(X_MIN, Y_MIN);
  45.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  46.     ac_max = ::get_max(ac_max, layer(i).get_max());
  47.   }
  48.   return ac() + ac_max;
  49. }
  50.  
  51. XY PRIMITIVE::get_min(void) const
  52. {
  53.   XY ac_min(X_MAX, Y_MAX);
  54.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  55.     ac_min = ::get_min(ac_min, layer(i).get_min());
  56.   }
  57.   return ac() + ac_min;
  58. }
  59.  
  60. void PRIMITIVE::shift(const XY& ac_dif, PRIMITIVE& target) const
  61. {
  62.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  63.     layer(i).shift(ac_dif, target.layer(i));
  64.   }
  65. }
  66.  
  67. void PRIMITIVE::unselect(void)
  68. {
  69.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  70.     layer(i).unselect();
  71.   }
  72. }
  73.  
  74. void PRIMITIVE::select_items_in_block(const XY& ac1, const XY& ac2)
  75. {
  76.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  77.     layer(i).select_items_in_block(ac1, ac2);
  78.   }
  79. }
  80.  
  81. void PRIMITIVE::collect_selected_items(PRIMITIVE& dst) const
  82. {
  83.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  84.     layer(i).collect_selected_items(dst.layer(i));
  85.   }
  86. }
  87.  
  88. void PRIMITIVE::remove_selected_items(void)
  89. {
  90.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  91.     layer(i).remove_selected_items();
  92.   }
  93. }
  94.  
  95. const INTSTR_ELEMENT PRIMITIVE::layer_str[] = {
  96.   {LAYER_PATTERN_COMMON, "layer_pattern_commmon"},
  97.   {LAYER_PATTERN_TOP   , "layer_pattern_top"    },
  98.   {LAYER_PATTERN_BOTTOM, "layer_pattern_bottom" },
  99.   {LAYER_SILK_TOP      , "layer_silk_top"       },
  100.   {LAYER_SILK_BOTTOM   , "layer_silk_bottom"    },
  101.   {LAYER_NUMBER        , NULL                   }
  102. };
  103.  
  104. const char *PRIMITIVE::get_layer_name(uint no) const
  105. {
  106.   INTSTR_TABLE table(layer_str, LAYER_NUMBER);
  107.   return table.get_str(no);
  108. }
  109.  
  110. uint PRIMITIVE::get_layer_number(const char *s) const
  111. {
  112.   INTSTR_TABLE table(layer_str, LAYER_NUMBER);
  113.   return table.get_no(s);
  114. }
  115.  
  116. int PRIMITIVE::load_text_list(FILE_NEW& fp)
  117. {
  118.   for(;;) {
  119.     char str[1024];
  120.     fp.gets_wo_return(str, 1024);
  121.     if(!strcmp(str, "end")) {
  122.       break;
  123.     }
  124.     fp.gets_wo_return(str, 1024);
  125.   }
  126.   return true;
  127. }
  128.  
  129. int PRIMITIVE::load_primitive_170(FILE_NEW& fp)
  130. {
  131.   for(;;) {
  132.     char str[1024];
  133.     fp.gets_wo_return(str, 1024);
  134.     if(!strcmp(str, "end")) {
  135.       break;
  136.     } else if(!strcmp(str, "pin_170")) {
  137.       PIN_LIST& pin_list = layer(LAYER_PATTERN_COMMON).pin_list();
  138.       pin_list.load_primitive_170(fp);
  139.     } else if(!strcmp(str, "line_top_120")) {
  140.       LINE_LIST& line_list = layer(LAYER_PATTERN_TOP).line_list();
  141.       line_list.load_primitive_170(fp);
  142.     } else if(!strcmp(str, "line_bottom_120")) {
  143.       LINE_LIST& line_list = layer(LAYER_PATTERN_BOTTOM).line_list();
  144.       line_list.load_primitive_170(fp);
  145.     } else if(!strcmp(str, "line_internal_1_120")) {
  146.       LINE_LIST dummy;
  147.       dummy.load_primitive_170(fp);
  148.     } else if(!strcmp(str, "line_internal_2_120")) {
  149.       LINE_LIST dummy;
  150.       dummy.load_primitive_170(fp);
  151.     } else if(!strcmp(str, "line_internal_3_120")) {
  152.       LINE_LIST dummy;
  153.       dummy.load_primitive_170(fp);
  154.     } else if(!strcmp(str, "line_internal_4_120")) {
  155.       LINE_LIST dummy;
  156.       dummy.load_primitive_170(fp);
  157.     } else if(!strcmp(str, "line_silk_120")) {
  158.       LINE_LIST& line_list = layer(LAYER_SILK_TOP).line_list();
  159.       line_list.load_primitive_170(fp);
  160.     } else if(!strcmp(str, "line_border_120")) {
  161.       LINE_LIST& line_list = layer(LAYER_SILK_BOTTOM).line_list();
  162.       line_list.load_primitive_170(fp);
  163.     } else if(!strcmp(str, "text_top_120")) {
  164.       load_text_list(fp);
  165.     } else if(!strcmp(str, "text_bottom_120")) {
  166.       load_text_list(fp);
  167.     } else if(!strcmp(str, "text_internal_1_120")) {
  168.       load_text_list(fp);
  169.     } else if(!strcmp(str, "text_internal_2_120")) {
  170.       load_text_list(fp);
  171.     } else if(!strcmp(str, "text_internal_3_120")) {
  172.       load_text_list(fp);
  173.     } else if(!strcmp(str, "text_internal_4_120")) {
  174.       load_text_list(fp);
  175.     } else if(!strcmp(str, "text_silk_120")) {
  176.       load_text_list(fp);
  177.     } else if(!strcmp(str, "text_border_120")) {
  178.       load_text_list(fp);
  179.     } else {
  180.       // corrupted
  181.       break;
  182.     }
  183.   }
  184.   return true;
  185. }
  186.  
  187. int PRIMITIVE::load_component_170(FILE_NEW& fp)
  188. {
  189.   for(;;) {
  190.     char str[1024];
  191.     fp.gets_wo_return(str, 1024);
  192.     if(!strcmp(str, "end")) {
  193.       break;
  194.     } else if(!strcmp(str, "pin_170")) {
  195.       PIN_LIST& pin_list = layer(LAYER_PATTERN_COMMON).pin_list();
  196.       pin_list.load_component_170(fp);
  197.     } else if(!strcmp(str, "line_top_120")) {
  198.       LINE_LIST& line_list = layer(LAYER_PATTERN_TOP).line_list();
  199.       line_list.load_component_170(fp);
  200.     } else if(!strcmp(str, "line_bottom_120")) {
  201.       LINE_LIST& line_list = layer(LAYER_PATTERN_BOTTOM).line_list();
  202.       line_list.load_component_170(fp);
  203.     } else if(!strcmp(str, "line_internal_1_120")) {
  204.       LINE_LIST dummy;
  205.       dummy.load_component_170(fp);
  206.     } else if(!strcmp(str, "line_internal_2_120")) {
  207.       LINE_LIST dummy;
  208.       dummy.load_component_170(fp);
  209.     } else if(!strcmp(str, "line_internal_3_120")) {
  210.       LINE_LIST dummy;
  211.       dummy.load_component_170(fp);
  212.     } else if(!strcmp(str, "line_internal_4_120")) {
  213.       LINE_LIST dummy;
  214.       dummy.load_component_170(fp);
  215.     } else if(!strcmp(str, "line_silk_120")) {
  216.       LINE_LIST& line_list = layer(LAYER_SILK_TOP).line_list();
  217.       line_list.load_component_170(fp);
  218.     } else if(!strcmp(str, "line_border_120")) {
  219.       LINE_LIST& line_list = layer(LAYER_SILK_BOTTOM).line_list();
  220.       line_list.load_component_170(fp);
  221.     } else if(!strcmp(str, "text_top_120")) {
  222.       load_text_list(fp);
  223.     } else if(!strcmp(str, "text_bottom_120")) {
  224.       load_text_list(fp);
  225.     } else if(!strcmp(str, "text_internal_1_120")) {
  226.       load_text_list(fp);
  227.     } else if(!strcmp(str, "text_internal_2_120")) {
  228.       load_text_list(fp);
  229.     } else if(!strcmp(str, "text_internal_3_120")) {
  230.       load_text_list(fp);
  231.     } else if(!strcmp(str, "text_internal_4_120")) {
  232.       load_text_list(fp);
  233.     } else if(!strcmp(str, "text_silk_120")) {
  234.       load_text_list(fp);
  235.     } else if(!strcmp(str, "text_border_120")) {
  236.       load_text_list(fp);
  237.     } else {
  238.       // corrupted
  239.       break;
  240.     }
  241.   }
  242.   return true;
  243. }
  244.  
  245. void PRIMITIVE::load_200a8(FILE_NEW& fp)
  246. {
  247.   char str[1024];
  248.   fp.gets_wo_return(str, 1024);
  249.   fp.gets_wo_return(str, 1024);
  250.   fp.gets_wo_return(str, 1024);
  251.   for(;;) {
  252.     fp.gets_wo_return(str, 1024);
  253.     if(!strcmp(str, "end")) {
  254.       break;
  255.     }
  256.     uint layer_no = get_layer_number(str);
  257.     layer(layer_no).load(fp);
  258.   }
  259. }
  260.  
  261. int PRIMITIVE::unit_change_micron2kban(int micron)
  262. {
  263.   return micron * DIS_MICRON;
  264. }
  265.  
  266. void PRIMITIVE::load_200b18(FILE_NEW& fp)
  267. {
  268.   char str[1024];
  269.   fp.gets_wo_return(str, 1024); // as component info
  270.   XYT x, y;
  271.   sscanf(str, "%d %d", &x, &y);
  272.   x = unit_change_micron2kban(x);
  273.   y = unit_change_micron2kban(y);
  274.   set_ac(XY(x, y));
  275.   fp.gets_wo_return(m_component_name, 1024);
  276.   fp.gets_wo_return(m_designator    , 1024);
  277.   for(;;) {
  278.     fp.gets_wo_return(str, 1024);
  279.     if(!strcmp(str, "end")) {
  280.       break;
  281.     }
  282.     uint layer_no = get_layer_number(str);
  283.     layer(layer_no).load(fp);
  284.   }
  285. }
  286.  
  287. uint PRIMITIVE::load_get_version(FILE_NEW& fp) const
  288. {
  289.   FILE_VERSION fver;
  290.   char str[1024];
  291.   fp.gets_wo_return(str, 1024);
  292.   return fver.get_version_no(str);
  293. }
  294.  
  295. PRIMITIVE::LOAD_FUNC_INFO PRIMITIVE::load_func_table[] = {
  296.   {FILE_VERSION::VERSION_200A8  , &PRIMITIVE::load_200a8 },
  297.   {FILE_VERSION::VERSION_200B18 , &PRIMITIVE::load_200b18},
  298.   {FILE_VERSION::VERSION_UNKNOWN, NULL                           }
  299. };
  300.  
  301. PRIMITIVE::LOAD_FUNC PRIMITIVE::get_load_func(uint version) const
  302. {
  303.   uint sentinel = FILE_VERSION::VERSION_UNKNOWN;
  304.   uint index = search_info_table(load_func_table, sentinel, version);
  305.   return load_func_table[index].func;
  306. }
  307.  
  308. int PRIMITIVE::load(FILE_NEW& fp)
  309. {
  310.   int retval;
  311.   uint version = load_get_version(fp);
  312.   LOAD_FUNC load_func = get_load_func(version);
  313.   if(load_func != NULL) {
  314.     (this->*load_func)(fp);
  315.     retval = true;
  316.   } else {
  317.     retval = false;
  318.   }
  319.   return retval;
  320. }
  321.  
  322. int PRIMITIVE::save(FILE_NEW& fp) const
  323. {
  324.   FILE_VERSION fver;
  325.   fp.printf("%s\n", fver.get_version_str(FILE_VERSION::VERSION_200B18));
  326.   fp.printf("%d %d\n", ac().x(), ac().y());
  327.   fp.printf("%s\n", m_component_name);
  328.   fp.printf("%s\n", m_designator);
  329.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  330.     fp.printf("%s\n", get_layer_name(i));
  331.     layer(i).save(fp);
  332.   }
  333.   fp.puts("end\n");
  334.   return true;
  335. }
  336.  
  337. void PRIMITIVE::collect_aperture(APT_TABLE& apt_pin_table, APT_TABLE& apt_line_table) const
  338. {
  339.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  340.     layer(i).collect_aperture(apt_pin_table, apt_line_table);
  341.   }
  342. }
  343.  
  344. bool PRIMITIVE::empty() const
  345. {
  346.   bool ret = true;
  347.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  348.     ret = ret && layer(i).empty();
  349.     if(!ret) {
  350.       break;
  351.     }
  352.   }
  353.   return ret;
  354. }
  355.  
  356. void PRIMITIVE::rotate_90()
  357. {
  358.   m_ac.rotate_90();
  359.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  360.     layer(i).rotate_90();
  361.   }
  362. }
  363.  
  364. void PRIMITIVE::limit_drill_size(uint drill)
  365. {
  366.   for(uint i = 0; i < LAYER_NUMBER; i++) {
  367.     layer(i).limit_drill_size(drill);
  368.   }
  369. }
  370.