From cbc176dc57a3049a383e81767ec1bc3f7c3e92e7 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 23 May 2014 08:08:22 +0400 Subject: [PATCH] Issue #36 sketch - Line is invisible, coordinates of End point are shown wrong --- src/ModuleBase/ModuleBase_Operation.cpp | 2 +- src/ModuleBase/ModuleBase_Operation.h | 5 ++- src/PartSet/PartSet_OperationSketch.cpp | 42 +++++++++++++++++-------- src/PartSet/PartSet_OperationSketch.h | 11 ++++++- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 5a2277391..c26eadb2a 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -42,7 +42,7 @@ boost::shared_ptr ModuleBase_Operation::feature() const return myFeature; } -bool ModuleBase_Operation::isNestedOperationsEnabled() +bool ModuleBase_Operation::isNestedOperationsEnabled() const { return true; } diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index f6569ccf2..89b369995 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -54,7 +54,10 @@ public: /// \return the feature boost::shared_ptr feature() const; - virtual bool isNestedOperationsEnabled(); + /// Returns whether the nested operations are enabled. + /// The state can depend on the operation current state. + /// \return enabled state + virtual bool isNestedOperationsEnabled() const; // Data model methods. /// Stores a real value in model. diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index e57a113b7..c43d16ef0 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -33,7 +33,7 @@ using namespace std; PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent) -: PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false) +: PartSet_OperationSketchBase(theId, theParent) { } @@ -44,7 +44,7 @@ PartSet_OperationSketch::~PartSet_OperationSketch() std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr theFeature) const { std::list aModes; - if (!myIsEditMode) + if (!hasSketchPlane()) aModes.push_back(TopAbs_FACE); else aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature); @@ -60,13 +60,11 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie const std::list& /*theSelected*/, const std::list& theHighlighted) { - if (!myIsEditMode) { + if (!hasSketchPlane()) { XGUI_ViewerPrs aPrs = theHighlighted.front(); const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) { + if (!aShape.IsNull()) setSketchPlane(aShape); - myIsEditMode = true; - } } else { if (theHighlighted.size() == 1) { @@ -81,7 +79,7 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { - if (!myIsEditMode || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) + if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) return; if (myFeatures.size() != 1) { @@ -122,6 +120,30 @@ void PartSet_OperationSketch::stopOperation() emit closeLocalContext(); } +bool PartSet_OperationSketch::isNestedOperationsEnabled() const +{ + return hasSketchPlane(); +} + +bool PartSet_OperationSketch::hasSketchPlane() const +{ + bool aHasPlane = false; + + if (feature()) { + // set plane parameters to feature + boost::shared_ptr aData = feature()->data(); + + boost::shared_ptr anAttr; + // temporary solution for main planes only + boost::shared_ptr aNormal = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + double aX = aNormal->x(), anY = aNormal->y(), aZ = aNormal->z(); + + aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); + } + return aHasPlane; +} + void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) { if (theShape.IsNull()) @@ -140,12 +162,6 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) aPlane->coefficients(anA, aB, aC, aD); boost::shared_ptr anAttr; - /* - aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA); - aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB); - aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC); - aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD); - */ // temporary solution for main planes only boost::shared_ptr anOrigin = boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 010b28d86..6b32d1955 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -60,6 +60,12 @@ public: /// Emits a signal to hide the preview of the operation virtual void stopOperation(); + /// Returns whether the nested operations are enabled. + /// The state can depend on the operation current state. + /// It returns true after the sketch plane is choosen. + /// \return enabled state + virtual bool isNestedOperationsEnabled() const; + signals: /// signal about the sketch plane is selected /// \param theX the value in the X direction of the plane @@ -68,12 +74,15 @@ signals: void planeSelected(double theX, double theY, double theZ); protected: + /// Returns whether the sketch plane is set + /// \return the boolean value whether the sketch is set + bool hasSketchPlane() const; + /// Set the plane to the current sketch /// \param theShape the shape void setSketchPlane(const TopoDS_Shape& theShape); private: - bool myIsEditMode; /// the edit mode of this operation std::list myFeatures; ///< the features to apply the edit operation }; -- 2.39.2