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