KiCad PCB EDA Suite
gerber_draw_item.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2016 <Jean-Pierre Charras>
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #ifndef GERBER_DRAW_ITEM_H
30 #define GERBER_DRAW_ITEM_H
31 
32 #include <base_struct.h>
33 #include <dlist.h>
35 #include <gr_basic.h>
36 #include <gbr_netlist_metadata.h>
37 #include <dcode.h>
39 
40 class GERBER_FILE_IMAGE;
41 class GBR_LAYOUT;
42 class D_CODE;
43 class MSG_PANEL_ITEM;
45 class PCB_BASE_FRAME;
46 
47 namespace KIGFX
48 {
49  class VIEW;
50 }
51 
52 
53 /* Shapes id for basic shapes ( .m_Shape member ) */
55  GBR_SEGMENT = 0, // usual segment : line with rounded ends
56  GBR_ARC, // Arcs (with rounded ends)
57  GBR_CIRCLE, // ring
58  GBR_POLYGON, // polygonal shape
59  GBR_SPOT_CIRCLE, // flashed shape: round shape (can have hole)
60  GBR_SPOT_RECT, // flashed shape: rectangular shape can have hole)
61  GBR_SPOT_OVAL, // flashed shape: oval shape
62  GBR_SPOT_POLY, // flashed shape: regular polygon, 3 to 12 edges
63  GBR_SPOT_MACRO, // complex shape described by a macro
64  GBR_LAST // last value for this list
65 };
66 
67 /***/
68 
69 class GERBER_DRAW_ITEM : public EDA_ITEM
70 {
71  // make SetNext() and SetBack() private so that they may not be called from anywhere.
72  // list management is done on GERBER_DRAW_ITEMs using DLIST<GERBER_DRAW_ITEM> only.
73 private:
74  void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
75  void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
76 
77 
78 public:
79  bool m_UnitsMetric; // store here the gerber units (inch/mm). Used
80  // only to calculate aperture macros shapes sizes
81  int m_Shape; // Shape and type of this gerber item
82  wxPoint m_Start; // Line or arc start point or position of the shape
83  // for flashed items
84  wxPoint m_End; // Line or arc end point
85  wxPoint m_ArcCentre; // for arcs only: Centre of arc
86  SHAPE_POLY_SET m_Polygon; // Polygon shape data (G36 to G37 coordinates)
87  // or for complex shapes which are converted to polygon
88  wxSize m_Size; // Flashed shapes: size of the shape
89  // Lines : m_Size.x = m_Size.y = line width
90  bool m_Flashed; // True for flashed items
91  int m_DCode; // DCode used to draw this item.
92  // Allowed values are >= 10. 0 when unknown
93  // values 0 to 9 can be used for special purposes
94  // Regions (polygons) doo not use DCode,
95  // so it is set to 0
96  wxString m_AperFunction; // the aperture function set by a %TA.AperFunction, xxx
97  // (stores thre xxx value).
98  // used for regions that do not have a attached DCode, but
99  // have a TA.AperFunction defined
100  GERBER_FILE_IMAGE* m_GerberImageFile; /* Gerber file image source of this item
101  * Note: some params stored in this class are common
102  * to the whole gerber file (i.e) the whole graphic
103  * layer and some can change when reading the file,
104  * so they are stored inside this item if there is no
105  * redundancy for these parameters
106  */
107 
108 private:
109  // These values are used to draw this item, according to gerber layers parameters
110  // Because they can change inside a gerber image, they are stored here
111  // for each item
112  bool m_LayerNegative; // true = item in negative Layer
113  bool m_swapAxis; // false if A = X, B = Y; true if A =Y, B = Y
114  bool m_mirrorA; // true: mirror / axe A
115  bool m_mirrorB; // true: mirror / axe B
116  wxRealPoint m_drawScale; // A and B scaling factor
117  wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
118  double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
120 
123 public:
124  GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberparams );
126 
127  GERBER_DRAW_ITEM* Next() const { return static_cast<GERBER_DRAW_ITEM*>( Pnext ); }
128  GERBER_DRAW_ITEM* Back() const { return static_cast<GERBER_DRAW_ITEM*>( Pback ); }
129 
130  void SetNetAttributes( const GBR_NETLIST_METADATA& aNetAttributes );
132 
137  int GetLayer() const;
138 
139  bool GetLayerPolarity() const
140  {
141  return m_LayerNegative;
142  }
143 
151  bool GetTextD_CodePrms( int& aSize, wxPoint& aPos, double& aOrientation );
152 
157  bool GetTextD_CodePrms( double& aSize, VECTOR2D& aPos, double& aOrientation );
158 
166  bool HasNegativeItems();
167 
176  void SetLayerParameters();
177 
178  void SetLayerPolarity( bool aNegative)
179  {
180  m_LayerNegative = aNegative;
181  }
182 
188  void MoveAB( const wxPoint& aMoveVector );
189 
195  void MoveXY( const wxPoint& aMoveVector );
196 
203  const wxPoint GetPosition() const { return m_Start; }
204  void SetPosition( const wxPoint& aPos ) { m_Start = aPos; }
205 
214  wxPoint GetABPosition( const wxPoint& aXYPosition ) const;
215 
216  VECTOR2I GetABPosition( const VECTOR2I& aXYPosition ) const
217  {
218  return VECTOR2I( GetABPosition( wxPoint( aXYPosition.x, aXYPosition.y ) ) );
219  }
220 
229  wxPoint GetXYPosition( const wxPoint& aABPosition ) const;
230 
236  D_CODE* GetDcodeDescr() const;
237 
238  const EDA_RECT GetBoundingBox() const override;
239 
240  void Print( wxDC* aDC, const wxPoint& aOffset, GBR_DISPLAY_OPTIONS* aOptions );
241 
249 
254  void PrintGerberPoly( wxDC* aDC, COLOR4D aColor, const wxPoint& aOffset, bool aFilledShape );
255 
256  /* divers */
257  int Shape() const { return m_Shape; }
258 
259  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
260 
261  wxString ShowGBRShape() const;
262 
269  bool HitTest( const wxPoint& aRefPos, int aAccuracy = 0 ) const override;
270 
278  bool HitTest( const EDA_RECT& aRefArea, bool aContained, int aAccuracy = 0 ) const override;
279 
285  wxString GetClass() const override
286  {
287  return wxT( "GERBER_DRAW_ITEM" );
288  }
289 
294  void UnLink()
295  {
297  wxASSERT( list );
298 
299  if( list )
300  list->Remove( this );
301  }
302 
308  {
309  UnLink();
310  delete this;
311  }
312 #if defined(DEBUG)
313  void Show( int nestLevel, std::ostream& os ) const override;
314 #endif
315 
317  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
318 
320  virtual const BOX2I ViewBBox() const override;
321 
323  virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
324 
326  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
327 
329  virtual wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
330 
332  BITMAP_DEF GetMenuImage() const override;
333 };
334 
335 
337 {
338 
339 };
340 
341 #endif /* GERBER_DRAW_ITEM_H */
void SetLayerParameters()
Function SetLayerParameters Initialize parameters from Image and Layer parameters found in the gerber...
Class GBR_LAYOUT holds list of GERBER_DRAW_ITEM currently loaded.
Definition: gbr_layout.h:53
DHEAD * GetList() const
Definition: base_struct.h:221
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:177
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
virtual unsigned int ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
wxString GetClass() const override
Function GetClass returns the class name.
void SetNext(EDA_ITEM *aNext)
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
BITMAP_DEF GetMenuImage() const override
void MoveAB(const wxPoint &aMoveVector)
Function MoveAB move this object.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
Gbr_Basic_Shapes
void SetPosition(const wxPoint &aPos)
bool HasNegativeItems()
Function HasNegativeItems.
VECTOR2I GetABPosition(const VECTOR2I &aXYPosition) const
void SetBack(EDA_ITEM *aBack)
virtual const BOX2I ViewBBox() const override
int GetLayer() const
Function GetLayer returns the layer this item is on.
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner.
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
GERBER_DRAW_ITEM(GERBER_FILE_IMAGE *aGerberparams)
void Print(wxDC *aDC, const wxPoint &aOffset, GBR_DISPLAY_OPTIONS *aOptions)
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
bool HitTest(const wxPoint &aRefPos, int aAccuracy=0) const override
Function HitTest tests if the given wxPoint is within the bounds of this object.
void SetNetAttributes(const GBR_NETLIST_METADATA &aNetAttributes)
this class handle info which can be added in a gerber file as attribute of an object the GBR_INFO_TYP...
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
SHAPE_POLY_SET m_Polygon
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
GERBER_DRAW_ITEM * Back() const
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:108
wxPoint GetABPosition(const wxPoint &aXYPosition) const
Function GetABPosition returns the image position of aPosition for this object.
Class SHAPE_POLY_SET.
GBR_NETLIST_METADATA m_netAttributes
the string given by a TO attribute set in aperture (dcode).
bool GetTextD_CodePrms(int &aSize, wxPoint &aPos, double &aOrientation)
Returns the best size and orientation to display the D_Code on screen.
const GBR_NETLIST_METADATA & GetNetAttributes() const
void ConvertSegmentToPolygon()
Function ConvertSegmentToPolygon convert a line to an equivalent polygon.
virtual wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
GERBER_DRAW_ITEM * Next() const
void PrintGerberPoly(wxDC *aDC, COLOR4D aColor, const wxPoint &aOffset, bool aFilledShape)
Function PrintGerberPoly a helper function used to print the polygon stored in m_PolyCorners.
const wxPoint GetPosition() const
Function GetPosition returns the position of this object.
Board layer functions and definitions.
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
void SetLayerPolarity(bool aNegative)
wxPoint GetXYPosition(const wxPoint &aABPosition) const
Function GetXYPosition returns the image position of aPosition for this object.
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
Class VIEW.
Definition: view.h:61
SEARCH_RESULT
Definition: base_struct.h:54
void MoveXY(const wxPoint &aMoveVector)
Function MoveXY move this object.
bool GetLayerPolarity() const
GERBER_FILE_IMAGE * m_GerberImageFile
EDA_ITEM * Pnext
next in linked list
Definition: base_struct.h:176
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
EDA_UNITS_T
Definition: common.h:133
void UnLink()
Function UnLink detaches this object from its owner.
wxString ShowGBRShape() const
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxRealPoint m_drawScale