home *** CD-ROM | disk | FTP | other *** search
- /*
- * the class PRIMITIVE
- * Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
- */
-
- #include "../finfo.h"
- #include "../intstr.h"
- #include "../kbandef.h"
-
- #include "prim.h"
-
- PRIMITIVE::PRIMITIVE(const PRIMITIVE& src)
- : m_layer(src.m_layer),
- m_ac (src.m_ac )
- {
- strcpy(m_component_name, src.m_component_name);
- strcpy(m_designator , src.m_designator );
- }
-
- void PRIMITIVE::operator=(const PRIMITIVE& src)
- {
- m_ac = src.m_ac;
- strcpy(m_component_name, src.m_component_name);
- strcpy(m_designator , src.m_designator );
- m_layer = src.m_layer;
- }
-
- void PRIMITIVE::operator+=(const PRIMITIVE& target)
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i) += target.layer(i);
- }
- }
-
- void PRIMITIVE::clear(void)
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).clear();
- }
- }
-
- XY PRIMITIVE::get_max(void) const
- {
- XY ac_max(X_MIN, Y_MIN);
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- ac_max = ::get_max(ac_max, layer(i).get_max());
- }
- return ac() + ac_max;
- }
-
- XY PRIMITIVE::get_min(void) const
- {
- XY ac_min(X_MAX, Y_MAX);
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- ac_min = ::get_min(ac_min, layer(i).get_min());
- }
- return ac() + ac_min;
- }
-
- void PRIMITIVE::shift(const XY& ac_dif, PRIMITIVE& target) const
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).shift(ac_dif, target.layer(i));
- }
- }
-
- void PRIMITIVE::unselect(void)
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).unselect();
- }
- }
-
- void PRIMITIVE::select_items_in_block(const XY& ac1, const XY& ac2)
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).select_items_in_block(ac1, ac2);
- }
- }
-
- void PRIMITIVE::collect_selected_items(PRIMITIVE& dst) const
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).collect_selected_items(dst.layer(i));
- }
- }
-
- void PRIMITIVE::remove_selected_items(void)
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).remove_selected_items();
- }
- }
-
- const INTSTR_ELEMENT PRIMITIVE::layer_str[] = {
- {LAYER_PATTERN_COMMON, "layer_pattern_commmon"},
- {LAYER_PATTERN_TOP , "layer_pattern_top" },
- {LAYER_PATTERN_BOTTOM, "layer_pattern_bottom" },
- {LAYER_SILK_TOP , "layer_silk_top" },
- {LAYER_SILK_BOTTOM , "layer_silk_bottom" },
- {LAYER_NUMBER , NULL }
- };
-
- const char *PRIMITIVE::get_layer_name(uint no) const
- {
- INTSTR_TABLE table(layer_str, LAYER_NUMBER);
- return table.get_str(no);
- }
-
- uint PRIMITIVE::get_layer_number(const char *s) const
- {
- INTSTR_TABLE table(layer_str, LAYER_NUMBER);
- return table.get_no(s);
- }
-
- int PRIMITIVE::load_text_list(FILE_NEW& fp)
- {
- for(;;) {
- char str[1024];
- fp.gets_wo_return(str, 1024);
- if(!strcmp(str, "end")) {
- break;
- }
- fp.gets_wo_return(str, 1024);
- }
- return true;
- }
-
- int PRIMITIVE::load_primitive_170(FILE_NEW& fp)
- {
- for(;;) {
- char str[1024];
- fp.gets_wo_return(str, 1024);
- if(!strcmp(str, "end")) {
- break;
- } else if(!strcmp(str, "pin_170")) {
- PIN_LIST& pin_list = layer(LAYER_PATTERN_COMMON).pin_list();
- pin_list.load_primitive_170(fp);
- } else if(!strcmp(str, "line_top_120")) {
- LINE_LIST& line_list = layer(LAYER_PATTERN_TOP).line_list();
- line_list.load_primitive_170(fp);
- } else if(!strcmp(str, "line_bottom_120")) {
- LINE_LIST& line_list = layer(LAYER_PATTERN_BOTTOM).line_list();
- line_list.load_primitive_170(fp);
- } else if(!strcmp(str, "line_internal_1_120")) {
- LINE_LIST dummy;
- dummy.load_primitive_170(fp);
- } else if(!strcmp(str, "line_internal_2_120")) {
- LINE_LIST dummy;
- dummy.load_primitive_170(fp);
- } else if(!strcmp(str, "line_internal_3_120")) {
- LINE_LIST dummy;
- dummy.load_primitive_170(fp);
- } else if(!strcmp(str, "line_internal_4_120")) {
- LINE_LIST dummy;
- dummy.load_primitive_170(fp);
- } else if(!strcmp(str, "line_silk_120")) {
- LINE_LIST& line_list = layer(LAYER_SILK_TOP).line_list();
- line_list.load_primitive_170(fp);
- } else if(!strcmp(str, "line_border_120")) {
- LINE_LIST& line_list = layer(LAYER_SILK_BOTTOM).line_list();
- line_list.load_primitive_170(fp);
- } else if(!strcmp(str, "text_top_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_bottom_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_internal_1_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_internal_2_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_internal_3_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_internal_4_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_silk_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_border_120")) {
- load_text_list(fp);
- } else {
- // corrupted
- break;
- }
- }
- return true;
- }
-
- int PRIMITIVE::load_component_170(FILE_NEW& fp)
- {
- for(;;) {
- char str[1024];
- fp.gets_wo_return(str, 1024);
- if(!strcmp(str, "end")) {
- break;
- } else if(!strcmp(str, "pin_170")) {
- PIN_LIST& pin_list = layer(LAYER_PATTERN_COMMON).pin_list();
- pin_list.load_component_170(fp);
- } else if(!strcmp(str, "line_top_120")) {
- LINE_LIST& line_list = layer(LAYER_PATTERN_TOP).line_list();
- line_list.load_component_170(fp);
- } else if(!strcmp(str, "line_bottom_120")) {
- LINE_LIST& line_list = layer(LAYER_PATTERN_BOTTOM).line_list();
- line_list.load_component_170(fp);
- } else if(!strcmp(str, "line_internal_1_120")) {
- LINE_LIST dummy;
- dummy.load_component_170(fp);
- } else if(!strcmp(str, "line_internal_2_120")) {
- LINE_LIST dummy;
- dummy.load_component_170(fp);
- } else if(!strcmp(str, "line_internal_3_120")) {
- LINE_LIST dummy;
- dummy.load_component_170(fp);
- } else if(!strcmp(str, "line_internal_4_120")) {
- LINE_LIST dummy;
- dummy.load_component_170(fp);
- } else if(!strcmp(str, "line_silk_120")) {
- LINE_LIST& line_list = layer(LAYER_SILK_TOP).line_list();
- line_list.load_component_170(fp);
- } else if(!strcmp(str, "line_border_120")) {
- LINE_LIST& line_list = layer(LAYER_SILK_BOTTOM).line_list();
- line_list.load_component_170(fp);
- } else if(!strcmp(str, "text_top_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_bottom_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_internal_1_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_internal_2_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_internal_3_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_internal_4_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_silk_120")) {
- load_text_list(fp);
- } else if(!strcmp(str, "text_border_120")) {
- load_text_list(fp);
- } else {
- // corrupted
- break;
- }
- }
- return true;
- }
-
- void PRIMITIVE::load_200a8(FILE_NEW& fp)
- {
- char str[1024];
- fp.gets_wo_return(str, 1024);
- fp.gets_wo_return(str, 1024);
- fp.gets_wo_return(str, 1024);
- for(;;) {
- fp.gets_wo_return(str, 1024);
- if(!strcmp(str, "end")) {
- break;
- }
- uint layer_no = get_layer_number(str);
- layer(layer_no).load(fp);
- }
- }
-
- int PRIMITIVE::unit_change_micron2kban(int micron)
- {
- return micron * DIS_MICRON;
- }
-
- void PRIMITIVE::load_200b18(FILE_NEW& fp)
- {
- char str[1024];
- fp.gets_wo_return(str, 1024); // as component info
- XYT x, y;
- sscanf(str, "%d %d", &x, &y);
- x = unit_change_micron2kban(x);
- y = unit_change_micron2kban(y);
- set_ac(XY(x, y));
- fp.gets_wo_return(m_component_name, 1024);
- fp.gets_wo_return(m_designator , 1024);
- for(;;) {
- fp.gets_wo_return(str, 1024);
- if(!strcmp(str, "end")) {
- break;
- }
- uint layer_no = get_layer_number(str);
- layer(layer_no).load(fp);
- }
- }
-
- uint PRIMITIVE::load_get_version(FILE_NEW& fp) const
- {
- FILE_VERSION fver;
- char str[1024];
- fp.gets_wo_return(str, 1024);
- return fver.get_version_no(str);
- }
-
- PRIMITIVE::LOAD_FUNC_INFO PRIMITIVE::load_func_table[] = {
- {FILE_VERSION::VERSION_200A8 , &PRIMITIVE::load_200a8 },
- {FILE_VERSION::VERSION_200B18 , &PRIMITIVE::load_200b18},
- {FILE_VERSION::VERSION_UNKNOWN, NULL }
- };
-
- PRIMITIVE::LOAD_FUNC PRIMITIVE::get_load_func(uint version) const
- {
- uint sentinel = FILE_VERSION::VERSION_UNKNOWN;
- uint index = search_info_table(load_func_table, sentinel, version);
- return load_func_table[index].func;
- }
-
- int PRIMITIVE::load(FILE_NEW& fp)
- {
- int retval;
- uint version = load_get_version(fp);
- LOAD_FUNC load_func = get_load_func(version);
- if(load_func != NULL) {
- (this->*load_func)(fp);
- retval = true;
- } else {
- retval = false;
- }
- return retval;
- }
-
- int PRIMITIVE::save(FILE_NEW& fp) const
- {
- FILE_VERSION fver;
- fp.printf("%s\n", fver.get_version_str(FILE_VERSION::VERSION_200B18));
- fp.printf("%d %d\n", ac().x(), ac().y());
- fp.printf("%s\n", m_component_name);
- fp.printf("%s\n", m_designator);
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- fp.printf("%s\n", get_layer_name(i));
- layer(i).save(fp);
- }
- fp.puts("end\n");
- return true;
- }
-
- void PRIMITIVE::collect_aperture(APT_TABLE& apt_pin_table, APT_TABLE& apt_line_table) const
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).collect_aperture(apt_pin_table, apt_line_table);
- }
- }
-
- bool PRIMITIVE::empty() const
- {
- bool ret = true;
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- ret = ret && layer(i).empty();
- if(!ret) {
- break;
- }
- }
- return ret;
- }
-
- void PRIMITIVE::rotate_90()
- {
- m_ac.rotate_90();
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).rotate_90();
- }
- }
-
- void PRIMITIVE::limit_drill_size(uint drill)
- {
- for(uint i = 0; i < LAYER_NUMBER; i++) {
- layer(i).limit_drill_size(drill);
- }
- }
-