]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1786 : make Recover feature duplicate the result, not re-create a previous...
authormpv <mpv@opencascade.com>
Mon, 21 Nov 2016 12:41:18 +0000 (15:41 +0300)
committermpv <mpv@opencascade.com>
Mon, 21 Nov 2016 12:41:18 +0000 (15:41 +0300)
src/FeaturesAPI/FeaturesAPI_Recover.cpp
src/FeaturesAPI/FeaturesAPI_Recover.h
src/FeaturesPlugin/FeaturesPlugin_Recover.cpp
src/FeaturesPlugin/FeaturesPlugin_Recover.h
src/FeaturesPlugin/Test/TestRecover.py
src/FeaturesPlugin/recover_widget.xml
src/Model/Model_Data.cpp
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/ModelAPI_Validator.h

index 7f86b7a5723f76df42795735ef3ed513465d94ab..40637b30bef9a47c4cb6f2053901dc22a5e64232 100644 (file)
@@ -26,7 +26,6 @@ FeaturesAPI_Recover::FeaturesAPI_Recover(const std::shared_ptr<ModelAPI_Feature>
   if(initialize()) {
     setBaseFeature(theBaseFeature);
     setRecoveredList(theRecoveredList);
-    setIsPersistent(thePersistent);
   }
 }
 
@@ -49,13 +48,6 @@ void FeaturesAPI_Recover::setRecoveredList(const std::list<ModelHighAPI_Selectio
   // do not need to execute because on attribute changed it does everything anyway
 }
 
-//=================================================================================================
-void FeaturesAPI_Recover::setIsPersistent(bool thePersistent)
-{
-  fillAttribute(thePersistent, myisPersistent);
-  // do not need to execute because on attribute changed it does everything anyway
-}
-
 //==================================================================================================
 void FeaturesAPI_Recover::dump(ModelHighAPI_Dumper& theDumper) const
 {
@@ -66,13 +58,11 @@ void FeaturesAPI_Recover::dump(ModelHighAPI_Dumper& theDumper) const
     aBase->reference(FeaturesPlugin_Recover::BASE_FEATURE());
   AttributeRefListPtr anAttrRecoveredEntities =
     aBase->reflist(FeaturesPlugin_Recover::RECOVERED_ENTITIES());
-  AttributeBooleanPtr anAttrPersistent = aBase->boolean(FeaturesPlugin_Recover::PERSISTENT());
 
   FeaturePtr aFeature = ModelAPI_Feature::feature(anAttrBaseFeature->value());
 
   theDumper << aBase << " = model.addRecover(" << aDocName << ", "
-            << aFeature << ", " << anAttrRecoveredEntities << ", "
-            << anAttrPersistent << ")" << std::endl;
+            << aFeature << ", " << anAttrRecoveredEntities << ")" << std::endl;
 }
 
 //=================================================================================================
index 2263ae84f2be9b5957cab95b83d20e1b755c62d4..90af8140d61c83fbe8a9fb177a0192fb4f6a9dc6 100644 (file)
@@ -38,13 +38,11 @@ public:
   FEATURESAPI_EXPORT
   virtual ~FeaturesAPI_Recover();
 
-  INTERFACE_3(FeaturesPlugin_Recover::ID(),
+  INTERFACE_2(FeaturesPlugin_Recover::ID(),
               baseFeature, FeaturesPlugin_Recover::BASE_FEATURE(),
               ModelAPI_AttributeReference, /** Concealed feature */,
               recoveredList, FeaturesPlugin_Recover::RECOVERED_ENTITIES(),
-              ModelAPI_AttributeRefList, /** Recover list*/,
-              isPersistent, FeaturesPlugin_Recover::PERSISTENT(),
-              ModelAPI_AttributeBoolean, /** Is persistent flag */)
+              ModelAPI_AttributeRefList, /** Recover list*/)
 
   /// Set base feature.
   FEATURESAPI_EXPORT
