1 // Copyright (C) 2007-2016 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 <BRepOffsetAPI_MakeThickSolid.hxx>
33 #include <TopoDS_Shape.hxx>
36 #include <BRepClass3d_SolidClassifier.hxx>
37 #include <Precision.hxx>
38 #include <Standard_ConstructionError.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");
51 //=======================================================================
52 //function : GEOMImpl_OffsetDriver
54 //=======================================================================
55 GEOMImpl_OffsetDriver::GEOMImpl_OffsetDriver()
59 //=======================================================================
62 //=======================================================================
63 Standard_Integer GEOMImpl_OffsetDriver::Execute(LOGBOOK& log) const
65 if (Label().IsNull()) return 0;
66 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
68 GEOMImpl_IOffset aCI (aFunction);
69 Standard_Integer aType = aFunction->GetType();
73 Handle(GEOM_Function) aRefShape = aCI.GetShape();
74 TopoDS_Shape aShapeBase = aRefShape->GetValue();
75 Standard_Real anOffset = aCI.GetValue();
76 Standard_Boolean isInside = aCI.GetParam();
77 Standard_Real aTol = Precision::Confusion();
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);
86 StdFail_NotDone::Raise(aMsg.ToCString());
89 if (aType == OFFSET_SHAPE || aType == OFFSET_SHAPE_COPY) {
90 BRepOffsetAPI_MakeOffsetShape MO (aShapeBase,
95 if ( !GEOMUtils::CheckShape(aShape, true) && !GEOMUtils::FixShapeTolerance(aShape) )
96 Standard_ConstructionError::Raise("Boolean operation aborted : non valid shape result");
99 StdFail_NotDone::Raise("Offset construction failed");
102 else if (aType == OFFSET_THICKENING || aType == OFFSET_THICKENING_COPY)
104 const TopAbs_ShapeEnum aType = aShapeBase.ShapeType();
106 if (aType == TopAbs_FACE || aType == TopAbs_SHELL) {
107 // Create a thick solid.
108 BRepClass3d_SolidClassifier aClassifier(aShapeBase);
109 aClassifier.PerformInfinitePoint(Precision::Confusion());
110 if (aClassifier.State()==TopAbs_IN)
112 // If the generated pipe faces normals are oriented towards the inside, the offset is negative
113 // so that the thickening is still towards outside
117 BRepOffset_MakeOffset myOffsetShape(aShapeBase, anOffset, aTol, BRepOffset_Skin,
118 Standard_False, Standard_False, GeomAbs_Intersection, Standard_True);
120 if (!myOffsetShape.IsDone())
122 StdFail_NotDone::Raise("Thickening construction failed");
124 aShape = myOffsetShape.Shape();
126 // Control the solid orientation. This is mostly done to fix a bug in case of extrusion
127 // of a circle. The built solid is then badly oriented
128 BRepClass3d_SolidClassifier anotherClassifier(aShape);
129 anotherClassifier.PerformInfinitePoint(Precision::Confusion());
130 if (anotherClassifier.State()==TopAbs_IN)
134 } else if (aType == TopAbs_SOLID) {
135 // Create a hollowed solid.
136 Handle(TColStd_HArray1OfInteger) aFacesIDs = aCI.GetFaceIDs();
137 TopTools_ListOfShape aFacesToRm;
139 if (aFacesIDs.IsNull()) {
143 TopTools_IndexedMapOfShape anIndices;
145 TopExp::MapShapes(aShapeBase, anIndices);
147 Standard_Integer aNbShapes = anIndices.Extent();
150 for (i = aFacesIDs->Lower(); i <= aFacesIDs->Upper(); ++i) {
151 const Standard_Integer anIndex = aFacesIDs->Value(i);
153 if (anIndex < 1 || anIndex > aNbShapes) {
158 const TopoDS_Shape &aFace = anIndices.FindKey(anIndex);
160 if (aFace.ShapeType() != TopAbs_FACE) {
161 // Shape by index is not a face.
165 aFacesToRm.Append(aFace);
168 // Create a hollowed solid.
169 BRepOffsetAPI_MakeThickSolid aMkSolid
170 (aShapeBase, aFacesToRm, anOffset, aTol, BRepOffset_Skin,
171 Standard_False, Standard_False, GeomAbs_Intersection);
173 if (aMkSolid.IsDone()) {
174 aShape = aMkSolid.Shape();
179 if (aShape.IsNull()) return 0;
181 aFunction->SetValue(aShape);
183 #if OCC_VERSION_MAJOR < 7
184 log.SetTouched(Label());
186 log->SetTouched(Label());
192 //================================================================================
194 * \brief Returns a name of creation operation and names and values of creation parameters
196 //================================================================================
198 bool GEOMImpl_OffsetDriver::
199 GetCreationInformation(std::string& theOperationName,
200 std::vector<GEOM_Param>& theParams)
202 if (Label().IsNull()) return 0;
203 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
205 GEOMImpl_IOffset aCI( function );
206 Standard_Integer aType = function->GetType();
210 case OFFSET_SHAPE_COPY:
211 theOperationName = "OFFSET";
212 AddParam( theParams, "Object", aCI.GetShape() );
213 AddParam( theParams, "Offset", aCI.GetValue() );
215 case OFFSET_THICKENING:
216 case OFFSET_THICKENING_COPY:
217 theOperationName = "THICKNESS";
218 AddParam( theParams, "Object", aCI.GetShape() );
219 AddParam( theParams, "Offset", aCI.GetParam() ? -aCI.GetValue() : aCI.GetValue() );
221 Handle(TColStd_HArray1OfInteger) aFacesIDs = aCI.GetFaceIDs();
223 if (aFacesIDs.IsNull() == Standard_False) {
224 AddParam(theParams, "Faces IDs", aFacesIDs);
235 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_OffsetDriver,GEOM_BaseDriver);