Salome HOME
Issue #1660: Ability to change the deflection coefficient
[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 <Config_PropManager.h>
10 #include <GeomAPI_PlanarEdges.h>
11 #include <GeomAlgoAPI_SketchBuilder.h>
12 #include <Events_Loop.h>
13 #include <ModelAPI_Events.h>
14
15 void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
16                                        std::string& theDefault)
17 {
18   theSection = "Visualization";
19   theName = "result_construction_color";
20   theDefault = DEFAULT_COLOR();
21 }
22
23 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
24 {
25   if (myShape != theShape && (!theShape.get() || !theShape->isEqual(myShape))) {
26     static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
27     ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
28     myShape = theShape;
29     if (theShape.get()) {
30       myFacesUpToDate = false;
31       myFaces.clear();
32     }
33   }
34 }
35
36 std::shared_ptr<GeomAPI_Shape> Model_ResultConstruction::shape()
37 {
38   return myShape;
39 }
40
41 Model_ResultConstruction::Model_ResultConstruction()
42 {
43   myIsInHistory = true;
44   myIsInfinite = false;
45   myFacesUpToDate = false;
46 }
47
48 void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
49 {
50   myIsInHistory = isInHistory;
51 }
52
53 int Model_ResultConstruction::facesNum()
54 {
55   if (!myFacesUpToDate) {
56     std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = 
57       std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(myShape);
58     if (aWirePtr.get()) {
59       std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
60       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
61         aWirePtr->norm(), aWirePtr, aFaces);
62       std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
63       for(; aFIter != aFaces.end(); aFIter++) {
64         std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
65         if (aFace.get() && !aFace->isNull())
66           myFaces.push_back(aFace);
67       }
68     }
69     myFacesUpToDate = true;
70   }
71   return int(myFaces.size());
72 }
73
74 std::shared_ptr<GeomAPI_Face> Model_ResultConstruction::face(const int theIndex)
75 {
76   return myFaces[theIndex];
77 }
78
79 bool Model_ResultConstruction::isInfinite()
80 {
81   return myIsInfinite;
82 }
83
84 void Model_ResultConstruction::setInfinite(const bool theInfinite)
85 {
86   myIsInfinite = theInfinite;
87 }
88
89 void Model_ResultConstruction::setIsConcealed(const bool theValue)
90 {
91   // do nothing: the construction element is never consealed
92 }