@@ -54,10 +52,6 @@ public:
   FEATURESAPI_EXPORT
   void setRecoveredList(const std::list<ModelHighAPI_Selection>& theRecoverList);
 
-  /// Set auxiliary
-  FEATURESAPI_EXPORT
-  void setIsPersistent(bool thePersistent);
-
   /// Dump wrapped feature
   FEATURESAPI_EXPORT
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
index e521c3a296f4fb00d9a6fc1817c385df66313446..4bbfd76e858d294d47999b3f45cff366337897a5 100644 (file)
@@ -15,6 +15,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Tools.h>
+#include <GeomAlgoAPI_Copy.h>
 
 FeaturesPlugin_Recover::FeaturesPlugin_Recover()
 {
@@ -24,105 +25,54 @@ void FeaturesPlugin_Recover::initAttributes()
 {
   data()->addAttribute(BASE_FEATURE(), ModelAPI_AttributeReference::typeId());
   data()->addAttribute(RECOVERED_ENTITIES(), ModelAPI_AttributeRefList::typeId());
-  data()->addAttribute(PERSISTENT(), ModelAPI_AttributeBoolean::typeId());
 
-  myPersistent = boolean(PERSISTENT())->value();
-  synchronizeRegistered();
 }
 
 void FeaturesPlugin_Recover::execute()
 {
-  synchronizeRegistered();
-}
-
-void FeaturesPlugin_Recover::attributeChanged(const std::string& theID)
-{
-  synchronizeRegistered();
-}
-
-void FeaturesPlugin_Recover::synchronizeRegistered()
-{
-  FeaturePtr aBase = baseFeature();
-  bool aNewPersistent = boolean(PERSISTENT())->value();
-  if (aNewPersistent != myPersistent || myCurrentBase != aBase)
-    clearRegistered();
+  int aResultIndex = 0;
+  AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES());
+  for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) {
+    ObjectPtr anObj = aRecovered->object(anIndex);
+    if (!anObj.get())
+      continue;
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (!aResult.get())
+      continue;
+    GeomShapePtr aShape = aResult->shape();
+    if (!aShape.get())
+      continue;
 
-  std::set<ObjectPtr> aRecoveredInList;
-  // add unconcealed which are not in the myRegistered map
-  if (isStable() && !isDisabled()) { // if unstable, clear any unconcealment effect
-    AttributeRefListPtr aRecovered = reflist(RECOVERED_ENTITIES());
-    for(int anIndex = aRecovered->size() - 1; anIndex >= 0; anIndex--) {
-      ObjectPtr anObj = aRecovered->object(anIndex);
-      aRecoveredInList.insert(anObj);
-      if (myRegistered.find(anObj) == myRegistered.end()) {
-        // not found, so register a new
-        ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
-        if (aRes.get()) { // this may be on first update after "open"
-          ModelAPI_Session::get()->validators()->registerUnconcealment(
-            aRes, aNewPersistent ? FeaturePtr() : aBase);
-          myRegistered.insert(anObj);
-        }
-      }
+    // Copy shape.
+    GeomAlgoAPI_Copy aCopyAlgo(aShape);
+    // Check that algo is done.
+    if(!aCopyAlgo.isDone()) {
+      setError("Error: recover algorithm failed.");
+      return;
     }
-  }
-  // remove unconcealed which are not in the stored list, but in the map
-  std::set<std::shared_ptr<ModelAPI_Object> >::iterator aMyReg = myRegistered.begin();
-  while(aMyReg != myRegistered.end()) {
-    if (aRecoveredInList.find(*aMyReg) == aRecoveredInList.end()) {
-      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*aMyReg);
-      ModelAPI_Session::get()->validators()->disableUnconcealment(
-        aRes, aNewPersistent ? FeaturePtr() : myCurrentBase);
-      myRegistered.erase(aMyReg);
-      aMyReg = myRegistered.begin(); // restart iteration because after erase iterator may be bad
-    } else {
-      aMyReg++;
+    // Check if shape is not null.
+    if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) {
+      setError("Error: resulting shape is null.");
+      return;
+    }
+    // Check that resulting shape is valid.
+    if(!aCopyAlgo.isValid()) {
+      setError("Error: resulting shape is not valid.");
+      return;
     }
-  }
-  myCurrentBase = aBase;
-  myPersistent = aNewPersistent;
-}
-
-void FeaturesPlugin_Recover::erase()
-{
-  // clears myRegistered before all information is destroyed
-  clearRegistered();
-  ModelAPI_Feature::erase();
-}
-
-bool FeaturesPlugin_Recover::setStable(const bool theFlag)
-{
-  bool aRes = ModelAPI_Feature::setStable(theFlag);
-  synchronizeRegistered();
-  return aRes;
-}
-
-bool FeaturesPlugin_Recover::setDisabled(const bool theFlag)
-{
-  bool aRes = ModelAPI_Feature::setDisabled(theFlag);
-  synchronizeRegistered();
-  return aRes;
-}
 
