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()
15 setIsConcealed(false);
18 void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
20 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
22 TDF_Label& aShapeLab = aData->shapeLab();
25 // store the new shape as primitive
26 TNaming_Builder aBuilder(aShapeLab);
29 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
31 return; // null shape inside
33 aBuilder.Generated(aShape);
37 void Model_ResultBody::storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
38 const boost::shared_ptr<GeomAPI_Shape>& theToShape)
40 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
42 TDF_Label& aShapeLab = aData->shapeLab();
45 // store the new shape as primitive
46 TNaming_Builder aBuilder(aShapeLab);
47 if (!theFromShape || !theToShape)
49 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
50 if (aShapeBasis.IsNull())
51 return; // null shape inside
52 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
53 if (aShapeNew.IsNull())
54 return; // null shape inside
55 aBuilder.Generated(aShapeBasis, aShapeNew);
59 void Model_ResultBody::storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
60 const boost::shared_ptr<GeomAPI_Shape>& theNewShape)
62 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
64 TDF_Label& aShapeLab = aData->shapeLab();
67 // store the new shape as primitive
68 TNaming_Builder aBuilder(aShapeLab);
69 if (!theOldShape || !theNewShape)
71 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
72 if (aShapeOld.IsNull())
73 return; // null shape inside
74 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
75 if (aShapeNew.IsNull())
76 return; // null shape inside
77 aBuilder.Generated(aShapeOld, aShapeNew);
81 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
83 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
85 TDF_Label& aShapeLab = aData->shapeLab();
86 Handle(TNaming_NamedShape) aName;
87 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
88 TopoDS_Shape aShape = aName->Get();
89 if (!aShape.IsNull()) {
90 boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
91 aRes->setImpl(new TopoDS_Shape(aShape));
96 return boost::shared_ptr<GeomAPI_Shape>();
99 boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
104 void Model_ResultBody::clean()
106 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
107 for(; aBuilder != myBuilders.end(); aBuilder++)
111 Model_ResultBody::~Model_ResultBody()
116 TNaming_Builder* Model_ResultBody::builder(const int theTag)
118 if (myBuilders.size() < (unsigned int)theTag) {
119 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
121 if (!myBuilders[theTag]) {
122 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
123 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
125 return myBuilders[theTag];
128 void Model_ResultBody::generated(
129 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
131 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
132 builder(theTag)->Generated(aShape);
135 void Model_ResultBody::generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
136 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
138 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
139 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
140 builder(theTag)->Generated(anOldShape, aNewShape);
144 void Model_ResultBody::modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
145 const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
147 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
148 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
149 builder(theTag)->Modify(anOldShape, aNewShape);
152 void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
155 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
156 builder(theTag)->Delete(aShape);