From: nds Date: Tue, 6 May 2014 11:58:35 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~85^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=741c81c48a9621a02f92507824d383431ac7af68;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Restart for the line creation operation instead of the operation internal manipulation. --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 36a58e67e..d77c02df5 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -212,6 +212,7 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptrinit(theFeature); } + myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true); sendOperation(anOperation); } diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 0fb183348..46b0c4ca2 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -37,6 +37,10 @@ std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr aModes; if (!myIsEditMode) aModes.push_back(TopAbs_FACE); + else { + aModes.push_back(TopAbs_VERTEX); + aModes.push_back(TopAbs_EDGE); + } return aModes; } diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 25bc76673..cc4c02ede 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -38,12 +38,16 @@ bool PartSet_OperationSketchLine::isGranted() const std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr theFeature) const { - std::list aModes; - if (theFeature != feature()) { - aModes.push_back(TopAbs_VERTEX); - aModes.push_back(TopAbs_EDGE); - } - return aModes; + return std::list(); +} + +void PartSet_OperationSketchLine::init(boost::shared_ptr theFeature) +{ + if (!theFeature) + return; + // use the last point of the previous feature as the first of the new one + boost::shared_ptr aData = theFeature->data(); + myInitPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); } void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/) @@ -57,10 +61,9 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEv break; case SM_SecondPoint: { setLinePoint(thePoint, LINE_ATTR_END); - myPointSelectionMode = SM_None; - } - break; - case SM_None: { + commit(); + emit featureConstructed(feature(), FM_Deactivation); + emit launchOperation(PartSet_OperationSketchLine::Type(), feature()); } break; default: @@ -75,22 +78,6 @@ void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent 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, FM_Deactivation); - } - break; default: break; } @@ -100,19 +87,12 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey) { switch (theKey) { case Qt::Key_Escape: { - if (myPointSelectionMode != SM_None) - emit featureConstructed(feature(), FM_Abort); abort(); } break; case Qt::Key_Return: { - if (myPointSelectionMode != SM_None) { - emit featureConstructed(feature(), FM_Abort); - myPointSelectionMode = SM_FirstPoint; - document()->abortOperation(); - } - else - myPointSelectionMode = SM_FirstPoint; + abort(); + emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr()); } break; default: @@ -123,13 +103,13 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey) void PartSet_OperationSketchLine::startOperation() { PartSet_OperationSketchBase::startOperation(); - myPointSelectionMode = SM_FirstPoint; + myPointSelectionMode = !myInitPoint ? SM_FirstPoint : SM_SecondPoint; } -void PartSet_OperationSketchLine::stopOperation() +void PartSet_OperationSketchLine::abortOperation() { - PartSet_OperationSketchBase::stopOperation(); - myPointSelectionMode = SM_None; + emit featureConstructed(feature(), FM_Abort); + PartSet_OperationSketchBase::abortOperation(); } boost::shared_ptr PartSet_OperationSketchLine::createFeature() @@ -141,6 +121,13 @@ boost::shared_ptr PartSet_OperationSketchLine::createFeature() aFeature->addSub(aNewFeature); } + if (myInitPoint) { + boost::shared_ptr aData = aNewFeature->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_START)); + aPoint->setValue(myInitPoint->x(), myInitPoint->y()); + } + emit featureConstructed(aNewFeature, FM_Activation); return aNewFeature; } @@ -156,18 +143,3 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY); 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); -} diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index cab05194c..044e739ff 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -10,6 +10,7 @@ #include #include +class GeomDataAPI_Point2D; class QMouseEvent; /*! @@ -43,6 +44,10 @@ public: /// \return the selection mode virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; + /// Initializes some fields accorging to the feature + /// \param theFeature the feature + virtual void init(boost::shared_ptr theFeature); + /// Gives the current selected objects to be processed by the operation /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event @@ -61,10 +66,9 @@ protected: /// After the parent operation body perform, set sketch feature to the created line feature virtual void startOperation(); - /// \brief Virtual method called when operation is started - /// Virtual method called when operation stopped - committed or aborted. - /// After the parent operation body perform, reset selection point mode of the operation - virtual void stopOperation(); + /// Virtual method called when operation aborted (see abort() method for more description) + /// Before the feature is aborted, it should be hidden from the viewer + virtual void abortOperation(); /// Creates an operation new feature /// In addition to the default realization it appends the created line feature to @@ -78,20 +82,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); - protected: ///< Structure to lists the possible types of point selection modes - enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None}; + enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint}; private: boost::shared_ptr mySketch; ///< the sketch feature + boost::shared_ptr myInitPoint; ///< the first line point PointSelectionMode myPointSelectionMode; ///< point selection mode }; diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp index 46b15993a..a49689970 100644 --- a/src/XGUI/XGUI_ActionsMgr.cpp +++ b/src/XGUI/XGUI_ActionsMgr.cpp @@ -88,6 +88,13 @@ void XGUI_ActionsMgr::restoreCommandState() } } +void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked) +{ + if(myActions.contains(theId)) { + myActions[theId]->setChecked(theChecked); + } +} + void XGUI_ActionsMgr::updateAction(const QString& theId) { if(myActions.contains(theId)){ diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h index fe80fa21e..965f2289f 100644 --- a/src/XGUI/XGUI_ActionsMgr.h +++ b/src/XGUI/XGUI_ActionsMgr.h @@ -34,6 +34,11 @@ public: void saveCommandsState(); void restoreCommandState(); + /// Set the action is checked + /// \param theId - string ID of the command + /// \praram theChecked - the new checked state + void setActionChecked(const QString& theId, const bool theChecked); + void updateAction(const QString&); void setNestedActionsEnabled(bool);