KiCad PCB EDA Suite
eeschema/dialogs/dialog_global_edit_text_and_graphics.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) 2019 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <fctsys.h>
25 #include <kicad_string.h>
26 #include <widgets/unit_binder.h>
27 #include <tool/tool_manager.h>
29 #include <tools/sch_edit_tool.h>
30 #include <sch_edit_frame.h>
31 #include <sch_component.h>
32 #include <sch_line.h>
33 #include <sch_connection.h>
34 #include <sch_sheet.h>
35 #include <connection_graph.h>
37 #include <advanced_config.h>
38 
39 static bool g_modifyReferences;
40 static bool g_modifyValues;
41 static bool g_modifyOtherFields;
42 static bool g_modifyWires;
43 static bool g_modifyBusses;
45 static bool g_modifyHierLabels;
46 static bool g_modifySheetTitles;
47 static bool g_modifySheetPins;
49 
50 static bool g_filterByFieldname;
51 static wxString g_fieldnameFilter;
52 static bool g_filterByReference;
53 static wxString g_referenceFilter;
54 static bool g_filterBySymbol;
55 static wxString g_symbolFilter;
56 static bool g_filterByNet;
57 static wxString g_netFilter;
58 
59 
61 {
63 
66 
67 public:
70 
71 protected:
72  void OnUpdateUI( wxUpdateUIEvent& event ) override;
73  void OnReferenceFilterText( wxCommandEvent& event ) override
74  {
75  m_referenceFilterOpt->SetValue( true );
76  }
77  void OnSymbolFilterText( wxCommandEvent& event ) override
78  {
79  m_symbolFilterOpt->SetValue( true );
80  }
81 
82  bool TransferDataToWindow() override;
83  bool TransferDataFromWindow() override;
84 
85  void visitItem( const SCH_SHEET_PATH& aSheetPath, SCH_ITEM* aItem );
86  void processItem( const SCH_SHEET_PATH& aSheetPath, SCH_ITEM* aItem );
87 };
88 
89 
92  m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
93  m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits, true )
94 {
95  m_parent = parent;
96 
97  // TODO(JE) remove once real-time connectivity is a given
98  if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
100 
101  m_sdbSizerButtonsOK->SetDefault();
102 
104 }
105 
106 
108 {
109  g_modifyReferences = m_references->GetValue();
110  g_modifyValues = m_values->GetValue();
111  g_modifyOtherFields = m_otherFields->GetValue();
112  g_modifyWires = m_wires->GetValue();
113  g_modifyBusses = m_busses->GetValue();
114  g_modifyGlobalLabels = m_globalLabels->GetValue();
115  g_modifyHierLabels = m_hierLabels->GetValue();
116  g_modifySheetTitles = m_sheetTitles->GetValue();
117  g_modifySheetPins = m_sheetPins->GetValue();
119 
121  g_fieldnameFilter = m_fieldnameFilter->GetValue();
123  g_referenceFilter = m_referenceFilter->GetValue();
124  g_filterBySymbol = m_symbolFilterOpt->GetValue();
125  g_symbolFilter = m_symbolFilter->GetValue();
126  g_filterByNet = m_netFilterOpt->GetValue();
127  g_netFilter = m_netFilter->GetValue();
128 }
129 
130 
132 {
134  SELECTION& selection = selectionTool->GetSelection();
135 
136  m_references->SetValue( g_modifyReferences );
137  m_values->SetValue( g_modifyValues );
138  m_otherFields->SetValue( g_modifyOtherFields );
139  m_wires->SetValue( g_modifyWires );
140  m_busses->SetValue( g_modifyBusses );
142  m_hierLabels->SetValue( g_modifyHierLabels );
143  m_sheetTitles->SetValue( g_modifySheetTitles );
144  m_sheetPins->SetValue( g_modifySheetPins );
146 
147  // SetValue() generates events, ChangeValue() does not
148  m_fieldnameFilter->ChangeValue( g_fieldnameFilter );
150  m_referenceFilter->ChangeValue( g_referenceFilter );
152  m_symbolFilter->ChangeValue( g_symbolFilter );
153  m_symbolFilterOpt->SetValue( g_filterBySymbol );
154 
155  if( g_filterByNet && !g_netFilter.IsEmpty() )
156  {
157  m_netFilter->SetValue( g_netFilter );
158  m_netFilterOpt->SetValue( true );
159  }
160  else if( !m_parent->GetSelectedNetName().IsEmpty() )
161  {
162  m_netFilter->SetValue( m_parent->GetSelectedNetName() );
163  }
164  else if( selection.GetSize() )
165  {
166  SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
167  SCH_CONNECTION* connection = sch_item->Connection( *g_CurrentSheet );
168 
169  if( connection )
170  m_netFilter->SetValue( connection->Name() );
171  }
172 
173  m_netFilterOpt->SetValue( g_filterByNet );
174 
176  m_orientation->SetStringSelection( INDETERMINATE );
177  m_hAlign->SetStringSelection( INDETERMINATE );
178  m_vAlign->SetStringSelection( INDETERMINATE );
179  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
180  m_Bold->Set3StateValue( wxCHK_UNDETERMINED );
181  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
183  m_lineStyle->SetStringSelection( INDETERMINATE );
184  m_setColor->SetValue( false );
185 
186  return true;
187 }
188 
189 
191 {
192 }
193 
194 
196  SCH_ITEM* aItem )
197 {
198  auto eda_text = dynamic_cast<EDA_TEXT*>( aItem );
199  auto sch_text = dynamic_cast<SCH_TEXT*>( aItem );
200  auto lineItem = dynamic_cast<SCH_LINE*>( aItem );
201 
202  if( eda_text )
203  {
204  if( !m_textSize.IsIndeterminate() )
205  eda_text->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
206 
207  if( m_hAlign->GetStringSelection() != INDETERMINATE )
208  eda_text->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_hAlign->GetSelection() - 1 ) );
209 
210  if( m_hAlign->GetStringSelection() != INDETERMINATE )
211  eda_text->SetVertJustify( EDA_TEXT::MapVertJustify( m_vAlign->GetSelection() - 1 ) );
212 
213  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED )
214  eda_text->SetVisible( m_Visible->GetValue() );
215 
216  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED )
217  eda_text->SetItalic( m_Visible->GetValue() );
218 
219  if( m_Bold->Get3StateValue() != wxCHK_UNDETERMINED )
220  eda_text->SetBold( m_Visible->GetValue() );
221  }
222 
223  // No else! Labels are both.
224  if( sch_text )
225  {
226  if( m_orientation->GetStringSelection() != INDETERMINATE )
227  {
228  sch_text->SetLabelSpinStyle( m_orientation->GetSelection() );
229  }
230  }
231 
232  if( lineItem )
233  {
235  lineItem->SetLineWidth( m_lineWidth.GetValue() );
236 
237  if( lineItem->GetLayer() == LAYER_NOTES )
238  {
239  if( m_lineStyle->GetStringSelection() != INDETERMINATE )
240  lineItem->SetLineStyle( m_lineStyle->GetSelection() );
241 
242  if( m_setColor->GetValue() )
243  lineItem->SetLineColor( m_color->GetColour() );
244  }
245  }
246 
247  m_parent->OnModify();
248 }
249 
251  SCH_ITEM* aItem )
252 {
253  if( m_netFilterOpt->GetValue() && !m_netFilter->GetValue().IsEmpty() )
254  {
255  SCH_CONNECTION* connection = aItem->Connection( aSheetPath );
256 
257  if( !connection )
258  return;
259 
260  if( !WildCompareString( m_netFilter->GetValue(), connection->Name(), false ) )
261  return;
262  }
263 
264  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
265  {
266  if( aItem->Type() == SCH_COMPONENT_T )
267  {
268  wxString ref = static_cast<SCH_COMPONENT*>( aItem )->GetRef( &aSheetPath );
269 
270  if( !WildCompareString( m_referenceFilter->GetValue(), ref, false ) )
271  return;
272  }
273  }
274 
275  if( m_symbolFilterOpt->GetValue() && !m_symbolFilter->GetValue().IsEmpty() )
276  {
277  if( aItem->Type() == SCH_COMPONENT_T )
278  {
279  wxString id = static_cast<SCH_COMPONENT*>( aItem )->GetLibId().Format();
280 
281  if( !WildCompareString( m_symbolFilter->GetValue(), id, false ) )
282  return;
283  }
284  }
285 
286  static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LABEL_LOCATE_WIRE_T, EOT };
287  static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, SCH_LABEL_LOCATE_BUS_T, EOT };
288  static KICAD_T schTextAndGraphics[] = { SCH_TEXT_T, SCH_LINE_LOCATE_GRAPHIC_LINE_T, EOT };
289 
290  if( aItem->Type() == SCH_COMPONENT_T )
291  {
292  SCH_COMPONENT* component = (SCH_COMPONENT*) aItem;
293 
294  if( m_references->GetValue() )
295  processItem( aSheetPath, component->GetField( REFERENCE ) );
296 
297  if( m_values->GetValue() )
298  processItem( aSheetPath, component->GetField( VALUE ) );
299 
300  if( m_otherFields->GetValue() )
301  {
302  for( int i = 2; i < component->GetFieldCount(); ++i )
303  {
304  SCH_FIELD* field = component->GetField( i );
305  const wxString& fieldName = field->GetName();
306 
307  if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
308  || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
309  {
310  processItem( aSheetPath, field );
311  }
312  }
313  }
314  }
315  else if( m_wires->GetValue() && aItem->IsType( wireTypes ) )
316  processItem( aSheetPath, aItem );
317  else if( m_busses->GetValue() && aItem->IsType( busTypes ) )
318  processItem( aSheetPath, aItem );
319  else if( m_globalLabels->GetValue() && aItem->Type() == SCH_GLOBAL_LABEL_T )
320  processItem( aSheetPath, aItem );
321  else if( m_hierLabels->GetValue() && aItem->Type() == SCH_HIER_LABEL_T )
322  processItem( aSheetPath, aItem );
323  else if( m_sheetTitles->GetValue() && aItem->Type() == SCH_SHEET_T )
324  {
325  if( !m_textSize.IsIndeterminate() )
326  static_cast<SCH_SHEET*>( aItem )->SetSheetNameSize( m_textSize.GetValue() );
327  }
328  else if( m_sheetPins->GetValue() && aItem->Type() == SCH_SHEET_PIN_T )
329  processItem( aSheetPath, aItem );
330  else if( m_schTextAndGraphics->GetValue() && aItem->IsType( schTextAndGraphics ) )
331  processItem( aSheetPath, aItem );
332 }
333 
334 
336 {
337  if( !m_textSize.Validate( Mils2iu( 1 ), Mils2iu( 10000 ) ) ) // 1 mil .. 10 inches
338  return false;
339 
340  SCH_SHEET_LIST aSheets( g_RootSheet );
341 
342  // Go through sheets
343  for( const SCH_SHEET_PATH& sheetPath : aSheets )
344  {
345  SCH_SCREEN* screen = sheetPath.LastScreen();
346 
347  if( screen )
348  {
349  for( auto item : screen->Items() )
350  visitItem( sheetPath, item );
351  }
352  }
353 
354  m_parent->HardRedraw();
355 
356  return true;
357 }
358 
359 
361 {
363  dlg.ShowModal();
364  return 0;
365 }
366 
367 
SCH_SHEET_LIST.
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
const wxString & GetSelectedNetName() const
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generates the connection data for the entire schematic hierarchy.
void visitItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Schematic editor (Eeschema) main window.
bool IsIndeterminate() const
Function IsIndeterminate Returns true if the control holds the indeterminate value (for instance,...
Field Reference of part, i.e. "IC21".
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
EE_SELECTION & GetSelection()
Function GetSelection()
#define VALUE
wxString Name(bool aIgnoreSheet=false) const
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:58
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
void HardRedraw() override
Rebuild the GAL and redraw the screen.
#define INDETERMINATE
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
Compare a string against wild card (* and ?) pattern using the usual rules.
Definition: string.cpp:433
TOOL_EVENT.
Definition: tool_event.h:171
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:284
SCH_SHEET_PATH.
virtual bool Validate(long long int aMin, long long int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
int GetFieldCount() const
Return the number of fields in this symbol.
static EDA_TEXT_VJUSTIFY_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:72
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieves the connection associated with this object in the given sheet Note: the returned value can ...
Definition: sch_item.cpp:128
static bool m_allowRealTime
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:371
EE_RTREE & Items()
Definition: sch_screen.h:127
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:89
void processItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
SCH_SHEET * g_RootSheet
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:136
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207