Salome HOME
Issue #83: rename and transfer some methods related to document
[modules/shaper.git] / src / Model / Model_ResultPart.cpp
1 // File:        ModelAPI_ResultPart.cpp
2 // Created:     07 Jul 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include <Model_ResultPart.h>
6 #include <ModelAPI_Data.h>
7 #include <ModelAPI_AttributeDocRef.h>
8 #include <ModelAPI_Session.h>
9
10 boost::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
11 {
12   return data()->docRef("PartDocument")->value();
13 }
14
15 boost::shared_ptr<ModelAPI_Feature> Model_ResultPart::owner()
16 {
17   return boost::shared_ptr<ModelAPI_Feature>();  // return empty pointer
18 }
19
20 Model_ResultPart::Model_ResultPart()
21 {
22 }
23
24 void Model_ResultPart::setData(boost::shared_ptr<ModelAPI_Data> theData)
25 {
26   ModelAPI_Result::setData(theData);
27   if (theData) {
28     data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::type());
29   }
30 }
31
32 void Model_ResultPart::activate()
33 {
34   boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(DOC_REF());
35   
36   if (!aDocRef->value()) {  // create (or open) a document if it is not yet created
37     boost::shared_ptr<ModelAPI_Document> aDoc = document()->subDocument(data()->name());
38     if (aDoc) {
39       aDocRef->setValue(aDoc);
40     }
41   }
42   if (aDocRef->value())
43     ModelAPI_Session::get()->setActiveDocument(aDocRef->value());
44 }