]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implementation of names of features selection.
authormpv <mikhail.ponikarov@opencascade.com>
Fri, 10 Aug 2018 07:30:16 +0000 (10:30 +0300)
committermpv <mikhail.ponikarov@opencascade.com>
Fri, 10 Aug 2018 07:48:47 +0000 (10:48 +0300)
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/GeomValidators/GeomValidators_IntersectionSelection.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_Data.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.cpp

index c62648649936a3bb113ea9e73fa10352b3d6099b..5400cbd3fa9886fc16062ef8edbe57865939fd39 100644 (file)
@@ -583,8 +583,11 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
     }
     ResultPtr aContext = anAttrSelection->context();
     if(!aContext.get()) {
-      theError = "Error: Empty selection context.";
-      return false;
+      FeaturePtr aContFeat = anAttrSelection->contextFeature();
+      if (!aContFeat.get()) {
+        theError = "Error: Empty selection context.";
+        return false;
+      }
     }
     ResultConstructionPtr aResultConstruction =
       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
@@ -596,15 +599,15 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
       }
     }
     std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
-    GeomShapePtr aContextShape = aContext->shape();
     if(!aShape.get()) {
+      GeomShapePtr aContextShape = aContext->shape();
       aShape = aContextShape;
     }
     if(!aShape.get()) {
       theError = "Error: Empty shape.";
       return false;
     }
-    if(!aShape->isEqual(aContextShape)) {
+    if (aContext.get() && !aShape->isEqual(aContext->shape())) {
       theError = "Error: Local selection not allowed.";
       return false;
     }
index 0100988007bf5812e038acc1140d7e1b61cb29ce..fe437a01a8884929d87658487fbb0595ca876044 100644 (file)
@@ -45,12 +45,18 @@ bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttrib
       theError = "Error: empty attribute selection.";
       return false;
     }
+    FeaturePtr aFeature;
     ResultPtr aContext = anAttrSelection->context();
     if(!aContext.get()) {
-      theError = "Error: empty selection context.";
-      return false;
+      aFeature = anAttrSelection->contextFeature();
+      if (!aFeature.get()) {
+        theError = "Error: Empty selection context.";
+        return false;
+      }
+    } else {
+      aFeature = ModelAPI_Feature::feature(aContext);
     }
-    FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+
     if(!aFeature.get()) {
       theError = "Error: empty feature.";
       return false;
index a57ba24b3a48efadd0b013b81e1923c3080dbcdf..b76998d854b0001c40180d39f0bfb1fafb0ca6e9 100644 (file)
@@ -39,6 +39,7 @@
 #include <Events_InfoMessage.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Vertex.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
 
 #include <TNaming_Selector.hxx>
 #include <TNaming_NamedShape.hxx>
@@ -85,6 +86,9 @@ Standard_GUID kELLIPSE_CENTER1("f70df04c-3168-4dc9-87a4-f1f840c1275d");
 // identifier of the selection of the second focus point of ellipse on edge
 Standard_GUID kELLIPSE_CENTER2("1395ae73-8e02-4cf8-b204-06ff35873a32");
 
+// prefix for the whole feature context identification
+const static std::string kWHOLE_FEATURE = "all-in-";
+
 // on this label is stored:
 // TNaming_NamedShape - selected shape
 // TNaming_Naming - topological selection information (for the body)
@@ -349,6 +353,22 @@ std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::internalValue(CenterTyp
       if (aConstr->isInfinite())
         return aResult; // empty result
     }
+    // whole feature
+    FeaturePtr aFeature = contextFeature();
+    if (aFeature.get()) {
+      std::list<GeomShapePtr> allShapes;
+      std::list<ResultPtr>::const_iterator aRes = aFeature->results().cbegin();
+      for (; aRes != aFeature->results().cend(); aRes++) {
+        if (aRes->get() && !(*aRes)->isDisabled()) {
+          GeomShapePtr aShape = (*aRes)->shape();
+          if (aShape.get() && !aShape->isNull()) {
+            allShapes.push_back(aShape);
+          }
+        }
+      }
+      return GeomAlgoAPI_CompoundBuilder::compound(allShapes);
+    }
+
     Handle(TNaming_NamedShape) aSelection;
     if (aSelLab.FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
       TopoDS_Shape aSelShape = aSelection->Get();
@@ -394,6 +414,10 @@ bool Model_AttributeSelection::isInitialized()
             return true;
           }
         }
