1 // Copyright (C) 2007-2015 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>
29 #include <GEOMUtils.hxx>
31 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
32 #include <TopoDS_Shape.hxx>
34 #include <BRepClass3d_SolidClassifier.hxx>
35 #include <Precision.hxx>
36 #include <Standard_ConstructionError.hxx>
37 #include <StdFail_NotDone.hxx>
39 //=======================================================================
42 //=======================================================================
43 const Standard_GUID& GEOMImpl_OffsetDriver::GetID()
45 static Standard_GUID aOffsetDriver("FF1BBB51-5D14-4df2-980B-3A668264EA16");
49 //=======================================================================
50 //function : GEOMImpl_OffsetDriver
52 //=======================================================================
53 GEOMImpl_OffsetDriver::GEOMImpl_OffsetDriver()
57 //=======================================================================
60 //=======================================================================
61 Standard_Integer GEOMImpl_OffsetDriver::Execute(TFunction_Logbook& log) const
63 if (Label().IsNull()) return 0;
64 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
66 GEOMImpl_IOffset aCI (aFunction);
67 Standard_Integer aType = aFunction->GetType();
71 Handle(GEOM_Function) aRefShape = aCI.GetShape();
72 TopoDS_Shape aShapeBase = aRefShape->GetValue();
73 Standard_Real anOffset = aCI.GetValue();
74 Standard_Real aTol = Precision::Confusion();
76 if (Abs(anOffset) < aTol) {
77 TCollection_AsciiString aMsg ("Absolute value of offset can not be less than the tolerance value (");
78 aMsg += TCollection_AsciiString(aTol);
80 StdFail_NotDone::Raise(aMsg.ToCString());
83 if (aType == OFFSET_SHAPE || aType == OFFSET_SHAPE_COPY) {
84 BRepOffsetAPI_MakeOffsetShape MO (aShapeBase,
89 if ( !GEOMUtils::CheckShape(aShape, true) && !GEOMUtils::FixShapeTolerance(aShape) )
90 Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
93 StdFail_NotDone::Raise("Offset construction failed");
96 else if (aType == OFFSET_THICKENING || aType == OFFSET_THICKENING_COPY)
98 BRepClass3d_SolidClassifier aClassifier = BRepClass3d_SolidClassifier(aShapeBase);
99 aClassifier.PerformInfinitePoint(Precision::Confusion());
100 if (aClassifier.State()==TopAbs_IN)
102 // If the generated pipe faces normals are oriented towards the inside, the offset is negative
103 // so that the thickening is still towards outside
107 BRepOffset_MakeOffset myOffsetShape(aShapeBase, anOffset, aTol, BRepOffset_Skin,
108 Standard_False, Standard_False, GeomAbs_Intersection, Standard_True);
110 if (!myOffsetShape.IsDone())
112 StdFail_NotDone::Raise("Thickening construction failed");
114 aShape = myOffsetShape.Shape();
116 // Control the solid orientation. This is mostly done to fix a bug in case of extrusion
117 // of a circle. The built solid is then badly oriented
118 BRepClass3d_SolidClassifier anotherClassifier = BRepClass3d_SolidClassifier(aShape);
119 anotherClassifier.PerformInfinitePoint(Precision::Confusion());
120 if (anotherClassifier.State()==TopAbs_IN)
126 if (aShape.IsNull()) return 0;
128 aFunction->SetValue(aShape);
130 log.SetTouched(Label());
135 //================================================================================
137 * \brief Returns a name of creation operation and names and values of creation parameters
139 //================================================================================
141 bool GEOMImpl_OffsetDriver::
142 GetCreationInformation(std::string& theOperationName,
143 std::vector<GEOM_Param>& theParams)
145 if (Label().IsNull()) return 0;
146 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
148 GEOMImpl_IOffset aCI( function );
149 Standard_Integer aType = function->GetType();
153 case OFFSET_SHAPE_COPY:
154 theOperationName = "OFFSET";
155 AddParam( theParams, "Object", aCI.GetShape() );
156 AddParam( theParams, "Offset", aCI.GetValue() );
158 case OFFSET_THICKENING:
159 case OFFSET_THICKENING_COPY:
160 theOperationName = "MakeThickening";
161 AddParam( theParams, "Object", aCI.GetShape() );
162 AddParam( theParams, "Offset", aCI.GetValue() );
171 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_OffsetDriver,GEOM_BaseDriver);
172 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_OffsetDriver,GEOM_BaseDriver);