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();
22 // remove the previous history
24 aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
25 for(TDF_ChildIterator anIter(aShapeLab); anIter.More(); anIter.Next()) {
26 anIter.Value().ForgetAllAttributes();
28 // store the new shape as primitive
29 TNaming_Builder aBuilder(aShapeLab);
32 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
34 return; // null shape inside
36 aBuilder.Generated(aShape);
40 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
42 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
44 TDF_Label& aShapeLab = aData->shapeLab();
45 Handle(TNaming_NamedShape) aName;
46 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
47 TopoDS_Shape aShape = aName->Get();
48 if (!aShape.IsNull()) {
49 boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
50 aRes->setImpl(new TopoDS_Shape(aShape));
55 return boost::shared_ptr<GeomAPI_Shape>();
58 boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
63 void Model_ResultBody::clean()
65 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
66 for(; aBuilder != myBuilders.end(); aBuilder++)
70 Model_ResultBody::~Model_ResultBody()
75 TNaming_Builder* Model_ResultBody::builder(const int theTag)
77 if (myBuilders.size() < (unsigned int)theTag) {
78 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
80 if (!myBuilders[theTag]) {
81 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
82 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
84 return myBuilders[theTag];
87 void Model_ResultBody::generated(
88 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
90 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
91 builder(theTag)->Generated(aShape);
94 void Model_ResultBody::generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
95 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
97 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
98 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
99 builder(theTag)->Generated(anOldShape, aNewShape);
103 void Model_ResultBody::modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
104 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
106 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
107 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
108 builder(theTag)->Modify(anOldShape, aNewShape);
111 void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
114 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
115 builder(theTag)->Delete(aShape);