]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authornds <natalia.donis@opencascade.com>
Fri, 23 May 2014 04:08:37 +0000 (08:08 +0400)
committernds <natalia.donis@opencascade.com>
Fri, 23 May 2014 04:08:37 +0000 (08:08 +0400)
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h

index 5a2277391c7a753fe159ed96b222e8408a925fb1..c26eadb2a9e2d50b73ed90752ae33a91e51aebc0 100644 (file)
@@ -42,7 +42,7 @@ boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
   return myFeature;
 }
 
-bool ModuleBase_Operation::isNestedOperationsEnabled()
+bool ModuleBase_Operation::isNestedOperationsEnabled() const
 {
   return true;
 }
index f6569ccf2e2596cf8679c8d08b6ecdbc7eff0a8d..89b369995926046420fbd3256b035f732b1623c0 100644 (file)
@@ -54,7 +54,10 @@ public:
   /// \return the feature
   boost::shared_ptr<ModelAPI_Feature> 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.
index e57a113b73ebc39cc1a6cd82a708afc48c8c795d..c43d16ef0a87a310c29ee1f3d3bbdf2be38993ee 100644 (file)
@@ -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<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
   std::list<int> 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<XGUI_ViewerPrs>& /*theSelected*/,
                                            const std::list<XGUI_ViewerPrs>& 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<ModelAPI_Data> aData = feature()->data();
+
+    boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+    // temporary solution for main planes only
+    boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
+      boost::dynamic_pointer_cast<GeomDataAPI_Dir>(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<ModelAPI_AttributeDouble> 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<GeomDataAPI_Point> anOrigin = 
     boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
index 010b28d86f09c60865fef09d35632cd3402b0d0f..6b32d1955969eccbd52b2427f5d602f76cdd151c 100644 (file)
@@ -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<XGUI_ViewerPrs> myFeatures; ///< the features to apply the edit operation
 };