-FeaturePtr FeaturesPlugin_Recover::baseFeature()
-{
-  // for the current moment it can be result of feature of feature: GUI is not debugged
-  ObjectPtr aBaseObj = reference(BASE_FEATURE())->value();
-  FeaturePtr aResult;
-  if (aBaseObj.get() == NULL)
-    return aResult;
-  aResult = std::dynamic_pointer_cast<ModelAPI_Feature>(aBaseObj);
-  if (aResult.get() == NULL)
-    aResult = aBaseObj->document()->feature(std::dynamic_pointer_cast<ModelAPI_Result>(aBaseObj));
-  return aResult;
-}
+    // Store result.
+    ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+    aResultBody->store(aCopyAlgo.shape());//, aCopyAlgo.shape());
+    std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aCopyAlgo.mapOfSubShapes();
+    // like in import: forget any history
+    int aTag(1);
+    std::string aNameMS = "Shape";
+    aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS, aTag);
 
-void FeaturesPlugin_Recover::clearRegistered()
-{
-  std::set<std::shared_ptr<ModelAPI_Object> >::iterator aMyReg = myRegistered.begin();
-  for(; aMyReg != myRegistered.end(); aMyReg++) {
-    ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*aMyReg);
-    ModelAPI_Session::get()->validators()->disableUnconcealment(
-      aRes, myPersistent ? FeaturePtr() : myCurrentBase);
+    setResult(aResultBody, aResultIndex);
+    ++aResultIndex;
   }
-  myRegistered.clear();
+
+  removeResults(aResultIndex);
 }
index 9016ddbd8076c807019f1ff671d15a6b42b8a702..438ee950e88cb90eaa4dd6df0bb84c895cb7f49f 100644 (file)
@@ -46,13 +46,6 @@ class FeaturesPlugin_Recover : public ModelAPI_Feature
     return MY_RECOVERED_ENTITIES_ID;
   }
 
-  /// Attribute name of persistenc concealment flag.
-  inline static const std::string& PERSISTENT()
-  {
-    static const std::string MY_PERSISTENT_ID("persistent");
-    return MY_PERSISTENT_ID;
-  }
-
   /// Returns the kind of a feature
   FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
   {
@@ -69,26 +62,6 @@ class FeaturesPlugin_Recover : public ModelAPI_Feature
   /// Use plugin manager for features creation
   FeaturesPlugin_Recover();
 
-  /// Called on change of any argument-attribute of this object. Needed here for synchronization
-  /// of registered unconcealed.
-  virtual void attributeChanged(const std::string& theID);
-
-  /// Synchronises myRegistered before all attributes are erased
-  virtual void erase();
-
-  /// on unstability of feature, remove all unconcealment effect
-  virtual bool setStable(const bool theFlag);
-  /// on disable of feature, remove all unconcealment effect
-  virtual bool setDisabled(const bool theFlag);
-private:
-  /// Synchronises registration of unconcealed entities with the attributes values of this feature
-  void synchronizeRegistered();
-
-  /// Returns the base feature of this
-  FeaturePtr baseFeature();
-
-  /// erases all registered cashed values
-  void clearRegistered();
 };
 
 #endif
