Salome HOME
Making compilable all non-GUI classes
[modules/shaper.git] / src / PartSetPlugin / PartSetPlugin_Part.cpp
1 // File:        PartSetPlugin_Part.cxx
2 // Created:     27 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include "PartSetPlugin_Part.h"
6 #include "ModelAPI_PluginManager.h"
7 #include "ModelAPI_Document.h"
8 #include "ModelAPI_Data.h"
9 #include "ModelAPI_AttributeDocRef.h"
10 #include <ModelAPI_ResultPart.h>
11
12 using namespace std;
13
14 PartSetPlugin_Part::PartSetPlugin_Part()
15 {
16 }
17
18 void PartSetPlugin_Part::initAttributes()
19 {
20   data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type());
21 }
22
23 void PartSetPlugin_Part::execute() 
24 {
25   boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(PART_ATTR_DOC_REF);
26   if (!aDocRef->value()) { // create a document if not yet created
27     boost::shared_ptr<ModelAPI_Document> aPartSetDoc = 
28       ModelAPI_PluginManager::get()->rootDocument();
29     aDocRef->setValue(aPartSetDoc->subDocument(data()->name()));
30   }
31   // create a result only once
32   if (results().empty()) {
33     boost::shared_ptr<ModelAPI_ResultPart> aResult = document()->createPart();
34     document()->storeResult(data(), aResult);
35     if (aResult->data()->name().empty())
36       aResult->data()->setName(data()->name());
37   }
38 }
39
40 boost::shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd() {
41   return ModelAPI_PluginManager::get()->rootDocument();
42 }