pcb 4.1.1
An interactive printed circuit board layout editor.
|
00001 00037 #ifdef HAVE_CONFIG_H 00038 #include "config.h" 00039 #endif 00040 00041 #include <math.h> 00042 #include <stdio.h> 00043 #include <stdlib.h> 00044 #ifdef HAVE_STRING_H 00045 #include <string.h> 00046 #endif 00047 00048 #include "global.h" 00049 00050 #include "action.h" 00051 #include "buffer.h" 00052 #include "compat.h" 00053 #include "crosshair.h" 00054 #include "data.h" 00055 #include "draw.h" 00056 #include "error.h" 00057 #include "find.h" 00058 #include "misc.h" 00059 #include "move.h" 00060 #include "set.h" 00061 #include "undo.h" 00062 #include "pcb-printf.h" 00063 00064 #ifdef HAVE_LIBDMALLOC 00065 #include <dmalloc.h> 00066 #endif 00067 00068 static int mode_position = 0; 00069 static int mode_stack[MAX_MODESTACK_DEPTH]; 00070 00074 void 00075 SetGrid (Coord Grid, bool align) 00076 { 00077 char *grid_string; 00078 if (Grid >= 1 && Grid <= MAX_GRID) 00079 { 00080 if (align) 00081 { 00082 PCB->GridOffsetX = Crosshair.X % Grid; 00083 PCB->GridOffsetY = Crosshair.Y % Grid; 00084 } 00085 PCB->Grid = Grid; 00086 grid_string = pcb_g_strdup_printf ("%mr", Grid); 00087 if (grid_string) 00088 AttributePut (PCB, "PCB::grid::size", grid_string); 00089 g_free (grid_string); 00090 if (Settings.DrawGrid) 00091 Redraw (); 00092 } 00093 } 00094 00098 void 00099 SetLineSize (Coord Size) 00100 { 00101 if (Size >= MIN_LINESIZE && Size <= MAX_LINESIZE) 00102 { 00103 Settings.LineThickness = Size; 00104 if (TEST_FLAG (AUTODRCFLAG, PCB)) 00105 FitCrosshairIntoGrid (Crosshair.X, Crosshair.Y); 00106 } 00107 } 00108 00112 void 00113 SetViaSize (Coord Size, bool Force) 00114 { 00115 if (Force || (Size <= MAX_PINORVIASIZE && 00116 Size >= MIN_PINORVIASIZE && 00117 Size >= Settings.ViaDrillingHole + MIN_PINORVIACOPPER)) 00118 { 00119 Settings.ViaThickness = Size; 00120 } 00121 } 00122 00126 void 00127 SetViaDrillingHole (Coord Size, bool Force) 00128 { 00129 if (Force || (Size <= MAX_PINORVIASIZE && 00130 Size >= MIN_PINORVIAHOLE && 00131 Size <= Settings.ViaThickness - MIN_PINORVIACOPPER)) 00132 { 00133 Settings.ViaDrillingHole = Size; 00134 } 00135 } 00136 00137 void 00138 pcb_use_route_style (RouteStyleType * rst) 00139 { 00140 Settings.LineThickness = rst->Thick; 00141 Settings.ViaThickness = rst->Diameter; 00142 Settings.ViaDrillingHole = rst->Hole; 00143 Settings.Keepaway = rst->Keepaway; 00144 } 00145 00149 void 00150 SetKeepawayWidth (Coord Width) 00151 { 00152 if (Width <= MAX_LINESIZE) 00153 { 00154 Settings.Keepaway = Width; 00155 } 00156 } 00157 00161 void 00162 SetTextScale (int Scale) 00163 { 00164 if (Scale <= MAX_TEXTSCALE && Scale >= MIN_TEXTSCALE) 00165 { 00166 Settings.TextScale = Scale; 00167 } 00168 } 00169 00173 void 00174 SetChangedFlag (bool New) 00175 { 00176 if (PCB->Changed != New) 00177 { 00178 PCB->Changed = New; 00179 00180 } 00181 } 00182 00186 void 00187 SetBufferNumber (int Number) 00188 { 00189 if (Number >= 0 && Number < MAX_BUFFER) 00190 { 00191 Settings.BufferNumber = Number; 00192 00193 /* do an update on the crosshair range */ 00194 crosshair_update_range(); 00195 } 00196 } 00197 00201 void 00202 SaveMode (void) 00203 { 00204 mode_stack[mode_position] = Settings.Mode; 00205 if (mode_position < MAX_MODESTACK_DEPTH - 1) 00206 mode_position++; 00207 } 00208 00212 void 00213 RestoreMode (void) 00214 { 00215 if (mode_position == 0) 00216 { 00217 Message ("hace: underflow of restore mode\n"); 00218 return; 00219 } 00220 SetMode (mode_stack[--mode_position]); 00221 } 00222 00223 00233 void 00234 SetMode (int Mode) 00235 { 00236 static bool recursing = false; 00237 if (recursing) 00238 return; 00239 recursing = true; 00240 notify_crosshair_change (false); 00241 addedLines = 0; 00242 Crosshair.AttachedObject.Type = NO_TYPE; 00243 Crosshair.AttachedObject.State = STATE_FIRST; 00244 Crosshair.AttachedPolygon.PointN = 0; 00245 if (PCB->RatDraw) 00246 { 00247 if (Mode == ARC_MODE || Mode == RECTANGLE_MODE || 00248 Mode == VIA_MODE || Mode == POLYGON_MODE || 00249 Mode == POLYGONHOLE_MODE || 00250 Mode == TEXT_MODE || Mode == INSERTPOINT_MODE || 00251 Mode == THERMAL_MODE) 00252 { 00253 Message (_("That mode is NOT allowed when drawing ratlines!\n")); 00254 Mode = NO_MODE; 00255 } 00256 } 00257 if (Settings.Mode == LINE_MODE && Mode == ARC_MODE && 00258 Crosshair.AttachedLine.State != STATE_FIRST) 00259 { 00260 Crosshair.AttachedLine.State = STATE_FIRST; 00261 Crosshair.AttachedBox.State = STATE_SECOND; 00262 Crosshair.AttachedBox.Point1.X = Crosshair.AttachedBox.Point2.X = 00263 Crosshair.AttachedLine.Point1.X; 00264 Crosshair.AttachedBox.Point1.Y = Crosshair.AttachedBox.Point2.Y = 00265 Crosshair.AttachedLine.Point1.Y; 00266 AdjustAttachedObjects (); 00267 } 00268 else if (Settings.Mode == ARC_MODE && Mode == LINE_MODE && 00269 Crosshair.AttachedBox.State != STATE_FIRST) 00270 { 00271 Crosshair.AttachedBox.State = STATE_FIRST; 00272 Crosshair.AttachedLine.State = STATE_SECOND; 00273 Crosshair.AttachedLine.Point1.X = Crosshair.AttachedLine.Point2.X = 00274 Crosshair.AttachedBox.Point1.X; 00275 Crosshair.AttachedLine.Point1.Y = Crosshair.AttachedLine.Point2.Y = 00276 Crosshair.AttachedBox.Point1.Y; 00277 Settings.Mode = Mode; 00278 AdjustAttachedObjects (); 00279 } 00280 /* Cancel rubberband move */ 00281 else if (Settings.Mode == MOVE_MODE) 00282 MoveObjectAndRubberband (Crosshair.AttachedObject.Type, 00283 Crosshair.AttachedObject.Ptr1, 00284 Crosshair.AttachedObject.Ptr2, 00285 Crosshair.AttachedObject.Ptr3, 00286 0, 0); 00287 else 00288 { 00289 if (Settings.Mode == ARC_MODE || Settings.Mode == LINE_MODE) 00290 SetLocalRef (0, 0, false); 00291 Crosshair.AttachedBox.State = STATE_FIRST; 00292 Crosshair.AttachedLine.State = STATE_FIRST; 00293 if (Mode == LINE_MODE && TEST_FLAG (AUTODRCFLAG, PCB)) 00294 { 00295 if (ClearFlagOnAllObjects (true, CONNECTEDFLAG | FOUNDFLAG)) 00296 { 00297 IncrementUndoSerialNumber (); 00298 Draw (); 00299 } 00300 } 00301 } 00302 00303 Settings.Mode = Mode; 00304 crosshair_update_range(); 00305 00306 recursing = false; 00307 00308 notify_crosshair_change (true); 00309 } 00310 00314 void 00315 SetRouteStyle (char *name) 00316 { 00317 char num[10]; 00318 00319 STYLE_LOOP (PCB); 00320 { 00321 if (name && NSTRCMP (name, style->Name) == 0) 00322 { 00323 sprintf (num, "%d", n + 1); 00324 hid_actionl ("RouteStyle", num, NULL); 00325 break; 00326 } 00327 } 00328 END_LOOP; 00329 } 00330 00331 void 00332 SetLocalRef (Coord X, Coord Y, bool Showing) 00333 { 00334 static MarkType old; 00335 static int count = 0; 00336 00337 if (Showing) 00338 { 00339 notify_mark_change (false); 00340 if (count == 0) 00341 old = Marked; 00342 Marked.X = X; 00343 Marked.Y = Y; 00344 Marked.status = true; 00345 count++; 00346 notify_mark_change (true); 00347 } 00348 else if (count > 0) 00349 { 00350 notify_mark_change (false); 00351 count = 0; 00352 Marked = old; 00353 notify_mark_change (true); 00354 } 00355 }