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 <GeomAPI_Shape.h>
12 Model_ResultBody::Model_ResultBody()
16 void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
18 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
20 TDF_Label& aShapeLab = aData->shapeLab();
21 // remove the previous history
23 aShapeLab.ForgetAllAttributes();
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 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
38 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
40 TDF_Label& aShapeLab = aData->shapeLab();
41 Handle(TNaming_NamedShape) aName;
42 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
43 TopoDS_Shape aShape = aName->Get();
44 if (!aShape.IsNull()) {
45 boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
46 aRes->setImpl(new TopoDS_Shape(aShape));
51 return boost::shared_ptr<GeomAPI_Shape>();
54 boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
59 void Model_ResultBody::clean()
61 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
62 for(; aBuilder != myBuilders.end(); aBuilder++)
66 Model_ResultBody::~Model_ResultBody()
71 TNaming_Builder* Model_ResultBody::builder(const int theTag)
73 if (myBuilders.size() < (unsigned int)theTag) {
74 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
76 if (!myBuilders[theTag]) {
77 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
78 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
80 return myBuilders[theTag];
83 void Model_ResultBody::generated(
84 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
86 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
87 builder(theTag)->Generated(aShape);
90 void Model_ResultBody::generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
91 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
93 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
94 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
95 builder(theTag)->Generated(anOldShape, aNewShape);
99 void Model_ResultBody::modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
100 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
102 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
103 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
104 builder(theTag)->Modify(anOldShape, aNewShape);
107 void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
110 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
111 builder(theTag)->Delete(aShape);