Salome HOME
Sources formated according to the codeing standards
[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 {  // all is in part result
20 }
21
22 void PartSetPlugin_Part::execute()
23 {
24   ResultPartPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
25   if (!aResult) {
26     aResult = document()->createPart(data());
27     setResult(aResult);
28   }
29   boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aResult->data()->docRef(
30       ModelAPI_ResultPart::DOC_REF());
31
32   if (!aDocRef->value()) {  // create a document if not yet created
33     boost::shared_ptr<ModelAPI_Document> aPartSetDoc =
34         ModelAPI_PluginManager::get()->rootDocument();
35     aDocRef->setValue(aPartSetDoc->subDocument(data()->name()));
36   }
37 }
38
39 boost::shared_ptr<ModelAPI_Document> PartSetPlugin_Part::documentToAdd()
40 {
41   return ModelAPI_PluginManager::get()->rootDocument();
42 }