utilities.h

00001 /*
00002  * utilities
00003  *
00004  * Copyright 2008 Dean Ferreyra <dferreyra@igc.org>, All rights reserved
00005  *
00006  * This file is part of Footprint-Update.
00007  * 
00008  * Footprint-Update is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  * 
00013  * Footprint-Update is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with Footprint-Update.  If not, see <http://www.gnu.org/licenses/>.
00020  *
00021  * $Id: utilities.h,v 1.21 2008-05-22 04:52:13 dean Exp $
00022  * Dean Ferreyra
00023  */
00024 
00025 #ifndef UTILITIES_H_INCLUDED
00026 #define UTILITIES_H_INCLUDED 1
00027 
00028 #include <stdio.h>
00029 #include <math.h>
00030 #include <assert.h>
00031 
00032 #include "global.h"
00033 #include "box.h"
00034 #include "copy.h"
00035 #include "change.h"
00036 #include "rotate.h"
00037 #include "move.h"
00038 #include "data.h"
00039 #include "hid.h"
00040 #include "misc.h"
00041 #include "create.h"
00042 #include "rtree.h"
00043 #include "polygon.h"
00044 #include "undo.h"
00045 
00046 #define TITLE "footprintupdate"
00047 #define ACTION_NAME "UpdateFootprintsFromBuffer"
00048 
00049 /*
00050  * Pad/pin type
00051  */
00052 
00053 typedef struct {
00054   PadTypePtr pad;
00055   PinTypePtr pin;
00056 } PadOrPinType;
00057 
00058 PadOrPinType make_pad_or_pin(PadTypePtr pad, PinTypePtr pin);
00059 Boolean is_pad_or_pin(const PadOrPinType* pp);
00060 int number_cmp(const char* number_a, const char* number_b);
00061 const char* pad_or_pin_number(const PadOrPinType* pp);
00062 const char* pad_or_pin_name(const PadOrPinType* pp);
00063 Boolean pad_or_pin_test_flag(const PadOrPinType* pp, unsigned long flag);
00064 void pad_or_pin_set_flag(PadOrPinType* pp, unsigned long flag);
00065 int pad_or_pin_number_cmp(const PadOrPinType* ppa, const PadOrPinType* ppb);
00066 
00067 CheapPointType pad_center(PadTypePtr pad);
00068 CheapPointType pin_center(PinTypePtr pin);
00069 CheapPointType pad_or_pin_center(PadOrPinType* pp);
00070 
00071 PadTypePtr find_pad(ElementTypePtr element, const char* number);
00072 PinTypePtr find_pin(ElementTypePtr element, const char* number);
00073 Boolean find_pad_or_pin(ElementTypePtr element, const char* number,
00074                         PadOrPinType* pp_ptr);
00075 
00076 Boolean is_number_unique(ElementTypePtr element, const char* number);
00077 
00078 Boolean have_two_corresponding_non_coincident(ElementTypePtr old_element,
00079                                               ElementTypePtr new_element,
00080                                               PadOrPinType* old1_pp_ptr,
00081                                               PadOrPinType* old2_pp_ptr,
00082                                               PadOrPinType* new1_pp_ptr,
00083                                               PadOrPinType* new2_pp_ptr);
00084 Boolean have_two_corresponding_unique_non_coincident(ElementTypePtr old_element,
00085                                                      ElementTypePtr new_element,
00086                                                      PadOrPinType* old1_pp_ptr,
00087                                                      PadOrPinType* old2_pp_ptr,
00088                                                      PadOrPinType* new1_pp_ptr,
00089                                                      PadOrPinType* new2_pp_ptr);
00090 Boolean have_any_corresponding_pad_or_pin(ElementTypePtr old_element,
00091                                           ElementTypePtr new_element,
00092                                           PadOrPinType* old_pp,
00093                                           PadOrPinType* new_pp);
00094 
00095 /*
00096  * Points
00097  */
00098 
00099 CheapPointType make_point(LocationType x, LocationType y);
00100 CheapPointType subtract_point(CheapPointType pt1, CheapPointType pt2);
00101 double point_distance2(CheapPointType pt1, CheapPointType pt2);
00102 
00103 /*
00104  * Logging
00105  */
00106 
00107 void log_point(CheapPointType pt);
00108 
00109 void log_pad_or_pin(const PadOrPinType* pp);
00110 void log_pad(PadTypePtr p);
00111 void log_pin(PinTypePtr p);
00112 void log_element(ElementTypePtr e);
00113 
00114 #if DEBUG
00115 #  define debug_log_point(pt) log_point(pt)
00116 #  define debug_log_pad_or_pin(pp) log_pad_or_pin(pp)
00117 #  define debug_log_pad(p) log_pad(p)
00118 #  define debug_log_pin(p) log_pin(p)
00119 #  define debug_log_element(e) log_element(e)
00120 #else
00121 #  define debug_log_point(pt)
00122 #  define debug_log_pad_or_pin(pp)
00123 #  define debug_log_pad(p)
00124 #  define debug_log_pin(p)
00125 #  define debug_log_element(e)
00126 #endif
00127 
00128 void base_log(const char *fmt, ...);
00129 void debug_log(const char *fmt, ...);
00130 
00131 /*
00132  * Miscellaneous
00133  */
00134 
00135 double round(double v);
00136 double multiple_of_90(double rad);
00137 BYTE angle_to_rotation_steps(double rad);
00138 
00139 /*
00140  * Macros
00141  */
00142 
00143 #define FLAG_VALUE(o) ((o).f)
00144 
00145 #define MAKE_PT(obj)                            \
00146     make_point((obj).X, (obj).Y)
00147 
00148 #define IS_REFLECTED(elem1, elem2)              \
00149     (TEST_FLAG(ONSOLDERFLAG, (elem1))           \
00150      != TEST_FLAG(ONSOLDERFLAG, (elem2)));
00151 
00152 /* "Hygienic" loop macros for nesting */
00153 
00154 #define PAD_LOOP_HYG(element, suffix)                                   \
00155     do {                                                                \
00156         Cardinal        n##suffix, sn##suffix;                          \
00157         PadTypePtr      pad##suffix;                                    \
00158         for (sn##suffix = (element)->PadN, n##suffix = 0;               \
00159              (element)->PadN > 0 && n##suffix < (element)->PadN ;       \
00160              sn##suffix == (element)->PadN ? n##suffix++ : 0)           \
00161             {                                                           \
00162                 pad##suffix = &(element)->Pad[n##suffix]
00163 
00164 
00165 #define PIN_LOOP_HYG(element, suffix)                                   \
00166     do {                                                                \
00167         Cardinal        n##suffix, sn##suffix;                          \
00168         PinTypePtr      pin##suffix;                                    \
00169         for (sn##suffix = (element)->PinN, n##suffix = 0;               \
00170              (element)->PinN > 0 && n##suffix < (element)->PinN ;       \
00171              sn##suffix == (element)->PinN ? n##suffix++ : 0)           \
00172             {                                                           \
00173                 pin##suffix = &(element)->Pin[n##suffix]
00174 
00175 #define PAD_OR_PIN_LOOP_HYG(element, suffix)                            \
00176     do {                                                                \
00177         Cardinal   n##suffix = 0;                                       \
00178         Cardinal   internal_n##suffix = 0;                              \
00179         Boolean    pad_done##suffix = False;                            \
00180         while (1) {                                                     \
00181             PadOrPinType pp##suffix = make_pad_or_pin(NULL, NULL);      \
00182             if (! pad_done##suffix) {                                   \
00183                 if (internal_n##suffix < (element)->PadN) {             \
00184                     n##suffix = internal_n##suffix++;                   \
00185                     pp##suffix =                                        \
00186                         make_pad_or_pin(&(element)->Pad[n##suffix],     \
00187                                         NULL);                          \
00188                 } else {                                                \
00189                     pad_done##suffix = True;                            \
00190                     internal_n##suffix = 0;                             \
00191                 }                                                       \
00192             }                                                           \
00193             if (pad_done##suffix) {                                     \
00194                 if (internal_n##suffix < (element)->PinN) {             \
00195                     n##suffix = internal_n##suffix++;                   \
00196                     pp##suffix =                                        \
00197                         make_pad_or_pin(NULL,                           \
00198                                         &(element)->Pin[n##suffix]);    \
00199                                                                         \
00200                 } else {                                                \
00201                     break;                                              \
00202                 }                                                       \
00203             }
00204 
00205 #define PAD_OR_PIN_LOOP(element) PAD_OR_PIN_LOOP_HYG(element, )
00206 
00207 #endif

Generated on Tue Aug 17 15:28:04 2010 for pcb-plugins by  doxygen 1.4.6-NO