Added TOOL_ACTION for updating EDIT_POINTS.
EDIT_POINTs show up when there is only one item selected (now after deselection as well).
This commit is contained in:
parent
c5c83bd271
commit
f87f12e222
|
@ -99,6 +99,9 @@ TOOL_ACTION COMMON_ACTIONS::routerActivate( "pcbnew.InteractiveRouter",
|
|||
AS_GLOBAL, 0,
|
||||
"Run push & shove router", "Run push & shove router" );
|
||||
|
||||
TOOL_ACTION COMMON_ACTIONS::pointEditorUpdate( "pcbnew.PointEditor.update",
|
||||
AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere
|
||||
|
||||
|
||||
std::string COMMON_ACTIONS::TranslateLegacyId( int aId )
|
||||
{
|
||||
|
|
|
@ -87,6 +87,9 @@ public:
|
|||
/// Activation of the Push and Shove router
|
||||
static TOOL_ACTION routerActivate;
|
||||
|
||||
/// Update edit points
|
||||
static TOOL_ACTION pointEditorUpdate;
|
||||
|
||||
/**
|
||||
* Function TranslateLegacyId()
|
||||
* Translates legacy tool ids to the corresponding TOOL_ACTION name.
|
||||
|
|
|
@ -37,13 +37,13 @@ class EDIT_POINT;
|
|||
class EDIT_POINT_CONSTRAINT
|
||||
{
|
||||
public:
|
||||
EDIT_POINT_CONSTRAINT( EDIT_POINT* aConstrained ) : m_constrained( aConstrained ) {};
|
||||
EDIT_POINT_CONSTRAINT( EDIT_POINT& aConstrained ) : m_constrained( aConstrained ) {};
|
||||
virtual ~EDIT_POINT_CONSTRAINT() {};
|
||||
|
||||
virtual void Apply() = 0;
|
||||
|
||||
protected:
|
||||
EDIT_POINT* m_constrained;
|
||||
EDIT_POINT& m_constrained;
|
||||
};
|
||||
|
||||
|
||||
|
@ -53,6 +53,7 @@ class EDIT_POINT
|
|||
public:
|
||||
EDIT_POINT( const VECTOR2I& aPoint ) :
|
||||
m_point( aPoint ), m_constraint( NULL ) {};
|
||||
|
||||
~EDIT_POINT()
|
||||
{
|
||||
delete m_constraint;
|
||||
|
@ -121,6 +122,11 @@ public:
|
|||
*/
|
||||
EDIT_POINT* FindPoint( const VECTOR2I& aLocation );
|
||||
|
||||
EDA_ITEM* GetParent() const
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
void Add( const EDIT_POINT& aPoint )
|
||||
{
|
||||
m_points.push_back( aPoint );
|
||||
|
@ -172,7 +178,7 @@ private:
|
|||
class EPC_VERTICAL : public EDIT_POINT_CONSTRAINT
|
||||
{
|
||||
public:
|
||||
EPC_VERTICAL( EDIT_POINT* aConstrained, EDIT_POINT& aConstrainer ) :
|
||||
EPC_VERTICAL( EDIT_POINT& aConstrained, EDIT_POINT& aConstrainer ) :
|
||||
EDIT_POINT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer )
|
||||
{}
|
||||
|
||||
|
@ -180,9 +186,9 @@ public:
|
|||
|
||||
virtual void Apply()
|
||||
{
|
||||
VECTOR2I point = m_constrained->GetPosition();
|
||||
VECTOR2I point = m_constrained.GetPosition();
|
||||
point.x = m_constrainer.GetPosition().x;
|
||||
m_constrained->SetPosition( point );
|
||||
m_constrained.SetPosition( point );
|
||||
}
|
||||
|
||||
virtual std::list<EDIT_POINT*> GetConstrainers() const
|
||||
|
@ -198,7 +204,7 @@ private:
|
|||
class EPC_HORIZONTAL : public EDIT_POINT_CONSTRAINT
|
||||
{
|
||||
public:
|
||||
EPC_HORIZONTAL( EDIT_POINT* aConstrained, EDIT_POINT& aConstrainer ) :
|
||||
EPC_HORIZONTAL( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ) :
|
||||
EDIT_POINT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer )
|
||||
{}
|
||||
|
||||
|
@ -206,20 +212,20 @@ public:
|
|||
|
||||
virtual void Apply()
|
||||
{
|
||||
VECTOR2I point = m_constrained->GetPosition();
|
||||
VECTOR2I point = m_constrained.GetPosition();
|
||||
point.y = m_constrainer.GetPosition().y;
|
||||
m_constrained->SetPosition( point );
|
||||
m_constrained.SetPosition( point );
|
||||
}
|
||||
|
||||
private:
|
||||
EDIT_POINT& m_constrainer;
|
||||
const EDIT_POINT& m_constrainer;
|
||||
};
|
||||
|
||||
|
||||
class EPC_CIRCLE : public EDIT_POINT_CONSTRAINT
|
||||
{
|
||||
public:
|
||||
EPC_CIRCLE( EDIT_POINT* aConstrained, EDIT_POINT& aCenter, EDIT_POINT& aEnd ) :
|
||||
EPC_CIRCLE( EDIT_POINT& aConstrained, const EDIT_POINT& aCenter, const EDIT_POINT& aEnd ) :
|
||||
EDIT_POINT_CONSTRAINT( aConstrained ), m_center( aCenter ), m_end( aEnd )
|
||||
{}
|
||||
|
||||
|
@ -228,7 +234,7 @@ public:
|
|||
virtual void Apply()
|
||||
{
|
||||
VECTOR2I centerToEnd = m_end.GetPosition() - m_center.GetPosition();
|
||||
VECTOR2I centerToPoint = m_constrained->GetPosition() - m_center.GetPosition();
|
||||
VECTOR2I centerToPoint = m_constrained.GetPosition() - m_center.GetPosition();
|
||||
|
||||
int radius = centerToEnd.EuclideanNorm();
|
||||
double angle = centerToPoint.Angle();
|
||||
|
@ -236,12 +242,12 @@ public:
|
|||
VECTOR2I newLine( radius, 0 );
|
||||
newLine = newLine.Rotate( angle );
|
||||
|
||||
m_constrained->SetPosition( m_center.GetPosition() + newLine );
|
||||
m_constrained.SetPosition( m_center.GetPosition() + newLine );
|
||||
}
|
||||
|
||||
private:
|
||||
EDIT_POINT& m_center;
|
||||
EDIT_POINT& m_end;
|
||||
const EDIT_POINT& m_center;
|
||||
const EDIT_POINT& m_end;
|
||||
};
|
||||
|
||||
#endif /* EDIT_POINTS_H_ */
|
||||
|
|
|
@ -151,6 +151,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
|
|||
|
||||
selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY );
|
||||
dragPosition = controls->GetCursorPosition();
|
||||
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate );
|
||||
}
|
||||
|
||||
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
||||
|
@ -233,6 +234,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
|
|||
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
|
||||
}
|
||||
|
||||
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate );
|
||||
setTransitions();
|
||||
|
||||
return 0;
|
||||
|
@ -268,9 +270,6 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
|
|||
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
}
|
||||
|
||||
setTransitions();
|
||||
updateRatsnest( true );
|
||||
|
||||
if( m_dragging )
|
||||
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
else
|
||||
|
@ -279,6 +278,11 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
|
|||
if( unselect )
|
||||
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
|
||||
|
||||
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate );
|
||||
|
||||
updateRatsnest( true );
|
||||
setTransitions();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -312,9 +316,6 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
|
|||
item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
|
||||
}
|
||||
|
||||
setTransitions();
|
||||
updateRatsnest( true );
|
||||
|
||||
if( m_dragging )
|
||||
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
else
|
||||
|
@ -323,6 +324,11 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
|
|||
if( unselect )
|
||||
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
|
||||
|
||||
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate );
|
||||
|
||||
updateRatsnest( true );
|
||||
setTransitions();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -359,8 +365,8 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent )
|
|||
if( !( board->m_Status_Pcb & NET_CODES_OK ) )
|
||||
board->BuildListOfNets();
|
||||
|
||||
board->GetRatsnest()->Recalculate(); // TODO is it necessary?
|
||||
setTransitions();
|
||||
board->GetRatsnest()->Recalculate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include <tool/tool_manager.h>
|
||||
#include <view/view_controls.h>
|
||||
#include <confirm.h>
|
||||
|
@ -41,10 +43,10 @@
|
|||
class EDIT_POINTS_FACTORY
|
||||
{
|
||||
public:
|
||||
static EDIT_POINTS Make( EDA_ITEM* aItem )
|
||||
static boost::shared_ptr<EDIT_POINTS> Make( EDA_ITEM* aItem )
|
||||
{
|
||||
// TODO generate list of points basing on the type
|
||||
EDIT_POINTS points( aItem );
|
||||
boost::shared_ptr<EDIT_POINTS> points = boost::make_shared<EDIT_POINTS>( aItem );
|
||||
|
||||
switch( aItem->Type() )
|
||||
{
|
||||
|
@ -55,19 +57,19 @@ public:
|
|||
switch( segment->GetShape() )
|
||||
{
|
||||
case S_SEGMENT:
|
||||
points.Add( segment->GetStart() );
|
||||
points.Add( segment->GetEnd() );
|
||||
points->Add( segment->GetStart() );
|
||||
points->Add( segment->GetEnd() );
|
||||
|
||||
break;
|
||||
|
||||
case S_ARC:
|
||||
points.Add( segment->GetCenter() ); // points[0]
|
||||
points.Add( segment->GetArcStart() ); // points[1]
|
||||
points.Add( segment->GetArcEnd() ); // points[2]
|
||||
points->Add( segment->GetCenter() ); // points[0]
|
||||
points->Add( segment->GetArcStart() ); // points[1]
|
||||
points->Add( segment->GetArcEnd() ); // points[2]
|
||||
|
||||
// Set constraints
|
||||
// Arc end has to stay at the same radius as the start
|
||||
points[2].SetConstraint( new EPC_CIRCLE( &points[2], points[0], points[1] ) );
|
||||
(*points)[2].SetConstraint( new EPC_CIRCLE( (*points)[2], (*points)[0], (*points)[1] ) );
|
||||
break;
|
||||
|
||||
default: // suppress warnings
|
||||
|
@ -111,11 +113,8 @@ bool POINT_EDITOR::Init()
|
|||
}
|
||||
|
||||
|
||||
int POINT_EDITOR::OnSelected( TOOL_EVENT& aEvent )
|
||||
int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent )
|
||||
{
|
||||
std::cout << "point editor activated" << std::endl;
|
||||
std::cout << aEvent.Format() << std::endl;
|
||||
|
||||
const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection();
|
||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||
m_dragPoint = NULL;
|
||||
|
@ -125,24 +124,15 @@ int POINT_EDITOR::OnSelected( TOOL_EVENT& aEvent )
|
|||
Activate();
|
||||
|
||||
EDA_ITEM* item = selection.items.GetPickedItem( 0 );
|
||||
EDIT_POINTS editPoints = EDIT_POINTS_FACTORY::Make( item );
|
||||
m_toolMgr->GetView()->Add( &editPoints );
|
||||
m_editPoints = EDIT_POINTS_FACTORY::Make( item );
|
||||
m_toolMgr->GetView()->Add( m_editPoints.get() );
|
||||
|
||||
// Main loop: keep receiving events
|
||||
while( OPT_TOOL_EVENT evt = Wait() )
|
||||
{
|
||||
if( evt->IsCancel() ||
|
||||
evt->Matches( m_selectionTool->ClearedEvent ) ||
|
||||
evt->Matches( m_selectionTool->DeselectedEvent ) ||
|
||||
evt->Matches( m_selectionTool->SelectedEvent ) )
|
||||
if( evt->IsMotion() )
|
||||
{
|
||||
m_toolMgr->PassEvent();
|
||||
break;
|
||||
}
|
||||
|
||||
else if( evt->IsMotion() )
|
||||
{
|
||||
EDIT_POINT* point = editPoints.FindPoint( evt->Position() );
|
||||
EDIT_POINT* point = m_editPoints->FindPoint( evt->Position() );
|
||||
|
||||
if( m_dragPoint != point )
|
||||
{
|
||||
|
@ -163,30 +153,37 @@ int POINT_EDITOR::OnSelected( TOOL_EVENT& aEvent )
|
|||
m_dragPoint = point;
|
||||
}
|
||||
|
||||
else if( evt->IsDrag( BUT_LEFT ) )
|
||||
else if( evt->IsDrag( BUT_LEFT ) && m_dragPoint )
|
||||
{
|
||||
if( m_dragPoint )
|
||||
{
|
||||
m_dragPoint->SetPosition( controls->GetCursorPosition() );
|
||||
m_dragPoint->ApplyConstraint();
|
||||
updateItem( item, editPoints );
|
||||
updatePoints( item, editPoints );
|
||||
m_dragPoint->SetPosition( controls->GetCursorPosition() );
|
||||
m_dragPoint->ApplyConstraint();
|
||||
updateItem();
|
||||
updatePoints();
|
||||
|
||||
editPoints.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_toolMgr->PassEvent();
|
||||
}
|
||||
m_editPoints->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
}
|
||||
|
||||
else if( evt->IsClick( BUT_LEFT ) )
|
||||
else if( evt->IsAction( &COMMON_ACTIONS::pointEditorUpdate ) )
|
||||
{
|
||||
updatePoints();
|
||||
}
|
||||
|
||||
else if( evt->IsCancel() ||
|
||||
evt->Matches( m_selectionTool->ClearedEvent ) ||
|
||||
evt->Matches( m_selectionTool->DeselectedEvent ) ||
|
||||
evt->Matches( m_selectionTool->SelectedEvent ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
m_toolMgr->PassEvent();
|
||||
}
|
||||
}
|
||||
|
||||
m_toolMgr->GetView()->Remove( &editPoints );
|
||||
m_toolMgr->GetView()->Remove( m_editPoints.get() );
|
||||
m_editPoints.reset();
|
||||
item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
||||
}
|
||||
|
||||
|
@ -200,42 +197,38 @@ int POINT_EDITOR::OnSelected( TOOL_EVENT& aEvent )
|
|||
}
|
||||
|
||||
|
||||
void POINT_EDITOR::setTransitions()
|
||||
void POINT_EDITOR::updateItem() const
|
||||
{
|
||||
Go( &POINT_EDITOR::OnSelected, m_selectionTool->SelectedEvent );
|
||||
}
|
||||
EDA_ITEM* item = m_editPoints->GetParent();
|
||||
|
||||
|
||||
void POINT_EDITOR::updateItem( EDA_ITEM* aItem, EDIT_POINTS& aPoints ) const
|
||||
{
|
||||
switch( aItem->Type() )
|
||||
switch( item->Type() )
|
||||
{
|
||||
case PCB_LINE_T:
|
||||
{
|
||||
DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( aItem );
|
||||
DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item );
|
||||
switch( segment->GetShape() )
|
||||
{
|
||||
case S_SEGMENT:
|
||||
if( &aPoints[0] == m_dragPoint )
|
||||
segment->SetStart( wxPoint( aPoints[0].GetPosition().x, aPoints[0].GetPosition().y ) );
|
||||
else if( &aPoints[1] == m_dragPoint )
|
||||
segment->SetEnd( wxPoint( aPoints[1].GetPosition().x, aPoints[1].GetPosition().y ) );
|
||||
if( &(*m_editPoints)[0] == m_dragPoint )
|
||||
segment->SetStart( wxPoint( (*m_editPoints)[0].GetPosition().x, (*m_editPoints)[0].GetPosition().y ) );
|
||||
else if( &(*m_editPoints)[1] == m_dragPoint )
|
||||
segment->SetEnd( wxPoint( (*m_editPoints)[1].GetPosition().x, (*m_editPoints)[1].GetPosition().y ) );
|
||||
|
||||
break;
|
||||
|
||||
case S_ARC:
|
||||
{
|
||||
const VECTOR2I& center = aPoints[0].GetPosition();
|
||||
const VECTOR2I& start = aPoints[1].GetPosition();
|
||||
const VECTOR2I& end = aPoints[2].GetPosition();
|
||||
const VECTOR2I& center = (*m_editPoints)[0].GetPosition();
|
||||
const VECTOR2I& start = (*m_editPoints)[1].GetPosition();
|
||||
const VECTOR2I& end = (*m_editPoints)[2].GetPosition();
|
||||
|
||||
if( center != segment->GetCenter() )
|
||||
{
|
||||
wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter();
|
||||
segment->Move( moveVector );
|
||||
|
||||
aPoints[1].SetPosition( segment->GetArcStart() );
|
||||
aPoints[2].SetPosition( segment->GetArcEnd() );
|
||||
(*m_editPoints)[1].SetPosition( segment->GetArcStart() );
|
||||
(*m_editPoints)[2].SetPosition( segment->GetArcEnd() );
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -270,25 +263,30 @@ void POINT_EDITOR::updateItem( EDA_ITEM* aItem, EDIT_POINTS& aPoints ) const
|
|||
}
|
||||
|
||||
|
||||
void POINT_EDITOR::updatePoints( const EDA_ITEM* aItem, EDIT_POINTS& aPoints ) const
|
||||
void POINT_EDITOR::updatePoints() const
|
||||
{
|
||||
switch( aItem->Type() )
|
||||
if( !m_editPoints )
|
||||
return;
|
||||
|
||||
EDA_ITEM* item = m_editPoints->GetParent();
|
||||
|
||||
switch( item->Type() )
|
||||
{
|
||||
case PCB_LINE_T:
|
||||
{
|
||||
const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( aItem );
|
||||
const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( item );
|
||||
{
|
||||
switch( segment->GetShape() )
|
||||
{
|
||||
case S_SEGMENT:
|
||||
aPoints[0].SetPosition( segment->GetStart() );
|
||||
aPoints[1].SetPosition( segment->GetEnd() );
|
||||
(*m_editPoints)[0].SetPosition( segment->GetStart() );
|
||||
(*m_editPoints)[1].SetPosition( segment->GetEnd() );
|
||||
break;
|
||||
|
||||
case S_ARC:
|
||||
aPoints[0].SetPosition( segment->GetCenter() );
|
||||
aPoints[1].SetPosition( segment->GetArcStart() );
|
||||
aPoints[2].SetPosition( segment->GetArcEnd() );
|
||||
(*m_editPoints)[0].SetPosition( segment->GetCenter() );
|
||||
(*m_editPoints)[1].SetPosition( segment->GetArcStart() );
|
||||
(*m_editPoints)[2].SetPosition( segment->GetArcEnd() );
|
||||
break;
|
||||
|
||||
default: // suppress warnings
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#ifndef __POINT_EDITOR_H
|
||||
#define __POINT_EDITOR_H
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <tool/tool_interactive.h>
|
||||
#include "edit_points.h"
|
||||
|
||||
|
@ -52,7 +54,7 @@ public:
|
|||
*
|
||||
* Change selection event handler.
|
||||
*/
|
||||
int OnSelected( TOOL_EVENT& aEvent );
|
||||
int OnSelectionChange( TOOL_EVENT& aEvent );
|
||||
|
||||
private:
|
||||
///> Selection tool used for obtaining selected items
|
||||
|
@ -61,14 +63,21 @@ private:
|
|||
///> Currently edited point, NULL if there is none.
|
||||
EDIT_POINT* m_dragPoint;
|
||||
|
||||
///> Currently available edit points.
|
||||
boost::shared_ptr<EDIT_POINTS> m_editPoints;
|
||||
|
||||
///> Updates item's points with edit points.
|
||||
void updateItem( EDA_ITEM* aItem, EDIT_POINTS& aPoints ) const;
|
||||
void updateItem() const;
|
||||
|
||||
///> Updates edit points with item's points.
|
||||
void updatePoints( const EDA_ITEM* aItem, EDIT_POINTS& aPoints ) const;
|
||||
void updatePoints() const;
|
||||
|
||||
///> Sets up handlers for various events.
|
||||
void setTransitions();
|
||||
void setTransitions()
|
||||
{
|
||||
Go( &POINT_EDITOR::OnSelectionChange, m_selectionTool->SelectedEvent );
|
||||
Go( &POINT_EDITOR::OnSelectionChange, m_selectionTool->DeselectedEvent );
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue