KiCad PCB EDA Suite
rs274d.cpp File Reference

functions to read the rs274d commands from a rs274d/rs274x file More...

#include <fctsys.h>
#include <common.h>
#include <gerbview.h>
#include <gerbview_frame.h>
#include <trigo.h>
#include <class_gerber_file_image.h>
#include <class_X2_gerber_attributes.h>
#include <cmath>

Go to the source code of this file.

Functions

void fillFlashedGBRITEM (GERBER_DRAW_ITEM *aGbrItem, APERTURE_T aAperture, int Dcode_index, const wxPoint &aPos, wxSize aSize, bool aLayerNegative)
 Function fillFlashedGBRITEM initializes a given GBRITEM so that it can draw a circle which is filled and has no pen border. More...
 
void fillLineGBRITEM (GERBER_DRAW_ITEM *aGbrItem, int Dcode_index, const wxPoint &aStart, const wxPoint &aEnd, wxSize aPenSize, bool aLayerNegative)
 Function fillLineGBRITEM initializes a given GBRITEM so that it can draw a linear D code. More...
 
static void fillArcGBRITEM (GERBER_DRAW_ITEM *aGbrItem, int Dcode_index, const wxPoint &aStart, const wxPoint &aEnd, const wxPoint &aRelCenter, wxSize aPenSize, bool aClockwise, bool aMultiquadrant, bool aLayerNegative)
 Function fillArcGBRITEM initializes a given GBRITEM so that it can draw an arc G code. More...
 
static void fillArcPOLY (GERBER_DRAW_ITEM *aGbrItem, const wxPoint &aStart, const wxPoint &aEnd, const wxPoint &rel_center, bool aClockwise, bool aMultiquadrant, bool aLayerNegative)
 Function fillArcPOLY creates an arc G code when found in poly outlines. More...
 

Detailed Description

functions to read the rs274d commands from a rs274d/rs274x file

Definition in file rs274d.cpp.

Function Documentation

static void fillArcGBRITEM ( GERBER_DRAW_ITEM aGbrItem,
int  Dcode_index,
const wxPoint aStart,
const wxPoint aEnd,
const wxPoint aRelCenter,
wxSize  aPenSize,
bool  aClockwise,
bool  aMultiquadrant,
bool  aLayerNegative 
)
static

Function fillArcGBRITEM initializes a given GBRITEM so that it can draw an arc G code.

if multiquadrant == true : arc can be 0 to 360 degrees and rel_center is the center coordinate relative to start point.

if multiquadrant == false arc can be only 0 to 90 deg, and only in the same quadrant :

  • absolute angle 0 to 90 (quadrant 1) or
  • absolute angle 90 to 180 (quadrant 2) or
  • absolute angle 180 to 270 (quadrant 3) or
  • absolute angle 270 to 0 (quadrant 4)
Parameters
aGbrItemis the GBRITEM to fill in.
Dcode_indexis the DCODE value, like D14
aLayeris the layer index to set into the GBRITEM
aStartis the starting point
aEndis the ending point
aRelCenteris the center coordinate relative to start point, given in ABSOLUTE VALUE and the sign of values x et y de rel_center must be calculated from the previously given constraint: arc only in the same quadrant.
aClockwisetrue if arc must be created clockwise
aPenSizeThe size of the flash. Note rectangular shapes are legal.
aMultiquadrant= true to create arcs upto 360 deg, false when arc is inside one quadrant
aLayerNegative= true if the current layer is negative

Definition at line 212 of file rs274d.cpp.

References delta, GBR_ARC, GERBER_DRAW_ITEM::m_ArcCentre, GERBER_DRAW_ITEM::m_DCode, GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_Flashed, GERBER_DRAW_ITEM::m_GerberImageFile, GERBER_FILE_IMAGE::m_NetAttributeDict, GERBER_DRAW_ITEM::m_Shape, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, GERBER_DRAW_ITEM::SetLayerPolarity(), GERBER_DRAW_ITEM::SetNetAttributes(), wxPoint::x, and wxPoint::y.

Referenced by GERBER_FILE_IMAGE::Execute_DCODE_Command(), and fillArcPOLY().

