Salome HOME
db84973912106b76e3b243d27d2855b676390366
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Loft.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "FeaturesPlugin_Loft.h"
21 #include "FeaturesPlugin_Tools.h"
22
23 #include <ModelAPI_AttributeSelection.h>
24
25 #include <GeomAlgoAPI_Copy.h>
26 #include <GeomAlgoAPI_Filling.h>
27 #include <GeomAlgoAPI_ShapeTools.h>
28 #include <GeomAlgoAPI_Tools.h>
29 #include <GeomAPI_Pnt.h>
30 #include <GeomAPI_ShapeExplorer.h>
31
32 #include <cmath>
33
34 //==================================================================================================
35 FeaturesPlugin_Loft::FeaturesPlugin_Loft()
36 {
37 }
38
39 //==================================================================================================
40 void FeaturesPlugin_Loft::initAttributes()
41 {
42   data()->addAttribute(FIRST_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
43   data()->addAttribute(SECOND_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
44 }
45
46 //==================================================================================================
47 void FeaturesPlugin_Loft::execute()
48 {
49   AttributeSelectionPtr aFirstSelection = selection(FIRST_OBJECT_ID());
50   AttributeSelectionPtr aSecondelection = selection(SECOND_OBJECT_ID());
51
52   if (aFirstSelection->isInitialized() && aSecondelection->isInitialized()) {
53
54     GeomShapePtr aFirstShape, aSecondShape;
55
56     if (aFirstSelection && aSecondelection) {
57       aFirstShape = aFirstSelection->value();
58       if (!aFirstShape && aFirstSelection->context())
59         aFirstShape = aFirstSelection->context()->shape();
60
61       aSecondShape = aSecondelection->value();
62       if (!aSecondShape && aSecondelection->context())
63         aSecondShape = aSecondelection->context()->shape();
64     }
65
66     std::string anError;
67     std::shared_ptr<GeomAlgoAPI_Loft> aLoftAlgo(new GeomAlgoAPI_Loft(aFirstShape, aSecondShape));
68
69     if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aLoftAlgo, getKind(), anError)) {
70       setError(anError);
71       return;
72     }
73     ListOfShape  theBoundaryShapes;
74     theBoundaryShapes.push_back(aFirstShape);
75     theBoundaryShapes.push_back(aSecondShape);
76
77     // Create result body.
78     ResultBodyPtr aResultBody = document()->createBody(data());
79
80     aResultBody->store(aLoftAlgo->shape());
81     // store Faces
82     for(GeomAPI_ShapeExplorer anExp(aLoftAlgo->shape(), GeomAPI_Shape::FACE);
83                               anExp.more(); anExp.next()) {
84       GeomShapePtr anEdge = anExp.current();
85       aResultBody->generated(anEdge, "Loft_Face");
86     }
87     setResult(aResultBody, 0);
88   }
89 }