return myRef->Extent();
}
+bool Model_AttributeRefList::isInitialized()
+{
+ if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
+ return false;
+ }
+ return ModelAPI_AttributeRefList::isInitialized();
+}
+
list<ObjectPtr> Model_AttributeRefList::list()
{
std::list<ObjectPtr> aResult;
/// Returns the list of features
MODEL_EXPORT virtual ObjectPtr object(const int theIndex) const;
+ /// Returns true if attribute was initialized by some value
+ MODEL_EXPORT virtual bool isInitialized();
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
}
}
+bool Model_AttributeSelectionList::isInitialized()
+{
+ if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
+ return false;
+ }
+ return ModelAPI_AttributeSelectionList::isInitialized();
+}
+
Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
{
myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
/// Returns all attributes
MODEL_EXPORT virtual void clear();
+ /// Returns true if attribute was initialized by some value
+ MODEL_EXPORT virtual bool isInitialized();
+
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
{
TDF_Label anEmptyLab;
FeaturePtr anEmptyFeature;
- FeaturePtr aFeature =
- std::dynamic_pointer_cast<Model_Session>(ModelAPI_Session::get())->createFeature(theID, this);
+ std::shared_ptr<Model_Session> aSession =
+ std::dynamic_pointer_cast<Model_Session>(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<Model_Document>(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<Model_Document>(aSession->moduleDocument()).get();
+ } else {
+ aDocToAdd = this;
+ }
} else { // if customized is not presented, add to "this" document
aDocToAdd = this;
}
MODELAPI_EXPORT const std::shared_ptr<ModelAPI_Object>& owner() const;
/// Returns true if attribute was initialized by some value
- MODELAPI_EXPORT bool isInitialized();
+ MODELAPI_EXPORT virtual bool isInitialized();
/// Makes attribute initialized
MODELAPI_EXPORT void setInitialized();
}
}
-std::shared_ptr<ModelAPI_Document> ModelAPI_Feature::documentToAdd()
+const std::string& ModelAPI_Feature::documentToAdd()
{
- // null pointer t ouse the current document
- return std::shared_ptr<ModelAPI_Document>();
+ // empty to use the current document
+ static const std::string anEmpty;
+ return anEmpty;
}
void ModelAPI_Feature::erase()
}
/// 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<ModelAPI_Document> 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();
}
// 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() {};
}
}
-std::shared_ptr<ModelAPI_Document> 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();
}
/// Request for initialization of data model of the feature: adding all attributes
PARTSETPLUGIN_EXPORT virtual void initAttributes();
- PARTSETPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Document> 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()