KiCad PCB EDA Suite
sheetlab.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 wanadoo.fr
5  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #include <fctsys.h>
32 #include <gr_basic.h>
33 #include <macros.h>
34 #include <class_drawpanel.h>
35 #include <confirm.h>
36 #include <schframe.h>
37 #include <base_units.h>
38 
39 #include <general.h>
40 #include <sch_sheet.h>
41 #include <dialog_helpers.h>
42 
44 
45 
49 
51 {
52  // Delayed initialization (need the preferences to be loaded)
53  if( m_lastSheetPinTextSize.x == -1 )
54  {
57  }
59 }
60 
61 int SCH_EDIT_FRAME::EditSheetPin( SCH_SHEET_PIN* aSheetPin, bool aRedraw )
62 {
63  if( aSheetPin == NULL )
64  return wxID_CANCEL;
65 
66  DIALOG_SCH_EDIT_SHEET_PIN dlg( this );
67 
68  dlg.SetLabelName( aSheetPin->GetText() );
69  dlg.SetTextHeight( StringFromValue( g_UserUnit, aSheetPin->GetTextHeight() ) );
71  dlg.SetTextWidth( StringFromValue( g_UserUnit, aSheetPin->GetTextWidth() ) );
73  dlg.SetConnectionType( aSheetPin->GetShape() );
74 
75  /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier versions for
76  * the flex grid sizer in wxGTK that prevents the last column from being sized
77  * correctly. It doesn't cause any problems on win32 so it doesn't need to wrapped
78  * in ugly #ifdef __WXGTK__ #endif.
79  */
80  dlg.Layout();
81  dlg.Fit();
82  dlg.SetMinSize( dlg.GetSize() );
83 
84  if( dlg.ShowModal() == wxID_CANCEL )
85  return wxID_CANCEL;
86 
87  if( !aSheetPin->IsNew() )
88  {
89  SaveCopyInUndoList( (SCH_ITEM*) aSheetPin->GetParent(), UR_CHANGED );
90  GetScreen()->SetCurItem( NULL );
91  }
92 
93  aSheetPin->SetText( dlg.GetLabelName() );
94 
95  aSheetPin->SetTextSize( wxSize(
98 
99  aSheetPin->SetShape( dlg.GetConnectionType() );
100 
101  OnModify();
102 
103  if( aRedraw )
104  m_canvas->Refresh();
105 
106  return wxID_OK;
107 }
108 
109 
111 {
112  wxString line;
113  SCH_SHEET_PIN* sheetPin;
114 
115  sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), line );
116  sheetPin->SetFlags( IS_NEW );
117  sheetPin->SetTextSize( GetLastSheetPinTextSize() );
118  sheetPin->SetShape( m_lastSheetPinType );
119 
120  int response = EditSheetPin( sheetPin, false );
121 
122  if( sheetPin->GetText().IsEmpty() || (response == wxID_CANCEL) )
123  {
124  delete sheetPin;
125  return NULL;
126  }
127 
128  m_lastSheetPinType = sheetPin->GetShape();
129  m_lastSheetPinTextSize = sheetPin->GetTextSize();
130 
131  sheetPin->SetPosition( GetCrossHairPosition() );
132  sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
133  PrepareMoveItem( (SCH_ITEM*) sheetPin, aDC );
134 
135  OnModify();
136  return sheetPin;
137 }
138 
139 
141 {
142  EDA_ITEM* item;
143  SCH_SHEET_PIN* sheetPin;
144  SCH_HIERLABEL* label = NULL;
145 
146  if( !aSheet->GetScreen() )
147  return NULL;
148 
149  item = aSheet->GetScreen()->GetDrawItems();
150 
151  for( ; item != NULL; item = item->Next() )
152  {
153  if( item->Type() != SCH_HIERARCHICAL_LABEL_T )
154  continue;
155 
156  label = (SCH_HIERLABEL*) item;
157 
158  /* A global label has been found: check if there a corresponding sheet label. */
159  if( !aSheet->HasPin( label->GetText() ) )
160  break;
161 
162  label = NULL;
163  }
164 
165  if( label == NULL )
166  {
167  DisplayInfoMessage( this, _( "No new hierarchical labels found." ) );
168  return NULL;
169  }
170 
171  sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->GetText() );
172  sheetPin->SetFlags( IS_NEW );
173  sheetPin->SetTextSize( GetLastSheetPinTextSize() );
174  m_lastSheetPinType = label->GetShape();
175  sheetPin->SetShape( label->GetShape() );
176  sheetPin->SetPosition( GetCrossHairPosition() );
177 
178  sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
179  PrepareMoveItem( (SCH_ITEM*) sheetPin, aDC );
180 
181  return sheetPin;
182 }
Definition of the SCH_SHEET class for Eeschema.
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:121
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:123
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:161
void SetTextWidth(const wxString &aWidth)
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))
Function SaveCopyInUndoList.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
Implementation of conversion functions that require both schematic and board internal units...
This file is part of the common library.
bool IsNew() const
Definition: base_struct.h:230
void OnModify()
Function OnModify Must be called after a schematic change in order to set the "modify" flag of the cu...
Definition: schframe.cpp:770
void SetTextWidthUnits(const wxString &aUnit)
void SetTextHeightUnits(const wxString &aUnit)
static wxSize m_lastSheetPinTextSize
Last sheet pin text size.
Definition: schframe.h:179
wxString GetUnitsLabel(EDA_UNITS_T aUnit)
Get a human readable units string.
Definition: base_units.cpp:452
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:203
int GetTextWidth() const
Definition: eda_text.h:218
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
EDA_ITEM * Next() const
Definition: base_struct.h:220
void SetTextHeight(const wxString &aHeight)
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
void PrepareMoveItem(SCH_ITEM *aItem, wxDC *aDC)
Function PrepareMoveItem start moving aItem using the mouse.
Definition: schedit.cpp:783
PINSHEETLABEL_SHAPE GetConnectionType() const
This file contains miscellaneous commonly used macros and functions.
SCH_SHEET_PIN * CreateSheetPin(SCH_SHEET *aSheet, wxDC *aDC)
Function CreateSheetPin creates a new SCH_SHEET_PIN object and add it to aSheet at the current cursor...
Definition: sheetlab.cpp:110
Subclass of DIALOG_SCH_EDIT_SHEET_PIN_BASE, which is generated by wxFormBuilder.
#define IS_NEW
New item, just created.
Definition: base_struct.h:127
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:529
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:267
static PINSHEETLABEL_SHAPE m_lastSheetPinType
Last sheet pin type.
Definition: schframe.h:178
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:368
Helper dialog and control classes.
const wxSize & GetLastSheetPinTextSize()
Initializing accessor for the pin text size.
Definition: sheetlab.cpp:50
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:102
Class SCH_SHEET_PIN defines a sheet pin (label) used in sheets to create hierarchical schematics...
Definition: sch_sheet.h:62
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
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.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_sheet.h:201
SCH_ITEM * GetDrawItems() const
Function GetDrawItems().
PINSHEETLABEL_SHAPE
Definition: sch_text.h:46
void SetLabelName(const wxString &aName)
void SetCurItem(SCH_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
int GetTextHeight() const
Definition: eda_text.h:221
bool HasPin(const wxString &aName)
Checks if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:390
SCH_SHEET_PIN * ImportSheetPin(SCH_SHEET *aSheet, wxDC *aDC)
Function ImportSheetPin automatically creates a sheet pin from the hierarchical labels in the schemat...
Definition: sheetlab.cpp:140
const wxSize & GetTextSize() const
Definition: eda_text.h:215
static wxPoint m_lastSheetPinPosition
Last sheet pin position.
Definition: schframe.h:180
int EditSheetPin(SCH_SHEET_PIN *aSheetPin, bool aRedraw)
Function EditSheetPin displays the dialog for editing the parameters of aSheetPin.
Definition: sheetlab.cpp:61
void SetConnectionType(PINSHEETLABEL_SHAPE aType)
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
int GetDefaultTextSize()
Default size for text in general.
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141