X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBuildPlugin%2FBuildPlugin_Vertex.cpp;h=4632aa3ef33f72d5bc09604bcd3c2c90f235d22a;hb=77ce6d35ac8d2f0fdaecb4f23e0870bf74e36103;hp=536d442a71de21b0f4c450fd964da680c5ca5e28;hpb=2532fb2df83ee1ddd9ff3e8b381d3788eaa15b69;p=modules%2Fshaper.git diff --git a/src/BuildPlugin/BuildPlugin_Vertex.cpp b/src/BuildPlugin/BuildPlugin_Vertex.cpp index 536d442a7..4632aa3ef 100644 --- a/src/BuildPlugin/BuildPlugin_Vertex.cpp +++ b/src/BuildPlugin/BuildPlugin_Vertex.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2024 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,17 +12,28 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// 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() @@ -33,74 +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; - } - - // 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; - } + GeomShapePtr aResult; + std::shared_ptr aPartitionAlgo; + if (isIntersect) { + aPartitionAlgo.reset(new GeomAlgoAPI_Partition(theShapes, ListOfShape())); - aShape = aContext->shape(); - } - if(!aShape.get()) { - setError("Error: Empty shape selected."); + std::string anError; + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPartitionAlgo, getKind(), anError)) { + setError(anError); return; } - if(aShape->shapeType() != GeomAPI_Shape::VERTEX) { - setError("Error: Selected shape has wrong type. Only vertices acceptable."); - return; - } + aResult = aPartitionAlgo->shape(); + } + else + aResult = GeomAlgoAPI_CompoundBuilder::compound(theShapes); - // Copy shape. - GeomAlgoAPI_Copy aCopyAlgo(aShape); + int aResultIndex = 0; - // Check that algo is done. - if(!aCopyAlgo.isDone()) { - setError("Error: " + getKind() + " algorithm failed."); - 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); - // Check if shape is not null. - if(!aCopyAlgo.shape().get() || aCopyAlgo.shape()->isNull()) { - setError("Error: Resulting shape is null."); - return; - } + std::shared_ptr aCopy(new GeomAlgoAPI_Copy(aVertex)); + aVertex.reset(new GeomAPI_Vertex(aCopy->shape())); - // Check that resulting shape is valid. - if(!aCopyAlgo.isValid()) { - setError("Error: Resulting shape is not valid."); - return; - } + std::shared_ptr aMakeShapeList(new GeomAlgoAPI_MakeShapeList); + if (aPartitionAlgo) + aMakeShapeList->appendAlgo(aPartitionAlgo); + aMakeShapeList->appendAlgo(aCopy); // Store result. ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - aResultBody->storeModified(aShape, aCopyAlgo.shape()); + 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); +}