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>
11 #include <ModelAPI_ResultConstruction.h>
13 #include <Events_Error.h>
15 #include <GeomAPI_DataMapOfShapeShape.h>
16 #include <GeomAPI_PlanarEdges.h>
17 #include <GeomAPI_Pln.h>
18 #include <GeomAPI_ShapeExplorer.h>
20 #include <GeomAlgoAPI_ShapeTools.h>
21 #include <GeomAlgoAPI_SketchBuilder.h>
22 #include <GeomAlgoAPI_WireBuilder.h>
27 //=================================================================================================
28 BuildPlugin_Face::BuildPlugin_Face()
32 //=================================================================================================
33 void BuildPlugin_Face::initAttributes()
35 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
38 //=================================================================================================
39 void BuildPlugin_Face::execute()
41 // Get base objects list.
42 AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
43 if(!aSelectionList.get()) {
44 setError("Error: Could not get selection list.");
47 if(aSelectionList->size() == 0) {
48 setError("Error: Empty selection list.");
52 // Collect base shapes.
54 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
55 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
56 GeomShapePtr aShape = aSelection->value();
58 aShape = aSelection->context()->shape();
60 for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
61 GeomShapePtr anEdge = anExp.current();
62 anEdges.push_back(anEdge);
67 std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
71 GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(), aPln->direction(), anEdges, aFaces);
73 // Get wires from faces.
75 for(ListOfShape::const_iterator anIt = aFaces.cbegin(); anIt != aFaces.cend(); ++anIt) {
76 for(GeomAPI_ShapeExplorer anExp(*anIt, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
77 aWires.push_back(anExp.current());
81 // Make faces with holes.
83 GeomAlgoAPI_ShapeTools::makeFacesWithHoles(aPln->location(), aPln->direction(), aWires, aFaces);
87 for(ListOfShape::const_iterator anIt = aFaces.cbegin(); anIt != aFaces.cend(); ++anIt) {
88 ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
89 GeomShapePtr aShape = *anIt;
90 aResultBody->store(aShape);
92 for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
93 GeomShapePtr anEdgeInResult = anExp.current();
94 for(ListOfShape::const_iterator anIt = anEdges.cbegin(); anIt != anEdges.cend(); ++anIt) {
95 std::shared_ptr<GeomAPI_Edge> anEdgeInList(new GeomAPI_Edge(*anIt));
96 if(anEdgeInList->isEqual(anEdgeInResult)) {
97 aResultBody->modified(anEdgeInList, anEdgeInResult, "Edge");
103 setResult(aResultBody, anIndex);
107 removeResults(anIndex);