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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef SCH_SHAPE_H
22#define SCH_SHAPE_H
23
24#include <sch_item.h>
25#include <eda_shape.h>
26#include <schematic.h>
27
28
29class SCH_SHAPE : public SCH_ITEM, public EDA_SHAPE
30{
31public:
33 int aLineWidth = 0, FILL_T aFillType = FILL_T::NO_FILL,
34 KICAD_T aType = SCH_SHAPE_T );
35
36 // Do not create a copy constructor. The one generated by the compiler is adequate.
37
38 virtual ~SCH_SHAPE() override {}
39
40 void Serialize( google::protobuf::Any& aContainer ) const override;
41 bool Deserialize( const google::protobuf::Any& aContainer ) override;
42
43 wxString GetClass() const override
44 {
45 return wxT( "SCH_SHAPE" );
46 }
47
48 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
49 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
50 bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
51
52 bool IsEndPoint( const VECTOR2I& aPoint ) const override;
53
54 int GetPenWidth() const override { return GetStroke().GetWidth(); }
55
56 bool HasLineStroke() const override { return true; }
57 STROKE_PARAMS GetStroke() const override { return m_stroke; }
58 void SetStroke( const STROKE_PARAMS& aStroke ) override;
59
60 int GetEffectiveWidth() const override;
61
63 {
64 if( m_stroke.GetLineStyle() == LINE_STYLE::DEFAULT )
65 return LINE_STYLE::SOLID;
66 else
67 return m_stroke.GetLineStyle();
68 }
69
70 int GetHatchLineWidth() const override
71 {
72 return GetEffectiveWidth() / 2;
73 }
74
75 int GetHatchLineSpacing() const override
76 {
77 return GetHatchLineWidth() * 40;
78 }
79
80 void SetFilled( bool aFilled ) override;
81
82 const BOX2I GetBoundingBox() const override;
83
84 VECTOR2I GetPosition() const override { return getPosition(); }
85 void SetPosition( const VECTOR2I& aPos ) override { setPosition( aPos ); }
86
87 int GetPositionX() const { return GetPosition().x; }
88 int GetPositionY() const { return GetPosition().y; }
89 void SetPositionX( int aX ) { SetPosition( VECTOR2I( aX, GetPosition().y ) ); }
90 void SetPositionY( int aY ) { SetPosition( VECTOR2I( GetPosition().x, aY ) ); }
91
92 VECTOR2I GetCenter() const { return getCenter(); }
93
94 void BeginEdit( const VECTOR2I& aStartPoint ) override { beginEdit( aStartPoint ); }
95 bool ContinueEdit( const VECTOR2I& aPosition ) override { return continueEdit( aPosition ); }
96 void CalcEdit( const VECTOR2I& aPosition ) override { calcEdit( aPosition ); }
97 void EndEdit( bool aClosed = false ) override { endEdit(); }
98 void SetEditState( int aState ) { setEditState( aState ); }
99
100 void Move( const VECTOR2I& aOffset ) override;
101
102 void Normalize();
103
104 void MirrorHorizontally( int aCenter ) override;
105 void MirrorVertically( int aCenter ) override;
106 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
107
108 void AddPoint( const VECTOR2I& aPosition );
109
116 std::vector<SHAPE*> MakeEffectiveShapes( bool aEdgeOnly = false ) const override
117 {
118 return makeEffectiveShapes( aEdgeOnly, true );
119 }
120
121 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
122 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
123
124 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
125
126 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
127
128 BITMAPS GetMenuImage() const override;
129
130 EDA_ITEM* Clone() const override;
131
132 std::vector<int> ViewGetLayers() const override;
133
134 double Similarity( const SCH_ITEM& aOther ) const override;
135
136 bool operator==( const SCH_ITEM& aOther ) const override;
137
138#if defined(DEBUG)
139 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
140#endif
141
142protected:
143 void swapData( SCH_ITEM* aItem ) override;
144
145 void setFilled( bool aFlag ) override
146 {
148 }
149
150 bool isMoving() const override { return IsMoving(); }
151
152 int getMaxError() const override { return GetMaxError(); }
153
162 int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
163};
164
165
166#endif // SCH_SHAPE_H
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
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:96
bool IsMoving() const
Definition eda_item.h:130
VECTOR2I getCenter() const
std::vector< SHAPE * > makeEffectiveShapes(bool aEdgeOnly, bool aLineChainOnly=false, bool aHittesting=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
void calcEdit(const VECTOR2I &aPosition)
bool continueEdit(const VECTOR2I &aPosition)
EDA_SHAPE(SHAPE_T aType, int aLineWidth, FILL_T aFill)
Definition eda_shape.cpp:53
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:593
void setEditState(int aState)
Definition eda_shape.h:560
FILL_T m_fill
Definition eda_shape.h:594
Base plotter engine class.
Definition plotter.h:133
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
int GetMaxError() const
Definition sch_item.cpp:759
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:52
void SetPosition(const VECTOR2I &aPos) override
Definition sch_shape.h:85
bool isMoving() const override
Definition sch_shape.h:150
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
void SetPositionX(int aX)
Definition sch_shape.h:89
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition sch_shape.cpp:72
std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const override
Make a set of SHAPE objects representing the SCH_SHAPE.
Definition sch_shape.h:116
virtual ~SCH_SHAPE() override
Definition sch_shape.h:38
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition sch_shape.h:94
void SetFilled(bool aFilled) override
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
void SetEditState(int aState)
Definition sch_shape.h:98
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_shape.cpp:49
void setFilled(bool aFlag) override
Definition sch_shape.h:145
void EndEdit(bool aClosed=false) override
End an object editing action.
Definition sch_shape.h:97
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition sch_shape.cpp:98
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition sch_shape.cpp:90
LINE_STYLE GetEffectiveLineStyle() const
Definition sch_shape.h:62
VECTOR2I GetCenter() const
Definition sch_shape.h:92
bool ContinueEdit(const VECTOR2I &aPosition) override
Continue an edit in progress at aPosition.
Definition sch_shape.h:95
void Normalize()
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:40
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:96
int GetHatchLineSpacing() const override
Definition sch_shape.h:75
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:56
bool operator==(const SCH_ITEM &aOther) const override
wxString GetClass() const override
Return the class name.
Definition sch_shape.h:43
void SetPositionY(int aY)
Definition sch_shape.h:90
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:54
bool IsEndPoint(const VECTOR2I &aPoint) const override
Test if aPt is an end point of this schematic object.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_shape.cpp:55
int GetHatchLineWidth() const override
Definition sch_shape.h:70
STROKE_PARAMS GetStroke() const override
Definition sch_shape.h:57
int GetPositionX() const
Definition sch_shape.h:87
VECTOR2I GetPosition() const override
Definition sch_shape.h:84
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 GetPositionY() const
Definition sch_shape.h:88
int getMaxError() const override
Definition sch_shape.h:152
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:44
@ UNDEFINED
Definition eda_shape.h:45
FILL_T
Definition eda_shape.h:59
@ FILLED_WITH_COLOR
Definition eda_shape.h:63
@ NO_FILL
Definition eda_shape.h:60
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:447
@ LAYER_NOTES
Definition layer_ids.h:465
LINE_STYLE
Dashed line types.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ SCH_SHAPE_T
Definition typeinfo.h:146
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683