Salome HOME
Initial version of redesign of working with results
[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(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
13   : myOwner(theFeature)
14 {
15 }
16
17 void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
18 {
19   boost::shared_ptr<Model_Data> aData =  boost::dynamic_pointer_cast<Model_Data>(data());
20   if (aData) {
21     TDF_Label& aShapeLab = aData->shapeLab();
22     // TODO: to add the naming mechanism for shape storage in the next iteration
23     TNaming_Builder aBuilder(aShapeLab);
24     if (!theShape) return; // bad shape
25     TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
26     if (aShape.IsNull()) return; // null shape inside
27
28     aBuilder.Generated(aShape);
29   }
30 }
31
32 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
33 {
34   boost::shared_ptr<Model_Data> aData =  boost::dynamic_pointer_cast<Model_Data>(data());
35   if (aData) {
36     TDF_Label& aShapeLab = aData->shapeLab();
37     Handle(TNaming_NamedShape) aName;
38     if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
39       TopoDS_Shape aShape = aName->Get();
40       if (!aShape.IsNull()) {
41         boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
42         aRes->setImpl(new TopoDS_Shape(aShape));
43         return aRes;
44       }
45     }
46   }
47   return boost::shared_ptr<GeomAPI_Shape>();
48 }
49
50 boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
51 {
52   return myOwner;
53 }