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 <connection_graph.h>
26 #include <fctsys.h>
27 #include <kicad_string.h>
28 #include <sch_component.h>
29 #include <sch_connection.h>
30 #include <sch_edit_frame.h>
31 #include <sch_line.h>
32 #include <sch_sheet.h>
33 #include <schematic.h>
34 #include <advanced_config.h>
35 #include <tool/tool_manager.h>
37 #include <tools/sch_edit_tool.h>
38 #include <widgets/unit_binder.h>
39 
40 static bool g_modifyReferences;
41 static bool g_modifyValues;
42 static bool g_modifyOtherFields;
43 static bool g_modifyWires;
44 static bool g_modifyBuses;
46 static bool g_modifyHierLabels;
47 static bool g_modifySheetTitles;
49 static bool g_modifySheetPins;
52 
53 static bool g_filterByFieldname;
54 static wxString g_fieldnameFilter;
55 static bool g_filterByReference;
56 static wxString g_referenceFilter;
57 static bool g_filterBySymbol;
58 static wxString g_symbolFilter;
59 static bool g_filterByType;
60 static bool g_typeFilterIsPower;
61 static bool g_filterByNet;
62 static wxString g_netFilter;
63 
64 
66 {
68 
71 
73 
74 public:
77 
78 protected:
79  void OnUpdateUI( wxUpdateUIEvent& event ) override;
80  void OnReferenceFilterText( wxCommandEvent& event ) override
81  {
82  m_referenceFilterOpt->SetValue( true );
83  }
84  void OnSymbolFilterText( wxCommandEvent& event ) override
85  {
86  m_symbolFilterOpt->SetValue( true );
87  }
88 
89  bool TransferDataToWindow() override;
90  bool TransferDataFromWindow() override;
91 
92  void visitItem( const SCH_SHEET_PATH& aSheetPath, SCH_ITEM* aItem );
93  void processItem( const SCH_SHEET_PATH& aSheetPath, SCH_ITEM* aItem );
94 };
95 
96 
99  m_textSize( parent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
100  m_lineWidth( parent, m_lineWidthLabel, m_LineWidthCtrl, m_lineWidthUnits, true )
101 {
102  m_parent = parent;
103  m_hasChange = false;
104 
105  // TODO(JE) remove once real-time connectivity is a given
106  if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
108 
109  m_sdbSizerButtonsOK->SetDefault();
110 
112 }
113 
114 
116 {
117  g_modifyReferences = m_references->GetValue();
118  g_modifyValues = m_values->GetValue();
119  g_modifyOtherFields = m_otherFields->GetValue();
120  g_modifyWires = m_wires->GetValue();
121  g_modifyBuses = m_buses->GetValue();
122  g_modifyGlobalLabels = m_globalLabels->GetValue();
123  g_modifyHierLabels = m_hierLabels->GetValue();
124  g_modifySheetTitles = m_sheetTitles->GetValue();
126  g_modifySheetPins = m_sheetPins->GetValue();
127  g_modifySheetBorders = m_sheetBorders->GetValue();
129 
131  g_fieldnameFilter = m_fieldnameFilter->GetValue();
133  g_referenceFilter = m_referenceFilter->GetValue();
134  g_filterBySymbol = m_symbolFilterOpt->GetValue();
135  g_symbolFilter = m_symbolFilter->GetValue();
136  g_filterByType = m_typeFilterOpt->GetValue();
137  g_typeFilterIsPower = m_typeFilter->GetSelection() == 1;
138  g_filterByNet = m_netFilterOpt->GetValue();
139  g_netFilter = m_netFilter->GetValue();
140 }
141 
142 
144 {
146  SELECTION& selection = selectionTool->GetSelection();
147 
148  m_references->SetValue( g_modifyReferences );
149  m_values->SetValue( g_modifyValues );
150  m_otherFields->SetValue( g_modifyOtherFields );
151  m_wires->SetValue( g_modifyWires );
152  m_buses->SetValue( g_modifyBuses );
154  m_hierLabels->SetValue( g_modifyHierLabels );
155  m_sheetTitles->SetValue( g_modifySheetTitles );
157  m_sheetPins->SetValue( g_modifySheetPins );
160 
161  // SetValue() generates events, ChangeValue() does not
162  m_fieldnameFilter->ChangeValue( g_fieldnameFilter );
164  m_referenceFilter->ChangeValue( g_referenceFilter );
166  m_symbolFilter->ChangeValue( g_symbolFilter );
167  m_symbolFilterOpt->SetValue( g_filterBySymbol );
168  m_typeFilter->SetSelection( g_typeFilterIsPower ? 1 : 0 );
169  m_typeFilterOpt->SetValue( g_filterByType );
170 
171  if( g_filterByNet && !g_netFilter.IsEmpty() )
172  {
173  m_netFilter->SetValue( g_netFilter );
174  m_netFilterOpt->SetValue( true );
175  }
176  else if( m_parent->GetHighlightedConnection() )
177  {
179  }
180  else if( selection.GetSize() )
181  {
182  SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
183  SCH_CONNECTION* connection = sch_item->Connection( m_parent->GetCurrentSheet() );
184 
185  if( connection )
186  m_netFilter->SetValue( connection->Name() );
187  }
188 
189  m_netFilterOpt->SetValue( g_filterByNet );
190 
192  m_orientation->SetStringSelection( INDETERMINATE_ACTION );
193  m_hAlign->SetStringSelection( INDETERMINATE_ACTION );
194  m_vAlign->SetStringSelection( INDETERMINATE_ACTION );
195  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
196  m_Bold->Set3StateValue( wxCHK_UNDETERMINED );
197  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
199  m_lineStyle->SetStringSelection( INDETERMINATE_ACTION );
200  m_setColor->SetValue( false );
201  m_setBgColor->SetValue( false );
202 
203  return true;
204 }
205 
206 
208 {
209 }
210 
211 
213  SCH_ITEM* aItem )
214 {
215  auto eda_text = dynamic_cast<EDA_TEXT*>( aItem );
216  auto sch_text = dynamic_cast<SCH_TEXT*>( aItem );
217  auto lineItem = dynamic_cast<SCH_LINE*>( aItem );
218 
220 
221  if( eda_text )
222  {
223  if( !m_textSize.IsIndeterminate() )
224  {
225  eda_text->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
226  m_hasChange = true;
227  }
228 
229  if( m_hAlign->GetStringSelection() != INDETERMINATE_ACTION )
230  {
231  eda_text->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_hAlign->GetSelection() - 1 ) );
232  m_hasChange = true;
233  }
234 
235  if( m_hAlign->GetStringSelection() != INDETERMINATE_ACTION )
236  {
237  eda_text->SetVertJustify( EDA_TEXT::MapVertJustify( m_vAlign->GetSelection() - 1 ) );
238  m_hasChange = true;
239  }
240 
241  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED )
242  {
243  eda_text->SetVisible( m_Visible->GetValue() );
244  m_hasChange = true;
245  }
246 
247  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED )
248  {
249  eda_text->SetItalic( m_Italic->GetValue() );
250  m_hasChange = true;
251  }
252 
253  if( m_Bold->Get3StateValue() != wxCHK_UNDETERMINED )
254  {
255  eda_text->SetBold( m_Bold->GetValue() );
256  m_hasChange = true;
257  }
258  }
259 
260  // No else! Labels are both.
261  if( sch_text )
262  {
263  if( m_orientation->GetStringSelection() != INDETERMINATE_ACTION )
264  {
265  sch_text->SetLabelSpinStyle( (LABEL_SPIN_STYLE::SPIN) m_orientation->GetSelection() );
266  m_hasChange = true;
267  }
268  }
269 
270  if( lineItem )
271  {
273  {
274  lineItem->SetLineWidth( m_lineWidth.GetValue() );
275  m_hasChange = true;
276  }
277 
278  if( m_lineStyle->GetStringSelection() != INDETERMINATE_ACTION )
279  {
280  lineItem->SetLineStyle( m_lineStyle->GetSelection() );
281  m_hasChange = true;
282  }
283 
284  if( m_setColor->GetValue() )
285  {
286  lineItem->SetLineColor( m_colorSwatch->GetSwatchColor() );
287  m_hasChange = true;
288  }
289  }
290 }
291 
293  SCH_ITEM* aItem )
294 {
295  if( m_netFilterOpt->GetValue() && !m_netFilter->GetValue().IsEmpty() )
296  {
297  SCH_CONNECTION* connection = aItem->Connection( aSheetPath );
298 
299  if( !connection )
300  return;
301 
302  if( !WildCompareString( m_netFilter->GetValue(), connection->Name(), false ) )
303  return;
304  }
305 
306  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
307  {
308  if( aItem->Type() == SCH_COMPONENT_T )
309  {
310  wxString ref = static_cast<SCH_COMPONENT*>( aItem )->GetRef( &aSheetPath );
311 
312  if( !WildCompareString( m_referenceFilter->GetValue(), ref, false ) )
313  return;
314  }
315  }
316 
317  if( m_symbolFilterOpt->GetValue() && !m_symbolFilter->GetValue().IsEmpty() )
318  {
319  if( aItem->Type() == SCH_COMPONENT_T )
320  {
321  wxString id = static_cast<SCH_COMPONENT*>( aItem )->GetLibId().Format();
322 
323  if( !WildCompareString( m_symbolFilter->GetValue(), id, false ) )
324  return;
325  }
326  }
327 
328  if( m_typeFilterOpt->GetValue() )
329  {
330  if( aItem->Type() == SCH_COMPONENT_T )
331  {
332  bool isPower = static_cast<SCH_COMPONENT*>( aItem )->GetPartRef()->IsPower();
333 
334  if( isPower != ( m_typeFilter->GetSelection() == 1 ) )
335  return;
336  }
337  }
338 
339  static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LABEL_LOCATE_WIRE_T, EOT };
340  static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, SCH_LABEL_LOCATE_BUS_T, EOT };
341  static KICAD_T schTextAndGraphics[] = { SCH_TEXT_T, SCH_LINE_LOCATE_GRAPHIC_LINE_T, EOT };
342 
343  if( aItem->Type() == SCH_COMPONENT_T )
344  {
345  SCH_COMPONENT* component = (SCH_COMPONENT*) aItem;
346 
347  if( m_references->GetValue() )
348  processItem( aSheetPath, component->GetField( REFERENCE ) );
349 
350  if( m_values->GetValue() )
351  processItem( aSheetPath, component->GetField( VALUE ) );
352 
353  if( m_otherFields->GetValue() )
354  {
355  for( int i = 2; i < component->GetFieldCount(); ++i )
356  {
357  SCH_FIELD* field = component->GetField( i );
358  const wxString& fieldName = field->GetName();
359 
360  if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
361  || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
362  {
363  processItem( aSheetPath, field );
364  }
365  }
366  }
367  }
368  else if( aItem->Type() == SCH_SHEET_T )
369  {
370  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
371 
372  if( m_sheetTitles->GetValue() )
373  processItem( aSheetPath, &sheet->GetFields()[ SHEETNAME ] );
374 
375  if( m_sheetFields->GetValue() )
376  {
377  for( SCH_FIELD& field : sheet->GetFields() )
378  {
379  if( field.GetId() == SHEETNAME )
380  continue;
381 
382  const wxString& fieldName = field.GetName();
383 
384  if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
385  || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
386  {
387  processItem( aSheetPath, &field );
388  }
389  }
390  }
391 
392  if( m_sheetBorders->GetValue() )
393  {
395  {
396  sheet->SetBorderWidth( m_lineWidth.GetValue() );
397  m_hasChange = true;
398  }
399 
400  if( m_setColor->GetValue() )
401  {
403  m_hasChange = true;
404  }
405 
406  if( m_setBgColor->GetValue() )
407  {
409  m_hasChange = true;
410  }
411  }
412  }
413  else if( m_wires->GetValue() && aItem->IsType( wireTypes ) )
414  processItem( aSheetPath, aItem );
415  else if( m_buses->GetValue() && aItem->IsType( busTypes ) )
416  processItem( aSheetPath, aItem );
417  else if( m_globalLabels->GetValue() && aItem->Type() == SCH_GLOBAL_LABEL_T )
418  processItem( aSheetPath, aItem );
419  else if( m_hierLabels->GetValue() && aItem->Type() == SCH_HIER_LABEL_T )
420  processItem( aSheetPath, aItem );
421  else if( m_sheetPins->GetValue() && aItem->Type() == SCH_SHEET_PIN_T )
422  processItem( aSheetPath, aItem );
423  else if( m_schTextAndGraphics->GetValue() && aItem->IsType( schTextAndGraphics ) )
424  processItem( aSheetPath, aItem );
425 }
426 
427 
429 {
430  if( !m_textSize.Validate( Mils2iu( 1 ), Mils2iu( 10000 ) ) ) // 1 mil .. 10 inches
431  return false;
432 
433  SCH_SHEET_PATH currentSheet = m_parent->GetCurrentSheet();
434 
435  // Go through sheets
436  for( const SCH_SHEET_PATH& sheetPath : m_parent->Schematic().GetSheets() )
437  {
438  SCH_SCREEN* screen = sheetPath.LastScreen();
439 
440  if( screen )
441  {
442  m_parent->SetCurrentSheet( sheetPath );
443  m_hasChange = false;
444 
445  for( auto item : screen->Items() )
446  visitItem( sheetPath, item );
447 
448  if( m_hasChange )
449  {
450  m_parent->OnModify();
451  m_parent->HardRedraw();
452  }
453  }
454  }
455 
456  // Reset the view to where we left the user
457  m_parent->SetCurrentSheet( currentSheet );
458 
459  return true;
460 }
461 
462 
464 {
466  dlg.ShowModal();
467  return 0;
468 }
469 
470 
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
KIGFX::COLOR4D GetSwatchColor() const
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:99
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generates the connection data for the entire schematic hierarchy.
const SCH_CONNECTION * GetHighlightedConnection() const
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
void SetBorderWidth(int aWidth)
Definition: sch_sheet.h:288
EE_SELECTION & GetSelection()
Function GetSelection()
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
#define VALUE
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:294
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:58
void HardRedraw() override
Rebuild the GAL and redraw the screen.
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:467
TOOL_EVENT.
Definition: tool_event.h:171
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend=false, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
SCHEMATIC & Schematic() const
void SetBorderColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:291
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:269
const wxString & Name(bool aIgnoreSheet=false) const
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:147
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
static bool m_allowRealTime
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
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:420
EE_RTREE & Items()
Definition: sch_screen.h:162
#define INDETERMINATE_ACTION
Schematic symbol object.
Definition: sch_component.h:88
void processItem(const SCH_SHEET_PATH &aSheetPath, SCH_ITEM *aItem)
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
SCH_SHEET_PATH & GetCurrentSheet() const
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:151
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197