1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_ResultPart.cpp
4 // Created: 07 Jul 2014
5 // Author: Mikhail PONIKAROV
7 #include <Model_ResultPart.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_AttributeDocRef.h>
10 #include <ModelAPI_Session.h>
11 #include <ModelAPI_Feature.h>
13 std::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
15 return data()->document("PartDocument")->value();
18 std::shared_ptr<ModelAPI_Feature> Model_ResultPart::owner()
20 return std::shared_ptr<ModelAPI_Feature>(); // return empty pointer
23 Model_ResultPart::Model_ResultPart()
25 myIsDisabled = true; // by default it is not initialized and false to be after created
26 setIsConcealed(false);
29 void Model_ResultPart::setData(std::shared_ptr<ModelAPI_Data> theData)
31 ModelAPI_Result::setData(theData);
33 data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::typeId());
37 void Model_ResultPart::activate()
39 std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
41 if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created
42 std::shared_ptr<ModelAPI_Document> aDoc = document()->subDocument(data()->name());
44 aDocRef->setValue(aDoc);
47 if (aDocRef->value().get()) {
48 SessionPtr aMgr = ModelAPI_Session::get();
49 bool isNewTransaction = !aMgr->isOperation();
50 // activation may cause changes in current features in document, so it must be in transaction
51 if (isNewTransaction) {
52 aMgr->startOperation("Activation");
54 ModelAPI_Session::get()->setActiveDocument(aDocRef->value());
55 if (isNewTransaction) {
56 aMgr->finishOperation();
61 bool Model_ResultPart::isActivated()
63 std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
64 return aDocRef->value().get();
67 bool Model_ResultPart::setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
70 if (ModelAPI_ResultPart::setDisabled(theThis, theFlag)) {
71 DocumentPtr aDoc = Model_ResultPart::partDoc();
73 if (theFlag) { // disable, so make all features disabled too
74 aDoc->setCurrentFeature(FeaturePtr(), false);
75 } else { // enabled, so make the current feature the last inside of this document
76 FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aDoc->object(
77 ModelAPI_Feature::group(), aDoc->size(ModelAPI_Feature::group()) - 1));
78 aDoc->setCurrentFeature(aLastFeature, false);