Salome HOME
Issue #1489 Multi-rotation problem if there is a reference to copied objects
[modules/shaper.git] / src / PartSet / PartSet_ExternalObjectsMgr.cpp
old mode 100644 (file)
new mode 100755 (executable)
index bf1eeb9..98bcf3d
@@ -8,6 +8,9 @@
 #include "PartSet_Tools.h"
 
 #include <XGUI_Workshop.h>
+#include <XGUI_ModuleConnector.h>
+
+#include <SketchPlugin_Feature.h>
 
 #include <QString>
 
@@ -21,103 +24,53 @@ PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExt
   }
 }
 
-ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
-                                                     const GeomShapePtr& theShape,
-                                                     const CompositeFeaturePtr& theSketch)
+bool PartSet_ExternalObjectsMgr::isValidObject(const ObjectPtr& theObject)
 {
-  ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                             theSelectedObject, theSketch);
-  if (!aSelectedObject.get()) {
-    // Processing of external (non-sketch) object
-    aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                                 theSelectedObject, theSketch);
-    if (aSelectedObject.get())
-      myExternalObjects.append(aSelectedObject);
+  bool aValid = true;
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+  // Do check using of external feature
+  std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+
+  // Do check that we can use external feature
+  if (aSPFeature.get() != NULL && aSPFeature->isExternal() && !useExternal()) {
+    aValid = false;
   }
-  return aSelectedObject;
+
+  return aValid;
 }
 
-//********************************************************************
-ObjectPtr PartSet_ExternalObjectsMgr::externalObjectValidated(const ObjectPtr& theSelectedObject,
+ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject,
                                                      const GeomShapePtr& theShape,
-                                                     const CompositeFeaturePtr& theSketch)
+                                                     const CompositeFeaturePtr& theSketch,
+                                                     const bool theTemporary)
 {
-  // TODO(nds): unite with externalObject()
-  ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                             theSelectedObject, theSketch);
+  ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(
+                                  theShape->impl<TopoDS_Shape>(), theSelectedObject, theSketch);
   if (!aSelectedObject.get()) {
     // Processing of external (non-sketch) object
     aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                                 theSelectedObject, theSketch);
-    if (aSelectedObject.get())
-      myExternalObjectValidated = aSelectedObject;
+                                                    theSelectedObject, theSketch, theTemporary);
+    if (aSelectedObject.get() && theTemporary)
+        myExternalObjectValidated = aSelectedObject;
   }
   return aSelectedObject;
 }
 
 //********************************************************************
 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
-                                                const FeaturePtr& theFeature)
+                                                const FeaturePtr& theFeature,
+                                                ModuleBase_IWorkshop* theWorkshop,
+                                                const bool theTemporary)
 {
-  QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
-  for (; anIt != aLast; anIt++) {
-    ObjectPtr anObject = *anIt;
-    if (anObject.get()) {
-      DocumentPtr aDoc = anObject->document();
-      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
-      if (aFeature.get() != NULL) {
-        QObjectPtrList anObjects;
-        anObjects.append(aFeature);
-        // the external feature should be removed with all references, sketch feature should be ignored
-        std::set<FeaturePtr> anIgnoredFeatures;
-        anIgnoredFeatures.insert(theSketch);
-        // the current feature should be ignored, because it can use the external feature in the
-        // attributes and, therefore have a references to it. So, the delete functionality tries
-        // to delete this feature. Test case is creation of a constraint on external point,
-        // use in this control after an external point, the point of the sketch.
-        anIgnoredFeatures.insert(theFeature);
-        XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
-      }
-    }
-    //removeExternalObject(anObject, theSketch, theFeature);
-  }
-  myExternalObjects.clear();
-}
-
-//********************************************************************
-void PartSet_ExternalObjectsMgr::removeUnusedExternalObjects(const QObjectPtrList& theIgnoreObjects,
-                                                             const CompositeFeaturePtr& theSketch,
-                                                             const FeaturePtr& theFeature)
-{
-  /*
-  // TODO(nds): unite with removeExternal(), remove parameters
-  QObjectPtrList aUsedExternalObjects;
-
-  QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end();
-  for (; anIt != aLast; anIt++) {
-    ObjectPtr anObject = *anIt;
-    if (theIgnoreObjects.contains(anObject))
-      aUsedExternalObjects.append(anObject);
-    else
-      removeExternalObject(anObject, theSketch, theFeature);
-  }*/
-  myExternalObjects.clear();
-  //if (!aUsedExternalObjects.empty())
-  //  myExternalObjects = aUsedExternalObjects;
-}
-
-//********************************************************************
-void PartSet_ExternalObjectsMgr::removeExternalValidated(const CompositeFeaturePtr& theSketch,
-                                                         const FeaturePtr& theFeature)
-{
-  // TODO(nds): unite with removeExternal(), remove parameters
-  removeExternalObject(myExternalObjectValidated, theSketch, theFeature);
-  myExternalObjectValidated = ObjectPtr();
+  if (theTemporary)
+    removeExternalObject(myExternalObjectValidated, theSketch, theFeature, theWorkshop);
 }
 
 void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject,
-                                                      const CompositeFeaturePtr& theSketch,
-                                                      const FeaturePtr& theFeature)
+                                                      const CompositeFeaturePtr& /*theSketch*/,
+                                                      const FeaturePtr& theFeature,
+                                                      ModuleBase_IWorkshop* theWorkshop)
 {
   if (theObject.get()) {
     DocumentPtr aDoc = theObject->document();
@@ -125,15 +78,14 @@ void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject
     if (aFeature.get() != NULL) {
       QObjectPtrList anObjects;
       anObjects.append(aFeature);
-      // the external feature should be removed with all references, sketch feature should be ignored
-      std::set<FeaturePtr> anIgnoredFeatures;
-      anIgnoredFeatures.insert(theSketch);
-      // the current feature should be ignored, because it can use the external feature in the
-      // attributes and, therefore have a references to it. So, the delete functionality tries
-      // to delete this feature. Test case is creation of a constraint on external point,
-      // use in this control after an external point, the point of the sketch.
-      anIgnoredFeatures.insert(theFeature);
-      XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures);
+      // the external feature should be removed with all references, composite sketch feature will be ignored
+      workshop(theWorkshop)->deleteFeatures(anObjects);
     }
   }
 }
+
+XGUI_Workshop* PartSet_ExternalObjectsMgr::workshop(ModuleBase_IWorkshop* theWorkshop)
+{
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
+  return aConnector->workshop();
+}