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 <class_drawpanel.h>
33 #include <drawtxt.h>
34 #include <class_plotter.h>
35 #include <trigo.h>
36 #include <richio.h>
37 #include <schframe.h>
38 #include <bitmaps.h>
39 
40 #include <general.h>
41 #include <sch_sheet.h>
42 #include <kicad_string.h>
43 
44 
45 SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxString& text ) :
46  SCH_HIERLABEL( pos, text, SCH_SHEET_PIN_T )
47 {
48  SetParent( parent );
49  wxASSERT( parent );
51 
52  SetTextPos( pos );
53 
54  if( parent->IsVerticalOrientation() )
56  else
58 
60  m_isDangling = true;
61  m_number = 2;
62 }
63 
64 
66 {
67  return new SCH_SHEET_PIN( *this );
68 }
69 
70 
72  wxDC* aDC,
73  const wxPoint& aOffset,
74  GR_DRAWMODE aDraw_mode,
75  COLOR4D aColor )
76 {
77  // The icon selection is handle by the virtual method CreateGraphicShape
78  // called by ::Draw
79  SCH_HIERLABEL::Draw( aPanel, aDC, aOffset, aDraw_mode, aColor );
80 }
81 
82 
84 {
85  wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T,
86  wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ),
87  GetChars( aItem->GetClass() ) ) );
88 
89  SCH_SHEET_PIN* pin = ( SCH_SHEET_PIN* ) aItem;
90  SCH_TEXT::SwapData( (SCH_TEXT*) pin );
91  int tmp = pin->GetNumber();
92  pin->SetNumber( GetNumber() );
93  SetNumber( tmp );
94  SHEET_SIDE stmp = pin->GetEdge();
95  pin->SetEdge( GetEdge() );
96  SetEdge( stmp );
97 }
98 
99 
100 bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
101 {
102  return aPin == this;
103 }
104 
105 
107 {
108  return GetDefaultLineThickness();
109 }
110 
111 
112 void SCH_SHEET_PIN::SetNumber( int aNumber )
113 {
114  wxASSERT( aNumber >= 2 );
115 
116  m_number = aNumber;
117 }
118 
119 
121 {
122  SCH_SHEET* Sheet = GetParent();
123 
124  // use SHEET_UNDEFINED_SIDE to adjust text orientation without changing edge
125 
126  switch( aEdge )
127  {
128  case SHEET_LEFT_SIDE:
129  m_edge = aEdge;
130  SetTextX( Sheet->m_pos.x );
131  SetLabelSpinStyle( 2 ); // Orientation horiz inverse
132  break;
133 
134  case SHEET_RIGHT_SIDE:
135  m_edge = aEdge;
136  SetTextX( Sheet->m_pos.x + Sheet->m_size.x );
137  SetLabelSpinStyle( 0 ); // Orientation horiz normal
138  break;
139 
140  case SHEET_TOP_SIDE:
141  m_edge = aEdge;
142  SetTextY( Sheet->m_pos.y );
143  SetLabelSpinStyle( 3 ); // Orientation vert BOTTOM
144  break;
145 
146  case SHEET_BOTTOM_SIDE:
147  m_edge = aEdge;
148  SetTextY( Sheet->m_pos.y + Sheet->m_size.y );
149  SetLabelSpinStyle( 1 ); // Orientation vert UP
150  break;
151 
152  default:
153  break;
154  }
155 }
156 
157 
159 {
160  return m_edge;
161 }
162 
163 
165 {
166  SCH_SHEET* sheet = GetParent();
167 
168  if( sheet == NULL )
169  return;
170 
171  wxPoint center = sheet->m_pos + ( sheet->m_size / 2 );
172 
174  {
175  if( Pos.x > center.x )
176  {
178  }
179  else
180  {
182  }
183 
184  SetTextY( Pos.y );
185 
186  if( GetTextPos().y < sheet->m_pos.y )
187  SetTextY( sheet->m_pos.y );
188 
189  if( GetTextPos().y > (sheet->m_pos.y + sheet->m_size.y) )
190  SetTextY( sheet->m_pos.y + sheet->m_size.y );
191  }
192  else
193  {
194  if( Pos.y > center.y )
195  {
197  }
198  else
199  {
201  }
202 
203  SetTextX( Pos.x );
204 
205  if( GetTextPos().x < sheet->m_pos.x )
206  SetTextX( sheet->m_pos.x );
207 
208  if( GetTextPos().x > (sheet->m_pos.x + sheet->m_size.x) )
209  SetTextX( sheet->m_pos.x + sheet->m_size.x );
210  }
211 }
212 
213 
214 bool SCH_SHEET_PIN::Matches( wxFindReplaceData& aSearchData,
215  void* aAuxData, wxPoint* aFindLocation )
216 {
217  wxCHECK_MSG( GetParent() != NULL, false,
218  wxT( "Sheet pin " ) + m_Text + wxT( " does not have a parent sheet!" ) );
219 
220  wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() );
221 
222  if( SCH_ITEM::Matches( m_Text, aSearchData ) )
223  {
224  if( aFindLocation )
225  *aFindLocation = GetBoundingBox().Centre();
226 
227  return true;
228  }
229 
230  return false;
231 }
232 
233 
234 void SCH_SHEET_PIN::MirrorX( int aXaxis_position )
235 {
236  int p = GetTextPos().y - aXaxis_position;
237 
238  SetTextY( aXaxis_position - p );
239 
240  switch( m_edge )
241  {
242  case SHEET_TOP_SIDE:
244  break;
245 
246  case SHEET_BOTTOM_SIDE:
248  break;
249 
250  default:
251  break;
252  }
253 }
254 
255 
256 void SCH_SHEET_PIN::MirrorY( int aYaxis_position )
257 {
258  int p = GetTextPos().x - aYaxis_position;
259 
260  SetTextX( aYaxis_position - p );
261 
262  switch( m_edge )
263  {
264  case SHEET_LEFT_SIDE:
266  break;
267 
268  case SHEET_RIGHT_SIDE:
270  break;
271 
272  default:
273  break;
274  }
275 }
276 
277 
279 {
280  wxPoint pt = GetTextPos();
281  RotatePoint( &pt, aPosition, 900 );
282  SetTextPos( pt );
283 
284  switch( m_edge )
285  {
286  case SHEET_LEFT_SIDE: //pin on left side
288  break;
289 
290  case SHEET_RIGHT_SIDE: //pin on right side
292  break;
293 
294  case SHEET_TOP_SIDE: //pin on top side
296  break;
297 
298  case SHEET_BOTTOM_SIDE: //pin on bottom side
300  break;
301 
302  default:
303  break;
304  }
305 }
306 
307 
308 void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos )
309 {
310  /* This is the same icon shapes as SCH_HIERLABEL
311  * but the graphic icon is slightly different in 2 cases:
312  * for INPUT type the icon is the OUTPUT shape of SCH_HIERLABEL
313  * for OUTPUT type the icon is the INPUT shape of SCH_HIERLABEL
314  */
316 
317  switch( m_shape )
318  {
319  case NET_INPUT:
321  break;
322 
323  case NET_OUTPUT:
324  m_shape = NET_INPUT;
325  break;
326 
327  default:
328  break;
329  }
330 
331  SCH_HIERLABEL::CreateGraphicShape( aPoints, aPos );
332  m_shape = tmp;
333 }
334 
335 
336 void SCH_SHEET_PIN::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
337 {
339  aItemList.push_back( item );
340 }
341 
342 
344 {
345  wxString tmp;
346  tmp.Printf( _( "Hierarchical Sheet Pin %s" ), GetChars( ShortenedShownText() ) );
347  return tmp;
348 }
349 
351 {
352  return add_hierar_pin_xpm;
353 }
354 
355 
356 bool SCH_SHEET_PIN::HitTest( const wxPoint& aPoint, int aAccuracy ) const
357 {
358  EDA_RECT rect = GetBoundingBox();
359 
360  rect.Inflate( aAccuracy );
361 
362  return rect.Contains( aPoint );
363 }
364 
365 
366 #if defined(DEBUG)
367 
368 void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os ) const
369 {
370  // XML output:
371  wxString s = GetClass();
372 
373  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
374  << " pin_name=\"" << TO_UTF8( m_Text )
375  << '"' << "/>\n" << std::flush;
376 
377 // NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
378 }
379 
380 #endif
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
Definition of the SCH_SHEET class for Eeschema.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
SCH_LAYER_ID m_Layer
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:159
wxString m_Text
Definition: eda_text.h:346
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:79
PNG memory record (file in memory).
Definition: bitmap_types.h:38
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
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 Contains(const wxPoint &aPoint) const
Function Contains.
bool m_isDangling
True if not connected to another object if the object derive from SCH_TEXT supports connections...
Definition: sch_text.h:65
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:427
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:223
SHEET_SIDE GetEdge() const
wxSize m_size
The size of the sheet.
Definition: sch_sheet.h:238
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_sheet.h:99
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
bool operator==(const SCH_SHEET_PIN *aPin) const
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:235
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
void SetTextX(int aX)
Definition: eda_text.h:226
#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
const wxString traceFindItem
Flag to enable finding schematic item debug output.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:240
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, const wxPoint &offset, GR_DRAWMODE draw_mode, COLOR4D Color=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Definition: sch_text.cpp:1243
void SetEdge(SHEET_SIDE aEdge)
int GetNumber() const
Get the sheet label number.
Definition: sch_sheet.h:134
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_text.cpp:1310
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
wxPoint Centre() const
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:209
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1287
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:1209
PINSHEETLABEL_SHAPE
Definition: sch_text.h:46
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:73
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:92
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
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:83
virtual void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:311
Class EDA_RECT handles the component boundary box.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:178
bool IsVerticalOrientation() const
Definition: sch_sheet.cpp:220
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.
This file is part of the common libary.
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:61
Class DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be conn...
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
int GetPenSize() const override
Function GetPenSize virtual pure.
SHEET_SIDE m_edge
Definition: sch_sheet.h:88
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:227
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39