1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,F
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_ThruSectionsDriver.hxx>
24 #include <GEOMImpl_IThruSections.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <TColStd_HSequenceOfTransient.hxx>
29 #include <Precision.hxx>
30 #include <BRepCheck_Analyzer.hxx>
31 #include <BRepOffsetAPI_ThruSections.hxx>
32 #include <BRepBuilderAPI_MakeWire.hxx>
33 #include <TopExp_Explorer.hxx>
38 #include <TopoDS_Wire.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Shape.hxx>
42 #include <Standard_NullObject.hxx>
43 #include <Standard_TypeMismatch.hxx>
44 #include <Standard_ConstructionError.hxx>
45 #include <ShapeFix_Shape.hxx>
46 #include <ShapeFix_ShapeTolerance.hxx>
47 #include <Precision.hxx>
48 //=======================================================================
51 //=======================================================================
52 const Standard_GUID& GEOMImpl_ThruSectionsDriver::GetID()
54 static Standard_GUID aThruSectionsDriver("FF1BB971-E99C-4f89-B989-5B48E061049B");
55 return aThruSectionsDriver;
59 //=======================================================================
60 //function : GEOMImpl_ThruSectionsDriver
62 //=======================================================================
63 GEOMImpl_ThruSectionsDriver::GEOMImpl_ThruSectionsDriver()
67 //=======================================================================
70 //=======================================================================
71 Standard_Integer GEOMImpl_ThruSectionsDriver::Execute(TFunction_Logbook& log) const
73 if (Label().IsNull()) return 0;
74 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
76 GEOMImpl_IThruSections aCI (aFunction);
77 Standard_Integer aType = aFunction->GetType();
79 Standard_Boolean isSolid = (aCI.GetSolidMode() == 1);
80 Handle(TColStd_HSequenceOfTransient) aSeqSections = aCI.GetSections();
82 if( aSeqSections.IsNull())
85 Standard_Integer aNbSections = aSeqSections->Length();
86 Standard_Real aPreci = Max(aCI.GetPrecision(),Precision::Confusion());
90 BRepOffsetAPI_ThruSections aBuilder(isSolid,aType ==THRUSECTIONS_RULED,aPreci);
93 aBuilder.CheckCompatibility(Standard_False);
94 //added sections for building surface
95 Standard_Integer i =1;
96 Standard_Integer nbAdded =0;
97 for( ; i <= aNbSections; i++,nbAdded++)
99 Handle(Standard_Transient) anItem = aSeqSections->Value(i);
103 Handle(GEOM_Function) aSection = Handle(GEOM_Function)::DownCast(anItem);
104 if(aSection.IsNull())
107 TopoDS_Shape aShapeSection = aSection->GetValue();
108 TopAbs_ShapeEnum aTypeSect = aShapeSection.ShapeType();
109 if(aTypeSect == TopAbs_WIRE)
110 aBuilder.AddWire(TopoDS::Wire(aShapeSection));
112 else if(aTypeSect == TopAbs_EDGE) {
113 TopoDS_Edge anEdge = TopoDS::Edge(aShapeSection);
114 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge);
115 aBuilder.AddWire(aWire);
117 else if(aTypeSect == TopAbs_VERTEX) {
118 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeSection);
119 aBuilder.AddVertex(aVert);
125 Standard_TypeMismatch::Raise("ThruSections aborted : invalid types of sections");
126 //make surface by sections
128 TopoDS_Shape aShape = aBuilder.Shape();
129 if (aShape.IsNull()) {
133 BRepCheck_Analyzer ana (aShape, Standard_False);
134 if (!ana.IsValid()) {
135 //algoritm thru section creats on the arcs invalid shapes gka
136 ShapeFix_ShapeTolerance aSFT;
137 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
138 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
139 aSfs->SetPrecision(Precision::Confusion());
141 aShape = aSfs->Shape();
142 //ana.Init(aShape, Standard_False);
143 //if (!ana.IsValid())
144 // Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
148 aFunction->SetValue(aShape);
150 log.SetTouched(Label());
156 //=======================================================================
157 //function : GEOMImpl_ThruSectionsDriver_Type_
159 //=======================================================================
160 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ThruSectionsDriver_Type_()
163 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
164 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
165 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
166 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
167 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
168 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
171 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
172 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ThruSectionsDriver",
173 sizeof(GEOMImpl_ThruSectionsDriver),
175 (Standard_Address)_Ancestors,
176 (Standard_Address)NULL);
181 //=======================================================================
182 //function : DownCast
184 //=======================================================================
185 const Handle(GEOMImpl_ThruSectionsDriver) Handle(GEOMImpl_ThruSectionsDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
187 Handle(GEOMImpl_ThruSectionsDriver) _anOtherObject;
189 if (!AnObject.IsNull()) {
190 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ThruSectionsDriver))) {
191 _anOtherObject = Handle(GEOMImpl_ThruSectionsDriver)((Handle(GEOMImpl_ThruSectionsDriver)&)AnObject);
195 return _anOtherObject ;