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  // 0 for items that do not use DCodes (polygons)
93  // or when unknown and normal values are 10 to 999
94  // values 0 to 9 can be used for special purposes
95  GERBER_FILE_IMAGE* m_GerberImageFile; /* Gerber file image source of this item
96  * Note: some params stored in this class are common
97  * to the whole gerber file (i.e) the whole graphic
98  * layer and some can change when reading the file,
99  * so they are stored inside this item if there is no
100  * redundancy for these parameters
101  */
102 
103 private:
104  // These values are used to draw this item, according to gerber layers parameters
105  // Because they can change inside a gerber image, they are stored here
106  // for each item
107  bool m_LayerNegative; // true = item in negative Layer
108  bool m_swapAxis; // false if A = X, B = Y; true if A =Y, B = Y
109  bool m_mirrorA; // true: mirror / axe A
110  bool m_mirrorB; // true: mirror / axe B
111  wxRealPoint m_drawScale; // A and B scaling factor
112  wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
113  double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
115 
118 public:
119  GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberparams );
121 
122  GERBER_DRAW_ITEM* Next() const { return static_cast<GERBER_DRAW_ITEM*>( Pnext ); }
123  GERBER_DRAW_ITEM* Back() const { return static_cast<GERBER_DRAW_ITEM*>( Pback ); }
124 
125  void SetNetAttributes( const GBR_NETLIST_METADATA& aNetAttributes );
127 
132  int GetLayer() const;
133 
134  bool GetLayerPolarity() const
135  {
136  return m_LayerNegative;
137  }
138 
146  bool GetTextD_CodePrms( int& aSize, wxPoint& aPos, double& aOrientation );
147 
152  bool GetTextD_CodePrms( double& aSize, VECTOR2D& aPos, double& aOrientation );
153 
161  bool HasNegativeItems();
162 
171  void SetLayerParameters();
172 
173  void SetLayerPolarity( bool aNegative)
174  {
175  m_LayerNegative = aNegative;
176  }
177 
183  void MoveAB( const wxPoint& aMoveVector );
184 
190  void MoveXY( const wxPoint& aMoveVector );
191 
198  const wxPoint GetPosition() const { return m_Start; }
199  void SetPosition( const wxPoint& aPos ) { m_Start = aPos; }
200 
209  wxPoint GetABPosition( const wxPoint& aXYPosition ) const;
210 
211  VECTOR2I GetABPosition( const VECTOR2I& aXYPosition ) const
212  {
213  return VECTOR2I( GetABPosition( wxPoint( aXYPosition.x, aXYPosition.y ) ) );
214  }
215 
224  wxPoint GetXYPosition( const wxPoint& aABPosition ) const;
225 
231  D_CODE* GetDcodeDescr() const;
232 
233  const EDA_RECT GetBoundingBox() const override;
234 
235  void Print( wxDC* aDC, const wxPoint& aOffset, GBR_DISPLAY_OPTIONS* aOptions );
236 
244 
249  void PrintGerberPoly( wxDC* aDC, COLOR4D aColor, const wxPoint& aOffset, bool aFilledShape );
250 
251  /* divers */
252  int Shape() const { return m_Shape; }
253 
254  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
255 
256  wxString ShowGBRShape() const;
257 
264  bool HitTest( const wxPoint& aRefPos, int aAccuracy = 0 ) const override;
265 
273  bool HitTest( const EDA_RECT& aRefArea, bool aContained, int aAccuracy = 0 ) const override;
274 
280  wxString GetClass() const override
281  {
282  return wxT( "GERBER_DRAW_ITEM" );
283  }
284 
289  void UnLink()
290  {
292  wxASSERT( list );
293 
294  if( list )
295  list->Remove( this );
296  }
297 
303  {
304  UnLink();
305  delete this;
306  }
307 #if defined(DEBUG)
308  void Show( int nestLevel, std::ostream& os ) const override;
309 #endif
310 
312  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
313 
315  virtual const BOX2I ViewBBox() const override;
316 
318  virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
319 
321  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
322 
324  virtual wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
325 
327  BITMAP_DEF GetMenuImage() const override;
328 };
329 
330 
332 {
333 
334 };
335 
336 #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:208
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:164
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:57
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 obtect 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:95
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:150
void SetLayerPolarity(bool aNegative)
wxPoint GetXYPosition(const wxPoint &aABPosition) const
Function GetXYPosition returns the image position of aPosition for this object.
Basic classes for most KiCad items.
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:59
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:163
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
EDA_UNITS_T
Definition: common.h:157
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