Salome HOME
Make sketch features invisible in constructions and fix the nested commit warning
[modules/shaper.git] / src / Model / Model_Document.cpp
index f63dbbb25a6bc478b95fbc7a218779a298672d8b..4ca962723f80c34bbdcc8d4a444e5fb8e1536756 100644 (file)
@@ -222,10 +222,17 @@ void Model_Document::compactNested() {
 void Model_Document::finishOperation()
 {
   // just to be sure that everybody knows that changes were performed
+  
+  if (!myDoc->HasOpenCommand() && myNestedNum != -1)
+    boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
+      setCheckTransactions(false); // for nested transaction commit
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+  if (!myDoc->HasOpenCommand() && myNestedNum != -1)
+    boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
+      setCheckTransactions(true); // for nested transaction commit
 
   if (myNestedNum != -1) // this nested transaction is owervritten
     myNestedNum++;
@@ -362,7 +369,6 @@ FeaturePtr Model_Document::addFeature(std::string theID)
       aDocToAdd->initData(aFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS);
       // keep the feature ID to restore document later correctly
       TDataStd_Comment::Set(aFeatureLab, aFeature->getKind().c_str());
-      aDocToAdd->setUniqueName(aFeature);
       aDocToAdd->myObjs.Bind(aFeatureLab, aFeature);
       // store feature in the history of features array
       if (aFeature->isInHistory()) {
@@ -445,15 +451,19 @@ FeaturePtr Model_Document::feature(TDF_Label& theLabel)
 
 ObjectPtr Model_Document::object(TDF_Label theLabel)
 {
-  TDF_Label aFeatureLabel = theLabel.Father().Father();
-  FeaturePtr aFeature = feature(aFeatureLabel);
+  // try feature by label
+  FeaturePtr aFeature = feature(theLabel);
+  if (aFeature)
+    return feature(theLabel);
+  TDF_Label aFeatureLabel = theLabel.Father().Father(); // let's suppose it is result
+  aFeature = feature(aFeatureLabel);
   if (aFeature) {
     const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
     std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
     for(; aRIter != aResults.cend(); aRIter++) {
       boost::shared_ptr<Model_Data> aResData = 
         boost::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
-      if (aResData->label().IsEqual(theLabel))
+      if (aResData->label().Father().IsEqual(theLabel))
         return *aRIter;
     }
   }
@@ -547,6 +557,7 @@ TDF_Label Model_Document::featuresLabel()
 
 void Model_Document::setUniqueName(FeaturePtr theFeature)
 {
+  if (!theFeature->data()->name().empty()) return; // not needed, name is already defined
   std::string aName; // result
   // first count all objects of such kind to start with index = count + 1
   int aNumObjects = 0;
@@ -586,12 +597,15 @@ void Model_Document::initData(ObjectPtr theObj, TDF_Label theLab, const int theT
   boost::shared_ptr<ModelAPI_Document> aThis = 
     Model_Application::getApplication()->getDocument(myID);
   boost::shared_ptr<Model_Data> aData(new Model_Data);
-  aData->setLabel(theLab.FindChild(theTag + 1));
+  aData->setLabel(theLab.FindChild(theTag));
   aData->setObject(theObj);
   theObj->setDoc(aThis);
   theObj->setData(aData);
   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
-  if (aFeature) aFeature->initAttributes();
+  if (aFeature) {
+    setUniqueName(aFeature); // must be before "initAttributes" because duplicate part uses name
+    aFeature->initAttributes();
+  }
 }
 
 void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
@@ -668,8 +682,8 @@ void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData
   boost::shared_ptr<ModelAPI_Document> aThis = 
     Model_Application::getApplication()->getDocument(myID);
   theResult->setDoc(aThis);
-  initData(theResult, boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->
-    label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex);
+  initData(theResult, boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->label().
+    Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1), TAG_FEATURE_ARGUMENTS);
   if (theResult->data()->name().empty()) { // if was not initialized, generate event and set a name
     theResult->data()->setName(theFeatureData->name());
   }
@@ -728,7 +742,7 @@ boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(
 {
   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(theResult->data());
   if (aData) {
-    TDF_Label aFeatureLab = aData->label().Father().Father();
+    TDF_Label aFeatureLab = aData->label().Father().Father().Father();
     return feature(aFeatureLab);
   }
   return FeaturePtr();