Salome HOME
Face selection for sketch entity - the OB selected result should be checked on face...
[modules/shaper.git] / src / PartSet / PartSet_WidgetShapeSelector.cpp
index 82c0479bd67ced814630e957d64583b71d6212e5..089bd98a6ccf1cc1794b3d8cd0da43b06a6d416b 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_Validator.h>
 
 #include <ModuleBase_Definitions.h>
+#include <Config_WidgetAPI.h>
 
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
@@ -23,8 +24,13 @@ PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
                                                          ModuleBase_IWorkshop* theWorkshop,
                                                          const Config_WidgetAPI* theData,
                                                          const std::string& theParentId)
-: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId)
+: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId), myUseExternal(true)
 {
+  QString aIsExternal(theData->getProperty("use_external").c_str());
+  if (!aIsExternal.isEmpty()) {
+    QString aStr = aIsExternal.toUpper();
+    myUseExternal = (aStr == "TRUE") || (aStr == "YES"); 
+  }
 }
 
 bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape)
@@ -35,15 +41,24 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject);
   if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
     return false;
+  // Do check using of external feature
   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;
+
+  // Do check that we can use external feature
+  if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myUseExternal))
+    return false;
+
+  if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myUseExternal) {
+    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 +107,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 +114,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