1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: BuildPlugin_Shell.cpp
4 // Created: 14 April 2016
5 // Author: Dmitry Bobylev
7 #include "BuildPlugin_Shell.h"
9 #include <ModelAPI_AttributeSelectionList.h>
10 #include <ModelAPI_ResultBody.h>
11 #include <ModelAPI_ResultConstruction.h>
13 #include <GeomAlgoAPI_Sewing.h>
14 #include <GeomAPI_ShapeExplorer.h>
16 //=================================================================================================
17 BuildPlugin_Shell::BuildPlugin_Shell()
21 //=================================================================================================
22 void BuildPlugin_Shell::initAttributes()
24 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
27 //=================================================================================================
28 void BuildPlugin_Shell::execute()
30 // Get base objects list.
31 AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
33 // Collect base shapes.
35 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
36 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
37 GeomShapePtr aShape = aSelection->value();
39 aShape = aSelection->context()->shape();
41 aShapes.push_back(aShape);
45 GeomAlgoAPI_Sewing aSewingAlgo(aShapes);
47 // Check that algo is done.
48 if(!aSewingAlgo.isDone()) {
49 setError("Error: " + getKind() + " algorithm failed.");
53 // Check if shape is not null.
54 if(!aSewingAlgo.shape().get() || aSewingAlgo.shape()->isNull()) {
55 setError("Error: Resulting shape is null.");
59 // Check that resulting shape is valid.
60 if(!aSewingAlgo.isValid()) {
61 setError("Error: Resulting shape is not valid.");
66 GeomShapePtr aResult = aSewingAlgo.shape();
67 std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfShapes = aSewingAlgo.mapOfSubShapes();
70 for(GeomAPI_ShapeExplorer anExp(aResult, GeomAPI_Shape::SHELL); anExp.more(); anExp.next()) {
71 GeomShapePtr aShell = anExp.current();
72 ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
73 aResultBody->store(aShell);
74 for(ListOfShape::const_iterator anIt = aShapes.cbegin(); anIt != aShapes.cend(); ++anIt) {
75 for(GeomAPI_ShapeExplorer
76 aFaceExp(*anIt, GeomAPI_Shape::FACE); aFaceExp.more(); aFaceExp.next()) {
77 GeomShapePtr aFace = aFaceExp.current();
79 aSewingAlgo.modified(aFace, aHistory);
80 for(ListOfShape::const_iterator aHistoryIt = aHistory.cbegin();
81 aHistoryIt != aHistory.cend();
83 GeomShapePtr aHistoryShape = *aHistoryIt;
84 if(aMapOfShapes->isBound(aHistoryShape)) {
85 aHistoryShape = aMapOfShapes->find(aHistoryShape);
87 if(aShell->isSubShape(aHistoryShape)) {
88 aResultBody->loadAndOrientModifiedShapes(&aSewingAlgo, aFace, GeomAPI_Shape::EDGE,
89 1, "Modified_Edge", *aMapOfShapes.get());
90 aResultBody->loadAndOrientModifiedShapes(&aSewingAlgo, aFace, GeomAPI_Shape::FACE,
91 2, "Modified_Face", *aMapOfShapes.get());
97 setResult(aResultBody, anIndex);
101 removeResults(anIndex);