home *** CD-ROM | disk | FTP | other *** search
- // the implementation of class PIN_ELEMENT
- // Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
-
- #include "../common/bool.h"
- #include "../kbandef.h"
-
- #include "pinelem.h"
-
- XY PIN_ELEMENT::get_max() const
- {
- XY ac_max;
-
- switch(apt().type()) {
- case APERTURE::APT_ROUND :
- case APERTURE::APT_SQUARE : {
- ac_max = ac() + apt().width() / 2;
- break;
- }
- case APERTURE::APT_OBLONG :
- case APERTURE::APT_RECTANGLE : {
- ac_max = ac() + XY(apt().width() / 2, apt().height() / 2);
- break;
- }
- default : {
- ac_max = ac();
- break;
- }
- }
- return ac_max;
- }
-
- XY PIN_ELEMENT::get_min() const
- {
- XY ac_min;
-
- switch(apt().type()) {
- case APERTURE::APT_ROUND :
- case APERTURE::APT_SQUARE : {
- ac_min = ac() - apt().width() / 2;
- break;
- }
- case APERTURE::APT_OBLONG :
- case APERTURE::APT_RECTANGLE : {
- ac_min = ac() - XY(apt().width() / 2, apt().height() / 2);
- break;
- }
- default : {
- ac_min = ac();
- break;
- }
- }
- return ac_min;
- }
-
- uint PIN_ELEMENT::is_inside(const XY& ac_target)
- {
- uint retval;
-
- switch(apt().type()) {
- case APERTURE::APT_ROUND : {
- retval = compare_distance_lt(ac_target, ac(), apt().width() / 2);
- break;
- }
- case APERTURE::APT_SQUARE : {
- XY p = get_min();
- XY q = get_max();
- retval = ac_target.is_in_box(p, q);
- break;
- }
- case APERTURE::APT_OBLONG : {
- // This case needs more developmenmt.
- if(apt().width() < apt().height()) {
- // vertically long
- int r = apt().width() / 2;
- int y1 = ac().y() - apt().height() / 2 + r;
- int y2 = ac().y() + apt().height() / 2 - r;
- XY p(ac().x() - r, y1);
- XY q(ac().x() + r, y2);
- XY ac_lower(ac().x(), y1);
- XY ac_upper(ac().x(), y2);
- retval = ac_target.is_in_box(p, q)
- || compare_distance_lt(ac_target, ac_lower, r)
- || compare_distance_lt(ac_target, ac_upper, r);
- } else {
- // horizontally long
- int r = apt().height() / 2;
- int x1 = ac().x() - apt().width() / 2 + r;
- int x2 = ac().x() + apt().width() / 2 - r;
- XY p(x1, ac().y() - r);
- XY q(x2, ac().y() + r);
- XY ac_left (x1, ac().y());
- XY ac_right(x2, ac().y());
- retval = ac_target.is_in_box(p, q)
- || compare_distance_lt(ac_target, ac_left , r)
- || compare_distance_lt(ac_target, ac_right, r);
- }
- break;
- }
- case APERTURE::APT_RECTANGLE : {
- XY p = get_min();
- XY q = get_max();
- retval = ac_target.is_in_box(p, q);
- break;
- }
- default : {
- retval = false;
- }
- }
- return retval;
- }
-
- void PIN_ELEMENT::load_170_core(const char *str)
- {
- XYT x, y;
- uint type, width, drill, no;
- sscanf(str, "%d %d %d %d %d %d", &x, &y, &type, &width, &drill, &no);
- x = x * 25400 / 300;
- y = y * 25400 / 300;
- width = width * 25400 / 1000;
- drill = drill * 25400 / 1000;
- set_ac(XY(x, y));
- set_apt(APERTURE(type, width, 0, drill));
- set_number(no);
- }
-
- void PIN_ELEMENT::load_primitive_170(const char *str)
- {
- load_170_core(str);
- XY ac_new = XY(ac().x(), Y_V1TOV2 - ac().y());
- set_ac(ac_new);
- }
-
- void PIN_ELEMENT::load_component_170(const char *str)
- {
- load_170_core(str);
- XY ac_new = XY(ac().x(), - ac().y());
- set_ac(ac_new);
- }
-
- int PIN_ELEMENT::unit_change_micron2kban(int micron)
- {
- return micron * DIS_MICRON;
- }
-
- // x y type width drill number
-
- void PIN_ELEMENT::load_200a8(const char *str)
- {
- XYT x, y;
- uint type, width, drill, no;
- sscanf(str, "%d %d %d %d %d %d", &x, &y, &type, &width, &drill, &no);
- x = unit_change_micron2kban(x);
- y = unit_change_micron2kban(y);
- width = unit_change_micron2kban(width);
- drill = unit_change_micron2kban(drill);
- XY ac(x, y);
- set_ac(ac);
- set_apt(APERTURE(type, width, 0, drill));
- set_number(no);
- }
-
- // x y type width height drill number
-
- void PIN_ELEMENT::load_200b0(const char *str)
- {
- XYT x, y;
- uint type, width, height, drill, no;
- sscanf(str, "%d %d %d %d %d %d %d", &x, &y, &type, &width, &height, &drill, &no);
- x = unit_change_micron2kban(x);
- y = unit_change_micron2kban(y);
- width = unit_change_micron2kban(width);
- height = unit_change_micron2kban(height);
- drill = unit_change_micron2kban(drill);
- XY ac(x, y);
- set_ac(ac);
- set_apt(APERTURE(type, width, height, drill));
- set_number(no);
- }
-
- #if 0
- void PIN_ELEMENT::save_200a8(FILE_NEW& fp) const
- {
- fi.printf("%d %d %d %d %d %d\n",
- ac().x(),
- ac().y(),
- apt().type(),
- apt().width(),
- apt().drill(),
- number()
- );
- }
- #endif
-
- // x y type width height drill number
-
- void PIN_ELEMENT::save_200b0(FILE_NEW& fp) const
- {
- fp.printf("%d %d %d %d %d %d %d\n",
- ac().x(),
- ac().y(),
- apt().type(),
- apt().width(),
- apt().height(),
- apt().drill(),
- number()
- );
- }
-
- void PIN_ELEMENT::rotate_90()
- {
- m_ac .rotate_90();
- m_apt.rotate_90();
- }
-
- void PIN_ELEMENT::limit_drill_size(uint drill)
- {
- APERTURE temp = apt();
- temp.set_drill(minimum(temp.drill(), drill));
- set_apt(temp);
- }
-