Salome HOME
Copyright update 2022
[modules/shaper.git] / src / GDMLPlugin / GDMLPlugin_ConeSegment.cpp
1 // Copyright (C) 2014-2022  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 <GDMLPlugin_ConeSegment.h>
21
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_ResultBody.h>
24 #include <ModelAPI_AttributeDouble.h>
25
26 //=================================================================================================
27 GDMLPlugin_ConeSegment::GDMLPlugin_ConeSegment() // Nothing to do during instantiation
28 {
29 }
30
31 //=================================================================================================
32 void GDMLPlugin_ConeSegment::initAttributes()
33 {
34   data()->addAttribute(GDMLPlugin_ConeSegment::RMIN1_ID(), ModelAPI_AttributeDouble::typeId());
35   data()->addAttribute(GDMLPlugin_ConeSegment::RMAX1_ID(), ModelAPI_AttributeDouble::typeId());
36   data()->addAttribute(GDMLPlugin_ConeSegment::RMIN2_ID(), ModelAPI_AttributeDouble::typeId());
37   data()->addAttribute(GDMLPlugin_ConeSegment::RMAX2_ID(), ModelAPI_AttributeDouble::typeId());
38   data()->addAttribute(GDMLPlugin_ConeSegment::Z_ID(), ModelAPI_AttributeDouble::typeId());
39   data()->addAttribute(GDMLPlugin_ConeSegment::STARTPHI_ID(), ModelAPI_AttributeDouble::typeId());
40   data()->addAttribute(GDMLPlugin_ConeSegment::DELTAPHI_ID(), ModelAPI_AttributeDouble::typeId());
41 }
42
43 //=================================================================================================
44 void GDMLPlugin_ConeSegment::execute()
45 {
46   double aRMin1 = real(GDMLPlugin_ConeSegment::RMIN1_ID())->value();
47   double aRMax1 = real(GDMLPlugin_ConeSegment::RMAX1_ID())->value();
48   double aRMin2 = real(GDMLPlugin_ConeSegment::RMIN2_ID())->value();
49   double aRMax2 = real(GDMLPlugin_ConeSegment::RMAX2_ID())->value();
50   double aZ = real(GDMLPlugin_ConeSegment::Z_ID())->value();
51   double aStartPhi = real(GDMLPlugin_ConeSegment::STARTPHI_ID())->value();
52   double aDeltaPhi = real(GDMLPlugin_ConeSegment::DELTAPHI_ID())->value();
53
54   std::shared_ptr<GeomAlgoAPI_ConeSegment> aConeSegmentAlgo =
55     std::shared_ptr<GeomAlgoAPI_ConeSegment>(new GeomAlgoAPI_ConeSegment(aRMin1, aRMax1,
56                                                                          aRMin2, aRMax2,
57                                                                          aZ,
58                                                                          aStartPhi, aDeltaPhi));
59
60   // Check with that the arguments for aConeSegmentAlgo are correct
61   if (!aConeSegmentAlgo->check()){
62     setError(aConeSegmentAlgo->getError());
63     return;
64   }
65
66   aConeSegmentAlgo->build();
67
68   // Check if the creation of the cone segment went well
69   if(!aConeSegmentAlgo->isDone()) {
70     setError(aConeSegmentAlgo->getError());
71     return;
72   }
73   if (!aConeSegmentAlgo->checkValid("Cone Segment builder")) {
74     setError(aConeSegmentAlgo->getError());
75     return;
76   }
77
78   int aResultIndex = 0;
79   ResultBodyPtr aResultConeSegment = document()->createBody(data(), aResultIndex);
80   loadNamingDS(aConeSegmentAlgo, aResultConeSegment);
81   setResult(aResultConeSegment, aResultIndex);
82 }
83
84 //=================================================================================================
85 void GDMLPlugin_ConeSegment::loadNamingDS(
86     std::shared_ptr<GeomAlgoAPI_ConeSegment> theConeSegmentAlgo,
87     std::shared_ptr<ModelAPI_ResultBody> theResultConeSegment)
88 {
89   // Load the result
90   theResultConeSegment->store(theConeSegmentAlgo->shape());
91
92   // Prepare the naming
93   theConeSegmentAlgo->prepareNamingFaces();
94
95   // Insert to faces
96   std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
97     theConeSegmentAlgo->getCreatedFaces();
98   for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator it = listOfFaces.begin();
99        it != listOfFaces.end();
100        ++it)
101   {
102     theResultConeSegment->generated((*it).second, (*it).first);
103   }
104 }
105