]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make sub-group features presented correctly in he tree
authormpv <mpv@opencascade.com>
Tue, 21 Jun 2016 08:59:43 +0000 (11:59 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Wed, 22 Jun 2016 11:06:02 +0000 (14:06 +0300)
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/Model/Model_Objects.cpp

index f1592b5b5779580fb7634ae49503f0468af20a65..bdbbce4b49cb64d16f57b029df2a72d46f798e0c 100644 (file)
@@ -201,6 +201,74 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
   }
 }
 
+//============================================================================
+std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::addFeature(
+    std::string theID)
+{
+  std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
+  if (aNew)
+    data()->reflist(FEATURES_ID())->append(aNew);
+  // set as current also after it becomes sub to set correctly enabled for other subs
+  //document()->setCurrentFeature(aNew, false);
+  return aNew;
+}
+
+void ExchangePlugin_ImportFeature::removeFeature(
+    std::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  if (!data()->isValid())
+    return;
+  AttributeRefListPtr aList = reflist(FEATURES_ID());
+  // if the object is last, remove it from the list (needed to skip empty transaction on edit of sketch feature)
+  if (aList->object(aList->size(true) - 1, true) == theFeature) {
+    aList->remove(theFeature);
+  } else {
+    // to keep the persistent sub-elements indexing, do not remove elements from list,
+    // but substitute by nulls
+    aList->substitute(theFeature, ObjectPtr());
+  }
+}
+
+int ExchangePlugin_ImportFeature::numberOfSubs(bool forTree) const
+{
+  return data()->reflist(FEATURES_ID())->size(false);
+}
+
+std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::subFeature(
+    const int theIndex, bool forTree)
+{
+  ObjectPtr anObj = data()->reflist(FEATURES_ID())->object(theIndex, false);
+  FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+  return aRes;
+}
+
+int ExchangePlugin_ImportFeature::subFeatureId(const int theIndex) const
+{
+  std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
+      ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
+  std::list<ObjectPtr> aFeatures = aRefList->list();
+  std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin();
+  int aResultIndex = 1; // number of the counted (created) features, started from 1
+  int aFeatureIndex = -1; // number of the not-empty features in the list
+  for (; anIt != aFeatures.end(); anIt++) {
+    if (anIt->get())
+      aFeatureIndex++;
+    if (aFeatureIndex == theIndex)
+      break;
+    aResultIndex++;
+  }
+  return aResultIndex;
+}
+
+bool ExchangePlugin_ImportFeature::isSub(ObjectPtr theObject) const
+{
+  // check is this feature of result
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+  if (aFeature)
+    return data()->reflist(FEATURES_ID())->isInList(aFeature);
+  return false;
+}
+
 //============================================================================
 void ExchangePlugin_ImportFeature::loadNamingDS(
     std::shared_ptr<GeomAPI_Shape> theGeomShape,
index 1bb70767645a98bcddd7974d21ef481d55343b43..0519e3b1231b61074a6b4cb257b9f6021ac8714d 100644 (file)
@@ -354,12 +354,14 @@ void Model_Objects::createHistory(const std::string& theGroupID)
         FeaturePtr aFeature = feature(aRefs->Value(a));
         if (aFeature.get()) {
           // if feature is in sub-component, remove it from history: it is in sub-tree of sub-component
-          if (!ModelAPI_Tools::compositeOwner(aFeature).get()) {
-            if (isFeature) { // here may be also disabled features
-              if (aFeature->isInHistory()) {
-                aResult.push_back(aFeature);
-              }
-            } else if (!aFeature->isDisabled()) { // iterate all results of not-disabled feature
+          bool isSub = ModelAPI_Tools::compositeOwner(aFeature).get() != NULL;
+          if (isFeature) { // here may be also disabled features
+            if (!isSub && aFeature->isInHistory()) {
+              aResult.push_back(aFeature);
+            }
+          } else if (!aFeature->isDisabled()) { // iterate all results of not-disabled feature
+            // construction results of sub-features should not be in the tree
+            if (!isSub || theGroupID != ModelAPI_ResultConstruction::group()) {
               // do not use reference to the list here since results can be changed by "isConcealed"
               const std::list<std::shared_ptr<ModelAPI_Result> > aResults = aFeature->results();
               std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();