KiCad PCB EDA Suite
sch_drawing_tools.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 "sch_drawing_tools.h"
25 #include "ee_selection_tool.h"
26 #include <ee_actions.h>
27 
28 #include <sch_edit_frame.h>
29 #include <sch_view.h>
30 #include <class_draw_panel_gal.h>
31 #include <project.h>
32 #include <id.h>
33 #include <eeschema_id.h>
34 #include <confirm.h>
35 #include <view/view_group.h>
36 #include <view/view_controls.h>
37 #include <view/view.h>
38 #include <tool/tool_manager.h>
39 #include <ee_hotkeys.h>
40 #include <sch_component.h>
41 #include <sch_no_connect.h>
42 #include <sch_junction.h>
43 #include <sch_bus_entry.h>
44 #include <sch_text.h>
45 #include <sch_sheet.h>
46 #include <sch_bitmap.h>
47 #include <class_library.h>
48 
49 
50 // Drawing tool actions
51 TOOL_ACTION EE_ACTIONS::placeSymbol( "eeschema.InteractiveDrawing.placeSymbol",
53  _( "Add Symbol" ), _( "Add a symbol" ),
54  add_component_xpm, AF_ACTIVATE );
55 
56 TOOL_ACTION EE_ACTIONS::placePower( "eeschema.InteractiveDrawing.placePowerPort",
58  _( "Add Power" ), _( "Add a power port" ),
59  add_power_xpm, AF_ACTIVATE );
60 
61 TOOL_ACTION EE_ACTIONS::placeNoConnect( "eeschema.InteractiveDrawing.placeNoConnect",
63  _( "Add No Connect Flag" ), _( "Add a no-connection flag" ),
64  noconn_xpm, AF_ACTIVATE );
65 
66 TOOL_ACTION EE_ACTIONS::placeJunction( "eeschema.InteractiveDrawing.placeJunction",
68  _( "Add Junction" ), _( "Add a junction" ),
69  add_junction_xpm, AF_ACTIVATE );
70 
71 TOOL_ACTION EE_ACTIONS::placeBusWireEntry( "eeschema.InteractiveDrawing.placeBusWireEntry",
73  _( "Add Wire to Bus Entry" ), _( "Add a wire entry to a bus" ),
74  add_line2bus_xpm, AF_ACTIVATE );
75 
76 TOOL_ACTION EE_ACTIONS::placeBusBusEntry( "eeschema.InteractiveDrawing.placeBusBusEntry",
78  _( "Add Bus to Bus Entry" ), _( "Add a bus entry to a bus" ),
79  add_bus2bus_xpm, AF_ACTIVATE );
80 
81 TOOL_ACTION EE_ACTIONS::placeLabel( "eeschema.InteractiveDrawing.placeLabel",
83  _( "Add Label" ), _( "Add a net label" ),
84  add_line_label_xpm, AF_ACTIVATE );
85 
86 TOOL_ACTION EE_ACTIONS::placeHierarchicalLabel( "eeschema.InteractiveDrawing.placeHierarchicalLabel",
88  _( "Add Hierarchical Label" ), _( "Add a hierarchical sheet label" ),
89  add_hierarchical_label_xpm, AF_ACTIVATE );
90 
91 TOOL_ACTION EE_ACTIONS::drawSheet( "eeschema.InteractiveDrawing.drawSheet",
93  _( "Add Sheet" ), _( "Add a hierarchical sheet" ),
94  add_hierarchical_subsheet_xpm, AF_ACTIVATE );
95 
96 TOOL_ACTION EE_ACTIONS::placeSheetPin( "eeschema.InteractiveDrawing.placeSheetPin",
97  AS_GLOBAL, 0, _( "Add Sheet Pin" ), _( "Add a sheet pin" ),
98  add_hierar_pin_xpm, AF_ACTIVATE );
99 
100 TOOL_ACTION EE_ACTIONS::importSheetPin( "eeschema.InteractiveDrawing.importSheetPin",
101  AS_GLOBAL, 0, _( "Import Sheet Pin" ), _( "Import a hierarchical sheet pin" ),
102  import_hierarchical_label_xpm, AF_ACTIVATE );
103 
104 TOOL_ACTION EE_ACTIONS::placeGlobalLabel( "eeschema.InteractiveDrawing.placeGlobalLabel",
106  _( "Add Global Label" ), _( "Add a global label" ),
107  add_glabel_xpm, AF_ACTIVATE );
108 
109 TOOL_ACTION EE_ACTIONS::placeSchematicText( "eeschema.InteractiveDrawing.placeSchematicText",
111  _( "Add Text" ), _( "Add text" ),
113 
114 TOOL_ACTION EE_ACTIONS::placeImage( "eeschema.InteractiveDrawing.placeImage",
115  AS_GLOBAL, 0, _( "Add Image" ), _( "Add bitmap image" ),
116  image_xpm, AF_ACTIVATE );
117 
118 TOOL_ACTION EE_ACTIONS::finishSheet( "eeschema.InteractiveDrawing.finishSheet",
119  AS_GLOBAL, 0, _( "Finish Sheet" ), _( "Finish drawing sheet" ),
120  checked_ok_xpm, AF_NONE );
121 
122 TOOL_ACTION EE_ACTIONS::addJunction( "eeschema.InteractiveEditing.addJunction",
123  AS_GLOBAL, 0, _( "Add Junction" ), _( "Add a wire or bus junction" ),
124  add_junction_xpm, AF_NONE );
125 
126 TOOL_ACTION EE_ACTIONS::addLabel( "eeschema.InteractiveEditing.addLabel",
127  AS_GLOBAL, 0, _( "Add Label" ), _( "Add a label to a wire or bus" ),
128  add_line_label_xpm, AF_NONE );
129 
130 TOOL_ACTION EE_ACTIONS::addGlobalLabel( "eeschema.InteractiveEditing.addGlobalLabel",
131  AS_GLOBAL, 0, _( "Add Global Label" ), _( "Add a global label to a wire or bus" ),
132  add_glabel_xpm, AF_NONE );
133 
134 TOOL_ACTION EE_ACTIONS::addHierLabel( "eeschema.InteractiveEditing.addHierLabel",
135  AS_GLOBAL, 0, _( "Add Hierarchical Label" ), _( "Add a hierarchical label to a wire or bus" ),
136  add_hierarchical_label_xpm, AF_NONE );
137 
138 
140  EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveDrawing" )
141 {
142 }
143 
144 
146 {
147 }
148 
149 
151 {
153 
154  auto belowRootSheetCondition = [] ( const SELECTION& aSel ) {
155  return g_CurrentSheet->Last() != g_RootSheet;
156  };
157 
158  auto& ctxMenu = m_menu.GetMenu();
159  ctxMenu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 2 );
160 
161  return true;
162 }
163 
164 
166 {
168 
171 
172  return 0;
173 }
174 
175 
177 {
179 
180  int layer = LAYER_NOTES;
181 
182  if( aEvent.IsAction( &EE_ACTIONS::addLabel ) )
183  layer = LAYER_LOCLABEL;
184  else if( aEvent.IsAction( &EE_ACTIONS::addGlobalLabel ) )
185  layer = LAYER_GLOBLABEL;
186  else if( aEvent.IsAction( &EE_ACTIONS::addHierLabel ) )
187  layer = LAYER_HIERLABEL;
188 
189  SCH_ITEM* item = m_frame->CreateNewText( layer );
191 
192  return 0;
193 }
194 
195 
196 // History lists for PlaceSymbol()
199 
200 
202 {
203  SCH_COMPONENT* component = aEvent.Parameter<SCH_COMPONENT*>();
204 
205  m_frame->SetToolID( ID_PLACE_SYMBOL_TOOL, wxCURSOR_PENCIL, _( "Add Symbol" ) );
206 
207  return doPlaceComponent( component, nullptr, s_SymbolHistoryList );
208 }
209 
210 
212 {
213  SCH_COMPONENT* component = aEvent.Parameter<SCH_COMPONENT*>();
214  SCHLIB_FILTER filter;
215 
216  filter.FilterPowerParts( true );
217  m_frame->SetToolID( ID_PLACE_POWER_TOOL, wxCURSOR_PENCIL, _( "Add Power" ) );
218 
219  return doPlaceComponent( component, &filter, s_PowerHistoryList );
220 }
221 
222 
224  SCH_BASE_FRAME::HISTORY_LIST aHistoryList )
225 {
226  VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
227  getViewControls()->ShowCursor( true );
228 
229  Activate();
230 
231  // If a component was passed in get it ready for placement.
232  if( aComponent )
233  {
234  aComponent->SetFlags( IS_NEW | IS_MOVED );
235 
237  m_selectionTool->AddItemToSel( aComponent );
238 
239  // Queue up a refresh event so we don't have to wait for the next mouse-moved event
241  }
242 
243  // Main loop: keep receiving events
244  while( OPT_TOOL_EVENT evt = Wait() )
245  {
246  cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
247 
248  if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
249  {
250  if( aComponent )
251  {
253  m_view->ClearPreview();
254  delete aComponent;
255  aComponent = nullptr;
256 
257  if( !evt->IsActivate() )
258  continue;
259  }
260 
261  break;
262  }
263  else if( evt->IsClick( BUT_LEFT ) )
264  {
265  if( !aComponent )
266  {
268 
269  // Pick the module to be placed
271 
272  auto sel = m_frame->SelectCompFromLibTree( aFilter, aHistoryList, true, 1, 1,
274 
276 
277  // Restore cursor after dialog
279 
280  LIB_PART* part = sel.LibId.IsValid() ? m_frame->GetLibPart( sel.LibId ) : nullptr;
281 
282  if( !part )
283  continue;
284 
285  aComponent = new SCH_COMPONENT( *part, g_CurrentSheet, sel, (wxPoint) cursorPos );
286  aComponent->SetFlags( IS_NEW | IS_MOVED );
287 
288  // Be sure the link to the corresponding LIB_PART is OK:
289  aComponent->Resolve( *m_frame->Prj().SchSymbolLibTable() );
290 
291  if( m_frame->GetAutoplaceFields() )
292  aComponent->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
293 
294  m_frame->SaveCopyForRepeatItem( aComponent );
295 
296  m_view->ClearPreview();
297  m_view->AddToPreview( aComponent->Clone() );
298  m_selectionTool->AddItemToSel( aComponent );
299  }
300  else
301  {
302  m_frame->AddItemToScreenAndUndoList( aComponent );
303  aComponent = nullptr;
304 
305  m_view->ClearPreview();
306  }
307  }
308  else if( evt->IsClick( BUT_RIGHT ) )
309  {
310  // Warp after context menu only if dragging...
311  if( !aComponent )
313 
315  }
316  else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CONTEXT_MENU_CHOICE )
317  {
318  if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
319  && evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_CMP_MAX )
320  {
321  int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
322 
323  if( aComponent )
324  {
325  m_frame->SelectUnit( aComponent, unit );
327  }
328  }
329  }
330  else if( aComponent && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
331  || evt->IsMotion() ) )
332  {
333  aComponent->SetPosition( (wxPoint)cursorPos );
334  m_view->ClearPreview();
335  m_view->AddToPreview( aComponent->Clone() );
336  }
337 
338  // Enable autopanning and cursor capture only when there is a module to be placed
339  getViewControls()->SetAutoPan( !!aComponent );
340  getViewControls()->CaptureCursor( !!aComponent );
341  }
342 
344 
345  return 0;
346 }
347 
348 
350 {
351  SCH_BITMAP* image = aEvent.Parameter<SCH_BITMAP*>();
352 
353  m_frame->SetToolID( ID_PLACE_IMAGE_TOOL, wxCURSOR_PENCIL, _( "Add image" ) );
354 
355  VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
356 
358  getViewControls()->ShowCursor( true );
359 
360  Activate();
361 
362  // Add all the drawable parts to preview
363  if( image )
364  {
365  image->SetPosition( (wxPoint)cursorPos );
366  m_view->ClearPreview();
367  m_view->AddToPreview( image->Clone() );
368  }
369 
370  // Main loop: keep receiving events
371  while( OPT_TOOL_EVENT evt = Wait() )
372  {
373  cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
374 
375  if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
376  {
377  if( image )
378  {
380  m_view->ClearPreview();
381  delete image;
382  image = nullptr;
383 
384  if( !evt->IsActivate() )
385  continue;
386  }
387 
388  break;
389  }
390  else if( evt->IsClick( BUT_LEFT ) )
391  {
392  if( !image )
393  {
395 
397 
398  wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, wxEmptyString,
399  _( "Image Files " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN );
400 
401  if( dlg.ShowModal() != wxID_OK )
402  continue;
403 
405 
406  // Restore cursor after dialog
408 
409  wxString fullFilename = dlg.GetPath();
410 
411  if( wxFileExists( fullFilename ) )
412  image = new SCH_BITMAP( (wxPoint)cursorPos );
413 
414  if( !image || !image->ReadImageFile( fullFilename ) )
415  {
416  wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
417  delete image;
418  image = nullptr;
419  continue;
420  }
421 
422  image->SetFlags( IS_NEW | IS_MOVED );
423 
424  m_frame->SaveCopyForRepeatItem( image );
425 
426  m_view->ClearPreview();
427  m_view->AddToPreview( image->Clone() );
428  m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
429 
430  m_selectionTool->AddItemToSel( image );
431 
432  getViewControls()->SetCursorPosition( cursorPos, false );
433  }
434  else
435  {
437  image = nullptr;
438 
439  m_view->ClearPreview();
440  }
441  }
442  else if( evt->IsClick( BUT_RIGHT ) )
443  {
444  // Warp after context menu only if dragging...
445  if( !image )
447 
449  }
450  else if( image && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
451  || evt->IsMotion() ) )
452  {
453  image->SetPosition( (wxPoint)cursorPos );
454  m_view->ClearPreview();
455  m_view->AddToPreview( image->Clone() );
456  m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
457  }
458 
459  // Enable autopanning and cursor capture only when there is a module to be placed
460  getViewControls()->SetAutoPan( !!image );
461  getViewControls()->CaptureCursor( !!image );
462  }
463 
465 
466  return 0;
467 }
468 
469 
471 {
472  m_frame->SetToolID( ID_NOCONNECT_TOOL, wxCURSOR_PENCIL, _( "Add no connect" ) );
474 }
475 
476 
478 {
479  m_frame->SetToolID( ID_JUNCTION_TOOL, wxCURSOR_PENCIL, _( "Add junction" ) );
481 }
482 
483 
485 {
486  m_frame->SetToolID( ID_WIRETOBUS_ENTRY_TOOL, wxCURSOR_PENCIL, _( "Add wire to bus entry" ) );
488 }
489 
490 
492 {
493  m_frame->SetToolID( ID_BUSTOBUS_ENTRY_TOOL, wxCURSOR_PENCIL, _( "Add bus to bus entry" ) );
495 }
496 
497 
499 {
500  wxPoint cursorPos;
501 
503  getViewControls()->ShowCursor( true );
504  getViewControls()->SetSnapping( true );
505 
506  Activate();
507 
508  // Main loop: keep receiving events
509  while( OPT_TOOL_EVENT evt = Wait() )
510  {
511  cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
512 
513  if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
514  {
515  break;
516  }
517  else if( evt->IsClick( BUT_LEFT ) )
518  {
519  SCH_ITEM* item = nullptr;
520 
521  if( !m_frame->GetScreen()->GetItem( cursorPos, 0, aType ) )
522  {
523  switch( aType )
524  {
525  case SCH_NO_CONNECT_T:
526  item = new SCH_NO_CONNECT( cursorPos );
527  break;
528  case SCH_JUNCTION_T:
529  item = m_frame->AddJunction( cursorPos );
530  break;
532  item = new SCH_BUS_WIRE_ENTRY( cursorPos, g_lastBusEntryShape );
533  break;
534  case SCH_BUS_BUS_ENTRY_T:
535  item = new SCH_BUS_BUS_ENTRY( cursorPos, g_lastBusEntryShape );
536  break;
537  default:
538  wxFAIL_MSG( "doSingleClickPlace(): unknown type" );
539  }
540  }
541 
542  if( item )
543  {
544  item->SetFlags( IS_NEW );
546 
548 
551  m_frame->OnModify();
552  }
553  }
554  else if( evt->IsClick( BUT_RIGHT ) )
555  {
557  }
558  }
559 
561 
562  return 0;
563 }
564 
565 
567 {
568  m_frame->SetToolID( ID_LABEL_TOOL, wxCURSOR_PENCIL, _( "Add net label" ) );
569  return doTwoClickPlace( SCH_LABEL_T );
570 }
571 
572 
574 {
575  m_frame->SetToolID( ID_GLOBALLABEL_TOOL, wxCURSOR_PENCIL, _( "Add global label" ) );
577 }
578 
579 
581 {
582  m_frame->SetToolID( ID_HIERLABEL_TOOL, wxCURSOR_PENCIL, _( "Add hierarchical label" ) );
584 }
585 
586 
588 {
589  m_frame->SetToolID( ID_SHEETPIN_TOOL, wxCURSOR_PENCIL, _( "Add sheet pins" ) );
591 }
592 
593 
595 {
596  m_frame->SetToolID( ID_IMPORT_SHEETPIN_TOOL, wxCURSOR_PENCIL, _( "Import sheet pins" ) );
598 }
599 
600 
602 {
603  m_frame->SetToolID( ID_SCHEMATIC_TEXT_TOOL, wxCURSOR_PENCIL, _( "Add text" ) );
604  return doTwoClickPlace( SCH_TEXT_T );
605 }
606 
607 
609 {
610  VECTOR2I cursorPos;
611  EDA_ITEM* item = nullptr;
612 
614  getViewControls()->ShowCursor( true );
615 
616  Activate();
617 
618  // Main loop: keep receiving events
619  while( OPT_TOOL_EVENT evt = Wait() )
620  {
621  cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
622 
623  if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
624  {
625  if( item )
626  {
628  m_view->ClearPreview();
629  delete item;
630  item = nullptr;
631 
632  if( !evt->IsActivate() )
633  continue;
634  }
635 
636  break;
637  }
638  else if( evt->IsClick( BUT_LEFT ) )
639  {
640  // First click creates...
641  if( !item )
642  {
645 
646  switch( aType )
647  {
648  case SCH_LABEL_T:
650  break;
651  case SCH_HIER_LABEL_T:
653  break;
654  case SCH_GLOBAL_LABEL_T:
656  break;
657  case SCH_TEXT_T:
658  item = m_frame->CreateNewText( LAYER_NOTES );
659  break;
660  case SCH_SHEET_PIN_T:
662 
663  if( item )
664  {
666  item = m_frame->ImportSheetPin( (SCH_SHEET*) item );
667  else
668  item = m_frame->CreateSheetPin( (SCH_SHEET*) item );
669  }
670  break;
671  default:
672  wxFAIL_MSG( "doTwoClickPlace(): unknown type" );
673  }
674 
676 
677  // Restore cursor after dialog
679 
680  if( item )
681  {
682  item->SetFlags( IS_NEW | IS_MOVED );
683  m_view->ClearPreview();
684  m_view->AddToPreview( item->Clone() );
685  m_selectionTool->AddItemToSel( item );
686  }
687 
688  getViewControls()->SetCursorPosition( cursorPos, false );
689  }
690 
691  // ... and second click places:
692  else
693  {
695  item = nullptr;
696 
697  m_view->ClearPreview();
698  }
699  }
700  else if( evt->IsClick( BUT_RIGHT ) )
701  {
702  // Warp after context menu only if dragging...
703  if( !item )
705 
707  }
708  else if( item && TOOL_EVT_UTILS::IsSelectionEvent( evt.get() ) )
709  {
710  // This happens if our text was replaced out from under us by ConvertTextType()
711  SELECTION& selection = m_selectionTool->GetSelection();
712 
713  if( selection.GetSize() == 1 )
714  {
715  item = (SCH_ITEM*) selection.Front();
716  m_view->ClearPreview();
717  m_view->AddToPreview( item->Clone() );
718  }
719  else
720  item = nullptr;
721  }
722  else if( item && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
723  || evt->IsMotion() ) )
724  {
725  static_cast<SCH_ITEM*>( item )->SetPosition( (wxPoint)cursorPos );
726  m_view->ClearPreview();
727  m_view->AddToPreview( item->Clone() );
728  }
729 
730  // Enable autopanning and cursor capture only when there is a module to be placed
731  getViewControls()->SetAutoPan( !!item );
732  getViewControls()->CaptureCursor( !!item );
733  }
734 
736 
737  return 0;
738 }
739 
740 
742 {
743  m_frame->SetToolID( ID_SHEET_TOOL, wxCURSOR_PENCIL, _( "Add sheet" ) );
745  getViewControls()->ShowCursor( true );
746 
747  SCH_SHEET* sheet = nullptr;
748 
749  Activate();
750 
751  // Main loop: keep receiving events
752  while( auto evt = Wait() )
753  {
754  VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
755 
756  if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) )
757  {
759  m_view->ClearPreview();
760 
761  if( sheet )
762  {
763  delete sheet;
764  sheet = nullptr;
765 
766  if( !evt->IsActivate() )
767  continue;
768  }
769 
770  break;
771  }
772 
773  else if( evt->IsClick( BUT_LEFT ) && !sheet )
774  {
776 
777  sheet = new SCH_SHEET( (wxPoint) cursorPos );
778  sheet->SetFlags( IS_NEW | IS_RESIZED );
779  sheet->SetTimeStamp( GetNewTimeStamp() );
780  sheet->SetParent( m_frame->GetScreen() );
781  sheet->SetScreen( NULL );
782  sizeSheet( sheet, cursorPos );
783 
784  m_selectionTool->AddItemToSel( sheet );
785  m_view->ClearPreview();
786  m_view->AddToPreview( sheet->Clone() );
787  }
788 
789  else if( sheet && ( evt->IsClick( BUT_LEFT )
790  || evt->IsAction( &EE_ACTIONS::finishSheet ) ) )
791  {
792  m_view->ClearPreview();
793 
794  if( m_frame->EditSheet( (SCH_SHEET*)sheet, g_CurrentSheet, nullptr ) )
796  else
797  delete sheet;
798 
799  sheet = nullptr;
800  }
801 
802  else if( sheet && ( evt->IsAction( &EE_ACTIONS::refreshPreview )
803  || evt->IsMotion() ) )
804  {
805  sizeSheet( sheet, cursorPos );
806  m_view->ClearPreview();
807  m_view->AddToPreview( sheet->Clone() );
808  }
809 
810  else if( evt->IsClick( BUT_RIGHT ) )
811  {
812  // Warp after context menu only if dragging...
813  if( !sheet )
815 
817  }
818 
819  // Enable autopanning and cursor capture only when there is a sheet to be placed
820  getViewControls()->SetAutoPan( !!sheet );
821  getViewControls()->CaptureCursor( !!sheet );
822  }
823 
825 
826  return 0;
827 }
828 
829 
831 {
832  wxPoint pos = aSheet->GetPosition();
833  wxPoint size = (wxPoint) aPos - pos;
834 
835  size.x = std::max( size.x, MIN_SHEET_WIDTH );
836  size.y = std::max( size.y, MIN_SHEET_HEIGHT );
837 
838  wxPoint grid = m_frame->GetNearestGridPosition( pos + size );
839  aSheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
840 }
841 
842 
844 {
859 
864 }
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
SELECTION & GetSelection()
Function GetSelection()
Class for a bus to bus entry.
bool SchematicCleanUp(SCH_SCREEN *aScreen=nullptr)
Performs routine schematic cleaning including breaking wire and buses and deleting identical objects ...
int PlaceSchematicText(const TOOL_EVENT &aEvent)
void AddToPreview(EDA_ITEM *aItem, bool aTakeOwnership=true)
Definition: sch_view.cpp:145
static TOOL_ACTION finishSheet
Definition: ee_actions.h:103
static TOOL_ACTION addHierLabel
Definition: ee_actions.h:135
void FilterPowerParts(bool aFilterEnable)
set the filtering of power parts
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
SCH_TEXT * CreateNewText(int aType)
Definition: edit_label.cpp:47
char g_lastBusEntryShape
Definition: ee_actions.cpp:29
SCH_SHEET * Last() const
Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "pa...
This file is part of the common library.
VIEW_CONTROLS class definition.
bool Resolve(PART_LIBS *aLibs)
Assigns the current LIB_PART from aLibs which this symbol is based on.
virtual void MoveCursorToCrossHair() override
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
bool GetShowFootprintPreviews() const
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
int PlaceBusBusEntry(const TOOL_EVENT &aEvent)
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
static TOOL_ACTION placeJunction
Definition: ee_actions.h:86
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1401
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:104
int PlaceLabel(const TOOL_EVENT &aEvent)
static const KICAD_T SheetsAndSheetLabels[]
Definition: ee_collectors.h:46
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
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: sheet.cpp:345
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
static TOOL_ACTION refreshPreview
Definition: ee_actions.h:168
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
static int LegacyHotKey(int aHotKey)
Creates a hot key code that refers to a legacy hot key setting, instead of a particular key.
Definition: tool_action.h:165
std::vector< COMPONENT_SELECTION > HISTORY_LIST
bool IsSelectionEvent(const TOOL_EVENT &aEvt)
Function IsSelectionEvent()
Definition: tool_event.cpp:185
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
static SCH_BASE_FRAME::HISTORY_LIST s_PowerHistoryList
int PlaceBusWireEntry(const TOOL_EVENT &aEvent)
Schematic editor (Eeschema) main window.
static TOOL_ACTION placeBusBusEntry
Definition: ee_actions.h:88
LIB_PART * GetLibPart(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:87
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
int ImportSheetPin(const TOOL_EVENT &aEvent)
bool GetAutoplaceFields() const
int PlaceImage(const TOOL_EVENT &aEvent)
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
bool EditSheet(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, bool *aClearAnnotationNewItems)
Edit an existing sheet or add a new sheet to the schematic.
Definition: sheet.cpp:49
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
#define MIN_SHEET_WIDTH
Definition: sch_sheet.h:42
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:54
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:161
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:69
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static TOOL_ACTION drawSheet
Definition: ee_actions.h:92
int doTwoClickPlace(KICAD_T aType)
timestamp_t GetNewTimeStamp()
Definition: common.cpp:217
int PlaceSymbol(const TOOL_EVENT &aEvent)
static TOOL_ACTION placePower
Definition: ee_actions.h:79
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:259
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
COMPONENT_SELECTION SelectCompFromLibTree(const SCHLIB_FILTER *aFilter, std::vector< COMPONENT_SELECTION > &aHistoryList, bool aUseLibBrowser, int aUnit, int aConvert, bool aShowFootprints, const LIB_ID *aHighlight=nullptr, bool aAllowFields=true)
Function SelectComponentFromLib Calls the library viewer to select component to import into schematic...
Definition: getpart.cpp:95
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:219
static TOOL_ACTION placeSheetPin
Definition: ee_actions.h:93
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:378
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:95
SCH_DRAW_PANEL * GetCanvas() const override
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Class TOOL_EVENT.
Definition: tool_event.h:167
static TOOL_ACTION placeImage
Definition: ee_actions.h:98
void ClearPreview()
Definition: sch_view.cpp:133
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T) const
Check aPosition within a distance of aAccuracy for items of type aFilter.
Definition: sch_screen.cpp:237
int PlaceHierarchicalLabel(const TOOL_EVENT &aEvent)
static TOOL_ACTION addJunction
Definition: ee_actions.h:132
Define a library symbol object.
void SaveCopyForRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
SCH_SHEET_PIN * ImportSheetPin(SCH_SHEET *aSheet)
Automatically create a sheet pin from the hierarchical labels in the schematic referenced by aSheet.
Definition: sheet.cpp:372
SCH_JUNCTION * AddJunction(const wxPoint &aPos, bool aAppendToUndo=false, bool aFinal=true)
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:143
int PlacePower(const TOOL_EVENT &aEvent)
static TOOL_ACTION importSheetPin
Definition: ee_actions.h:94
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:57
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:78
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg)
Set the tool command ID to aId and sets the cursor to aCursor.
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
Definition: tool_event.cpp:177
All active tools
Definition: tool_event.h:143
static TOOL_ACTION placeHierarchicalLabel
Definition: ee_actions.h:91
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:530
int PlaceJunction(const TOOL_EVENT &aEvent)
TOOL_MENU m_menu
Menu model displayed by the tool.
Definition: ee_tool_base.h:147
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
void SelectUnit(SCH_COMPONENT *aComponent, int aUnit)
Definition: getpart.cpp:207
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:201
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:98
static TOOL_ACTION placeLabel
Definition: ee_actions.h:89
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Return the nearest aGridSize location to aPosition.
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_sheet.cpp:98
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Automatically orient all the fields in the component.
int AddItemToSel(const TOOL_EVENT &aEvent)
#define max(a, b)
Definition: auxiliary.h:86
Class TOOL_ACTION.
Definition: tool_action.h:46
void SetIgnoreMouseEvents(bool aIgnore)
void VetoContextMenuMouseWarp()
Disables mouse warping after the current context menu is closed.
Definition: tool_manager.h:385
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:85
int PlaceGlobalLabel(const TOOL_EVENT &aEvent)
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_bitmap.cpp:86
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
#define MIN_SHEET_HEIGHT
Definition: sch_sheet.h:43
#define IS_RESIZED
Item being resized.
Definition: base_struct.h:115
int PlaceSheetPin(const TOOL_EVENT &aEvent)
int AddLabel(const TOOL_EVENT &aEvent)
int PlaceNoConnect(const TOOL_EVENT &aEvent)
Class for a wire to bus entry.
void Activate()
Function Activate() Runs the tool.
static TOOL_ACTION addLabel
Definition: ee_actions.h:133
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores an image file.
Definition: sch_bitmap.cpp:80
Class EE_TOOL_BASE.
Definition: ee_tool_base.h:49
int doSingleClickPlace(KICAD_T aType)
static const char * text_xpm[]
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
static TOOL_ACTION addGlobalLabel
Definition: ee_actions.h:134
EDA_ITEM * SelectPoint(const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems, bool *aSelectionCancelledFlag=NULL, bool aCheckLocked=false)
Function selectPoint() Selects an item pointed by the parameter aWhere.
Definition for part library class.
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:90
int doPlaceComponent(SCH_COMPONENT *aComponent, SCHLIB_FILTER *aFilter, SCH_BASE_FRAME::HISTORY_LIST aHistoryList)
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
Implementation of the label properties dialog.
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_bitmap.h:153
void setTransitions() override
Sets up handlers for various events.
int GetToolId() const
Definition: draw_frame.h:524
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false)=0
Moves cursor to the requested position expressed in world coordinates.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:155
int DrawSheet(const TOOL_EVENT &aEvent)
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:486
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:209
static SCH_BASE_FRAME::HISTORY_LIST s_SymbolHistoryList
void Resize(const wxSize &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
Definition: sch_sheet.cpp:702
void sizeSheet(SCH_SHEET *aSheet, VECTOR2I aPos)
void AddItemToScreenAndUndoList(SCH_ITEM *aItem, bool aUndoAppend=false)
Add an item to the schematic and adds the changes to the undo/redo container.
int AddJunction(const TOOL_EVENT &aEvent)
#define IS_MOVED
Item being moved.
Definition: base_struct.h:113