Salome HOME
PAL8395: Fix pb. with bug2extraEdges.py
[modules/geom.git] / src / GEOMImpl / GEOMImpl_OffsetDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_OffsetDriver.hxx"
4 #include "GEOMImpl_IOffset.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
9 #include <BRep_Tool.hxx>
10 #include <TopoDS.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Vertex.hxx>
13 #include <TopAbs.hxx>
14 #include <TopExp.hxx>
15
16 #include <Precision.hxx>
17 #include <gp_Pnt.hxx>
18
19 #include <StdFail_NotDone.hxx>
20
21 //=======================================================================
22 //function : GetID
23 //purpose  :
24 //=======================================================================
25 const Standard_GUID& GEOMImpl_OffsetDriver::GetID()
26 {
27   static Standard_GUID aOffsetDriver("FF1BBB51-5D14-4df2-980B-3A668264EA16");
28   return aOffsetDriver;
29 }
30
31
32 //=======================================================================
33 //function : GEOMImpl_OffsetDriver
34 //purpose  :
35 //=======================================================================
36 GEOMImpl_OffsetDriver::GEOMImpl_OffsetDriver()
37 {
38 }
39
40 //=======================================================================
41 //function : Execute
42 //purpose  :
43 //=======================================================================
44 Standard_Integer GEOMImpl_OffsetDriver::Execute(TFunction_Logbook& log) const
45 {
46   if (Label().IsNull()) return 0;
47   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
48
49   GEOMImpl_IOffset aCI (aFunction);
50   Standard_Integer aType = aFunction->GetType();
51
52   TopoDS_Shape aShape;
53
54   if (aType == OFFSET_SHAPE || aType == OFFSET_SHAPE_COPY) {
55     Handle(GEOM_Function) aRefShape = aCI.GetShape();
56     TopoDS_Shape aShapeBase = aRefShape->GetValue();
57     Standard_Real anOffset = aCI.GetValue();
58     Standard_Real aTol = Precision::Confusion();
59
60     if (Abs(anOffset) < aTol) {
61       TCollection_AsciiString aMsg ("Absolute value of offset can not be less than the tolerance value (");
62       aMsg += TCollection_AsciiString(aTol);
63       aMsg += ")";
64       StdFail_NotDone::Raise(aMsg.ToCString());
65     }
66
67     BRepOffsetAPI_MakeOffsetShape MO (aShapeBase,
68                                       aCI.GetValue(),
69                                       aTol);
70     if (MO.IsDone()) {
71       aShape = MO.Shape();
72     } else {
73       StdFail_NotDone::Raise("Offset construction failed");
74     }
75   } else {
76   }
77
78   if (aShape.IsNull()) return 0;
79
80   aFunction->SetValue(aShape);
81
82   log.SetTouched(Label());
83
84   return 1;
85 }
86
87
88 //=======================================================================
89 //function :  GEOMImpl_OffsetDriver_Type_
90 //purpose  :
91 //=======================================================================
92 Standard_EXPORT Handle_Standard_Type& GEOMImpl_OffsetDriver_Type_()
93 {
94
95   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
96   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
97   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
98   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
99   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
100   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
101
102
103   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
104   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_OffsetDriver",
105                                                          sizeof(GEOMImpl_OffsetDriver),
106                                                          1,
107                                                          (Standard_Address)_Ancestors,
108                                                          (Standard_Address)NULL);
109
110   return _aType;
111 }
112
113 //=======================================================================
114 //function : DownCast
115 //purpose  :
116 //=======================================================================
117 const Handle(GEOMImpl_OffsetDriver) Handle(GEOMImpl_OffsetDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
118 {
119   Handle(GEOMImpl_OffsetDriver) _anOtherObject;
120
121   if (!AnObject.IsNull()) {
122      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_OffsetDriver))) {
123        _anOtherObject = Handle(GEOMImpl_OffsetDriver)((Handle(GEOMImpl_OffsetDriver)&)AnObject);
124      }
125   }
126
127   return _anOtherObject ;
128 }