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>
12 #include <ModelAPI_ResultBody.h>
14 #include <TopoDS_Compound.hxx>
15 #include <BRep_Builder.hxx>
17 std::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
19 return data()->document("PartDocument")->value();
22 std::shared_ptr<ModelAPI_Feature> Model_ResultPart::owner()
24 return std::shared_ptr<ModelAPI_Feature>(); // return empty pointer
27 Model_ResultPart::Model_ResultPart()
29 myIsDisabled = true; // by default it is not initialized and false to be after created
30 setIsConcealed(false);
33 void Model_ResultPart::setData(std::shared_ptr<ModelAPI_Data> theData)
35 ModelAPI_Result::setData(theData);
37 data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::typeId());
41 void Model_ResultPart::activate()
43 std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
45 if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created
46 std::shared_ptr<ModelAPI_Document> aDoc = document()->subDocument(data()->name());
48 aDocRef->setValue(aDoc);
51 if (aDocRef->value().get()) {
52 SessionPtr aMgr = ModelAPI_Session::get();
53 bool isNewTransaction = !aMgr->isOperation();
54 // activation may cause changes in current features in document, so it must be in transaction
55 if (isNewTransaction) {
56 aMgr->startOperation("Activation");
58 ModelAPI_Session::get()->setActiveDocument(aDocRef->value());
59 if (isNewTransaction) {
60 aMgr->finishOperation();
65 bool Model_ResultPart::isActivated()
67 std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
68 return aDocRef->value().get();
71 bool Model_ResultPart::setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
74 if (ModelAPI_ResultPart::setDisabled(theThis, theFlag)) {
75 DocumentPtr aDoc = Model_ResultPart::partDoc();
77 if (theFlag) { // disable, so make all features disabled too
78 aDoc->setCurrentFeature(FeaturePtr(), false);
79 } else { // enabled, so make the current feature the last inside of this document
80 FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aDoc->object(
81 ModelAPI_Feature::group(), aDoc->size(ModelAPI_Feature::group()) - 1));
82 aDoc->setCurrentFeature(aLastFeature, false);
90 std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shape()
92 DocumentPtr aDoc = Model_ResultPart::partDoc();
94 const std::string& aBodyGroup = ModelAPI_ResultBody::group();
95 TopoDS_Compound aResultComp;
96 BRep_Builder aBuilder;
97 aBuilder.MakeCompound(aResultComp);
99 for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) {
100 ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(aDoc->object(aBodyGroup, a));
101 if (aBody.get() && aBody->shape().get()) {
102 TopoDS_Shape aShape = *(aBody->shape()->implPtr<TopoDS_Shape>());
103 if (!aShape.IsNull()) {
104 aBuilder.Add(aResultComp, aShape);
110 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
111 aResult->setImpl(new TopoDS_Shape(aResultComp));
115 return std::shared_ptr<GeomAPI_Shape>();