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