From: dbv Date: Mon, 30 May 2016 14:18:27 +0000 (+0300) Subject: Allow Pipe on compounds with edges and faces. X-Git-Tag: V_2.3.1~27 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4577dab438f77747984a4da46e4a2fbb0e98ae62;p=modules%2Fshaper.git Allow Pipe on compounds with edges and faces. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index bf8cc53e2..476f15214 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -274,7 +274,6 @@ void FeaturesPlugin_CompositeSketch::storeGenerationHistory(ResultBodyPtr theRes switch(aBaseShapeType) { case GeomAPI_Shape::VERTEX: { aShapeTypeToExplode = GeomAPI_Shape::VERTEX; - aGenName += "Edge"; break; } case GeomAPI_Shape::EDGE: @@ -294,7 +293,6 @@ void FeaturesPlugin_CompositeSketch::storeGenerationHistory(ResultBodyPtr theRes case GeomAPI_Shape::FACE: case GeomAPI_Shape::SHELL: { aShapeTypeToExplode = GeomAPI_Shape::EDGE; - aGenName += "Face"; break; } case GeomAPI_Shape::COMPOUND: { @@ -395,4 +393,4 @@ void storeSubShape(ResultBodyPtr theResultBody, aStr << theName << "_" << theShapeIndex++; theResultBody->generated(aSubShape, aStr.str(), theTag++); } -} \ No newline at end of file +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp b/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp index 101034de0..ca171dd01 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Pipe.cpp @@ -22,12 +22,20 @@ #include #include -//================================================================================================= +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); + +//================================================================================================== FeaturesPlugin_Pipe::FeaturesPlugin_Pipe() { } -//================================================================================================= +//================================================================================================== void FeaturesPlugin_Pipe::initAttributes() { data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); @@ -41,7 +49,7 @@ void FeaturesPlugin_Pipe::initAttributes() ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATIONS_ID()); } -//================================================================================================= +//================================================================================================== void FeaturesPlugin_Pipe::execute() { // Getting creation method. @@ -253,7 +261,7 @@ void FeaturesPlugin_Pipe::execute() removeResults(aResultIndex); } -//================================================================================================= +//================================================================================================== void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr theBaseShape, GeomAlgoAPI_Pipe& thePipeAlgo, const int theResultIndex) @@ -274,7 +282,6 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr theBa switch(aBaseShapeType) { case GeomAPI_Shape::VERTEX: { aShapeTypeToExplode = GeomAPI_Shape::VERTEX; - aGenName += "Edge"; break; } case GeomAPI_Shape::EDGE: @@ -294,10 +301,22 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr theBa case GeomAPI_Shape::FACE: case GeomAPI_Shape::SHELL: { aShapeTypeToExplode = GeomAPI_Shape::EDGE; - aGenName += "Face"; break; } + case GeomAPI_Shape::COMPOUND: { + aShapeTypeToExplode = GeomAPI_Shape::COMPOUND; + } + } + + 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::EDGE || aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) { + aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, GeomAPI_Shape::EDGE, + aGenTag++, aGenName + "Face", *aMapOfSubShapes.get()); } + aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, aShapeTypeToExplode, aGenTag++, aGenName, *aMapOfSubShapes.get()); // Store from shapes. @@ -311,7 +330,7 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr theBa setResult(aResultBody, theResultIndex); } -//================================================================================================= +//================================================================================================== void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes, GeomAlgoAPI_Pipe& thePipeAlgo, const int theResultIndex) @@ -369,7 +388,7 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes, setResult(aResultBody, theResultIndex); } -//================================================================================================= +//================================================================================================== void FeaturesPlugin_Pipe::storeShapes(ResultBodyPtr theResultBody, const GeomAPI_Shape::ShapeType theBaseShapeType, const std::shared_ptr theMapOfSubShapes, @@ -397,21 +416,51 @@ void FeaturesPlugin_Pipe::storeShapes(ResultBodyPtr theResultBody, aShapeTypeStr = "Face"; break; } + case GeomAPI_Shape::COMPOUND: { + aShapeTypeToExplore = GeomAPI_Shape::COMPOUND; + break; + } } // Store shapes. int aShapeIndex = 1; - std::string aName = theName + aShapeTypeStr; + int aFaceIndex = 1; for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) { - std::shared_ptr aShape = *anIt; - for(GeomAPI_ShapeExplorer anExp(aShape, aShapeTypeToExplore); anExp.more(); anExp.next()) { - std::shared_ptr aSubShape = anExp.current(); - if(theMapOfSubShapes->isBound(aSubShape)) { - aSubShape = theMapOfSubShapes->find(aSubShape); - } - std::ostringstream aStr; - aStr << aName << "_" << aShapeIndex++; - theResultBody->generated(aSubShape, aStr.str(), theTag++); + GeomShapePtr aShape = *anIt; + + if(aShapeTypeToExplore == GeomAPI_Shape::COMPOUND) { + std::string aName = theName + (aShape->shapeType() == GeomAPI_Shape::EDGE ? "Edge" : "Face"); + storeSubShape(theResultBody, + aShape, + aShape->shapeType(), + theMapOfSubShapes, + aName, + aShape->shapeType() == GeomAPI_Shape::EDGE ? aShapeIndex : aFaceIndex, + theTag); + } else { + std::string aName = theName + aShapeTypeStr; + storeSubShape(theResultBody, aShape, aShapeTypeToExplore, + theMapOfSubShapes, aName, aShapeIndex, theTag); + } + } +} + +//================================================================================================== +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) +{ + 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++); } } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp index c24a9600e..04b310006 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp @@ -30,15 +30,16 @@ static bool getBase(TopoDS_Shape& theBaseOut, static bool getPath(TopoDS_Wire& thePathOut, const GeomShapePtr thePathShape); static bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder); +static ListOfShape getListFromShape(const TopoDS_Shape& theShape); -//================================================================================================= +//================================================================================================== GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape) { build(theBaseShape, thePathShape); } -//================================================================================================= +//================================================================================================== GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape, const GeomShapePtr theBiNormal) @@ -46,7 +47,7 @@ GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const GeomShapePtr theBaseShape, build(theBaseShape, thePathShape, theBiNormal); } -//================================================================================================= +//================================================================================================== GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const ListOfShape& theBaseShapes, const ListOfShape& theLocations, const GeomShapePtr thePathShape) @@ -54,7 +55,7 @@ GeomAlgoAPI_Pipe::GeomAlgoAPI_Pipe(const ListOfShape& theBaseShapes, build(theBaseShapes, theLocations, thePathShape); } -//================================================================================================= +//================================================================================================== void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape) { @@ -69,7 +70,7 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, TopAbs_ShapeEnum aBaseShapeType = aBaseShape.ShapeType(); if(aBaseShapeType != TopAbs_VERTEX && aBaseShapeType != TopAbs_EDGE && aBaseShapeType != TopAbs_WIRE && aBaseShapeType != TopAbs_FACE && - aBaseShapeType != TopAbs_SHELL) { + aBaseShapeType != TopAbs_SHELL && aBaseShapeType != TopAbs_COMPOUND) { return; } @@ -94,11 +95,8 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, this->initialize(aPipeBuilder); // Setting naming. - GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); - aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape())); - aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape())); - this->addFromShape(aFromShape); - this->addToShape(aToShape); + this->setToShapes(getListFromShape(aPipeBuilder->LastShape())); + this->setFromShapes(getListFromShape(aPipeBuilder->FirstShape())); // Setting result. TopoDS_Shape aResult = aPipeBuilder->Shape(); @@ -109,7 +107,7 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, this->setDone(true); } -//================================================================================================= +//================================================================================================== void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, const GeomShapePtr thePathShape, const GeomShapePtr theBiNormal) @@ -164,18 +162,15 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, } } TopoDS_Shape aResult = aPipeBuilder->Shape(); + if(aResult.IsNull()) { + return; + } // Setting naming. - GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); - aFromShape->setImpl(new TopoDS_Shape(aPipeBuilder->FirstShape())); - aToShape->setImpl(new TopoDS_Shape(aPipeBuilder->LastShape())); - this->addFromShape(aFromShape); - this->addToShape(aToShape); + this->setToShapes(getListFromShape(aPipeBuilder->LastShape())); + this->setFromShapes(getListFromShape(aPipeBuilder->FirstShape())); // Setting result. - if(aResult.IsNull()) { - return; - } aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aResult)); @@ -183,7 +178,7 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, this->setDone(true); } -//================================================================================================= +//================================================================================================== void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, const ListOfShape& theLocations, const GeomShapePtr thePathShape) @@ -275,7 +270,7 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, this->setDone(true); } -//================================================================================================= +//================================================================================================== void GeomAlgoAPI_Pipe::generated(const GeomShapePtr theShape, ListOfShape& theHistory) { @@ -283,7 +278,7 @@ void GeomAlgoAPI_Pipe::generated(const GeomShapePtr theShape, } // Auxilary functions: -//================================================================================================= +//================================================================================================== bool getBase(TopoDS_Shape& theBaseOut, TopAbs_ShapeEnum& theBaseTypeOut, const GeomShapePtr theBaseShape) @@ -313,7 +308,7 @@ bool getBase(TopoDS_Shape& theBaseOut, return true; } -//================================================================================================= +//================================================================================================== bool getPath(TopoDS_Wire& thePathOut, const GeomShapePtr thePathShape) { @@ -338,7 +333,7 @@ bool getPath(TopoDS_Wire& thePathOut, return true; } -//================================================================================================= +//================================================================================================== bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder) { thePipeBuilder->Build(); @@ -354,3 +349,24 @@ bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder) return isDone == Standard_True; } + +//================================================================================================== +ListOfShape getListFromShape(const TopoDS_Shape& theShape) +{ + ListOfShape aList; + + TopAbs_ShapeEnum aType = theShape.ShapeType(); + if(aType == TopAbs_WIRE || aType == TopAbs_SHELL || aType == TopAbs_COMPOUND) { + for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next()) { + GeomShapePtr aGeomShape(new GeomAPI_Shape()); + aGeomShape->setImpl(new TopoDS_Shape(anIt.Value())); + aList.push_back(aGeomShape); + } + } else { + GeomShapePtr aGeomShape(new GeomAPI_Shape()); + aGeomShape->setImpl(new TopoDS_Shape(theShape)); + aList.push_back(aGeomShape); + } + + return aList; +}