1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_ResultConstruction.cpp
4 // Created: 07 Jul 2014
5 // Author: Mikhail PONIKAROV
7 #include <Model_ResultConstruction.h>
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>
16 void Model_ResultConstruction::initAttributes()
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());
23 void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
24 std::string& theDefault)
26 theSection = "Visualization";
27 theName = "result_construction_color";
28 theDefault = DEFAULT_COLOR();
31 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
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);
38 myFacesUpToDate = false;
44 std::shared_ptr<GeomAPI_Shape> Model_ResultConstruction::shape()
49 Model_ResultConstruction::Model_ResultConstruction()
53 myFacesUpToDate = false;
56 void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
58 myIsInHistory = isInHistory;
61 int Model_ResultConstruction::facesNum()
63 if (!myFacesUpToDate) {
64 std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
65 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(myShape);
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);
77 myFacesUpToDate = true;
79 return int(myFaces.size());
82 std::shared_ptr<GeomAPI_Face> Model_ResultConstruction::face(const int theIndex)
84 return myFaces[theIndex];
87 bool Model_ResultConstruction::isInfinite()
92 void Model_ResultConstruction::setInfinite(const bool theInfinite)
94 myIsInfinite = theInfinite;
97 void Model_ResultConstruction::setIsConcealed(const bool theValue)
99 // do nothing: the construction element is never consealed