Loading pcbnew/tools/common_actions.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -99,6 +99,9 @@ TOOL_ACTION COMMON_ACTIONS::routerActivate( "pcbnew.InteractiveRouter", AS_GLOBAL, 0, AS_GLOBAL, 0, "Run push & shove router", "Run push & shove router" ); "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 ) std::string COMMON_ACTIONS::TranslateLegacyId( int aId ) { { Loading pcbnew/tools/common_actions.h +3 −0 Original line number Original line Diff line number Diff line Loading @@ -87,6 +87,9 @@ public: /// Activation of the Push and Shove router /// Activation of the Push and Shove router static TOOL_ACTION routerActivate; static TOOL_ACTION routerActivate; /// Update edit points static TOOL_ACTION pointEditorUpdate; /** /** * Function TranslateLegacyId() * Function TranslateLegacyId() * Translates legacy tool ids to the corresponding TOOL_ACTION name. * Translates legacy tool ids to the corresponding TOOL_ACTION name. Loading pcbnew/tools/edit_points.h +20 −14 Original line number Original line Diff line number Diff line Loading @@ -37,13 +37,13 @@ class EDIT_POINT; class EDIT_POINT_CONSTRAINT class EDIT_POINT_CONSTRAINT { { public: public: EDIT_POINT_CONSTRAINT( EDIT_POINT* aConstrained ) : m_constrained( aConstrained ) {}; EDIT_POINT_CONSTRAINT( EDIT_POINT& aConstrained ) : m_constrained( aConstrained ) {}; virtual ~EDIT_POINT_CONSTRAINT() {}; virtual ~EDIT_POINT_CONSTRAINT() {}; virtual void Apply() = 0; virtual void Apply() = 0; protected: protected: EDIT_POINT* m_constrained; EDIT_POINT& m_constrained; }; }; Loading @@ -53,6 +53,7 @@ class EDIT_POINT public: public: EDIT_POINT( const VECTOR2I& aPoint ) : EDIT_POINT( const VECTOR2I& aPoint ) : m_point( aPoint ), m_constraint( NULL ) {}; m_point( aPoint ), m_constraint( NULL ) {}; ~EDIT_POINT() ~EDIT_POINT() { { delete m_constraint; delete m_constraint; Loading Loading @@ -121,6 +122,11 @@ public: */ */ EDIT_POINT* FindPoint( const VECTOR2I& aLocation ); EDIT_POINT* FindPoint( const VECTOR2I& aLocation ); EDA_ITEM* GetParent() const { return m_parent; } void Add( const EDIT_POINT& aPoint ) void Add( const EDIT_POINT& aPoint ) { { m_points.push_back( aPoint ); m_points.push_back( aPoint ); Loading Loading @@ -172,7 +178,7 @@ private: class EPC_VERTICAL : public EDIT_POINT_CONSTRAINT class EPC_VERTICAL : public EDIT_POINT_CONSTRAINT { { public: public: EPC_VERTICAL( EDIT_POINT* aConstrained, EDIT_POINT& aConstrainer ) : EPC_VERTICAL( EDIT_POINT& aConstrained, EDIT_POINT& aConstrainer ) : EDIT_POINT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) EDIT_POINT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) {} {} Loading @@ -180,9 +186,9 @@ public: virtual void Apply() virtual void Apply() { { VECTOR2I point = m_constrained->GetPosition(); VECTOR2I point = m_constrained.GetPosition(); point.x = m_constrainer.GetPosition().x; point.x = m_constrainer.GetPosition().x; m_constrained->SetPosition( point ); m_constrained.SetPosition( point ); } } virtual std::list<EDIT_POINT*> GetConstrainers() const virtual std::list<EDIT_POINT*> GetConstrainers() const Loading @@ -198,7 +204,7 @@ private: class EPC_HORIZONTAL : public EDIT_POINT_CONSTRAINT class EPC_HORIZONTAL : public EDIT_POINT_CONSTRAINT { { public: 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 ) EDIT_POINT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) {} {} Loading @@ -206,20 +212,20 @@ public: virtual void Apply() virtual void Apply() { { VECTOR2I point = m_constrained->GetPosition(); VECTOR2I point = m_constrained.GetPosition(); point.y = m_constrainer.GetPosition().y; point.y = m_constrainer.GetPosition().y; m_constrained->SetPosition( point ); m_constrained.SetPosition( point ); } } private: private: EDIT_POINT& m_constrainer; const EDIT_POINT& m_constrainer; }; }; class EPC_CIRCLE : public EDIT_POINT_CONSTRAINT class EPC_CIRCLE : public EDIT_POINT_CONSTRAINT { { public: 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 ) EDIT_POINT_CONSTRAINT( aConstrained ), m_center( aCenter ), m_end( aEnd ) {} {} Loading @@ -228,7 +234,7 @@ public: virtual void Apply() virtual void Apply() { { VECTOR2I centerToEnd = m_end.GetPosition() - m_center.GetPosition(); 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(); int radius = centerToEnd.EuclideanNorm(); double angle = centerToPoint.Angle(); double angle = centerToPoint.Angle(); Loading @@ -236,12 +242,12 @@ public: VECTOR2I newLine( radius, 0 ); VECTOR2I newLine( radius, 0 ); newLine = newLine.Rotate( angle ); newLine = newLine.Rotate( angle ); m_constrained->SetPosition( m_center.GetPosition() + newLine ); m_constrained.SetPosition( m_center.GetPosition() + newLine ); } } private: private: EDIT_POINT& m_center; const EDIT_POINT& m_center; EDIT_POINT& m_end; const EDIT_POINT& m_end; }; }; #endif /* EDIT_POINTS_H_ */ #endif /* EDIT_POINTS_H_ */ pcbnew/tools/edit_tool.cpp +13 −7 Original line number Original line Diff line number Diff line Loading @@ -151,6 +151,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); dragPosition = controls->GetCursorPosition(); dragPosition = controls->GetCursorPosition(); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); } } else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) Loading Loading @@ -233,6 +234,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); } } m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); setTransitions(); setTransitions(); return 0; return 0; Loading Loading @@ -268,9 +270,6 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } setTransitions(); updateRatsnest( true ); if( m_dragging ) if( m_dragging ) selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); else else Loading @@ -279,6 +278,11 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) if( unselect ) if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); updateRatsnest( true ); setTransitions(); return 0; return 0; } } Loading Loading @@ -312,9 +316,6 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); } } setTransitions(); updateRatsnest( true ); if( m_dragging ) if( m_dragging ) selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); else else Loading @@ -323,6 +324,11 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) if( unselect ) if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); updateRatsnest( true ); setTransitions(); return 0; return 0; } } Loading Loading @@ -359,8 +365,8 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) if( !( board->m_Status_Pcb & NET_CODES_OK ) ) if( !( board->m_Status_Pcb & NET_CODES_OK ) ) board->BuildListOfNets(); board->BuildListOfNets(); board->GetRatsnest()->Recalculate(); // TODO is it necessary? setTransitions(); setTransitions(); board->GetRatsnest()->Recalculate(); return 0; return 0; } } Loading pcbnew/tools/point_editor.cpp +63 −65 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ */ #include <boost/make_shared.hpp> #include <tool/tool_manager.h> #include <tool/tool_manager.h> #include <view/view_controls.h> #include <view/view_controls.h> #include <confirm.h> #include <confirm.h> Loading @@ -41,10 +43,10 @@ class EDIT_POINTS_FACTORY class EDIT_POINTS_FACTORY { { public: 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 // 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() ) switch( aItem->Type() ) { { Loading @@ -55,19 +57,19 @@ public: switch( segment->GetShape() ) switch( segment->GetShape() ) { { case S_SEGMENT: case S_SEGMENT: points.Add( segment->GetStart() ); points->Add( segment->GetStart() ); points.Add( segment->GetEnd() ); points->Add( segment->GetEnd() ); break; break; case S_ARC: case S_ARC: points.Add( segment->GetCenter() ); // points[0] points->Add( segment->GetCenter() ); // points[0] points.Add( segment->GetArcStart() ); // points[1] points->Add( segment->GetArcStart() ); // points[1] points.Add( segment->GetArcEnd() ); // points[2] points->Add( segment->GetArcEnd() ); // points[2] // Set constraints // Set constraints // Arc end has to stay at the same radius as the start // 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; break; default: // suppress warnings default: // suppress warnings Loading Loading @@ -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(); const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); m_dragPoint = NULL; m_dragPoint = NULL; Loading @@ -125,24 +124,15 @@ int POINT_EDITOR::OnSelected( TOOL_EVENT& aEvent ) Activate(); Activate(); EDA_ITEM* item = selection.items.GetPickedItem( 0 ); EDA_ITEM* item = selection.items.GetPickedItem( 0 ); EDIT_POINTS editPoints = EDIT_POINTS_FACTORY::Make( item ); m_editPoints = EDIT_POINTS_FACTORY::Make( item ); m_toolMgr->GetView()->Add( &editPoints ); m_toolMgr->GetView()->Add( m_editPoints.get() ); // Main loop: keep receiving events // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() ) { { if( evt->IsCancel() || if( evt->IsMotion() ) evt->Matches( m_selectionTool->ClearedEvent ) || evt->Matches( m_selectionTool->DeselectedEvent ) || evt->Matches( m_selectionTool->SelectedEvent ) ) { { m_toolMgr->PassEvent(); EDIT_POINT* point = m_editPoints->FindPoint( evt->Position() ); break; } else if( evt->IsMotion() ) { EDIT_POINT* point = editPoints.FindPoint( evt->Position() ); if( m_dragPoint != point ) if( m_dragPoint != point ) { { Loading @@ -163,30 +153,37 @@ int POINT_EDITOR::OnSelected( TOOL_EVENT& aEvent ) m_dragPoint = point; 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->SetPosition( controls->GetCursorPosition() ); m_dragPoint->ApplyConstraint(); m_dragPoint->ApplyConstraint(); updateItem( item, editPoints ); updateItem(); updatePoints( item, editPoints ); updatePoints(); editPoints.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_editPoints->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else else if( evt->IsAction( &COMMON_ACTIONS::pointEditorUpdate ) ) { { m_toolMgr->PassEvent(); updatePoints(); } } else if( evt->IsCancel() || evt->Matches( m_selectionTool->ClearedEvent ) || evt->Matches( m_selectionTool->DeselectedEvent ) || evt->Matches( m_selectionTool->SelectedEvent ) ) { break; } } else if( evt->IsClick( BUT_LEFT ) ) else { { m_toolMgr->PassEvent(); m_toolMgr->PassEvent(); } } } } m_toolMgr->GetView()->Remove( &editPoints ); m_toolMgr->GetView()->Remove( m_editPoints.get() ); m_editPoints.reset(); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } Loading @@ -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(); } switch( item->Type() ) void POINT_EDITOR::updateItem( EDA_ITEM* aItem, EDIT_POINTS& aPoints ) const { switch( aItem->Type() ) { { case PCB_LINE_T: case PCB_LINE_T: { { DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( aItem ); DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item ); switch( segment->GetShape() ) switch( segment->GetShape() ) { { case S_SEGMENT: case S_SEGMENT: if( &aPoints[0] == m_dragPoint ) if( &(*m_editPoints)[0] == m_dragPoint ) segment->SetStart( wxPoint( aPoints[0].GetPosition().x, aPoints[0].GetPosition().y ) ); segment->SetStart( wxPoint( (*m_editPoints)[0].GetPosition().x, (*m_editPoints)[0].GetPosition().y ) ); else if( &aPoints[1] == m_dragPoint ) else if( &(*m_editPoints)[1] == m_dragPoint ) segment->SetEnd( wxPoint( aPoints[1].GetPosition().x, aPoints[1].GetPosition().y ) ); segment->SetEnd( wxPoint( (*m_editPoints)[1].GetPosition().x, (*m_editPoints)[1].GetPosition().y ) ); break; break; case S_ARC: case S_ARC: { { const VECTOR2I& center = aPoints[0].GetPosition(); const VECTOR2I& center = (*m_editPoints)[0].GetPosition(); const VECTOR2I& start = aPoints[1].GetPosition(); const VECTOR2I& start = (*m_editPoints)[1].GetPosition(); const VECTOR2I& end = aPoints[2].GetPosition(); const VECTOR2I& end = (*m_editPoints)[2].GetPosition(); if( center != segment->GetCenter() ) if( center != segment->GetCenter() ) { { wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter(); wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter(); segment->Move( moveVector ); segment->Move( moveVector ); aPoints[1].SetPosition( segment->GetArcStart() ); (*m_editPoints)[1].SetPosition( segment->GetArcStart() ); aPoints[2].SetPosition( segment->GetArcEnd() ); (*m_editPoints)[2].SetPosition( segment->GetArcEnd() ); } } else else Loading Loading @@ -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: case PCB_LINE_T: { { const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( aItem ); const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( item ); { { switch( segment->GetShape() ) switch( segment->GetShape() ) { { case S_SEGMENT: case S_SEGMENT: aPoints[0].SetPosition( segment->GetStart() ); (*m_editPoints)[0].SetPosition( segment->GetStart() ); aPoints[1].SetPosition( segment->GetEnd() ); (*m_editPoints)[1].SetPosition( segment->GetEnd() ); break; break; case S_ARC: case S_ARC: aPoints[0].SetPosition( segment->GetCenter() ); (*m_editPoints)[0].SetPosition( segment->GetCenter() ); aPoints[1].SetPosition( segment->GetArcStart() ); (*m_editPoints)[1].SetPosition( segment->GetArcStart() ); aPoints[2].SetPosition( segment->GetArcEnd() ); (*m_editPoints)[2].SetPosition( segment->GetArcEnd() ); break; break; default: // suppress warnings default: // suppress warnings Loading Loading
pcbnew/tools/common_actions.cpp +3 −0 Original line number Original line Diff line number Diff line Loading @@ -99,6 +99,9 @@ TOOL_ACTION COMMON_ACTIONS::routerActivate( "pcbnew.InteractiveRouter", AS_GLOBAL, 0, AS_GLOBAL, 0, "Run push & shove router", "Run push & shove router" ); "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 ) std::string COMMON_ACTIONS::TranslateLegacyId( int aId ) { { Loading
pcbnew/tools/common_actions.h +3 −0 Original line number Original line Diff line number Diff line Loading @@ -87,6 +87,9 @@ public: /// Activation of the Push and Shove router /// Activation of the Push and Shove router static TOOL_ACTION routerActivate; static TOOL_ACTION routerActivate; /// Update edit points static TOOL_ACTION pointEditorUpdate; /** /** * Function TranslateLegacyId() * Function TranslateLegacyId() * Translates legacy tool ids to the corresponding TOOL_ACTION name. * Translates legacy tool ids to the corresponding TOOL_ACTION name. Loading
pcbnew/tools/edit_points.h +20 −14 Original line number Original line Diff line number Diff line Loading @@ -37,13 +37,13 @@ class EDIT_POINT; class EDIT_POINT_CONSTRAINT class EDIT_POINT_CONSTRAINT { { public: public: EDIT_POINT_CONSTRAINT( EDIT_POINT* aConstrained ) : m_constrained( aConstrained ) {}; EDIT_POINT_CONSTRAINT( EDIT_POINT& aConstrained ) : m_constrained( aConstrained ) {}; virtual ~EDIT_POINT_CONSTRAINT() {}; virtual ~EDIT_POINT_CONSTRAINT() {}; virtual void Apply() = 0; virtual void Apply() = 0; protected: protected: EDIT_POINT* m_constrained; EDIT_POINT& m_constrained; }; }; Loading @@ -53,6 +53,7 @@ class EDIT_POINT public: public: EDIT_POINT( const VECTOR2I& aPoint ) : EDIT_POINT( const VECTOR2I& aPoint ) : m_point( aPoint ), m_constraint( NULL ) {}; m_point( aPoint ), m_constraint( NULL ) {}; ~EDIT_POINT() ~EDIT_POINT() { { delete m_constraint; delete m_constraint; Loading Loading @@ -121,6 +122,11 @@ public: */ */ EDIT_POINT* FindPoint( const VECTOR2I& aLocation ); EDIT_POINT* FindPoint( const VECTOR2I& aLocation ); EDA_ITEM* GetParent() const { return m_parent; } void Add( const EDIT_POINT& aPoint ) void Add( const EDIT_POINT& aPoint ) { { m_points.push_back( aPoint ); m_points.push_back( aPoint ); Loading Loading @@ -172,7 +178,7 @@ private: class EPC_VERTICAL : public EDIT_POINT_CONSTRAINT class EPC_VERTICAL : public EDIT_POINT_CONSTRAINT { { public: public: EPC_VERTICAL( EDIT_POINT* aConstrained, EDIT_POINT& aConstrainer ) : EPC_VERTICAL( EDIT_POINT& aConstrained, EDIT_POINT& aConstrainer ) : EDIT_POINT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) EDIT_POINT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) {} {} Loading @@ -180,9 +186,9 @@ public: virtual void Apply() virtual void Apply() { { VECTOR2I point = m_constrained->GetPosition(); VECTOR2I point = m_constrained.GetPosition(); point.x = m_constrainer.GetPosition().x; point.x = m_constrainer.GetPosition().x; m_constrained->SetPosition( point ); m_constrained.SetPosition( point ); } } virtual std::list<EDIT_POINT*> GetConstrainers() const virtual std::list<EDIT_POINT*> GetConstrainers() const Loading @@ -198,7 +204,7 @@ private: class EPC_HORIZONTAL : public EDIT_POINT_CONSTRAINT class EPC_HORIZONTAL : public EDIT_POINT_CONSTRAINT { { public: 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 ) EDIT_POINT_CONSTRAINT( aConstrained ), m_constrainer( aConstrainer ) {} {} Loading @@ -206,20 +212,20 @@ public: virtual void Apply() virtual void Apply() { { VECTOR2I point = m_constrained->GetPosition(); VECTOR2I point = m_constrained.GetPosition(); point.y = m_constrainer.GetPosition().y; point.y = m_constrainer.GetPosition().y; m_constrained->SetPosition( point ); m_constrained.SetPosition( point ); } } private: private: EDIT_POINT& m_constrainer; const EDIT_POINT& m_constrainer; }; }; class EPC_CIRCLE : public EDIT_POINT_CONSTRAINT class EPC_CIRCLE : public EDIT_POINT_CONSTRAINT { { public: 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 ) EDIT_POINT_CONSTRAINT( aConstrained ), m_center( aCenter ), m_end( aEnd ) {} {} Loading @@ -228,7 +234,7 @@ public: virtual void Apply() virtual void Apply() { { VECTOR2I centerToEnd = m_end.GetPosition() - m_center.GetPosition(); 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(); int radius = centerToEnd.EuclideanNorm(); double angle = centerToPoint.Angle(); double angle = centerToPoint.Angle(); Loading @@ -236,12 +242,12 @@ public: VECTOR2I newLine( radius, 0 ); VECTOR2I newLine( radius, 0 ); newLine = newLine.Rotate( angle ); newLine = newLine.Rotate( angle ); m_constrained->SetPosition( m_center.GetPosition() + newLine ); m_constrained.SetPosition( m_center.GetPosition() + newLine ); } } private: private: EDIT_POINT& m_center; const EDIT_POINT& m_center; EDIT_POINT& m_end; const EDIT_POINT& m_end; }; }; #endif /* EDIT_POINTS_H_ */ #endif /* EDIT_POINTS_H_ */
pcbnew/tools/edit_tool.cpp +13 −7 Original line number Original line Diff line number Diff line Loading @@ -151,6 +151,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); selection.group->ViewUpdate( VIEW_ITEM::GEOMETRY ); dragPosition = controls->GetCursorPosition(); dragPosition = controls->GetCursorPosition(); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); } } else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) Loading Loading @@ -233,6 +234,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); } } m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); setTransitions(); setTransitions(); return 0; return 0; Loading Loading @@ -268,9 +270,6 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } setTransitions(); updateRatsnest( true ); if( m_dragging ) if( m_dragging ) selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); else else Loading @@ -279,6 +278,11 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) if( unselect ) if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); updateRatsnest( true ); setTransitions(); return 0; return 0; } } Loading Loading @@ -312,9 +316,6 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS ); } } setTransitions(); updateRatsnest( true ); if( m_dragging ) if( m_dragging ) selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); else else Loading @@ -323,6 +324,11 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) if( unselect ) if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate ); updateRatsnest( true ); setTransitions(); return 0; return 0; } } Loading Loading @@ -359,8 +365,8 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) if( !( board->m_Status_Pcb & NET_CODES_OK ) ) if( !( board->m_Status_Pcb & NET_CODES_OK ) ) board->BuildListOfNets(); board->BuildListOfNets(); board->GetRatsnest()->Recalculate(); // TODO is it necessary? setTransitions(); setTransitions(); board->GetRatsnest()->Recalculate(); return 0; return 0; } } Loading
pcbnew/tools/point_editor.cpp +63 −65 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ */ #include <boost/make_shared.hpp> #include <tool/tool_manager.h> #include <tool/tool_manager.h> #include <view/view_controls.h> #include <view/view_controls.h> #include <confirm.h> #include <confirm.h> Loading @@ -41,10 +43,10 @@ class EDIT_POINTS_FACTORY class EDIT_POINTS_FACTORY { { public: 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 // 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() ) switch( aItem->Type() ) { { Loading @@ -55,19 +57,19 @@ public: switch( segment->GetShape() ) switch( segment->GetShape() ) { { case S_SEGMENT: case S_SEGMENT: points.Add( segment->GetStart() ); points->Add( segment->GetStart() ); points.Add( segment->GetEnd() ); points->Add( segment->GetEnd() ); break; break; case S_ARC: case S_ARC: points.Add( segment->GetCenter() ); // points[0] points->Add( segment->GetCenter() ); // points[0] points.Add( segment->GetArcStart() ); // points[1] points->Add( segment->GetArcStart() ); // points[1] points.Add( segment->GetArcEnd() ); // points[2] points->Add( segment->GetArcEnd() ); // points[2] // Set constraints // Set constraints // Arc end has to stay at the same radius as the start // 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; break; default: // suppress warnings default: // suppress warnings Loading Loading @@ -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(); const SELECTION_TOOL::SELECTION& selection = m_selectionTool->GetSelection(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); m_dragPoint = NULL; m_dragPoint = NULL; Loading @@ -125,24 +124,15 @@ int POINT_EDITOR::OnSelected( TOOL_EVENT& aEvent ) Activate(); Activate(); EDA_ITEM* item = selection.items.GetPickedItem( 0 ); EDA_ITEM* item = selection.items.GetPickedItem( 0 ); EDIT_POINTS editPoints = EDIT_POINTS_FACTORY::Make( item ); m_editPoints = EDIT_POINTS_FACTORY::Make( item ); m_toolMgr->GetView()->Add( &editPoints ); m_toolMgr->GetView()->Add( m_editPoints.get() ); // Main loop: keep receiving events // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) while( OPT_TOOL_EVENT evt = Wait() ) { { if( evt->IsCancel() || if( evt->IsMotion() ) evt->Matches( m_selectionTool->ClearedEvent ) || evt->Matches( m_selectionTool->DeselectedEvent ) || evt->Matches( m_selectionTool->SelectedEvent ) ) { { m_toolMgr->PassEvent(); EDIT_POINT* point = m_editPoints->FindPoint( evt->Position() ); break; } else if( evt->IsMotion() ) { EDIT_POINT* point = editPoints.FindPoint( evt->Position() ); if( m_dragPoint != point ) if( m_dragPoint != point ) { { Loading @@ -163,30 +153,37 @@ int POINT_EDITOR::OnSelected( TOOL_EVENT& aEvent ) m_dragPoint = point; 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->SetPosition( controls->GetCursorPosition() ); m_dragPoint->ApplyConstraint(); m_dragPoint->ApplyConstraint(); updateItem( item, editPoints ); updateItem(); updatePoints( item, editPoints ); updatePoints(); editPoints.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_editPoints->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else else if( evt->IsAction( &COMMON_ACTIONS::pointEditorUpdate ) ) { { m_toolMgr->PassEvent(); updatePoints(); } } else if( evt->IsCancel() || evt->Matches( m_selectionTool->ClearedEvent ) || evt->Matches( m_selectionTool->DeselectedEvent ) || evt->Matches( m_selectionTool->SelectedEvent ) ) { break; } } else if( evt->IsClick( BUT_LEFT ) ) else { { m_toolMgr->PassEvent(); m_toolMgr->PassEvent(); } } } } m_toolMgr->GetView()->Remove( &editPoints ); m_toolMgr->GetView()->Remove( m_editPoints.get() ); m_editPoints.reset(); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } Loading @@ -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(); } switch( item->Type() ) void POINT_EDITOR::updateItem( EDA_ITEM* aItem, EDIT_POINTS& aPoints ) const { switch( aItem->Type() ) { { case PCB_LINE_T: case PCB_LINE_T: { { DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( aItem ); DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item ); switch( segment->GetShape() ) switch( segment->GetShape() ) { { case S_SEGMENT: case S_SEGMENT: if( &aPoints[0] == m_dragPoint ) if( &(*m_editPoints)[0] == m_dragPoint ) segment->SetStart( wxPoint( aPoints[0].GetPosition().x, aPoints[0].GetPosition().y ) ); segment->SetStart( wxPoint( (*m_editPoints)[0].GetPosition().x, (*m_editPoints)[0].GetPosition().y ) ); else if( &aPoints[1] == m_dragPoint ) else if( &(*m_editPoints)[1] == m_dragPoint ) segment->SetEnd( wxPoint( aPoints[1].GetPosition().x, aPoints[1].GetPosition().y ) ); segment->SetEnd( wxPoint( (*m_editPoints)[1].GetPosition().x, (*m_editPoints)[1].GetPosition().y ) ); break; break; case S_ARC: case S_ARC: { { const VECTOR2I& center = aPoints[0].GetPosition(); const VECTOR2I& center = (*m_editPoints)[0].GetPosition(); const VECTOR2I& start = aPoints[1].GetPosition(); const VECTOR2I& start = (*m_editPoints)[1].GetPosition(); const VECTOR2I& end = aPoints[2].GetPosition(); const VECTOR2I& end = (*m_editPoints)[2].GetPosition(); if( center != segment->GetCenter() ) if( center != segment->GetCenter() ) { { wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter(); wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter(); segment->Move( moveVector ); segment->Move( moveVector ); aPoints[1].SetPosition( segment->GetArcStart() ); (*m_editPoints)[1].SetPosition( segment->GetArcStart() ); aPoints[2].SetPosition( segment->GetArcEnd() ); (*m_editPoints)[2].SetPosition( segment->GetArcEnd() ); } } else else Loading Loading @@ -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: case PCB_LINE_T: { { const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( aItem ); const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( item ); { { switch( segment->GetShape() ) switch( segment->GetShape() ) { { case S_SEGMENT: case S_SEGMENT: aPoints[0].SetPosition( segment->GetStart() ); (*m_editPoints)[0].SetPosition( segment->GetStart() ); aPoints[1].SetPosition( segment->GetEnd() ); (*m_editPoints)[1].SetPosition( segment->GetEnd() ); break; break; case S_ARC: case S_ARC: aPoints[0].SetPosition( segment->GetCenter() ); (*m_editPoints)[0].SetPosition( segment->GetCenter() ); aPoints[1].SetPosition( segment->GetArcStart() ); (*m_editPoints)[1].SetPosition( segment->GetArcStart() ); aPoints[2].SetPosition( segment->GetArcEnd() ); (*m_editPoints)[2].SetPosition( segment->GetArcEnd() ); break; break; default: // suppress warnings default: // suppress warnings Loading