217 {
218  wxPoint center, delta;
219 
220  aGbrItem->m_Shape = GBR_ARC;
221  aGbrItem->m_Size = aPenSize;
222  aGbrItem->m_Flashed = false;
223 
224  if( aGbrItem->m_GerberImageFile )
225  aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
226 
227  if( aMultiquadrant )
228  center = aStart + aRelCenter;
229  else
230  {
231  // in single quadrant mode the relative coordinate aRelCenter is always >= 0
232  // So we must recalculate the actual sign of aRelCenter.x and aRelCenter.y
233  center = aRelCenter;
234 
235  // calculate arc end coordinate relative to the starting point,
236  // because center is relative to the center point
237  delta = aEnd - aStart;
238 
239  // now calculate the relative to aStart center position, for a draw function
240  // that use trigonometric arc angle (or counter-clockwise)
241  /* Quadrants:
242  * Y
243  * 2 | 1
244  * -------X
245  * 3 | 4
246  * C = actual relative arc center, S = arc start (axis origin) E = relative arc end
247  */
248  if( (delta.x >= 0) && (delta.y >= 0) )
249  {
250  /* Quadrant 1 (trigo or cclockwise):
251  * C | E
252  * ---S---
253  * 3 | 4
254  */
255  center.x = -center.x;
256  }
257  else if( (delta.x >= 0) && (delta.y < 0) )
258  {
259  /* Quadrant 4 (trigo or cclockwise):
260  * 2 | C
261  * ---S---
262  * 3 | E
263  */
264  // Nothing to do
265  }
266  else if( (delta.x < 0) && (delta.y >= 0) )
267  {
268  /* Quadrant 2 (trigo or cclockwise):
269  * E | 1
270  * ---S---
271  * C | 4
272  */
273  center.x = -center.x;
274  center.y = -center.y;
275  }
276  else
277  {
278  /* Quadrant 3 (trigo or cclockwise):
279  * 2 | 1
280  * ---S---
281  * E | C
282  */
283  center.y = -center.y;
284  }
285 
286  // Due to your draw arc function, we need this:
287  if( !aClockwise )
288  center = - center;
289 
290  // Calculate actual arc center coordinate:
291  center += aStart;
292  }
293 
294  if( aClockwise )
295  {
296  aGbrItem->m_Start = aStart;
297  aGbrItem->m_End = aEnd;
298  }
299  else
300  {
301  aGbrItem->m_Start = aEnd;
302  aGbrItem->m_End = aStart;
303  }
304 
305  aGbrItem->m_ArcCentre = center;
306 
307  aGbrItem->m_DCode = Dcode_index;
308  aGbrItem->SetLayerPolarity( aLayerNegative );
309 }
void SetNetAttributes(const GBR_NETLIST_METADATA &aNetAttributes)
static const int delta[8][2]
Definition: solve.cpp:112
GBR_NETLIST_METADATA m_NetAttributeDict
void SetLayerPolarity(bool aNegative)
GERBER_FILE_IMAGE * m_GerberImageFile
static void fillArcPOLY ( GERBER_DRAW_ITEM aGbrItem,
const wxPoint aStart,
const wxPoint aEnd,
const wxPoint rel_center,
bool  aClockwise,
bool  aMultiquadrant,
bool  aLayerNegative 
)
static

Function fillArcPOLY creates an arc G code when found in poly outlines.

if multiquadrant == true : arc can be 0 to 360 degrees and rel_center is the center coordinate relative to start point.

if multiquadrant == false arc can be only 0 to 90 deg, and only in the same quadrant :

  • absolute angle 0 to 90 (quadrant 1) or
  • absolute angle 90 to 180 (quadrant 2) or
  • absolute angle 180 to 270 (quadrant 3) or
  • absolute angle 270 to 0 (quadrant 4)
Parameters
aGbrItemis the GBRITEM to fill in.
aStartis the starting point
aEndis the ending point
rel_centeris the center coordinate relative to start point, given in ABSOLUTE VALUE and the sign of values x et y de rel_center must be calculated from the previously given constraint: arc only in the same quadrant.
aClockwisetrue if arc must be created clockwise
aMultiquadrant= true to create arcs upto 360 deg, false when arc is inside one quadrant
aLayerNegative= true if the current layer is negative

Definition at line 339 of file rs274d.cpp.

References abs, ArcTangente(), fillArcGBRITEM(), GERBER_DRAW_ITEM::m_ArcCentre, GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_GerberImageFile, GERBER_FILE_IMAGE::m_NetAttributeDict, GERBER_DRAW_ITEM::m_PolyCorners, GERBER_DRAW_ITEM::m_Start, RotatePoint(), GERBER_DRAW_ITEM::SetLayerPolarity(), GERBER_DRAW_ITEM::SetNetAttributes(), wxPoint::x, and wxPoint::y.

