You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

758 lines
24 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /**
  2. * @file rs274d.cpp
  3. * @brief functions to read the rs274d commands from a rs274d/rs274x file
  4. */
  5. /*
  6. * This program source code file is part of KiCad, a free EDA CAD application.
  7. *
  8. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <fctsys.h>
  28. #include <common.h>
  29. #include <gerbview.h>
  30. #include <gerbview_frame.h>
  31. #include <trigo.h>
  32. #include <class_gerber_file_image.h>
  33. #include <class_X2_gerber_attributes.h>
  34. #include <cmath>
  35. /* Gerber: NOTES about some important commands found in RS274D and RS274X (G codes):
  36. * Gn =
  37. * G01 linear interpolation (right trace)
  38. * G02, G20, G21 Circular interpolation, meaning trig <0 (clockwise)
  39. * G03, G30, G31 Circular interpolation, meaning trigo> 0 (counterclockwise)
  40. * G04 = comment. Since Sept 2014, file attributes can be found here
  41. * if the line starts by G04 #@!
  42. * G06 parabolic interpolation
  43. * G07 Cubic Interpolation
  44. * G10 linear interpolation (scale x10)
  45. * G11 linear interpolation (0.1x range)
  46. * G12 linear interpolation (0.01x scale)
  47. * G36 Start polygon mode
  48. * G37 Stop polygon mode (and close it)
  49. * G54 Selection Tool
  50. * G60 linear interpolation (scale x100)
  51. * G70 Select Units = Inches
  52. * G71 Select Units = Millimeters
  53. * G74 disable 360 degrees circular interpolation (return to 90 deg mode)
  54. * and perhaps circular interpolation (return to linear interpolation )
  55. * see rs274xrevd_e.pdf pages 47 and 48
  56. * Unfortunately page 47 said G74 disable G02 or G03
  57. * and page 48 said G01 must be used to disable G02 or G03.
  58. * Currently GerbView disable G02 or G03 after a G74 command (tests using 2 gerber files).
  59. * G75 enable 360 degrees circular interpolation
  60. * G90 mode absolute coordinates
  61. *
  62. * X, Y
  63. * X and Y are followed by + or - and m + n digits (not separated)
  64. * m = integer part
  65. * n = part after the comma
  66. * Classic formats: m = 2, n = 3 (size 2.3)
  67. * m = 3, n = 4 (size 3.4)
  68. * eg
  69. * GxxX00345Y-06123*
  70. *
  71. * Tools and D_CODES
  72. * Tool number (identification of shapes)
  73. * 10 to 999
  74. * D_CODES:
  75. * D01 ... D9 = command codes:
  76. * D01 = activating light (pen down) when placement
  77. * D02 = light extinction (pen up) when placement
  78. * D03 = Flash
  79. * D09 = VAPE Flash (I never see this command in gerber file)
  80. * D51 = G54 preceded by -> Select VAPE
  81. *
  82. * D10 ... D999 = Identification Tool: tool selection
  83. */
  84. /* Local Functions (are lower case since they are private to this source file)
  85. **/
  86. /**
  87. * Function fillFlashedGBRITEM
  88. * initializes a given GBRITEM so that it can draw a circle which is filled and
  89. * has no pen border.
  90. *
  91. * @param aGbrItem The GBRITEM to fill in.
  92. * @param aAperture the associated type of aperture
  93. * @param Dcode_index The DCODE value, like D14
  94. * @param aPos The center point of the flash
  95. * @param aSize The diameter of the round flash
  96. * @param aLayerNegative = true if the current layer is negative
  97. */
  98. void fillFlashedGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
  99. APERTURE_T aAperture,
  100. int Dcode_index,
  101. const wxPoint& aPos,
  102. wxSize aSize,
  103. bool aLayerNegative )
  104. {
  105. aGbrItem->m_Size = aSize;
  106. aGbrItem->m_Start = aPos;
  107. aGbrItem->m_End = aGbrItem->m_Start;
  108. aGbrItem->m_DCode = Dcode_index;
  109. aGbrItem->SetLayerPolarity( aLayerNegative );
  110. aGbrItem->m_Flashed = true;
  111. aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
  112. switch( aAperture )
  113. {
  114. case APT_POLYGON: // flashed regular polygon
  115. aGbrItem->m_Shape = GBR_SPOT_POLY;
  116. break;
  117. case APT_CIRCLE:
  118. aGbrItem->m_Shape = GBR_SPOT_CIRCLE;
  119. aGbrItem->m_Size.y = aGbrItem->m_Size.x;
  120. break;
  121. case APT_OVAL:
  122. aGbrItem->m_Shape = GBR_SPOT_OVAL;
  123. break;
  124. case APT_RECT:
  125. aGbrItem->m_Shape = GBR_SPOT_RECT;
  126. break;
  127. case APT_MACRO:
  128. aGbrItem->m_Shape = GBR_SPOT_MACRO;
  129. // Cache the bounding box for aperture macros
  130. aGbrItem->GetDcodeDescr()->GetMacro()->GetApertureMacroShape( aGbrItem, aPos );
  131. break;
  132. }
  133. }
  134. /**
  135. * Function fillLineGBRITEM
  136. * initializes a given GBRITEM so that it can draw a linear D code.
  137. *
  138. * @param aGbrItem The GERBER_DRAW_ITEM to fill in.
  139. * @param Dcode_index The DCODE value, like D14
  140. * @param aStart The starting point of the line
  141. * @param aEnd The ending point of the line
  142. * @param aPenSize The size of the flash. Note rectangular shapes are legal.
  143. * @param aLayerNegative = true if the current layer is negative
  144. */
  145. void fillLineGBRITEM( GERBER_DRAW_ITEM* aGbrItem,
  146. int Dcode_index,
  147. const wxPoint& aStart,
  148. const wxPoint& aEnd,
  149. wxSize aPenSize,
  150. bool aLayerNegative )
  151. {
  152. aGbrItem->m_Flashed = false;
  153. aGbrItem->m_Size = aPenSize;
  154. aGbrItem->m_Start = aStart;
  155. aGbrItem->m_End = aEnd;
  156. aGbrItem->m_DCode = Dcode_index;
  157. aGbrItem->SetLayerPolarity( aLayerNegative );
  158. aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
  159. }
  160. /**
  161. * Function fillArcGBRITEM
  162. * initializes a given GBRITEM so that it can draw an arc G code.
  163. * <p>
  164. * if multiquadrant == true : arc can be 0 to 360 degrees
  165. * and \a rel_center is the center coordinate relative to start point.
  166. * <p>
  167. * if multiquadrant == false arc can be only 0 to 90 deg,
  168. * and only in the same quadrant :
  169. * <ul>
  170. * <li> absolute angle 0 to 90 (quadrant 1) or
  171. * <li> absolute angle 90 to 180 (quadrant 2) or
  172. * <li> absolute angle 180 to 270 (quadrant 3) or
  173. * <li> absolute angle 270 to 0 (quadrant 4)
  174. * </ul><p>
  175. * @param aGbrItem is the GBRITEM to fill in.
  176. * @param Dcode_index is the DCODE value, like D14
  177. * @param aStart is the starting point
  178. * @param aEnd is the ending point
  179. * @param aRelCenter is the center coordinate relative to start point,
  180. * given in ABSOLUTE VALUE and the sign of values x et y de rel_center
  181. * must be calculated from the previously given constraint: arc only in the same quadrant.
  182. * @param aClockwise true if arc must be created clockwise
  183. * @param aPenSize The size of the flash. Note rectangular shapes are legal.
  184. * @param aMultiquadrant = true to create arcs upto 360 deg,
  185. * false when arc is inside one quadrant
  186. * @param aLayerNegative = true if the current layer is negative
  187. */
  188. static void fillArcGBRITEM( GERBER_DRAW_ITEM* aGbrItem, int Dcode_index,
  189. const wxPoint& aStart, const wxPoint& aEnd,
  190. const wxPoint& aRelCenter, wxSize aPenSize,
  191. bool aClockwise, bool aMultiquadrant,
  192. bool aLayerNegative )
  193. {
  194. wxPoint center, delta;
  195. aGbrItem->m_Shape = GBR_ARC;
  196. aGbrItem->m_Size = aPenSize;
  197. aGbrItem->m_Flashed = false;
  198. if( aGbrItem->m_GerberImageFile )
  199. aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
  200. if( aMultiquadrant )
  201. center = aStart + aRelCenter;
  202. else
  203. {
  204. // in single quadrant mode the relative coordinate aRelCenter is always >= 0
  205. // So we must recalculate the actual sign of aRelCenter.x and aRelCenter.y
  206. center = aRelCenter;
  207. // calculate arc end coordinate relative to the starting point,
  208. // because center is relative to the center point
  209. delta = aEnd - aStart;
  210. // now calculate the relative to aStart center position, for a draw function
  211. // that use trigonometric arc angle (or counter-clockwise)
  212. /* Quadrants:
  213. * Y
  214. * 2 | 1
  215. * -------X
  216. * 3 | 4
  217. * C = actual relative arc center, S = arc start (axis origin) E = relative arc end
  218. */
  219. if( (delta.x >= 0) && (delta.y >= 0) )
  220. {
  221. /* Quadrant 1 (trigo or cclockwise):
  222. * C | E
  223. * ---S---
  224. * 3 | 4
  225. */
  226. center.x = -center.x;
  227. }
  228. else if( (delta.x >= 0) && (delta.y < 0) )
  229. {
  230. /* Quadrant 4 (trigo or cclockwise):
  231. * 2 | C
  232. * ---S---
  233. * 3 | E
  234. */
  235. // Nothing to do
  236. }
  237. else if( (delta.x < 0) && (delta.y >= 0) )
  238. {
  239. /* Quadrant 2 (trigo or cclockwise):
  240. * E | 1
  241. * ---S---
  242. * C | 4
  243. */
  244. center.x = -center.x;
  245. center.y = -center.y;
  246. }
  247. else
  248. {
  249. /* Quadrant 3 (trigo or cclockwise):
  250. * 2 | 1
  251. * ---S---
  252. * E | C
  253. */
  254. center.y = -center.y;
  255. }
  256. // Due to your draw arc function, we need this:
  257. if( !aClockwise )
  258. center = - center;
  259. // Calculate actual arc center coordinate:
  260. center += aStart;
  261. }
  262. if( aClockwise )
  263. {
  264. aGbrItem->m_Start = aStart;
  265. aGbrItem->m_End = aEnd;
  266. }
  267. else
  268. {
  269. aGbrItem->m_Start = aEnd;
  270. aGbrItem->m_End = aStart;
  271. }
  272. aGbrItem->m_ArcCentre = center;
  273. aGbrItem->m_DCode = Dcode_index;
  274. aGbrItem->SetLayerPolarity( aLayerNegative );
  275. }
  276. /**
  277. * Function fillArcPOLY
  278. * creates an arc G code when found in poly outlines.
  279. * <p>
  280. * if multiquadrant == true : arc can be 0 to 360 degrees
  281. * and \a rel_center is the center coordinate relative to start point.
  282. * <p>
  283. * if multiquadrant == false arc can be only 0 to 90 deg,
  284. * and only in the same quadrant :
  285. * <ul>
  286. * <li> absolute angle 0 to 90 (quadrant 1) or
  287. * <li> absolute angle 90 to 180 (quadrant 2) or
  288. * <li> absolute angle 180 to 270 (quadrant 3) or
  289. * <li> absolute angle 270 to 0 (quadrant 4)
  290. * </ul><p>
  291. * @param aGbrItem is the GBRITEM to fill in.
  292. * @param aStart is the starting point
  293. * @param aEnd is the ending point
  294. * @param rel_center is the center coordinate relative to start point,
  295. * given in ABSOLUTE VALUE and the sign of values x et y de rel_center
  296. * must be calculated from the previously given constraint: arc only in the
  297. * same quadrant.
  298. * @param aClockwise true if arc must be created clockwise
  299. * @param aMultiquadrant = true to create arcs upto 360 deg,
  300. * false when arc is inside one quadrant
  301. * @param aLayerNegative = true if the current layer is negative
  302. */
  303. static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem,
  304. const wxPoint& aStart, const wxPoint& aEnd,
  305. const wxPoint& rel_center,
  306. bool aClockwise, bool aMultiquadrant,
  307. bool aLayerNegative )
  308. {
  309. /* in order to calculate arc parameters, we use fillArcGBRITEM
  310. * so we muse create a dummy track and use its geometric parameters
  311. */
  312. static GERBER_DRAW_ITEM dummyGbrItem( NULL );
  313. aGbrItem->SetLayerPolarity( aLayerNegative );
  314. fillArcGBRITEM( &dummyGbrItem, 0,
  315. aStart, aEnd, rel_center, wxSize(0, 0),
  316. aClockwise, aMultiquadrant, aLayerNegative );
  317. aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
  318. wxPoint center;
  319. center = dummyGbrItem.m_ArcCentre;
  320. // Calculate coordinates relative to arc center;
  321. wxPoint start = dummyGbrItem.m_Start - center;
  322. wxPoint end = dummyGbrItem.m_End - center;
  323. /* Calculate angle arc
  324. * angles are in 0.1 deg
  325. * angle is trigonometrical (counter-clockwise),
  326. * and axis is the X,Y gerber coordinates
  327. */
  328. double start_angle = ArcTangente( start.y, start.x );
  329. double end_angle = ArcTangente( end.y, end.x );
  330. // dummyTrack has right geometric parameters, but
  331. // fillArcGBRITEM calculates arc parameters for a draw function that expects
  332. // start_angle < end_angle. So ensure this is the case here:
  333. // Due to the fact atan2 returns angles between -180 to + 180 degrees,
  334. // this is not always the case ( a modulo 360.0 degrees can be lost )
  335. if( start_angle > end_angle )
  336. end_angle += 3600;
  337. double arc_angle = start_angle - end_angle;
  338. // Approximate arc by 36 segments per 360 degree
  339. const int increment_angle = 3600 / 36;
  340. int count = std::abs( arc_angle / increment_angle );
  341. if( aGbrItem->m_Polygon.OutlineCount() == 0 )
  342. aGbrItem->m_Polygon.NewOutline();
  343. // calculate polygon corners
  344. // when arc is counter-clockwise, dummyGbrItem arc goes from end to start
  345. // and we must always create a polygon from start to end.
  346. wxPoint start_arc = start;
  347. for( int ii = 0; ii <= count; ii++ )
  348. {
  349. double rot;
  350. wxPoint end_arc = start;
  351. if( aClockwise )
  352. rot = ii * increment_angle; // rot is in 0.1 deg
  353. else
  354. rot = (count - ii) * increment_angle; // rot is in 0.1 deg
  355. if( ii < count )
  356. RotatePoint( &end_arc, -rot );
  357. else // last point
  358. end_arc = aClockwise ? end : start;
  359. aGbrItem->m_Polygon.Append( VECTOR2I( end_arc + center ) );
  360. start_arc = end_arc;
  361. }
  362. }
  363. /* Read the Gnn sequence and returns the value nn.
  364. */
  365. int GERBER_FILE_IMAGE::GCodeNumber( char*& Text )
  366. {
  367. int ii = 0;
  368. char* text;
  369. char line[1024];
  370. if( Text == NULL )
  371. return 0;
  372. Text++;
  373. text = line;
  374. while( IsNumber( *Text ) )
  375. {
  376. *(text++) = *(Text++);
  377. }
  378. *text = 0;
  379. ii = atoi( line );
  380. return ii;
  381. }
  382. /* Get the sequence Dnn and returns the value nn
  383. */
  384. int GERBER_FILE_IMAGE::DCodeNumber( char*& Text )
  385. {
  386. int ii = 0;
  387. char* text;
  388. char line[1024];
  389. if( Text == NULL )
  390. return 0;
  391. Text++;
  392. text = line;
  393. while( IsNumber( *Text ) )
  394. *(text++) = *(Text++);
  395. *text = 0;
  396. ii = atoi( line );
  397. return ii;
  398. }
  399. bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command )
  400. {
  401. // D( printf( "%22s: G_CODE<%d>\n", __func__, G_command ); )
  402. switch( G_command )
  403. {
  404. case GC_PHOTO_MODE: // can starts a D03 flash command: redundant, can
  405. // be safely ignored
  406. break;
  407. case GC_LINEAR_INTERPOL_1X:
  408. m_Iterpolation = GERB_INTERPOL_LINEAR_1X;
  409. break;
  410. case GC_CIRCLE_NEG_INTERPOL:
  411. m_Iterpolation = GERB_INTERPOL_ARC_NEG;
  412. break;
  413. case GC_CIRCLE_POS_INTERPOL:
  414. m_Iterpolation = GERB_INTERPOL_ARC_POS;
  415. break;
  416. case GC_COMMENT:
  417. // Skip comment, but only if the line does not start by "G04 #@! TF"
  418. // which is a metadata
  419. if( strncmp( text, " #@! TF", 7 ) == 0 )
  420. {
  421. text += 7;
  422. X2_ATTRIBUTE dummy;
  423. dummy.ParseAttribCmd( m_Current_File, NULL, 0, text, m_LineNum );
  424. if( dummy.IsFileFunction() )
  425. {
  426. delete m_FileFunction;
  427. m_FileFunction = new X2_ATTRIBUTE_FILEFUNCTION( dummy );
  428. }
  429. }
  430. while ( *text && (*text != '*') )
  431. text++;
  432. break;
  433. case GC_LINEAR_INTERPOL_10X:
  434. m_Iterpolation = GERB_INTERPOL_LINEAR_10X;
  435. break;
  436. case GC_LINEAR_INTERPOL_0P1X:
  437. m_Iterpolation = GERB_INTERPOL_LINEAR_01X;
  438. break;
  439. case GC_LINEAR_INTERPOL_0P01X:
  440. m_Iterpolation = GERB_INTERPOL_LINEAR_001X;
  441. break;
  442. case GC_SELECT_TOOL:
  443. {
  444. int D_commande = DCodeNumber( text );
  445. if( D_commande < FIRST_DCODE )
  446. return false;
  447. if( D_commande > (TOOLS_MAX_COUNT - 1) )
  448. D_commande = TOOLS_MAX_COUNT - 1;
  449. m_Current_Tool = D_commande;
  450. D_CODE* pt_Dcode = GetDCODE( D_commande );
  451. if( pt_Dcode )
  452. pt_Dcode->m_InUse = true;
  453. break;
  454. }
  455. case GC_SPECIFY_INCHES:
  456. m_GerbMetric = false; // false = Inches, true = metric
  457. break;
  458. case GC_SPECIFY_MILLIMETERS:
  459. m_GerbMetric = true; // false = Inches, true = metric
  460. break;
  461. case GC_TURN_OFF_360_INTERPOL: // disable Multi cadran arc and Arc interpol
  462. m_360Arc_enbl = false;
  463. m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // not sure it should be done
  464. break;
  465. case GC_TURN_ON_360_INTERPOL:
  466. m_360Arc_enbl = true;
  467. break;
  468. case GC_SPECIFY_ABSOLUES_COORD:
  469. m_Relative = false; // false = absolute Coord, true = relative
  470. // Coord
  471. break;
  472. case GC_SPECIFY_RELATIVEES_COORD:
  473. m_Relative = true; // false = absolute Coord, true = relative
  474. // Coord
  475. break;
  476. case GC_TURN_ON_POLY_FILL:
  477. m_PolygonFillMode = true;
  478. m_Exposure = false;
  479. break;
  480. case GC_TURN_OFF_POLY_FILL:
  481. if( m_Exposure && GetItemsList() ) // End of polygon
  482. {
  483. GERBER_DRAW_ITEM * gbritem = m_Drawings.GetLast();
  484. gbritem->m_Polygon.Append( gbritem->m_Polygon.Vertex( 0 ) );
  485. StepAndRepeatItem( *gbritem );
  486. }
  487. m_Exposure = false;
  488. m_PolygonFillMode = false;
  489. m_PolygonFillModeState = 0;
  490. break;
  491. case GC_MOVE: // Non existent
  492. default:
  493. {
  494. wxString msg;
  495. msg.Printf( wxT( "G%0.2d command not handled" ), G_command );
  496. AddMessageToList( msg );
  497. return false;
  498. }
  499. }
  500. return true;
  501. }
  502. bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande )
  503. {
  504. wxSize size( 15, 15 );
  505. APERTURE_T aperture = APT_CIRCLE;
  506. GERBER_DRAW_ITEM* gbritem;
  507. int dcode = 0;
  508. D_CODE* tool = NULL;
  509. wxString msg;
  510. if( D_commande >= FIRST_DCODE ) // This is a "Set tool" command
  511. {
  512. if( D_commande > (TOOLS_MAX_COUNT - 1) )
  513. D_commande = TOOLS_MAX_COUNT - 1;
  514. // remember which tool is selected, nothing is done with it in this
  515. // call
  516. m_Current_Tool = D_commande;
  517. D_CODE* pt_Dcode = GetDCODE( D_commande );
  518. if( pt_Dcode )
  519. pt_Dcode->m_InUse = true;
  520. return true;
  521. }
  522. else // D_commande = 0..9: this is a pen command (usually D1, D2 or D3)
  523. {
  524. m_Last_Pen_Command = D_commande;
  525. }
  526. if( m_PolygonFillMode ) // Enter a polygon description:
  527. {
  528. switch( D_commande )
  529. {
  530. case 1: // code D01 Draw line, exposure ON
  531. if( !m_Exposure ) // Start a new polygon outline:
  532. {
  533. m_Exposure = true;
  534. gbritem = new GERBER_DRAW_ITEM( this );
  535. m_Drawings.Append( gbritem );
  536. gbritem->m_Shape = GBR_POLYGON;
  537. gbritem->m_Flashed = false;
  538. }
  539. switch( m_Iterpolation )
  540. {
  541. case GERB_INTERPOL_ARC_NEG:
  542. case GERB_INTERPOL_ARC_POS:
  543. gbritem = m_Drawings.GetLast();
  544. fillArcPOLY( gbritem, m_PreviousPos,
  545. m_CurrentPos, m_IJPos,
  546. ( m_Iterpolation == GERB_INTERPOL_ARC_NEG ) ? false : true,
  547. m_360Arc_enbl, GetLayerParams().m_LayerNegative );
  548. break;
  549. default:
  550. gbritem = m_Drawings.GetLast();
  551. gbritem->m_Start = m_PreviousPos; // m_Start is used as temporary storage
  552. if( gbritem->m_Polygon.OutlineCount() == 0 )
  553. {
  554. gbritem->m_Polygon.NewOutline();
  555. gbritem->m_Polygon.Append( VECTOR2I( gbritem->m_Start ) );
  556. }
  557. gbritem->m_End = m_CurrentPos; // m_End is used as temporary storage
  558. gbritem->m_Polygon.Append( VECTOR2I( gbritem->m_End ) );
  559. break;
  560. }
  561. m_PreviousPos = m_CurrentPos;
  562. m_PolygonFillModeState = 1;
  563. break;
  564. case 2: // code D2: exposure OFF (i.e. "move to")
  565. if( m_Exposure && GetItemsList() ) // End of polygon
  566. {
  567. gbritem = m_Drawings.GetLast();
  568. gbritem->m_Polygon.Append( gbritem->m_Polygon.Vertex( 0 ) );
  569. StepAndRepeatItem( *gbritem );
  570. }
  571. m_Exposure = false;
  572. m_PreviousPos = m_CurrentPos;
  573. m_PolygonFillModeState = 0;
  574. break;
  575. default:
  576. return false;
  577. }
  578. }
  579. else
  580. {
  581. switch( D_commande )
  582. {
  583. case 1: // code D01 Draw line, exposure ON
  584. m_Exposure = true;
  585. tool = GetDCODE( m_Current_Tool );
  586. if( tool )
  587. {
  588. size = tool->m_Size;
  589. dcode = tool->m_Num_Dcode;
  590. aperture = tool->m_Shape;
  591. }
  592. switch( m_Iterpolation )
  593. {
  594. case GERB_INTERPOL_LINEAR_1X:
  595. gbritem = new GERBER_DRAW_ITEM( this );
  596. m_Drawings.Append( gbritem );
  597. fillLineGBRITEM( gbritem, dcode, m_PreviousPos,
  598. m_CurrentPos, size, GetLayerParams().m_LayerNegative );
  599. StepAndRepeatItem( *gbritem );
  600. break;
  601. case GERB_INTERPOL_LINEAR_01X:
  602. case GERB_INTERPOL_LINEAR_001X:
  603. case GERB_INTERPOL_LINEAR_10X:
  604. wxBell();
  605. break;
  606. case GERB_INTERPOL_ARC_NEG:
  607. case GERB_INTERPOL_ARC_POS:
  608. gbritem = new GERBER_DRAW_ITEM( this );
  609. m_Drawings.Append( gbritem );
  610. fillArcGBRITEM( gbritem, dcode, m_PreviousPos,
  611. m_CurrentPos, m_IJPos, size,
  612. ( m_Iterpolation == GERB_INTERPOL_ARC_NEG ) ?
  613. false : true, m_360Arc_enbl, GetLayerParams().m_LayerNegative );
  614. StepAndRepeatItem( *gbritem );
  615. break;
  616. default:
  617. msg.Printf( wxT( "RS274D: DCODE Command: interpol error (type %X)" ),
  618. m_Iterpolation );
  619. AddMessageToList( msg );
  620. break;
  621. }
  622. m_PreviousPos = m_CurrentPos;
  623. break;
  624. case 2: // code D2: exposure OFF (i.e. "move to")
  625. m_Exposure = false;
  626. m_PreviousPos = m_CurrentPos;
  627. break;
  628. case 3: // code D3: flash aperture
  629. tool = GetDCODE( m_Current_Tool );
  630. if( tool )
  631. {
  632. size = tool->m_Size;
  633. dcode = tool->m_Num_Dcode;
  634. aperture = tool->m_Shape;
  635. }
  636. gbritem = new GERBER_DRAW_ITEM( this );
  637. m_Drawings.Append( gbritem );
  638. fillFlashedGBRITEM( gbritem, aperture, dcode, m_CurrentPos,
  639. size, GetLayerParams().m_LayerNegative );
  640. StepAndRepeatItem( *gbritem );
  641. m_PreviousPos = m_CurrentPos;
  642. break;
  643. default:
  644. return false;
  645. }
  646. }
  647. return true;
  648. }