From: nds Date: Wed, 30 Apr 2014 08:15:19 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~99^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=55e582d99100282870295dcf5373c329866b75bb;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Continuous line creation. --- diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp index 580186b56..a9c1eb2cb 100644 --- a/src/PartSet/PartSet_Listener.cpp +++ b/src/PartSet/PartSet_Listener.cpp @@ -32,6 +32,8 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage) { if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED) { - myModule->visualizePreview(true); + const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); + boost::shared_ptr aFeature = aUpdMsg->feature(); + myModule->visualizePreview(aFeature, true); } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 167d9f0ea..8bcafffef 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -138,7 +138,10 @@ void PartSet_Module::onOperationStarted() PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { - visualizePreview(true); + visualizePreview(aPreviewOp->feature(), true); + + connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr)), + this, SLOT(onFeatureConstructed(boost::shared_ptr))); PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); if (aSketchOp) { @@ -224,14 +227,19 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { aPreviewOp->setEditMode(true); - visualizePreview(false); + visualizePreview(aPreviewOp->feature(), false); } } myWorkshop->actionsMgr()->setNestedActionsEnabled(true); } -void PartSet_Module::visualizePreview(bool isDisplay) +void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature) +{ + visualizePreview(theFeature, true); +} + +void PartSet_Module::visualizePreview(boost::shared_ptr theFeature, bool isDisplay) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); if (!anOperation) @@ -243,10 +251,10 @@ void PartSet_Module::visualizePreview(bool isDisplay) XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (isDisplay) { - boost::shared_ptr aPreview = aPreviewOp->preview(); + boost::shared_ptr aPreview = aPreviewOp->preview(theFeature); if (aPreview) { - aDisplayer->DisplayInLocalContext(anOperation->feature(), aPreview->impl(), - aPreviewOp->getSelectionMode()); + aDisplayer->DisplayInLocalContext(theFeature, aPreview->impl(), + aPreviewOp->getSelectionMode(theFeature)); } } else { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index ba120ea09..ea7d30e4d 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -11,9 +11,12 @@ #include +#include + class XGUI_ViewWindow; class QMouseEvent; class PartSet_Listener; +class ModelAPI_Feature; class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module { @@ -31,8 +34,9 @@ public: virtual void launchOperation(const QString& theCmdId); /// Displays or erase the current operation preview, if it has it. + /// \param theF /// \param isDisplay the state whether the presentation should be displayed or erased - void visualizePreview(bool isDisplay); + void visualizePreview(boost::shared_ptr theFeature, bool isDisplay); public slots: void onFeatureTriggered(); @@ -63,6 +67,10 @@ public slots: /// \param theZ the Z projection value void onPlaneSelected(double theX, double theY, double theZ); + /// SLOT, to visualize the feature in another local context mode + /// \param theFeature the feature to be put in another local context mode + void onFeatureConstructed(boost::shared_ptr theFeature); + private: XGUI_Workshop* myWorkshop; PartSet_Listener* myListener; diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 9a3a5c716..b583c1e80 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -30,7 +30,7 @@ PartSet_OperationSketch::~PartSet_OperationSketch() { } -int PartSet_OperationSketch::getSelectionMode() const +int PartSet_OperationSketch::getSelectionMode(boost::shared_ptr theFeature) const { int aMode = TopAbs_FACE; if (isEditMode()) diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 5eb45b17e..7818a67cd 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -26,8 +26,9 @@ public: virtual ~PartSet_OperationSketch(); /// Returns the operation local selection mode + /// \param theFeature the feature object to get the selection mode /// \return the selection mode - virtual int getSelectionMode() const; + virtual int getSelectionMode(boost::shared_ptr theFeature) const; /// Gives the current selected objects to be processed by the operation /// \param theList a list of interactive selected shapes diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index a9f861fbb..c372bc72f 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -23,9 +23,10 @@ PartSet_OperationSketchBase::~PartSet_OperationSketchBase() { } -boost::shared_ptr PartSet_OperationSketchBase::preview() const +boost::shared_ptr PartSet_OperationSketchBase::preview( + boost::shared_ptr theFeature) const { boost::shared_ptr aFeature = - boost::dynamic_pointer_cast(feature()); + boost::dynamic_pointer_cast(theFeature); return aFeature->preview(); } diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index c578796a5..e5aa868a3 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -33,11 +33,13 @@ public: virtual ~PartSet_OperationSketchBase(); /// Returns the feature preview shape - boost::shared_ptr preview() const; + /// \param theFeature the feature object to obtain the preview + boost::shared_ptr preview(boost::shared_ptr theFeature) const; /// Returns the operation local selection mode + /// \param theFeature the feature object to get the selection mode /// \return the selection mode - virtual int getSelectionMode() const = 0; + virtual int getSelectionMode(boost::shared_ptr theFeature) const = 0; /// Gives the current selected objects to be processed by the operation /// \param theList a list of interactive selected shapes @@ -51,6 +53,12 @@ public: /// \param thePoint a 3D point clicked in the viewer virtual void mouseMoved(const gp_Pnt& thePoint) {}; +signals: + /// Signal about the feature construing is finished + /// \param theFeature the result feature + void featureConstructed(boost::shared_ptr theFeature); + +public: /// temporary code to provide edition mode void setEditMode(const bool isEditMode) { myIsEditMode = isEditMode; }; protected: diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 366d650e8..b76a73084 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -36,9 +37,12 @@ bool PartSet_OperationSketchLine::isGranted() const return true; } -int PartSet_OperationSketchLine::getSelectionMode() const +int PartSet_OperationSketchLine::getSelectionMode(boost::shared_ptr theFeature) const { - return 0;//TopAbs_FACE; + int aMode = 0; + if (theFeature != feature()) + aMode = TopAbs_VERTEX; + return aMode; } void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint) @@ -66,8 +70,30 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint) void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint) { - if (myPointSelectionMode == SM_SecondPoint) - setLinePoint(thePoint, LINE_ATTR_END); + switch (myPointSelectionMode) + { + case SM_SecondPoint: + setLinePoint(thePoint, LINE_ATTR_END); + break; + case SM_None: { + boost::shared_ptr aPrevFeature = feature(); + // stop the last operation + commitOperation(); + document()->finishOperation(); + //emit changeSelectionMode(aPrevFeature, TopAbs_VERTEX); + // start a new operation + document()->startOperation(); + startOperation(); + // use the last point of the previous feature as the first of the new one + setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START); + myPointSelectionMode = SM_SecondPoint; + + emit featureConstructed(aPrevFeature); + } + break; + default: + break; + } } void PartSet_OperationSketchLine::startOperation() @@ -102,6 +128,21 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, aPoint->setValue(aX, anY); } +void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr theSourceFeature, + const std::string& theSourceAttribute, + const std::string& theAttribute) +{ + boost::shared_ptr aData = theSourceFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theSourceAttribute)); + double aX = aPoint->x(); + double anY = aPoint->y(); + + aData = feature()->data(); + aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + aPoint->setValue(aX, anY); +} + void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY) { if (!mySketch) diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index 456bcf013..3e07b82b8 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -32,8 +32,9 @@ public: virtual bool isGranted() const; /// Returns the operation local selection mode + /// \param theFeature the feature object to get the selection mode /// \return the selection mode - virtual int getSelectionMode() const; + virtual int getSelectionMode(boost::shared_ptr theFeature) const; /// Gives the current selected objects to be processed by the operation /// \param thePoint a point clicked in the viewer @@ -42,6 +43,14 @@ public: /// \param thePoint a point clicked in the viewer virtual void mouseMoved(const gp_Pnt& thePoint); +signals: + /// signal about the sketch plane is selected + /// \param theX the value in the X direction of the plane + /// \param theX the value in the Y direction value of the plane + /// \param theX the value in the Z direction of the plane + void localContextChanged(boost::shared_ptr theFeature, + int theMode); + protected: /// \brief Virtual method called when operation is started /// Virtual method called when operation started (see start() method for more description) @@ -59,6 +68,13 @@ protected: /// \param theAttribute the start or end attribute of the line void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute); + /// \brief Set the point to the line by the point of the source line. + /// \param theSourceFeature the feature, where the point is obtained + /// \param theSourceAttribute the start or end attribute of the source line + /// \param theAttribute the start or end attribute of the line + void setLinePoint(boost::shared_ptr theSourceFeature, + const std::string& theSourceAttribute, + const std::string& theAttribute); /// \brief Converts the 3D point to the projected coodinates on the sketch plane. /// \param thePoint the 3D point in the viewer /// \param theX the X coordinate