1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: BuildPlugin_Edge.cpp
4 // Created: 18 April 2016
5 // Author: Dmitry Bobylev
7 #include "BuildPlugin_Edge.h"
9 #include <ModelAPI_AttributeSelectionList.h>
10 #include <ModelAPI_ResultBody.h>
12 #include <GeomAlgoAPI_Copy.h>
14 //=================================================================================================
15 BuildPlugin_Edge::BuildPlugin_Edge()
19 //=================================================================================================
20 void BuildPlugin_Edge::initAttributes()
22 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
25 //=================================================================================================
26 void BuildPlugin_Edge::execute()
28 // Get base objects list.
29 AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
30 if(!aSelectionList.get()) {
31 setError("Error: Could not get selection list.");
34 if(aSelectionList->size() == 0) {
35 setError("Error: Empty selection list.");
39 // Collect base shapes.
40 ListOfShape aListOfShapes;
42 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
43 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
44 GeomShapePtr aShape = aSelection->value();
46 ResultPtr aContext = aSelection->context();
48 setError("Error: Attribute has empty context.");
52 aShape = aContext->shape();
55 setError("Error: Empty shape selected.");
59 if(aShape->shapeType() != GeomAPI_Shape::EDGE) {
60 setError("Error: Selected shape has wrong type. Only edges acceptable.");
65 GeomAlgoAPI_Copy aCopyAlgo(aShape);
67 // Check that algo is done.
68 if(!aCopyAlgo.isDone()) {
69 setError("Error: " + getKind() + " algorithm failed.");
73 // Check if shape is not null.
74 if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) {
75 setError("Error: Resulting shape is null.");
79 // Check that resulting shape is valid.
80 if(!aCopyAlgo.isValid()) {
81 setError("Error: Resulting shape is not valid.");
86 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
87 aResultBody->storeModified(aShape, aCopyAlgo.shape());
88 std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aCopyAlgo.mapOfSubShapes();
89 int aModVertexTag = 1;
90 std::string aModVertexName = "Modified_Vertex";
91 aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aShape, GeomAPI_Shape::VERTEX,
92 aModVertexTag, aModVertexName, *aSubShapes.get());
94 setResult(aResultBody, aResultIndex);
98 removeResults(aResultIndex);