KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_shape.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, [email protected]
5 * Copyright The 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
25#ifndef SCH_SHAPE_H
26#define SCH_SHAPE_H
27
28#include <sch_item.h>
29#include <eda_shape.h>
30#include <schematic.h>
31
32
33class SCH_SHAPE : public SCH_ITEM, public EDA_SHAPE
34{
35public:
37 int aLineWidth = 0, FILL_T aFillType = FILL_T::NO_FILL,
38 KICAD_T aType = SCH_SHAPE_T );
39
40 // Do not create a copy constructor. The one generated by the compiler is adequate.
41
42 virtual ~SCH_SHAPE() override {}
43
44 wxString GetClass() const override
45 {
46 return wxT( "SCH_SHAPE" );
47 }
48
49 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
50 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
51 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
52
53 bool IsEndPoint( const VECTOR2I& aPoint ) const override;
54
55 int GetPenWidth() const override { return GetStroke().GetWidth(); }
56
57 bool HasLineStroke() const override { return true; }
58 STROKE_PARAMS GetStroke() const override { return m_stroke; }
59 void SetStroke( const STROKE_PARAMS& aStroke ) override;
60
61 int GetEffectiveWidth() const override;
62
64 {
65 if( m_stroke.GetLineStyle() == LINE_STYLE::DEFAULT )
66 return LINE_STYLE::SOLID;
67 else
68 return m_stroke.GetLineStyle();
69 }
70
71 int GetHatchLineWidth() const override
72 {
73 return GetEffectiveWidth() / 2;
74 }
75
76 int GetHatchLineSpacing() const override
77 {
78 return GetHatchLineWidth() * 40;
79 }
80
81 void SetFilled( bool aFilled ) override;
82
83 const BOX2I GetBoundingBox() const override;
84
85 VECTOR2I GetPosition() const override { return getPosition(); }
86 void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); }
87
88 VECTOR2I GetCenter() const { return getCenter(); }
89
90 void BeginEdit( const VECTOR2I& aStartPoint ) override { beginEdit( aStartPoint ); }
91 bool ContinueEdit( const VECTOR2I& aPosition ) override { return continueEdit( aPosition ); }
92 void CalcEdit( const VECTOR2I& aPosition ) override { calcEdit( aPosition ); }
93 void EndEdit( bool aClosed = false ) override { endEdit(); }
94 void SetEditState( int aState ) { setEditState( aState ); }
95
96 void Move( const VECTOR2I& aOffset ) override;
97
98 void Normalize();
99
100 void MirrorHorizontally( int aCenter ) override;
101 void MirrorVertically( int aCenter ) override;
102 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
103
104 void AddPoint( const VECTOR2I& aPosition );
105
112 std::vector<SHAPE*> MakeEffectiveShapes( bool aEdgeOnly = false ) const override
113 {
114 return makeEffectiveShapes( aEdgeOnly, true );
115 }
116
117 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
118 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
119
120 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
121
122 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
123
124 BITMAPS GetMenuImage() const override;
125
126 EDA_ITEM* Clone() const override;
127
128 std::vector<int> ViewGetLayers() const override;
129
130 double Similarity( const SCH_ITEM& aOther ) const override;
131
132 bool operator==( const SCH_ITEM& aOther ) const override;
133
134#if defined(DEBUG)
135 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
136#endif
137
138protected:
139 void swapData( SCH_ITEM* aItem ) override;
140
141 void setFilled( bool aFlag ) override
142 {
144 }
145
146 bool isMoving() const override { return IsMoving(); }
147
148 int getMaxError() const override
149 {
150 if( SCHEMATIC* schematic = Schematic() )
151 return schematic->Settings().m_MaxError;
152 else
153 return schIUScale.mmToIU( ARC_LOW_DEF_MM );
154 }
155
164 int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
165};
166
167
168#endif // SCH_SHAPE_H
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
constexpr double ARC_LOW_DEF_MM
Definition base_units.h:118
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
bool IsMoving() const
Definition eda_item.h:125
VECTOR2I getCenter() const
void calcEdit(const VECTOR2I &aPosition)
bool continueEdit(const VECTOR2I &aPosition)
std::vector< SHAPE * > makeEffectiveShapes(bool aEdgeOnly, bool aLineChainOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
EDA_SHAPE(SHAPE_T aType, int aLineWidth, FILL_T aFill)
Definition eda_shape.cpp:51
void beginEdit(const VECTOR2I &aStartPoint)
void endEdit(bool aClosed=true)
Finish editing the shape.
void setPosition(const VECTOR2I &aPos)
VECTOR2I getPosition() const
STROKE_PARAMS m_stroke
Definition eda_shape.h:493
void setEditState(int aState)
Definition eda_shape.h:471
FILL_T m_fill
Definition eda_shape.h:494
Base plotter engine class.
Definition plotter.h:121
Holds all the data relating to one schematic.
Definition schematic.h:88
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:217
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:51
void SetPosition(const VECTOR2I &aPos) override
Definition sch_shape.h:86
bool isMoving() const override
Definition sch_shape.h:146
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const override
Make a set of SHAPE objects representing the SCH_SHAPE.
Definition sch_shape.h:112
virtual ~SCH_SHAPE() override
Definition sch_shape.h:42
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition sch_shape.h:90
void SetFilled(bool aFilled) override
Definition sch_shape.cpp:67
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
Definition sch_shape.cpp:78
void SetEditState(int aState)
Definition sch_shape.h:94
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_shape.cpp:47
void setFilled(bool aFlag) override
Definition sch_shape.h:141
void EndEdit(bool aClosed=false) override
End an object editing action.
Definition sch_shape.h:93
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition sch_shape.cpp:61
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition sch_shape.cpp:53
LINE_STYLE GetEffectiveLineStyle() const
Definition sch_shape.h:63
VECTOR2I GetCenter() const
Definition sch_shape.h:88
bool ContinueEdit(const VECTOR2I &aPosition) override
Continue an edit in progress at aPosition.
Definition sch_shape.h:91
void Normalize()
Definition sch_shape.cpp:84
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
SCH_SHAPE(SHAPE_T aShape=SHAPE_T::UNDEFINED, SCH_LAYER_ID aLayer=LAYER_NOTES, int aLineWidth=0, FILL_T aFillType=FILL_T::NO_FILL, KICAD_T aType=SCH_SHAPE_T)
Definition sch_shape.cpp:38
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
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.
void AddPoint(const VECTOR2I &aPosition)
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition sch_shape.h:92
int GetHatchLineSpacing() const override
Definition sch_shape.h:76
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition sch_shape.h:57
bool operator==(const SCH_ITEM &aOther) const override
wxString GetClass() const override
Return the class name.
Definition sch_shape.h:44
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
int GetPenWidth() const override
Definition sch_shape.h:55
bool IsEndPoint(const VECTOR2I &aPoint) const override
Test if aPt is an end point of this schematic object.
int GetHatchLineWidth() const override
Definition sch_shape.h:71
STROKE_PARAMS GetStroke() const override
Definition sch_shape.h:58
VECTOR2I GetPosition() const override
Definition sch_shape.h:85
int GetEffectiveWidth() const override
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
int getMaxError() const override
Definition sch_shape.h:148
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Simple container to manage line stroke parameters.
int GetWidth() const
SHAPE_T
Definition eda_shape.h:43
@ UNDEFINED
Definition eda_shape.h:44
FILL_T
Definition eda_shape.h:56
@ FILLED_WITH_COLOR
Definition eda_shape.h:60
@ NO_FILL
Definition eda_shape.h:57
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:448
@ LAYER_NOTES
Definition layer_ids.h:466
LINE_STYLE
Dashed line types.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:78
@ SCH_SHAPE_T
Definition typeinfo.h:151
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695