Salome HOME
Fix of unstable behavior of results creation events on Linux
[modules/shaper.git] / src / Model / Model_ResultPart.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_ResultPart.cpp
4 // Created:     07 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include <Model_ResultPart.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_AttributeDocRef.h>
10 #include <ModelAPI_Session.h>
11
12 std::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
13 {
14   return data()->document("PartDocument")->value();
15 }
16
17 std::shared_ptr<ModelAPI_Feature> Model_ResultPart::owner()
18 {
19   return std::shared_ptr<ModelAPI_Feature>();  // return empty pointer
20 }
21
22 Model_ResultPart::Model_ResultPart()
23 {
24   myIsDisabled = true; // by default it is not initialized and false to be after created
25   setIsConcealed(false);
26 }
27
28 void Model_ResultPart::setData(std::shared_ptr<ModelAPI_Data> theData)
29 {
30   ModelAPI_Result::setData(theData);
31   if (theData) {
32     data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::typeId());
33   }
34 }
35
36 void Model_ResultPart::activate()
37 {
38   std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
39   
40   if (!aDocRef->value().get()) {  // create (or open) a document if it is not yet created
41     std::shared_ptr<ModelAPI_Document> aDoc = document()->subDocument(data()->name());
42     if (aDoc) {
43       aDocRef->setValue(aDoc);
44     }
45   }
46   if (aDocRef->value().get()) {
47     ModelAPI_Session::get()->setActiveDocument(aDocRef->value());
48   }
49 }
50
51 bool Model_ResultPart::isActivated() 
52 {
53   std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
54   return aDocRef->value().get();
55 }