Salome HOME
Make circle with radius 0 not crashed: check validity before execution
[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)
24       return;  // bad shape
25     TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
26     if (aShape.IsNull())
27       return;  // null shape inside
28
29     aBuilder.Generated(aShape);
30   }
31 }
32
33 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
34 {
35   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
36   if (aData) {
37     TDF_Label& aShapeLab = aData->shapeLab();
38     Handle(TNaming_NamedShape) aName;
39     if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
40       TopoDS_Shape aShape = aName->Get();
41       if (!aShape.IsNull()) {
42         boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
43         aRes->setImpl(new TopoDS_Shape(aShape));
44         return aRes;
45       }
46     }
47   }
48   return boost::shared_ptr<GeomAPI_Shape>();
49 }
50
51 boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
52 {
53   return myOwner;
54 }