1 // Copyright (C) 2007-2008 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
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_ThruSectionsDriver.hxx>
25 #include <GEOMImpl_IThruSections.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <TColStd_HSequenceOfTransient.hxx>
30 #include <Precision.hxx>
31 #include <BRepCheck_Analyzer.hxx>
32 #include <BRepOffsetAPI_ThruSections.hxx>
33 #include <BRepBuilderAPI_MakeWire.hxx>
34 #include <TopExp_Explorer.hxx>
39 #include <TopoDS_Wire.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Shape.hxx>
43 #include <Standard_NullObject.hxx>
44 #include <Standard_TypeMismatch.hxx>
45 #include <Standard_ConstructionError.hxx>
46 #include <ShapeFix_Shape.hxx>
47 #include <ShapeFix_ShapeTolerance.hxx>
48 #include <Precision.hxx>
49 //=======================================================================
52 //=======================================================================
53 const Standard_GUID& GEOMImpl_ThruSectionsDriver::GetID()
55 static Standard_GUID aThruSectionsDriver("FF1BB971-E99C-4f89-B989-5B48E061049B");
56 return aThruSectionsDriver;
60 //=======================================================================
61 //function : GEOMImpl_ThruSectionsDriver
63 //=======================================================================
64 GEOMImpl_ThruSectionsDriver::GEOMImpl_ThruSectionsDriver()
68 //=======================================================================
71 //=======================================================================
72 Standard_Integer GEOMImpl_ThruSectionsDriver::Execute(TFunction_Logbook& log) const
74 if (Label().IsNull()) return 0;
75 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
77 GEOMImpl_IThruSections aCI (aFunction);
78 Standard_Integer aType = aFunction->GetType();
80 Standard_Boolean isSolid = (aCI.GetSolidMode() == 1);
81 Handle(TColStd_HSequenceOfTransient) aSeqSections = aCI.GetSections();
83 if( aSeqSections.IsNull())
86 Standard_Integer aNbSections = aSeqSections->Length();
87 Standard_Real aPreci = Max(aCI.GetPrecision(),Precision::Confusion());
91 BRepOffsetAPI_ThruSections aBuilder(isSolid,aType ==THRUSECTIONS_RULED,aPreci);
94 aBuilder.CheckCompatibility(Standard_False);
95 //added sections for building surface
96 Standard_Integer i =1;
97 Standard_Integer nbAdded =0;
98 for( ; i <= aNbSections; i++,nbAdded++)
100 Handle(Standard_Transient) anItem = aSeqSections->Value(i);
104 Handle(GEOM_Function) aSection = Handle(GEOM_Function)::DownCast(anItem);
105 if(aSection.IsNull())
108 TopoDS_Shape aShapeSection = aSection->GetValue();
109 TopAbs_ShapeEnum aTypeSect = aShapeSection.ShapeType();
110 if(aTypeSect == TopAbs_WIRE)
111 aBuilder.AddWire(TopoDS::Wire(aShapeSection));
113 else if(aTypeSect == TopAbs_EDGE) {
114 TopoDS_Edge anEdge = TopoDS::Edge(aShapeSection);
115 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge);
116 aBuilder.AddWire(aWire);
118 else if(aTypeSect == TopAbs_VERTEX) {
119 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeSection);
120 aBuilder.AddVertex(aVert);
126 Standard_TypeMismatch::Raise("ThruSections aborted : invalid types of sections");
127 //make surface by sections
129 TopoDS_Shape aShape = aBuilder.Shape();
130 if (aShape.IsNull()) {
134 BRepCheck_Analyzer ana (aShape, Standard_False);
135 if (!ana.IsValid()) {
136 //algoritm thru section creats on the arcs invalid shapes gka
137 ShapeFix_ShapeTolerance aSFT;
138 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
139 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
140 aSfs->SetPrecision(Precision::Confusion());
142 aShape = aSfs->Shape();
143 //ana.Init(aShape, Standard_False);
144 //if (!ana.IsValid())
145 // Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
149 aFunction->SetValue(aShape);
151 log.SetTouched(Label());
157 //=======================================================================
158 //function : GEOMImpl_ThruSectionsDriver_Type_
160 //=======================================================================
161 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ThruSectionsDriver_Type_()
164 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
165 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
166 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
167 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
168 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
169 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
172 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
173 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ThruSectionsDriver",
174 sizeof(GEOMImpl_ThruSectionsDriver),
176 (Standard_Address)_Ancestors,
177 (Standard_Address)NULL);
182 //=======================================================================
183 //function : DownCast
185 //=======================================================================
186 const Handle(GEOMImpl_ThruSectionsDriver) Handle(GEOMImpl_ThruSectionsDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
188 Handle(GEOMImpl_ThruSectionsDriver) _anOtherObject;
190 if (!AnObject.IsNull()) {
191 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ThruSectionsDriver))) {
192 _anOtherObject = Handle(GEOMImpl_ThruSectionsDriver)((Handle(GEOMImpl_ThruSectionsDriver)&)AnObject);
196 return _anOtherObject ;