Commit e6c1254d authored by Maciej Suminski's avatar Maciej Suminski

"Create corner" context menu entry for draw segments and zone outlines (GAL).

parent ff30ced4
......@@ -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",
......
......@@ -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;
......
......@@ -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<const ZONE_CONTAINER*>( 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<BOARD_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<DRAWSEGMENT*>( item )->GetShape() == S_SEGMENT );
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment