From d035fc0204f90d7c2be3f3b138e42bb84f33c696 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 2 Jun 2014 13:55:05 +0400 Subject: [PATCH] Constraint for distance start creation. --- src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_Module.cpp | 11 +- src/PartSet/PartSet_OperationConstraint.cpp | 245 ++++++++++++++++++++ src/PartSet/PartSet_OperationConstraint.h | 92 ++++++++ src/PartSet/PartSet_OperationEditLine.h | 1 - src/PartSet/PartSet_OperationSketchBase.h | 2 +- src/SketchPlugin/plugin-Sketch.xml | 4 +- 7 files changed, 349 insertions(+), 8 deletions(-) create mode 100644 src/PartSet/PartSet_OperationConstraint.cpp create mode 100644 src/PartSet/PartSet_OperationConstraint.h diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 9ccf4e46b..a9f0973b2 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -7,6 +7,7 @@ SET(PROJECT_HEADERS PartSet.h PartSet_Listener.h PartSet_Module.h + PartSet_OperationConstraint.h PartSet_OperationEditLine.h PartSet_OperationSketchBase.h PartSet_OperationSketch.h @@ -18,6 +19,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES PartSet_Listener.cpp PartSet_Module.cpp + PartSet_OperationConstraint.cpp PartSet_OperationEditLine.cpp PartSet_OperationSketchBase.cpp PartSet_OperationSketch.cpp diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index abf5d270d..739edf06a 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -318,8 +319,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI if (theCmdId == PartSet_OperationSketch::Type()) { anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this); } - else if(theCmdId == PartSet_OperationSketchLine::Type() || - theCmdId == PartSet_OperationEditLine::Type()) { + else { ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); boost::shared_ptr aSketch; PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); @@ -327,10 +327,13 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI aSketch = aPrevOp->sketch(); if (theCmdId == PartSet_OperationSketchLine::Type()) anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch); - else + else if (theCmdId == PartSet_OperationEditLine::Type()) anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch); + else if (theCmdId == PartSet_OperationConstraint::Type()) + anOperation = new PartSet_OperationConstraint(theCmdId.c_str(), this, aSketch); } - else { + + if (!anOperation) { anOperation = new ModuleBase_Operation(theCmdId.c_str(), this); } anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); diff --git a/src/PartSet/PartSet_OperationConstraint.cpp b/src/PartSet/PartSet_OperationConstraint.cpp new file mode 100644 index 000000000..9f5e5b503 --- /dev/null +++ b/src/PartSet/PartSet_OperationConstraint.cpp @@ -0,0 +1,245 @@ +// File: PartSet_OperationConstraint.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#ifdef _DEBUG +#include +#endif + +#include + +using namespace std; + +PartSet_OperationConstraint::PartSet_OperationConstraint(const QString& theId, + QObject* theParent, + boost::shared_ptr theFeature) +: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature) +{ +} + +PartSet_OperationConstraint::~PartSet_OperationConstraint() +{ +} + +bool PartSet_OperationConstraint::isGranted(ModuleBase_IOperation* theOperation) const +{ + return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); +} + +void PartSet_OperationConstraint::init(boost::shared_ptr theFeature, + const std::list& /*theSelected*/, + const std::list& /*theHighlighted*/) +{ + //if (!theFeature || theFeature->getKind() != "SketchLine") + // 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)); +} + +boost::shared_ptr PartSet_OperationConstraint::sketch() const +{ + return mySketch; +} + +void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected, + const std::list& /*theHighlighted*/) +{ + /*if (myPointSelectionMode == SM_DonePoint) + { + // if the point creation is finished, the next mouse release should commit the modification + // the next release can happens by double click in the viewer + commit(); + restartOperation(PartSet_OperationConstraint::Type(), feature()); + return; + } + + double aX, anY; + + bool isFoundPoint = false; + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + if (theSelected.empty()) { + PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); + isFoundPoint = true; + } + else { + XGUI_ViewerPrs aPrs = theSelected.front(); + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) // the point is selected + { + if (aShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); + if (!aVertex.IsNull()) { + aPoint = BRep_Tool::Pnt(aVertex); + PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); + isFoundPoint = true; + + setConstraints(aX, anY); + } + } + else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected + { + boost::shared_ptr aFeature = aPrs.feature(); + if (aFeature) { + double X0, X1, X2, X3; + double Y0, Y1, Y2, Y3; + getLinePoint(aFeature, LINE_ATTR_START, X2, Y2); + getLinePoint(aFeature, LINE_ATTR_END, X3, Y3); + PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1); + + switch (myPointSelectionMode) { + case SM_FirstPoint: + PartSet_Tools::ProjectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY); + break; + case SM_SecondPoint: { + getLinePoint(feature(), LINE_ATTR_START, X0, Y0); + PartSet_Tools::IntersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY); + } + break; + default: + break; + } + isFoundPoint = true; + } + } + } + } + + switch (myPointSelectionMode) + { + case SM_FirstPoint: { + setLinePoint(feature(), aX, anY, LINE_ATTR_START); + setLinePoint(feature(), aX, anY, LINE_ATTR_END); + flushUpdated(); + + //setPointSelectionMode(SM_SecondPoint); + } + break; + case SM_SecondPoint: { + setLinePoint(feature(), aX, anY, LINE_ATTR_END); + flushUpdated(); + + //setPointSelectionMode(SM_DonePoint); + } + break; + default: + break; + } +*/ +} + +void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) +{ +/* switch (myPointSelectionMode) + { + case SM_FirstPoint: { + double aX, anY; + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); + setLinePoint(feature(), aX, anY, LINE_ATTR_START); + setLinePoint(feature(), aX, anY, LINE_ATTR_END); + flushUpdated(); + emit focusActivated(LINE_ATTR_START); + } + break; + case SM_SecondPoint: + { + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); + setLinePoint(aPoint, theView, LINE_ATTR_END); + flushUpdated(); + emit focusActivated(LINE_ATTR_END); + } + break; + case SM_DonePoint: + { + commit(); + restartOperation(PartSet_OperationConstraint::Type(), feature()); + } + default: + break; + }*/ +} + +void PartSet_OperationConstraint::startOperation() +{ + PartSet_OperationSketchBase::startOperation(); + //setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint); + + emit multiSelectionEnabled(false); +} + +void PartSet_OperationConstraint::abortOperation() +{ + emit featureConstructed(feature(), FM_Hide); + PartSet_OperationSketchBase::abortOperation(); +} + +void PartSet_OperationConstraint::stopOperation() +{ + PartSet_OperationSketchBase::stopOperation(); + emit multiSelectionEnabled(true); +} + +void PartSet_OperationConstraint::afterCommitOperation() +{ + PartSet_OperationSketchBase::afterCommitOperation(); + emit featureConstructed(feature(), FM_Deactivation); +} + +boost::shared_ptr PartSet_OperationConstraint::createFeature(const bool theFlushMessage) +{ + boost::shared_ptr aNewFeature = ModuleBase_Operation::createFeature(false); + if (sketch()) { + boost::shared_ptr aFeature = + boost::dynamic_pointer_cast(sketch()); + + aFeature->addSub(aNewFeature); + } + /*if (myInitPoint) { + setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START); + setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END); + + boost::shared_ptr aData = aNewFeature->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_START)); + createConstraint(myInitPoint, aPoint); + }*/ + + emit featureConstructed(aNewFeature, FM_Activation); + if (theFlushMessage) + flushCreated(); + return aNewFeature; +} diff --git a/src/PartSet/PartSet_OperationConstraint.h b/src/PartSet/PartSet_OperationConstraint.h new file mode 100644 index 000000000..fe1ea19ce --- /dev/null +++ b/src/PartSet/PartSet_OperationConstraint.h @@ -0,0 +1,92 @@ +// File: PartSet_OperationConstraint.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_OperationConstraint_H +#define PartSet_OperationConstraint_H + +#include "PartSet.h" + +#include +#include + +/*! + \class PartSet_OperationConstraint + * \brief The operation for the sketch constraint feature creation +*/ +class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketchBase +{ + Q_OBJECT + +public: + /// Returns the operation type key + static std::string Type() { return "SketchConstraintDistance"; } + +public: + /// Constructor + /// \param theId the feature identifier + /// \param theParent the operation parent + /// \param theFeature the parent feature + PartSet_OperationConstraint(const QString& theId, QObject* theParent, + boost::shared_ptr theSketchFeature); + /// Destructor + virtual ~PartSet_OperationConstraint(); + + /// 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; + + /// Initializes some fields accorging to the feature + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void init(boost::shared_ptr theFeature, + const std::list& theSelected, + const std::list& theHighlighted); + + /// 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 theEvent the mouse event + /// \param theView a viewer to have the viewer the eye position + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected, + const std::list& theHighlighted); + /// 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); + +protected: + /// \brief Virtual method called when operation is started + /// Virtual method called when operation started (see start() method for more description) + /// After the parent operation body perform, set sketch feature to the created line feature + virtual void startOperation(); + + /// 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(); + + /// Virtual method called when operation stopped - committed or aborted. + /// Restore the multi selection state + virtual void stopOperation(); + + /// Virtual method called after operation committed (see commit() method for more description) + virtual void afterCommitOperation(); + + /// Creates an operation new feature + /// In addition to the default realization it appends the created line feature to + /// the sketch feature + /// \param theFlushMessage the flag whether the create message should be flushed + /// \returns the created feature + virtual boost::shared_ptr createFeature(const bool theFlushMessage = true); + +private: + boost::shared_ptr mySketch; ///< the sketch feature +}; + +#endif diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h index d42d0e545..fef4c95fc 100644 --- a/src/PartSet/PartSet_OperationEditLine.h +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -141,7 +141,6 @@ private: boost::shared_ptr mySketch; ///< the sketch feature std::list myFeatures; ///< the features to apply the edit operation Point myCurPoint; ///< the current 3D point clicked or moved - gp_Pnt myCurPressed; ///< the current 3D point clicked or moved bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal }; diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 0c10c6c1a..697208c5a 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -52,7 +52,7 @@ public: /// Returns the operation local selection mode /// \param theFeature the feature object to get the selection mode /// \return the selection mode - virtual std::list getSelectionModes(boost::shared_ptr theFeature) const = 0; + virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; /// Initializes some fields accorging to the feature /// \param theSelected the list of selected presentations diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index d91e6066c..be9b3f879 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -1,7 +1,7 @@ - + @@ -19,7 +19,7 @@ - + -- 2.39.2