Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GDMLPlugin / GDMLPlugin_ConeSegment.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // File:        GDMLPlugin_ConeSegment.cpp
4 // Created:     23 Nov 2016
5 // Author:      Clarisse Genrault (CEA)
6
7 #include <GDMLPlugin_ConeSegment.h>
8
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_ResultBody.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeString.h>
13
14 //=================================================================================================
15 GDMLPlugin_ConeSegment::GDMLPlugin_ConeSegment() // Nothing to do during instantiation
16 {
17 }
18
19 //=================================================================================================
20 void GDMLPlugin_ConeSegment::initAttributes()
21 {
22   data()->addAttribute(GDMLPlugin_ConeSegment::RMIN1_ID(), ModelAPI_AttributeDouble::typeId());
23   data()->addAttribute(GDMLPlugin_ConeSegment::RMAX1_ID(), ModelAPI_AttributeDouble::typeId());
24   data()->addAttribute(GDMLPlugin_ConeSegment::RMIN2_ID(), ModelAPI_AttributeDouble::typeId());
25   data()->addAttribute(GDMLPlugin_ConeSegment::RMAX2_ID(), ModelAPI_AttributeDouble::typeId());
26   data()->addAttribute(GDMLPlugin_ConeSegment::Z_ID(), ModelAPI_AttributeDouble::typeId());
27   data()->addAttribute(GDMLPlugin_ConeSegment::STARTPHI_ID(), ModelAPI_AttributeDouble::typeId());
28   data()->addAttribute(GDMLPlugin_ConeSegment::DELTAPHI_ID(), ModelAPI_AttributeDouble::typeId());
29 }
30
31 //=================================================================================================
32 void GDMLPlugin_ConeSegment::execute()
33 {
34   double aRMin1 = real(GDMLPlugin_ConeSegment::RMIN1_ID())->value();
35   double aRMax1 = real(GDMLPlugin_ConeSegment::RMAX1_ID())->value();
36   double aRMin2 = real(GDMLPlugin_ConeSegment::RMIN2_ID())->value();
37   double aRMax2 = real(GDMLPlugin_ConeSegment::RMAX2_ID())->value();
38   double aZ = real(GDMLPlugin_ConeSegment::Z_ID())->value();
39   double aStartPhi = real(GDMLPlugin_ConeSegment::STARTPHI_ID())->value();
40   double aDeltaPhi = real(GDMLPlugin_ConeSegment::DELTAPHI_ID())->value();
41
42   std::shared_ptr<GeomAlgoAPI_ConeSegment> aConeSegmentAlgo =
43     std::shared_ptr<GeomAlgoAPI_ConeSegment>(new GeomAlgoAPI_ConeSegment(aRMin1, aRMax1,
44                                                                          aRMin2, aRMax2,
45                                                                          aZ,
46                                                                          aStartPhi, aDeltaPhi));
47
48   // Check with that the arguments for aConeSegmentAlgo are correct
49   if (!aConeSegmentAlgo->check()){
50     setError(aConeSegmentAlgo->getError());
51     return;
52   }
53
54   aConeSegmentAlgo->build();
55
56   // Check if the creation of the cone segment went well
57   if(!aConeSegmentAlgo->isDone()) {
58     setError(aConeSegmentAlgo->getError());
59     return;
60   }
61   if (!aConeSegmentAlgo->checkValid("Cone Segment builder")) {
62     setError(aConeSegmentAlgo->getError());
63     return;
64   }
65
66   int aResultIndex = 0;
67   ResultBodyPtr aResultConeSegment = document()->createBody(data(), aResultIndex);
68   loadNamingDS(aConeSegmentAlgo, aResultConeSegment);
69   setResult(aResultConeSegment, aResultIndex);
70 }
71
72 //=================================================================================================
73 void GDMLPlugin_ConeSegment::loadNamingDS(
74     std::shared_ptr<GeomAlgoAPI_ConeSegment> theConeSegmentAlgo,
75     std::shared_ptr<ModelAPI_ResultBody> theResultConeSegment)
76 {
77   // Load the result
78   theResultConeSegment->store(theConeSegmentAlgo->shape());
79
80   // Prepare the naming
81   theConeSegmentAlgo->prepareNamingFaces();
82
83   // Insert to faces
84   int num = 1;
85   std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
86     theConeSegmentAlgo->getCreatedFaces();
87   for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator
88        it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) {
89     std::shared_ptr<GeomAPI_Shape> aFace = (*it).second;
90     theResultConeSegment->generated(aFace, (*it).first, num++);
91   }
92 }
93