X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Pipe.cpp;h=c3a38788782385f5fa00772b093daaa95fefc2fb;hb=d5c7ad3c50f89a2ddc2de1866ffb7f09397f3be2;hp=787a37fcc07b4582c88c90e030877961a9621da0;hpb=f98f887290d4e2b4bd6618389911e82b6b9674f3;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp b/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp index 787a37fcc..c3a387887 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: FeaturesPlugin_Pipe.cpp -// Created: 16 March 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 "FeaturesPlugin_Pipe.h" @@ -16,6 +29,8 @@ #include #include #include +#include + #include #include @@ -25,10 +40,8 @@ static void storeSubShape(ResultBodyPtr theResultBody, const GeomShapePtr theShape, const GeomAPI_Shape::ShapeType theType, - const std::shared_ptr theMapOfSubShapes, const std::string theName, - int& theShapeIndex, - int& theTag); + int& theShapeIndex); //================================================================================================== FeaturesPlugin_Pipe::FeaturesPlugin_Pipe() @@ -78,7 +91,8 @@ void FeaturesPlugin_Pipe::execute() GeomAPI_Shape::ShapeType aST = aBaseShape->shapeType(); ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aBaseObjectSelection->context()); - if(aConstruction.get() && !aBaseShape->isEqual(aConstruction->shape()) && aST == GeomAPI_Shape::WIRE) { + 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; @@ -88,7 +102,8 @@ void FeaturesPlugin_Pipe::execute() } } else { // This may be the whole sketch result selected, check and get faces. - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aBaseObjectSelection->context()); + ResultConstructionPtr aConstruction = + std::dynamic_pointer_cast(aBaseObjectSelection->context()); if(!aConstruction.get()) { setError("Error: One of selected sketches does not have results."); return; @@ -103,7 +118,8 @@ void FeaturesPlugin_Pipe::execute() } } else { for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) { - std::shared_ptr aBaseFace = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); + std::shared_ptr aBaseFace = + std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); if(!aBaseFace.get() || aBaseFace->isNull()) { setError("Error: One of the faces on selected sketch is Null."); return; @@ -130,12 +146,9 @@ void FeaturesPlugin_Pipe::execute() // Searching faces with common edges. if(aCreationMethod == CREATION_METHOD_SIMPLE()) { - ListOfShape aShells; - ListOfShape aFreeFaces; - std::shared_ptr aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseFacesList); - GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, aShells, aFreeFaces); - aBaseShapesList.insert(aBaseShapesList.end(), aFreeFaces.begin(), aFreeFaces.end()); - aBaseShapesList.insert(aBaseShapesList.end(), aShells.begin(), aShells.end()); + std::shared_ptr aFacesCompound = + GeomAlgoAPI_CompoundBuilder::compound(aBaseFacesList); + GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, aBaseShapesList); } else { aBaseShapesList.insert(aBaseShapesList.end(), aBaseFacesList.begin(), aBaseFacesList.end()); } @@ -146,9 +159,10 @@ void FeaturesPlugin_Pipe::execute() setError("Error: Path selection is empty."); return; } - std::shared_ptr aPathShape = std::dynamic_pointer_cast(aPathSelection->value()); - if(!aPathShape.get()) { - // Probaply it is a construction. + std::shared_ptr aPathShape = + std::dynamic_pointer_cast(aPathSelection->value()); + if(!aPathShape.get() && aPathSelection->context().get()) { + // Probably it is a construction. aPathShape = aPathSelection->context()->shape(); } if(!aPathShape.get() || aPathShape->isNull()) { @@ -165,7 +179,7 @@ void FeaturesPlugin_Pipe::execute() return; } aBiNormal = std::dynamic_pointer_cast(aBiNormalSelection->value()); - if(!aBiNormal.get()) { + if(!aBiNormal.get() && aBiNormalSelection->context().get()) { // Probably it is a construction. aBiNormal = aBiNormalSelection->context()->shape(); } @@ -190,7 +204,7 @@ void FeaturesPlugin_Pipe::execute() return; } std::shared_ptr aLocationShape = aLocationSelection->value(); - if(!aLocationShape.get()) { + if(!aLocationShape.get() && aLocationSelection->context().get()) { // Probably it is a construction. aLocationShape = aLocationSelection->context()->shape(); } @@ -204,56 +218,40 @@ void FeaturesPlugin_Pipe::execute() // Generating result for each object. int aResultIndex = 0; - if(aCreationMethod == CREATION_METHOD_SIMPLE() || aCreationMethod == CREATION_METHOD_BINORMAL()) { - for(ListOfShape::const_iterator anIter = aBaseShapesList.cbegin(); anIter != aBaseShapesList.cend(); anIter++) { + std::string anError; + if(aCreationMethod == CREATION_METHOD_SIMPLE() || + aCreationMethod == CREATION_METHOD_BINORMAL()) { + for(ListOfShape::const_iterator + anIter = aBaseShapesList.cbegin(); anIter != aBaseShapesList.cend(); anIter++) { std::shared_ptr aBaseShape = *anIter; - GeomAlgoAPI_Pipe aPipeAlgo = aCreationMethod == - CREATION_METHOD_SIMPLE() ? GeomAlgoAPI_Pipe(aBaseShape, aPathShape) : - GeomAlgoAPI_Pipe(aBaseShape, aPathShape, aBiNormal); + std::shared_ptr aPipeAlgo( + aCreationMethod == CREATION_METHOD_SIMPLE() ? new GeomAlgoAPI_Pipe(aBaseShape, + aPathShape) + : new GeomAlgoAPI_Pipe(aBaseShape, + aPathShape, + aBiNormal)); - if(!aPipeAlgo.isDone()) { - setError("Error: Pipe algorithm failed."); - aResultIndex = 0; - break; - } - - // Check if shape is valid - if(!aPipeAlgo.shape().get() || aPipeAlgo.shape()->isNull()) { - setError("Error: Resulting shape is Null."); - aResultIndex = 0; - break; - } - if(!aPipeAlgo.isValid()) { - setError("Error: Resulting shape is not valid."); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPipeAlgo, getKind(), anError)) { + setError(anError); aResultIndex = 0; break; } - storeResult(aBaseShape, aPipeAlgo, aResultIndex++); + storeResult(aBaseShape, aPathShape, aPipeAlgo, aResultIndex++); } } else if(aCreationMethod == CREATION_METHOD_LOCATIONS()) { - GeomAlgoAPI_Pipe aPipeAlgo = GeomAlgoAPI_Pipe(aBaseShapesList, aLocations, aPathShape); + std::shared_ptr aPipeAlgo(new GeomAlgoAPI_Pipe(aBaseShapesList, + aLocations, + aPathShape)); - if(!aPipeAlgo.isDone()) { - setError("Error: Pipe algorithm failed."); + if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPipeAlgo, getKind(), anError)) { + setError(anError); removeResults(0); return; } - // Check if shape is valid - if(!aPipeAlgo.shape().get() || aPipeAlgo.shape()->isNull()) { - setError("Error: Resulting shape is Null."); - removeResults(0); - return; - } - if(!aPipeAlgo.isValid()) { - setError("Error: Resulting shape is not valid."); - removeResults(0); - return; - } - - storeResult(aBaseShapesList, aPipeAlgo, aResultIndex++); + storeResult(aBaseShapesList, aPathShape, aPipeAlgo, aResultIndex++); } else { setError("Error: Wrong creation method."); return; @@ -264,22 +262,20 @@ void FeaturesPlugin_Pipe::execute() //================================================================================================== void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr theBaseShape, - GeomAlgoAPI_Pipe& thePipeAlgo, + const std::shared_ptr thePathShape, + const std::shared_ptr thePipeAlgo, const int theResultIndex) { // Create result body. ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex); // Store generated shape. - aResultBody->storeGenerated(theBaseShape, thePipeAlgo.shape()); + aResultBody->storeGenerated(theBaseShape, thePipeAlgo->shape()); // Store generated edges/faces. GeomAPI_Shape::ShapeType aBaseShapeType = theBaseShape->shapeType(); GeomAPI_Shape::ShapeType aShapeTypeToExplode; - int aGenTag = 1; - std::string aGenName = "Generated_"; - std::shared_ptr aMapOfSubShapes = thePipeAlgo.mapOfSubShapes(); switch(aBaseShapeType) { case GeomAPI_Shape::VERTEX: { aShapeTypeToExplode = GeomAPI_Shape::VERTEX; @@ -290,13 +286,13 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr theBa std::shared_ptr aV1, aV2; GeomAlgoAPI_ShapeTools::findBounds(theBaseShape, aV1, aV2); ListOfShape aV1History, aV2History; - thePipeAlgo.generated(aV1, aV1History); - thePipeAlgo.generated(aV2, aV2History); + thePipeAlgo->generated(aV1, aV1History); + thePipeAlgo->generated(aV2, aV2History); if(!aV1History.empty()) { - aResultBody->generated(aV1, aV1History.front(), aGenName + "Edge_1", aGenTag++); + aResultBody->generated(aV1, aV1History.front()); } if(!aV2History.empty()) { - aResultBody->generated(aV2, aV2History.front(), aGenName + "Edge_2", aGenTag++); + aResultBody->generated(aV2, aV2History.front()); } } case GeomAPI_Shape::FACE: @@ -309,52 +305,49 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr theBa } } - if(aShapeTypeToExplode == GeomAPI_Shape::VERTEX || aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) { - aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, GeomAPI_Shape::VERTEX, - aGenTag++, aGenName + "Edge", *aMapOfSubShapes.get()); + if(aShapeTypeToExplode == GeomAPI_Shape::VERTEX || + aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) { + aResultBody->loadGeneratedShapes(thePipeAlgo, theBaseShape, GeomAPI_Shape::VERTEX); } - if(aShapeTypeToExplode == GeomAPI_Shape::EDGE || aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) { - aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, GeomAPI_Shape::EDGE, - aGenTag++, aGenName + "Face", *aMapOfSubShapes.get()); + if(aShapeTypeToExplode == GeomAPI_Shape::EDGE || + aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) { + aResultBody->loadGeneratedShapes(thePipeAlgo, theBaseShape, GeomAPI_Shape::EDGE); } - - aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, aShapeTypeToExplode, aGenTag++, aGenName, *aMapOfSubShapes.get()); + if (thePathShape.get()) + aResultBody->loadGeneratedShapes(thePipeAlgo, thePathShape, GeomAPI_Shape::EDGE); // Store from shapes. - int aFromTag = aGenTag; - storeShapes(aResultBody, aBaseShapeType, aMapOfSubShapes, thePipeAlgo.fromShapes(), "From_", aFromTag); + storeShapes(aResultBody, aBaseShapeType, thePipeAlgo->fromShapes(), "From_"); // Store to shapes. - int aToTag = aFromTag; - storeShapes(aResultBody, aBaseShapeType, aMapOfSubShapes, thePipeAlgo.toShapes(), "To_", aToTag); + storeShapes(aResultBody, aBaseShapeType, thePipeAlgo->toShapes(), "To_"); setResult(aResultBody, theResultIndex); } //================================================================================================== void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes, - GeomAlgoAPI_Pipe& thePipeAlgo, + const std::shared_ptr thePathShape, + const std::shared_ptr thePipeAlgo, const int theResultIndex) { // Create result body. ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex); // Store generated shape. - aResultBody->storeGenerated(theBaseShapes.front(), thePipeAlgo.shape()); + aResultBody->storeGenerated(theBaseShapes.front(), thePipeAlgo->shape()); // Store generated edges/faces. - int aGenTag = 1; - std::shared_ptr aMapOfSubShapes = thePipeAlgo.mapOfSubShapes(); - - for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) { + for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); + anIter != theBaseShapes.cend(); + ++anIter) + { GeomShapePtr aBaseShape = *anIter; GeomAPI_Shape::ShapeType aBaseShapeType = aBaseShape->shapeType(); GeomAPI_Shape::ShapeType aShapeTypeToExplode; - std::string aGenName = "Generated_"; switch(aBaseShapeType) { case GeomAPI_Shape::VERTEX: { aShapeTypeToExplode = GeomAPI_Shape::VERTEX; - aGenName += "Edge"; break; } case GeomAPI_Shape::EDGE: @@ -362,28 +355,28 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes, std::shared_ptr aV1, aV2; GeomAlgoAPI_ShapeTools::findBounds(aBaseShape, aV1, aV2); ListOfShape aV1History, aV2History; - thePipeAlgo.generated(aV1, aV1History); - thePipeAlgo.generated(aV2, aV2History); - aResultBody->generated(aV1, aV1History.front(), aGenName + "Edge_1", aGenTag++); - aResultBody->generated(aV2, aV2History.front(), aGenName + "Edge_2", aGenTag++); + thePipeAlgo->generated(aV1, aV1History); + thePipeAlgo->generated(aV2, aV2History); + aResultBody->generated(aV1, aV1History.front()); + aResultBody->generated(aV2, aV2History.front()); } case GeomAPI_Shape::FACE: case GeomAPI_Shape::SHELL: { aShapeTypeToExplode = GeomAPI_Shape::EDGE; - aGenName += "Face"; break; } } - aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, aBaseShape, aShapeTypeToExplode, aGenTag++, aGenName, *aMapOfSubShapes.get()); + aResultBody->loadGeneratedShapes(thePipeAlgo, aBaseShape, aShapeTypeToExplode); } + if (thePathShape.get()) + aResultBody->loadGeneratedShapes(thePipeAlgo, thePathShape, GeomAPI_Shape::EDGE); + // Store from shapes. - int aFromTag = aGenTag; - storeShapes(aResultBody, theBaseShapes.front()->shapeType(), aMapOfSubShapes, thePipeAlgo.fromShapes(), "From", aFromTag); + storeShapes(aResultBody, theBaseShapes.front()->shapeType(), thePipeAlgo->fromShapes(), "From_"); // Store to shapes. - int aToTag = aFromTag; - storeShapes(aResultBody, theBaseShapes.back()->shapeType(), aMapOfSubShapes, thePipeAlgo.toShapes(), "To", aToTag); + storeShapes(aResultBody, theBaseShapes.back()->shapeType(), thePipeAlgo->toShapes(), "To_"); setResult(aResultBody, theResultIndex); @@ -392,10 +385,8 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes, //================================================================================================== void FeaturesPlugin_Pipe::storeShapes(ResultBodyPtr theResultBody, const GeomAPI_Shape::ShapeType theBaseShapeType, - const std::shared_ptr theMapOfSubShapes, const ListOfShape& theShapes, - const std::string theName, - int& theTag) + const std::string theName) { GeomAPI_Shape::ShapeType aShapeTypeToExplore = GeomAPI_Shape::FACE; std::string aShapeTypeStr = "Face"; @@ -431,17 +422,13 @@ void FeaturesPlugin_Pipe::storeShapes(ResultBodyPtr theResultBody, if(aShapeTypeToExplore == GeomAPI_Shape::COMPOUND) { std::string aName = theName + (aShape->shapeType() == GeomAPI_Shape::EDGE ? "Edge" : "Face"); - storeSubShape(theResultBody, - aShape, + storeSubShape(theResultBody, aShape, aShape->shapeType(), - theMapOfSubShapes, aName, - aShape->shapeType() == GeomAPI_Shape::EDGE ? aShapeIndex : aFaceIndex, - theTag); + aShape->shapeType() == GeomAPI_Shape::EDGE ? aShapeIndex : aFaceIndex); } else { std::string aName = theName + aShapeTypeStr; - storeSubShape(theResultBody, aShape, aShapeTypeToExplore, - theMapOfSubShapes, aName, aShapeIndex, theTag); + storeSubShape(theResultBody, aShape, aShapeTypeToExplore, aName, aShapeIndex); } } } @@ -450,18 +437,13 @@ void FeaturesPlugin_Pipe::storeShapes(ResultBodyPtr theResultBody, void storeSubShape(ResultBodyPtr theResultBody, const GeomShapePtr theShape, const GeomAPI_Shape::ShapeType theType, - const std::shared_ptr theMapOfSubShapes, const std::string theName, - int& theShapeIndex, - int& theTag) + int& theShapeIndex) { for(GeomAPI_ShapeExplorer anExp(theShape, theType); anExp.more(); anExp.next()) { GeomShapePtr aSubShape = anExp.current(); - if(theMapOfSubShapes->isBound(aSubShape)) { - aSubShape = theMapOfSubShapes->find(aSubShape); - } std::ostringstream aStr; aStr << theName << "_" << theShapeIndex++; - theResultBody->generated(aSubShape, aStr.str(), theTag++); + theResultBody->generated(aSubShape, aStr.str()); } }