]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
The external edge should be removed only if it was created by the widget. So, the...
authornds <natalia.donis@opencascade.com>
Thu, 2 Apr 2015 08:48:18 +0000 (11:48 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 2 Apr 2015 08:48:18 +0000 (11:48 +0300)
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h

index a92364d0594b30c0c7d950c77e94bfc4995f720a..82675355b292f78aeec6255f5ac6ad880d81757a 100644 (file)
@@ -431,19 +431,30 @@ std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2
   return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
 }
 
-ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
-                                                 const ObjectPtr& theObject, 
-                                                 CompositeFeaturePtr theSketch)
+ResultPtr PartSet_Tools::findFixedObjectByExternal(const TopoDS_Shape& theShape,
+                                                   const ObjectPtr& theObject,
+                                                   CompositeFeaturePtr theSketch)
 {
+  ResultPtr aResult;
   if (theShape.ShapeType() == TopAbs_EDGE) {
     // Check that we already have such external edge
     std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
     aInEdge->setImpl(new TopoDS_Shape(theShape));
-    ResultPtr aResult = findExternalEdge(theSketch, aInEdge);
-    if (aResult)
-      return aResult;
+    aResult = findExternalEdge(theSketch, aInEdge);
+  }
+  if (theShape.ShapeType() == TopAbs_VERTEX) {
+    std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
+    aInVert->setImpl(new TopoDS_Shape(theShape));
+    aResult = findExternalVertex(theSketch, aInVert);
+  }
+  return aResult;
+}
 
-    // If not found then we have to create new
+ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
+                                                 const ObjectPtr& theObject, 
+                                                 CompositeFeaturePtr theSketch)
+{
+  if (theShape.ShapeType() == TopAbs_EDGE) {
     Standard_Real aStart, aEnd;
     Handle(V3d_View) aNullView;
     FeaturePtr aMyFeature;
@@ -487,12 +498,6 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
     }
   }
   if (theShape.ShapeType() == TopAbs_VERTEX) {
-    std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
-    aInVert->setImpl(new TopoDS_Shape(theShape));
-    ResultPtr aResult = findExternalVertex(theSketch, aInVert);
-    if (aResult)
-      return aResult;
-
     FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
 
     if (aMyFeature) {
index 854dd3b0eb1d5b5ae86e9c48bdf71b520ba75188..e614074a828550745b584f46ec607058121c9045 100644 (file)
@@ -145,6 +145,15 @@ class PARTSET_EXPORT PartSet_Tools
   static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
                                                 CompositeFeaturePtr theSketch);
 
+  /// Finds a line (arc or circle) by given edge
+  /// \param theShape an edge
+  /// \param theObject a selected result object
+  /// \param theSketch a sketch feature
+  /// \return result of found feature or NULL
+  static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape, 
+                                             const ObjectPtr& theObject, 
+                                             CompositeFeaturePtr theSketch);
+
   /// Creates a line (arc or circle) by given edge
   /// Created line will have fixed constraint
   /// \param theShape an edge
index 5c5700b99f3e31663fc58d885ada99cd311bfa54..f3799357c04e50d0e89e1a89e1f1771f0ce6a5d3 100644 (file)
 
 bool PartSet_WidgetConstraintShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
 {
-  ObjectPtr aSelectedObject = theSelectedObject;
+  // initially the method is wrote to create an external object. Since the parent widget creates it,
+  // the redefinition is not necessary anymore.
+  // TODO: remove the widget and use the parent one insted of it
+  return PartSet_WidgetShapeSelector::setObject(theSelectedObject, theShape);
+  /*ObjectPtr aSelectedObject = theSelectedObject;
 
   FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject);
   if (aFeature) {
@@ -29,5 +33,5 @@ bool PartSet_WidgetConstraintShapeSelector::setObject(ObjectPtr theSelectedObjec
         return false;
     }
   }
-  return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);
+  return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);*/
 }
index 4104331df0114782194ca1c48b9e04ee0eed99d7..10f6de95fd65dc663d5e28d6d00fcbcab2f4ebed 100644 (file)
@@ -262,8 +262,11 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
     if (aSelectedFeature.get() != NULL) {
       std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
               std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
-      if ((!aSPFeature) && (!aShape.IsNull()))
-        PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+      if ((!aSPFeature) && (!aShape.IsNull())) {
+        ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
+        if (!aFixedObject.get())
+          aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+      }
     }
     double aX, aY;
     if (getPoint2d(aView, aShape, aX, aY)) {
index 82c0479bd67ced814630e957d64583b71d6212e5..cd659c04dc1aaac826683c67df61c3e6a167fe51 100644 (file)
@@ -38,12 +38,15 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
   if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) {
-    // Processing of external (non-sketch) object
-    createExternal(theSelectedObject, theShape);
-    if (myExternalObject)
-      aSelectedObject = myExternalObject;
-    else
-      return false;
+    aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+                                                  theSelectedObject, mySketch);
+    if (!aSelectedObject.get()) {
+      // Processing of external (non-sketch) object
+      aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+                                                  theSelectedObject, mySketch);
+      if (aSelectedObject.get())
+        myExternalObject = aSelectedObject;
+    }
   } else {
     // Processing of sketch object
     DataPtr aData = myFeature->data();
@@ -92,18 +95,6 @@ void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
   removeExternal();
 }
 
-//********************************************************************
-void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject,
-                                                 GeomShapePtr theShape)
-{
-  ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                              theSelectedObject, mySketch);
-  if (aObj != myExternalObject) {
-    removeExternal();
-    myExternalObject = aObj;
-  }
-}
-
 //********************************************************************
 void PartSet_WidgetShapeSelector::removeExternal()
 {
@@ -111,24 +102,6 @@ void PartSet_WidgetShapeSelector::removeExternal()
     DocumentPtr aDoc = myExternalObject->document();
     FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
     if (aFeature.get() != NULL) {
-      // 1. check whether the external object can be deleted
-      // It should not be deleted if there are references to the object from other features,
-      // which are not the sketch or a rigid constraints.
-      std::set<FeaturePtr> aRefFeatures;
-      aFeature->document()->refsToFeature(aFeature, aRefFeatures, false);
-      std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
-                                       aLast = aRefFeatures.end();
-      bool aReferenceExist = false;
-      CompositeFeaturePtr aSketch = sketch();
-      for (; anIt != aLast && !aReferenceExist; anIt++) {
-        FeaturePtr aFeature = (*anIt);
-        aReferenceExist = aFeature != aSketch &&
-                          aFeature->getKind() != SketchPlugin_ConstraintRigid::ID();
-      }
-      if (aReferenceExist)
-        return;
-
-      // 2. delete external object
       QObjectPtrList anObjects;
       anObjects.append(aFeature);
       // the external feature should be removed with all references, sketch feature should be ignored
index e529e33ec5f45e122d69457f7739114cec4c4730..fb32bff9cc7242135412d6e1fc82a7b421395003 100644 (file)
@@ -54,11 +54,6 @@ protected:
   /// \param theValid a boolean flag, if restore happens for valid parameters
   void restoreAttributeValue(const bool theValid);
 
-  // Removes the external presentation from the model
-  /// \param theSelectedObject an object
-  /// \param theShape a selected shape, which is used in the selection attribute
-  void createExternal(ObjectPtr theSelectedObject, GeomShapePtr theShape);
-
   // Removes the external presentation from the model
   void removeExternal();