Salome HOME
Issue #1369: removed unnecessary includes in Vertex and Edge features from Build...
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Vertex.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        BuildPlugin_Vertex.cpp
4 // Created:     18 April 2016
5 // Author:      Dmitry Bobylev
6
7 #include "BuildPlugin_Vertex.h"
8
9 #include <ModelAPI_AttributeSelectionList.h>
10 #include <ModelAPI_ResultBody.h>
11
12 //=================================================================================================
13 BuildPlugin_Vertex::BuildPlugin_Vertex()
14 {
15 }
16
17 //=================================================================================================
18 void BuildPlugin_Vertex::initAttributes()
19 {
20   data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
21 }
22
23 //=================================================================================================
24 void BuildPlugin_Vertex::execute()
25 {
26   // Get base objects list.
27   AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
28   if(!aSelectionList.get()) {
29     setError("Error: Could not get selection list.");
30     return;
31   }
32   if(aSelectionList->size() == 0) {
33     setError("Error: Empty selection list.");
34     return;
35   }
36
37   // Collect base shapes.
38   ListOfShape aListOfShapes;
39   int aResultIndex = 0;
40   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
41     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
42     GeomShapePtr aShape = aSelection->value();
43     if(!aShape.get()) {
44       ResultPtr aContext = aSelection->context();
45       if(!aContext.get()) {
46         setError("Error: Attribute has empty context.");
47         return;
48       }
49
50       aShape = aContext->shape();
51     }
52     if(!aShape.get()) {
53       setError("Error: Empty shape selected.");
54       return;
55     }
56
57     if(aShape->shapeType() != GeomAPI_Shape::VERTEX) {
58       setError("Error: Selected shape has wrong type. Only vertices acceptable.");
59       return;
60     }
61
62     // Store result.
63     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
64     aResultBody->store(aShape);
65     setResult(aResultBody, aResultIndex);
66     ++aResultIndex;
67   }
68
69   removeResults(aResultIndex);
70 }