1 // File: Model_ResultBody.cpp
2 // Created: 08 Jul 2014
3 // Author: Mikhail PONIKAROV
5 #include <Model_ResultBody.h>
6 #include <Model_Data.h>
7 #include <TNaming_Builder.hxx>
8 #include <TNaming_NamedShape.hxx>
9 #include <TopoDS_Shape.hxx>
10 #include <TDF_ChildIterator.hxx>
11 #include <TopTools_MapOfShape.hxx>
12 #include <TopExp_Explorer.hxx>
13 #include <GeomAPI_Shape.h>
14 #include <GeomAlgoAPI_MakeShape.h>
16 //#include <TCollection_AsciiString.hxx>
17 //#include <TDF_Tool.hxx>
18 Model_ResultBody::Model_ResultBody()
20 setIsConcealed(false);
23 void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
25 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
27 TDF_Label& aShapeLab = aData->shapeLab();
30 // store the new shape as primitive
31 TNaming_Builder aBuilder(aShapeLab);
34 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
36 return; // null shape inside
38 aBuilder.Generated(aShape);
42 void Model_ResultBody::storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
43 const boost::shared_ptr<GeomAPI_Shape>& theToShape)
45 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
47 TDF_Label& aShapeLab = aData->shapeLab();
50 // store the new shape as primitive
51 TNaming_Builder aBuilder(aShapeLab);
52 if (!theFromShape || !theToShape)
54 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
55 if (aShapeBasis.IsNull())
56 return; // null shape inside
57 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
58 if (aShapeNew.IsNull())
59 return; // null shape inside
60 aBuilder.Generated(aShapeBasis, aShapeNew);
64 void Model_ResultBody::storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
65 const boost::shared_ptr<GeomAPI_Shape>& theNewShape)
67 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
69 TDF_Label& aShapeLab = aData->shapeLab();
72 // store the new shape as primitive
73 TNaming_Builder aBuilder(aShapeLab);
74 if (!theOldShape || !theNewShape)
76 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
77 if (aShapeOld.IsNull())
78 return; // null shape inside
79 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
80 if (aShapeNew.IsNull())
81 return; // null shape inside
82 aBuilder.Generated(aShapeOld, aShapeNew);
86 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
88 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
90 TDF_Label& aShapeLab = aData->shapeLab();
91 Handle(TNaming_NamedShape) aName;
92 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
93 TopoDS_Shape aShape = aName->Get();
94 if (!aShape.IsNull()) {
95 boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
96 aRes->setImpl(new TopoDS_Shape(aShape));
101 return boost::shared_ptr<GeomAPI_Shape>();
104 boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
109 void Model_ResultBody::clean()
111 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
112 for(; aBuilder != myBuilders.end(); aBuilder++)
116 Model_ResultBody::~Model_ResultBody()
121 TNaming_Builder* Model_ResultBody::builder(const int theTag)
123 if (myBuilders.size() <= (unsigned int)theTag) {
124 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
126 if (!myBuilders[theTag]) {
127 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
128 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
129 //TCollection_AsciiString entry;//
130 //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
131 //cout << "Label = " <<entry.ToCString() <<endl;
133 return myBuilders[theTag];
136 void Model_ResultBody::generated(
137 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
139 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
140 builder(theTag)->Generated(aShape);
143 void Model_ResultBody::generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
144 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
146 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
147 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
148 builder(theTag)->Generated(anOldShape, aNewShape);
152 void Model_ResultBody::modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
153 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
155 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
156 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
157 builder(theTag)->Modify(anOldShape, aNewShape);
160 void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
163 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
164 builder(theTag)->Delete(aShape);
167 void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
168 boost::shared_ptr<GeomAPI_Shape> theShapeIn,
169 const int theKindOfShape,
172 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
173 TopTools_MapOfShape aView;
174 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
175 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
176 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
177 if (!aView.Add(aRoot)) continue;
178 boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
179 aRShape->setImpl((new TopoDS_Shape(aRoot)));
180 if (theMS->isDeleted (aRShape)) {
181 builder(theTag)->Delete(aRoot);
186 void Model_ResultBody::loadAndOrientModifiedShapes (
187 GeomAlgoAPI_MakeShape* theMS,
188 boost::shared_ptr<GeomAPI_Shape> theShapeIn,
189 const int theKindOfShape,
191 GeomAPI_DataMapOfShapeShape& theSubShapes)
193 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
194 TopTools_MapOfShape aView;
195 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
196 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
197 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
198 if (!aView.Add(aRoot)) continue;
200 boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
201 aRShape->setImpl((new TopoDS_Shape(aRoot)));
202 theMS->generated(aRShape, aList);
203 std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
204 for (; anIt != aLast; anIt++) {
205 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
206 if (theSubShapes.isBound(*anIt)) {
207 boost::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
208 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
210 if (!aRoot.IsSame (aNewShape))
211 builder(theTag)->Modify(aRoot,aNewShape);
216 void Model_ResultBody::loadAndOrientGeneratedShapes (
217 GeomAlgoAPI_MakeShape* theMS,
218 boost::shared_ptr<GeomAPI_Shape> theShapeIn,
219 const int theKindOfShape,
221 GeomAPI_DataMapOfShapeShape& theSubShapes)
223 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
224 TopTools_MapOfShape aView;
225 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
226 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
227 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
228 if (!aView.Add(aRoot)) continue;
230 boost::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
231 aRShape->setImpl((new TopoDS_Shape(aRoot)));
232 theMS->generated(aRShape, aList);
233 std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
234 for (; anIt != aLast; anIt++) {
235 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
236 if (theSubShapes.isBound(*anIt)) {
237 boost::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
238 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
240 if (!aRoot.IsSame (aNewShape))
241 builder(theTag)->Generated(aRoot,aNewShape);