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