From: nds Date: Tue, 20 May 2014 05:50:26 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~39 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=867dffeb10c41d0619372c56a54ea888da7bd60d;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Start operation of line creation during the edit operation is active. --- diff --git a/src/ModuleBase/ModuleBase_IOperation.cpp b/src/ModuleBase/ModuleBase_IOperation.cpp index 9a14779c6..6853d0d70 100644 --- a/src/ModuleBase/ModuleBase_IOperation.cpp +++ b/src/ModuleBase/ModuleBase_IOperation.cpp @@ -31,7 +31,7 @@ ModuleBase_OperationDescription* ModuleBase_IOperation::getDescription() const return myDescription; } -bool ModuleBase_IOperation::isGranted() const +bool ModuleBase_IOperation::isGranted(ModuleBase_IOperation* /*theOperation*/) const { return false; } diff --git a/src/ModuleBase/ModuleBase_IOperation.h b/src/ModuleBase/ModuleBase_IOperation.h index 6b75e7eca..966d26681 100644 --- a/src/ModuleBase/ModuleBase_IOperation.h +++ b/src/ModuleBase/ModuleBase_IOperation.h @@ -61,7 +61,8 @@ public: /// must be always can start above any launched one. Default impl returns FALSE, /// so it is being checked for IsValid, but some operations may overload IsGranted() /// In this case they will always start, no matter what operation is running. - virtual bool isGranted() const; + /// \param theOperation the previous running operation + virtual bool isGranted(ModuleBase_IOperation* theOperation) const; signals: void started(); /// the operation is started diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 0074285dd..596ccf5be 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -247,13 +247,14 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI else if(theCmdId == PartSet_OperationSketchLine::Type() || theCmdId == PartSet_OperationEditLine::Type()) { ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); - boost::shared_ptr aSketchFeature; - if (aCurOperation) - aSketchFeature = aCurOperation->feature(); + boost::shared_ptr aSketch; + PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); + if (aPrevOp) + aSketch = aPrevOp->sketch(); if (theCmdId == PartSet_OperationSketchLine::Type()) - anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketchFeature); + anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch); else - anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketchFeature); + anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch); } else { anOperation = new ModuleBase_Operation(theCmdId.c_str(), this); diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index f482cabef..5383e0d49 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -4,6 +4,9 @@ #include #include +#include + +#include #include @@ -35,9 +38,9 @@ PartSet_OperationEditLine::~PartSet_OperationEditLine() { } -bool PartSet_OperationEditLine::isGranted() const +bool PartSet_OperationEditLine::isGranted(ModuleBase_IOperation* theOperation) const { - return true; + return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); } std::list PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr theFeature) const @@ -52,6 +55,11 @@ void PartSet_OperationEditLine::init(boost::shared_ptr theFeat myFeatures = thePresentations; } +boost::shared_ptr PartSet_OperationEditLine::sketch() const +{ + return mySketch; +} + void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView) { if (!(theEvent->buttons() & Qt::LeftButton)) @@ -69,10 +77,10 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie if (myCurPoint.myIsInitialized) { double aCurX, aCurY; - PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY); + PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY); double aX, anY; - PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); + PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); double aDeltaX = aX - aCurX; double aDeltaY = anY - aCurY; diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h index 0c225f2f2..5f447c730 100644 --- a/src/PartSet/PartSet_OperationEditLine.h +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -60,9 +60,10 @@ public: /// Destructor virtual ~PartSet_OperationEditLine(); - /// Returns that this operator can be started above already running one. - /// The runned operation should be the sketch feature modified operation - virtual bool isGranted() const; + /// Returns that this operator can be started above already running one. + /// The runned operation should be the sketch feature modified operation + /// \param theOperation the previous running operation + virtual bool isGranted(ModuleBase_IOperation* theOperation) const; /// Returns the operation local selection mode /// \param theFeature the feature object to get the selection mode @@ -75,6 +76,10 @@ public: virtual void init(boost::shared_ptr theFeature, const std::list& thePresentations); + /// Returns the operation sketch feature + /// \returns the sketch instance + virtual boost::shared_ptr sketch() const; + /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 3bb916fab..4c4aa241d 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -51,6 +51,11 @@ std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr PartSet_OperationSketch::sketch() const +{ + return feature(); +} + void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, const std::list& theSelected) { diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 162627c56..e964939d4 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -34,6 +34,10 @@ public: /// \return the selection mode virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; + /// Returns the operation sketch feature + /// \returns the sketch instance + virtual boost::shared_ptr sketch() const; + /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 4fd20d515..b11406c2d 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -60,6 +60,10 @@ public: virtual void init(boost::shared_ptr theFeature, const std::list& thePresentations) {} + /// Returns the operation sketch feature + /// \returns the sketch instance + virtual boost::shared_ptr sketch() const = 0; + /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 0b05a8ef9..c5ac31a6f 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -5,11 +5,15 @@ #include #include +#include #include #include #include + +#include + #include #include #include @@ -49,9 +53,9 @@ PartSet_OperationSketchLine::~PartSet_OperationSketchLine() { } -bool PartSet_OperationSketchLine::isGranted() const +bool PartSet_OperationSketchLine::isGranted(ModuleBase_IOperation* theOperation) const { - return true; + return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); } std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr theFeature) const @@ -72,6 +76,11 @@ void PartSet_OperationSketchLine::init(boost::shared_ptr theFe myInitPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); } +boost::shared_ptr PartSet_OperationSketchLine::sketch() const +{ + return mySketch; +} + void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, const std::list& theSelected) { @@ -80,7 +89,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 bool isFoundPoint = false; gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); if (theSelected.empty()) { - PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); + PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); isFoundPoint = true; } else { @@ -92,7 +101,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); if (!aVertex.IsNull()) { aPoint = BRep_Tool::Pnt(aVertex); - PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY); + PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); isFoundPoint = true; setConstraints(aX, anY); @@ -106,7 +115,7 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3 double Y0, Y1, Y2, Y3; getLinePoint(aFeature, LINE_ATTR_START, X2, Y2); getLinePoint(aFeature, LINE_ATTR_END, X3, Y3); - PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, X1, Y1); + PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1); switch (myPointSelectionMode) { case SM_FirstPoint: @@ -201,9 +210,9 @@ void PartSet_OperationSketchLine::stopOperation() boost::shared_ptr PartSet_OperationSketchLine::createFeature() { boost::shared_ptr aNewFeature = ModuleBase_Operation::createFeature(); - if (mySketch) { + if (sketch()) { boost::shared_ptr aFeature = - boost::dynamic_pointer_cast(mySketch); + boost::dynamic_pointer_cast(sketch()); aFeature->addSub(aNewFeature); } @@ -226,9 +235,9 @@ void PartSet_OperationSketchLine::createConstraint(boost::shared_ptr aDoc = document(); boost::shared_ptr aFeature = aDoc->addFeature("SketchConstraintCoincidence"); - if (mySketch) { + if (sketch()) { boost::shared_ptr aSketch = - boost::dynamic_pointer_cast(mySketch); + boost::dynamic_pointer_cast(sketch()); aSketch->addSub(aFeature); } @@ -262,7 +271,7 @@ void PartSet_OperationSketchLine::setConstraints(double theX, double theY) boost::shared_ptr aData = feature()->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast (aData->attribute(aPointArg)); - aData = mySketch->data(); + aData = sketch()->data(); boost::shared_ptr aRefList = boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_FEATURES)); @@ -325,7 +334,7 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute) { double aX, anY; - PartSet_Tools::ConvertTo2D(thePoint, mySketch, theView, aX, anY); + PartSet_Tools::ConvertTo2D(thePoint, sketch(), theView, aX, anY); boost::shared_ptr aData = feature()->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index cc5af926c..fa5f12938 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -37,7 +37,8 @@ public: /// Returns that this operator can be started above already running one. /// The runned operation should be the sketch feature modified operation - virtual bool isGranted() const; + /// \param theOperation the previous running operation + virtual bool isGranted(ModuleBase_IOperation* theOperation) const; /// Returns the operation local selection mode /// \param theFeature the feature object to get the selection mode @@ -50,6 +51,10 @@ public: virtual void init(boost::shared_ptr theFeature, const std::list& thePresentations); + /// Returns the operation sketch feature + /// \returns the sketch instance + virtual boost::shared_ptr sketch() const; + /// Gives the current selected objects to be processed by the operation /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 792d58467..00aa7ecc5 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -68,7 +68,7 @@ bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation) { bool aCanStart = true; ModuleBase_Operation* aCurrentOp = currentOperation(); - if (aCurrentOp && !theOperation->isGranted()) + if (aCurrentOp && !theOperation->isGranted(aCurrentOp)) { if (canStopOperation()) { aCurrentOp->abort();