1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_OffsetDriver.hxx>
26 #include <GEOMImpl_IOffset.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
31 #include <BRep_Tool.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Vertex.hxx>
38 #include <BRepClass3d_SolidClassifier.hxx>
40 #include <Precision.hxx>
43 #include <BRepCheck_Analyzer.hxx>
44 #include <ShapeFix_ShapeTolerance.hxx>
45 #include <ShapeFix_Shape.hxx>
47 #include <Standard_ConstructionError.hxx>
48 #include <StdFail_NotDone.hxx>
50 #include "utilities.h"
52 //=======================================================================
55 //=======================================================================
56 const Standard_GUID& GEOMImpl_OffsetDriver::GetID()
58 static Standard_GUID aOffsetDriver("FF1BBB51-5D14-4df2-980B-3A668264EA16");
63 //=======================================================================
64 //function : GEOMImpl_OffsetDriver
66 //=======================================================================
67 GEOMImpl_OffsetDriver::GEOMImpl_OffsetDriver()
71 //=======================================================================
74 //=======================================================================
75 Standard_Integer GEOMImpl_OffsetDriver::Execute(TFunction_Logbook& log) const
77 if (Label().IsNull()) return 0;
78 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
80 GEOMImpl_IOffset aCI (aFunction);
81 Standard_Integer aType = aFunction->GetType();
85 Handle(GEOM_Function) aRefShape = aCI.GetShape();
86 TopoDS_Shape aShapeBase = aRefShape->GetValue();
87 Standard_Real anOffset = aCI.GetValue();
88 Standard_Real aTol = Precision::Confusion();
90 if (Abs(anOffset) < aTol) {
91 TCollection_AsciiString aMsg ("Absolute value of offset can not be less than the tolerance value (");
92 aMsg += TCollection_AsciiString(aTol);
94 StdFail_NotDone::Raise(aMsg.ToCString());
97 if (aType == OFFSET_SHAPE || aType == OFFSET_SHAPE_COPY) {
98 BRepOffsetAPI_MakeOffsetShape MO (aShapeBase,
103 // 23.04.2010 skl for bug 21699 from Mantis
104 BRepCheck_Analyzer ana (aShape, Standard_True);
106 if (!ana.IsValid()) {
107 ShapeFix_ShapeTolerance aSFT;
108 aSFT.LimitTolerance(aShape, Precision::Confusion(),
109 Precision::Confusion(), TopAbs_SHAPE);
110 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
112 aShape = aSfs->Shape();
115 Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
119 StdFail_NotDone::Raise("Offset construction failed");
122 else if (aType == OFFSET_THICKENING || aType == OFFSET_THICKENING_COPY)
124 BRepClass3d_SolidClassifier aClassifier = BRepClass3d_SolidClassifier(aShapeBase);
125 aClassifier.PerformInfinitePoint(Precision::Confusion());
126 if (aClassifier.State()==TopAbs_IN)
128 // If the generated pipe faces normals are oriented towards the inside, the offset is negative
129 // so that the thickening is still towards outside
133 BRepOffset_MakeOffset myOffsetShape(aShapeBase, anOffset, aTol, BRepOffset_Skin,
134 Standard_False, Standard_False, GeomAbs_Intersection, Standard_True);
136 if (!myOffsetShape.IsDone())
138 StdFail_NotDone::Raise("Thickening construction failed");
140 aShape = myOffsetShape.Shape();
142 // Control the solid orientation. This is mostly done to fix a bug in case of extrusion
143 // of a circle. The built solid is then badly oriented
144 BRepClass3d_SolidClassifier anotherClassifier = BRepClass3d_SolidClassifier(aShape);
145 anotherClassifier.PerformInfinitePoint(Precision::Confusion());
146 if (anotherClassifier.State()==TopAbs_IN)
152 if (aShape.IsNull()) return 0;
154 aFunction->SetValue(aShape);
156 log.SetTouched(Label());
161 //================================================================================
163 * \brief Returns a name of creation operation and names and values of creation parameters
165 //================================================================================
167 bool GEOMImpl_OffsetDriver::
168 GetCreationInformation(std::string& theOperationName,
169 std::vector<GEOM_Param>& theParams)
171 if (Label().IsNull()) return 0;
172 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
174 GEOMImpl_IOffset aCI( function );
175 Standard_Integer aType = function->GetType();
179 case OFFSET_SHAPE_COPY:
180 theOperationName = "OFFSET";
181 AddParam( theParams, "Object", aCI.GetShape() );
182 AddParam( theParams, "Offset", aCI.GetValue() );
184 case OFFSET_THICKENING:
185 case OFFSET_THICKENING_COPY:
186 theOperationName = "MakeThickening";
187 AddParam( theParams, "Object", aCI.GetShape() );
188 AddParam( theParams, "Offset", aCI.GetValue() );
197 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_OffsetDriver,GEOM_BaseDriver);
198 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_OffsetDriver,GEOM_BaseDriver);