From 9280c29fa98da95bcb1954470a4e2df96622d579 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 16:50:31 +0200 Subject: [PATCH] "Create corner" context menu entry for draw segments and zone outlines (GAL). --- pcbnew/tools/common_actions.cpp | 6 +++++ pcbnew/tools/common_actions.h | 3 +++ pcbnew/tools/point_editor.cpp | 47 ++++++++++++++++++++++++++++----- pcbnew/tools/point_editor.h | 13 +++++---- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index cf2879e725..47321a67c5 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -322,10 +322,16 @@ TOOL_ACTION COMMON_ACTIONS::routerActivate( "pcbnew.InteractiveRouter", AS_GLOBAL, 'X', "Run push & shove router", "Run push & shove router", AF_ACTIVATE ); + +// Point editor TOOL_ACTION COMMON_ACTIONS::pointEditorUpdate( "pcbnew.PointEditor.update", AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere +TOOL_ACTION COMMON_ACTIONS::pointEditorBreakOutline( "pcbnew.PointEditor.breakOutline", + AS_GLOBAL, 0, + "Create corner", "Create corner" ); + // Placement tool TOOL_ACTION COMMON_ACTIONS::alignTop( "pcbnew.Place.alignTop", diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 6df00fae9b..79af0ee129 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -105,6 +105,9 @@ public: /// Update edit points static TOOL_ACTION pointEditorUpdate; + /// Break outline (insert additional points to an edge) + static TOOL_ACTION pointEditorBreakOutline; + // Placement tool /// Align items to the top edge of selection bounding box static TOOL_ACTION alignTop; diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 3df09c4ce0..8951cb3f25 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -195,6 +195,9 @@ bool POINT_EDITOR::Init() return false; } + m_selectionTool->AddMenuItem( COMMON_ACTIONS::pointEditorBreakOutline, + POINT_EDITOR::breakOutlineCondition ); + setTransitions(); return true; @@ -259,9 +262,10 @@ int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent ) m_dragPoint = point; } - else if( evt->IsDblClick( BUT_LEFT ) ) + else if( evt->IsAction( &COMMON_ACTIONS::pointEditorBreakOutline ) ) { breakOutline( controls->GetCursorPosition() ); + updatePoints(); } else if( evt->IsDrag( BUT_LEFT ) && m_dragPoint ) @@ -446,8 +450,9 @@ void POINT_EDITOR::updateItem() const for( int i = 0; i < outline->GetCornersCount(); ++i ) { - outline->SetX( i, m_editPoints->Point( i ).GetPosition().x ); - outline->SetY( i, m_editPoints->Point( i ).GetPosition().y ); + VECTOR2I point = m_editPoints->Point( i ).GetPosition(); + outline->SetX( i, point.x ); + outline->SetY( i, point.y ); } break; @@ -521,7 +526,7 @@ void POINT_EDITOR::finishItem() const } -void POINT_EDITOR::updatePoints() const +void POINT_EDITOR::updatePoints() { EDA_ITEM* item = m_editPoints->GetParent(); @@ -563,8 +568,17 @@ void POINT_EDITOR::updatePoints() const const ZONE_CONTAINER* zone = static_cast( item ); const CPolyLine* outline = zone->Outline(); - for( int i = 0; i < outline->GetCornersCount(); ++i ) - m_editPoints->Point( i ).SetPosition( outline->GetPos( i ) ); + if( m_editPoints->PointsSize() != (unsigned) outline->GetCornersCount() ) + { + getView()->Remove( m_editPoints.get() ); + m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() ); + getView()->Add( m_editPoints.get() ); + } + else + { + for( int i = 0; i < outline->GetCornersCount(); ++i ) + m_editPoints->Point( i ).SetPosition( outline->GetPos( i ) ); + } break; } @@ -763,3 +777,24 @@ void POINT_EDITOR::breakOutline( const VECTOR2I& aBreakPoint ) } } } + + +void POINT_EDITOR::setTransitions() +{ + Go( &POINT_EDITOR::OnSelectionChange, m_selectionTool->SelectedEvent ); + Go( &POINT_EDITOR::OnSelectionChange, m_selectionTool->DeselectedEvent ); +} + + +bool POINT_EDITOR::breakOutlineCondition( const SELECTION& aSelection ) +{ + if( aSelection.Size() != 1 ) + return false; + + BOARD_ITEM* item = aSelection.Item( 0 ); + + // Works only for zones and line segments + return item->Type() == PCB_ZONE_AREA_T || + ( ( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) && + static_cast( item )->GetShape() == S_SEGMENT ); +} diff --git a/pcbnew/tools/point_editor.h b/pcbnew/tools/point_editor.h index b87224f613..d6f4b30611 100644 --- a/pcbnew/tools/point_editor.h +++ b/pcbnew/tools/point_editor.h @@ -81,7 +81,7 @@ private: void finishItem() const; ///> Updates edit points with item's points. - void updatePoints() const; + void updatePoints(); ///> Returns true if aPoint is the currently modified point. inline bool isModified( const EDIT_POINT& aPoint ) const @@ -95,15 +95,14 @@ private: ///> Returns a point that should be used as a constrainer for 45 degrees mode. EDIT_POINT get45DegConstrainer() const; - ///> Adds a new edit point on a zone outline. + ///> Adds a new edit point on a zone outline/line. void breakOutline( const VECTOR2I& aBreakPoint ); ///> Sets up handlers for various events. - void setTransitions() - { - Go( &POINT_EDITOR::OnSelectionChange, m_selectionTool->SelectedEvent ); - Go( &POINT_EDITOR::OnSelectionChange, m_selectionTool->DeselectedEvent ); - } + void setTransitions(); + + ///> Condition to display "Create corner" context menu entry. + static bool breakOutlineCondition( const SELECTION& aSelection ); }; #endif