1 // Copyright (C) 2007-2011 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.
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_ThruSectionsDriver.hxx>
26 #include <GEOMImpl_IThruSections.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <TColStd_HSequenceOfTransient.hxx>
31 #include <Precision.hxx>
32 #include <BRepCheck_Analyzer.hxx>
33 #include <BRepOffsetAPI_ThruSections.hxx>
34 #include <BRepBuilderAPI_MakeWire.hxx>
35 #include <TopExp_Explorer.hxx>
40 #include <TopoDS_Wire.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Shape.hxx>
44 #include <Standard_NullObject.hxx>
45 #include <Standard_TypeMismatch.hxx>
46 #include <Standard_ConstructionError.hxx>
47 #include <ShapeFix_Shape.hxx>
48 #include <ShapeFix_ShapeTolerance.hxx>
49 #include <Precision.hxx>
50 //=======================================================================
53 //=======================================================================
54 const Standard_GUID& GEOMImpl_ThruSectionsDriver::GetID()
56 static Standard_GUID aThruSectionsDriver("FF1BB971-E99C-4f89-B989-5B48E061049B");
57 return aThruSectionsDriver;
61 //=======================================================================
62 //function : GEOMImpl_ThruSectionsDriver
64 //=======================================================================
65 GEOMImpl_ThruSectionsDriver::GEOMImpl_ThruSectionsDriver()
69 //=======================================================================
72 //=======================================================================
73 Standard_Integer GEOMImpl_ThruSectionsDriver::Execute(TFunction_Logbook& log) const
75 if (Label().IsNull()) return 0;
76 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
78 GEOMImpl_IThruSections aCI (aFunction);
79 Standard_Integer aType = aFunction->GetType();
81 Standard_Boolean isSolid = (aCI.GetSolidMode() == 1);
82 Handle(TColStd_HSequenceOfTransient) aSeqSections = aCI.GetSections();
84 if( aSeqSections.IsNull())
87 Standard_Integer aNbSections = aSeqSections->Length();
88 Standard_Real aPreci = Max(aCI.GetPrecision(),Precision::Confusion());
92 BRepOffsetAPI_ThruSections aBuilder(isSolid,aType ==THRUSECTIONS_RULED,aPreci);
95 aBuilder.CheckCompatibility(Standard_False);
96 //added sections for building surface
97 Standard_Integer i =1;
98 Standard_Integer nbAdded =0;
99 for( ; i <= aNbSections; i++,nbAdded++)
101 Handle(Standard_Transient) anItem = aSeqSections->Value(i);
105 Handle(GEOM_Function) aSection = Handle(GEOM_Function)::DownCast(anItem);
106 if(aSection.IsNull())
109 TopoDS_Shape aShapeSection = aSection->GetValue();
110 TopAbs_ShapeEnum aTypeSect = aShapeSection.ShapeType();
111 if(aTypeSect == TopAbs_WIRE)
112 aBuilder.AddWire(TopoDS::Wire(aShapeSection));
114 else if(aTypeSect == TopAbs_EDGE) {
115 TopoDS_Edge anEdge = TopoDS::Edge(aShapeSection);
116 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge);
117 aBuilder.AddWire(aWire);
119 else if(aTypeSect == TopAbs_VERTEX) {
120 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeSection);
121 aBuilder.AddVertex(aVert);
127 Standard_TypeMismatch::Raise("ThruSections aborted : invalid types of sections");
128 //make surface by sections
130 TopoDS_Shape aShape = aBuilder.Shape();
131 if (aShape.IsNull()) {
135 BRepCheck_Analyzer ana (aShape, Standard_False);
136 if (!ana.IsValid()) {
137 //algoritm thru section creats on the arcs invalid shapes gka
138 ShapeFix_ShapeTolerance aSFT;
139 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
140 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
141 aSfs->SetPrecision(Precision::Confusion());
143 aShape = aSfs->Shape();
144 //ana.Init(aShape, Standard_False);
145 //if (!ana.IsValid())
146 // Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
150 aFunction->SetValue(aShape);
152 log.SetTouched(Label());
158 //=======================================================================
159 //function : GEOMImpl_ThruSectionsDriver_Type_
161 //=======================================================================
162 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ThruSectionsDriver_Type_()
165 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
166 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
167 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
168 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
169 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
170 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
173 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
174 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ThruSectionsDriver",
175 sizeof(GEOMImpl_ThruSectionsDriver),
177 (Standard_Address)_Ancestors,
178 (Standard_Address)NULL);
183 //=======================================================================
184 //function : DownCast
186 //=======================================================================
187 const Handle(GEOMImpl_ThruSectionsDriver) Handle(GEOMImpl_ThruSectionsDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
189 Handle(GEOMImpl_ThruSectionsDriver) _anOtherObject;
191 if (!AnObject.IsNull()) {
192 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ThruSectionsDriver))) {
193 _anOtherObject = Handle(GEOMImpl_ThruSectionsDriver)((Handle(GEOMImpl_ThruSectionsDriver)&)AnObject);
197 return _anOtherObject ;