Referenced by GERBER_FILE_IMAGE::Execute_DCODE_Command().

344 {
345  /* in order to calculate arc parameters, we use fillArcGBRITEM
346  * so we muse create a dummy track and use its geometric parameters
347  */
348  static GERBER_DRAW_ITEM dummyGbrItem( NULL );
349 
350  aGbrItem->SetLayerPolarity( aLayerNegative );
351 
352  fillArcGBRITEM( &dummyGbrItem, 0,
353  aStart, aEnd, rel_center, wxSize(0, 0),
354  aClockwise, aMultiquadrant, aLayerNegative );
355 
356  aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
357 
358  wxPoint center;
359  center = dummyGbrItem.m_ArcCentre;
360 
361  // Calculate coordinates relative to arc center;
362  wxPoint start = dummyGbrItem.m_Start - center;
363  wxPoint end = dummyGbrItem.m_End - center;
364 
365  /* Calculate angle arc
366  * angles are in 0.1 deg
367  * angle is trigonometrical (counter-clockwise),
368  * and axis is the X,Y gerber coordinates
369  */
370  double start_angle = ArcTangente( start.y, start.x );
371  double end_angle = ArcTangente( end.y, end.x );
372 
373  // dummyTrack has right geometric parameters, but
374  // fillArcGBRITEM calculates arc parameters for a draw function that expects
375  // start_angle < end_angle. So ensure this is the case here:
376  // Due to the fact atan2 returns angles between -180 to + 180 degrees,
377  // this is not always the case ( a modulo 360.0 degrees can be lost )
378  if( start_angle > end_angle )
379  end_angle += 3600;
380 
381  double arc_angle = start_angle - end_angle;
382  // Approximate arc by 36 segments per 360 degree
383  const int increment_angle = 3600 / 36;
384  int count = std::abs( arc_angle / increment_angle );
385 
386  // calculate polygon corners
387  // when arc is counter-clockwise, dummyGbrItem arc goes from end to start
388  // and we must always create a polygon from start to end.
389  wxPoint start_arc = start;
390  for( int ii = 0; ii <= count; ii++ )
391  {
392  double rot;
393  wxPoint end_arc = start;
394  if( aClockwise )
395  rot = ii * increment_angle; // rot is in 0.1 deg
396  else
397  rot = (count - ii) * increment_angle; // rot is in 0.1 deg
398 
399  if( ii < count )
400  RotatePoint( &end_arc, -rot );
401  else // last point
402  end_arc = aClockwise ? end : start;
403 
404  aGbrItem->m_PolyCorners.push_back( end_arc + center );
405 
406  start_arc = end_arc;
407  }
408 }
std::vector< wxPoint > m_PolyCorners
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
void SetNetAttributes(const GBR_NETLIST_METADATA &aNetAttributes)
#define abs(a)
Definition: auxiliary.h:84
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:271
GBR_NETLIST_METADATA m_NetAttributeDict
void SetLayerPolarity(bool aNegative)
static void fillArcGBRITEM(GERBER_DRAW_ITEM *aGbrItem, int Dcode_index, const wxPoint &aStart, const wxPoint &aEnd, const wxPoint &aRelCenter, wxSize aPenSize, bool aClockwise, bool aMultiquadrant, bool aLayerNegative)
Function fillArcGBRITEM initializes a given GBRITEM so that it can draw an arc G code.
Definition: rs274d.cpp:212
GERBER_FILE_IMAGE * m_GerberImageFile
void fillFlashedGBRITEM ( GERBER_DRAW_ITEM aGbrItem,
APERTURE_T  aAperture,
int  Dcode_index,
const wxPoint aPos,
wxSize  aSize,
bool  aLayerNegative 
)

Function fillFlashedGBRITEM initializes a given GBRITEM so that it can draw a circle which is filled and has no pen border.

Parameters
aGbrItemThe GBRITEM to fill in.
aAperturethe associated type of aperture
Dcode_indexThe DCODE value, like D14
aLayerThe layer index to set into the GBRITEM
aPosThe center point of the flash
aSizeThe diameter of the round flash
aLayerNegative= true if the current layer is negative

Definition at line 108 of file rs274d.cpp.