index 1a2765bc9d3b50a406dcf8002c20f90e308dea76..d591a56d6c6b174e4d765a6b0fc56a25d3c272a9 100644 (file)
@@ -45,9 +45,12 @@ assert(mypart.size("Bodies") == 1)
 
 # check persistent flag of recover: never concealed
 model.begin()
+recover = model.addRecover(mypart, cut, smallcyl.results())
+model.end()
 
-recover = model.addRecover(mypart, cut, smallcyl.results(), True)
 assert(mypart.size("Bodies") == 2)
+
+model.begin()
 sk3 = model.addSketch(mypart, model.defaultPlane("XOY"))
 c3 = sk3.addCircle(0, 0, 90)
 model.do()
@@ -60,12 +63,4 @@ model.end()
 # two booleans and small cylinder
 assert(mypart.size("Bodies") == 3)
 
-
-# make the flag as not-persistent => cylinder must be disappeared
-model.begin()
-recover.setIsPersistent(False)
-model.end()
-# only two booleans
-assert(mypart.size("Bodies") == 2)
-
 assert(model.checkPythonDump())
index b2c6e809100379f358b2f288e7323c62011f747e..f8b9a7fc24229f01cd582d5016841b61474bb07b 100644 (file)
@@ -9,5 +9,4 @@
   <concealed_objects_view id="recovered"\r
                   tooltip="Concealed results to be recevered"\r
                   base_shape_attribute="base_feature"/>\r
-  <boolvalue id="persistent" label="Persistent" default="false" tooltip="Makes unable to conceal result again" obligatory="0"/>\r
 </source>\r
index 4cfc34a59d32229da50e8f7f157e6f4110deee4f..c60d07cd33bed1c9b7c1b7aec2726663db3f88fe 100644 (file)
@@ -462,8 +462,7 @@ void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
     // 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
-    if (aRes && !theFeature->isDisabled() &&
-        !ModelAPI_Session::get()->validators()->isUnconcealed(aRes, theFeature)) {
+    if (aRes && !theFeature->isDisabled()) {
       aRes->setIsConcealed(true);
     }
   }
@@ -481,10 +480,8 @@ void Model_Data::updateConcealmentFlag()
           std::shared_ptr<ModelAPI_Result> aRes =
             std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
           if (aRes.get()) {
-            if (!ModelAPI_Session::get()->validators()->isUnconcealed(aRes, aFeature)) {
-              aRes->setIsConcealed(true); // set concealed
-              return;
-            }
+            aRes->setIsConcealed(true); // set concealed
+            return;
           }
         }
       }
index 0b7a6ea3a23e77c07b6f3a96cfed3ba840526dbd..d34681a13a2c5c9e4a7115d8c72ab9d5478ad282 100644 (file)
@@ -317,54 +317,6 @@ bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string th
   return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end();
 }
 
