KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_no_connect.cpp
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) 2015 Jean-Pierre Charras, jp.charras at wanoadoo.fr
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
25
26#include <sch_draw_panel.h>
27#include <plotters/plotter.h>
28#include <bitmaps.h>
29#include <schematic.h>
31#include <sch_no_connect.h>
33#include <default_values.h> // For some default values
34#include <core/mirror.h>
35#include <trigo.h>
36#include <gr_basic.h>
37#include <api/api_utils.h>
38#include <api/schematic/schematic_types.pb.h>
39
40
42 SCH_ITEM( nullptr, SCH_NO_CONNECT_T )
43{
44 m_pos = pos;
45 m_size = schIUScale.MilsToIU( DEFAULT_NOCONNECT_SIZE ); // Default no-connect symbol size.
46
48}
49
50
52{
53 return new SCH_NO_CONNECT( *this );
54}
55
56
57void SCH_NO_CONNECT::Serialize( google::protobuf::Any& aContainer ) const
58{
59 using namespace kiapi::common;
60
61 kiapi::schematic::types::NoConnectMarker marker;
62
63 marker.mutable_id()->set_value( m_Uuid.AsStdString() );
64 PackVector2( *marker.mutable_position(), m_pos, schIUScale );
65 PackDistance( *marker.mutable_size(), m_size, schIUScale );
66 marker.set_locked( IsLocked() ? types::LockedState::LS_LOCKED
67 : types::LockedState::LS_UNLOCKED );
68
69 kiapi::common::PackCustomProperties( marker.mutable_custom_properties(), *this );
70 aContainer.PackFrom( marker );
71}
72
73
74bool SCH_NO_CONNECT::Deserialize( const google::protobuf::Any& aContainer )
75{
76 using namespace kiapi::common;
77
78 kiapi::schematic::types::NoConnectMarker marker;
79
80 if( !aContainer.UnpackTo( &marker ) )
81 return false;
82
83 const_cast<KIID&>( m_Uuid ) = KIID( marker.id().value() );
84 m_pos = UnpackVector2( marker.position(), schIUScale );
85 m_size = UnpackDistance( marker.size(), schIUScale );
86 SetLocked( marker.locked() == types::LockedState::LS_LOCKED );
87 kiapi::common::UnpackCustomProperties( marker.custom_properties(), *this );
88 return true;
89}
90
91
93{
94 wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_NO_CONNECT_T ),
95 wxT( "Cannot swap no connect data with invalid item." ) );
96
97 SCH_NO_CONNECT* item = (SCH_NO_CONNECT*)aItem;
98 std::swap( m_pos, item->m_pos );
99 std::swap( m_size, item->m_size );
100}
101
102
104{
105 int delta = ( GetPenWidth() + GetSize() ) / 2;
106 BOX2I bbox( m_pos );
107
108 bbox.Inflate( delta );
109
110 return bbox;
111}
112
113
114std::vector<int> SCH_NO_CONNECT::ViewGetLayers() const
115{
117}
118
119
120void SCH_NO_CONNECT::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
121{
123 aItemList.push_back( item );
124}
125
126
128{
129 if( !Schematic() )
130 return 1;
131
132 return std::max( Schematic()->Settings().m_DefaultLineWidth, 1 );
133}
134
135
137{
138 MIRROR( m_pos.y, aCenter );
139}
140
141
143{
144 MIRROR( m_pos.x, aCenter );
145}
146
147
148void SCH_NO_CONNECT::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
149{
150 RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
151}
152
153
155 const SCH_SHEET_PATH* aInstance ) const
156{
157 // Do not compare to ourself.
158 if( aItem == this )
159 return false;
160
161 const SCH_NO_CONNECT* noConnect = dynamic_cast<const SCH_NO_CONNECT*>( aItem );
162
163 // Don't compare against a different SCH_ITEM.
164 wxCHECK( noConnect, false );
165
166 return GetPosition() != noConnect->GetPosition();
167}
168
169
170std::vector<VECTOR2I> SCH_NO_CONNECT::GetConnectionPoints() const
171{
172 return { m_pos };
173}
174
175
176bool SCH_NO_CONNECT::doIsConnected( const VECTOR2I& aPosition ) const
177{
178 return m_pos == aPosition;
179}
180
181
182bool SCH_NO_CONNECT::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
183{
184 int delta = ( GetPenWidth() + GetSize() ) / 2 + aAccuracy;
185
186 VECTOR2I dist = aPosition - m_pos;
187
188 if( ( std::abs( dist.x ) <= delta ) && ( std::abs( dist.y ) <= delta ) )
189 return true;
190
191 return false;
192}
193
194
195bool SCH_NO_CONNECT::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
196{
197 BOX2I rect = aRect;
198
199 rect.Inflate( aAccuracy );
200
201 if( aContained )
202 return rect.Contains( GetBoundingBox() );
203
204 return rect.Intersects( GetBoundingBox() );
205}
206
207
208bool SCH_NO_CONNECT::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
209{
210 return KIGEOM::BoxHitTest( aPoly, GetBoundingBox(), aContained );
211}
212
213
214void SCH_NO_CONNECT::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
215 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
216{
217 if( aBackground )
218 return;
219
220 int delta = GetSize() / 2;
221 int pX = m_pos.x;
222 int pY = m_pos.y;
223 int penWidth = GetEffectivePenWidth( getRenderSettings( aPlotter ) );
224
225 COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( LAYER_NOCONNECT );
226
227 if( color.m_text && Schematic() )
228 color = COLOR4D( ResolveText( *color.m_text, &Schematic()->CurrentSheet() ) );
229
230 aPlotter->SetCurrentLineWidth( penWidth );
231 aPlotter->SetColor( color );
232 aPlotter->MoveTo( VECTOR2I( pX - delta, pY - delta ) );
233 aPlotter->FinishTo( VECTOR2I( pX + delta, pY + delta ) );
234 aPlotter->MoveTo( VECTOR2I( pX + delta, pY - delta ) );
235 aPlotter->FinishTo( VECTOR2I( pX - delta, pY + delta ) );
236}
237
238
243
244
245bool SCH_NO_CONNECT::operator==( const SCH_ITEM& aOther ) const
246{
247 if( aOther.Type() != Type() )
248 return false;
249
250 const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
251
252 if( m_pos != other->m_pos )
253 return false;
254
255 return true;
256}
257
258
259double SCH_NO_CONNECT::Similarity( const SCH_ITEM& aOther ) const
260{
261 if( m_Uuid == aOther.m_Uuid )
262 return 1.0;
263
264 if( aOther.Type() != Type() )
265 return 0.0;
266
267 const SCH_NO_CONNECT* other = static_cast<const SCH_NO_CONNECT*>( &aOther );
268
269 if( m_pos != other->m_pos )
270 return 0.0;
271
272 return 1.0;
273}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:553
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:165
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:308
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition sch_item.h:96
const KIID m_Uuid
Definition eda_item.h:597
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
std::shared_ptr< wxString > m_text
Definition color4d.h:396
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
Definition kiid.h:46
Base plotter engine class.
Definition plotter.h:136
void MoveTo(const VECTOR2I &pos)
Definition plotter.h:308
void FinishTo(const VECTOR2I &pos)
Definition plotter.h:318
RENDER_SETTINGS * RenderSettings()
Definition plotter.h:167
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
virtual void SetColor(const COLOR4D &color)=0
void SetLocked(bool aLocked) override
Definition sch_item.h:256
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.h:739
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:281
bool IsLocked() const override
Definition sch_item.cpp:158
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:346
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:52
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:390
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:824
bool operator==(const SCH_ITEM &aOther) const override
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
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_NO_CONNECT(const VECTOR2I &pos=VECTOR2I(0, 0))
int m_size
Size of the no connect object.
int GetSize() const
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
VECTOR2I m_pos
Position of the no connect object.
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
VECTOR2I GetPosition() const override
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
int GetPenWidth() const override
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
#define DEFAULT_NOCONNECT_SIZE
The default junction diameter in mils. (can be changed in preference menu)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:424
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:427
a few functions useful in geometry calculations.
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:517
@ LAYER_NOCONNECT
Definition layer_ids.h:498
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:41
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:411
@ NO_CONNECT_END
Definition sch_item.h:87
int delta
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:225
@ SCH_NO_CONNECT_T
Definition typeinfo.h:156
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683