Salome HOME
fda4b4d8b5affe80cf677bde7bf6559b41f38415
[modules/shaper.git] / src / Model / Model_ResultBody.cpp
1 // File:        Model_ResultBody.cpp
2 // Created:     08 Jul 2014
3 // Author:      Mikhail PONIKAROV
4
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>
11
12 Model_ResultBody::Model_ResultBody()
13 {
14 }
15
16 void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
17 {
18   boost::shared_ptr<Model_Data> aData =  boost::dynamic_pointer_cast<Model_Data>(data());
19   if (aData) {
20     TDF_Label& aShapeLab = aData->shapeLab();
21     // TODO: to add the naming mechanism for shape storage in the next iteration
22     TNaming_Builder aBuilder(aShapeLab);
23     if (!theShape) return; // bad shape
24     TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
25     if (aShape.IsNull()) return; // null shape inside
26
27     aBuilder.Generated(aShape);
28   }
29 }
30
31 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
32 {
33   boost::shared_ptr<Model_Data> aData =  boost::dynamic_pointer_cast<Model_Data>(data());
34   if (aData) {
35     TDF_Label& aShapeLab = aData->shapeLab();
36     Handle(TNaming_NamedShape) aName;
37     if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
38       TopoDS_Shape aShape = aName->Get();
39       if (!aShape.IsNull()) {
40         boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
41         aRes->setImpl(new TopoDS_Shape(aShape));
42         return aRes;
43       }
44     }
45   }
46   return boost::shared_ptr<GeomAPI_Shape>();
47 }
48
49 boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
50 {
51   return myOwner;
52 }