KiCad PCB EDA Suite
class_dimension.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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2017 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 
30 #ifndef DIMENSION_H_
31 #define DIMENSION_H_
32 
33 
34 #include <class_board_item.h>
35 #include <class_pcb_text.h>
36 
37 
38 class LINE_READER;
39 class TEXTE_PCB;
40 class MSG_PANEL_ITEM;
41 
42 
61 class DIMENSION : public BOARD_ITEM
62 {
63  int m_Width;
64  int m_Shape;
66  bool m_UseMils;
67  int m_Value;
68  int m_Height;
70 
71 public:
72 // TODO private: These member should be private. they are public only due to legacy code
78 
79  DIMENSION( BOARD_ITEM* aParent );
80 
81  // Do not create a copy constructor & operator=.
82  // The ones generated by the compiler are adequate.
83 
84  ~DIMENSION();
85 
86  static inline bool ClassOf( const EDA_ITEM* aItem )
87  {
88  return aItem && PCB_DIMENSION_T == aItem->Type();
89  }
90 
91  bool IsType( const KICAD_T aScanTypes[] ) const override
92  {
93  if( BOARD_ITEM::IsType( aScanTypes ) )
94  return true;
95 
96  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
97  {
98  if( *p == PCB_LOCATE_GRAPHIC_T )
99  return true;
100  }
101 
102  return false;
103  }
104 
105  void SetValue( int aValue ) { m_Value = aValue; }
106 
107  int GetValue() const { return m_Value; }
108 
109  wxPoint GetPosition() const override;
110 
111  void SetPosition( const wxPoint& aPos ) override;
112 
113  void SetTextSize( const wxSize& aTextSize )
114  {
115  m_Text.SetTextSize( aTextSize );
116  }
117 
118  void SetLayer( PCB_LAYER_ID aLayer ) override;
119 
120  void SetShape( int aShape ) { m_Shape = aShape; }
121  int GetShape() const { return m_Shape; }
122 
123  int GetWidth() const { return m_Width; }
124  void SetWidth( int aWidth ) { m_Width = aWidth; }
125 
132  void SetOrigin( const wxPoint& aOrigin, int aPrecision );
133 
138  const wxPoint& GetOrigin() const
139  {
140  return m_featureLineGO;
141  }
142 
149  void SetEnd( const wxPoint& aEnd, int aPrecision );
150 
155  const wxPoint& GetEnd()
156  {
157  return m_featureLineDO;
158  }
159 
166  void SetHeight( int aHeight, int aPrecision );
167 
172  int GetHeight() const
173  {
174  return m_Height;
175  }
176 
181  void UpdateHeight();
182 
188  double GetAngle() const
189  {
191 
192  return atan2( (double)delta.y, (double)delta.x );
193  }
194 
200  void AdjustDimensionDetails( int aPrecision );
201 
202  void GetUnits( EDA_UNITS& aUnits, bool& aUseMils ) const
203  {
204  aUnits = m_Unit;
205  aUseMils = m_UseMils;
206  }
207 
208  void SetUnits( EDA_UNITS aUnits, bool aUseMils )
209  {
210  m_Unit = aUnits;
211  m_UseMils = aUseMils;
212  }
213 
214  void SetText( const wxString& NewText );
215  const wxString GetText() const;
216 
217  TEXTE_PCB& Text() { return m_Text; }
218  TEXTE_PCB& Text() const { return *(const_cast<TEXTE_PCB*> (&m_Text)); }
219 
224  void Move( const wxPoint& offset ) override;
225  void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
226  void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
227 
235  void Mirror( const wxPoint& axis_pos, bool aMirrorLeftRight = false );
236 
237  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
238 
239  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
240  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
241 
242  wxString GetClass() const override
243  {
244  return wxT( "DIMENSION" );
245  }
246 
247  // Virtual function
248  const EDA_RECT GetBoundingBox() const override;
249 
250  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
251 
252  BITMAP_DEF GetMenuImage() const override;
253 
254  EDA_ITEM* Clone() const override;
255 
256  virtual const BOX2I ViewBBox() const override;
257 
258  virtual void SwapData( BOARD_ITEM* aImage ) override;
259 
260 #if defined(DEBUG)
261  virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
262 #endif
263 };
264 
265 #endif // DIMENSION_H_
EDA_UNITS
Definition: common.h:198
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
void SetPosition(const wxPoint &aPos) override
int GetWidth() const
PNG memory record (file in memory).
Definition: bitmap_def.h:29
TEXTE_PCB class definition.
void SetText(const wxString &NewText)
wxPoint m_crossBarF
int m_Height
length of feature lines
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
wxPoint m_arrowD1F
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
DIMENSION(BOARD_ITEM *aParent)
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
TEXTE_PCB m_Text
void SetHeight(int aHeight, int aPrecision)
Function SetHeight Sets the length of feature lines.
int m_Shape
Currently always 0.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
wxPoint m_featureLineDF
void Mirror(const wxPoint &axis_pos, bool aMirrorLeftRight=false)
Function Mirror Mirror the Dimension , relative to a given horizontal axis the text is not mirrored.
void SetUnits(EDA_UNITS aUnits, bool aUseMils)
The base class for create windows for drawing purpose.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
wxPoint m_featureLineGO
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
PCB_LAYER_ID
A quick note on layer IDs:
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
void SetValue(int aValue)
bool m_UseMils
If inches, use mils.
void SetOrigin(const wxPoint &aOrigin, int aPrecision)
Function SetOrigin Sets a new origin of the crossbar line.
const wxPoint & GetEnd()
Function GetEnd.
void SetEnd(const wxPoint &aEnd, int aPrecision)
Function SetEnd Sets a new end of the crossbar line.
void SetTextSize(const wxSize &aTextSize)
int GetValue() const
void SetShape(int aShape)
wxPoint m_arrowG1F
wxPoint m_arrowD2F
wxPoint m_arrowG2F
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
wxString GetClass() const override
Function GetClass returns the class name.
wxPoint GetPosition() const override
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:262
const wxPoint & GetOrigin() const
Function GetOrigin.
int GetShape() const
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
int m_Width
Line width.
void AdjustDimensionDetails(int aPrecision)
Function AdjustDimensionDetails Calculate coordinates of segments used to draw the dimension.
TEXTE_PCB & Text() const
double GetAngle() const
Function GetAngle Returns angle of the crossbar.
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
void Move(const wxPoint &offset) override
Function Move.
TEXTE_PCB & Text()
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
bool IsType(const KICAD_T aScanTypes[]) const override
Function IsType Checks whether the item is one of the listed types.
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
void GetUnits(EDA_UNITS &aUnits, bool &aUseMils) const
static bool ClassOf(const EDA_ITEM *aItem)
wxPoint m_crossBarO
const wxString GetText() const
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
void SetWidth(int aWidth)
void UpdateHeight()
Function UpdateHeight Updates stored height basing on points coordinates.
int GetHeight() const
Function GetHeight Returns the length of feature lines.
wxPoint m_featureLineDO
int m_Value
value of PCB dimensions.
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
DIMENSION.
EDA_UNITS m_Unit
0 = inches, 1 = mm
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
wxPoint m_featureLineGF