From: dbv Date: Fri, 29 May 2015 11:40:52 +0000 (+0300) Subject: Algo fixes X-Git-Tag: V_1.2.0~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=98c1bd47dd95b02b7c512f9fb8b368ef21037635;p=modules%2Fshaper.git Algo fixes --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp index 304d3748a..edf556918 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp @@ -21,10 +21,11 @@ #include #include -#define _LATERAL_TAG 1 +#define FACE 4 +#define EDGE 6 +#define _GENERATE_TAG 1 #define _FIRST_TAG 2 #define _LAST_TAG 3 -#define EDGE 6 //================================================================================================= FeaturesPlugin_Revolution::FeaturesPlugin_Revolution() @@ -158,10 +159,6 @@ void FeaturesPlugin_Revolution::LoadNamingDS(GeomAlgoAPI_Revolution& theFeature, std::shared_ptr theBasis, std::shared_ptr theContext) { - //TODO: Fix naming - theResultBody->store(theFeature.shape()); - return; - //load result if(theBasis->isEqual(theContext)) theResultBody->store(theFeature.shape()); @@ -171,27 +168,27 @@ void FeaturesPlugin_Revolution::LoadNamingDS(GeomAlgoAPI_Revolution& theFeature, GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); theFeature.mapOfShapes(*aSubShapes); - //Insert lateral face : Face from Edge - std::string aLatName = "LateralFace"; - theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes); - - ////Insert first face - //std::string aBotName = "FirstFace"; - //std::shared_ptr aBottomFace = theFeature.firstShape(); - //if(!aBottomFace->isNull()) { - // if(aSubShapes->isBound(aBottomFace)) { - // aBottomFace = aSubShapes->find(aBottomFace); - // } - // theResultBody->generated(aBottomFace, aBotName, _FIRST_TAG); - //} - - ////Insert last face - //std::string aTopName = "LastFace"; - //std::shared_ptr aTopFace = theFeature.lastShape(); - //if (!aTopFace->isNull()) { - // if (aSubShapes->isBound(aTopFace)) { - // aTopFace = aSubShapes->find(aTopFace); - // } - // theResultBody->generated(aTopFace, aTopName, _LAST_TAG); - //} + std::string aGeneratedName = "Generated"; + theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_GENERATE_TAG, aGeneratedName, *aSubShapes); + + //Insert bottom face + std::string aBotName = "FromFace"; + std::shared_ptr aBottomFace = theFeature.firstShape(); + if(!aBottomFace->isNull()) { + if(aSubShapes->isBound(aBottomFace)) { + aBottomFace = aSubShapes->find(aBottomFace); + } + theResultBody->generated(aBottomFace, aBotName, _FIRST_TAG); + } + + //Insert top face + std::string aTopName = "ToFace"; + std::shared_ptr aTopFace = theFeature.lastShape(); + if (!aTopFace->isNull()) { + if (aSubShapes->isBound(aTopFace)) { + aTopFace = aSubShapes->find(aTopFace); + } + theResultBody->generated(aTopFace, aTopName, _LAST_TAG); + } + } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp index d5c050caa..618bc7c96 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp @@ -26,16 +26,16 @@ GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList(const ListOfMakeShape& theM //================================================================================================= void GeomAlgoAPI_MakeShapeList::init(const ListOfMakeShape& theMakeShapeList) { - myMakeShapeList = theMakeShapeList; + myListOfMakeShape = theMakeShapeList; } //================================================================================================= const std::shared_ptr GeomAlgoAPI_MakeShapeList::shape() const { - if(myMakeShapeList.empty()) { + if(myListOfMakeShape.empty()) { return std::shared_ptr(); } else { - return myMakeShapeList.back()->shape(); + return myListOfMakeShape.back()->shape(); } } @@ -53,34 +53,54 @@ void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr th result(theShape, theHistory, GeomAlgoAPI_MakeShapeList::Modified); } +bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr theShape) +{ + for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) { + BRepBuilderAPI_MakeShape* aBuilder = (*aBuilderIt)->implPtr(); + if(aBuilder && (aBuilder->IsDeleted(theShape->impl()) == Standard_True)) { + return true; + } + } + + return false; +} + void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr theShape, ListOfShape& theHistory, OperationType theOperationType) { - if(myMakeShapeList.empty()) { + if(myListOfMakeShape.empty()) { return; } - NCollection_Map aTempShapes; + NCollection_Map anAlgoShapes; NCollection_Map aResultShapes; - aTempShapes.Add(theShape->impl()); + anAlgoShapes.Add(theShape->impl()); + aResultShapes.Add(theShape->impl()); - for(ListOfMakeShape::iterator aBuilderIt = myMakeShapeList.begin(); aBuilderIt != myMakeShapeList.end(); aBuilderIt++) { + for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) { BRepBuilderAPI_MakeShape* aBuilder = (*aBuilderIt)->implPtr(); - for(NCollection_Map::Iterator aShapeIt(aTempShapes); aShapeIt.More(); aShapeIt.Next()) { + NCollection_Map aTempShapes; + bool hasResults = false; + for(NCollection_Map::Iterator aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) { const TopoDS_Shape& aShape = aShapeIt.Value(); - const TopTools_ListOfShape& aList = theOperationType == GeomAlgoAPI_MakeShapeList::Generated ? - aBuilder->Generated(aShape) : aBuilder->Modified(aShape); - bool prevResRemoved = false; - for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) { + const TopTools_ListOfShape& aGeneratedList = aBuilder->Generated(aShape); + const TopTools_ListOfShape& aModifiedList = aBuilder->Modified(aShape); + for(TopTools_ListIteratorOfListOfShape anIt(aGeneratedList); anIt.More(); anIt.Next()) { aTempShapes.Add(anIt.Value()); aResultShapes.Add(anIt.Value()); - if(!prevResRemoved) { - aResultShapes.Remove(aShape); - prevResRemoved = true; - } + hasResults = true; + } + for(TopTools_ListIteratorOfListOfShape anIt(aModifiedList); anIt.More(); anIt.Next()) { + aTempShapes.Add(anIt.Value()); + aResultShapes.Add(anIt.Value()); + hasResults = true; + } + if(hasResults) { + aResultShapes.Remove(aShape); } } + anAlgoShapes.Unite(aTempShapes); } for(NCollection_Map::Iterator aShapeIt(aResultShapes); aShapeIt.More(); aShapeIt.Next()) { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h index 8d7975071..7de577350 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h @@ -48,6 +48,9 @@ public: GEOMALGOAPI_EXPORT virtual void modified(const std::shared_ptr theShape, ListOfShape& theHistory); + /// Returns whether the shape is deleted + GEOMALGOAPI_EXPORT virtual bool isDeleted(const std::shared_ptr theShape); + private: void result(const std::shared_ptr theShape, ListOfShape& theHistory, @@ -55,7 +58,7 @@ private: protected: - ListOfMakeShape myMakeShapeList; + ListOfMakeShape myListOfMakeShape; }; #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index a608373d7..9c60540a9 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -117,24 +118,33 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi gp_Pln aBasisPln = isBasisPlanar.Plan(); gp_Ax1 anAxis = myAxis->impl(); + ListOfMakeShape aListOfMakeShape; + TopoDS_Shape aResult; if(!myFromShape && !myToShape) { // Case 1: When only angles was set. // Rotating base face with the negative value of "from angle". - GeomAlgoAPI_Rotation aRotation(theBasis, myAxis, -myFromAngle); - TopoDS_Shape aRotatedBaseShape = aRotation.shape()->impl(); + gp_Trsf aBaseTrsf; + aBaseTrsf.SetRotation(anAxis, -myFromAngle / 180.0 * M_PI); + BRepBuilderAPI_Transform* aBaseTransform = new BRepBuilderAPI_Transform(aBasisFace, + aBaseTrsf, + true); + aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBaseTransform))); + TopoDS_Shape aRotatedBaseShape = aBaseTransform->Shape(); // Making revolution to the angle equal to the sum of "from angle" and "to angle". double anAngle = myFromAngle + myToAngle; - BRepPrimAPI_MakeRevol aRevolBuilder(aRotatedBaseShape, - anAxis, - anAngle / 180 * M_PI, - Standard_True); - aRevolBuilder.Build(); - if(!aRevolBuilder.IsDone()) { + BRepPrimAPI_MakeRevol* aRevolBuilder = new BRepPrimAPI_MakeRevol(aRotatedBaseShape, + anAxis, + anAngle / 180 * M_PI, + Standard_True); + aRevolBuilder->Build(); + if(!aRevolBuilder->IsDone()) { return; } - - aResult = aRevolBuilder.Shape(); + aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aRevolBuilder))); + aResult = aRevolBuilder->Shape(); + myFirst->setImpl(new TopoDS_Shape(aRevolBuilder->FirstShape())); + myLast->setImpl(new TopoDS_Shape(aRevolBuilder->LastShape())); } else if(myFromShape && myToShape) { // Case 2: When both bounding planes were set. // Getting bounding faces. TopoDS_Face aFromFace = TopoDS::Face(myFromShape->impl()); @@ -169,28 +179,42 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi BRepBuilderAPI_Transform aFromTransform(aFromSolid, aFromTrsf, true); BRepBuilderAPI_Transform aToTransform(aToSolid, aToTrsf, true); aFromSolid = aFromTransform.Shape(); + TopoDS_Shape aRotatedFromFace = aFromTransform.Modified(aFromFace).First(); + TopoDS_Shape aRotatedToFace = aToTransform.Modified(aToFace).First(); aToSolid = aToTransform.Shape(); // Making revolution to the 360 angle. - BRepPrimAPI_MakeRevol aRevolBuilder(aBasisFace, anAxis, 2 * M_PI, Standard_True); - aRevolBuilder.Build(); - TopoDS_Shape aRevolShape = aRevolBuilder.Shape(); + BRepPrimAPI_MakeRevol* aRevolBuilder = new BRepPrimAPI_MakeRevol(aBasisFace, anAxis, 2 * M_PI, Standard_True); + aRevolBuilder->Build(); + aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aRevolBuilder))); + TopoDS_Shape aRevolShape = aRevolBuilder->Shape(); // Cutting revolution with from plane. - BRepAlgoAPI_Cut aFromCutBuilder(aRevolShape, aFromSolid); - aFromCutBuilder.Build(); - if(!aFromCutBuilder.IsDone()) { + BRepAlgoAPI_Cut* aFromCutBuilder = new BRepAlgoAPI_Cut(aRevolShape, aFromSolid); + aFromCutBuilder->Build(); + if(!aFromCutBuilder->IsDone()) { return; } - aResult = aFromCutBuilder.Shape(); + aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aFromCutBuilder))); + aResult = aFromCutBuilder->Shape(); + if(aFromCutBuilder->Modified(aRotatedFromFace).Extent() > 0) { + myFirst->setImpl(new TopoDS_Shape(aFromCutBuilder->Modified(aRotatedFromFace).First())); + } // Cutting revolution with to plane. - BRepAlgoAPI_Cut aToCutBuilder(aResult, aToSolid); - aToCutBuilder.Build(); - if(!aToCutBuilder.IsDone()) { + BRepAlgoAPI_Cut* aToCutBuilder = new BRepAlgoAPI_Cut(aResult, aToSolid); + aToCutBuilder->Build(); + if(!aToCutBuilder->IsDone()) { return; } - aResult = aToCutBuilder.Shape(); + aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aToCutBuilder))); + aResult = aToCutBuilder->Shape(); + if(aToCutBuilder->Modified(aRotatedToFace).Extent() > 0) { + myLast->setImpl(new TopoDS_Shape(aToCutBuilder->Modified(aRotatedToFace).First())); + } + if(aToCutBuilder->Modified(myFirst->impl()).Extent() > 0) { + myFirst->setImpl(new TopoDS_Shape(aToCutBuilder->Modified(myFirst->impl()).First())); + } // If after cut we got more than one solids then take closest to the center of mass of the base face. aResult = findClosest(aResult, aBasisCentr); @@ -238,19 +262,25 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi aBoundingSolid = aBoundingTransform.Shape(); // Making revolution to the 360 angle. - BRepPrimAPI_MakeRevol aRevolBuilder(aBasisFace, anAxis, 2 * M_PI, Standard_True); - aRevolBuilder.Build(); - TopoDS_Shape aRevolShape = aRevolBuilder.Shape(); + BRepPrimAPI_MakeRevol* aRevolBuilder = new BRepPrimAPI_MakeRevol(aBasisFace, anAxis, 2 * M_PI, Standard_True); + aRevolBuilder->Build(); + aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aRevolBuilder))); + TopoDS_Shape aRevolShape = aRevolBuilder->Shape(); // Cutting revolution with bounding plane. - BRepAlgoAPI_Cut aFromCutBuilder(aRevolShape, aBoundingSolid); - aFromCutBuilder.Build(); - if(!aFromCutBuilder.IsDone()) { + BRepAlgoAPI_Cut* aBoundingCutBuilder = new BRepAlgoAPI_Cut(aRevolShape, aBoundingSolid); + aBoundingCutBuilder->Build(); + if(!aBoundingCutBuilder->IsDone()) { return; } + aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBoundingCutBuilder))); + aResult = aBoundingCutBuilder->Shape(); + TopExp_Explorer anExp1(aResult, TopAbs_SOLID); + if(aBoundingCutBuilder->Modified(aBoundingFace).Extent() > 0) { + myLast->setImpl(new TopoDS_Shape(aBoundingCutBuilder->Modified(aBoundingFace).First())); + } // Try to cut with base face. If it can not be done then keep result of cut with bounding plane. - aResult = aFromCutBuilder.Shape(); if(isFromFaceSet) { aBasisFace.Orientation(TopAbs_REVERSED); } @@ -266,13 +296,17 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi aBasisSolid = aBasisTransform.Shape(); // Cutting revolution with basis face. - BRepAlgoAPI_Cut aBasisCutBuilder(aResult, aBasisSolid); - aBasisCutBuilder.Build(); - if(aBasisCutBuilder.IsDone()) { - TopoDS_Shape aCutResult = aBasisCutBuilder.Shape(); + BRepAlgoAPI_Cut* aBasisCutBuilder = new BRepAlgoAPI_Cut(aResult, aBasisSolid); + aBasisCutBuilder->Build(); + if(aBasisCutBuilder->IsDone()) { + TopoDS_Shape aCutResult = aBasisCutBuilder->Shape(); TopExp_Explorer anExp(aCutResult, TopAbs_SOLID); if(anExp.More()) { + aListOfMakeShape.push_back(std::shared_ptr(new GeomAlgoAPI_MakeShape(aBasisCutBuilder))); aResult = aCutResult; + if(aBasisCutBuilder->Modified(aBasisFace).Extent() > 0) { + myFirst->setImpl(new TopoDS_Shape(aBasisCutBuilder->Modified(aBasisFace).First())); + } } } @@ -286,15 +320,13 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr& theBasi } // fill data map to keep correct orientation of sub-shapes - //for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { - // std::shared_ptr aCurrentShape(new GeomAPI_Shape()); - // aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current())); - // myMap.bind(aCurrentShape, aCurrentShape); - //} + for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current())); + myMap.bind(aCurrentShape, aCurrentShape); + } myShape->setImpl(new TopoDS_Shape(aResult)); - //myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First())); - //myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First())); - //myMkShape = new GeomAlgoAPI_MakeShape (aBuilder); + myMkShape = new GeomAlgoAPI_MakeShapeList(aListOfMakeShape); myDone = true; return; }