1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: BuildPlugin_Vertex.cpp
4 // Created: 18 April 2016
5 // Author: Dmitry Bobylev
7 #include "BuildPlugin_Vertex.h"
9 #include <ModelAPI_AttributeSelectionList.h>
10 #include <ModelAPI_ResultBody.h>
12 #include <GeomAlgoAPI_Copy.h>
14 //=================================================================================================
15 BuildPlugin_Vertex::BuildPlugin_Vertex()
19 //=================================================================================================
20 void BuildPlugin_Vertex::initAttributes()
22 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
25 //=================================================================================================
26 void BuildPlugin_Vertex::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::VERTEX) {
60 setError("Error: Selected shape has wrong type. Only vertices 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 setResult(aResultBody, aResultIndex);
92 removeResults(aResultIndex);