]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Remove external links and features which produce such entities.
authorazv <azv@opencascade.com>
Mon, 3 Jun 2019 08:08:12 +0000 (11:08 +0300)
committerazv <azv@opencascade.com>
Mon, 3 Jun 2019 08:08:12 +0000 (11:08 +0300)
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp

index 811ccb0bf602b6c22026c2080d35f89fc481b36b..16527cefe449b4060e2fedfdea98d6c3d94658b3 100644 (file)
@@ -383,8 +383,51 @@ bool SketchPlugin_Sketch::customAction(const std::string& theActionId)
   return isOk;
 }
 
+static bool isExternalBased(const FeaturePtr theFeature)
+{
+  return theFeature->getKind() == SketchPlugin_Projection::ID() ||
+         theFeature->getKind() == SketchPlugin_IntersectionPoint::ID();
+}
+
 bool SketchPlugin_Sketch::removeLinksToExternal()
 {
-  // TODO
+  std::list<FeaturePtr> aRemove;
+  std::list<ObjectPtr> aSubs = reflist(FEATURES_ID())->list();
+  for (std::list<ObjectPtr>::iterator anIt = aSubs.begin(); anIt != aSubs.end(); ++anIt) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+    if (!aFeature)
+      continue;
+    if (isExternalBased(aFeature)) {
+      // mark feature as to be removed
+      aRemove.push_back(aFeature);
+    }
+    else {
+      AttributeSelectionPtr anExtAttr = aFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+      ResultPtr anExternal = anExtAttr ? anExtAttr->context() : ResultPtr();
+      if (anExternal) {
+        FeaturePtr anExtFeature = ModelAPI_Feature::feature(anExternal);
+        if (anExtFeature && isExternalBased(anExtFeature)) {
+          // make result of projection/intersection as non-external,
+          aFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->setValue(
+            ObjectPtr(), GeomShapePtr());
+          // set feature auxiliary if the parent is not included into sketch result
+          bool isIncludedToSketchResult = false;
+          if (anExtFeature->getKind() == SketchPlugin_Projection::ID()) {
+            isIncludedToSketchResult = anExtFeature->boolean(
+                SketchPlugin_Projection::INCLUDE_INTO_RESULT())->value();
+          }
+          if (anExtFeature->getKind() == SketchPlugin_IntersectionPoint::ID()) {
+            isIncludedToSketchResult = anExtFeature->boolean(
+                SketchPlugin_IntersectionPoint::INCLUDE_INTO_RESULT())->value();
+          }
+
+          aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(
+              !isIncludedToSketchResult);
+        }
+      }
+    }
+  }
+  for (std::list<FeaturePtr>::iterator anIt = aRemove.begin(); anIt != aRemove.end(); ++anIt)
+    removeFeature(*anIt);
   return true;
 }
index a01474bacb2756d6e77460e4a6b179973186834f..44cbf86fd1f05f3a73911a93bc9325535235aff0 100644 (file)
@@ -162,12 +162,12 @@ bool PlaneGCSSolver_Storage::update(FeaturePtr theFeature, bool theForce)
 {
   bool sendNotify = false;
   bool isUpdated = false;
+  std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+      std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
   EntityWrapperPtr aRelated = entity(theFeature);
   if (aRelated) // send signal to subscribers
     sendNotify = true;
   else { // Feature is not exist, create it
-    std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
-        std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
     bool isCopy = isCopyFeature(aSketchFeature);
     bool isProjReferred = hasReference(aSketchFeature, SketchPlugin_Projection::ID());
     // the feature is a copy in "Multi" constraint and does not used in other constraints
@@ -196,6 +196,16 @@ bool PlaneGCSSolver_Storage::update(FeaturePtr theFeature, bool theForce)
         (*anAttrIt)->attributeType() == ModelAPI_AttributeDouble::typeId())
       isUpdated = update(*anAttrIt) || isUpdated;
 
+  // check external attribute is changed
+  bool isExternal = aSketchFeature && aSketchFeature->isExternal();
+  if (aRelated && isExternal != aRelated->isExternal()) {
+    if (isExternal)
+      makeExternal(aRelated);
+    else
+      makeNonExternal(aRelated);
+    isUpdated = true;
+  }
+
   // send notification to listeners due to at least one attribute is changed
   if (sendNotify && isUpdated)
     notify(theFeature);