Salome HOME
Fix for crash on abort of Boolean with one argument set.
[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 #include <Events_Loop.h>
14 #include <ModelAPI_Events.h>
15
16 void Model_ResultConstruction::initAttributes()
17 {
18   // append the color attribute. It is empty, the attribute will be filled by a request
19   DataPtr aData = data();
20   aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
21 }
22
23 void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
24                                        std::string& theDefault)
25 {
26   theSection = "Visualization";
27   theName = "result_construction_color";
28   theDefault = DEFAULT_COLOR();
29 }
30
31 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
32 {
33   if (myShape != theShape && (!theShape.get() || !theShape->isEqual(myShape))) {
34     static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
35     ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
36     myShape = theShape;
37     if (theShape.get()) {
38       myFacesUpToDate = false;
39       myFaces.clear();
40     }
41   }
42 }
43
44 std::shared_ptr<GeomAPI_Shape> Model_ResultConstruction::shape()
45 {
46   return myShape;
47 }
48
49 Model_ResultConstruction::Model_ResultConstruction()
50 {
51   myIsInHistory = true;
52   myIsInfinite = false;
53   myFacesUpToDate = false;
54 }
55
56 void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
57 {
58   myIsInHistory = isInHistory;
59 }
60
61 int Model_ResultConstruction::facesNum()
62 {
63   if (!myFacesUpToDate) {
64     std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
65       std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(myShape);
66     if (aWirePtr.get()) {
67       std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
68       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
69         aWirePtr->norm(), aWirePtr, aFaces);
70       std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
71       for(; aFIter != aFaces.end(); aFIter++) {
72         std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
73         if (aFace.get() && !aFace->isNull())
74           myFaces.push_back(aFace);
75       }
76     }
77     myFacesUpToDate = true;
78   }
79   return int(myFaces.size());
80 }
81
82 std::shared_ptr<GeomAPI_Face> Model_ResultConstruction::face(const int theIndex)
83 {
84   return myFaces[theIndex];
85 }
86
87 bool Model_ResultConstruction::isInfinite()
88 {
89   return myIsInfinite;
90 }
91
92 void Model_ResultConstruction::setInfinite(const bool theInfinite)
93 {
94   myIsInfinite = theInfinite;
95 }
96
97 void Model_ResultConstruction::setIsConcealed(const bool theValue)
98 {
99   // do nothing: the construction element is never consealed
100 }