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 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include "sch_drawing_tools.h"
26 #include "ee_selection_tool.h"
27 #include "ee_point_editor.h"
28 #include <ee_actions.h>
29 #include <sch_edit_frame.h>
30 #include <sch_view.h>
31 #include <class_draw_panel_gal.h>
32 #include <project.h>
33 #include <id.h>
34 #include <eeschema_id.h>
35 #include <confirm.h>
36 #include <view/view_controls.h>
37 #include <view/view.h>
38 #include <sch_component.h>
39 #include <sch_no_connect.h>
40 #include <sch_line.h>
41 #include <sch_junction.h>
42 #include <sch_bus_entry.h>
43 #include <sch_text.h>
44 #include <sch_sheet.h>
45 #include <sch_bitmap.h>
46 #include <class_library.h>
47 
48 
50  EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveDrawing" )
51 {
52 }
53 
54 
56 {
58 
59  auto belowRootSheetCondition = [] ( const SELECTION& aSel ) {
60  return g_CurrentSheet->Last() != g_RootSheet;
61  };
62 
63  auto& ctxMenu = m_menu.GetMenu();
64  ctxMenu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 2 );
65 
66  return true;
67 }
68 
69 
70 // History lists for PlaceComponent()
73 
74 
76 {
77  SCH_COMPONENT* component = aEvent.Parameter<SCH_COMPONENT*>();
78  SCHLIB_FILTER filter;
79  SCH_BASE_FRAME::HISTORY_LIST* historyList = nullptr;
80 
81  if( aEvent.IsAction( &EE_ACTIONS::placeSymbol ) )
82  historyList = &s_SymbolHistoryList;
83  else if (aEvent.IsAction( &EE_ACTIONS::placePower ) )
84  {
85  historyList = &s_PowerHistoryList;
86  filter.FilterPowerParts( true );
87  }
88  else
89  wxFAIL_MSG( "PlaceCompontent(): unexpected request" );
90 
91  getViewControls()->ShowCursor( true );
92 
93  // If a component was passed in get it ready for placement.
94  if( component )
95  {
96  component->SetFlags( IS_NEW | IS_MOVED );
97 
99  m_selectionTool->AddItemToSel( component );
100  }
101 
102  std::string tool = aEvent.GetCommandStr().get();
103  m_frame->PushTool( tool );
104  Activate();
105 
106  // Prime the pump
107  if( component )
108  {
109  getViewControls()->WarpCursor( getViewControls()->GetMousePosition( false ) );
111  }
112  else if( aEvent.HasPosition() )
114 
115  // Main loop: keep receiving events
116  while( TOOL_EVENT* evt = Wait() )
117  {
118  m_frame->GetCanvas()->SetCurrentCursor( component ? wxCURSOR_ARROW : wxCURSOR_PENCIL );
119  VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
120 
121  auto cleanup = [&] () {
123  m_view->ClearPreview();
124  delete component;
125  component = nullptr;
126  };
127 
128  if( evt->IsCancelInteractive() )
129  {
130  if( component )
131  cleanup();
132  else
133  {
134  m_frame->PopTool( tool );
135  break;
136  }
137  }
138  else if( evt->IsActivate() )
139  {
140  if( component )
141  cleanup();
142 
143  if( evt->IsMoveTool() )
144  {
145  // leave ourselves on the stack so we come back after the move
146  break;
147  }
148  else
149  {
150  m_frame->PopTool( tool );
151  break;
152  }
153  }
154  else if( evt->IsClick( BUT_LEFT ) )
155  {
156  if( !component )
157  {
159 
160  // Pick the module to be placed
161  auto sel = m_frame->SelectCompFromLibTree( &filter, *historyList, true, 1, 1,
163 
164  // Restore cursor after dialog
165  getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
166 
167  LIB_PART* part = sel.LibId.IsValid() ? m_frame->GetLibPart( sel.LibId ) : nullptr;
168 
169  if( !part )
170  continue;
171 
172  component = new SCH_COMPONENT( *part, g_CurrentSheet, sel, (wxPoint) cursorPos );
173  component->SetFlags( IS_NEW | IS_MOVED );
174 
175  // Be sure the link to the corresponding LIB_PART is OK:
176  component->Resolve( *m_frame->Prj().SchSymbolLibTable() );
177 
178  if( m_frame->GetAutoplaceFields() )
179  component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
180 
181  m_frame->SaveCopyForRepeatItem( component );
182 
183  m_view->ClearPreview();
184  m_view->AddToPreview( component->Clone() );
185  m_selectionTool->AddItemToSel( component );
186  }
187  else
188  {
189  SCH_COMPONENT* next_comp = nullptr;
190 
191  m_view->ClearPreview();
192  m_frame->AddItemToScreenAndUndoList( component );
193 
194  EE_SELECTION new_sel;
195  new_sel.Add( component );
196 
198  m_frame->OnModify();
199 
201  {
202  int new_unit = component->GetUnit();
203 
204  if( m_frame->GetUseAllUnits()
205  && component->GetUnit() < component->GetUnitCount() )
206  new_unit++;
207  else
208  new_unit = 1;
209 
210  // We are either stepping to the next unit or next component
211  if( m_frame->GetRepeatComponent() || new_unit > 1 )
212  {
213  next_comp = static_cast<SCH_COMPONENT*>( component->Duplicate() );
214  next_comp->SetFlags( IS_NEW | IS_MOVED );
215  next_comp->SetUnit( new_unit );
216  next_comp->SetUnitSelection( g_CurrentSheet, new_unit );
217 
218  if( m_frame->GetAutoplaceFields() )
219  component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
220 
221  m_frame->SaveCopyForRepeatItem( next_comp );
222  m_view->AddToPreview( next_comp->Clone() );
223  m_selectionTool->AddItemToSel( next_comp );
224  }
225  }
226 
227  component = next_comp;
228  }
229  }
230  else if( evt->IsClick( BUT_RIGHT ) )
231  {
232  // Warp after context menu only if dragging...
233  if( !component )
235 
237  }
238  else if( evt->Category() == TC_COMMAND && evt->Action() == TA_CHOICE_MENU_CHOICE )
239  {
240  if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
241  && evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_CMP_MAX )
242  {
243  int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
244 
245  if( component )
246  {
247  m_frame->SelectUnit( component, unit );
249  }
250  }
251  }
252  else if( component && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
253  {
254  component->SetPosition( (wxPoint)cursorPos );
255  m_view->ClearPreview();
256  m_view->AddToPreview( component->Clone() );
257  }
258  else
259  evt->SetPassEvent();
260 
261  // Enable autopanning and cursor capture only when there is a module to be placed
262  getViewControls()->SetAutoPan( component != nullptr );
263  getViewControls()->CaptureCursor( component != nullptr );
264  }
265 
266  return 0;
267 }
268 
269 
271 {
272  SCH_BITMAP* image = aEvent.Parameter<SCH_BITMAP*>();
273  bool immediateMode = image;
274  VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
275 
277  getViewControls()->ShowCursor( true );
278 
279  // Add all the drawable parts to preview
280  if( image )
281  {
282  image->SetPosition( (wxPoint)cursorPos );
283  m_view->ClearPreview();
284  m_view->AddToPreview( image->Clone() );
285  }
286 
287  std::string tool = aEvent.GetCommandStr().get();
288  m_frame->PushTool( tool );
289  Activate();
290 
291  // Prime the pump
292  if( image )
294  else if( aEvent.HasPosition() )
296 
297  // Main loop: keep receiving events
298  while( TOOL_EVENT* evt = Wait() )
299  {
300  m_frame->GetCanvas()->SetCurrentCursor( image ? wxCURSOR_ARROW : wxCURSOR_PENCIL );
301  cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
302 
303  auto cleanup = [&] () {
305  m_view->ClearPreview();
306  delete image;
307  image = nullptr;
308  };
309 
310  if( evt->IsCancelInteractive() )
311  {
312  if( image )
313  cleanup();
314  else
315  {
316  m_frame->PopTool( tool );
317  break;
318  }
319 
320  if( immediateMode )
321  {
322  m_frame->PopTool( tool );
323  break;
324  }
325  }
326  else if( evt->IsActivate() )
327  {
328  if( image )
329  cleanup();
330 
331  if( evt->IsMoveTool() )
332  {
333  // leave ourselves on the stack so we come back after the move
334  break;
335  }
336  else
337  {
338  m_frame->PopTool( tool );
339  break;
340  }
341  }
342  else if( evt->IsClick( BUT_LEFT ) )
343  {
344  if( !image )
345  {
347  wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, wxEmptyString,
348  _( "Image Files " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN );
349 
350  if( dlg.ShowModal() != wxID_OK )
351  continue;
352 
353  // Restore cursor after dialog
354  getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
355 
356  wxString fullFilename = dlg.GetPath();
357 
358  if( wxFileExists( fullFilename ) )
359  image = new SCH_BITMAP( (wxPoint)cursorPos );
360 
361  if( !image || !image->ReadImageFile( fullFilename ) )
362  {
363  wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
364  delete image;
365  image = nullptr;
366  continue;
367  }
368 
369  image->SetFlags( IS_NEW | IS_MOVED );
370 
371  m_frame->SaveCopyForRepeatItem( image );
372 
373  m_view->ClearPreview();
374  m_view->AddToPreview( image->Clone() );
375  m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
376 
377  m_selectionTool->AddItemToSel( image );
378 
379  getViewControls()->SetCursorPosition( cursorPos, false );
380  }
381  else
382  {
384  image = nullptr;
386 
387  m_view->ClearPreview();
388 
389  if( immediateMode )
390  {
391  m_frame->PopTool( tool );
392  break;
393  }
394  }
395  }
396  else if( evt->IsClick( BUT_RIGHT ) )
397  {
398  // Warp after context menu only if dragging...
399  if( !image )
401 
403  }
404  else if( image && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
405  {
406  image->SetPosition( (wxPoint)cursorPos );
407  m_view->ClearPreview();
408  m_view->AddToPreview( image->Clone() );
409  m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
410  }
411  else
412  evt->SetPassEvent();
413 
414  // Enable autopanning and cursor capture only when there is a module to be placed
415  getViewControls()->SetAutoPan( image != nullptr );
416  getViewControls()->CaptureCursor( image != nullptr );
417  }
418 
419  return 0;
420 }
421 
422 
424 {
425  wxPoint cursorPos;
426  KICAD_T type = aEvent.Parameter<KICAD_T>();
427 
428  if( type == SCH_JUNCTION_T && aEvent.HasPosition() )
429  {
430  EE_SELECTION& selection = m_selectionTool->GetSelection();
431  SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() );
432 
433  if( wire )
434  {
435  SEG seg( wire->GetStartPoint(), wire->GetEndPoint() );
436  VECTOR2I nearest = seg.NearestPoint( getViewControls()->GetCursorPosition() );
437  getViewControls()->SetCrossHairCursorPosition( nearest, false );
438  getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
439  }
440  }
441 
443  getViewControls()->ShowCursor( true );
444  getViewControls()->SetSnapping( true );
445 
446  SCH_ITEM* previewItem;
447  switch( type )
448  {
449  case SCH_NO_CONNECT_T:
450  previewItem = new SCH_NO_CONNECT( cursorPos );
451  break;
452  case SCH_JUNCTION_T:
453  previewItem = new SCH_JUNCTION( cursorPos );
454  break;
456  previewItem = new SCH_BUS_WIRE_ENTRY( cursorPos, g_lastBusEntryShape );
457  break;
458  case SCH_BUS_BUS_ENTRY_T:
459  previewItem = new SCH_BUS_BUS_ENTRY( cursorPos, g_lastBusEntryShape );
460  break;
461  default:
462  wxASSERT_MSG( false, "Unknown item type in SCH_DRAWING_TOOLS::SingleClickPlace" );
463  return 0;
464  }
465 
466  m_view->ClearPreview();
467  m_view->AddToPreview( previewItem->Clone() );
468 
469  std::string tool = aEvent.GetCommandStr().get();
470  m_frame->PushTool( tool );
471  Activate();
472 
473  // Prime the pump
474  if( aEvent.HasPosition() )
476 
477  // Main loop: keep receiving events
478  while( TOOL_EVENT* evt = Wait() )
479  {
480  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
481  cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
482 
483  if( evt->IsCancelInteractive() )
484  {
485  m_frame->PopTool( tool );
486  break;
487  }
488  else if( evt->IsActivate() )
489  {
490  if( evt->IsMoveTool() )
491  {
492  // leave ourselves on the stack so we come back after the move
493  break;
494  }
495  else
496  {
497  m_frame->PopTool( tool );
498  break;
499  }
500  }
501  else if( evt->IsClick( BUT_LEFT ) )
502  {
503  if( !m_frame->GetScreen()->GetItem( cursorPos, 0, type ) )
504  {
505  if( type == SCH_JUNCTION_T )
506  m_frame->AddJunction( cursorPos );
507  else
508  {
509  SCH_ITEM* newItem = static_cast<SCH_ITEM*>( previewItem->Clone() );
510  newItem->SetPosition( cursorPos );
511  newItem->SetFlags( IS_NEW );
512 
514  m_frame->SaveCopyForRepeatItem( newItem );
515 
518  m_frame->OnModify();
519  }
520  }
521  }
522  else if( evt->IsClick( BUT_RIGHT ) )
523  {
525  }
526  else if( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() )
527  {
528  previewItem->SetPosition( (wxPoint)cursorPos );
529  m_view->ClearPreview();
530  m_view->AddToPreview( previewItem->Clone() );
531  }
532  else if( evt->Category() == TC_COMMAND )
533  {
534  if( ( type == SCH_BUS_BUS_ENTRY_T || type == SCH_BUS_WIRE_ENTRY_T )
535  && ( evt->IsAction( &EE_ACTIONS::rotateCW )
536  || evt->IsAction( &EE_ACTIONS::rotateCCW )
537  || evt->IsAction( &EE_ACTIONS::mirrorX )
538  || evt->IsAction( &EE_ACTIONS::mirrorY )
539  || evt->IsAction( &EE_ACTIONS::toShapeBackslash )
540  || evt->IsAction( &EE_ACTIONS::toShapeSlash ) ) )
541  {
542  // Update the shape of the bus entry
543  if( evt->IsAction( &EE_ACTIONS::toShapeSlash ) )
544  g_lastBusEntryShape = '/';
545  else if( evt->IsAction( &EE_ACTIONS::toShapeBackslash ) )
546  g_lastBusEntryShape = '\\';
547 
548  SCH_BUS_ENTRY_BASE* busItem = static_cast<SCH_BUS_ENTRY_BASE*>( previewItem );
549 
550  // The bus entries only rotate in one direction
551  if( evt->IsAction( &EE_ACTIONS::rotateCW )
552  || evt->IsAction( &EE_ACTIONS::rotateCCW ) )
553  busItem->Rotate( busItem->GetPosition() );
554  else if( evt->IsAction( &EE_ACTIONS::mirrorX ) )
555  busItem->MirrorX( busItem->GetPosition().x );
556  else if( evt->IsAction( &EE_ACTIONS::mirrorY ) )
557  busItem->MirrorY( busItem->GetPosition().y );
558  else if( evt->IsAction( &EE_ACTIONS::toShapeBackslash )
559  || evt->IsAction( &EE_ACTIONS::toShapeSlash ) )
561 
562  m_view->ClearPreview();
563  m_view->AddToPreview( previewItem->Clone() );
564  }
565  }
566  else
567  evt->SetPassEvent();
568  }
569 
570  delete previewItem;
571  m_view->ClearPreview();
572 
573  return 0;
574 }
575 
576 
578 {
579  EDA_ITEM* item = nullptr;
580  bool importMode = aEvent.IsAction( &EE_ACTIONS::importSheetPin );
581  KICAD_T type = aEvent.Parameter<KICAD_T>();
582 
584  getViewControls()->ShowCursor( true );
585 
586  std::string tool = aEvent.GetCommandStr().get();
587  m_frame->PushTool( tool );
588  Activate();
589 
590  // Prime the pump
591  if( aEvent.HasPosition() )
593 
594  // Main loop: keep receiving events
595  while( TOOL_EVENT* evt = Wait() )
596  {
597  m_frame->GetCanvas()->SetCurrentCursor( item ? wxCURSOR_ARROW : wxCURSOR_PENCIL );
598  VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
599 
600  auto cleanup = [&] () {
602  m_view->ClearPreview();
603  delete item;
604  item = nullptr;
605  };
606 
607  if( evt->IsCancelInteractive() )
608  {
609  if( item )
610  cleanup();
611  else
612  {
613  m_frame->PopTool( tool );
614  break;
615  }
616  }
617  else if( evt->IsActivate() )
618  {
619  if( item )
620  cleanup();
621 
622  if( evt->IsPointEditor() )
623  {
624  // don't exit (the point editor runs in the background)
625  }
626  else if( evt->IsMoveTool() )
627  {
628  // leave ourselves on the stack so we come back after the move
629  break;
630  }
631  else
632  {
633  m_frame->PopTool( tool );
634  break;
635  }
636  }
637  else if( evt->IsClick( BUT_LEFT ) )
638  {
639  // First click creates...
640  if( !item )
641  {
643 
644  switch( type )
645  {
646  case SCH_LABEL_T:
648  break;
649  case SCH_HIER_LABEL_T:
651  break;
652  case SCH_GLOBAL_LABEL_T:
654  break;
655  case SCH_TEXT_T:
656  item = m_frame->CreateNewText( LAYER_NOTES );
657  break;
658  case SCH_SHEET_PIN_T:
659  {
660  SCH_HIERLABEL* label = nullptr;
661  SCH_SHEET* sheet = (SCH_SHEET*) m_selectionTool->SelectPoint( cursorPos,
663  if( !sheet )
664  {
665  m_statusPopup.reset( new STATUS_TEXT_POPUP( m_frame ) );
666  m_statusPopup->SetText( _( "Click over a sheet." ) );
667  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
668  m_statusPopup->PopupFor( 2000 );
669  break;
670  }
671 
672  if( importMode )
673  {
674  label = m_frame->ImportHierLabel( sheet );
675 
676  if( !label )
677  {
678  m_statusPopup.reset( new STATUS_TEXT_POPUP( m_frame ) );
679  m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
680  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
681  m_statusPopup->PopupFor( 2000 );
682  break;
683  }
684  }
685 
686  item = m_frame->CreateSheetPin( sheet, label );
687  break;
688  }
689  default:
690  break;
691  }
692 
693  // Restore cursor after dialog
694  getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
695 
696  if( item )
697  {
698  item->SetFlags( IS_NEW | IS_MOVED );
699  m_view->ClearPreview();
700  m_view->AddToPreview( item->Clone() );
701  m_selectionTool->AddItemToSel( item );
702  }
703 
704  getViewControls()->SetCursorPosition( cursorPos, false );
705  }
706 
707  // ... and second click places:
708  else
709  {
710  item->ClearFlags( IS_MOVED );
712  item = m_frame->GetNextNewText();
713 
714  if( item )
715  {
717  item->SetFlags( IS_NEW | IS_MOVED );
718  m_view->ClearPreview();
719  m_view->AddToPreview( item->Clone() );
720  m_selectionTool->AddItemToSel( item );
721  }
722  else
723  {
724  m_view->ClearPreview();
725  }
726  }
727  }
728  else if( evt->IsClick( BUT_RIGHT ) )
729  {
730  // Warp after context menu only if dragging...
731  if( !item )
733 
735  }
736  else if( item && evt->IsSelectionEvent() )
737  {
738  // This happens if our text was replaced out from under us by ConvertTextType()
739  EE_SELECTION& selection = m_selectionTool->GetSelection();
740 
741  if( selection.GetSize() == 1 )
742  {
743  item = (SCH_ITEM*) selection.Front();
744  m_view->ClearPreview();
745  m_view->AddToPreview( item->Clone() );
746  }
747  else
748  item = nullptr;
749  }
750  else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
751  {
752  static_cast<SCH_ITEM*>( item )->SetPosition( (wxPoint) cursorPos );
753  m_view->ClearPreview();
754  m_view->AddToPreview( item->Clone() );
755  }
756  else
757  evt->SetPassEvent();
758 
759  // Enable autopanning and cursor capture only when there is a module to be placed
760  getViewControls()->SetAutoPan( item != nullptr );
761  getViewControls()->CaptureCursor( item != nullptr );
762  }
763 
764  return 0;
765 }
766 
767 
769 {
771  SCH_SHEET* sheet = nullptr;
772 
774  getViewControls()->ShowCursor( true );
775 
776  std::string tool = aEvent.GetCommandStr().get();
777  m_frame->PushTool( tool );
778  Activate();
779 
780  // Prime the pump
781  if( aEvent.HasPosition() )
783 
784  // Main loop: keep receiving events
785  while( TOOL_EVENT* evt = Wait() )
786  {
787  if( !pointEditor->HasPoint() )
788  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL );
789 
790  VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
791 
792  auto cleanup = [&] () {
794  m_view->ClearPreview();
795  delete sheet;
796  sheet = nullptr;
797  };
798 
799  if( evt->IsCancelInteractive() )
800  {
801  if( sheet )
802  cleanup();
803  else
804  {
805  m_frame->PopTool( tool );
806  break;
807  }
808  }
809  else if( evt->IsActivate() )
810  {
811  if( sheet )
812  cleanup();
813 
814  if( evt->IsPointEditor() )
815  {
816  // don't exit (the point editor runs in the background)
817  }
818  else if( evt->IsMoveTool() )
819  {
820  // leave ourselves on the stack so we come back after the move
821  break;
822  }
823  else
824  {
825  m_frame->PopTool( tool );
826  break;
827  }
828  }
829 
830  else if( evt->IsClick( BUT_LEFT ) && !sheet )
831  {
833 
834  sheet = new SCH_SHEET( (wxPoint) cursorPos );
835  sheet->SetFlags( IS_NEW | IS_RESIZED );
836  sheet->SetParent( m_frame->GetScreen() );
837  sheet->SetScreen( NULL );
838  sizeSheet( sheet, cursorPos );
839 
840  m_view->ClearPreview();
841  m_view->AddToPreview( sheet->Clone() );
842  }
843 
844  else if( sheet && ( evt->IsClick( BUT_LEFT )
845  || evt->IsAction( &EE_ACTIONS::finishSheet ) ) )
846  {
847  m_view->ClearPreview();
848  getViewControls()->SetAutoPan( false );
849  getViewControls()->CaptureCursor( false );
850 
851  if( m_frame->EditSheetProperties((SCH_SHEET*) sheet, g_CurrentSheet, nullptr ) )
852  {
853  sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
854 
857  m_selectionTool->AddItemToSel( sheet );
858  }
859  else
860  {
861  delete sheet;
862  }
863 
864  sheet = nullptr;
865  }
866 
867  else if( sheet && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
868  {
869  sizeSheet( sheet, cursorPos );
870  m_view->ClearPreview();
871  m_view->AddToPreview( sheet->Clone() );
872  }
873 
874  else if( evt->IsClick( BUT_RIGHT ) )
875  {
876  // Warp after context menu only if dragging...
877  if( !sheet )
879 
881  }
882  else
883  evt->SetPassEvent();
884 
885  // Enable autopanning and cursor capture only when there is a sheet to be placed
886  getViewControls()->SetAutoPan( sheet != nullptr );
887  getViewControls()->CaptureCursor( sheet != nullptr );
888  }
889 
890  return 0;
891 }
892 
893 
895 {
896  wxPoint pos = aSheet->GetPosition();
897  wxPoint size = (wxPoint) aPos - pos;
898 
899  size.x = std::max( size.x, MIN_SHEET_WIDTH );
900  size.y = std::max( size.y, MIN_SHEET_HEIGHT );
901 
902  wxPoint grid = m_frame->GetNearestGridPosition( pos + size );
903  aSheet->Resize( wxSize( grid.x - pos.x, grid.y - pos.y ) );
904 }
905 
906 
908 {
921 }
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
Class for a bus to bus entry.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool SchematicCleanUp(SCH_SCREEN *aScreen=nullptr)
Performs routine schematic cleaning including breaking wire and buses and deleting identical objects ...
int TwoClickPlace(const TOOL_EVENT &aEvent)
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
void AddToPreview(EDA_ITEM *aItem, bool aTakeOwnership=true)
Definition: sch_view.cpp:193
static TOOL_ACTION finishSheet
Definition: ee_actions.h:101
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
int PlaceComponent(const TOOL_EVENT &aEvent)
SCH_TEXT * CreateNewText(int aType)
Definition: edit_label.cpp:61
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
static TOOL_ACTION activatePointEditor
Definition: actions.h:163
wxPoint GetStartPoint() const
Definition: sch_line.h:97
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...
char g_lastBusEntryShape
This file is part of the common library.
static TOOL_ACTION toShapeBackslash
Definition: ee_actions.h:132
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
VIEW_CONTROLS class definition.
bool HasPoint()
Indicates the cursor is over an edit point.
bool Resolve(PART_LIBS *aLibs)
Assigns the current LIB_PART from aLibs which this symbol is based on.
STATUS_TEXT_POPUP.
Definition: status_popup.h:79
bool GetShowFootprintPreviews() const
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
static TOOL_ACTION mirrorY
Definition: ee_actions.h:121
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:90
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
static TOOL_ACTION placeJunction
Definition: ee_actions.h:85
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1402
int GetUnitCount() const
Return the number of units per package of the symbol.
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
std::vector< COMPONENT_SELECTION > HISTORY_LIST
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
static SCH_BASE_FRAME::HISTORY_LIST s_PowerHistoryList
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Moves cursor to the requested position expressed in world coordinates.
Schematic editor (Eeschema) main window.
LIB_PART * GetLibPart(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
Load symbol from symbol library table.
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:86
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
static const KICAD_T SheetsOnly[]
Definition: ee_collectors.h:45
wxPoint GetNearestGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize location to aPosition.
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()
const bool GetUseAllUnits()
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.
static TOOL_ACTION rotateCW
Definition: ee_actions.h:118
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:75
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:67
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:177
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:41
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:69
EE_SELECTION & GetSelection()
Function GetSelection()
#define IS_NEW
New item, just created.
Definition: base_struct.h:120
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:91
virtual void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
Function WarpCursor() If enabled (.
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:119
int GetUnit() const
static TOOL_ACTION placePower
Definition: ee_actions.h:80
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:257
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:75
#define NULL
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
virtual void SetPosition(const wxPoint &aPosition)=0
Function SetPosition set the schematic item position to aPosition.
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.
int SingleClickPlace(const TOOL_EVENT &aEvent)
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:94
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
TOOL_EVENT.
Definition: tool_event.h:171
static TOOL_ACTION placeImage
Definition: ee_actions.h:96
void ClearPreview()
Definition: sch_view.cpp:181
void UpdateHierarchyNavigator(bool aForceUpdate=false)
Run the Hierarchy Navigator dialog.
Define a library symbol object.
void SaveCopyForRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
SCH_JUNCTION * AddJunction(const wxPoint &aPos, bool aAppendToUndo=false, bool aFinal=true)
static TOOL_ACTION mirrorX
Definition: ee_actions.h:120
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:153
static TOOL_ACTION importSheetPin
Definition: ee_actions.h:93
void SetUnit(int aUnit)
Change the unit number to aUnit.
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:58
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:79
void SetBusEntryShape(char aShape)
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
SCH_TEXT * GetNextNewText()
Gets the next queued text item.
Definition: edit_label.cpp:49
static TOOL_ACTION addNeededJunctions
Definition: ee_actions.h:77
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:94
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:565
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:204
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:215
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
Definition: seg.h:39
static TOOL_ACTION placeLabel
Definition: ee_actions.h:88
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
const bool GetRepeatComponent()
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
SCH_HIERLABEL * ImportHierLabel(SCH_SHEET *aSheet)
Import a hierarchical label with no attached sheet pin.
Definition: sheet.cpp:547
int AddItemToSel(const TOOL_EVENT &aEvent)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:38
#define _(s)
Definition: 3d_actions.cpp:33
EE_POINT_EDITOR.
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
void VetoContextMenuMouseWarp()
Disables mouse warping after the current context menu is closed.
Definition: tool_manager.h:414
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:84
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Automatically orient all the fields in the component.
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:99
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_bitmap.cpp:89
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
#define MIN_SHEET_HEIGHT
Definition: sch_sheet.h:43
#define IS_RESIZED
Item being resized.
Definition: base_struct.h:121
virtual void PopTool(const std::string &actionName)
Class for a wire to bus entry.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:258
bool EditSheetProperties(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, bool *aClearAnnotationNewItems)
Edit an existing sheet or add a new sheet to the schematic.
Definition: sheet.cpp:479
void Activate()
Function Activate() Runs the tool.
bool ReadImageFile(const wxString &aFullFilename)
Reads and stores an image file.
Definition: sch_bitmap.cpp:83
EE_TOOL_BASE.
Definition: ee_tool_base.h:50
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T)
Check aPosition within a distance of aAccuracy for items of type aFilter.
Definition: sch_screen.cpp:273
bool HasPosition() const
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition: tool_event.h:260
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
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_sheet.cpp:451
Definition for part library class.
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
EDA_ITEM * SelectPoint(const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems, bool *aSelectionCancelledFlag=NULL, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Function selectPoint() Selects an item pointed by the parameter aWhere.
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:89
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
SCH_SHEET_PIN * CreateSheetPin(SCH_SHEET *aSheet, SCH_HIERLABEL *aLabel)
Create a new SCH_SHEET_PIN object and add it to aSheet at the current cursor position.
Definition: sheet.cpp:511
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_bitmap.h:141
void setTransitions() override
Sets up handlers for various events.
static TOOL_ACTION toShapeSlash
Definition: ee_actions.h:131
static TOOL_ACTION refreshPreview
Definition: actions.h:101
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:183
int DrawSheet(const TOOL_EVENT &aEvent)
static TOOL_ACTION cursorClick
Definition: actions.h:118
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:745
void sizeSheet(SCH_SHEET *aSheet, VECTOR2I aPos)
wxPoint GetPosition() const override
Function GetPosition.
void AddItemToScreenAndUndoList(SCH_ITEM *aItem, bool aUndoAppend=false)
Add an item to the schematic and adds the changes to the undo/redo container.
#define IS_MOVED
Item being moved.
Definition: base_struct.h:119
wxPoint GetEndPoint() const
Definition: sch_line.h:100
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup