X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBuildPlugin%2FBuildPlugin_Vertex.cpp;h=058b664b0f4792de9788bbb206056ef67e5676f0;hb=refs%2Fheads%2FCR35150;hp=d70bcc49761ce6b80324df941ac67a19ad03bdaa;hpb=3440b658f2f83d7ef920f3f37b2902ded180963b;p=modules%2Fshaper.git diff --git a/src/BuildPlugin/BuildPlugin_Vertex.cpp b/src/BuildPlugin/BuildPlugin_Vertex.cpp index d70bcc497..058b664b0 100644 --- a/src/BuildPlugin/BuildPlugin_Vertex.cpp +++ b/src/BuildPlugin/BuildPlugin_Vertex.cpp @@ -1,13 +1,39 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: BuildPlugin_Vertex.cpp -// Created: 18 April 2016 -// Author: Dmitry Bobylev +// Copyright (C) 2014-2023 CEA, EDF +// +// 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_Vertex.h" #include +#include +#include #include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include //================================================================================================= BuildPlugin_Vertex::BuildPlugin_Vertex() @@ -18,53 +44,120 @@ BuildPlugin_Vertex::BuildPlugin_Vertex() void BuildPlugin_Vertex::initAttributes() { data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId()); + + data()->addAttribute(INTERSECT_ID(), ModelAPI_AttributeBoolean::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), INTERSECT_ID()); } -//================================================================================================= -void BuildPlugin_Vertex::execute() +void BuildPlugin_Vertex::buildVertices(const ListOfShape& theShapes, bool isIntersect) { - // Get base objects list. - AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); - if(!aSelectionList.get()) { - setError("Error: Could not get selection list."); - return; - } - if(aSelectionList->size() == 0) { - setError("Error: Empty selection list."); - return; + GeomShapePtr aResult; + std::shared_ptr aPartitionAlgo; + if (isIntersect) { + aPartitionAlgo.reset(new GeomAlgoAPI_Partition(theShapes, ListOfShape())); + + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPartitionAlgo, getKind(), anError)) { + setError(anError); + return; + } + + aResult = aPartitionAlgo->shape(); } + else + aResult = GeomAlgoAPI_CompoundBuilder::compound(theShapes); - // Collect base shapes. - ListOfShape aListOfShapes; int aResultIndex = 0; - for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { - AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); - GeomShapePtr aShape = aSelection->value(); - if(!aShape.get()) { - ResultPtr aContext = aSelection->context(); - if(!aContext.get()) { - setError("Error: Attribute has empty context."); - return; - } - aShape = aContext->shape(); - } - if(!aShape.get()) { - setError("Error: Empty shape selected."); - return; - } + // Explode on vertices + std::set aProcessed; + for (GeomAPI_ShapeExplorer anExp(aResult, GeomAPI_Shape::VERTEX); anExp.more(); anExp.next()) { + GeomVertexPtr aVertex(new GeomAPI_Vertex(anExp.current())); + if (aProcessed.find(aVertex) != aProcessed.end()) + continue; // vertex is already processed + aProcessed.insert(aVertex); - if(aShape->shapeType() != GeomAPI_Shape::VERTEX) { - setError("Error: Selected shape has wrong type. Only vertices acceptable."); - return; - } + std::shared_ptr aCopy(new GeomAlgoAPI_Copy(aVertex)); + aVertex.reset(new GeomAPI_Vertex(aCopy->shape())); + + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + if (aPartitionAlgo) + aMakeShapeList->appendAlgo(aPartitionAlgo); + aMakeShapeList->appendAlgo(aCopy); // Store result. ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - aResultBody->store(aShape); + aResultBody->storeModified(theShapes, aVertex, aMakeShapeList); setResult(aResultBody, aResultIndex); ++aResultIndex; } removeResults(aResultIndex); } + +static void collectEdgesAndVertices(AttributeSelectionPtr theSelection, ListOfShape& thePrimitives) +{ + FeaturePtr aFeature = theSelection->contextFeature(); + ResultPtr aContext = theSelection->context(); + GeomShapePtr aShape = theSelection->value(); + if (aShape) + thePrimitives.push_back(aShape); + else { + if (aContext && !aFeature) + aFeature = ModelAPI_Feature::feature(aContext); + if (!aFeature) + return; + + // process results of the feature + const std::list& aResults = aFeature->results(); + std::list::const_iterator anIt = aResults.begin(); + for (; anIt != aResults.end(); ++anIt) + thePrimitives.push_back((*anIt)->shape()); + + CompositeFeaturePtr aComposite = + std::dynamic_pointer_cast(aFeature); + if (!aComposite) + return; + + // add construction points (centers of circles, etc.) + for (int i = 0, nbSubs = aComposite->numberOfSubs(); i < nbSubs; ++i) { + FeaturePtr aSubFeature = aComposite->subFeature(i); + const std::list& aSubResults = aSubFeature->results(); + // find all points + for (anIt = aSubResults.begin(); anIt != aSubResults.cend(); ++anIt) { + GeomShapePtr aSubResShape = (*anIt)->shape(); + if (aSubResShape->isVertex()) + thePrimitives.push_back(aSubResShape); + } + } + } +} + +void BuildPlugin_Vertex::execute() +{ + // Get base objects list. + AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); + if (!aSelectionList.get()) { + setError("Error: Could not get selection list."); + return; + } + if (aSelectionList->size() == 0) { + setError("Error: Empty selection list."); + return; + } + + // Get "Compute intersections" flag value + bool isIntersect = false; + if (boolean(INTERSECT_ID()).get() && boolean(INTERSECT_ID())->isInitialized()) { + isIntersect = boolean(INTERSECT_ID())->value(); + } + + // Iterate arguments and collect shapes + ListOfShape aShapes; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + collectEdgesAndVertices(aSelection, aShapes); + } + + buildVertices(aShapes, isIntersect); +}