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 <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 
73  wxDC* aDC,
74  const wxPoint& aOffset,
75  GR_DRAWMODE aDraw_mode,
76  COLOR4D aColor )
77 {
78  // The icon selection is handle by the virtual method CreateGraphicShape
79  // called by ::Draw
80  SCH_HIERLABEL::Draw( aPanel, aDC, aOffset, aDraw_mode, aColor );
81 }
82 
83 
85 {
86  wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T,
87  wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ),
88  GetChars( aItem->GetClass() ) ) );
89 
90  SCH_SHEET_PIN* pin = ( SCH_SHEET_PIN* ) aItem;
91  SCH_TEXT::SwapData( (SCH_TEXT*) pin );
92  int tmp = pin->GetNumber();
93  pin->SetNumber( GetNumber() );
94  SetNumber( tmp );
95  SHEET_SIDE stmp = pin->GetEdge();
96  pin->SetEdge( GetEdge() );
97  SetEdge( stmp );
98 }
99 
100 
101 bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
102 {
103  return aPin == this;
104 }
105 
106 
108 {
109  return GetDefaultLineThickness();
110 }
111 
112 
113 void SCH_SHEET_PIN::SetNumber( int aNumber )
114 {
115  wxASSERT( aNumber >= 2 );
116 
117  m_number = aNumber;
118 }
119 
120 
122 {
123  SCH_SHEET* Sheet = GetParent();
124 
125  // use SHEET_UNDEFINED_SIDE to adjust text orientation without changing edge
126 
127  switch( aEdge )
128  {
129  case SHEET_LEFT_SIDE:
130  m_edge = aEdge;
131  SetTextX( Sheet->m_pos.x );
132  SetLabelSpinStyle( 2 ); // Orientation horiz inverse
133  break;
134 
135  case SHEET_RIGHT_SIDE:
136  m_edge = aEdge;
137  SetTextX( Sheet->m_pos.x + Sheet->m_size.x );
138  SetLabelSpinStyle( 0 ); // Orientation horiz normal
139  break;
140 
141  case SHEET_TOP_SIDE:
142  m_edge = aEdge;
143  SetTextY( Sheet->m_pos.y );
144  SetLabelSpinStyle( 3 ); // Orientation vert BOTTOM
145  break;
146 
147  case SHEET_BOTTOM_SIDE:
148  m_edge = aEdge;
149  SetTextY( Sheet->m_pos.y + Sheet->m_size.y );
150  SetLabelSpinStyle( 1 ); // Orientation vert UP
151  break;
152 
153  default:
154  break;
155  }
156 }
157 
158 
160 {
161  return m_edge;
162 }
163 
164 
166 {
167  SCH_SHEET* sheet = GetParent();
168 
169  if( sheet == NULL )
170  return;
171 
172  wxPoint center = sheet->m_pos + ( sheet->m_size / 2 );
173 
175  {
176  if( Pos.x > center.x )
177  {
179  }
180  else
181  {
183  }
184 
185  SetTextY( Pos.y );
186 
187  if( GetTextPos().y < sheet->m_pos.y )
188  SetTextY( sheet->m_pos.y );
189 
190  if( GetTextPos().y > (sheet->m_pos.y + sheet->m_size.y) )
191  SetTextY( sheet->m_pos.y + sheet->m_size.y );
192  }
193  else
194  {
195  if( Pos.y > center.y )
196  {
198  }
199  else
200  {
202  }
203 
204  SetTextX( Pos.x );
205 
206  if( GetTextPos().x < sheet->m_pos.x )
207  SetTextX( sheet->m_pos.x );
208 
209  if( GetTextPos().x > (sheet->m_pos.x + sheet->m_size.x) )
210  SetTextX( sheet->m_pos.x + sheet->m_size.x );
211  }
212 }
213 
214 
215 bool SCH_SHEET_PIN::Matches( wxFindReplaceData& aSearchData,
216  void* aAuxData, wxPoint* aFindLocation )
217 {
218  wxCHECK_MSG( GetParent() != NULL, false,
219  wxT( "Sheet pin " ) + m_Text + wxT( " does not have a parent sheet!" ) );
220 
221  wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() );
222 
223  if( SCH_ITEM::Matches( m_Text, aSearchData ) )
224  {
225  if( aFindLocation )
226  *aFindLocation = GetBoundingBox().Centre();
227 
228  return true;
229  }
230 
231  return false;
232 }
233 
234 
235 void SCH_SHEET_PIN::MirrorX( int aXaxis_position )
236 {
237  int p = GetTextPos().y - aXaxis_position;
238 
239  SetTextY( aXaxis_position - p );
240 
241  switch( m_edge )
242  {
243  case SHEET_TOP_SIDE:
245  break;
246 
247  case SHEET_BOTTOM_SIDE:
249  break;
250 
251  default:
252  break;
253  }
254 }
255 
256 
257 void SCH_SHEET_PIN::MirrorY( int aYaxis_position )
258 {
259  int p = GetTextPos().x - aYaxis_position;
260 
261  SetTextX( aYaxis_position - p );
262 
263  switch( m_edge )
264  {
265  case SHEET_LEFT_SIDE:
267  break;
268 
269  case SHEET_RIGHT_SIDE:
271  break;
272 
273  default:
274  break;
275  }
276 }
277 
278 
280 {
281  wxPoint pt = GetTextPos();
282  RotatePoint( &pt, aPosition, 900 );
283  SetTextPos( pt );
284 
285  switch( m_edge )
286  {
287  case SHEET_LEFT_SIDE: //pin on left side
289  break;
290 
291  case SHEET_RIGHT_SIDE: //pin on right side
293  break;
294 
295  case SHEET_TOP_SIDE: //pin on top side
297  break;
298 
299  case SHEET_BOTTOM_SIDE: //pin on bottom side
301  break;
302 
303  default:
304  break;
305  }
306 }
307 
308 
309 void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos )
310 {
311  /* This is the same icon shapes as SCH_HIERLABEL
312  * but the graphic icon is slightly different in 2 cases:
313  * for INPUT type the icon is the OUTPUT shape of SCH_HIERLABEL
314  * for OUTPUT type the icon is the INPUT shape of SCH_HIERLABEL
315  */
317 
318  switch( m_shape )
319  {
320  case NET_INPUT:
322  break;
323 
324  case NET_OUTPUT:
325  m_shape = NET_INPUT;
326  break;
327 
328  default:
329  break;
330  }
331 
332  SCH_HIERLABEL::CreateGraphicShape( aPoints, aPos );
333  m_shape = tmp;
334 }
335 
336 
337 void SCH_SHEET_PIN::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
338 {
340  aItemList.push_back( item );
341 }
342 
343 
345 {
346  wxString tmp;
347  tmp.Printf( _( "Hierarchical Sheet Pin %s" ), GetChars( ShortenedShownText() ) );
348  return tmp;
349 }
350 
352 {
353  return add_hierar_pin_xpm;
354 }
355 
356 
357 bool SCH_SHEET_PIN::HitTest( const wxPoint& aPoint, int aAccuracy ) const
358 {
359  EDA_RECT rect = GetBoundingBox();
360 
361  rect.Inflate( aAccuracy );
362 
363  return rect.Contains( aPoint );
364 }
365 
366 
367 #if defined(DEBUG)
368 
369 void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os ) const
370 {
371  // XML output:
372  wxString s = GetClass();
373 
374  NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
375  << " pin_name=\"" << TO_UTF8( m_Text )
376  << '"' << "/>\n" << std::flush;
377 
378 // NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n";
379 }
380 
381 #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:209
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:344
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:41
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
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:411
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:221
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:216
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:224
#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:224
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
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:1244
void SetEdge(SHEET_SIDE aEdge)
int GetNumber() const
Get the sheet label number.
Definition: sch_sheet.h:134
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:1311
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
wxPoint Centre() const
Definition: eda_rect.h:60
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:1288
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:1210
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.
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:83
virtual void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:312
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
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.
virtual wxString GetClass() const override
Function GetClass returns the class name.
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:225
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39