Salome HOME
ff68f7e8d6908cf3fa1c058302d55a37009f6efc
[modules/geom.git] / src / GEOMImpl / GEOMImpl_OffsetDriver.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <Standard_Stream.hxx>
23
24 #include <GEOMImpl_OffsetDriver.hxx>
25 #include <GEOMImpl_IOffset.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
28
29 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
30 #include <BRep_Tool.hxx>
31 #include <TopoDS.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <TopAbs.hxx>
35 #include <TopExp.hxx>
36
37 #include <Precision.hxx>
38 #include <gp_Pnt.hxx>
39
40 #include <StdFail_NotDone.hxx>
41
42 //=======================================================================
43 //function : GetID
44 //purpose  :
45 //=======================================================================
46 const Standard_GUID& GEOMImpl_OffsetDriver::GetID()
47 {
48   static Standard_GUID aOffsetDriver("FF1BBB51-5D14-4df2-980B-3A668264EA16");
49   return aOffsetDriver;
50 }
51
52
53 //=======================================================================
54 //function : GEOMImpl_OffsetDriver
55 //purpose  :
56 //=======================================================================
57 GEOMImpl_OffsetDriver::GEOMImpl_OffsetDriver()
58 {
59 }
60
61 //=======================================================================
62 //function : Execute
63 //purpose  :
64 //=======================================================================
65 Standard_Integer GEOMImpl_OffsetDriver::Execute(TFunction_Logbook& log) const
66 {
67   if (Label().IsNull()) return 0;
68   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
69
70   GEOMImpl_IOffset aCI (aFunction);
71   Standard_Integer aType = aFunction->GetType();
72
73   TopoDS_Shape aShape;
74
75   if (aType == OFFSET_SHAPE || aType == OFFSET_SHAPE_COPY) {
76     Handle(GEOM_Function) aRefShape = aCI.GetShape();
77     TopoDS_Shape aShapeBase = aRefShape->GetValue();
78     Standard_Real anOffset = aCI.GetValue();
79     Standard_Real aTol = Precision::Confusion();
80
81     if (Abs(anOffset) < aTol) {
82       TCollection_AsciiString aMsg ("Absolute value of offset can not be less than the tolerance value (");
83       aMsg += TCollection_AsciiString(aTol);
84       aMsg += ")";
85       StdFail_NotDone::Raise(aMsg.ToCString());
86     }
87
88     BRepOffsetAPI_MakeOffsetShape MO (aShapeBase,
89                                       aCI.GetValue(),
90                                       aTol);
91     if (MO.IsDone()) {
92       aShape = MO.Shape();
93     } else {
94       StdFail_NotDone::Raise("Offset construction failed");
95     }
96   } else {
97   }
98
99   if (aShape.IsNull()) return 0;
100
101   aFunction->SetValue(aShape);
102
103   log.SetTouched(Label());
104
105   return 1;
106 }
107
108
109 //=======================================================================
110 //function :  GEOMImpl_OffsetDriver_Type_
111 //purpose  :
112 //=======================================================================
113 Standard_EXPORT Handle_Standard_Type& GEOMImpl_OffsetDriver_Type_()
114 {
115
116   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
117   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
118   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
119   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
120   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
121   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
122
123
124   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
125   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_OffsetDriver",
126                                                          sizeof(GEOMImpl_OffsetDriver),
127                                                          1,
128                                                          (Standard_Address)_Ancestors,
129                                                          (Standard_Address)NULL);
130
131   return _aType;
132 }
133
134 //=======================================================================
135 //function : DownCast
136 //purpose  :
137 //=======================================================================
138 const Handle(GEOMImpl_OffsetDriver) Handle(GEOMImpl_OffsetDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
139 {
140   Handle(GEOMImpl_OffsetDriver) _anOtherObject;
141
142   if (!AnObject.IsNull()) {
143      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_OffsetDriver))) {
144        _anOtherObject = Handle(GEOMImpl_OffsetDriver)((Handle(GEOMImpl_OffsetDriver)&)AnObject);
145      }
146   }
147
148   return _anOtherObject ;
149 }