1 // Copyright (C) 2014-2023 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GeomAlgoAPI_DFLoader.h"
21 #include "GeomAlgoAPI_Loft.h"
22 #include "GeomAlgoAPI_WireBuilder.h"
24 #include <BRepOffsetAPI_ThruSections.hxx>
25 #include <Precision.hxx>
26 #include <TopExp_Explorer.hxx>
29 //==================================================================================================
30 GeomAlgoAPI_Loft::GeomAlgoAPI_Loft(const GeomShapePtr theFirstShape, const GeomShapePtr theSecondShape)
32 build(theFirstShape, theSecondShape);
35 //==================================================================================================
36 void GeomAlgoAPI_Loft::build(const GeomShapePtr theFirstShape,
37 const GeomShapePtr theSecondShape)
39 // Getting base shape.
40 if(!theFirstShape.get() || !theSecondShape.get()) {
43 TopoDS_Shape aFirstShape = theFirstShape->impl<TopoDS_Shape>();
44 if(aFirstShape.IsNull()) {
47 TopoDS_Shape aSecondShape= theSecondShape->impl<TopoDS_Shape>();
48 if(aSecondShape.IsNull()) {
52 bool anIsSolid = false;
54 TopoDS_Shape aFirstShapeOut;
55 TopoDS_Shape aSecondShapeOut;
56 if (aFirstShape.ShapeType() == TopAbs_FACE) {
57 TopExp_Explorer anExp(aFirstShape, TopAbs_WIRE);
58 aFirstShapeOut = anExp.Current();
59 TopExp_Explorer anExp2(aSecondShape, TopAbs_WIRE);
60 aSecondShapeOut = anExp2.Current();
64 if (aFirstShape.ShapeType() == TopAbs_WIRE) {
65 aFirstShapeOut = aFirstShape;
66 aSecondShapeOut = aSecondShape;
69 if (aFirstShape.ShapeType() == TopAbs_EDGE)
71 GeomShapePtr aFirstWire, aSecondWire;
72 ListOfShape aFirstEdge, aSecondEdge;
74 // Convert first edge to wire
75 aFirstEdge.push_back(theFirstShape);
76 aFirstWire = GeomAlgoAPI_WireBuilder::wire(aFirstEdge);
77 TopoDS_Shape aFirstShape = aFirstWire->impl<TopoDS_Shape>();
79 // Convert first edge to wire
80 aSecondEdge.push_back(theSecondShape);
81 aSecondWire = GeomAlgoAPI_WireBuilder::wire(aSecondEdge);
82 TopoDS_Shape aSecondShape = aSecondWire->impl<TopoDS_Shape>();
84 aFirstShapeOut = aFirstShape;
85 aSecondShapeOut = aSecondShape;
88 // Initialize and build
89 BRepOffsetAPI_ThruSections * ThruSections =
90 new BRepOffsetAPI_ThruSections(anIsSolid);
91 ThruSections->AddWire( TopoDS::Wire( aFirstShapeOut ) );
92 ThruSections->AddWire( TopoDS::Wire( aSecondShapeOut) );
96 ThruSections->Build();
98 catch (Standard_Failure& aFail)
104 if(!ThruSections->IsDone() || ThruSections->Shape().IsNull()) {
109 this->initialize(ThruSections);
112 TopoDS_Shape aResult = ThruSections->Shape();
113 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
114 GeomShapePtr aGeomSh(new GeomAPI_Shape());
115 aGeomSh->setImpl(new TopoDS_Shape(aResult));
116 this->setShape(aGeomSh);