+        // for the whole feature, a feature object
+        FeaturePtr aFeat = contextFeature();
+        if (aFeat.get())
+          return true;
       }
     }
   }
@@ -795,8 +819,15 @@ std::string Model_AttributeSelection::namingName(const std::string& theDefaultNa
   std::shared_ptr<GeomAPI_Shape> aSubSh = internalValue(aCenterType);
   ResultPtr aCont = context();
 
-  if (!aCont.get()) // in case of selection of removed result
+  if (!aCont.get()) {
+    // selection of a full feature
+    FeaturePtr aFeatureCont = contextFeature();
+    if (aFeatureCont.get()) {
+      return kWHOLE_FEATURE + aFeatureCont->name();
+    }
+    // in case of selection of removed result
     return "";
+  }
 
   Model_SelectionNaming aSelNaming(selectionLabel());
   std::string aResult = aSelNaming.namingName(
@@ -867,9 +898,21 @@ void Model_AttributeSelection::selectSubShape(
       }
     }
 
-    Model_SelectionNaming aSelNaming(selectionLabel());
     std::shared_ptr<Model_Document> aDoc =
       std::dynamic_pointer_cast<Model_Document>(owner()->document());
+    // check this is a whole feature context
+    if (aSubShapeName.size() > kWHOLE_FEATURE.size() &&
+      aSubShapeName.substr(0, kWHOLE_FEATURE.size()) == kWHOLE_FEATURE) {
+      std::string aFeatureName = aSubShapeName.substr(kWHOLE_FEATURE.size());
+      ObjectPtr anObj = aDoc->objectByName(ModelAPI_Feature::group(), aFeatureName);
+      if (anObj.get()) {
+        static const GeomShapePtr anEmptyShape;
+        setValue(anObj, anEmptyShape);
+        return;
+      }
+    }
+
+    Model_SelectionNaming aSelNaming(selectionLabel());
     std::shared_ptr<GeomAPI_Shape> aShapeToBeSelected;
     ResultPtr aCont;
     if (aSelNaming.selectSubShape(aType, aSubShapeName, aDoc, aShapeToBeSelected, aCont)) {
index 6a7af0170458fb67cf02bc27b49d5e5738fa599a..697bfedd91724a9702dfeb8fe834f6aab255101e 100644 (file)
@@ -484,10 +484,10 @@ int Model_Data::featureId() const
 void Model_Data::eraseBackReferences()
 {
   myRefsToMe.clear();
-  std::shared_ptr<ModelAPI_Result> aRes =
-    std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
-  if (aRes)
+  std::shared_ptr<ModelAPI_Result> aRes = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+  if (aRes) {
     aRes->setIsConcealed(false);
+  }
 }
 
 void Model_Data::removeBackReference(ObjectPtr theObject, std::string theAttrID)
@@ -518,8 +518,7 @@ void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
 
   if (theApplyConcealment &&  theFeature->isStable() &&
       ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
-    std::shared_ptr<ModelAPI_Result> aRes =
-      std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+    std::shared_ptr<ModelAPI_Result> aRes = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
     // the second condition is for history upper than concealment causer, so the feature result may
     // be displayed and previewed; also for avoiding of quick show/hide on history
     // moving deep down
@@ -546,8 +545,7 @@ void Model_Data::updateConcealmentFlag()
       if (aFeature.get() && !aFeature->isDisabled() && aFeature->isStable()) {
         if (ModelAPI_Session::get()->validators()->isConcealed(
               aFeature->getKind(), (*aRefsIter)->id())) {
-          std::shared_ptr<ModelAPI_Result> aRes =
-            std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+          std::shared_ptr<ModelAPI_Result> aRes = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
           if (aRes.get()) {
             aRes->setIsConcealed(true); // set concealed
             return;
@@ -637,15 +635,34 @@ void Model_Data::referencesToObjects(
       }
     } else if (aType == ModelAPI_AttributeRefList::typeId()) { // list of references
       aReferenced = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr)->list();
-    } else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute
+    }
+    else if (aType == ModelAPI_AttributeSelection::typeId()) { // selection attribute
       std::shared_ptr<ModelAPI_AttributeSelection> aRef = std::dynamic_pointer_cast<
-          ModelAPI_AttributeSelection>(anAttr);
-      aReferenced.push_back(aRef->context());
+        ModelAPI_AttributeSelection>(anAttr);
+      FeaturePtr aRefFeat = aRef->contextFeature();
+      if (aRefFeat.get()) { // reference to all results of the referenced feature
+        const std::list<ResultPtr>& allRes = aRefFeat->results();
+        std::list<ResultPtr>::const_iterator aRefRes = allRes.cbegin();
+        for(; aRefRes != allRes.cend(); aRefRes++) {
+          aReferenced.push_back(*aRefRes);
+        }
+      } else {
+        aReferenced.push_back(aRef->context());
+      }
     } else if (aType == ModelAPI_AttributeSelectionList::typeId()) { // list of selection attributes
       std::shared_ptr<ModelAPI_AttributeSelectionList> aRef = std::dynamic_pointer_cast<
           ModelAPI_AttributeSelectionList>(anAttr);
       for(int a = 0, aSize = aRef->size(); a < aSize; ++a) {
-        aReferenced.push_back(aRef->value(a)->context());
+        FeaturePtr aRefFeat = aRef->value(a)->contextFeature();
+        if (aRefFeat.get()) { // reference to all results of the referenced feature
+          const std::list<ResultPtr>& allRes = aRefFeat->results();
+          std::list<ResultPtr>::const_iterator aRefRes = allRes.cbegin();
+          for (; aRefRes != allRes.cend(); aRefRes++) {
+            aReferenced.push_back(*aRefRes);
+          }
+        } else {
+          aReferenced.push_back(aRef->value(a)->context());
+        }
       }
     } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
       std::shared_ptr<ModelAPI_AttributeRefAttrList> aRefAttr = std::dynamic_pointer_cast<
index 5142efc3185f74979a58424b4479ad8196420c42..8bc41417be4434a04555ce2e0e807a020e4416ce 100644 (file)
@@ -787,16 +787,24 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ResultPtr& theResult)
 {
   // iterate in the structure of sub-results to the parent
   ResultPtr aCurRes = theResult;
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
   std::list<int> anIndices; // indexes of results in the parent result, starting from topmost
   while(aCurRes.get()) {
     ResultBodyPtr aParent = ModelAPI_Tools::bodyOwner(aCurRes);
     if (aParent) {
       anIndices.push_front(ModelAPI_Tools::bodyIndex(aCurRes));
+    } else { // index of the result in the feature
+      std::list<ResultPtr>::const_iterator aRes = aFeature->results().cbegin();
+      for(int anIndex = 0; aRes != aFeature->results().cend(); aRes++, anIndex++) {
+        if (*aRes == aCurRes) {
+          anIndices.push_front(anIndex);
+          break;
+        }
+      }
     }
     aCurRes = aParent;
   }
 
-  FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
   myDumpBuffer << name(aFeature);
   for (std::list<int>::iterator anI = anIndices.begin(); anI != anIndices.end(); anI++) {
     if (anI == anIndices.begin()) {