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-2021 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 <eda_item.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 class GERBER_DRAW_ITEM : public EDA_ITEM
67 {
68 public:
69  GERBER_DRAW_ITEM( GERBER_FILE_IMAGE* aGerberparams );
71 
72  void SetNetAttributes( const GBR_NETLIST_METADATA& aNetAttributes );
74 
78  int GetLayer() const;
79 
80  bool GetLayerPolarity() const
81  {
82  return m_LayerNegative;
83  }
84 
93  bool GetTextD_CodePrms( int& aSize, wxPoint& aPos, double& aOrientation );
94 
99  bool GetTextD_CodePrms( double& aSize, VECTOR2D& aPos, double& aOrientation );
100 
107  bool HasNegativeItems();
108 
115  void SetLayerParameters();
116 
117  void SetLayerPolarity( bool aNegative)
118  {
119  m_LayerNegative = aNegative;
120  }
121 
127  void MoveAB( const wxPoint& aMoveVector );
128 
134  void MoveXY( const wxPoint& aMoveVector );
135 
143  wxPoint GetPosition() const override { return m_Start; }
144  void SetPosition( const wxPoint& aPos ) override { m_Start = aPos; }
145 
155  wxPoint GetABPosition( const wxPoint& aXYPosition ) const;
156 
157  VECTOR2I GetABPosition( const VECTOR2I& aXYPosition ) const
158  {
159  return VECTOR2I( GetABPosition( wxPoint( aXYPosition.x, aXYPosition.y ) ) );
160  }
161 
171  wxPoint GetXYPosition( const wxPoint& aABPosition ) const;
172 
178  D_CODE* GetDcodeDescr() const;
179 
180  const EDA_RECT GetBoundingBox() const override;
181 
182  void Print( wxDC* aDC, const wxPoint& aOffset, GBR_DISPLAY_OPTIONS* aOptions );
183 
191 
195  void PrintGerberPoly( wxDC* aDC, COLOR4D aColor, const wxPoint& aOffset, bool aFilledShape );
196 
197  int Shape() const { return m_Shape; }
198 
199  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
200 
201  wxString ShowGBRShape() const;
202 
209  bool HitTest( const wxPoint& aRefPos, int aAccuracy = 0 ) const override;
210 
219  bool HitTest( const EDA_RECT& aRefArea, bool aContained, int aAccuracy = 0 ) const override;
220 
224  wxString GetClass() const override
225  {
226  return wxT( "GERBER_DRAW_ITEM" );
227  }
228 
229 #if defined(DEBUG)
230  void Show( int nestLevel, std::ostream& os ) const override;
231 #endif
232 
234  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
235 
237  virtual const BOX2I ViewBBox() const override;
238 
240  double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
241 
243  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
244 
246  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
247 
249  BITMAPS GetMenuImage() const override;
250 
251  bool m_UnitsMetric; // store here the gerber units (inch/mm). Used
252  // only to calculate aperture macros shapes sizes
253  int m_Shape; // Shape and type of this gerber item
254  wxPoint m_Start; // Line or arc start point or position of the shape
255  // for flashed items
256  wxPoint m_End; // Line or arc end point
257  wxPoint m_ArcCentre; // for arcs only: Center of arc
258  SHAPE_POLY_SET m_Polygon; // Polygon shape data (G36 to G37 coordinates)
259  // or for complex shapes which are converted to polygon
260  wxSize m_Size; // Flashed shapes: size of the shape
261  // Lines : m_Size.x = m_Size.y = line width
262  bool m_Flashed; // True for flashed items
263  int m_DCode; // DCode used to draw this item.
264  // Allowed values are >= 10. 0 when unknown
265  // values 0 to 9 can be used for special purposes
266  // Regions (polygons) do not use DCode,
267  // so it is set to 0
268  wxString m_AperFunction; // the aperture function set by a %TA.AperFunction, xxx
269  // (stores the xxx value). Used for regions that do
270  // not have a attached DCode, but
271  // have a TA.AperFunction defined
272  GERBER_FILE_IMAGE* m_GerberImageFile; /* Gerber file image source of this item
273  * Note: some params stored in this class are common
274  * to the whole gerber file (i.e) the whole graphic
275  * layer and some can change when reading the file,
276  * so they are stored inside this item if there is no
277  * redundancy for these parameters
278  */
279 
280 private:
281  // These values are used to draw this item, according to gerber layers parameters
282  // Because they can change inside a gerber image, they are stored here
283  // for each item
284  bool m_LayerNegative; // true = item in negative Layer
285  bool m_swapAxis; // false if A = X, B = Y; true if A =Y, B = Y
286  bool m_mirrorA; // true: mirror / axis A
287  bool m_mirrorB; // true: mirror / ax's B
288  wxRealPoint m_drawScale; // A and B scaling factor
289  wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
290  double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
292 };
295 
296 
298 {
299 
300 };
301 
302 #endif /* GERBER_DRAW_ITEM_H */
void SetLayerParameters()
Initialize parameters from Image and Layer parameters found in the gerber file: m_UnitsMetric,...
A list of GERBER_DRAW_ITEM objects currently loaded.
Definition: gbr_layout.h:45
D_CODE * GetDcodeDescr() const
Return the GetDcodeDescr of this object, or NULL.
wxString GetClass() const override
void MoveAB(const wxPoint &aMoveVector)
Move this object.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:194
Gbr_Basic_Shapes
bool HasNegativeItems()
Optimize screen refresh (when no items are in background color refresh can be faster).
VECTOR2I GetABPosition(const VECTOR2I &aXYPosition) const
virtual const BOX2I ViewBBox() const override
int GetLayer() const
Return the layer this item is on.
Hold 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
Return the orthogonal bounding box of this object for display purposes.
bool HitTest(const wxPoint &aRefPos, int aAccuracy=0) const override
Test if the given wxPoint is within the bounds of this object.
void SetNetAttributes(const GBR_NETLIST_METADATA &aNetAttributes)
Information which can be added in a gerber file as attribute of an object.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
The base class for create windows for drawing purpose.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
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
Return the text to display to be used in the selection clarification context menu when multiple items...
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:94
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
wxPoint GetABPosition(const wxPoint &aXYPosition) const
Return the image position of aPosition for this object.
Represent a set of closed polygons.
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)
Return the best size and orientation to display the D_Code on screen.
const GBR_NETLIST_METADATA & GetNetAttributes() const
void SetPosition(const wxPoint &aPos) override
void ConvertSegmentToPolygon()
Convert a line to an equivalent polygon.
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return a pointer to an image to be used in menus.
EDA_UNITS
Definition: eda_units.h:38
void PrintGerberPoly(wxDC *aDC, COLOR4D aColor, const wxPoint &aOffset, bool aFilledShape)
Print the polygon stored in m_PolyCorners.
Board layer functions and definitions.
A gerber DCODE (also called Aperture) definition.
Definition: dcode.h:80
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
wxPoint GetPosition() const override
Return the position of this object.
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
void SetLayerPolarity(bool aNegative)
wxPoint GetXYPosition(const wxPoint &aABPosition) const
Return the image position of aPosition for this object.
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
void MoveXY(const wxPoint &aMoveVector)
Move this object.
SEARCH_RESULT
Definition: eda_item.h:41
bool GetLayerPolarity() const
GERBER_FILE_IMAGE * m_GerberImageFile
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
wxString ShowGBRShape() const
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
wxRealPoint m_drawScale