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