From: nds Date: Wed, 14 May 2014 07:25:48 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~65^2^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1d7a043abfadf964bf38802e8adb5a4773fec900;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Edit for milti selected lines --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 2ad243d68..d7a92caf5 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -143,7 +143,6 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) if (aSelector) { NCollection_List aList; aSelector->selectedShapes(aList); - aPresentations = myWorkshop->displayer()->GetViewerPrs(aList); } aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations); @@ -156,7 +155,14 @@ void PartSet_Module::onMouseMoved(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView()); + XGUI_SelectionMgr* aSelector = myWorkshop->selector(); + std::list aPresentations; + if (aSelector) { + NCollection_List aList; + aSelector->selectedShapes(aList); + aPresentations = myWorkshop->displayer()->GetViewerPrs(aList); + } + aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView(), aPresentations); } } @@ -202,6 +208,12 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled) aViewer->enableMultiselection(theEnabled); } +void PartSet_Module::onSelectionEnabled(bool theEnabled) +{ + XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + aViewer->enableSelection(theEnabled); +} + void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, int theMode) { @@ -252,6 +264,8 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI this, SLOT(onLaunchOperation(std::string, boost::shared_ptr))); connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this, SLOT(onMultiSelectionEnabled(bool))); + connect(aPreviewOp, SIGNAL(selectionEnabled(bool)), + this, SLOT(onSelectionEnabled(bool))); PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); if (aSketchOp) { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 82fe68b4f..6138a43dc 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -79,6 +79,10 @@ public slots: /// \param theEnabled the enabled state void onMultiSelectionEnabled(bool theEnabled); + /// SLOT, to switch on/off the selection in the viewer + /// \param theEnabled the enabled state + void onSelectionEnabled(bool theEnabled); + /// SLOT, to visualize the feature in another local context mode /// \param theFeature the feature to be put in another local context mode /// \param theMode the mode appeared on the feature diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index 5f7c7ebca..f0049b007 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -58,27 +58,39 @@ void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_V if (!(theEvent->buttons() & Qt::LeftButton)) return; gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); - myCurPressed = aPoint; + myCurPoint.setPoint(aPoint); } -void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected) { if (!(theEvent->buttons() & Qt::LeftButton)) return; - - double aCurX, aCurY; - PartSet_Tools::ConvertTo2D(myCurPressed, mySketch, theView, aCurX, aCurY); - - double aX, anY; gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); - PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); - - double aDeltaX = aX - aCurX; - double aDeltaY = anY - aCurY; - moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_START); - moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_END); - myCurPressed = aPoint; + if (myCurPoint.myIsInitialized) { + double aCurX, aCurY; + PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY); + + double aX, anY; + PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); + + double aDeltaX = aX - aCurX; + double aDeltaY = anY - aCurY; + + moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_START); + moveLinePoint(feature(), aDeltaX, aDeltaY, LINE_ATTR_END); + + /*std::list::const_iterator anIt = theSelected.begin(), aLast = theSelected.end(); + for (; anIt != aLast; anIt++) { + boost::shared_ptr aFeature = (*anIt).feature(); + if (!aFeature) + continue; + moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_START); + moveLinePoint(aFeature, aDeltaX, aDeltaY, LINE_ATTR_END); + }*/ + } + myCurPoint.setPoint(aPoint); } void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, @@ -99,12 +111,13 @@ void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_ void PartSet_OperationEditLine::startOperation() { // do nothing in order to do not create a new feature - emit multiSelectionEnabled(false); + emit selectionEnabled(false); + myCurPoint.clear(); } void PartSet_OperationEditLine::stopOperation() { - emit multiSelectionEnabled(true); + emit selectionEnabled(true); } boost::shared_ptr PartSet_OperationEditLine::createFeature() @@ -113,10 +126,14 @@ boost::shared_ptr PartSet_OperationEditLine::createFeature() return boost::shared_ptr(); } -void PartSet_OperationEditLine::moveLinePoint(double theDeltaX, double theDeltaY, +void PartSet_OperationEditLine::moveLinePoint(boost::shared_ptr theFeature, + double theDeltaX, double theDeltaY, const std::string& theAttribute) { - boost::shared_ptr aData = feature()->data(); + if (!theFeature) + return; + + boost::shared_ptr aData = theFeature->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h index a935f2f70..826a5f9ae 100644 --- a/src/PartSet/PartSet_OperationEditLine.h +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -19,6 +19,33 @@ class QMouseEvent; class PARTSET_EXPORT PartSet_OperationEditLine : public PartSet_OperationSketchBase { Q_OBJECT + /// Struct to define gp point, with the state is the point is initialized + struct Point + { + /// Constructor + Point() {} + /// Constructor + /// \param thePoint the point + Point(gp_Pnt thePoint) + { + setPoint(thePoint); + } + ~Point() {} + + /// clear the initialized flag. + void clear() { myIsInitialized = false; } + /// set the point and switch on the initialized flag + /// \param thePoint the point + void setPoint(const gp_Pnt& thePoint) + { + myIsInitialized = true; + myPoint = thePoint; + } + + bool myIsInitialized; /// the state whether the point is set + gp_Pnt myPoint; /// the point + }; + public: /// Returns the operation type key static std::string Type() { return "EditLine"; } @@ -53,13 +80,15 @@ public: /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); + /// \param theSelected the list of selected presentations + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected); /// Gives the current selected objects to be processed by the operation /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event /// \param theSelected the list of selected presentations virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected); + const std::list& theSelected); protected: /// \brief Virtual method called when operation is started /// Virtual method called when operation started (see start() method for more description) @@ -77,14 +106,17 @@ protected: protected: /// \brief Save the point to the line. + /// \param theFeature the source feature /// \param theDeltaX the delta for X coordinate is moved /// \param theDeltaY the delta for Y coordinate is moved /// \param theAttribute the start or end attribute of the line - void moveLinePoint(double theDeltaX, double theDeltaY, + void moveLinePoint(boost::shared_ptr theFeature, + double theDeltaX, double theDeltaY, const std::string& theAttribute); private: boost::shared_ptr mySketch; ///< the sketch feature + Point myCurPoint; ///< the current 3D point clicked or moved gp_Pnt myCurPressed; ///< the current 3D point clicked or moved }; diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 04de17112..e5290aa77 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -5,8 +5,10 @@ #include #include +#include #include + #include #include #include @@ -23,6 +25,8 @@ #include #endif +#include + using namespace std; PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, @@ -52,19 +56,27 @@ void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_Vi { if (theSelected.empty()) return; - XGUI_ViewerPrs aPrs = theSelected.front(); if (!myIsEditMode) { + XGUI_ViewerPrs aPrs = theSelected.front(); const TopoDS_Shape& aShape = aPrs.shape(); if (!aShape.IsNull()) { setSketchPlane(aShape); myIsEditMode = true; } } - else { - if (aPrs.feature()) - emit launchOperation(PartSet_OperationEditLine::Type(), aPrs.feature()); - } +} + +void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected) +{ + if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || theSelected.empty()) + return; + + boost::shared_ptr aFeature = PartSet_Tools::NearestFeature(theEvent->pos(), + theView, feature(), theSelected); + if (aFeature) + emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); } void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) @@ -107,4 +119,3 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) boost::shared_ptr aDir = aPlane->direction(); emit planeSelected(aDir->x(), aDir->y(), aDir->z()); } - diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index acc374e41..227722dc7 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -40,6 +40,12 @@ public: /// \param theSelected the list of selected presentations virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, const std::list& theSelected); + /// Gives the current mouse point in the viewer + /// \param thePoint a point clicked in the viewer + /// \param theEvent the mouse event + /// \param theSelected the list of selected presentations + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected); signals: /// signal about the sketch plane is selected diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 85c0a2c30..4113c3cba 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -47,6 +47,7 @@ void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3 const std::list& theSelected) { } -void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected) { } diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index d13358515..b30f29935 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -67,7 +67,9 @@ public: /// Processes the mouse move in the point /// \param thePoint a 3D point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); + /// \param theSelected the list of selected presentations + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected); /// Processes the key pressed in the view /// \param theKey a key value @@ -87,6 +89,10 @@ signals: /// \param theEnabled the boolean state void multiSelectionEnabled(bool theEnabled); + /// signal to enable/disable usual selection in the viewer + /// \param theEnabled the boolean state + void selectionEnabled(bool theEnabled); + protected: /// Creates an operation new feature /// In addition to the default realization it appends the created line feature to diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 6baec986b..97fd78c74 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -79,9 +79,11 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 { double aX, anY; + bool isFoundPoint = false; gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); if (theSelected.empty()) { PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); + isFoundPoint = true; } else { XGUI_ViewerPrs aPrs = theSelected.front(); @@ -93,6 +95,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 if (!aVertex.IsNull()) { aPoint = BRep_Tool::Pnt(aVertex); PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); + isFoundPoint = true; setConstraints(aX, anY); } @@ -119,10 +122,14 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 default: break; } + isFoundPoint = true; } } } } + //if (!isFoundPoint) + // return; + switch (myPointSelectionMode) { case SM_FirstPoint: { @@ -142,7 +149,8 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 } } -void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +void PartSet_OperationSketchLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& /*theSelected*/) { switch (myPointSelectionMode) { diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index c06462d7a..b048ef8a7 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -57,7 +57,9 @@ public: /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); + /// \param theSelected the list of selected presentations + virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected); /// Processes the key pressed in the view /// \param theKey a key value virtual void keyReleased(const int theKey); diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 3caf619ca..2c7a93b06 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -9,11 +9,15 @@ #include #include +#include #include #include #include +#include + +#include #include #include @@ -139,3 +143,53 @@ void PartSet_Tools::ProjectPointOnLine(double theX1, double theY1, double theX2, theY = aPoint.Y(); } } + +boost::shared_ptr PartSet_Tools::NearestFeature(QPoint thePoint, + Handle_V3d_View theView, + boost::shared_ptr theSketch, + const std::list& theFeatures) +{ + double aX, anY; + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, theView); + PartSet_Tools::ConvertTo2D(aPoint, theSketch, theView, aX, anY); + + boost::shared_ptr aFeature; + std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); + + boost::shared_ptr aDeltaFeature; + double aMinDelta = -1; + XGUI_ViewerPrs aPrs; + for (; anIt != aLast; anIt++) { + aPrs = *anIt; + if (!aPrs.feature()) + continue; + double aDelta = DistanceToPoint(aPrs.feature(), aX, anY); + if (aMinDelta < 0 || aMinDelta > aDelta) { + aMinDelta = aDelta; + aDeltaFeature = aPrs.feature(); + } + } + return aDeltaFeature; +} + +double PartSet_Tools::DistanceToPoint(boost::shared_ptr theFeature, + double theX, double theY) +{ + double aDelta = 0; + if (theFeature->getKind() != "SketchLine") + return aDelta; + + boost::shared_ptr aData = theFeature->data(); + + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + + double aX, anY; + PartSet_Tools::ProjectPointOnLine(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y(), theX, theY, aX, anY); + + aDelta = gp_Pnt(theX, theY, 0).Distance(gp_Pnt(aX, anY, 0)); + + return aDelta; +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index ecb28b744..957585b26 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -13,8 +13,11 @@ #include +#include + class Handle_V3d_View; class ModelAPI_Feature; +class XGUI_ViewerPrs; /*! \class PartSet_Tools @@ -61,6 +64,22 @@ public: /// \param theY2 the vertical coordinate of the second line point static void ProjectPointOnLine(double theX1, double theY1, double theX2, double theY2, double thePointX, double thePointY, double& theX, double& theY); + + /// Returns a feature that is under the mouse point + /// \param thePoint a screen point + /// \param theView a 3D view + /// \param theSketch the sketch feature + /// \param theFeatures the list of selected presentations + static boost::shared_ptr NearestFeature(QPoint thePoint, Handle_V3d_View theView, + boost::shared_ptr theSketch, + const std::list& theFeatures); +private: + /// Return the distance between the feature and the point + /// \param theFeature feature object + /// \param theX the horizontal coordinate of the point + /// \param theX the vertical coordinate of the point + static double DistanceToPoint(boost::shared_ptr theFeature, + double theX, double theY); }; #endif diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index 12eae6e4a..b5b5aaedc 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -519,8 +519,10 @@ void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) */ void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) { - if (!mySelectionEnabled) return; - if (theEvent->button() != Qt::LeftButton) return; + if (!mySelectionEnabled || theEvent->button() != Qt::LeftButton) { + emit mouseRelease(theWindow, theEvent); + return; + } myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y()); bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);