]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
The sketch initialization problem fix
authormpv <mikhail.ponikarov@opencascade.com>
Thu, 17 Jul 2014 14:58:28 +0000 (18:58 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Thu, 17 Jul 2014 14:58:28 +0000 (18:58 +0400)
src/Model/Model_AttributeRefList.cpp
src/Model/Model_Document.cpp
src/PartSetPlugin/PartSetPlugin_Duplicate.cpp
src/PartSetPlugin/PartSetPlugin_Duplicate.h
src/PartSetPlugin/PartSetPlugin_Remove.cpp

index 0a6eee7c45cb9b66de20009239fc98ccb6eba55a..83e6b9c44624c74fb8d39f3c9085dcf3750f12e4 100644 (file)
@@ -41,7 +41,11 @@ list<ObjectPtr> Model_AttributeRefList::list()
   if (aDoc) {
     const TDF_LabelList& aList = myRef->List();
     for(TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
-      aResult.push_back(aDoc->object(aLIter.Value()));
+      ObjectPtr anObj = aDoc->object(aLIter.Value());
+      if (!anObj) { // try to use father (for feature)
+        anObj = aDoc->object(aLIter.Value().Father());
+      }
+      aResult.push_back(anObj);
     }
   }
   return aResult;
index f63dbbb25a6bc478b95fbc7a218779a298672d8b..c35f09e6cc9d1242265cdba0b38d98ff5273e105 100644 (file)
@@ -362,7 +362,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,7 +444,9 @@ FeaturePtr Model_Document::feature(TDF_Label& theLabel)
 
 ObjectPtr Model_Document::object(TDF_Label theLabel)
 {
-  TDF_Label aFeatureLabel = theLabel.Father().Father();
+  if (feature(theLabel)) // feature by label
+    return feature(theLabel);
+  TDF_Label aFeatureLabel = theLabel.Father().Father(); // let's suppose it is result
   FeaturePtr aFeature = feature(aFeatureLabel);
   if (aFeature) {
     const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
@@ -547,6 +548,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 +588,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)
@@ -669,7 +674,7 @@ void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData
     Model_Application::getApplication()->getDocument(myID);
   theResult->setDoc(aThis);
   initData(theResult, boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->
-    label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex);
+    label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex + 1);
   if (theResult->data()->name().empty()) { // if was not initialized, generate event and set a name
     theResult->data()->setName(theFeatureData->name());
   }
index 2307e09064e5478f142c72fe2187a13ea29ffb45..b02ae41f83810e9400f5293793bdf5d91be21861 100644 (file)
@@ -18,26 +18,22 @@ PartSetPlugin_Duplicate::PartSetPlugin_Duplicate()
 void PartSetPlugin_Duplicate::initAttributes()
 {
   PartSetPlugin_Part::initAttributes();
-  data()->addAttribute(PartSetPlugin_Duplicate::DOC_REF(), ModelAPI_AttributeRefAttr::type());
+  data()->addAttribute(ORIGIN_REF(), ModelAPI_AttributeRefAttr::type());
 
-  ResultPartPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
-    aResult->data()->refattr(ModelAPI_ResultPart::DOC_REF());
-  if (!aRef->attr()) { // create a copy: if not created yet attribute is not initialized
-    boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
-    boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
-    boost::shared_ptr<PartSetPlugin_Part> aSource; // searching for source document attribute
-    for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
-      aSource = boost::dynamic_pointer_cast<PartSetPlugin_Part>(
-        aRoot->object(ModelAPI_Feature::group(), a));
-      if (aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() == aPManager->currentDocument())
-        break;
-      aSource.reset();
-    }
-    if (aSource) {
-      boost::shared_ptr<ModelAPI_Document> aCopy = 
-        aPManager->copy(aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(), data()->name());
-      aRef->setObject(aSource);
-    }
+  boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
+  boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
+  boost::shared_ptr<ModelAPI_ResultPart> aSource; // searching for source document attribute
+  for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
+    aSource = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aRoot->object(getGroup(), a));
+    if (aSource && aSource->data() && 
+        aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() == 
+        aPManager->currentDocument())
+      break;
+    aSource.reset();
+  }
+  if (aSource) {
+    boost::shared_ptr<ModelAPI_Document> aCopy = aPManager->copy(
+      aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(),
+      data()->name());
   }
 }
index dc64d2aec9a0e8665189403d0705eacd1c7189f6..cecac050548943a950686bf2cc488f185a195986 100644 (file)
@@ -15,7 +15,7 @@ class PartSetPlugin_Duplicate: public PartSetPlugin_Part
 {
 public:
   /// the reference to copy: reference to the attribute
-  inline static const std::string& DOC_REF()
+  inline static const std::string& ORIGIN_REF()
   {
     static const std::string MY_DUPLICATE_ID("Origin");
     return MY_DUPLICATE_ID;
index f352aa39e8641fd815f297e47ba0a181420829c5..da0dd7ee15654c3047d3a29715bd7558676a27fd 100644 (file)
@@ -15,16 +15,17 @@ void PartSetPlugin_Remove::execute()
   boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
   boost::shared_ptr<ModelAPI_Document> aCurrent;
   boost::shared_ptr<PartSetPlugin_Part> a;
-  for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
-    FeaturePtr aFeature = 
-      boost::dynamic_pointer_cast<ModelAPI_Feature>(aRoot->object(ModelAPI_Feature::group(), a));
+  for(int a = aRoot->size(ModelAPI_Feature::group()) - 1; a >= 0; a--) {
+    FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(
+      aRoot->object(ModelAPI_Feature::group(), a));
     if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
       boost::shared_ptr<PartSetPlugin_Part> aPart = 
         boost::static_pointer_cast<PartSetPlugin_Part>(aFeature);
-      if (aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() == 
-        aPManager->currentDocument()) {
+      if (aPart && aPart->firstResult() &&
+          aPart->firstResult()->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() == 
+            aPManager->currentDocument()) {
         // do remove
-        aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value()->close();
+        aPart->firstResult()->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value()->close();
         aRoot->removeFeature(aPart);
       }
     }