Salome HOME
443c9ce9f24316fbef0b2f1d9c924866f5061d82
[modules/shaper.git] / src / Model / Model_ResultConstruction.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_ResultConstruction.cpp
4 // Created:     07 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include <Model_ResultConstruction.h>
8
9 #include <ModelAPI_AttributeIntArray.h>
10 #include <Config_PropManager.h>
11 #include <GeomAPI_PlanarEdges.h>
12 #include <GeomAlgoAPI_SketchBuilder.h>
13
14 void Model_ResultConstruction::initAttributes()
15 {
16   // append the color attribute. It is empty, the attribute will be filled by a request
17   DataPtr aData = data();
18   aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
19 }
20
21 void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
22                                        std::string& theDefault)
23 {
24   theSection = "Visualization";
25   theName = "result_construction_color";
26   theDefault = DEFAULT_COLOR();
27 }
28
29 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
30 {
31   if (myShape != theShape && (!theShape.get() || !theShape->isEqual(myShape))) {
32     myShape = theShape;
33     if (theShape.get()) {
34       myFacesUpToDate = false;
35       myFaces.clear();
36     }
37   }
38 }
39
40 std::shared_ptr<GeomAPI_Shape> Model_ResultConstruction::shape()
41 {
42   return myShape;
43 }
44
45 Model_ResultConstruction::Model_ResultConstruction()
46 {
47   myIsInHistory = true;
48   myIsInfinite = false;
49   myFacesUpToDate = false;
50 }
51
52 void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
53 {
54   myIsInHistory = isInHistory;
55 }
56
57 int Model_ResultConstruction::facesNum()
58 {
59   if (!myFacesUpToDate) {
60     std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
61       std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(myShape);
62     if (aWirePtr.get()) {
63       std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
64       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
65         aWirePtr->norm(), aWirePtr, aFaces);
66       std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
67       for(; aFIter != aFaces.end(); aFIter++) {
68         std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
69         if (aFace.get() && !aFace->isNull())
70           myFaces.push_back(aFace);
71       }
72     }
73     myFacesUpToDate = true;
74   }
75   return myFaces.size();
76 }
77
78 std::shared_ptr<GeomAPI_Face> Model_ResultConstruction::face(const int theIndex)
79 {
80   return myFaces[theIndex];
81 }
82
83 bool Model_ResultConstruction::isInfinite()
84 {
85   return myIsInfinite;
86 }
87
88 void Model_ResultConstruction::setInfinite(const bool theInfinite)
89 {
90   myIsInfinite = theInfinite;
91 }
92
93 void Model_ResultConstruction::setIsConcealed(const bool theValue)
94 {
95   // do nothing: the construction element is never consealed
96 }