KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_editor_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-2022 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 <ee_actions.h>
26#include <optional>
27#include <symbol_edit_frame.h>
28#include <sch_commit.h>
33#include <lib_text.h>
35#include <lib_shape.h>
36#include <lib_textbox.h>
37#include <pgm_base.h>
40#include <string_utils.h>
42#include <wx/msgdlg.h>
45
46static void* g_lastPinWeakPtr;
47
48
50 EE_TOOL_BASE<SYMBOL_EDIT_FRAME>( "eeschema.SymbolDrawing" ),
51 m_lastTextBold( false ),
52 m_lastTextItalic( false ),
53 m_lastTextAngle( ANGLE_HORIZONTAL ),
54 m_lastTextJust( GR_TEXT_H_ALIGN_LEFT ),
55 m_lastFillStyle( FILL_T::NO_FILL ),
56 m_lastFillColor( COLOR4D::UNSPECIFIED ),
57 m_lastStroke( 0, LINE_STYLE::DEFAULT, COLOR4D::UNSPECIFIED ),
58 m_drawSpecificBodyStyle( true ),
59 m_drawSpecificUnit( false ),
60 m_inDrawShape( false ),
61 m_inTwoClickPlace( false )
62{
63}
64
65
67{
69
70 auto isDrawingCondition =
71 [] ( const SELECTION& aSel )
72 {
73 LIB_ITEM* item = (LIB_ITEM*) aSel.Front();
74 return item && item->IsNew();
75 };
76
77 m_menu.GetMenu().AddItem( ACTIONS::finishInteractive, isDrawingCondition, 2 );
78
79 return true;
80}
81
82
84{
85 KICAD_T type = aEvent.Parameter<KICAD_T>();
86 auto* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
87 auto* pinTool = type == LIB_PIN_T ? m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>() : nullptr;
88
90 return 0;
91
93
96 VECTOR2I cursorPos;
97 bool ignorePrimePosition = false;
98 LIB_ITEM* item = nullptr;
99 bool isText = aEvent.IsAction( &EE_ACTIONS::placeSymbolText );
100 COMMON_SETTINGS* common_settings = Pgm().GetCommonSettings();
101
103
104 m_frame->PushTool( aEvent );
105
106 auto setCursor =
107 [&]()
108 {
109 if( item )
110 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PLACE );
111 else if( isText )
112 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::TEXT );
113 else
114 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
115 };
116
117 auto cleanup =
118 [&] ()
119 {
122 delete item;
123 item = nullptr;
124 };
125
126 Activate();
127 // Must be done after Activate() so that it gets set into the correct context
128 controls->ShowCursor( true );
129 // Set initial cursor
130 setCursor();
131
132 if( aEvent.HasPosition() )
133 {
134 m_toolMgr->PrimeTool( aEvent.Position() );
135 }
136 else if( common_settings->m_Input.immediate_actions && !aEvent.IsReactivate() )
137 {
138 m_toolMgr->PrimeTool( { 0, 0 } );
139 ignorePrimePosition = true;
140 }
141
142 // Main loop: keep receiving events
143 while( TOOL_EVENT* evt = Wait() )
144 {
145 setCursor();
146 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
147 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
148
149 cursorPos = grid.Align( controls->GetMousePosition(), grid.GetItemGrid( item ) );
150 controls->ForceCursorPosition( true, cursorPos );
151
152 // The tool hotkey is interpreted as a click when drawing
153 bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition()
154 && evt->Matches( aEvent );
155
156 if( evt->IsCancelInteractive() )
157 {
159
160 if( item )
161 {
162 cleanup();
163 }
164 else
165 {
166 m_frame->PopTool( aEvent );
167 break;
168 }
169 }
170 else if( evt->IsActivate() && !isSyntheticClick )
171 {
172 if( item && evt->IsMoveTool() )
173 {
174 // we're already moving our own item; ignore the move tool
175 evt->SetPassEvent( false );
176 continue;
177 }
178
179 if( item )
180 {
181 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel item creation." ) );
182 evt->SetPassEvent( false );
183 continue;
184 }
185
186 if( evt->IsPointEditor() )
187 {
188 // don't exit (the point editor runs in the background)
189 }
190 else if( evt->IsMoveTool() )
191 {
192 break;
193 }
194 else
195 {
196 m_frame->PopTool( aEvent );
197 break;
198 }
199 }
200 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) || isSyntheticClick )
201 {
202 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
203
204 if( !symbol )
205 continue;
206
207 // First click creates...
208 if( !item )
209 {
211
212 switch( type )
213 {
214 case LIB_PIN_T:
215 {
216 item = pinTool->CreatePin( VECTOR2I( cursorPos.x, -cursorPos.y ), symbol );
217 g_lastPinWeakPtr = item;
218 break;
219 }
220 case LIB_TEXT_T:
221 {
222 LIB_TEXT* text = new LIB_TEXT( symbol );
223
225 text->SetUnit( m_frame->GetUnit() );
226
228 text->SetBodyStyle( m_frame->GetBodyStyle() );
229
230 text->SetPosition( VECTOR2I( cursorPos.x, -cursorPos.y ) );
231 text->SetTextSize( VECTOR2I( schIUScale.MilsToIU( settings->m_Defaults.text_size ),
232 schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
233 text->SetTextAngle( m_lastTextAngle );
234
236
237 if( dlg.ShowModal() != wxID_OK || NoPrintableChars( text->GetText() ) )
238 delete text;
239 else
240 item = text;
241
242 break;
243 }
244 default:
245 wxFAIL_MSG( "TwoClickPlace(): unknown type" );
246 }
247
248 // If we started with a hotkey which has a position then warp back to that.
249 // Otherwise update to the current mouse position pinned inside the autoscroll
250 // boundaries.
251 if( evt->IsPrime() && !ignorePrimePosition )
252 {
253 cursorPos = grid.Align( evt->Position(), grid.GetItemGrid( item ) );
254 getViewControls()->WarpMouseCursor( cursorPos, true );
255 }
256 else
257 {
259 cursorPos = getViewControls()->GetMousePosition();
260 }
261
262 if( item )
263 {
264 item->SetPosition( VECTOR2I( cursorPos.x, -cursorPos.y ) );
265
266 item->SetFlags( IS_NEW | IS_MOVING );
268 m_view->AddToPreview( item->Clone() );
270
271 // update the cursor so it looks correct before another event
272 setCursor();
273 }
274
275 controls->SetCursorPosition( cursorPos, false );
276 }
277 // ... and second click places:
278 else
279 {
280 SCH_COMMIT commit( m_toolMgr );
281 commit.Modify( symbol, m_frame->GetScreen() );
282
283 switch( item->Type() )
284 {
285 case LIB_PIN_T:
286 pinTool->PlacePin( (LIB_PIN*) item );
287 item->ClearEditFlags();
288 commit.Push( _( "Add Pin" ) );
289 break;
290
291 case LIB_TEXT_T:
292 symbol->AddDrawItem( (LIB_TEXT*) item );
293 item->ClearEditFlags();
294 commit.Push( _( "Add Text" ) );
295 break;
296
297 default:
298 wxFAIL_MSG( "TwoClickPlace(): unknown type" );
299 }
300
301 item = nullptr;
304 }
305 }
306 else if( evt->IsClick( BUT_RIGHT ) )
307 {
308 // Warp after context menu only if dragging...
309 if( !item )
311
313 }
314 else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
315 {
316 item->SetPosition( VECTOR2I( cursorPos.x, -cursorPos.y ) );
318 m_view->AddToPreview( item->Clone() );
319 }
320 else
321 {
322 evt->SetPassEvent();
323 }
324
325 // Enable autopanning and cursor capture only when there is an item to be placed
326 controls->SetAutoPan( item != nullptr );
327 controls->CaptureCursor( item != nullptr );
328 }
329
330 controls->SetAutoPan( false );
331 controls->CaptureCursor( false );
332 controls->ForceCursorPosition( false );
333 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
334 return 0;
335}
336
337
339{
340 SHAPE_T requestedShape = aEvent.Parameter<SHAPE_T>();
341
342 return doDrawShape( aEvent, requestedShape );
343}
344
345
347{
348 return doDrawShape( aEvent, std::nullopt /* Draw text box */ );
349}
350
351
352int SYMBOL_EDITOR_DRAWING_TOOLS::doDrawShape( const TOOL_EVENT& aEvent, std::optional<SHAPE_T> aDrawingShape )
353{
354 bool isTextBox = !aDrawingShape.has_value();
355 SHAPE_T toolType = aDrawingShape.value_or( SHAPE_T::SEGMENT );
356
358 SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager();
361 VECTOR2I cursorPos;
362 SHAPE_T shapeType = toolType == SHAPE_T::SEGMENT ? SHAPE_T::POLY : toolType;
363 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
364 LIB_SHAPE* item = nullptr;
365 wxString description;
366
367 if( m_inDrawShape )
368 return 0;
369
371
372 // We might be running as the same shape in another co-routine. Make sure that one
373 // gets whacked.
375
377
378 m_frame->PushTool( aEvent );
379
380 auto setCursor =
381 [&]()
382 {
383 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
384 };
385
386 auto cleanup =
387 [&] ()
388 {
391 delete item;
392 item = nullptr;
393 };
394
395 Activate();
396 // Must be done after Activate() so that it gets set into the correct context
397 controls->ShowCursor( true );
398 // Set initial cursor
399 setCursor();
400
401 if( aEvent.HasPosition() )
402 m_toolMgr->PrimeTool( aEvent.Position() );
403
404 // Main loop: keep receiving events
405 while( TOOL_EVENT* evt = Wait() )
406 {
407 setCursor();
408 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
409 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
410
411 cursorPos = grid.Align( controls->GetMousePosition(), grid.GetItemGrid( item ) );
412 controls->ForceCursorPosition( true, cursorPos );
413
414 // The tool hotkey is interpreted as a click when drawing
415 bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition()
416 && evt->Matches( aEvent );
417
418 if( evt->IsCancelInteractive() )
419 {
420 if( item )
421 {
422 cleanup();
423 }
424 else
425 {
426 m_frame->PopTool( aEvent );
427 break;
428 }
429 }
430 else if( evt->IsActivate() && !isSyntheticClick )
431 {
432 if( item )
433 cleanup();
434
435 if( evt->IsPointEditor() )
436 {
437 // don't exit (the point editor runs in the background)
438 }
439 else if( evt->IsMoveTool() )
440 {
441 // leave ourselves on the stack so we come back after the move
442 break;
443 }
444 else
445 {
446 m_frame->PopTool( aEvent );
447 break;
448 }
449 }
450 else if( evt->IsClick( BUT_LEFT ) && !item )
451 {
452 // Update in case the symbol was changed while the tool was running
453 symbol = m_frame->GetCurSymbol();
454
455 if( !symbol )
456 continue;
457
459
460 int lineWidth = schIUScale.MilsToIU( settings->m_Defaults.line_width );
461
462 if( isTextBox )
463 {
464 LIB_TEXTBOX* textbox = new LIB_TEXTBOX( symbol, lineWidth, m_lastFillStyle );
465
467 schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
468
469 // Must be after SetTextSize()
470 textbox->SetBold( m_lastTextBold );
471 textbox->SetItalic( m_lastTextItalic );
472
473 textbox->SetTextAngle( m_lastTextAngle );
475
476 item = textbox;
477 description = _( "Add Text Box" );
478 }
479 else
480 {
481 item = new LIB_SHAPE( symbol, shapeType, lineWidth, m_lastFillStyle );
482 description = wxString::Format( _( "Add %s" ), item->EDA_SHAPE::GetFriendlyName() );
483 }
484
485 item->SetStroke( m_lastStroke );
487
488 item->SetFlags( IS_NEW );
489 item->BeginEdit( VECTOR2I( cursorPos.x, -cursorPos.y ) );
490
492 item->SetUnit( m_frame->GetUnit() );
493
496
498 }
499 else if( item && ( evt->IsClick( BUT_LEFT )
500 || evt->IsDblClick( BUT_LEFT )
501 || isSyntheticClick
502 || evt->IsAction( &ACTIONS::finishInteractive ) ) )
503 {
504 if( symbol != m_frame->GetCurSymbol() )
505 {
506 symbol = m_frame->GetCurSymbol();
507 item->SetParent( symbol );
508 }
509
510 if( evt->IsDblClick( BUT_LEFT ) || evt->IsAction( &ACTIONS::finishInteractive )
511 || !item->ContinueEdit( VECTOR2I( cursorPos.x, -cursorPos.y ) ) )
512 {
513 if( toolType == SHAPE_T::POLY )
514 {
515 item->CalcEdit( item->GetPosition() ); // Close shape
516 item->EndEdit( true );
517 }
518 else
519 {
520 item->EndEdit();
521 }
522
523 item->ClearEditFlags();
524
525 if( isTextBox )
526 {
527 LIB_TEXTBOX* textbox = static_cast<LIB_TEXTBOX*>( item );
528 DIALOG_LIB_TEXTBOX_PROPERTIES dlg( m_frame, static_cast<LIB_TEXTBOX*>( item ) );
529
530 // QuasiModal required for syntax help and Scintilla auto-complete
531 if( dlg.ShowQuasiModal() != wxID_OK )
532 {
533 cleanup();
534 continue;
535 }
536
537 m_lastTextBold = textbox->IsBold();
538 m_lastTextItalic = textbox->IsItalic();
539 m_lastTextAngle = textbox->GetTextAngle();
540 m_lastTextJust = textbox->GetHorizJustify();
541 }
542
543 m_lastStroke = item->GetStroke();
546
548
549 SCH_COMMIT commit( m_toolMgr );
550 commit.Modify( symbol, m_frame->GetScreen() );
551
552 symbol->AddDrawItem( item );
553 item = nullptr;
554
555 commit.Push( description );
558 }
559 }
560 else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
561 {
562 item->CalcEdit( VECTOR2I( cursorPos.x, -cursorPos.y ) );
564 m_view->AddToPreview( item->Clone() );
565 }
566 else if( evt->IsDblClick( BUT_LEFT ) && !item )
567 {
569 }
570 else if( evt->IsClick( BUT_RIGHT ) )
571 {
572 // Warp after context menu only if dragging...
573 if( !item )
575
577 }
578 else
579 {
580 evt->SetPassEvent();
581 }
582
583 // Enable autopanning and cursor capture only when there is a shape being drawn
584 controls->SetAutoPan( item != nullptr );
585 controls->CaptureCursor( item != nullptr );
586 }
587
588 controls->SetAutoPan( false );
589 controls->CaptureCursor( false );
590 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
591 return 0;
592}
593
594
596{
597 m_frame->PushTool( aEvent );
598
599 auto setCursor =
600 [&]()
601 {
602 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
603 };
604
605 Activate();
606 // Must be done after Activate() so that it gets set into the correct context
607 getViewControls()->ShowCursor( true );
608 // Set initial cursor
609 setCursor();
610
611 // Main loop: keep receiving events
612 while( TOOL_EVENT* evt = Wait() )
613 {
614 setCursor();
615
616 if( evt->IsCancelInteractive() )
617 {
618 m_frame->PopTool( aEvent );
619 break;
620 }
621 else if( evt->IsActivate() )
622 {
623 m_frame->PopTool( aEvent );
624 break;
625 }
626 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
627 {
628 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
629
630 if( !symbol )
631 continue;
632
633 VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() );
634 VECTOR2I offset( -cursorPos.x, cursorPos.y );
635
636 symbol->SetOffset( offset );
637
638 // Refresh the view without changing the viewport
639 auto center = m_view->GetCenter();
640 center.x += offset.x;
641 center.y -= offset.y;
642 m_view->SetCenter( center );
644 m_frame->OnModify();
645 }
646 else if( evt->IsClick( BUT_RIGHT ) )
647 {
649 }
650 else
651 {
652 evt->SetPassEvent();
653 }
654 }
655
656 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
657 return 0;
658}
659
660
662{
663 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
664
665 if( !symbol )
666 return 0;
667
668 // Note: PlaceImportedGraphics() will convert PCB_SHAPE_T and PCB_TEXT_T to footprint
669 // items if needed
671 int dlgResult = dlg.ShowModal();
672
673 std::list<std::unique_ptr<EDA_ITEM>>& list = dlg.GetImportedItems();
674
675 if( dlgResult != wxID_OK )
676 return 0;
677
678 // Ensure the list is not empty:
679 if( list.empty() )
680 {
681 wxMessageBox( _( "No graphic items found in file." ) );
682 return 0;
683 }
684
686
688 std::vector<LIB_ITEM*> newItems; // all new items, including group
689 std::vector<LIB_ITEM*> selectedItems; // the group, or newItems if no group
690 EE_SELECTION preview;
691 SCH_COMMIT commit( m_toolMgr );
692
693 for( std::unique_ptr<EDA_ITEM>& ptr : list )
694 {
695 LIB_ITEM* item = dynamic_cast<LIB_ITEM*>( ptr.get() );
696 wxCHECK2( item, continue );
697
698 newItems.push_back( item );
699 selectedItems.push_back( item );
700 preview.Add( item );
701
702 ptr.release();
703 }
704
705 if( !dlg.IsPlacementInteractive() )
706 {
707 commit.Modify( symbol, m_frame->GetScreen() );
708
709 // Place the imported drawings
710 for( LIB_ITEM* item : newItems )
711 {
712 symbol->AddDrawItem( item );
713 item->ClearEditFlags();
714 }
715
716 commit.Push( _( "Import Graphic" ) );
718
719 return 0;
720 }
721
722 m_view->Add( &preview );
723
724 // Clear the current selection then select the drawings so that edit tools work on them
726
727 EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
729
730 m_frame->PushTool( aEvent );
731
732 auto setCursor = [&]()
733 {
734 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
735 };
736
737 Activate();
738 // Must be done after Activate() so that it gets set into the correct context
739 controls->ShowCursor( true );
740 controls->ForceCursorPosition( false );
741 // Set initial cursor
742 setCursor();
743
744 //SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF );
746
747 // Now move the new items to the current cursor position:
748 VECTOR2I cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
749 VECTOR2I delta = cursorPos;
750 VECTOR2I currentOffset;
751
752 for( LIB_ITEM* item : selectedItems )
753 item->Offset( delta );
754
755 currentOffset += delta;
756
757 m_view->Update( &preview );
758
759 // Main loop: keep receiving events
760 while( TOOL_EVENT* evt = Wait() )
761 {
762 setCursor();
763
764 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
765 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
766
767 cursorPos = grid.Align( controls->GetMousePosition(), GRID_GRAPHICS );
768 controls->ForceCursorPosition( true, cursorPos );
769
770 if( evt->IsCancelInteractive() || evt->IsActivate() )
771 {
773
774 for( LIB_ITEM* item : newItems )
775 delete item;
776
777 break;
778 }
779 else if( evt->IsMotion() )
780 {
781 delta = VECTOR2I( cursorPos.x, -cursorPos.y ) - currentOffset;
782
783 for( LIB_ITEM* item : selectedItems )
784 item->Offset( delta );
785
786 currentOffset += delta;
787
788 m_view->Update( &preview );
789 }
790 else if( evt->IsClick( BUT_RIGHT ) )
791 {
793 }
794 else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
795 {
796 commit.Modify( symbol, m_frame->GetScreen() );
797
798 // Place the imported drawings
799 for( LIB_ITEM* item : newItems )
800 {
801 symbol->AddDrawItem( item );
802 item->ClearEditFlags();
803 }
804
805 commit.Push( _( "Import Graphic" ) );
806 break; // This is a one-shot command, not a tool
807 }
808 else
809 {
810 evt->SetPassEvent();
811 }
812 }
813
814 preview.Clear();
815 m_view->Remove( &preview );
816
818
819 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
820 controls->ForceCursorPosition( false );
821
822 m_frame->PopTool( aEvent );
823
824 return 0;
825}
826
827
829{
831 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
832 LIB_PIN* sourcePin = nullptr;
833
834 if( !symbol )
835 return 0;
836
837 // See if we have a pin matching our weak ptr
838 std::vector<LIB_PIN*> pins = symbol->GetAllLibPins();
839
840 for( LIB_PIN* test : pins )
841 {
842 if( (void*) test == g_lastPinWeakPtr )
843 {
844 sourcePin = test;
845 break;
846 }
847 }
848
849 if( sourcePin )
850 {
851 LIB_PIN* pin = pinTool->RepeatPin( sourcePin );
853
855
856 if( pin )
858 }
859
860 return 0;
861}
862
863
865{
877}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
static TOOL_ACTION activatePointEditor
Definition: actions.h:205
static TOOL_ACTION refreshPreview
Definition: actions.h:137
static TOOL_ACTION finishInteractive
Definition: actions.h:64
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
std::list< std::unique_ptr< EDA_ITEM > > & GetImportedItems()
int ShowQuasiModal()
void ShowInfoBarMsg(const wxString &aMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an info icon on the left of...
WX_INFOBAR * GetInfoBar()
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:123
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:372
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:82
void ClearEditFlags()
Definition: eda_item.h:137
bool IsNew() const
Definition: eda_item.h:103
FILL_T GetFillMode() const
Definition: eda_shape.h:101
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:106
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
bool IsItalic() const
Definition: eda_text.h:141
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:374
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:161
void SetBold(bool aBold)
Definition: eda_text.cpp:221
bool IsBold() const
Definition: eda_text.h:145
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:205
void SetItalic(bool aItalic)
Definition: eda_text.cpp:213
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:268
static TOOL_ACTION properties
Definition: ee_actions.h:126
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: ee_actions.h:63
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION placeSymbolAnchor
Definition: ee_actions.h:114
static TOOL_ACTION drawSymbolPolygon
Definition: ee_actions.h:113
static TOOL_ACTION drawCircle
Definition: ee_actions.h:101
static TOOL_ACTION placeSymbolText
Definition: ee_actions.h:110
static TOOL_ACTION importGraphics
Definition: ee_actions.h:252
static TOOL_ACTION addItemToSel
Selects an item (specified as the event parameter).
Definition: ee_actions.h:59
static TOOL_ACTION drawRectangle
Definition: ee_actions.h:100
static TOOL_ACTION drawSymbolTextBox
Definition: ee_actions.h:111
static TOOL_ACTION drawSymbolLines
Definition: ee_actions.h:112
static TOOL_ACTION drawArc
Definition: ee_actions.h:102
static TOOL_ACTION repeatDrawItem
Definition: ee_actions.h:120
static TOOL_ACTION placeSymbolPin
Definition: ee_actions.h:109
EE_SELECTION & GetSelection()
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:48
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:200
bool Init() override
Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:64
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
virtual void WarpMouseCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
If enabled (.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
virtual void PinCursorInsideNonAutoscrollArea(bool aWarpMouseCursor)=0
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
Definition: view.h:341
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:315
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:354
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1636
void ClearPreview()
Definition: view.cpp:1658
void RecacheAllItems()
Rebuild GAL display lists.
Definition: view.cpp:1415
void AddToPreview(VIEW_ITEM *aItem, bool aTakeOwnership=true)
Definition: view.cpp:1680
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:578
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
void SetPosition(const VECTOR2I &aPosition) override
Definition: lib_item.h:304
void SetBodyStyle(int aBodyStyle)
Definition: lib_item.h:345
void SetUnit(int aUnit)
Definition: lib_item.h:342
STROKE_PARAMS GetStroke() const
Definition: lib_shape.h:57
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: lib_shape.h:77
void EndEdit(bool aClosed=false) override
End an object editing action.
Definition: lib_shape.h:81
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:58
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_shape.cpp:64
bool ContinueEdit(const VECTOR2I &aPosition) override
Continue an edit in progress at aPosition.
Definition: lib_shape.h:78
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_shape.h:79
VECTOR2I GetPosition() const override
Definition: lib_shape.h:90
Define a library symbol object.
Definition: lib_symbol.h:99
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
void SetOffset(const VECTOR2I &aOffset)
Move the symbol aOffset.
Define a symbol library graphical text item.
Definition: lib_text.h:40
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:393
int AddItemToSel(const TOOL_EVENT &aEvent)
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:42
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:92
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
int PlaceAnchor(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
bool m_drawSpecificUnit
Re-entrancy guards.
int RepeatDrawItem(const TOOL_EVENT &aEvent)
int doDrawShape(const TOOL_EVENT &aEvent, std::optional< SHAPE_T > aDrawingShape)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int ImportGraphics(const TOOL_EVENT &aEvent)
int DrawShape(const TOOL_EVENT &aEvent)
int DrawSymbolTextBox(const TOOL_EVENT &aEvent)
int TwoClickPlace(const TOOL_EVENT &aEvent)
LIB_PIN * RepeatPin(const LIB_PIN *aSourcePin)
The symbol library editor main window.
int GetBodyStyle() const
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
virtual void PopTool(const TOOL_EVENT &aEvent)
Pops a tool from the stack.
virtual void PushTool(const TOOL_EVENT &aEvent)
NB: the definition of "tool" is different at the user level.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
Generic, UI-independent tool event.
Definition: tool_event.h:167
bool HasPosition() const
Definition: tool_event.h:256
bool DisableGridSnapping() const
Definition: tool_event.h:363
const VECTOR2D Position() const
Returns the point where dragging has started.
Definition: tool_event.h:285
bool IsReactivate() const
Definition: tool_event.h:268
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
void Activate()
Run the tool.
void DeactivateTool()
Deactivate the currently active tool.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:145
void PrimeTool(const VECTOR2D &aPosition)
"Prime" a tool by sending a cursor left-click event with the mouse position set to the passed in posi...
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:230
void VetoContextMenuMouseWarp()
Disable mouse warping after the current context menu is closed.
Definition: tool_manager.h:517
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:57
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:187
#define _(s)
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:431
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:529
#define IS_NEW
New item, just created.
#define IS_MOVING
Item being moved.
SHAPE_T
Definition: eda_shape.h:42
FILL_T
Definition: eda_shape.h:54
a few functions useful in geometry calculations.
@ GRID_GRAPHICS
Definition: grid_helper.h:45
see class PGM_BASE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
bool NoPrintableChars(const wxString &aString)
Return true if the string is empty or contains only whitespace.
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:48
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
static void * g_lastPinWeakPtr
constexpr int delta
@ GR_TEXT_H_ALIGN_LEFT
@ MD_SHIFT
Definition: tool_event.h:142
@ BUT_LEFT
Definition: tool_event.h:131
@ BUT_RIGHT
Definition: tool_event.h:132
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ LIB_TEXT_T
Definition: typeinfo.h:204
@ LIB_PIN_T
Definition: typeinfo.h:206
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588