1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_OffsetDriver.hxx>
24 #include <GEOMImpl_IOffset.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
29 #include <BRep_Tool.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
36 #include <Precision.hxx>
39 #include <StdFail_NotDone.hxx>
41 //=======================================================================
44 //=======================================================================
45 const Standard_GUID& GEOMImpl_OffsetDriver::GetID()
47 static Standard_GUID aOffsetDriver("FF1BBB51-5D14-4df2-980B-3A668264EA16");
52 //=======================================================================
53 //function : GEOMImpl_OffsetDriver
55 //=======================================================================
56 GEOMImpl_OffsetDriver::GEOMImpl_OffsetDriver()
60 //=======================================================================
63 //=======================================================================
64 Standard_Integer GEOMImpl_OffsetDriver::Execute(TFunction_Logbook& log) const
66 if (Label().IsNull()) return 0;
67 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
69 GEOMImpl_IOffset aCI (aFunction);
70 Standard_Integer aType = aFunction->GetType();
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();
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);
84 StdFail_NotDone::Raise(aMsg.ToCString());
87 BRepOffsetAPI_MakeOffsetShape MO (aShapeBase,
93 StdFail_NotDone::Raise("Offset construction failed");
98 if (aShape.IsNull()) return 0;
100 aFunction->SetValue(aShape);
102 log.SetTouched(Label());
108 //=======================================================================
109 //function : GEOMImpl_OffsetDriver_Type_
111 //=======================================================================
112 Standard_EXPORT Handle_Standard_Type& GEOMImpl_OffsetDriver_Type_()
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);
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),
127 (Standard_Address)_Ancestors,
128 (Standard_Address)NULL);
133 //=======================================================================
134 //function : DownCast
136 //=======================================================================
137 const Handle(GEOMImpl_OffsetDriver) Handle(GEOMImpl_OffsetDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
139 Handle(GEOMImpl_OffsetDriver) _anOtherObject;
141 if (!AnObject.IsNull()) {
142 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_OffsetDriver))) {
143 _anOtherObject = Handle(GEOMImpl_OffsetDriver)((Handle(GEOMImpl_OffsetDriver)&)AnObject);
147 return _anOtherObject ;