Model_ResultPart::Model_ResultPart()
{
}
+
+void Model_ResultPart::setData(boost::shared_ptr<ModelAPI_Data> theData)
+{
+ ModelAPI_Result::setData(theData);
+ if (theData) {
+ data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::type());
+ }
+}
/// makes a result on a temporary feature (an action)
Model_ResultPart();
+ /// Sets the data manager of an object (document does), here also attributes are initialized
+ virtual void setData(boost::shared_ptr<ModelAPI_Data> theData);
+
friend class Model_Document;
};
std::list<boost::shared_ptr<ModelAPI_Result> >& results() {return myResults;}
/// returns the first result in the list or NULL reference
boost::shared_ptr<ModelAPI_Result> firstResult()
- {return myResults.size() ? *(myResults.begin()) : boost::shared_ptr<ModelAPI_Result>();}
+ {return myResults.empty() ? boost::shared_ptr<ModelAPI_Result>() : *(myResults.begin());}
/// sets the alone result
void setResult(const boost::shared_ptr<ModelAPI_Result>& theResult)
{myResults.clear(); myResults.push_back(theResult);}
static std::string group()
{static std::string MY_GROUP = "Parts"; return MY_GROUP;}
+ /// part document reference attribute
+ inline static const std::string& DOC_REF()
+ {
+ static const std::string MY_DOC_REF("PartDocument");
+ return MY_DOC_REF;
+ }
+
/// Returns the part-document of this result
virtual boost::shared_ptr<ModelAPI_Document> partDoc() = 0;
};
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
+#include <ModelAPI_ResultPart.h>
using namespace std;
PartSetPlugin_Part::initAttributes();
data()->addAttribute(PartSetPlugin_Duplicate::DOC_REF(), ModelAPI_AttributeRefAttr::type());
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = data()->refattr(PartSetPlugin_Duplicate::DOC_REF());
+ 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();
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(PartSetPlugin_Part::DOC_REF())->value() == aPManager->currentDocument())
+ 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(PartSetPlugin_Part::DOC_REF())->value(), data()->name());
+ aPManager->copy(aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(), data()->name());
aRef->setObject(aSource);
}
}
}
void PartSetPlugin_Part::initAttributes()
-{
- data()->addAttribute(PartSetPlugin_Part::DOC_REF(), ModelAPI_AttributeDocRef::type());
+{// all is in part result
}
void PartSetPlugin_Part::execute()
{
- boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(PartSetPlugin_Part::DOC_REF());
+ ResultPartPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
+ if (!aResult) {
+ aResult = document()->createPart(data());
+ setResult(aResult);
+ }
+ boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef =
+ aResult->data()->docRef(ModelAPI_ResultPart::DOC_REF());
+
if (!aDocRef->value()) { // create a document if not yet created
boost::shared_ptr<ModelAPI_Document> aPartSetDoc =
ModelAPI_PluginManager::get()->rootDocument();
aDocRef->setValue(aPartSetDoc->subDocument(data()->name()));
}
- // create a result only once
- if (results().empty()) {
- boost::shared_ptr<ModelAPI_ResultPart> aResult = document()->createPart(data());
- setResult(aResult);
- }
}
boost::shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd() {
static const std::string MY_PART_KIND("Part");
return MY_PART_KIND;
}
- /// part reference attribute
- inline static const std::string& DOC_REF()
- {
- static const std::string MY_DOC_REF("PartDocument");
- return MY_DOC_REF;
- }
/// Returns the kind of a feature
PARTSETPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = PartSetPlugin_Part::ID(); return MY_KIND;}
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_ResultPart.h>
void PartSetPlugin_Remove::execute()
{
if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
boost::shared_ptr<PartSetPlugin_Part> aPart =
boost::static_pointer_cast<PartSetPlugin_Part>(aFeature);
- if (aPart->data()->docRef(PartSetPlugin_Part::DOC_REF())->value() == aPManager->currentDocument()) {
+ if (aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() ==
+ aPManager->currentDocument()) {
// do remove
- aPart->data()->docRef(PartSetPlugin_Part::DOC_REF())->value()->close();
+ aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value()->close();
aRoot->removeFeature(aPart);
}
}