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_Edge.h"
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_ResultBody.h>
26 #include <GeomAlgoAPI_Copy.h>
28 //=================================================================================================
29 BuildPlugin_Edge::BuildPlugin_Edge()
33 //=================================================================================================
34 void BuildPlugin_Edge::initAttributes()
36 data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
39 //=================================================================================================
40 void BuildPlugin_Edge::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::EDGE) {
74 setError("Error: Selected shape has wrong type. Only edges 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 std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aCopyAlgo.mapOfSubShapes();
103 int aModVertexTag = 1;
104 std::string aModVertexName = "Modified_Vertex";
105 aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aShape, GeomAPI_Shape::VERTEX,
106 aModVertexTag, aModVertexName, *aSubShapes.get());
108 setResult(aResultBody, aResultIndex);
112 removeResults(aResultIndex);