Salome HOME
0187d253403c5d2a3ed84ffcaa1c994bb9a30aee
[modules/shaper.git] / src / ModelAPI / ModelAPI_ResultBody.cpp
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
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_ResultBody.h"
21
22 #include <ModelAPI_BodyBuilder.h>
23 #include <Events_Loop.h>
24 #include <ModelAPI_Events.h>
25
26 ModelAPI_ResultBody::ModelAPI_ResultBody()
27   : myBuilder(0)
28 {
29   myConnect = ConnectionNotComputed;
30 }
31
32 ModelAPI_ResultBody::~ModelAPI_ResultBody()
33 {
34 }
35
36 std::string ModelAPI_ResultBody::groupName()
37 {
38   return group();
39 }
40
41 void ModelAPI_ResultBody::store(const GeomShapePtr& theShape,
42                                 const bool theIsStoreSameShapes)
43 {
44   myBuilder->store(theShape, theIsStoreSameShapes);
45   myConnect = ConnectionNotComputed;
46
47   static Events_Loop* aLoop = Events_Loop::loop();
48   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
49   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
50   aECreator->sendUpdated(data()->owner(), aRedispEvent);
51
52   updateSubs(theShape);
53 }
54
55 void ModelAPI_ResultBody::storeGenerated(const GeomShapePtr& theFromShape,
56                                          const GeomShapePtr& theToShape)
57 {
58   myBuilder->storeGenerated(theFromShape, theToShape);
59   myConnect = ConnectionNotComputed;
60
61   static Events_Loop* aLoop = Events_Loop::loop();
62   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
63   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
64   aECreator->sendUpdated(data()->owner(), aRedispEvent);
65
66   updateSubs(theToShape);
67 }
68
69 void ModelAPI_ResultBody::storeGenerated(
70   const std::list<GeomShapePtr>& theFromShapes, const GeomShapePtr& theToShape,
71   const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
72 {
73   myBuilder->storeGenerated(theFromShapes, theToShape, theMakeShape);
74   myConnect = ConnectionNotComputed;
75
76   static Events_Loop* aLoop = Events_Loop::loop();
77   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
78   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
79   aECreator->sendUpdated(data()->owner(), aRedispEvent);
80
81   updateSubs(theToShape, theFromShapes, theMakeShape, true);
82 }
83
84 void ModelAPI_ResultBody::storeModified(const GeomShapePtr& theOldShape,
85                                         const GeomShapePtr& theNewShape,
86                                         const bool theIsCleanStored)
87 {
88   myBuilder->storeModified(theOldShape, theNewShape, theIsCleanStored);
89   myConnect = ConnectionNotComputed;
90
91   static Events_Loop* aLoop = Events_Loop::loop();
92   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
93   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
94   aECreator->sendUpdated(data()->owner(), aRedispEvent);
95
96   updateSubs(theNewShape);
97 }
98
99 void ModelAPI_ResultBody::storeModified(
100   const std::list<GeomShapePtr>& theOldShapes, const GeomShapePtr& theNewShape,
101   const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
102 {
103   myBuilder->storeModified(theOldShapes, theNewShape, theMakeShape);
104   myConnect = ConnectionNotComputed;
105
106   static Events_Loop* aLoop = Events_Loop::loop();
107   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
108   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
109   aECreator->sendUpdated(data()->owner(), aRedispEvent);
110
111   updateSubs(theNewShape, theOldShapes, theMakeShape, false);
112 }
113
114 GeomShapePtr ModelAPI_ResultBody::shape()
115 {
116   return myBuilder->shape();
117 }
118
119 void ModelAPI_ResultBody::generated(const GeomShapePtr& theOldShape,
120                                     const GeomShapePtr& theNewShape,
121                                     const std::string& theName)
122 {
123   myBuilder->generated(theOldShape, theNewShape, theName);
124 }
125
126 void ModelAPI_ResultBody::modified(const GeomShapePtr& theOldShape,
127                                    const GeomShapePtr& theNewShape,
128                                    const std::string& theName)
129 {
130   myBuilder->modified(theOldShape, theNewShape, theName);
131 }
132
133
134 void ModelAPI_ResultBody::loadDeletedShapes(const GeomMakeShapePtr& theAlgo,
135                                             const GeomShapePtr& theOldShape,
136                                             const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
137                                             const GeomShapePtr& theShapesToExclude)
138 {
139   myBuilder->loadDeletedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theShapesToExclude);
140 }
141
142 // LCOV_EXCL_START
143 bool ModelAPI_ResultBody::isConnectedTopology()
144 {
145   if (myConnect == ConnectionNotComputed) {
146     myConnect = shape()->isConnectedTopology() ? IsConnected : IsNotConnected;
147   }
148   return myConnect == IsConnected;
149 }
150
151 void ModelAPI_ResultBody::setDisplayed(const bool theDisplay)
152 {
153   ModelAPI_Result::setDisplayed(theDisplay);
154   for (int i = 0; i < numberOfSubs(); i++)
155     subResult(i)->setDisplayed(theDisplay);
156 }
157 // LCOV_EXCL_STOP