]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Result.cpp
Salome HOME
[GITHUB #2] problem in export dialog - difference in STEP vs BREP
[modules/shaper.git] / src / ModelAPI / ModelAPI_Result.cpp
1 // Copyright (C) 2014-2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ModelAPI_Result.h"
21 #include <ModelAPI_Events.h>
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Attribute.h>
24 #include <ModelAPI_AttributeIntArray.h>
25 #include <ModelAPI_AttributeDouble.h>
26 #include <ModelAPI_AttributeBoolean.h>
27
28 #include <GeomAPI_Shape.h>
29
30 #include <Events_Loop.h>
31 #include <Events_InfoMessage.h>
32
33 #include <Locale_Convert.h>
34
35 #include <PyInterp_Interp.h>
36 #include <Python.h>
37
38 ModelAPI_Result::~ModelAPI_Result()
39 {
40 }
41
42 void ModelAPI_Result::initAttributes()
43 {
44   // append the color attribute. It is empty, the attribute will be filled by a request
45   DataPtr aData = data();
46   aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId())->setIsArgument(false);
47   aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId())->setIsArgument(false);
48   aData->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeDouble::typeId())->setIsArgument(false);
49   aData->addAttribute(ISO_LINES_ID(), ModelAPI_AttributeIntArray::typeId())->setIsArgument(false);
50   aData->addAttribute(SHOW_ISO_LINES_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false);
51   aData->addAttribute(SHOW_EDGES_DIRECTION_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false);
52   // Add the "Bring To Front" attribute to the Result base class, as we may support it in the future
53   // for all type of results. Actually, only ResultGroups are supported.
54   aData->addAttribute(BRING_TO_FRONT_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false);
55 }
56
57 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
58 {
59   if (myIsDisabled != theFlag) {
60     myIsDisabled = theFlag;
61     if (data()->isValid())
62       data()->setIsDeleted(theFlag); // store it in data model (to get back on undo/redo, etc)
63     // this must be before "updated" message send to have history updated for OB update
64     document()->updateHistory(groupName()); // to update the history cash data in the document
65     // generate related events
66     static Events_Loop* aLoop = Events_Loop::loop();
67     static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
68     if (myIsDisabled) { // disabled result looks like removed
69       aECreator->sendDeleted(document(), groupName());
70     } else { // un-disabled equals to created
71       static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
72       aECreator->sendUpdated(theThis, anEvent /*, false*/); // flush is in setCurrentFeature
73     }
74     static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
75     aECreator->sendUpdated(theThis, EVENT_DISP/*, false*/); // flush is in setCurrentFeature
76     return true;
77   }
78   return false;
79 }
80
81 bool ModelAPI_Result::isDisabled()
82 {
83   if (data()->isValid() && myIsDisabled != data()->isDeleted())
84     setDisabled(std::dynamic_pointer_cast<ModelAPI_Result>(
85       data()->owner()), data()->isDeleted()); // restore from the data model the correct value
86   return myIsDisabled;
87 }
88
89 bool ModelAPI_Result::isConcealed()
90 {
91   return myIsConcealed;
92 }
93
94 void ModelAPI_Result::setIsConcealed(const bool theValue, const bool /*theForced*/)
95 {
96   if (myIsConcealed != theValue) {
97     myIsConcealed = theValue;
98     if (document().get()) { // can be on creation of result
99       document()->updateHistory(groupName()); // to update the history cash data in the document
100       if (myIsConcealed) {
101         ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
102         static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
103         ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kDispEvent);
104       } else {
105         static Events_ID kEventCreated = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
106         ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kEventCreated);
107       }
108     }
109   }
110 }
111
112 std::shared_ptr<GeomAPI_Shape> ModelAPI_Result::shape()
113 {
114   return std::shared_ptr<GeomAPI_Shape>();
115 }
116
117 void ModelAPI_Result::showErrorMessage()
118 {
119   PyLockWrapper lck;
120   std::string aResName{};
121   if(data().get())
122   {
123     aResName = Locale::Convert::toString(data()->name());
124   }
125   std::string aMessage = "WARNING! The "+ aResName +" result is not valid.";
126   PySys_WriteStdout("%s\n", aMessage.c_str());
127 }
128
129 ListOfShape ModelAPI_Result::vertices(const bool theOnlyUnique)
130 {
131   if(!shape().get() || isDisabled())
132   {
133     showErrorMessage();
134     return ListOfShape();
135   }
136   return shape()->subShapes(GeomAPI_Shape::VERTEX, theOnlyUnique);
137 }
138
139 ListOfShape ModelAPI_Result::edges(const bool theOnlyUnique)
140 {
141   if(!shape().get() || isDisabled())
142   {
143     showErrorMessage();
144     return ListOfShape();
145   }
146   return shape()->subShapes(GeomAPI_Shape::EDGE, theOnlyUnique);
147 }
148
149 ListOfShape ModelAPI_Result::wires(const bool theOnlyUnique)
150 {
151   if(!shape().get() || isDisabled())
152   {
153     showErrorMessage();
154     return ListOfShape();
155   }
156   return shape()->subShapes(GeomAPI_Shape::WIRE, theOnlyUnique);
157 }
158
159 ListOfShape ModelAPI_Result::faces(const bool theOnlyUnique)
160 {
161   if(!shape().get() || isDisabled())
162   {
163     showErrorMessage();
164     return ListOfShape();
165   }
166   return shape()->subShapes(GeomAPI_Shape::FACE, theOnlyUnique);
167 }
168
169 ListOfShape ModelAPI_Result::shells(const bool theOnlyUnique)
170 {
171   if(!shape().get() || isDisabled())
172   {
173     showErrorMessage();
174     return ListOfShape();
175   }
176   return shape()->subShapes(GeomAPI_Shape::SHELL, theOnlyUnique);
177 }
178
179 ListOfShape ModelAPI_Result::solids(const bool theOnlyUnique)
180 {
181   if(!shape().get() || isDisabled())
182   {
183     showErrorMessage();
184     return ListOfShape();
185   }
186   return shape()->subShapes(GeomAPI_Shape::SOLID, theOnlyUnique);
187 }
188
189 void ModelAPI_Result::attributeChanged(const std::string& theID)
190 {
191   static Events_Loop* aLoop = Events_Loop::loop();
192   static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
193   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
194   aECreator->sendUpdated(data()->attribute(theID)->owner(), EVENT_DISP);
195 }
196
197 void ModelAPI_Result::init()
198 {
199   myIsDisabled = true; // by default it is not initialized and false to be after created
200   myIsConcealed = false;
201 }