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