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 
110 
111  m_sdbSizerButtonsOK->SetDefault();
112 
114 }
115 
116 
118 {
119  g_modifyReferences = m_references->GetValue();
120  g_modifyValues = m_values->GetValue();
121  g_modifyOtherFields = m_otherFields->GetValue();
122  g_modifyWires = m_wires->GetValue();
123  g_modifyBuses = m_buses->GetValue();
124  g_modifyGlobalLabels = m_globalLabels->GetValue();
125  g_modifyHierLabels = m_hierLabels->GetValue();
126  g_modifySheetTitles = m_sheetTitles->GetValue();
128  g_modifySheetPins = m_sheetPins->GetValue();
129  g_modifySheetBorders = m_sheetBorders->GetValue();
131 
133  g_fieldnameFilter = m_fieldnameFilter->GetValue();
135  g_referenceFilter = m_referenceFilter->GetValue();
136  g_filterBySymbol = m_symbolFilterOpt->GetValue();
137  g_symbolFilter = m_symbolFilter->GetValue();
138  g_filterByType = m_typeFilterOpt->GetValue();
139  g_typeFilterIsPower = m_typeFilter->GetSelection() == 1;
140  g_filterByNet = m_netFilterOpt->GetValue();
141  g_netFilter = m_netFilter->GetValue();
142 }
143 
144 
146 {
148  SELECTION& selection = selectionTool->GetSelection();
149 
150  m_references->SetValue( g_modifyReferences );
151  m_values->SetValue( g_modifyValues );
152  m_otherFields->SetValue( g_modifyOtherFields );
153  m_wires->SetValue( g_modifyWires );
154  m_buses->SetValue( g_modifyBuses );
156  m_hierLabels->SetValue( g_modifyHierLabels );
157  m_sheetTitles->SetValue( g_modifySheetTitles );
159  m_sheetPins->SetValue( g_modifySheetPins );
162 
163  // SetValue() generates events, ChangeValue() does not
164  m_fieldnameFilter->ChangeValue( g_fieldnameFilter );
166  m_referenceFilter->ChangeValue( g_referenceFilter );
168  m_symbolFilter->ChangeValue( g_symbolFilter );
169  m_symbolFilterOpt->SetValue( g_filterBySymbol );
170  m_typeFilter->SetSelection( g_typeFilterIsPower ? 1 : 0 );
171  m_typeFilterOpt->SetValue( g_filterByType );
172 
173  if( g_filterByNet && !g_netFilter.IsEmpty() )
174  {
175  m_netFilter->SetValue( g_netFilter );
176  m_netFilterOpt->SetValue( true );
177  }
178  else if( m_parent->GetHighlightedConnection() )
179  {
181  }
182  else if( selection.GetSize() )
183  {
184  SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
185  SCH_CONNECTION* connection = sch_item->Connection( m_parent->GetCurrentSheet() );
186 
187  if( connection )
188  m_netFilter->SetValue( connection->Name() );
189  }
190 
191  m_netFilterOpt->SetValue( g_filterByNet );
192 
194  m_orientation->SetStringSelection( INDETERMINATE_ACTION );
195  m_hAlign->SetStringSelection( INDETERMINATE_ACTION );
196  m_vAlign->SetStringSelection( INDETERMINATE_ACTION );
197  m_Italic->Set3StateValue( wxCHK_UNDETERMINED );
198  m_Bold->Set3StateValue( wxCHK_UNDETERMINED );
199  m_Visible->Set3StateValue( wxCHK_UNDETERMINED );
201  m_lineStyle->SetStringSelection( INDETERMINATE_ACTION );
202  m_setColor->SetValue( false );
203  m_setBgColor->SetValue( false );
204 
205  return true;
206 }
207 
208 
210 {
211 }
212 
213 
215  SCH_ITEM* aItem )
216 {
217  auto eda_text = dynamic_cast<EDA_TEXT*>( aItem );
218  auto sch_text = dynamic_cast<SCH_TEXT*>( aItem );
219  auto lineItem = dynamic_cast<SCH_LINE*>( aItem );
220 
221  m_parent->SaveCopyInUndoList( aSheetPath.LastScreen(), aItem, UR_CHANGED, m_hasChange );
222 
223  if( eda_text )
224  {
225  if( !m_textSize.IsIndeterminate() )
226  {
227  eda_text->SetTextSize( wxSize( m_textSize.GetValue(), m_textSize.GetValue() ) );
228  m_hasChange = true;
229  }
230 
231  if( m_hAlign->GetStringSelection() != INDETERMINATE_ACTION )
232  {
233  eda_text->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_hAlign->GetSelection() - 1 ) );
234  m_hasChange = true;
235  }
236 
237  if( m_hAlign->GetStringSelection() != INDETERMINATE_ACTION )
238  {
239  eda_text->SetVertJustify( EDA_TEXT::MapVertJustify( m_vAlign->GetSelection() - 1 ) );
240  m_hasChange = true;
241  }
242 
243  if( m_Visible->Get3StateValue() != wxCHK_UNDETERMINED )
244  {
245  eda_text->SetVisible( m_Visible->GetValue() );
246  m_hasChange = true;
247  }
248 
249  if( m_Italic->Get3StateValue() != wxCHK_UNDETERMINED )
250  {
251  eda_text->SetItalic( m_Italic->GetValue() );
252  m_hasChange = true;
253  }
254 
255  if( m_Bold->Get3StateValue() != wxCHK_UNDETERMINED )
256  {
257  eda_text->SetBold( m_Bold->GetValue() );
258  m_hasChange = true;
259  }
260  }
261 
262  // No else! Labels are both.
263  if( sch_text )
264  {
265  if( m_orientation->GetStringSelection() != INDETERMINATE_ACTION )
266  {
267  sch_text->SetLabelSpinStyle( (LABEL_SPIN_STYLE::SPIN) m_orientation->GetSelection() );
268  m_hasChange = true;
269  }
270  }
271 
272  if( lineItem )
273  {
275  {
276  lineItem->SetLineWidth( m_lineWidth.GetValue() );
277  m_hasChange = true;
278  }
279 
280  if( m_lineStyle->GetStringSelection() != INDETERMINATE_ACTION )
281  {
282  lineItem->SetLineStyle( m_lineStyle->GetSelection() );
283  m_hasChange = true;
284  }
285 
286  if( m_setColor->GetValue() )
287  {
288  lineItem->SetLineColor( m_colorSwatch->GetSwatchColor() );
289  m_hasChange = true;
290  }
291  }
292 }
293 
295  SCH_ITEM* aItem )
296 {
297  if( m_netFilterOpt->GetValue() && !m_netFilter->GetValue().IsEmpty() )
298  {
299  SCH_CONNECTION* connection = aItem->Connection( aSheetPath );
300 
301  if( !connection )
302  return;
303 
304  if( !WildCompareString( m_netFilter->GetValue(), connection->Name(), false ) )
305  return;
306  }
307 
308  if( m_referenceFilterOpt->GetValue() && !m_referenceFilter->GetValue().IsEmpty() )
309  {
310  if( aItem->Type() == SCH_COMPONENT_T )
311  {
312  wxString ref = static_cast<SCH_COMPONENT*>( aItem )->GetRef( &aSheetPath );
313 
314  if( !WildCompareString( m_referenceFilter->GetValue(), ref, false ) )
315  return;
316  }
317  }
318 
319  if( m_symbolFilterOpt->GetValue() && !m_symbolFilter->GetValue().IsEmpty() )
320  {
321  if( aItem->Type() == SCH_COMPONENT_T )
322  {
323  wxString id = static_cast<SCH_COMPONENT*>( aItem )->GetLibId().Format();
324 
325  if( !WildCompareString( m_symbolFilter->GetValue(), id, false ) )
326  return;
327  }
328  }
329 
330  if( m_typeFilterOpt->GetValue() )
331  {
332  if( aItem->Type() == SCH_COMPONENT_T )
333  {
334  bool isPower = static_cast<SCH_COMPONENT*>( aItem )->GetPartRef()->IsPower();
335 
336  if( isPower != ( m_typeFilter->GetSelection() == 1 ) )
337  return;
338  }
339  }
340 
341  static KICAD_T wireTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LABEL_LOCATE_WIRE_T, EOT };
342  static KICAD_T busTypes[] = { SCH_LINE_LOCATE_BUS_T, SCH_LABEL_LOCATE_BUS_T, EOT };
343  static KICAD_T schTextAndGraphics[] = { SCH_TEXT_T, SCH_LINE_LOCATE_GRAPHIC_LINE_T, EOT };
344 
345  if( aItem->Type() == SCH_COMPONENT_T )
346  {
347  SCH_COMPONENT* component = (SCH_COMPONENT*) aItem;
348 
349  if( m_references->GetValue() )
350  processItem( aSheetPath, component->GetField( REFERENCE ) );
351 
352  if( m_values->GetValue() )
353  processItem( aSheetPath, component->GetField( VALUE ) );
354 
355  if( m_otherFields->GetValue() )
356  {
357  for( int i = 2; i < component->GetFieldCount(); ++i )
358  {
359  SCH_FIELD* field = component->GetField( i );
360  const wxString& fieldName = field->GetName();
361 
362  if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
363  || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
364  {
365  processItem( aSheetPath, field );
366  }
367  }
368  }
369  }
370  else if( aItem->Type() == SCH_SHEET_T )
371  {
372  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
373 
374  if( m_sheetTitles->GetValue() )
375  processItem( aSheetPath, &sheet->GetFields()[ SHEETNAME ] );
376 
377  if( m_sheetFields->GetValue() )
378  {
379  for( SCH_FIELD& field : sheet->GetFields() )
380  {
381  if( field.GetId() == SHEETNAME )
382  continue;
383 
384  const wxString& fieldName = field.GetName();
385 
386  if( !m_fieldnameFilterOpt->GetValue() || m_fieldnameFilter->GetValue().IsEmpty()
387  || WildCompareString( m_fieldnameFilter->GetValue(), fieldName, false ) )
388  {
389  processItem( aSheetPath, &field );
390  }
391  }
392  }
393 
394  if( m_sheetBorders->GetValue() )
395  {
397  {
398  sheet->SetBorderWidth( m_lineWidth.GetValue() );
399  m_hasChange = true;
400  }
401 
402  if( m_setColor->GetValue() )
403  {
405  m_hasChange = true;
406  }
407 
408  if( m_setBgColor->GetValue() )
409  {
411  m_hasChange = true;
412  }
413  }
414  }
415  else if( m_wires->GetValue() && aItem->IsType( wireTypes ) )
416  processItem( aSheetPath, aItem );
417  else if( m_buses->GetValue() && aItem->IsType( busTypes ) )
418  processItem( aSheetPath, aItem );
419  else if( m_globalLabels->GetValue() && aItem->Type() == SCH_GLOBAL_LABEL_T )
420  processItem( aSheetPath, aItem );
421  else if( m_hierLabels->GetValue() && aItem->Type() == SCH_HIER_LABEL_T )
422  processItem( aSheetPath, aItem );
423  else if( m_sheetPins->GetValue() && aItem->Type() == SCH_SHEET_PIN_T )
424  processItem( aSheetPath, aItem );
425  else if( m_schTextAndGraphics->GetValue() && aItem->IsType( schTextAndGraphics ) )
426  processItem( aSheetPath, aItem );
427 }
428 
429 
431 {
432  if( !m_textSize.Validate( 1.0, 10000.0, EDA_UNITS::INCHES, true ) ) // 1 mil .. 10 inches
433  return false;
434 
435  SCH_SHEET_PATH currentSheet = m_parent->GetCurrentSheet();
436 
437  // Go through sheets
438  for( const SCH_SHEET_PATH& sheetPath : m_parent->Schematic().GetSheets() )
439  {
440  SCH_SCREEN* screen = sheetPath.LastScreen();
441 
442  if( screen )
443  {
444  m_parent->SetCurrentSheet( sheetPath );
445  m_hasChange = false;
446 
447  for( auto item : screen->Items() )
448  visitItem( sheetPath, item );
449 
450  if( m_hasChange )
451  {
452  m_parent->OnModify();
453  m_parent->HardRedraw();
454  }
455  }
456  }
457 
458  // Reset the view to where we left the user
459  m_parent->SetCurrentSheet( currentSheet );
460 
461  return true;
462 }
463 
464 
466 {
468  dlg.ShowModal();
469  return 0;
470 }
471 
472 
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:92
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
void SetBackgroundColor(KIGFX::COLOR4D aColor)
Definition: sch_sheet.h:294
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:63
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:461
TOOL_EVENT.
Definition: tool_event.h:171
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:262
const wxString & Name(bool aIgnoreSheet=false) const
SCH_SHEET_PATH.
int GetFieldCount() const
Return the number of fields in this symbol.
static EDA_TEXT_VJUSTIFY_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:77
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:150
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.
Field Value of part, i.e. "3.3K".
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
Function Validate Validates the control against the given range, informing the user of any errors fou...
SCH_SCREEN * LastScreen()
Function LastScreen.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO_T 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 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:438
EE_RTREE & Items()
Definition: sch_screen.h:158
#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...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193