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>
34 #include <gr_basic.h>
35 #include <gbr_netlist_metadata.h>
36 #include <dcode.h>
38 
39 class GERBER_FILE_IMAGE;
40 class GBR_LAYOUT;
41 class D_CODE;
42 class MSG_PANEL_ITEM;
44 class PCB_BASE_FRAME;
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 
74 
75 public:
76  bool m_UnitsMetric; // store here the gerber units (inch/mm). Used
77  // only to calculate aperture macros shapes sizes
78  int m_Shape; // Shape and type of this gerber item
79  wxPoint m_Start; // Line or arc start point or position of the shape
80  // for flashed items
81  wxPoint m_End; // Line or arc end point
82  wxPoint m_ArcCentre; // for arcs only: Centre of arc
83  SHAPE_POLY_SET m_Polygon; // Polygon shape data (G36 to G37 coordinates)
84  // or for complex shapes which are converted to polygon
85  wxSize m_Size; // Flashed shapes: size of the shape
86  // Lines : m_Size.x = m_Size.y = line width
87  bool m_Flashed; // True for flashed items
88  int m_DCode; // DCode used to draw this item.
89  // Allowed values are >= 10. 0 when unknown
90  // values 0 to 9 can be used for special purposes
91  // Regions (polygons) doo not use DCode,
92  // so it is set to 0
93  wxString m_AperFunction; // the aperture function set by a %TA.AperFunction, xxx
94  // (stores thre xxx value).
95  // used for regions that do not have a attached DCode, but
96  // have a TA.AperFunction defined
97  GERBER_FILE_IMAGE* m_GerberImageFile; /* Gerber file image source of this item
98  * Note: some params stored in this class are common
99  * to the whole gerber file (i.e) the whole graphic
100  * layer and some can change when reading the file,
101  * so they are stored inside this item if there is no
102  * redundancy for these parameters
103  */
104 
105 private:
106  // These values are used to draw this item, according to gerber layers parameters
107  // Because they can change inside a gerber image, they are stored here
108  // for each item
109  bool m_LayerNegative; // true = item in negative Layer
110  bool m_swapAxis; // false if A = X, B = Y; true if A =Y, B = Y
111  bool m_mirrorA; // true: mirror / axe A
112  bool m_mirrorB; // true: mirror / axe B
113  wxRealPoint m_drawScale; // A and B scaling factor
114  wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
115  double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
117 
120 public:
121  GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberparams );
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  void Print( wxDC* aDC, const wxPoint& aOffset, GBR_DISPLAY_OPTIONS* aOptions );
235 
243 
248  void PrintGerberPoly( wxDC* aDC, COLOR4D aColor, const wxPoint& aOffset, bool aFilledShape );
249 
250  /* divers */
251  int Shape() const { return m_Shape; }
252 
253  void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
254 
255  wxString ShowGBRShape() const;
256 
263  bool HitTest( const wxPoint& aRefPos, int aAccuracy = 0 ) const override;
264 
272  bool HitTest( const EDA_RECT& aRefArea, bool aContained, int aAccuracy = 0 ) const override;
273 
279  wxString GetClass() const override
280  {
281  return wxT( "GERBER_DRAW_ITEM" );
282  }
283 
284 #if defined(DEBUG)
285  void Show( int nestLevel, std::ostream& os ) const override;
286 #endif
287 
289  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
290 
292  virtual const BOX2I ViewBBox() const override;
293 
295  virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
296 
298  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
299 
301  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
302 
304  BITMAP_DEF GetMenuImage() const override;
305 };
306 
307 
309 {
310 
311 };
312 
313 #endif /* GERBER_DRAW_ITEM_H */
EDA_UNITS
Definition: common.h:72
void SetLayerParameters()
Function SetLayerParameters Initialize parameters from Image and Layer parameters found in the gerber...
GBR_LAYOUT holds list of GERBER_DRAW_ITEM currently loaded.
Definition: gbr_layout.h:48
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.
PNG memory record (file in memory).
Definition: bitmap_def.h:29
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: color4d.cpp:131
Gbr_Basic_Shapes
void SetPosition(const wxPoint &aPos)
bool HasNegativeItems()
Function HasNegativeItems.
VECTOR2I GetABPosition(const VECTOR2I &aXYPosition) const
virtual const BOX2I ViewBBox() const override
int GetLayer() const
Function GetLayer returns the layer this item is on.
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
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...
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
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
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.
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 aUnits) const override
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.
D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
void GetMsgPanelInfo(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
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.
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
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
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
wxString ShowGBRShape() const
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxRealPoint m_drawScale