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 <GeomAPI_Shape.h>
13 Model_ResultBody::Model_ResultBody()
17 void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
19 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
21 TDF_Label& aShapeLab = aData->shapeLab();
24 // store the new shape as primitive
25 TNaming_Builder aBuilder(aShapeLab);
28 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
30 return; // null shape inside
32 aBuilder.Generated(aShape);
36 void Model_ResultBody::storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
37 const boost::shared_ptr<GeomAPI_Shape>& theToShape)
39 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
41 TDF_Label& aShapeLab = aData->shapeLab();
44 // store the new shape as primitive
45 TNaming_Builder aBuilder(aShapeLab);
46 if (!theFromShape || !theToShape)
48 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
49 if (aShapeBasis.IsNull())
50 return; // null shape inside
51 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
52 if (aShapeNew.IsNull())
53 return; // null shape inside
54 aBuilder.Generated(aShapeBasis, aShapeNew);
58 void Model_ResultBody::storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
59 const boost::shared_ptr<GeomAPI_Shape>& theNewShape)
61 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
63 TDF_Label& aShapeLab = aData->shapeLab();
66 // store the new shape as primitive
67 TNaming_Builder aBuilder(aShapeLab);
68 if (!theOldShape || !theNewShape)
70 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
71 if (aShapeOld.IsNull())
72 return; // null shape inside
73 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
74 if (aShapeNew.IsNull())
75 return; // null shape inside
76 aBuilder.Generated(aShapeOld, aShapeNew);
80 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
82 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
84 TDF_Label& aShapeLab = aData->shapeLab();
85 Handle(TNaming_NamedShape) aName;
86 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
87 TopoDS_Shape aShape = aName->Get();
88 if (!aShape.IsNull()) {
89 boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
90 aRes->setImpl(new TopoDS_Shape(aShape));
95 return boost::shared_ptr<GeomAPI_Shape>();
98 boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
103 void Model_ResultBody::clean()
105 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
106 for(; aBuilder != myBuilders.end(); aBuilder++)
110 Model_ResultBody::~Model_ResultBody()
115 TNaming_Builder* Model_ResultBody::builder(const int theTag)
117 if (myBuilders.size() < (unsigned int)theTag) {
118 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
120 if (!myBuilders[theTag]) {
121 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
122 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
124 return myBuilders[theTag];
127 void Model_ResultBody::generated(
128 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
130 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
131 builder(theTag)->Generated(aShape);
134 void Model_ResultBody::generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
135 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
137 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
138 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
139 builder(theTag)->Generated(anOldShape, aNewShape);
143 void Model_ResultBody::modified(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)->Modify(anOldShape, aNewShape);
151 void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
154 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
155 builder(theTag)->Delete(aShape);