X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Tools.cpp;h=55a1738426044d18276c31f08beaa65c2c16d58c;hb=00e7032c437ca3e2e47996307b679505794842c1;hp=efdee580134ed3afa36a9cb0b81da35e8df9655b;hpb=d4b0a5cb916f4eccf4a0bce02e43a54c7a67cb93;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp b/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp index efdee5801..55a173842 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Tools.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// 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 @@ -12,46 +12,49 @@ // // 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 "FeaturesPlugin_Tools.h" +#include #include +#include +#include +#include + +#include #include //================================================================================================== void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody, - const GeomShapePtr theBaseShape, + const ListOfShape& theBaseShapes, const ListOfShape& theTools, const GeomMakeShapePtr& theMakeShape, - const GeomShapePtr theResultShape) + const GeomShapePtr theResultShape, + const std::string& theNamePrefix) { - if (theBaseShape->isEqual(theResultShape)) { - theResultBody->store(theResultShape, false); - return; - } - - theResultBody->storeModified(theBaseShape, theResultShape); + theResultBody->storeModified(theBaseShapes, theResultShape, theMakeShape); - ListOfShape aShapes = theTools; - aShapes.push_front(theBaseShape); + ListOfShape aShapes = theBaseShapes; + ListOfShape::const_iterator aToolIter = theTools.cbegin(); + for(; aToolIter != theTools.cend(); aToolIter++) + aShapes.push_back(*aToolIter); for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); ++anIter) { - theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::VERTEX); - theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::EDGE); - theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE); + theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::VERTEX, theNamePrefix); + theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::EDGE, theNamePrefix); + theResultBody->loadModifiedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE, theNamePrefix); } } //================================================================================================== void FeaturesPlugin_Tools::loadModifiedShapes(ResultBodyPtr theResultBody, - const GeomShapePtr theBaseShape, + const GeomShapePtr& theBaseShape, const GeomMakeShapePtr& theMakeShape, const std::string theName) { @@ -98,7 +101,8 @@ void FeaturesPlugin_Tools::loadDeletedShapes(ResultBodyPtr theResultBody, const GeomShapePtr theResultShapesCompound) { ListOfShape aShapes = theTools; - aShapes.push_front(theBaseShape); + if (theBaseShape.get()) + aShapes.push_front(theBaseShape); for (ListOfShape::const_iterator anIter = aShapes.begin(); anIter != aShapes.end(); anIter++) { @@ -135,3 +139,105 @@ void FeaturesPlugin_Tools::loadDeletedShapes( theResultShapesCompound); } } + +//================================================================================================== +bool FeaturesPlugin_Tools::getShape(const AttributeSelectionListPtr theSelectionList, + const bool theShareTopology, + ListOfShape& theShapesList, + std::string& theError) +{ + theShapesList.clear(); + + ListOfShape aBaseFacesList; + std::map aSketchWiresMap; + if(!theSelectionList.get()) { + theError = "Error: Could not get base objects selection list."; + return false; + } + if(theSelectionList->size() == 0) { + theError = "Error: Base objects list is empty."; + return false; + } + for(int anIndex = 0; anIndex < theSelectionList->size(); anIndex++) { + AttributeSelectionPtr aBaseObjectSelection = theSelectionList->value(anIndex); + if(!aBaseObjectSelection.get()) { + theError = "Error: Selected base object is empty."; + return false; + } + GeomShapePtr aBaseShape = aBaseObjectSelection->value(); + if(aBaseShape.get() && !aBaseShape->isNull()) { + GeomAPI_Shape::ShapeType aST = aBaseShape->shapeType(); + if(aST == GeomAPI_Shape::SOLID || aST == GeomAPI_Shape::COMPSOLID) { + theError = "Error: Selected shapes has unsupported type."; + return false; + } + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aBaseObjectSelection->context()); + if(aConstruction.get() && !aBaseShape->isEqual(aConstruction->shape()) && + aST == GeomAPI_Shape::WIRE) { + // It is a wire on the sketch, store it to make face later. + aSketchWiresMap[aConstruction].push_back(aBaseShape); + continue; + } else { + aST == GeomAPI_Shape::FACE ? aBaseFacesList.push_back(aBaseShape) : + theShapesList.push_back(aBaseShape); + } + } else { + // This may be the whole sketch result selected, check and get faces. + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aBaseObjectSelection->context()); + if(!aConstruction.get()) { + theError = "Error: Selected sketches does not have results."; + return false; + } + int aFacesNum = aConstruction->facesNum(); + if(aFacesNum == 0) { + // Probably it can be construction. + aBaseShape = aConstruction->shape(); + if(aBaseShape.get() && !aBaseShape->isNull()) { + GeomAPI_Shape::ShapeType aST = aBaseShape->shapeType(); + if(aST != GeomAPI_Shape::VERTEX && aST != GeomAPI_Shape::EDGE && + aST != GeomAPI_Shape::WIRE && + aST != GeomAPI_Shape::FACE && aST != GeomAPI_Shape::SHELL) { + theError = "Error: Selected shapes has unsupported type."; + return false; + } + aST == GeomAPI_Shape::FACE ? aBaseFacesList.push_back(aBaseShape) : + theShapesList.push_back(aBaseShape); + } + } else { + for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) { + GeomShapePtr aBaseFace = aConstruction->face(aFaceIndex); + if(!aBaseFace.get() || aBaseFace->isNull()) { + theError = "Error: One of the faces on selected sketch is null."; + return false; + } + aBaseFacesList.push_back(aBaseFace); + } + } + } + } + + // Make faces from sketch wires. + for(std::map::const_iterator anIt = aSketchWiresMap.cbegin(); + anIt != aSketchWiresMap.cend(); ++anIt) { + const std::shared_ptr aSketchPlanarEdges = + std::dynamic_pointer_cast((*anIt).first->shape()); + const ListOfShape& aWiresList = (*anIt).second; + ListOfShape aFaces; + GeomAlgoAPI_ShapeTools::makeFacesWithHoles(aSketchPlanarEdges->origin(), + aSketchPlanarEdges->norm(), + aWiresList, + aFaces); + aBaseFacesList.insert(aBaseFacesList.end(), aFaces.begin(), aFaces.end()); + } + + // Searching faces with common edges. + if(theShareTopology && aBaseFacesList.size() > 1) { + GeomShapePtr aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseFacesList); + GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, theShapesList); + } else { + theShapesList.insert(theShapesList.end(), aBaseFacesList.begin(), aBaseFacesList.end()); + } + return true; +}