KiCad PCB EDA Suite
sch_sheet_pin.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) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2019 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 #include <fctsys.h>
26 #include <gr_basic.h>
27 #include <sch_draw_panel.h>
28 #include <gr_text.h>
29 #include <plotter.h>
30 #include <trigo.h>
31 #include <sch_edit_frame.h>
32 #include <bitmaps.h>
33 #include <general.h>
34 #include <sch_sheet.h>
35 #include <kicad_string.h>
36 
37 
38 SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxString& text ) :
39  SCH_HIERLABEL( pos, text, SCH_SHEET_PIN_T ),
40  m_edge( SHEET_UNDEFINED_SIDE )
41 {
42  SetParent( parent );
43  wxASSERT( parent );
45 
46  SetTextPos( pos );
47 
48  if( parent->IsVerticalOrientation() )
50  else
52 
54  m_isDangling = true;
55  m_number = 2;
56 }
57 
58 
60 {
61  return new SCH_SHEET_PIN( *this );
62 }
63 
64 
65 void SCH_SHEET_PIN::Print( wxDC* aDC, const wxPoint& aOffset )
66 {
67  // The icon selection is handle by the virtual method CreateGraphicShape called by ::Print
68  SCH_HIERLABEL::Print( aDC, aOffset );
69 }
70 
71 
73 {
74  wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T,
75  wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ),
76  GetChars( aItem->GetClass() ) ) );
77 
78  SCH_SHEET_PIN* pin = ( SCH_SHEET_PIN* ) aItem;
79  SCH_TEXT::SwapData( (SCH_TEXT*) pin );
80  int tmp = pin->GetNumber();
81  pin->SetNumber( GetNumber() );
82  SetNumber( tmp );
83  SHEET_SIDE stmp = pin->GetEdge();
84  pin->SetEdge( GetEdge() );
85  SetEdge( stmp );
86 }
87 
88 
89 bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
90 {
91  return aPin == this;
92 }
93 
94 
96 {
97  return GetDefaultLineThickness();
98 }
99 
100 
101 void SCH_SHEET_PIN::SetNumber( int aNumber )
102 {
103  wxASSERT( aNumber >= 2 );
104 
105  m_number = aNumber;
106 }
107 
108 
110 {
111  SCH_SHEET* Sheet = GetParent();
112 
113  // use SHEET_UNDEFINED_SIDE to adjust text orientation without changing edge
114 
115  switch( aEdge )
116  {
117  case SHEET_LEFT_SIDE:
118  m_edge = aEdge;
119  SetTextX( Sheet->m_pos.x );
120  SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT ); // Orientation horiz inverse
121  break;
122 
123  case SHEET_RIGHT_SIDE:
124  m_edge = aEdge;
125  SetTextX( Sheet->m_pos.x + Sheet->m_size.x );
126  SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT ); // Orientation horiz normal
127  break;
128 
129  case SHEET_TOP_SIDE:
130  m_edge = aEdge;
131  SetTextY( Sheet->m_pos.y );
132  SetLabelSpinStyle( LABEL_SPIN_STYLE::BOTTOM ); // Orientation vert BOTTOM
133  break;
134 
135  case SHEET_BOTTOM_SIDE:
136  m_edge = aEdge;
137  SetTextY( Sheet->m_pos.y + Sheet->m_size.y );
138  SetLabelSpinStyle( LABEL_SPIN_STYLE::UP ); // Orientation vert UP
139  break;
140 
141  default:
142  break;
143  }
144 }
145 
146 
148 {
149  return m_edge;
150 }
151 
152 
154 {
155  SCH_SHEET* sheet = GetParent();
156 
157  if( sheet == NULL )
158  return;
159 
160  wxPoint center = sheet->m_pos + ( sheet->m_size / 2 );
161 
163  {
164  if( Pos.x > center.x )
166  else
168 
169  SetTextY( Pos.y );
170 
171  if( GetTextPos().y < sheet->m_pos.y )
172  SetTextY( sheet->m_pos.y );
173 
174  if( GetTextPos().y > (sheet->m_pos.y + sheet->m_size.y) )
175  SetTextY( sheet->m_pos.y + sheet->m_size.y );
176  }
177  else
178  {
179  if( Pos.y > center.y )
181  else
183 
184  SetTextX( Pos.x );
185 
186  if( GetTextPos().x < sheet->m_pos.x )
187  SetTextX( sheet->m_pos.x );
188 
189  if( GetTextPos().x > (sheet->m_pos.x + sheet->m_size.x) )
190  SetTextX( sheet->m_pos.x + sheet->m_size.x );
191  }
192 }
193 
194 
195 void SCH_SHEET_PIN::MirrorX( int aXaxis_position )
196 {
197  int p = GetTextPos().y - aXaxis_position;
198 
199  SetTextY( aXaxis_position - p );
200 
201  switch( m_edge )
202  {
203  case SHEET_TOP_SIDE: SetEdge( SHEET_BOTTOM_SIDE ); break;
204  case SHEET_BOTTOM_SIDE: SetEdge( SHEET_TOP_SIDE ); break;
205  default: break;
206  }
207 }
208 
209 
210 void SCH_SHEET_PIN::MirrorY( int aYaxis_position )
211 {
212  int p = GetTextPos().x - aYaxis_position;
213 
214  SetTextX( aYaxis_position - p );
215 
216  switch( m_edge )
217  {
218  case SHEET_LEFT_SIDE: SetEdge( SHEET_RIGHT_SIDE ); break;
219  case SHEET_RIGHT_SIDE: SetEdge( SHEET_LEFT_SIDE ); break;
220  default: break;
221  }
222 }
223 
224 
226 {
227  wxPoint pt = GetTextPos();
228  RotatePoint( &pt, aPosition, 900 );
229 
230  switch( m_edge )
231  {
232  case SHEET_LEFT_SIDE: SetEdge( SHEET_BOTTOM_SIDE ); break;
233  case SHEET_RIGHT_SIDE: SetEdge( SHEET_TOP_SIDE ); break;
234  case SHEET_TOP_SIDE: SetEdge( SHEET_LEFT_SIDE ); break;
236  default: break;
237  }
238 
239  ConstrainOnEdge( pt );
240 }
241 
242 
243 void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos )
244 {
245  /*
246  * These are the same icon shapes as SCH_HIERLABEL but the graphic icon is slightly
247  * different in 2 cases:
248  * for INPUT type the icon is the OUTPUT shape of SCH_HIERLABEL
249  * for OUTPUT type the icon is the INPUT shape of SCH_HIERLABEL
250  */
252 
253  switch( m_shape )
254  {
257  break;
260  break;
261  default:
262  break;
263  }
264 
265  SCH_HIERLABEL::CreateGraphicShape( aPoints, aPos );
266  m_shape = tmp;
267 }
268 
269 
270 void SCH_SHEET_PIN::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
271 {
273  aItemList.push_back( item );
274 }
275 
276 
278 {
279  return wxString::Format( _( "Hierarchical Sheet Pin %s" ), ShortenedShownText() );
280 }
281 
282 
284 {
285  return add_hierar_pin_xpm;
286 }
287 
288 
289 bool SCH_SHEET_PIN::HitTest( const wxPoint& aPoint, int aAccuracy ) const
290 {
291  EDA_RECT rect = GetBoundingBox();
292 
293  rect.Inflate( aAccuracy );
294 
295  return rect.Contains( aPoint );
296 }
297 
298 
299 #if defined(DEBUG)
300 
301 void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os ) const
302 {
303  // XML output:
304  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << ">"
305  << " pin_name=\"" << TO_UTF8( GetText() )
306  << '"' << "/>\n" << std::flush;
307 }
308 
309 #endif
EDA_UNITS
Definition: common.h:72
SCH_LAYER_ID m_Layer
Definition: sch_item.h:141
SHEET_SIDE
Defines the edge of the sheet that the sheet pin is positioned SHEET_LEFT_SIDE = 0: pin on left side ...
Definition: sch_sheet.h:55
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:158
PNG memory record (file in memory).
Definition: bitmap_def.h:29
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
SCH_SHEET_PIN(SCH_SHEET *parent, const wxPoint &pos=wxPoint(0, 0), const wxString &text=wxEmptyString)
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
bool m_isDangling
True if not connected to another object if the object derive from SCH_TEXT supports connections.
Definition: sch_text.h:185
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i....
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:231
wxSize m_size
The size of the sheet.
Definition: sch_sheet.h:235
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_sheet.h:99
SHEET_SIDE GetEdge() const
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
const BITMAP_OPAQUE add_hierar_pin_xpm[1]
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
wxPoint m_pos
The position of the sheet.
Definition: sch_sheet.h:232
void Print(wxDC *aDC, const wxPoint &aOffset) override
Function Print Print a schematic item.
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
bool Contains(const wxPoint &aPoint) const
Function Contains.
void SetTextX(int aX)
Definition: eda_text.h:234
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
#define NULL
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:216
void SetEdge(SHEET_SIDE aEdge)
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:163
void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:1016
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:1102
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:75
int GetNumber() const
Get the sheet label number.
Definition: sch_sheet.h:133
void ConstrainOnEdge(wxPoint Pos)
Adjust label position to edge based on proximity to vertical or horizontal edge of the parent sheet.
void Print(wxDC *DC, const wxPoint &offset) override
Function Print Print a schematic item.
Definition: sch_text.cpp:1057
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:206
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1080
PINSHEETLABEL_SHAPE
Definition: sch_text.h:164
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
void SetNumber(int aNumber)
Set the sheet label number.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points.
int m_number
Label number use for saving sheet label to file.
Definition: sch_sheet.h:78
#define _(s)
Definition: 3d_actions.cpp:31
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:221
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:251
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
bool operator==(const SCH_SHEET_PIN *aPin) const
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:162
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
PINSHEETLABEL_SHAPE m_shape
Definition: sch_text.h:181
DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be connected ...
Definition: sch_item.h:67
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:136
int GetPenSize() const override
Function GetPenSize virtual pure.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
SHEET_SIDE m_edge
Definition: sch_sheet.h:83
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
void SetTextY(int aY)
Definition: eda_text.h:235
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207