Salome HOME
Union of validator and filter functionalities.
[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::type());
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   myFacesUpToDate = false;
49   setIsConcealed(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     std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
63     GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
64       aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
65     std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
66     for(; aFIter != aFaces.end(); aFIter++) {
67       std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
68       if (aFace.get())
69         myFaces.push_back(aFace);
70     }
71     myFacesUpToDate = true;
72   }
73   return myFaces.size();
74 }
75
76 std::shared_ptr<GeomAPI_Face> Model_ResultConstruction::face(const int theIndex)
77 {
78   return myFaces[theIndex];
79 }