X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBuildPlugin%2FBuildPlugin_Wire.cpp;h=4fe602e84c29c5c4f0dfb3a8c3369b6cdf07c726;hb=6c4e803061682cbb1423fe65cd2c1b232e7a95e6;hp=99d6bd74ed7cb704e9d5bea0d831852aac9f6f9a;hpb=37bd12bd6f4626fc2bfa7764c8f4927dc5b01b9c;p=modules%2Fshaper.git diff --git a/src/BuildPlugin/BuildPlugin_Wire.cpp b/src/BuildPlugin/BuildPlugin_Wire.cpp index 99d6bd74e..4fe602e84 100644 --- a/src/BuildPlugin/BuildPlugin_Wire.cpp +++ b/src/BuildPlugin/BuildPlugin_Wire.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: BuildPlugin_Wire.cpp -// Created: 14 April 2016 -// Author: Dmitry Bobylev +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "BuildPlugin_Wire.h" @@ -10,9 +23,8 @@ #include #include -#include +#include -#include #include #include @@ -47,25 +59,21 @@ void BuildPlugin_Wire::execute() } // Collect base shapes. - ListOfShape aListOfShapes; + ListOfShape anEdges; for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); GeomShapePtr aShape = aSelection->value(); if(!aShape.get()) { - setError("Error: Empty shape selected."); - return; + aShape = aSelection->context()->shape(); } - - if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) { - setError("Error: Selected shape has wrong type. Only edges and wires acceptable."); - return; + for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { + GeomShapePtr anEdge = anExp.current(); + anEdges.push_back(anEdge); } - - aListOfShapes.push_back(aShape); } // Create wire. - GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes); + GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(anEdges); if(!aWire.get()) { setError("Error: Result wire is empty. Probably it has disconnected edges or non-manifold."); return; @@ -74,16 +82,27 @@ void BuildPlugin_Wire::execute() // Store result. ResultBodyPtr aResultBody = document()->createBody(data()); aResultBody->store(aWire); + for(GeomAPI_ShapeExplorer anExp(aWire, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { + GeomShapePtr anEdgeInResult = anExp.current(); + for(ListOfShape::const_iterator anIt = anEdges.cbegin(); anIt != anEdges.cend(); ++anIt) { + std::shared_ptr anEdgeInList(new GeomAPI_Edge(*anIt)); + if(anEdgeInList->isEqual(anEdgeInResult)) { + aResultBody->modified(anEdgeInList, anEdgeInResult); + break; + } + } + } setResult(aResultBody); } //================================================================================================= bool BuildPlugin_Wire::customAction(const std::string& theActionId) { - if(theActionId == "add_contour") { + if(theActionId == ADD_CONTOUR_ACTION_ID()) { return addContour(); } else { - Events_Error::send("Error: Feature \"" + getKind() + "\" does not support action \"" + theActionId + "\"."); + std::string aMsg = "Error: Feature \"%1\" does not support action \"%2\"."; + Events_InfoMessage("BuildPlugin_Wire", aMsg).arg(getKind()).arg(theActionId).send(); } return false; @@ -95,7 +114,7 @@ bool BuildPlugin_Wire::addContour() // Get base objects list. AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); if(aSelectionList->size() == 0) { - Events_Error::send("Error: Empty selection list."); + Events_InfoMessage("BuildPlugin_Wire", "Error: Empty selection list.").send(); return false; } @@ -116,12 +135,14 @@ bool BuildPlugin_Wire::addContour() // Check that it is edge on sketch. ResultPtr aContext = aSelection->context(); - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aContext); if(!aConstruction.get()) { continue; } GeomShapePtr aContextShape = aConstruction->shape(); - std::shared_ptr aPlanarEdges = std::dynamic_pointer_cast(aContextShape); + std::shared_ptr aPlanarEdges = + std::dynamic_pointer_cast(aContextShape); if(!aPlanarEdges.get()) { continue; } @@ -143,38 +164,36 @@ bool BuildPlugin_Wire::addContour() AttributeSelectionPtr aSelection = *aListIt; std::shared_ptr anEdgeInList(new GeomAPI_Edge(aSelection->value())); - ListOfShape::const_iterator anEdgesIt = anAddedEdges.cbegin(); - for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) { - if(anEdgeInList->isEqual(*anEdgesIt)) { - break; - } - } + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aSelection->context()); - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSelection->context()); - std::shared_ptr aPlanarEdges = std::dynamic_pointer_cast(aConstruction->shape()); - - // Iterate on faces and add face with this edge. - std::shared_ptr aFoundFace; + // Iterate on wires and add wire with this edge. + std::shared_ptr aFoundWire; for(int anIndex = 0; anIndex < aConstruction->facesNum(); ++anIndex) { std::shared_ptr aFace = aConstruction->face(anIndex); - for(GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { - std::shared_ptr anEdgeOnFace(new GeomAPI_Edge(anExp.current())); - if(anEdgeInList->isEqual(anEdgeOnFace)) { - aFoundFace = aFace; - break; + for(GeomAPI_ShapeExplorer + aWireExp(aFace, GeomAPI_Shape::WIRE); aWireExp.more(); aWireExp.next()) { + GeomShapePtr aWireOnFace = aWireExp.current(); + for(GeomAPI_ShapeExplorer + anExp(aWireOnFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { + std::shared_ptr anEdgeOnFace(new GeomAPI_Edge(anExp.current())); + if(anEdgeInList->isEqual(anEdgeOnFace)) { + aFoundWire = aWireOnFace; + break; + } } } - - if(aFoundFace.get()) { + if(aFoundWire.get()) { break; } } - // If face with the same edge found. Add all other edges to list. - if(aFoundFace.get()) { - for(GeomAPI_ShapeExplorer anExp(aFoundFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { + // If wire with the same edge found. Add all other edges to list. + if(aFoundWire.get()) { + for(GeomAPI_ShapeExplorer + anExp(aFoundWire, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { std::shared_ptr anEdgeOnFace(new GeomAPI_Edge(anExp.current())); - anEdgesIt = anAddedEdges.cbegin(); + ListOfShape::const_iterator anEdgesIt = anAddedEdges.cbegin(); for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) { if(anEdgeOnFace->isEqual(*anEdgesIt)) { break; @@ -190,7 +209,8 @@ bool BuildPlugin_Wire::addContour() } if(!isAnyContourAdded) { - Events_Error::send("Error: Contours already closed or no contours found for selected edges."); + Events_InfoMessage("BuildPlugin_Wire", + "Error: Contours already closed or no contours found for selected edges.").send(); return false; }