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>
39 
40 class GERBER_FILE_IMAGE;
41 class GBR_LAYOUT;
42 class D_CODE;
43 class MSG_PANEL_ITEM;
45 
46 namespace KIGFX
47 {
48  class VIEW;
49 }
50 
51 
52 /* Shapes id for basic shapes ( .m_Shape member ) */
54  GBR_SEGMENT = 0, // usual segment : line with rounded ends
55  GBR_ARC, // Arcs (with rounded ends)
56  GBR_CIRCLE, // ring
57  GBR_POLYGON, // polygonal shape
58  GBR_SPOT_CIRCLE, // flashed shape: round shape (can have hole)
59  GBR_SPOT_RECT, // flashed shape: rectangular shape can have hole)
60  GBR_SPOT_OVAL, // flashed shape: oval shape
61  GBR_SPOT_POLY, // flashed shape: regular polygon, 3 to 12 edges
62  GBR_SPOT_MACRO, // complex shape described by a macro
63  GBR_LAST // last value for this list
64 };
65 
66 /***/
67 
68 class GERBER_DRAW_ITEM : public EDA_ITEM
69 {
70  // make SetNext() and SetBack() private so that they may not be called from anywhere.
71  // list management is done on GERBER_DRAW_ITEMs using DLIST<GERBER_DRAW_ITEM> only.
72 private:
73  void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
74  void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
75 
76 
77 public:
78  bool m_UnitsMetric; /* store here the gerber units (inch/mm). Used
79  * only to calculate aperture macros shapes sizes */
80  int m_Shape; // Shape and type of this gerber item
81  wxPoint m_Start; // Line or arc start point or position of the shape
82  // for flashed items
83  wxPoint m_End; // Line or arc end point
84  wxPoint m_ArcCentre; // for arcs only: Centre of arc
85  SHAPE_POLY_SET m_Polygon; // Polygon shape data (G36 to G37 coordinates)
86  // or for complex shapes which are converted to polygon
87  wxSize m_Size; // Flashed shapes: size of the shape
88  // Lines : m_Size.x = m_Size.y = line width
89  bool m_Flashed; // True for flashed items
90  int m_DCode; // DCode used to draw this item.
91  // 0 for items that do not use DCodes (polygons)
92  // or when unknown and normal values are 10 to 999
93  // values 0 to 9 can be used for special purposes
94  GERBER_FILE_IMAGE* m_GerberImageFile; /* Gerber file image source of this item
95  * Note: some params stored in this class are common
96  * to the whole gerber file (i.e) the whole graphic
97  * layer and some can change when reading the file,
98  * so they are stored inside this item if there is no
99  * redundancy for these parameters
100  */
101 
102 private:
103  // These values are used to draw this item, according to gerber layers parameters
104  // Because they can change inside a gerber image, they are stored here
105  // for each item
106  bool m_LayerNegative; // true = item in negative Layer
107  bool m_swapAxis; // false if A = X, B = Y; true if A =Y, B = Y
108  bool m_mirrorA; // true: mirror / axe A
109  bool m_mirrorB; // true: mirror / axe B
110  wxRealPoint m_drawScale; // A and B scaling factor
111  wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
112  double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
114 
117 public:
118  GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberparams );
120 
121  GERBER_DRAW_ITEM* Next() const { return static_cast<GERBER_DRAW_ITEM*>( Pnext ); }
122  GERBER_DRAW_ITEM* Back() const { return static_cast<GERBER_DRAW_ITEM*>( Pback ); }
123 
124  void SetNetAttributes( const GBR_NETLIST_METADATA& aNetAttributes );
126 
131  int GetLayer() const;
132 
133  bool GetLayerPolarity() const
134  {
135  return m_LayerNegative;
136  }
137 
145  bool GetTextD_CodePrms( int& aSize, wxPoint& aPos, double& aOrientation );
146 
151  bool GetTextD_CodePrms( double& aSize, VECTOR2D& aPos, double& aOrientation );
152 
160  bool HasNegativeItems();
161 
170  void SetLayerParameters();
171 
172  void SetLayerPolarity( bool aNegative)
173  {
174  m_LayerNegative = aNegative;
175  }
176 
182  void MoveAB( const wxPoint& aMoveVector );
183 
189  void MoveXY( const wxPoint& aMoveVector );
190 
197  const wxPoint& GetPosition() const { return m_Start; }
198  void SetPosition( const wxPoint& aPos ) { m_Start = aPos; }
199 
208  wxPoint GetABPosition( const wxPoint& aXYPosition ) const;
209 
210  VECTOR2I GetABPosition( const VECTOR2I& aXYPosition ) const
211  {
212  return VECTOR2I( GetABPosition( wxPoint( aXYPosition.x, aXYPosition.y ) ) );
213  }
214 
223  wxPoint GetXYPosition( const wxPoint& aABPosition ) const;
224 
230  D_CODE* GetDcodeDescr() const;
231 
232  const EDA_RECT GetBoundingBox() const override;
233 
234  /* Display on screen: */
235  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
236  GR_DRAWMODE aDrawMode, const wxPoint&aOffset, GBR_DISPLAY_OPTIONS* aDrawOptions );
237 
245 
250  void DrawGbrPoly( EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor,
251  const wxPoint& aOffset, bool aFilledShape );
252 
253  /* divers */
254  int Shape() const { return m_Shape; }
255 
256  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
257 
258  wxString ShowGBRShape() const;
259 
266  bool HitTest( const wxPoint& aRefPos ) const override;
267 
275  bool HitTest( const EDA_RECT& aRefArea ) const;
276 
282  wxString GetClass() const override
283  {
284  return wxT( "GERBER_DRAW_ITEM" );
285  }
286 
291  void UnLink()
292  {
294  wxASSERT( list );
295 
296  if( list )
297  list->Remove( this );
298  }
299 
305  {
306  UnLink();
307  delete this;
308  }
309 #if defined(DEBUG)
310  void Show( int nestLevel, std::ostream& os ) const override;
311 #endif
312 
314  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
315 
317  virtual const BOX2I ViewBBox() const override;
318 
320  virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
321 
323  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
324 
325  virtual wxString GetSelectMenuText() const override;
326 
327 };
328 
329 
331 {
332 
333 };
334 
335 #endif /* CLASS_GERBER_DRAW_ITEM_H */
DHEAD * GetList() const
Definition: base_struct.h:236
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:192
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)
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
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...
void SetBack(EDA_ITEM *aBack)
virtual const BOX2I ViewBBox() const override
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)
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...
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
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
virtual wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:118
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
int GetLayer() const
Function GetLayer returns the layer this item is on.
wxString ShowGBRShape() const
bool GetLayerPolarity() const
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
Class SHAPE_POLY_SET.
GERBER_DRAW_ITEM * Next() const
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.
VECTOR2I GetABPosition(const VECTOR2I &aXYPosition) const
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 GBR_NETLIST_METADATA & GetNetAttributes() const
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.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:178
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
Class VIEW.
Definition: view.h:58
SEARCH_RESULT
Definition: base_struct.h:82
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:191
void UnLink()
Function UnLink detaches this object from its owner.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39