From 17c9a33fd7ffb090ac85d173bfcdd52ba3182b1f Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 13 Apr 2015 16:29:52 +0300 Subject: [PATCH] Make python feature don't crash on documentToAdd call. --- src/Model/Model_Document.cpp | 13 +++++++++---- src/ModelAPI/ModelAPI_Feature.cpp | 7 ++++--- src/ModelAPI/ModelAPI_Feature.h | 4 ++-- src/ModelAPI/ModelAPI_Result.h | 3 ++- src/PartSetPlugin/PartSetPlugin_Part.cpp | 5 +++-- src/PartSetPlugin/PartSetPlugin_Part.h | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 00531ba84..ec0c236f6 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -557,13 +557,18 @@ FeaturePtr Model_Document::addFeature(std::string theID) { TDF_Label anEmptyLab; FeaturePtr anEmptyFeature; - FeaturePtr aFeature = - std::dynamic_pointer_cast(ModelAPI_Session::get())->createFeature(theID, this); + std::shared_ptr aSession = + std::dynamic_pointer_cast(ModelAPI_Session::get()); + FeaturePtr aFeature = aSession->createFeature(theID, this); if (!aFeature) return aFeature; Model_Document* aDocToAdd; - if (aFeature->documentToAdd().get()) { // use the customized document to add - aDocToAdd = std::dynamic_pointer_cast(aFeature->documentToAdd()).get(); + if (!aFeature->documentToAdd().empty()) { // use the customized document to add + if (aFeature->documentToAdd() != kind()) { // the root document by default + aDocToAdd = std::dynamic_pointer_cast(aSession->moduleDocument()).get(); + } else { + aDocToAdd = this; + } } else { // if customized is not presented, add to "this" document aDocToAdd = this; } diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index ef212d23f..d9533e83e 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -132,10 +132,11 @@ void ModelAPI_Feature::eraseResults() } } -std::shared_ptr ModelAPI_Feature::documentToAdd() +const std::string& ModelAPI_Feature::documentToAdd() { - // null pointer t ouse the current document - return std::shared_ptr(); + // empty to use the current document + static const std::string anEmpty; + return anEmpty; } void ModelAPI_Feature::erase() diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index b80583544..85ebe38b5 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -99,8 +99,8 @@ class ModelAPI_Feature : public ModelAPI_Object } /// Must return document where the new feature must be added to - /// By default it is null document: it is added to the document this method is called to - MODELAPI_EXPORT virtual std::shared_ptr documentToAdd(); + /// By default it is empty: it is added to the document this method is called to + MODELAPI_EXPORT virtual const std::string& documentToAdd(); /// To virtually destroy the fields of successors MODELAPI_EXPORT virtual ~ModelAPI_Feature(); diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index daad432e7..472fe0056 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -43,7 +43,8 @@ class ModelAPI_Result : public ModelAPI_Object } // Retuns the parameters of color definition in the resources config manager - virtual void colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault) {} + virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) {} /// Request for initialization of data model of the result: adding all attributes virtual void initAttributes() {}; diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 58c2d85fd..95fa5f06b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -31,7 +31,8 @@ void PartSetPlugin_Part::execute() } } -std::shared_ptr PartSetPlugin_Part::documentToAdd() +const std::string& PartSetPlugin_Part::documentToAdd() { - return ModelAPI_Session::get()->moduleDocument(); + // part must be added only to the module document + return ModelAPI_Session::get()->moduleDocument()->kind(); } diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h index 5b7d63e49..e7f23387c 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.h +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -43,7 +43,7 @@ class PartSetPlugin_Part : public ModelAPI_Feature /// Request for initialization of data model of the feature: adding all attributes PARTSETPLUGIN_EXPORT virtual void initAttributes(); - PARTSETPLUGIN_EXPORT virtual std::shared_ptr documentToAdd(); + PARTSETPLUGIN_EXPORT virtual const std::string& documentToAdd(); /// Returns true if this feature must be displayed in the history (top level of Part tree) PARTSETPLUGIN_EXPORT virtual bool isInHistory() -- 2.39.2