From 24f1f22de48301869843dad2130f75a2c3947387 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 6 May 2014 17:04:53 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Give V3d_view to the operation to calculate correctly a projection to sketch plane. --- src/PartSet/PartSet_Module.cpp | 13 +++---------- src/PartSet/PartSet_OperationEditLine.cpp | 14 +++++++++----- src/PartSet/PartSet_OperationEditLine.h | 4 ++-- src/PartSet/PartSet_OperationSketchBase.cpp | 13 +++++++++++++ src/PartSet/PartSet_OperationSketchBase.h | 8 ++++---- src/PartSet/PartSet_OperationSketchLine.cpp | 20 ++++++++++++++------ src/PartSet/PartSet_OperationSketchLine.h | 4 ++-- 7 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index d77c02df5..0939b57fe 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include @@ -150,9 +149,7 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), - myWorkshop->viewer()->activeView()); - aPreviewOp->mousePressed(aPnt, theEvent); + aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView()); } } @@ -162,9 +159,7 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), - myWorkshop->viewer()->activeView()); - aPreviewOp->mouseReleased(aPnt, theEvent); + aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView()); } } @@ -174,9 +169,7 @@ void PartSet_Module::onMouseMoved(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), - myWorkshop->viewer()->activeView()); - aPreviewOp->mouseMoved(aPnt, theEvent); + aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView()); } } diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index 784194575..1085f2d33 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -12,6 +12,8 @@ #include +#include + #ifdef _DEBUG #include #endif @@ -49,14 +51,15 @@ void PartSet_OperationEditLine::init(boost::shared_ptr theFeat setFeature(theFeature); } -void PartSet_OperationEditLine::mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent) +void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView) { if (!(theEvent->buttons() & Qt::LeftButton)) return; - myCurPressed = thePoint; + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + myCurPressed = aPoint; } -void PartSet_OperationEditLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent) +void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { if (!(theEvent->buttons() & Qt::LeftButton)) return; @@ -65,14 +68,15 @@ void PartSet_OperationEditLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent* PartSet_Tools::ConvertTo2D(myCurPressed, mySketch, aCurX, aCurY); double aX, anY; - PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY); + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + PartSet_Tools::ConvertTo2D(aPoint, mySketch, aX, anY); double aDeltaX = aX - aCurX; double aDeltaY = anY - aCurY; moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_START); moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_END); - myCurPressed = thePoint; + myCurPressed = aPoint; } void PartSet_OperationEditLine::setSelected(boost::shared_ptr theFeature, diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h index 28ae00298..01a705386 100644 --- a/src/PartSet/PartSet_OperationEditLine.h +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -49,11 +49,11 @@ public: /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent); + virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView); /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent); + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); /// Gives the current selected objects to be processed by the operation /// \param theFeature the selected feature diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index d424849b1..08e743572 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -6,6 +6,8 @@ #include +#include + #ifdef _DEBUG #include #endif @@ -36,3 +38,14 @@ boost::shared_ptr PartSet_OperationSketchBase::createFeature() emit featureConstructed(aFeature, FM_Activation); return aFeature; } + + +void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView) +{ +} +void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView) +{ +} +void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +{ +} diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index a7bcf789a..45a6b77d4 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -15,8 +15,8 @@ #include #include +class Handle_V3d_View; class QMouseEvent; - class GeomAPI_Shape; /*! @@ -60,17 +60,17 @@ public: /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent) {}; + virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView); /// Processes the mouse release in the point /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseReleased(const gp_Pnt& thePoint, QMouseEvent* theEvent) {}; + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView); /// Processes the mouse move in the point /// \param thePoint a 3D point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent) {}; + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); /// Processes the key pressed in the view /// \param theKey a key value diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index cc4c02ede..a0ab16944 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -13,10 +13,14 @@ #include +#include + #ifdef _DEBUG #include #endif +#include + using namespace std; PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId, @@ -50,17 +54,18 @@ void PartSet_OperationSketchLine::init(boost::shared_ptr theFe myInitPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); } -void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/) +void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView) { + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); switch (myPointSelectionMode) { case SM_FirstPoint: { - setLinePoint(thePoint, LINE_ATTR_START); + setLinePoint(aPoint, LINE_ATTR_START); myPointSelectionMode = SM_SecondPoint; } break; case SM_SecondPoint: { - setLinePoint(thePoint, LINE_ATTR_END); + setLinePoint(aPoint, LINE_ATTR_END); commit(); emit featureConstructed(feature(), FM_Deactivation); emit launchOperation(PartSet_OperationSketchLine::Type(), feature()); @@ -71,13 +76,16 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEv } } -void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/) +void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { switch (myPointSelectionMode) { case SM_SecondPoint: - setLinePoint(thePoint, LINE_ATTR_END); - break; + { + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + setLinePoint(aPoint, LINE_ATTR_END); + } + break; default: break; } diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index 044e739ff..e979034dd 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -51,11 +51,11 @@ public: /// Gives the current selected objects to be processed by the operation /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseReleased(const gp_Pnt& thePoint, QMouseEvent* theEvent); + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView); /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent); + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); /// Processes the key pressed in the view /// \param theKey a key value virtual void keyReleased(const int theKey); -- 2.39.2