From d41e93ef14e3e933d49252112b86495f07a05dee Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 13:50:27 +0200 Subject: [PATCH] Adapted tools to PCB_BASE{_EDIT}_FRAME. --- pcbnew/tools/common_actions.cpp | 11 ++- pcbnew/tools/common_actions.h | 3 +- pcbnew/tools/drawing_tool.cpp | 120 ++++++++++++++++++++++++++++++-- pcbnew/tools/drawing_tool.h | 17 +++-- pcbnew/tools/edit_tool.cpp | 12 ++-- pcbnew/tools/point_editor.cpp | 10 +-- pcbnew/tools/selection_tool.cpp | 16 +++-- pcbnew/tools/selection_tool.h | 4 ++ 8 files changed, 160 insertions(+), 33 deletions(-) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 73b67e462b..d96f42d3ee 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -67,7 +67,11 @@ TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc", AS_GLOBAL, 0, "Draw an arc", "Draw an arc" ); -TOOL_ACTION COMMON_ACTIONS::placeText( "pcbnew.InteractiveDrawing.text", +TOOL_ACTION COMMON_ACTIONS::placeTextModule( "pcbnew.InteractiveDrawing.textPcb", + AS_GLOBAL, 0, + "Add a text", "Add a text" ); + +TOOL_ACTION COMMON_ACTIONS::placeTextPcb( "pcbnew.InteractiveDrawing.textModule", AS_GLOBAL, 0, "Add a text", "Add a text" ); @@ -284,7 +288,10 @@ std::string COMMON_ACTIONS::TranslateLegacyId( int aId ) return COMMON_ACTIONS::drawArc.GetName(); case ID_PCB_ADD_TEXT_BUTT: - return COMMON_ACTIONS::placeText.GetName(); + return COMMON_ACTIONS::placeTextPcb.GetName(); + + case ID_MODEDIT_TEXT_TOOL: + return COMMON_ACTIONS::placeTextModule.GetName(); case ID_PCB_DIMENSION_BUTT: return COMMON_ACTIONS::drawDimension.GetName(); diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 5ddb660dbb..986489da63 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -64,7 +64,8 @@ public: static TOOL_ACTION drawArc; /// Activation of the drawing tool (text) - static TOOL_ACTION placeText; + static TOOL_ACTION placeTextPcb; + static TOOL_ACTION placeTextModule; /// Activation of the drawing tool (dimension) static TOOL_ACTION drawDimension; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 050681ca2f..c33bd7a3fa 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -65,7 +65,7 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason ) m_view = getView(); m_controls = getViewControls(); m_board = getModel(); - m_frame = getEditFrame(); + m_frame = getEditFrame(); setTransitions(); } @@ -281,7 +281,112 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent ) } -int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent ) +int DRAWING_TOOL::PlaceTextModule( TOOL_EVENT& aEvent ) +{ + TEXTE_MODULE* 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->GetTool()->ClearSelection(); + 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() ) + { + 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; + } + + else if( text && evt->Category() == TC_COMMAND ) + { + if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) + { + text->Rotate( text->GetPosition(), 900.0 /*m_frame->GetRotationAngle()*/ ); // FIXME + 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 = m_frame->CreateTextModule( m_frame->GetBoard()->m_Modules, 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; +} + + +int DRAWING_TOOL::PlaceTextPcb( TOOL_EVENT& aEvent ) { TEXTE_PCB* text = NULL; @@ -322,7 +427,7 @@ int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { - text->Rotate( text->GetPosition(), m_frame->GetRotationAngle() ); + text->Rotate( text->GetPosition(), /*m_frame->GetRotationAngle()*/ 900.0 ); // FIXME preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) @@ -337,7 +442,7 @@ int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent ) if( !text ) { // Init the new item attributes - text = m_frame->CreateTextePcb( NULL ); + text = static_cast( m_frame )->CreateTextePcb( NULL ); if( text == NULL ) continue; @@ -698,7 +803,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { - module->Rotate( module->GetPosition(), m_frame->GetRotationAngle() ); + module->Rotate( module->GetPosition(), /*m_frame->GetRotationAngle()*/ 900.0 ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) @@ -1029,7 +1134,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout ) m_view->Add( zone ); if( !aKeepout ) - m_frame->Fill_Zone( zone ); + static_cast( m_frame )->Fill_Zone( zone ); zone->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); @@ -1179,7 +1284,8 @@ 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::PlaceText, COMMON_ACTIONS::placeText.MakeEvent() ); + Go( &DRAWING_TOOL::PlaceTextPcb, COMMON_ACTIONS::placeTextPcb.MakeEvent() ); + Go( &DRAWING_TOOL::PlaceTextModule, COMMON_ACTIONS::placeTextModule.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() ); Go( &DRAWING_TOOL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() ); } diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index e05a3a59ce..99427a77be 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -33,7 +33,7 @@ namespace KIGFX class VIEW_CONTROLS; } class BOARD; -class PCB_EDIT_FRAME; +class PCB_BASE_FRAME; class DRAWSEGMENT; /** @@ -76,11 +76,18 @@ public: int DrawArc( TOOL_EVENT& aEvent ); /** - * Function DrawText() + * Function PlaceTextModule() * Displays a dialog that allows to input text and its settings and then lets the user decide - * where to place the text. + * where to place the text in module editor. */ - int PlaceText( TOOL_EVENT& aEvent ); + 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 ); /** * Function DrawDimension() @@ -143,7 +150,7 @@ private: KIGFX::VIEW* m_view; KIGFX::VIEW_CONTROLS* m_controls; BOARD* m_board; - PCB_EDIT_FRAME* m_frame; + PCB_BASE_FRAME* m_frame; // How does line width change after one -/+ key press. static const int WIDTH_STEP = 100000; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 496bc92d8f..4d33c1ec07 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -93,7 +93,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY; KIGFX::VIEW_CONTROLS* controls = getViewControls(); - PCB_EDIT_FRAME* editFrame = getEditFrame(); + PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); controls->ShowCursor( true ); controls->SetSnapping( true ); controls->SetAutoPan( true ); @@ -217,7 +217,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) { const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - PCB_EDIT_FRAME* editFrame = getEditFrame(); + PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); if( !makeSelection( selection ) ) { @@ -286,7 +286,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) { const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - PCB_EDIT_FRAME* editFrame = getEditFrame(); + PCB_BASE_FRAME* editFrame = getEditFrame(); // Shall the selection be cleared at the end? bool unselect = selection.Empty(); @@ -310,7 +310,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) { BOARD_ITEM* item = selection.Item( i ); - item->Rotate( rotatePoint, editFrame->GetRotationAngle() ); + item->Rotate( rotatePoint, 900.0 /*m_frame->GetRotationAngle()*/ ); if( !m_dragging ) item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); @@ -340,7 +340,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) { const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); - PCB_EDIT_FRAME* editFrame = getEditFrame(); + PCB_BASE_FRAME* editFrame = getEditFrame(); // Shall the selection be cleared at the end? bool unselect = selection.Empty(); @@ -404,7 +404,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) // Get a copy of the selected items set PICKED_ITEMS_LIST selectedItems = selection.items; - PCB_EDIT_FRAME* editFrame = getEditFrame(); + PCB_BASE_FRAME* editFrame = getEditFrame(); // As we are about to remove items, they have to be removed from the selection first m_selectionTool->ClearSelection(); diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 22bde0c384..fa9ae8b029 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -209,7 +209,7 @@ int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent ) KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW* view = getView(); - PCB_EDIT_FRAME* editFrame = getEditFrame(); + PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); EDA_ITEM* item = selection.items.GetPickedItem( 0 ); m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() ); @@ -661,8 +661,8 @@ void POINT_EDITOR::breakOutline( const VECTOR2I& aBreakPoint ) if( item->Type() == PCB_ZONE_AREA_T ) { - getEditFrame()->OnModify(); - getEditFrame()->SaveCopyInUndoList( selection.items, UR_CHANGED ); + getEditFrame()->OnModify(); + getEditFrame()->SaveCopyInUndoList( selection.items, UR_CHANGED ); ZONE_CONTAINER* zone = static_cast( item ); CPolyLine* outline = zone->Outline(); @@ -702,8 +702,8 @@ void POINT_EDITOR::breakOutline( const VECTOR2I& aBreakPoint ) else if( item->Type() == PCB_LINE_T ) { - getEditFrame()->OnModify(); - getEditFrame()->SaveCopyInUndoList( selection.items, UR_CHANGED ); + getEditFrame()->OnModify(); + getEditFrame()->SaveCopyInUndoList( selection.items, UR_CHANGED ); DRAWSEGMENT* segment = static_cast( item ); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 591bfb9e3e..08fb358094 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -78,6 +78,8 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason ) // Restore previous properties of selected items and remove them from containers ClearSelection(); + m_frame = getEditFrame(); + // Reinsert the VIEW_GROUP, in case it was removed from the VIEW getView()->Remove( m_selection.group ); getView()->Add( m_selection.group ); @@ -185,7 +187,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) bool SELECTION_TOOL::SelectSingle( const VECTOR2I& aWhere, bool aAllowDisambiguation ) { BOARD_ITEM* item; - GENERAL_COLLECTORS_GUIDE guide = getEditFrame()->GetCollectorsGuide(); + GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); GENERAL_COLLECTOR collector; const KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_LINE_T, EOT }; // preferred types @@ -269,7 +271,7 @@ void SELECTION_TOOL::ClearSelection() } m_selection.clear(); - getEditFrame()->SetCurItem( NULL ); + m_frame->SetCurItem( NULL ); // Do not show the context menu when there is nothing selected SetContextMenu( &m_menu, CMENU_OFF ); @@ -370,7 +372,7 @@ bool SELECTION_TOOL::selectMultiple() } // Do not display information about selected item,as there is more than one - getEditFrame()->SetCurItem( NULL ); + m_frame->SetCurItem( NULL ); if( !m_selection.Empty() ) { @@ -586,7 +588,7 @@ void SELECTION_TOOL::select( BOARD_ITEM* aItem ) if( m_selection.Size() == 1 ) { // Set as the current item, so the information about selection is displayed - getEditFrame()->SetCurItem( aItem, true ); + m_frame->SetCurItem( aItem, true ); // Now the context menu should be enabled SetContextMenu( &m_menu, CMENU_BUTTON ); @@ -594,7 +596,7 @@ void SELECTION_TOOL::select( BOARD_ITEM* aItem ) else if( m_selection.Size() == 2 ) // Check only for 2, so it will not be { // called for every next selected item // If multiple items are selected, do not show the information about the selected item - getEditFrame()->SetCurItem( NULL, true ); + m_frame->SetCurItem( NULL, true ); } } @@ -619,7 +621,7 @@ void SELECTION_TOOL::deselect( BOARD_ITEM* aItem ) if( m_selection.Empty() ) { SetContextMenu( &m_menu, CMENU_OFF ); - getEditFrame()->SetCurItem( NULL ); + m_frame->SetCurItem( NULL ); } // Inform other potentially interested tools @@ -671,7 +673,7 @@ bool SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const void SELECTION_TOOL::highlightNet( const VECTOR2I& aPoint ) { KIGFX::RENDER_SETTINGS* render = getView()->GetPainter()->GetSettings(); - GENERAL_COLLECTORS_GUIDE guide = getEditFrame()->GetCollectorsGuide(); + GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); GENERAL_COLLECTOR collector; int net = -1; diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 642b2ee358..fffd1ec27f 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -31,6 +31,7 @@ #include #include +class PCB_BASE_FRAME; class SELECTION_AREA; class BOARD_ITEM; class GENERAL_COLLECTOR; @@ -257,6 +258,9 @@ private: */ BOARD_ITEM* prefer( GENERAL_COLLECTOR& aCollector, const KICAD_T aTypes[] ) const; + /// Pointer to the parent frame. + PCB_BASE_FRAME* m_frame; + /// Visual representation of selection box SELECTION_AREA* m_selArea;