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-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 #include <fctsys.h>
31 #include <gr_basic.h>
32 #include <sch_draw_panel.h>
33 #include <draw_graphic_text.h>
34 #include <plotter.h>
35 #include <trigo.h>
36 #include <richio.h>
37 #include <sch_edit_frame.h>
38 #include <bitmaps.h>
39 
40 #include <general.h>
41 #include <sch_sheet.h>
42 #include <kicad_string.h>
43 #include <trace_helpers.h>
44 
45 
46 SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxString& text ) :
47  SCH_HIERLABEL( pos, text, SCH_SHEET_PIN_T )
48 {
49  SetParent( parent );
50  wxASSERT( parent );
52 
53  SetTextPos( pos );
54 
55  if( parent->IsVerticalOrientation() )
57  else
59 
61  m_isDangling = true;
62  m_number = 2;
63 }
64 
65 
67 {
68  return new SCH_SHEET_PIN( *this );
69 }
70 
71 
72 void SCH_SHEET_PIN::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset )
73 {
74  // The icon selection is handle by the virtual method CreateGraphicShape
75  // called by ::Draw
76  SCH_HIERLABEL::Draw( aPanel, aDC, aOffset );
77 }
78 
79 
81 {
82  wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T,
83  wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ),
84  GetChars( aItem->GetClass() ) ) );
85 
86  SCH_SHEET_PIN* pin = ( SCH_SHEET_PIN* ) aItem;
87  SCH_TEXT::SwapData( (SCH_TEXT*) pin );
88  int tmp = pin->GetNumber();
89  pin->SetNumber( GetNumber() );
90  SetNumber( tmp );
91  SHEET_SIDE stmp = pin->GetEdge();
92  pin->SetEdge( GetEdge() );
93  SetEdge( stmp );
94 }
95 
96 
97 bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
98 {
99  return aPin == this;
100 }
101 
102 
104 {
105  return GetDefaultLineThickness();
106 }
107 
108 
109 void SCH_SHEET_PIN::SetNumber( int aNumber )
110 {
111  wxASSERT( aNumber >= 2 );
112 
113  m_number = aNumber;
114 }
115 
116 
118 {
119  SCH_SHEET* Sheet = GetParent();
120 
121  // use SHEET_UNDEFINED_SIDE to adjust text orientation without changing edge
122 
123  switch( aEdge )
124  {
125  case SHEET_LEFT_SIDE:
126  m_edge = aEdge;
127  SetTextX( Sheet->m_pos.x );
128  SetLabelSpinStyle( 2 ); // Orientation horiz inverse
129  break;
130 
131  case SHEET_RIGHT_SIDE:
132  m_edge = aEdge;
133  SetTextX( Sheet->m_pos.x + Sheet->m_size.x );
134  SetLabelSpinStyle( 0 ); // Orientation horiz normal
135  break;
136 
137  case SHEET_TOP_SIDE:
138  m_edge = aEdge;
139  SetTextY( Sheet->m_pos.y );
140  SetLabelSpinStyle( 3 ); // Orientation vert BOTTOM
141  break;
142 
143  case SHEET_BOTTOM_SIDE:
144  m_edge = aEdge;
145  SetTextY( Sheet->m_pos.y + Sheet->m_size.y );
146  SetLabelSpinStyle( 1 ); // Orientation vert UP
147  break;
148 
149  default:
150  break;
151  }
152 }
153 
154 
156 {
157  return m_edge;
158 }
159 
160 
162 {
163  SCH_SHEET* sheet = GetParent();
164 
165  if( sheet == NULL )
166  return;
167 
168  wxPoint center = sheet->m_pos + ( sheet->m_size / 2 );
169 
171  {
172  if( Pos.x > center.x )
173  {
175  }
176  else
177  {
179  }
180 
181  SetTextY( Pos.y );
182 
183  if( GetTextPos().y < sheet->m_pos.y )
184  SetTextY( sheet->m_pos.y );
185 
186  if( GetTextPos().y > (sheet->m_pos.y + sheet->m_size.y) )
187  SetTextY( sheet->m_pos.y + sheet->m_size.y );
188  }
189  else
190  {
191  if( Pos.y > center.y )
192  {
194  }
195  else
196  {
198  }
199 
200  SetTextX( Pos.x );
201 
202  if( GetTextPos().x < sheet->m_pos.x )
203  SetTextX( sheet->m_pos.x );
204 
205  if( GetTextPos().x > (sheet->m_pos.x + sheet->m_size.x) )
206  SetTextX( sheet->m_pos.x + sheet->m_size.x );
207  }
208 }
209 
210 
211 bool SCH_SHEET_PIN::Matches( wxFindReplaceData& aSearchData,
212  void* aAuxData, wxPoint* aFindLocation )
213 {
214  wxCHECK_MSG( GetParent() != NULL, false,
215  wxT( "Sheet pin " ) + m_Text + wxT( " does not have a parent sheet!" ) );
216 
217  wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText( MILLIMETRES ) );
218 
219  if( SCH_ITEM::Matches( m_Text, aSearchData ) )
220  {
221  if( aFindLocation )
222  *aFindLocation = GetBoundingBox().Centre();
223 
224  return true;
225  }
226 
227  return false;
228 }
229 
230 
231 void SCH_SHEET_PIN::MirrorX( int aXaxis_position )
232 {
233  int p = GetTextPos().y - aXaxis_position;
234 
235  SetTextY( aXaxis_position - p );
236 
237  switch( m_edge )
238  {
239  case SHEET_TOP_SIDE:
241  break;
242 
243  case SHEET_BOTTOM_SIDE:
245  break;
246 
247  default:
248  break;
249  }
250 }
251 
252 
253 void SCH_SHEET_PIN::MirrorY( int aYaxis_position )
254 {
255  int p = GetTextPos().x - aYaxis_position;
256 
257  SetTextX( aYaxis_position - p );
258 
259  switch( m_edge )
260  {
261  case SHEET_LEFT_SIDE:
263  break;
264 
265  case SHEET_RIGHT_SIDE:
267  break;
268 
269  default:
270  break;
271  }
272 }
273 
274 
275 void SCH_SHEET_PIN::Rotate( wxPoint aPosition )
276 {
277  wxPoint pt = GetTextPos();
278  RotatePoint( &pt, aPosition, 900 );
279  SetTextPos( pt );
280 
281  switch( m_edge )
282  {
283  case SHEET_LEFT_SIDE: //pin on left side
285  break;
286 
287  case SHEET_RIGHT_SIDE: //pin on right side
289  break;
290 
291  case SHEET_TOP_SIDE: //pin on top side
293  break;
294 
295  case SHEET_BOTTOM_SIDE: //pin on bottom side
297  break;
298 
299  default:
300  break;
301  }
302 }
303 
304 
305 void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos )
306 {
307  /* This is the same icon shapes as SCH_HIERLABEL
308  * but the graphic icon is slightly different in 2 cases:
309  * for INPUT type the icon is the OUTPUT shape of SCH_HIERLABEL
310  * for OUTPUT type the icon is the INPUT shape of SCH_HIERLABEL
311  */
313 
314  switch( m_shape )
315  {
316  case NET_INPUT:
318  break;
319 
320  case NET_OUTPUT:
321  m_shape = NET_INPUT;
322  break;
323 
324  default:
325  break;
326  }
327 
328  SCH_HIERLABEL::CreateGraphicShape( aPoints, aPos );
329  m_shape = tmp;
330 }
331 
332 
333 void SCH_SHEET_PIN::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
334 {
336  aItemList.push_back( item );
337 }
338 
339 
341 {
342  return wxString::Format( _( "Hierarchical Sheet Pin %s" ), ShortenedShownText() );
343 }
344 
345 BITMAP_DEF SCH_SHEET_PIN::GetMenuImage() const
346 {
347  return add_hierar_pin_xpm;
348 }
349 
350 
351 bool SCH_SHEET_PIN::HitTest( const wxPoint& aPoint, int aAccuracy ) const
352 {
353  EDA_RECT rect = GetBoundingBox();
354 
355  rect.Inflate( aAccuracy );
356 
357  return rect.Contains( aPoint );
358 }
359 
360 
361 #if defined(DEBUG)
362 
363 void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os ) const
364 {
365  // XML output:
366  wxString s = GetClass();
367 
368  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
369  << " pin_name=\"" << TO_UTF8( m_Text )
370  << '"' << "/>\n" << std::flush;
371 
372 // NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
373 }
374 
375 #endif
SCH_LAYER_ID m_Layer
Definition: sch_item.h:119
wxString m_Text
Definition: eda_text.h:378
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:153
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
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:66
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:458
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:240
wxSize m_size
The size of the sheet.
Definition: sch_sheet.h:230
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_sheet.h:94
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
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 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:227
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:243
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:47
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:219
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, const wxPoint &offset) override
Function Draw Draw a schematic item.
Definition: sch_text.cpp:1049
void SetEdge(SHEET_SIDE aEdge)
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:96
wxLogTrace helper definitions.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:1094
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:56
int GetNumber() const
Get the sheet label number.
Definition: sch_sheet.h:128
void ConstrainOnEdge(wxPoint Pos)
Adjust label position to edge based on proximity to vertical or horizontal edge of the parent sheet.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:201
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1072
void SetLabelSpinStyle(int aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:1015
PINSHEETLABEL_SHAPE
Definition: sch_text.h:47
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:68
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:100
void SetNumber(int aNumber)
Set the sheet label number.
const wxChar *const traceFindItem
Flag to enable find debug tracing.
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
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
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
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:282
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
bool operator==(const SCH_SHEET_PIN *aPin) const
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
SHEET_SIDE GetEdge() const
wxPoint Centre() const
Definition: eda_rect.h:60
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:140
const wxPoint & GetTextPos() const
Definition: eda_text.h:241
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
PINSHEETLABEL_SHAPE m_shape
Definition: sch_text.h:62
Class DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be conn...
Definition: sch_item.h:67
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset) override
Function Draw Draw a schematic item.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
int GetPenSize() const override
Function GetPenSize virtual pure.
EDA_UNITS_T
Definition: common.h:157
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:244
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204