Loading pcbnew/tools/common_actions.cpp +2 −8 Original line number Diff line number Diff line Loading @@ -73,11 +73,7 @@ TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc", AS_GLOBAL, 0, "Draw an arc", "Draw an arc", AF_ACTIVATE ); TOOL_ACTION COMMON_ACTIONS::placeTextModule( "pcbnew.InteractiveDrawing.textPcb", AS_GLOBAL, 0, "Add a text", "Add a text", AF_ACTIVATE ); TOOL_ACTION COMMON_ACTIONS::placeTextPcb( "pcbnew.InteractiveDrawing.textModule", TOOL_ACTION COMMON_ACTIONS::placeText( "pcbnew.InteractiveDrawing.text", AS_GLOBAL, 0, "Add a text", "Add a text", AF_ACTIVATE ); Loading Loading @@ -299,10 +295,8 @@ boost::optional<TOOL_EVENT> COMMON_ACTIONS::TranslateLegacyId( int aId ) return COMMON_ACTIONS::drawArc.MakeEvent(); case ID_PCB_ADD_TEXT_BUTT: return COMMON_ACTIONS::placeTextPcb.MakeEvent(); case ID_MODEDIT_TEXT_TOOL: return COMMON_ACTIONS::placeTextModule.MakeEvent(); return COMMON_ACTIONS::placeText.MakeEvent(); case ID_PCB_DIMENSION_BUTT: return COMMON_ACTIONS::drawDimension.MakeEvent(); Loading pcbnew/tools/common_actions.h +1 −2 Original line number Diff line number Diff line Loading @@ -73,8 +73,7 @@ public: static TOOL_ACTION drawArc; /// Activation of the drawing tool (text) static TOOL_ACTION placeTextPcb; static TOOL_ACTION placeTextModule; static TOOL_ACTION placeText; /// Activation of the drawing tool (dimension) static TOOL_ACTION drawDimension; Loading pcbnew/tools/drawing_tool.cpp +243 −235 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ #include <class_module.h> DRAWING_TOOL::DRAWING_TOOL() : TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" ) TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" ), m_editModules( false ) { } Loading Loading @@ -125,231 +125,12 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) } int DRAWING_TOOL::PlaceTextModule( TOOL_EVENT& aEvent ) int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent ) { TEXTE_MODULE* text = new TEXTE_MODULE( NULL ); const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); MODULE* module = m_frame->GetBoard()->m_Modules; // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); m_controls->SetAutoPan( true ); Activate(); m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); bool placing = false; // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { preview.Clear(); preview.ViewUpdate(); m_controls->ShowCursor( true ); if( !placing || evt->IsActivate() ) { delete text; break; } else { placing = false; // start from the beginning } } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !placing ) { text->SetSize( dsnSettings.m_ModuleTextSize ); text->SetThickness( dsnSettings.m_ModuleTextWidth ); text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); DialogEditModuleText textDialog( m_frame, text, NULL ); placing = textDialog.ShowModal() && ( text->GetText().Length() > 0 ); if( !placing ) continue; m_controls->ShowCursor( false ); text->SetParent( module ); // it has to set after the settings dialog // otherwise the dialog stores it in undo buffer preview.Add( text ); } else { assert( text->GetText().Length() > 0 ); assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->SetLocalCoord(); text->ClearFlags(); // Module has to be saved before any modification is made m_frame->SaveCopyInUndoList( m_frame->GetBoard()->m_Modules, UR_MODEDIT ); module->GraphicalItems().PushFront( text ); m_view->Add( text ); text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); preview.Remove( text ); m_controls->ShowCursor( true ); text = new TEXTE_MODULE( NULL ); placing = false; } } else if( text && evt->IsMotion() ) { text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; } int DRAWING_TOOL::PlaceTextPcb( TOOL_EVENT& aEvent ) { TEXTE_PCB* text = NULL; // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); m_controls->SetAutoPan( true ); Activate(); m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { if( text ) { // Delete the old text and have another try m_board->Delete( text ); // it was already added by CreateTextPcb() text = NULL; preview.Clear(); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_controls->ShowCursor( true ); } else break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !text ) { // Init the new item attributes text = static_cast<PCB_EDIT_FRAME*>( m_frame )->CreateTextePcb( NULL ); if( text == NULL ) continue; m_controls->ShowCursor( false ); preview.Add( text ); } if( m_editModules ) return placeTextModule(); else { assert( text->GetText().Length() > 0 ); assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->ClearFlags(); m_view->Add( text ); // m_board->Add( text ); // it is already added by CreateTextePcb() text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( text, UR_NEW ); preview.Remove( text ); m_controls->ShowCursor( true ); text = NULL; } } else if( text && evt->IsMotion() ) { text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; return placeTextPcb(); } Loading Loading @@ -1271,6 +1052,234 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) } int DRAWING_TOOL::placeTextModule() { TEXTE_MODULE* text = new TEXTE_MODULE( NULL ); const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); MODULE* module = m_frame->GetBoard()->m_Modules; // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); m_controls->SetAutoPan( true ); Activate(); m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); bool placing = false; // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { preview.Clear(); preview.ViewUpdate(); m_controls->ShowCursor( true ); if( !placing || evt->IsActivate() ) { delete text; break; } else { placing = false; // start from the beginning } } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !placing ) { text->SetSize( dsnSettings.m_ModuleTextSize ); text->SetThickness( dsnSettings.m_ModuleTextWidth ); text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); DialogEditModuleText textDialog( m_frame, text, NULL ); placing = textDialog.ShowModal() && ( text->GetText().Length() > 0 ); if( !placing ) continue; m_controls->ShowCursor( false ); text->SetParent( module ); // it has to set after the settings dialog // otherwise the dialog stores it in undo buffer preview.Add( text ); } else { assert( text->GetText().Length() > 0 ); assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->SetLocalCoord(); text->ClearFlags(); // Module has to be saved before any modification is made m_frame->SaveCopyInUndoList( m_frame->GetBoard()->m_Modules, UR_MODEDIT ); module->GraphicalItems().PushFront( text ); m_view->Add( text ); text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); preview.Remove( text ); m_controls->ShowCursor( true ); text = new TEXTE_MODULE( NULL ); placing = false; } } else if( text && evt->IsMotion() ) { text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; } int DRAWING_TOOL::placeTextPcb() { TEXTE_PCB* text = NULL; // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); m_controls->SetAutoPan( true ); Activate(); m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { if( text ) { // Delete the old text and have another try m_board->Delete( text ); // it was already added by CreateTextPcb() text = NULL; preview.Clear(); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_controls->ShowCursor( true ); } else break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !text ) { // Init the new item attributes text = static_cast<PCB_EDIT_FRAME*>( m_frame )->CreateTextePcb( NULL ); if( text == NULL ) continue; m_controls->ShowCursor( false ); preview.Add( text ); } else { assert( text->GetText().Length() > 0 ); assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->ClearFlags(); m_view->Add( text ); // m_board->Add( text ); // it is already added by CreateTextePcb() text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( text, UR_NEW ); preview.Remove( text ); m_controls->ShowCursor( true ); text = NULL; } } else if( text && evt->IsMotion() ) { text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; } void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const { VECTOR2I cursorPos = m_controls->GetCursorPosition(); Loading Loading @@ -1301,8 +1310,7 @@ void DRAWING_TOOL::setTransitions() Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.MakeEvent() ); Go( &DRAWING_TOOL::DrawZone, COMMON_ACTIONS::drawZone.MakeEvent() ); Go( &DRAWING_TOOL::DrawKeepout, COMMON_ACTIONS::drawKeepout.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTextPcb, COMMON_ACTIONS::placeTextPcb.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTextModule, COMMON_ACTIONS::placeTextModule.MakeEvent() ); Go( &DRAWING_TOOL::PlaceText, COMMON_ACTIONS::placeText.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() ); Go( &DRAWING_TOOL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() ); } pcbnew/tools/drawing_tool.h +31 −10 Original line number Diff line number Diff line Loading @@ -76,18 +76,11 @@ public: int DrawArc( TOOL_EVENT& aEvent ); /** * Function PlaceTextModule() * Function PlaceText() * Displays a dialog that allows to input text and its settings and then lets the user decide * where to place the text in module editor. * where to place the text in editor. */ int PlaceTextModule( TOOL_EVENT& aEvent ); /** * Function PlaceTextPcb() * Displays a dialog that allows to input text and its settings and then lets the user decide * where to place the text in board editor. */ int PlaceTextPcb( TOOL_EVENT& aEvent ); int PlaceText( TOOL_EVENT& aEvent ); /** * Function DrawDimension() Loading Loading @@ -127,6 +120,17 @@ public: */ int PlaceModule( TOOL_EVENT& aEvent ); /** * Function EditModules() * Toggles edit module mode. When enabled, one may select parts of modules individually * (graphics, pads, etc.), so they can be modified. * @param aEnabled decides if the mode should be enabled. */ void EditModules( bool aEnabled ) { m_editModules = aEnabled; } private: ///> Starts drawing a selected shape (i.e. DRAWSEGMENT). ///> @param aShape is the type of created shape (@see STROKE_T). Loading @@ -147,6 +151,20 @@ private: ///> @param aKeepout decides if the drawn polygon is a zone or a keepout area. int drawZone( bool aKeepout ); /** * Function placeTextModule() * Displays a dialog that allows to input text and its settings and then lets the user decide * where to place the text in module . */ int placeTextModule(); /** * Function placeTextPcb() * Displays a dialog that allows to input text and its settings and then lets the user decide * where to place the text in board editor. */ int placeTextPcb(); ///> Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees. The origin ///> stays the same, the end of the aSegment is modified according to the ///> current cursor position. Loading @@ -162,6 +180,9 @@ private: BOARD* m_board; PCB_EDIT_FRAME* m_frame; /// Edit module mode flag bool m_editModules; // How does line width change after one -/+ key press. static const int WIDTH_STEP = 100000; }; Loading Loading
pcbnew/tools/common_actions.cpp +2 −8 Original line number Diff line number Diff line Loading @@ -73,11 +73,7 @@ TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc", AS_GLOBAL, 0, "Draw an arc", "Draw an arc", AF_ACTIVATE ); TOOL_ACTION COMMON_ACTIONS::placeTextModule( "pcbnew.InteractiveDrawing.textPcb", AS_GLOBAL, 0, "Add a text", "Add a text", AF_ACTIVATE ); TOOL_ACTION COMMON_ACTIONS::placeTextPcb( "pcbnew.InteractiveDrawing.textModule", TOOL_ACTION COMMON_ACTIONS::placeText( "pcbnew.InteractiveDrawing.text", AS_GLOBAL, 0, "Add a text", "Add a text", AF_ACTIVATE ); Loading Loading @@ -299,10 +295,8 @@ boost::optional<TOOL_EVENT> COMMON_ACTIONS::TranslateLegacyId( int aId ) return COMMON_ACTIONS::drawArc.MakeEvent(); case ID_PCB_ADD_TEXT_BUTT: return COMMON_ACTIONS::placeTextPcb.MakeEvent(); case ID_MODEDIT_TEXT_TOOL: return COMMON_ACTIONS::placeTextModule.MakeEvent(); return COMMON_ACTIONS::placeText.MakeEvent(); case ID_PCB_DIMENSION_BUTT: return COMMON_ACTIONS::drawDimension.MakeEvent(); Loading
pcbnew/tools/common_actions.h +1 −2 Original line number Diff line number Diff line Loading @@ -73,8 +73,7 @@ public: static TOOL_ACTION drawArc; /// Activation of the drawing tool (text) static TOOL_ACTION placeTextPcb; static TOOL_ACTION placeTextModule; static TOOL_ACTION placeText; /// Activation of the drawing tool (dimension) static TOOL_ACTION drawDimension; Loading
pcbnew/tools/drawing_tool.cpp +243 −235 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ #include <class_module.h> DRAWING_TOOL::DRAWING_TOOL() : TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" ) TOOL_INTERACTIVE( "pcbnew.InteractiveDrawing" ), m_editModules( false ) { } Loading Loading @@ -125,231 +125,12 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) } int DRAWING_TOOL::PlaceTextModule( TOOL_EVENT& aEvent ) int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent ) { TEXTE_MODULE* text = new TEXTE_MODULE( NULL ); const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); MODULE* module = m_frame->GetBoard()->m_Modules; // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); m_controls->SetAutoPan( true ); Activate(); m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); bool placing = false; // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { preview.Clear(); preview.ViewUpdate(); m_controls->ShowCursor( true ); if( !placing || evt->IsActivate() ) { delete text; break; } else { placing = false; // start from the beginning } } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !placing ) { text->SetSize( dsnSettings.m_ModuleTextSize ); text->SetThickness( dsnSettings.m_ModuleTextWidth ); text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); DialogEditModuleText textDialog( m_frame, text, NULL ); placing = textDialog.ShowModal() && ( text->GetText().Length() > 0 ); if( !placing ) continue; m_controls->ShowCursor( false ); text->SetParent( module ); // it has to set after the settings dialog // otherwise the dialog stores it in undo buffer preview.Add( text ); } else { assert( text->GetText().Length() > 0 ); assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->SetLocalCoord(); text->ClearFlags(); // Module has to be saved before any modification is made m_frame->SaveCopyInUndoList( m_frame->GetBoard()->m_Modules, UR_MODEDIT ); module->GraphicalItems().PushFront( text ); m_view->Add( text ); text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); preview.Remove( text ); m_controls->ShowCursor( true ); text = new TEXTE_MODULE( NULL ); placing = false; } } else if( text && evt->IsMotion() ) { text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; } int DRAWING_TOOL::PlaceTextPcb( TOOL_EVENT& aEvent ) { TEXTE_PCB* text = NULL; // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); m_controls->SetAutoPan( true ); Activate(); m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { if( text ) { // Delete the old text and have another try m_board->Delete( text ); // it was already added by CreateTextPcb() text = NULL; preview.Clear(); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_controls->ShowCursor( true ); } else break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !text ) { // Init the new item attributes text = static_cast<PCB_EDIT_FRAME*>( m_frame )->CreateTextePcb( NULL ); if( text == NULL ) continue; m_controls->ShowCursor( false ); preview.Add( text ); } if( m_editModules ) return placeTextModule(); else { assert( text->GetText().Length() > 0 ); assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->ClearFlags(); m_view->Add( text ); // m_board->Add( text ); // it is already added by CreateTextePcb() text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( text, UR_NEW ); preview.Remove( text ); m_controls->ShowCursor( true ); text = NULL; } } else if( text && evt->IsMotion() ) { text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; return placeTextPcb(); } Loading Loading @@ -1271,6 +1052,234 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) } int DRAWING_TOOL::placeTextModule() { TEXTE_MODULE* text = new TEXTE_MODULE( NULL ); const BOARD_DESIGN_SETTINGS& dsnSettings = m_frame->GetDesignSettings(); MODULE* module = m_frame->GetBoard()->m_Modules; // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); m_controls->SetAutoPan( true ); Activate(); m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); bool placing = false; // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { preview.Clear(); preview.ViewUpdate(); m_controls->ShowCursor( true ); if( !placing || evt->IsActivate() ) { delete text; break; } else { placing = false; // start from the beginning } } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !placing ) { text->SetSize( dsnSettings.m_ModuleTextSize ); text->SetThickness( dsnSettings.m_ModuleTextWidth ); text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); DialogEditModuleText textDialog( m_frame, text, NULL ); placing = textDialog.ShowModal() && ( text->GetText().Length() > 0 ); if( !placing ) continue; m_controls->ShowCursor( false ); text->SetParent( module ); // it has to set after the settings dialog // otherwise the dialog stores it in undo buffer preview.Add( text ); } else { assert( text->GetText().Length() > 0 ); assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->SetLocalCoord(); text->ClearFlags(); // Module has to be saved before any modification is made m_frame->SaveCopyInUndoList( m_frame->GetBoard()->m_Modules, UR_MODEDIT ); module->GraphicalItems().PushFront( text ); m_view->Add( text ); text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); preview.Remove( text ); m_controls->ShowCursor( true ); text = new TEXTE_MODULE( NULL ); placing = false; } } else if( text && evt->IsMotion() ) { text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; } int DRAWING_TOOL::placeTextPcb() { TEXTE_PCB* text = NULL; // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( m_view ); m_view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_controls->ShowCursor( true ); m_controls->SetSnapping( true ); m_controls->SetAutoPan( true ); Activate(); m_frame->SetToolID( ID_PCB_ADD_TEXT_BUTT, wxCURSOR_PENCIL, _( "Add text" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = m_controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { if( text ) { // Delete the old text and have another try m_board->Delete( text ); // it was already added by CreateTextPcb() text = NULL; preview.Clear(); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_controls->ShowCursor( true ); } else break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( text && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { text->Flip( text->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !text ) { // Init the new item attributes text = static_cast<PCB_EDIT_FRAME*>( m_frame )->CreateTextePcb( NULL ); if( text == NULL ) continue; m_controls->ShowCursor( false ); preview.Add( text ); } else { assert( text->GetText().Length() > 0 ); assert( text->GetSize().x > 0 && text->GetSize().y > 0 ); text->ClearFlags(); m_view->Add( text ); // m_board->Add( text ); // it is already added by CreateTextePcb() text->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( text, UR_NEW ); preview.Remove( text ); m_controls->ShowCursor( true ); text = NULL; } } else if( text && evt->IsMotion() ) { text->SetTextPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Show a preview of the item preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } m_controls->ShowCursor( false ); m_controls->SetSnapping( false ); m_controls->SetAutoPan( false ); m_view->Remove( &preview ); setTransitions(); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; } void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const { VECTOR2I cursorPos = m_controls->GetCursorPosition(); Loading Loading @@ -1301,8 +1310,7 @@ void DRAWING_TOOL::setTransitions() Go( &DRAWING_TOOL::DrawDimension, COMMON_ACTIONS::drawDimension.MakeEvent() ); Go( &DRAWING_TOOL::DrawZone, COMMON_ACTIONS::drawZone.MakeEvent() ); Go( &DRAWING_TOOL::DrawKeepout, COMMON_ACTIONS::drawKeepout.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTextPcb, COMMON_ACTIONS::placeTextPcb.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTextModule, COMMON_ACTIONS::placeTextModule.MakeEvent() ); Go( &DRAWING_TOOL::PlaceText, COMMON_ACTIONS::placeText.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() ); Go( &DRAWING_TOOL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() ); }
pcbnew/tools/drawing_tool.h +31 −10 Original line number Diff line number Diff line Loading @@ -76,18 +76,11 @@ public: int DrawArc( TOOL_EVENT& aEvent ); /** * Function PlaceTextModule() * Function PlaceText() * Displays a dialog that allows to input text and its settings and then lets the user decide * where to place the text in module editor. * where to place the text in editor. */ int PlaceTextModule( TOOL_EVENT& aEvent ); /** * Function PlaceTextPcb() * Displays a dialog that allows to input text and its settings and then lets the user decide * where to place the text in board editor. */ int PlaceTextPcb( TOOL_EVENT& aEvent ); int PlaceText( TOOL_EVENT& aEvent ); /** * Function DrawDimension() Loading Loading @@ -127,6 +120,17 @@ public: */ int PlaceModule( TOOL_EVENT& aEvent ); /** * Function EditModules() * Toggles edit module mode. When enabled, one may select parts of modules individually * (graphics, pads, etc.), so they can be modified. * @param aEnabled decides if the mode should be enabled. */ void EditModules( bool aEnabled ) { m_editModules = aEnabled; } private: ///> Starts drawing a selected shape (i.e. DRAWSEGMENT). ///> @param aShape is the type of created shape (@see STROKE_T). Loading @@ -147,6 +151,20 @@ private: ///> @param aKeepout decides if the drawn polygon is a zone or a keepout area. int drawZone( bool aKeepout ); /** * Function placeTextModule() * Displays a dialog that allows to input text and its settings and then lets the user decide * where to place the text in module . */ int placeTextModule(); /** * Function placeTextPcb() * Displays a dialog that allows to input text and its settings and then lets the user decide * where to place the text in board editor. */ int placeTextPcb(); ///> Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees. The origin ///> stays the same, the end of the aSegment is modified according to the ///> current cursor position. Loading @@ -162,6 +180,9 @@ private: BOARD* m_board; PCB_EDIT_FRAME* m_frame; /// Edit module mode flag bool m_editModules; // How does line width change after one -/+ key press. static const int WIDTH_STEP = 100000; }; Loading