1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: BuildPlugin_Face.cpp
4 // Created: 14 April 2016
5 // Author: Dmitry Bobylev
7 #include "BuildPlugin_Face.h"
9 #include <ModelAPI_AttributeSelectionList.h>
10 #include <ModelAPI_ResultBody.h>
12 #include <GeomAPI_Edge.h>
13 #include <GeomAPI_Pln.h>
14 #include <GeomAPI_ShapeExplorer.h>
16 #include <GeomAlgoAPI_ShapeTools.h>
17 #include <GeomAlgoAPI_SketchBuilder.h>
19 //=================================================================================================
20 BuildPlugin_Face::BuildPlugin_Face()
24 //=================================================================================================
25 void BuildPlugin_Face::initAttributes()
27 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
30 //=================================================================================================
31 void BuildPlugin_Face::execute()
33 // Get base objects list.
34 AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
35 if(!aSelectionList.get()) {
36 setError("Error: Could not get selection list.");
39 if(aSelectionList->size() == 0) {
40 setError("Error: Empty selection list.");
44 // Collect base shapes.
46 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
47 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
48 GeomShapePtr aShape = aSelection->value();
50 aShape = aSelection->context()->shape();
52 for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
53 GeomShapePtr anEdge = anExp.current();
54 anEdges.push_back(anEdge);
59 std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
63 GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(), aPln->direction(), anEdges, aFaces);
65 // Get wires from faces.
67 for(ListOfShape::const_iterator anIt = aFaces.cbegin(); anIt != aFaces.cend(); ++anIt) {
68 aWires.push_back(GeomAlgoAPI_ShapeTools::getFaceOuterWire(*anIt));
69 //for(GeomAPI_ShapeExplorer anExp(*anIt, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
70 // if(anExp.current()->orientation() == GeomAPI_Shape::REVERSED) {
73 // aWires.push_back(anExp.current());
77 // Make faces with holes.
79 GeomAlgoAPI_ShapeTools::makeFacesWithHoles(aPln->location(), aPln->direction(), aWires, aFaces);
83 for(ListOfShape::const_iterator anIt = aFaces.cbegin(); anIt != aFaces.cend(); ++anIt) {
84 ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
85 GeomShapePtr aShape = *anIt;
86 aResultBody->store(aShape);
88 for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
89 GeomShapePtr anEdgeInResult = anExp.current();
90 for(ListOfShape::const_iterator anIt = anEdges.cbegin(); anIt != anEdges.cend(); ++anIt) {
91 std::shared_ptr<GeomAPI_Edge> anEdgeInList(new GeomAPI_Edge(*anIt));
92 if(anEdgeInList->isEqual(anEdgeInResult)) {
93 aResultBody->modified(anEdgeInList, anEdgeInResult, "Edge");
99 setResult(aResultBody, anIndex);
103 removeResults(anIndex);