References APT_CIRCLE, APT_MACRO, APT_OVAL, APT_POLYGON, APT_RECT, GBR_SPOT_CIRCLE, GBR_SPOT_MACRO, GBR_SPOT_OVAL, GBR_SPOT_POLY, GBR_SPOT_RECT, GERBER_DRAW_ITEM::m_DCode, GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_Flashed, GERBER_DRAW_ITEM::m_GerberImageFile, GERBER_FILE_IMAGE::m_NetAttributeDict, GERBER_DRAW_ITEM::m_Shape, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, GERBER_DRAW_ITEM::SetLayerPolarity(), and GERBER_DRAW_ITEM::SetNetAttributes().

Referenced by GERBER_FILE_IMAGE::Execute_DCODE_Command(), and EXCELLON_IMAGE::Execute_Drill_Command().

114 {
115  aGbrItem->m_Size = aSize;
116  aGbrItem->m_Start = aPos;
117  aGbrItem->m_End = aGbrItem->m_Start;
118  aGbrItem->m_DCode = Dcode_index;
119  aGbrItem->SetLayerPolarity( aLayerNegative );
120  aGbrItem->m_Flashed = true;
121  aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
122 
123  switch( aAperture )
124  {
125  case APT_POLYGON: // flashed regular polygon
126  aGbrItem->m_Shape = GBR_SPOT_POLY;
127  break;
128 
129  case APT_CIRCLE:
130  aGbrItem->m_Shape = GBR_SPOT_CIRCLE;
131  aGbrItem->m_Size.y = aGbrItem->m_Size.x;
132  break;
133 
134  case APT_OVAL:
135  aGbrItem->m_Shape = GBR_SPOT_OVAL;
136  break;
137 
138  case APT_RECT:
139  aGbrItem->m_Shape = GBR_SPOT_RECT;
140  break;
141 
142  case APT_MACRO:
143  aGbrItem->m_Shape = GBR_SPOT_MACRO;
144  break;
145  }
146 }
Definition: dcode.h:52
void SetNetAttributes(const GBR_NETLIST_METADATA &aNetAttributes)
Definition: dcode.h:51
GBR_NETLIST_METADATA m_NetAttributeDict
void SetLayerPolarity(bool aNegative)
GERBER_FILE_IMAGE * m_GerberImageFile
void fillLineGBRITEM ( GERBER_DRAW_ITEM aGbrItem,
int  Dcode_index,
const wxPoint aStart,
const wxPoint aEnd,
wxSize  aPenSize,
bool  aLayerNegative 
)

Function fillLineGBRITEM initializes a given GBRITEM so that it can draw a linear D code.

Parameters
aGbrItemThe GERBER_DRAW_ITEM to fill in.
Dcode_indexThe DCODE value, like D14
aLayerThe layer index to set into the GBRITEM
aStartThe starting point of the line
aEndThe ending point of the line
aPenSizeThe size of the flash. Note rectangular shapes are legal.
aLayerNegative= true if the current layer is negative

Definition at line 161 of file rs274d.cpp.

References GERBER_DRAW_ITEM::m_DCode, GERBER_DRAW_ITEM::m_End, GERBER_DRAW_ITEM::m_Flashed, GERBER_DRAW_ITEM::m_GerberImageFile, GERBER_FILE_IMAGE::m_NetAttributeDict, GERBER_DRAW_ITEM::m_Size, GERBER_DRAW_ITEM::m_Start, GERBER_DRAW_ITEM::SetLayerPolarity(), and GERBER_DRAW_ITEM::SetNetAttributes().

Referenced by GERBER_FILE_IMAGE::Execute_DCODE_Command(), and EXCELLON_IMAGE::Execute_Drill_Command().

167 {
168  aGbrItem->m_Flashed = false;
169 
170  aGbrItem->m_Size = aPenSize;
171 
172  aGbrItem->m_Start = aStart;
173  aGbrItem->m_End = aEnd;
174 
175  aGbrItem->m_DCode = Dcode_index;
176  aGbrItem->SetLayerPolarity( aLayerNegative );
177 
178  aGbrItem->SetNetAttributes( aGbrItem->m_GerberImageFile->m_NetAttributeDict );
179 }
void SetNetAttributes(const GBR_NETLIST_METADATA &aNetAttributes)
GBR_NETLIST_METADATA m_NetAttributeDict
void SetLayerPolarity(bool aNegative)
GERBER_FILE_IMAGE * m_GerberImageFile