From: mpv Date: Thu, 17 Jul 2014 14:58:28 +0000 (+0400) Subject: The sketch initialization problem fix X-Git-Tag: V_0.4.4~172^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4da5ef887414bca016f01f3f4567d5788977dcba;p=modules%2Fshaper.git The sketch initialization problem fix --- diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index 0a6eee7c4..83e6b9c44 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -41,7 +41,11 @@ list 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; diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index f63dbbb25..c35f09e6c 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -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 >& 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 aThis = Model_Application::getApplication()->getDocument(myID); boost::shared_ptr 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(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 theFeatureData Model_Application::getApplication()->getDocument(myID); theResult->setDoc(aThis); initData(theResult, boost::dynamic_pointer_cast(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()); } diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp index 2307e0906..b02ae41f8 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp @@ -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(firstResult()); - boost::shared_ptr 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 aPManager = ModelAPI_PluginManager::get(); - boost::shared_ptr aRoot = aPManager->rootDocument(); - boost::shared_ptr aSource; // searching for source document attribute - for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { - aSource = boost::dynamic_pointer_cast( - 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 aCopy = - aPManager->copy(aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(), data()->name()); - aRef->setObject(aSource); - } + boost::shared_ptr aPManager = ModelAPI_PluginManager::get(); + boost::shared_ptr aRoot = aPManager->rootDocument(); + boost::shared_ptr aSource; // searching for source document attribute + for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { + aSource = boost::dynamic_pointer_cast(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 aCopy = aPManager->copy( + aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(), + data()->name()); } } diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.h b/src/PartSetPlugin/PartSetPlugin_Duplicate.h index dc64d2aec..cecac0505 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.h +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.h @@ -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; diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.cpp b/src/PartSetPlugin/PartSetPlugin_Remove.cpp index f352aa39e..da0dd7ee1 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Remove.cpp @@ -15,16 +15,17 @@ void PartSetPlugin_Remove::execute() boost::shared_ptr aRoot = aPManager->rootDocument(); boost::shared_ptr aCurrent; boost::shared_ptr a; - for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { - FeaturePtr aFeature = - boost::dynamic_pointer_cast(aRoot->object(ModelAPI_Feature::group(), a)); + for(int a = aRoot->size(ModelAPI_Feature::group()) - 1; a >= 0; a--) { + FeaturePtr aFeature = boost::dynamic_pointer_cast( + aRoot->object(ModelAPI_Feature::group(), a)); if (aFeature->getKind() == PartSetPlugin_Part::ID()) { boost::shared_ptr aPart = boost::static_pointer_cast(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); } }