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