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