Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #include "ModelAPI_ResultBody.h"
21 #include <ModelAPI_BodyBuilder.h>
22 #include <Events_Loop.h>
23 #include <ModelAPI_Events.h>
24
25 ModelAPI_ResultBody::ModelAPI_ResultBody()
26 : myBuilder(0)
27 {
28   myConnect = ConnectionNotComputed;
29 }
30
31 ModelAPI_ResultBody::~ModelAPI_ResultBody()
32 {
33   if (myBuilder)
34   delete myBuilder;
35 }
36
37 std::string ModelAPI_ResultBody::groupName()
38 {
39   return group();
40 }
41
42 void ModelAPI_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& 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
54 void ModelAPI_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
55                                   const std::shared_ptr<GeomAPI_Shape>& theToShape)
56 {
57   myBuilder->storeGenerated(theFromShape, theToShape);
58   myConnect = ConnectionNotComputed;
59
60   static Events_Loop* aLoop = Events_Loop::loop();
61   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
62   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
63   aECreator->sendUpdated(data()->owner(), aRedispEvent);
64 }
65
66 void ModelAPI_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
67                                   const std::shared_ptr<GeomAPI_Shape>& theNewShape,
68                             const int theDecomposeSolidsTag)
69 {
70   myBuilder->storeModified(theOldShape, theNewShape, theDecomposeSolidsTag);
71   myConnect = ConnectionNotComputed;
72
73   static Events_Loop* aLoop = Events_Loop::loop();
74   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
75   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
76   aECreator->sendUpdated(data()->owner(), aRedispEvent);
77 }
78
79 void ModelAPI_ResultBody::storeWithoutNaming(const std::shared_ptr<GeomAPI_Shape>& theShape)
80 {
81   myBuilder->storeWithoutNaming(theShape);
82   myConnect = ConnectionNotComputed;
83
84   static Events_Loop* aLoop = Events_Loop::loop();
85   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
86   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
87   aECreator->sendUpdated(data()->owner(), aRedispEvent);
88 }
89
90 std::shared_ptr<GeomAPI_Shape> ModelAPI_ResultBody::shape()
91 {
92   return myBuilder->shape();
93 }
94
95 void ModelAPI_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theNewShape,
96     const std::string& theName, const int theTag)
97 {
98   myBuilder->generated(theNewShape, theName, theTag);
99 }
100
101 void ModelAPI_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
102     const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName,
103     const int theTag)
104 {
105   myBuilder->generated(theOldShape, theNewShape, theName, theTag);
106 }
107
108 void ModelAPI_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
109     const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName,
110     const int theTag)
111 {
112   myBuilder->modified(theOldShape, theNewShape, theName, theTag);
113 }
114
115
116 void ModelAPI_ResultBody::deleted(
117     const std::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag)
118 {
119   myBuilder->deleted(theOldShape, theTag);
120 }
121
122 void ModelAPI_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
123                                   std::shared_ptr<GeomAPI_Shape>  theShapeIn,
124                                   const int  theKindOfShape,
125                                   const int  theTag)
126 {
127   myBuilder->loadDeletedShapes(theMS, theShapeIn, theKindOfShape, theTag);
128 }
129
130 void ModelAPI_ResultBody::loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS,
131     std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
132     const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
133     const bool theIsStoreSeparate,
134     const bool theIsStoreAsGenerated)
135 {
136   myBuilder->loadAndOrientModifiedShapes(
137     theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes, theIsStoreSeparate,
138     theIsStoreAsGenerated);
139 }
140
141 void ModelAPI_ResultBody::loadAndOrientGeneratedShapes (GeomAlgoAPI_MakeShape* theMS,
142     std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape,
143     const int  theTag, const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes)
144 {
145   myBuilder->loadAndOrientGeneratedShapes(
146     theMS, theShapeIn, theKindOfShape, theTag, theName, theSubShapes);
147 }
148
149 void ModelAPI_ResultBody::loadFirstLevel(std::shared_ptr<GeomAPI_Shape> theShape,
150     const std::string& theName, int&  theTag)
151 {
152   myBuilder->loadFirstLevel(theShape, theName, theTag);
153 }
154
155 void ModelAPI_ResultBody::loadDisconnectedEdges(std::shared_ptr<GeomAPI_Shape> theShape,
156     const std::string& theName, int&  theTag)
157 {
158   myBuilder->loadDisconnectedEdges(theShape, theName, theTag);
159 }
160
161 void ModelAPI_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape,
162     const std::string& theName,int&  theTag)
163 {
164   myBuilder->loadDisconnectedVertexes(theShape, theName, theTag);
165 }
166
167 bool ModelAPI_ResultBody::isConnectedTopology()
168 {
169   if (myConnect == ConnectionNotComputed) {
170     myConnect = shape()->isConnectedTopology() ? IsConnected : IsNotConnected;
171   }
172   return myConnect == IsConnected;
173 }