-void Model_ValidatorsFactory::registerUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
-{
-  if (myUnconcealed.find(theUnconcealed) == myUnconcealed.end()) {
-    myUnconcealed[theUnconcealed] = std::list<std::shared_ptr<ModelAPI_Feature> >();
-  }
-  myUnconcealed[theUnconcealed].push_back(theCanceledFeat);
-  std::dynamic_pointer_cast<Model_Data>(theUnconcealed->data())->updateConcealmentFlag();
-}
-
-void Model_ValidatorsFactory::disableUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
-{
-  std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
-    ::iterator aResFound = myUnconcealed.find(theUnconcealed);
-  if (aResFound != myUnconcealed.end()) {
-    std::list<std::shared_ptr<ModelAPI_Feature> >::iterator anIter = aResFound->second.begin();
-    for(; anIter != aResFound->second.end(); anIter++) {
-      if (*anIter == theCanceledFeat) {
-        aResFound->second.erase(anIter);
-        std::dynamic_pointer_cast<Model_Data>(theUnconcealed->data())->updateConcealmentFlag();
-        break;
-      }
-    }
-  }
-}
-
-bool Model_ValidatorsFactory::isUnconcealed(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat)
-{
-  std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
-    ::iterator aResFound = myUnconcealed.find(theUnconcealed);
-  if (aResFound != myUnconcealed.end()) {
-    std::list<std::shared_ptr<ModelAPI_Feature> >::iterator aFeatIter = aResFound->second.begin();
-    for(; aFeatIter != aResFound->second.end(); aFeatIter++) {
-      if (aFeatIter->get()) {
-        if ((*aFeatIter)->isDisabled()) continue;
-        if (*aFeatIter == theCanceledFeat)
-          return true; // this is exactly canceled
-        if (theCanceledFeat->document()->isLater(*aFeatIter, theCanceledFeat))
-          return true; // if unconcealed feature (from the list) is later than concealed
-      } else
-        return true; // empty attribute means that everything is canceled
-    }
-  }
-  return false;
-}
-
 void Model_ValidatorsFactory::registerCase(std::string theFeature, std::string theAttribute,
                             const std::list<std::pair<std::string, std::string> >& theCases)
 {
index 5ac63fd1b88f7c3e29e84402113cfe6f470e6c28..72a49316895f67597b9d0462f425723a3c068b31 100644 (file)
@@ -37,10 +37,6 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   /// Stores the registered attributes that leads to the concealment of referenced objects in
   /// data tree. Map from feature kind to set of attribute IDs.
   std::map<std::string, std::set<std::string> > myConcealed;
-  /// Stored the unconcealed results and features that caused the canceled concealment (Recover).
-  /// If the feature is empty, unconcealment is persistent.
-  std::map<std::shared_ptr<ModelAPI_Result>, std::list<std::shared_ptr<ModelAPI_Feature> > >
-    myUnconcealed;
   /// Stores the registered attributes must be checked only if the particular case is activated
   /// Map from feature kind to map of attribute IDs to pair
   // (switchId (ID of the attribute) and case Ids (possible values of the switch attribute))
@@ -98,19 +94,6 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   /// Returns true that it was registered that attribute conceals the referenced result
   virtual bool isConcealed(std::string theFeature, std::string theAttribute);
 
-  /// Registers (by Recover feature) cancel of concealment of specific result by specific feature.
-  /// If theCanceledFeat is empty, the concealment is canceled for this result forever.
-  virtual void registerUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
-
-  /// Disables cancel of concealment of specific result by specific feature.
-  virtual void disableUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
-
-  /// Returns true if concealment is canceled.
-  virtual bool isUnconcealed(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat);
-
   /// register the case-attribute (\a myCases set definition)
   virtual void registerCase(std::string theFeature, std::string theAttribute,
                             const std::list<std::pair<std::string, std::string> >& theCases);
index c621363d5e147b15fdf43d7382f336605c88face..0557333ba75079b3ae9ae5b4570d627d13becda9 100644 (file)
@@ -101,19 +101,6 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
   /// Returns true that it was registered that attribute conceals the referenced result
   virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0;
 
-  /// Registers (by Recover feature) cancel of concealment of specific result by specific feature.
-  /// If theCanceledFeat is empty, the concealment is canceled for this result forever.
-  virtual void registerUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat) = 0;
-
-  /// Disables cancel of concealment of specific result by specific feature.
-  virtual void disableUnconcealment(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat) = 0;
-
-  /// Returns true if concealment is canceled.
-  virtual bool isUnconcealed(std::shared_ptr<ModelAPI_Result> theUnconcealed,
-    std::shared_ptr<ModelAPI_Feature> theCanceledFeat) = 0;
-
   /// Register the case-attribute: this attribute is checked only if its case is selected
   virtual void registerCase(std::string theFeature, std::string theAttribute,
     const std::list<std::pair<std::string, std::string> >& theCases) = 0;