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 <sch_draw_panel.h>
35 #include <confirm.h>
36 #include <sch_edit_frame.h>
37 
38 #include <sch_sheet.h>
39 #include <dialog_helpers.h>
40 
42 
43 
47 
49 {
50  // Delayed initialization (need the preferences to be loaded)
51  if( m_lastSheetPinTextSize.x == -1 )
52  {
55  }
57 }
58 
59 
60 int SCH_EDIT_FRAME::EditSheetPin( SCH_SHEET_PIN* aSheetPin, bool aRedraw )
61 {
62  if( aSheetPin == NULL )
63  return wxID_CANCEL;
64 
65  DIALOG_SCH_EDIT_SHEET_PIN dlg( this, aSheetPin );
66 
67  if( dlg.ShowModal() == wxID_CANCEL )
68  return wxID_CANCEL;
69 
70  if( aRedraw )
71  RefreshItem( aSheetPin );
72 
73  return wxID_OK;
74 }
75 
76 
78 {
79  wxString line;
80  SCH_SHEET_PIN* sheetPin;
81 
82  sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), line );
83  sheetPin->SetFlags( IS_NEW );
84  sheetPin->SetTextSize( GetLastSheetPinTextSize() );
85  sheetPin->SetShape( m_lastSheetPinType );
86 
87  int response = EditSheetPin( sheetPin, false );
88 
89  if( sheetPin->GetText().IsEmpty() || (response == wxID_CANCEL) )
90  {
91  delete sheetPin;
92  return NULL;
93  }
94 
95  m_lastSheetPinType = sheetPin->GetShape();
96  m_lastSheetPinTextSize = sheetPin->GetTextSize();
97 
98  sheetPin->SetPosition( GetCrossHairPosition() );
99  PrepareMoveItem( sheetPin );
100 
101  OnModify();
102  return sheetPin;
103 }
104 
105 
107 {
108  EDA_ITEM* item;
109  SCH_SHEET_PIN* sheetPin;
110  SCH_HIERLABEL* label = NULL;
111 
112  if( !aSheet->GetScreen() )
113  return NULL;
114 
115  item = aSheet->GetScreen()->GetDrawItems();
116 
117  for( ; item != NULL; item = item->Next() )
118  {
119  if( item->Type() != SCH_HIERARCHICAL_LABEL_T )
120  continue;
121 
122  label = (SCH_HIERLABEL*) item;
123 
124  /* A global label has been found: check if there a corresponding sheet label. */
125  if( !aSheet->HasPin( label->GetText() ) )
126  break;
127 
128  label = NULL;
129  }
130 
131  if( label == NULL )
132  {
133  DisplayInfoMessage( this, _( "No new hierarchical labels found." ) );
134  return NULL;
135  }
136 
137  sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->GetText() );
138  sheetPin->SetFlags( IS_NEW );
139  sheetPin->SetTextSize( GetLastSheetPinTextSize() );
140  m_lastSheetPinType = label->GetShape();
141  sheetPin->SetShape( label->GetShape() );
142  sheetPin->SetPosition( GetCrossHairPosition() );
143 
144  PrepareMoveItem( sheetPin );
145 
146  return sheetPin;
147 }
Definition of the SCH_SHEET class for Eeschema.
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:118
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:120
This file is part of the common library.
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen* and ...
static wxSize m_lastSheetPinTextSize
Last sheet pin text size.
SCH_SHEET_PIN * CreateSheetPin(SCH_SHEET *aSheet)
Create a new SCH_SHEET_PIN object and add it to aSheet at the current cursor position.
Definition: sheetlab.cpp:77
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:227
EDA_ITEM * Next() const
Definition: base_struct.h:209
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:279
This file contains miscellaneous commonly used macros and functions.
Subclass of DIALOG_SCH_EDIT_SHEET_PIN_BASE, which is generated by wxFormBuilder.
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
void PrepareMoveItem(SCH_ITEM *aItem)
Start moving aItem using the mouse.
Definition: schedit.cpp:762
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
static PINSHEETLABEL_SHAPE m_lastSheetPinType
Last sheet pin type.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
SCH_SHEET_PIN * ImportSheetPin(SCH_SHEET *aSheet)
Automatically create a sheet pin from the hierarchical labels in the schematic referenced by aSheet...
Definition: sheetlab.cpp:106
Helper dialog and control classes.
const wxSize & GetLastSheetPinTextSize()
Initializing accessor for the pin text size.
Definition: sheetlab.cpp:48
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_sheet.h:195
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:160
PINSHEETLABEL_SHAPE
Definition: sch_text.h:46
void RefreshItem(SCH_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
bool HasPin(const wxString &aName)
Checks if the sheet already has a sheet pin named aName.
Definition: sch_sheet.cpp:209
const wxSize & GetTextSize() const
Definition: eda_text.h:228
static wxPoint m_lastSheetPinPosition
Last sheet pin position.
int EditSheetPin(SCH_SHEET_PIN *aSheetPin, bool aRedraw)
Display the dialog for editing the parameters of aSheetPin.
Definition: sheetlab.cpp:60
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:277
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
int GetDefaultTextSize()
Default size for text in general.