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 <GEOMImpl_ThruSectionsDriver.hxx>
24 #include <GEOMImpl_IThruSections.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27 #include <GEOMUtils.hxx>
29 #include <TColStd_HSequenceOfTransient.hxx>
30 #include <Precision.hxx>
31 #include <BRepOffsetAPI_ThruSections.hxx>
32 #include <BRepBuilderAPI_MakeWire.hxx>
37 #include <TopoDS_Wire.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Shape.hxx>
41 #include <Standard_TypeMismatch.hxx>
42 #include <Standard_ConstructionError.hxx>
44 //=======================================================================
47 //=======================================================================
48 const Standard_GUID& GEOMImpl_ThruSectionsDriver::GetID()
50 static Standard_GUID aThruSectionsDriver("FF1BB971-E99C-4f89-B989-5B48E061049B");
51 return aThruSectionsDriver;
55 //=======================================================================
56 //function : GEOMImpl_ThruSectionsDriver
58 //=======================================================================
59 GEOMImpl_ThruSectionsDriver::GEOMImpl_ThruSectionsDriver()
63 //=======================================================================
66 //=======================================================================
67 Standard_Integer GEOMImpl_ThruSectionsDriver::Execute(LOGBOOK& log) const
69 if (Label().IsNull()) return 0;
70 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
72 GEOMImpl_IThruSections aCI (aFunction);
73 Standard_Integer aType = aFunction->GetType();
75 Standard_Boolean isSolid = (aCI.GetSolidMode() == 1);
76 Handle(TColStd_HSequenceOfTransient) aSeqSections = aCI.GetSections();
78 if( aSeqSections.IsNull())
81 Standard_Integer aNbSections = aSeqSections->Length();
82 Standard_Real aPreci = Max(aCI.GetPrecision(),Precision::Confusion());
86 BRepOffsetAPI_ThruSections aBuilder(isSolid,aType ==THRUSECTIONS_RULED,aPreci);
89 aBuilder.CheckCompatibility(Standard_False);
90 //added sections for building surface
91 Standard_Integer i =1;
92 Standard_Integer nbAdded =0;
93 for( ; i <= aNbSections; i++,nbAdded++)
95 Handle(Standard_Transient) anItem = aSeqSections->Value(i);
99 Handle(GEOM_Function) aSection = Handle(GEOM_Function)::DownCast(anItem);
100 if(aSection.IsNull())
103 TopoDS_Shape aShapeSection = aSection->GetValue();
104 TopAbs_ShapeEnum aTypeSect = aShapeSection.ShapeType();
105 if(aTypeSect == TopAbs_WIRE)
106 aBuilder.AddWire(TopoDS::Wire(aShapeSection));
108 else if(aTypeSect == TopAbs_EDGE) {
109 TopoDS_Edge anEdge = TopoDS::Edge(aShapeSection);
110 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge);
111 aBuilder.AddWire(aWire);
113 else if(aTypeSect == TopAbs_VERTEX) {
114 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeSection);
115 aBuilder.AddVertex(aVert);
121 Standard_TypeMismatch::Raise("ThruSections aborted : invalid types of sections");
122 //make surface by sections
124 TopoDS_Shape aShape = aBuilder.Shape();
125 if (aShape.IsNull()) {
129 if ( !GEOMUtils::CheckShape(aShape) && !GEOMUtils::FixShapeTolerance(aShape) ) {
130 //algoritm thru section creats on the arcs invalid shapes gka
131 // Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
134 aFunction->SetValue(aShape);
136 #if OCC_VERSION_MAJOR < 7
137 log.SetTouched(Label());
139 log->SetTouched(Label());
145 //================================================================================
147 * \brief Returns a name of creation operation and names and values of creation parameters
149 //================================================================================
151 bool GEOMImpl_ThruSectionsDriver::
152 GetCreationInformation(std::string& theOperationName,
153 std::vector<GEOM_Param>& theParams)
155 if (Label().IsNull()) return 0;
156 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
158 GEOMImpl_IThruSections aCI( function );
159 Standard_Integer aType = function->GetType();
161 theOperationName = "MakeThruSections";
164 case THRUSECTIONS_RULED:
165 case THRUSECTIONS_SMOOTHED:
166 AddParam( theParams, "Sections", aCI.GetSections() );
167 AddParam( theParams, "Is solid", aCI.GetSolidMode() );
168 AddParam( theParams, "Precision", aCI.GetPrecision() );
169 AddParam( theParams, "Is ruled", aType == THRUSECTIONS_RULED );
178 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ThruSectionsDriver,GEOM_BaseDriver);