1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "BuildPlugin_Vertex.h"
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_ResultBody.h>
26 #include <GeomAlgoAPI_Copy.h>
28 //=================================================================================================
29 BuildPlugin_Vertex::BuildPlugin_Vertex()
33 //=================================================================================================
34 void BuildPlugin_Vertex::initAttributes()
36 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
39 //=================================================================================================
40 void BuildPlugin_Vertex::execute()
42 // Get base objects list.
43 AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
44 if(!aSelectionList.get()) {
45 setError("Error: Could not get selection list.");
48 if(aSelectionList->size() == 0) {
49 setError("Error: Empty selection list.");
53 // Collect base shapes.
54 ListOfShape aListOfShapes;
56 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
57 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
58 GeomShapePtr aShape = aSelection->value();
60 ResultPtr aContext = aSelection->context();
62 setError("Error: Attribute has empty context.");
66 aShape = aContext->shape();
69 setError("Error: Empty shape selected.");
73 if(aShape->shapeType() != GeomAPI_Shape::VERTEX) {
74 setError("Error: Selected shape has wrong type. Only vertices acceptable.");
79 GeomAlgoAPI_Copy aCopyAlgo(aShape);
81 // Check that algo is done.
82 if(!aCopyAlgo.isDone()) {
83 setError("Error: " + getKind() + " algorithm failed.");
87 // Check if shape is not null.
88 if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) {
89 setError("Error: Resulting shape is null.");
93 // Check that resulting shape is valid.
94 if(!aCopyAlgo.isValid()) {
95 setError("Error: Resulting shape is not valid.");
100 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
101 aResultBody->storeModified(aShape, aCopyAlgo.shape());
102 setResult(aResultBody, aResultIndex);
106 removeResults(aResultIndex);