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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "BuildPlugin_Edge.h"
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_ResultBody.h>
25 #include <GeomAlgoAPI_Copy.h>
27 //=================================================================================================
28 BuildPlugin_Edge::BuildPlugin_Edge()
32 //=================================================================================================
33 void BuildPlugin_Edge::initAttributes()
35 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
38 //=================================================================================================
39 void BuildPlugin_Edge::execute()
41 // Get base objects list.
42 AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
43 if(!aSelectionList.get()) {
44 setError("Error: Could not get selection list.");
47 if(aSelectionList->size() == 0) {
48 setError("Error: Empty selection list.");
52 // Collect base shapes.
53 ListOfShape aListOfShapes;
55 for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
56 AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
57 GeomShapePtr aShape = aSelection->value();
59 ResultPtr aContext = aSelection->context();
61 setError("Error: Attribute has empty context.");
65 aShape = aContext->shape();
68 setError("Error: Empty shape selected.");
72 if(aShape->shapeType() != GeomAPI_Shape::EDGE) {
73 setError("Error: Selected shape has wrong type. Only edges acceptable.");
78 GeomAlgoAPI_Copy aCopyAlgo(aShape);
80 // Check that algo is done.
81 if(!aCopyAlgo.isDone()) {
82 setError("Error: " + getKind() + " algorithm failed.");
86 // Check if shape is not null.
87 if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) {
88 setError("Error: Resulting shape is null.");
92 // Check that resulting shape is valid.
93 if(!aCopyAlgo.isValid()) {
94 setError("Error: Resulting shape is not valid.");
99 ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
100 aResultBody->storeModified(aShape, aCopyAlgo.shape());
101 std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aCopyAlgo.mapOfSubShapes();
102 int aModVertexTag = 1;
103 std::string aModVertexName = "Modified_Vertex";
104 aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aShape, GeomAPI_Shape::VERTEX,
105 aModVertexTag, aModVertexName, *aSubShapes.get());
107 setResult(aResultBody, aResultIndex);
111 removeResults(aResultIndex);