KiCad PCB EDA Suite
class_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 CLASS_GERBER_DRAW_ITEM_H
30 #define CLASS_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>
38 
39 class GERBER_FILE_IMAGE;
40 class GBR_LAYOUT;
41 class D_CODE;
42 class MSG_PANEL_ITEM;
44 
45 
46 /* Shapes id for basic shapes ( .m_Shape member ) */
48  GBR_SEGMENT = 0, // usual segment : line with rounded ends
49  GBR_ARC, // Arcs (with rounded ends)
50  GBR_CIRCLE, // ring
51  GBR_POLYGON, // polygonal shape
52  GBR_SPOT_CIRCLE, // flashed shape: round shape (can have hole)
53  GBR_SPOT_RECT, // flashed shape: rectangular shape can have hole)
54  GBR_SPOT_OVAL, // flashed shape: oval shape
55  GBR_SPOT_POLY, // flashed shape: regular polygon, 3 to 12 edges
56  GBR_SPOT_MACRO, // complex shape described by a macro
57  GBR_LAST // last value for this list
58 };
59 
60 /***/
61 
62 class GERBER_DRAW_ITEM : public EDA_ITEM
63 {
64  // make SetNext() and SetBack() private so that they may not be called from anywhere.
65  // list management is done on GERBER_DRAW_ITEMs using DLIST<GERBER_DRAW_ITEM> only.
66 private:
67  void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
68  void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
69 
70 
71 public:
72  bool m_UnitsMetric; /* store here the gerber units (inch/mm). Used
73  * only to calculate aperture macros shapes sizes */
74  int m_Shape; // Shape and type of this gerber item
75  wxPoint m_Start; // Line or arc start point or position of the shape
76  // for flashed items
77  wxPoint m_End; // Line or arc end point
78  wxPoint m_ArcCentre; // for arcs only: Centre of arc
79  std::vector <wxPoint> m_PolyCorners; // list of corners for polygons (G36 to G37 coordinates)
80  // or for complex shapes which are converted to polygon
81  wxSize m_Size; // Flashed shapes: size of the shape
82  // Lines : m_Size.x = m_Size.y = line width
83  bool m_Flashed; // True for flashed items
84  int m_DCode; // DCode used to draw this item.
85  // 0 for items that do not use DCodes (polygons)
86  // or when unknown and normal values are 10 to 999
87  // values 0 to 9 can be used for special purposes
88  GERBER_FILE_IMAGE* m_GerberImageFile; /* Gerber file image source of this item
89  * Note: some params stored in this class are common
90  * to the whole gerber file (i.e) the whole graphic
91  * layer and some can change when reading the file,
92  * so they are stored inside this item if there is no
93  * redundancy for these parameters
94  */
95 
96 private:
97  // These values are used to draw this item, according to gerber layers parameters
98  // Because they can change inside a gerber image, they are stored here
99  // for each item
100  bool m_LayerNegative; // true = item in negative Layer
101  bool m_swapAxis; // false if A = X, B = Y; true if A =Y, B = Y
102  bool m_mirrorA; // true: mirror / axe A
103  bool m_mirrorB; // true: mirror / axe B
104  wxRealPoint m_drawScale; // A and B scaling factor
105  wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
106  double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
108 
111 public:
112  GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberparams );
114 
115  GERBER_DRAW_ITEM* Next() const { return static_cast<GERBER_DRAW_ITEM*>( Pnext ); }
116  GERBER_DRAW_ITEM* Back() const { return static_cast<GERBER_DRAW_ITEM*>( Pback ); }
117 
118  void SetNetAttributes( const GBR_NETLIST_METADATA& aNetAttributes );
120 
125  int GetLayer() const;
126 
128  {
129  return m_LayerNegative;
130  }
131 
139  bool HasNegativeItems();
140 
149  void SetLayerParameters();
150 
151  void SetLayerPolarity( bool aNegative)
152  {
153  m_LayerNegative = aNegative;
154  }
155 
161  void MoveAB( const wxPoint& aMoveVector );
162 
168  void MoveXY( const wxPoint& aMoveVector );
169 
176  const wxPoint& GetPosition() const { return m_Start; }
177  void SetPosition( const wxPoint& aPos ) { m_Start = aPos; }
178 
187  wxPoint GetABPosition( const wxPoint& aXYPosition ) const;
188 
197  wxPoint GetXYPosition( const wxPoint& aABPosition ) const;
198 
205 
206  const EDA_RECT GetBoundingBox() const override;
207 
208  /* Display on screen: */
209  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
210  GR_DRAWMODE aDrawMode, const wxPoint&aOffset, GBR_DISPLAY_OPTIONS* aDrawOptions );
211 
219 
224  void DrawGbrPoly( EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor,
225  const wxPoint& aOffset, bool aFilledShape );
226 
227  /* divers */
228  int Shape() const { return m_Shape; }
229 
230  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
231 
232  wxString ShowGBRShape();
233 
240  bool HitTest( const wxPoint& aRefPos ) const override;
241 
249  bool HitTest( const EDA_RECT& aRefArea ) const;
250 
256  wxString GetClass() const override
257  {
258  return wxT( "GERBER_DRAW_ITEM" );
259  }
260 
265  void UnLink()
266  {
268  wxASSERT( list );
269 
270  if( list )
271  list->Remove( this );
272  }
273 
279  {
280  UnLink();
281  delete this;
282  }
283 #if defined(DEBUG)
284  void Show( int nestLevel, std::ostream& os ) const override;
285 #endif
286 
287 };
288 
289 #endif /* CLASS_GERBER_DRAW_ITEM_H */
DHEAD * GetList() const
Definition: base_struct.h:209
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.
void DrawGbrPoly(EDA_RECT *aClipBox, wxDC *aDC, COLOR4D aColor, const wxPoint &aOffset, bool aFilledShape)
Function DrawGbrPoly a helper function used to draw the polygon stored in m_PolyCorners.
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:165
wxString GetClass() const override
Function GetClass returns the class name.
void SetNext(EDA_ITEM *aNext)
void MoveAB(const wxPoint &aMoveVector)
Function MoveAB move this object.
void SetPosition(const wxPoint &aPos)
bool HasNegativeItems()
Function HasNegativeItems.
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
D_CODE * GetDcodeDescr()
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
void SetBack(EDA_ITEM *aBack)
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 ...
std::vector< wxPoint > m_PolyCorners
GERBER_DRAW_ITEM(GERBER_FILE_IMAGE *aGerberparams)
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
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...
int GetLayer() const
Function GetLayer returns the layer this item is on.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
GERBER_DRAW_ITEM * Next() const
GBR_NETLIST_METADATA m_netAttributes
the string given by a TO attribute set in aperture (dcode).
GERBER_DRAW_ITEM * Back() const
void ConvertSegmentToPolygon()
Function ConvertSegmentToPolygon convert a line to an equivalent polygon.
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset, GBR_DISPLAY_OPTIONS *aDrawOptions)
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:81
Class EDA_RECT handles the component boundary box.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
void SetLayerPolarity(bool aNegative)
bool HitTest(const wxPoint &aRefPos) const override
Function HitTest tests if the given wxPoint is within the bounds of 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
void MoveXY(const wxPoint &aMoveVector)
Function MoveXY move this object.
wxPoint GetXYPosition(const wxPoint &aABPosition) const
Function GetXYPosition returns the image position of aPosition for this object.
wxPoint GetABPosition(const wxPoint &aXYPosition) const
Function GetABPosition returns the image position of aPosition for this object.
GERBER_FILE_IMAGE * m_GerberImageFile
EDA_ITEM * Pnext
next in linked list
Definition: base_struct.h:164
void UnLink()
Function UnLink detaches this object from its owner.
const GBR_NETLIST_METADATA & GetNetAttributes()
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39