]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fixes for naming in revolution
authordbv <dbv@opencascade.com>
Fri, 8 Apr 2016 08:19:47 +0000 (11:19 +0300)
committerdbv <dbv@opencascade.com>
Fri, 8 Apr 2016 08:19:58 +0000 (11:19 +0300)
src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp

index 45e0adfebd1e93672ab87a0ea390d4a417535411..510668afa144cbe66e3ea04d4212292953a8149f 100644 (file)
@@ -110,25 +110,30 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr&                theBaseShape,
   }
 
   // Getting direction.
-  gp_Pnt aLoc;
   gp_Vec aDirVec;
   std::shared_ptr<GeomAPI_Pnt> aBaseLoc;
   std::shared_ptr<GeomAPI_Dir> aBaseDir;
   GeomShapePtr aBasePlane;
   const bool isBoundingShapesSet = theFromShape.get() || theToShape.get();
   BRepBuilderAPI_FindPlane aFindPlane(aBaseShape);
-  if(aBaseShape.ShapeType() == TopAbs_VERTEX || aBaseShape.ShapeType() == TopAbs_EDGE ||
-     aFindPlane.Found() != Standard_True) {
-    // Direction should be set.
-    if(!theDirection.get()) {
-      return;
-    }
-
+  if(theDirection.get()) {
     aBaseDir = theDirection;
     aDirVec = theDirection->impl<gp_Dir>();
+  } else if(aBaseShape.ShapeType() != TopAbs_VERTEX &&
+            aBaseShape.ShapeType() != TopAbs_EDGE &&
+            aFindPlane.Found() == Standard_True){
+    Handle(Geom_Plane) aPlane = aFindPlane.Plane();
+    gp_Pnt aLoc = aPlane->Axis().Location();
+    aDirVec = aPlane->Axis().Direction();
+    aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
+    aBaseDir.reset(new GeomAPI_Dir(aDirVec.X(), aDirVec.Y(), aDirVec.Z()));
+  } else {
+    return;
+  }
+  if(!aBaseLoc.get()) {
+    gp_Pnt aLoc;
     gp_XYZ aDirXYZ = aDirVec.XYZ();
     Standard_Real aMinParam = Precision::Infinite();
-
     for(TopExp_Explorer anExp(aBaseShape, TopAbs_VERTEX); anExp.More(); anExp.Next()) {
       const TopoDS_Shape& aVertex = anExp.Current();
       gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVertex));
@@ -138,19 +143,8 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr&                theBaseShape,
         aLoc = aPnt;
       }
     }
-  } else {
-    if(!theDirection.get()) {
-      Handle(Geom_Plane) aPlane = aFindPlane.Plane();
-      aLoc = aPlane->Axis().Location();
-      aDirVec = aPlane->Axis().Direction();
-
-      aBaseDir.reset(new GeomAPI_Dir(aDirVec.X(), aDirVec.Y(), aDirVec.Z()));
-    } else {
-      aBaseDir = theDirection;
-      aDirVec = theDirection->impl<gp_Dir>();
-    }
+    aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
   }
-  aBaseLoc.reset(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
   aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir);
 
   TopoDS_Shape aResult;
@@ -372,16 +366,15 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr&                theBaseShape,
     // Naming for extrusion from vertex, edge.
     for(TopExp_Explorer anExp(aResult, aShapeTypeToExp); anExp.More(); anExp.Next()) {
       const TopoDS_Shape& aShape = anExp.Current();
+      GeomShapePtr aGeomSh(new GeomAPI_Shape());
       if(aShapeTypeToExp == TopAbs_VERTEX) {
         gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
         IntTools_Context anIntTools;
         if(anIntTools.IsValidPointForFace(aPnt, aToFace, Precision::Confusion()) == Standard_True) {
-          GeomShapePtr aGeomSh(new GeomAPI_Shape());
           aGeomSh->setImpl(new TopoDS_Shape(aShape));
           this->addToShape(aGeomSh);
         }
         if(anIntTools.IsValidPointForFace(aPnt, aFromFace, Precision::Confusion()) == Standard_True) {
-          GeomShapePtr aGeomSh(new GeomAPI_Shape());
           aGeomSh->setImpl(new TopoDS_Shape(aShape));
           this->addFromShape(aGeomSh);
         }
@@ -390,14 +383,12 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr&                theBaseShape,
         BRepLib_CheckCurveOnSurface anEdgeCheck(anEdge, aToFace);
         anEdgeCheck.Perform();
         if(anEdgeCheck.MaxDistance() < Precision::Confusion()) {
-          GeomShapePtr aGeomSh(new GeomAPI_Shape());
           aGeomSh->setImpl(new TopoDS_Shape(aShape));
           this->addToShape(aGeomSh);
         }
         anEdgeCheck.Init(anEdge, aFromFace);
         anEdgeCheck.Perform();
         if(anEdgeCheck.MaxDistance() < Precision::Confusion()) {
-          GeomShapePtr aGeomSh(new GeomAPI_Shape());
           aGeomSh->setImpl(new TopoDS_Shape(aShape));
           this->addFromShape(aGeomSh);
         }
index 38b2eb57e1d5a49bb9ed9073d2e7c57951cd85e2..92e5924eaec1a813a4b6a8480558af7fe54a29ae 100644 (file)
@@ -297,16 +297,15 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
     // Setting naming.
     for(TopExp_Explorer anExp(aResult, aShapeTypeToExp); anExp.More (); anExp.Next ()) {
       const TopoDS_Shape& aShape = anExp.Current();
+      GeomShapePtr aGeomSh(new GeomAPI_Shape());
       if(aShapeTypeToExp == TopAbs_VERTEX) {
         gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
         IntTools_Context anIntTools;
         if(anIntTools.IsValidPointForFace(aPnt, TopoDS::Face(aRotatedToFace), Precision::Confusion()) == Standard_True) {
-          GeomShapePtr aGeomSh(new GeomAPI_Shape());
           aGeomSh->setImpl(new TopoDS_Shape(aShape));
           this->addToShape(aGeomSh);
         }
         if(anIntTools.IsValidPointForFace(aPnt, TopoDS::Face(aRotatedFromFace), Precision::Confusion()) == Standard_True) {
-          GeomShapePtr aGeomSh(new GeomAPI_Shape());
           aGeomSh->setImpl(new TopoDS_Shape(aShape));
           this->addFromShape(aGeomSh);
         }
@@ -315,14 +314,12 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
         BRepLib_CheckCurveOnSurface anEdgeCheck(anEdge, TopoDS::Face(aRotatedToFace));
         anEdgeCheck.Perform();
         if(anEdgeCheck.MaxDistance() < Precision::Confusion()) {
-          GeomShapePtr aGeomSh(new GeomAPI_Shape());
           aGeomSh->setImpl(new TopoDS_Shape(aShape));
           this->addToShape(aGeomSh);
         }
         anEdgeCheck.Init(anEdge, TopoDS::Face(aRotatedFromFace));
         anEdgeCheck.Perform();
         if(anEdgeCheck.MaxDistance() < Precision::Confusion()) {
-          GeomShapePtr aGeomSh(new GeomAPI_Shape());
           aGeomSh->setImpl(new TopoDS_Shape(aShape));
           this->addFromShape(aGeomSh);
         }
@@ -331,14 +328,12 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
         Handle(Geom_Surface) aFromSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedFromFace));
         Handle(Geom_Surface) aToSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedToFace));
         if(aFaceSurface == aFromSurface) {
-          GeomShapePtr aFSHape(new GeomAPI_Shape);
-          aFSHape->setImpl(new TopoDS_Shape(aShape));
-          this->addFromShape(aFSHape);
+          aGeomSh->setImpl(new TopoDS_Shape(aShape));
+          this->addFromShape(aGeomSh);
         }
         if(aFaceSurface == aToSurface) {
-          GeomShapePtr aTSHape(new GeomAPI_Shape);
-          aTSHape->setImpl(new TopoDS_Shape(aShape));
-          this->addToShape(aTSHape);
+          aGeomSh->setImpl(new TopoDS_Shape(aShape));
+          this->addToShape(aGeomSh);
         }
       }
     }
@@ -403,13 +398,18 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
     }
     this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aBoundingCutBuilder)));
     aResult = aBoundingCutBuilder->Shape();
+    if(aResult.ShapeType() == TopAbs_COMPOUND) {
+      aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+    }
 
     // Setting naming.
-    const TopTools_ListOfShape& aBndShapes = aBoundingCutBuilder->Modified(aBoundingFace);
-    for(TopTools_ListIteratorOfListOfShape anIt(aBndShapes); anIt.More(); anIt.Next()) {
-      GeomShapePtr aShape(new GeomAPI_Shape());
-      aShape->setImpl(new TopoDS_Shape(anIt.Value()));
-      isFromFaceSet ? this->addFromShape(aShape) : this->addToShape(aShape);
+    if(aShapeTypeToExp == TopAbs_FACE) {
+      const TopTools_ListOfShape& aBndShapes = aBoundingCutBuilder->Modified(aBoundingFace);
+      for(TopTools_ListIteratorOfListOfShape anIt(aBndShapes); anIt.More(); anIt.Next()) {
+        GeomShapePtr aShape(new GeomAPI_Shape());
+        aShape->setImpl(new TopoDS_Shape(anIt.Value()));
+        isFromFaceSet ? this->addFromShape(aShape) : this->addToShape(aShape);
+      }
     }
 
     // Try to cut with base face. If it can not be done then keep result of cut with bounding plane.
@@ -425,11 +425,10 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
                                                              aBasePlane->Axis().Direction().Y(),
                                                              aBasePlane->Axis().Direction().Z()));
       GeomShapePtr aPln = GeomAlgoAPI_FaceBuilder::planarFace(theCenter, theNormal);
-
       aList.push_back(aSh);
       std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(aList);
-
       aSh = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPln, aBoundingPoints);
+      aModifiedBaseShape = aSh->impl<TopoDS_Shape>();
     } else {
       aModifiedBaseShape = aBaseShape;
     }
@@ -459,27 +458,24 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
     aBaseCutBuilder->Build();
     if(aBaseCutBuilder->IsDone()) {
       TopoDS_Shape aCutResult = aBaseCutBuilder->Shape();
-      TopExp_Explorer anExp(aCutResult, TopAbs_SOLID);
-      if(anExp.More()) {
+      TopoDS_Iterator aCheckIt(aCutResult);
+      if(aCheckIt.More()) {
         this->appendAlgo(std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape(aBaseCutBuilder)));
         aResult = aCutResult;
+        if(aResult.ShapeType() == TopAbs_COMPOUND) {
+          aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+        }
+        if(aShapeTypeToExp == TopAbs_FACE) {
+          const TopTools_ListOfShape& aBsShapes = aBaseCutBuilder->Modified(aBoundingFace);
+          for(TopTools_ListIteratorOfListOfShape anIt(aBsShapes); anIt.More(); anIt.Next()) {
+            GeomShapePtr aShape(new GeomAPI_Shape());
+            aShape->setImpl(new TopoDS_Shape(anIt.Value()));
+            isFromFaceSet ? this->addToShape(aShape) : this->addFromShape(aShape);
+          }
+        }
       }
     }
 
-    const TopTools_ListOfShape& aBsShapes = aBaseCutBuilder->Modified(aBoundingFace);
-    for(TopTools_ListIteratorOfListOfShape anIt(aBsShapes); anIt.More(); anIt.Next()) {
-      GeomShapePtr aShape(new GeomAPI_Shape());
-      aShape->setImpl(new TopoDS_Shape(anIt.Value()));
-      isFromFaceSet ? this->addToShape(aShape) : this->addFromShape(aShape);
-    }
-
-    TopExp_Explorer anExp(aResult, TopAbs_SOLID);
-    if(!anExp.More()) {
-      return;
-    }
-    if(aResult.ShapeType() == TopAbs_COMPOUND) {
-      aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
-    }
     if(aResult.ShapeType() == TopAbs_COMPOUND) {
       GeomShapePtr aCompound(new GeomAPI_Shape);
       aCompound->setImpl(new TopoDS_Shape(aResult));
@@ -505,14 +501,46 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
     aResult = findClosest(aResult, aBaseCentre);
 
     // Setting naming.
-    for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More (); anExp.Next ()) {
-      const TopoDS_Shape& aFaceOnResult = anExp.Current();
-      Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aFaceOnResult));
-      Handle(Geom_Surface) aBoundingSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedBoundingFace));
-      if(aFaceSurface == aBoundingSurface) {
-        GeomShapePtr aShape(new GeomAPI_Shape());
-        aShape->setImpl(new TopoDS_Shape(aFaceOnResult));
-        isFromFaceSet ? this->addFromShape(aShape) : this->addToShape(aShape);
+    for(TopExp_Explorer anExp(aResult, aShapeTypeToExp); anExp.More (); anExp.Next ()) {
+      const TopoDS_Shape& aShape = anExp.Current();
+      GeomShapePtr aGeomSh(new GeomAPI_Shape());
+      if(aShapeTypeToExp == TopAbs_VERTEX) {
+        gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
+        IntTools_Context anIntTools;
+        if(anIntTools.IsValidPointForFace(aPnt, TopoDS::Face(aRotatedBoundingFace), Precision::Confusion()) == Standard_True) {
+          aGeomSh->setImpl(new TopoDS_Shape(aShape));
+          isFromFaceSet ? this->addFromShape(aGeomSh) : this->addToShape(aGeomSh);
+        }
+        if(anIntTools.IsValidPointForFace(aPnt, TopoDS::Face(aModifiedBaseShape), Precision::Confusion()) == Standard_True) {
+          aGeomSh->setImpl(new TopoDS_Shape(aShape));
+          isFromFaceSet ? this->addToShape(aGeomSh) : this->addFromShape(aGeomSh);
+        }
+      } else if(aShapeTypeToExp == TopAbs_EDGE) {
+        TopoDS_Edge anEdge = TopoDS::Edge(aShape);
+        BRepLib_CheckCurveOnSurface anEdgeCheck(anEdge, TopoDS::Face(aRotatedBoundingFace));
+        anEdgeCheck.Perform();
+        if(anEdgeCheck.MaxDistance() < Precision::Confusion()) {
+          aGeomSh->setImpl(new TopoDS_Shape(aShape));
+          isFromFaceSet ? this->addFromShape(aGeomSh) : this->addToShape(aGeomSh);
+        }
+        anEdgeCheck.Init(anEdge, TopoDS::Face(aModifiedBaseShape));
+        anEdgeCheck.Perform();
+        if(anEdgeCheck.MaxDistance() < Precision::Confusion()) {
+          aGeomSh->setImpl(new TopoDS_Shape(aShape));
+          isFromFaceSet ? this->addToShape(aGeomSh) : this->addFromShape(aGeomSh);
+        }
+      } else {
+        Handle(Geom_Surface) aFaceSurface = BRep_Tool::Surface(TopoDS::Face(aShape));
+        Handle(Geom_Surface) aBoundingSurface = BRep_Tool::Surface(TopoDS::Face(aRotatedBoundingFace));
+        Handle(Geom_Surface) aBaseSurface = BRep_Tool::Surface(TopoDS::Face(aModifiedBaseShape));
+        if(aFaceSurface == aBoundingSurface) {
+          aGeomSh->setImpl(new TopoDS_Shape(aShape));
+          isFromFaceSet ? this->addFromShape(aGeomSh) : this->addToShape(aGeomSh);
+        }
+        if(aFaceSurface == aBaseSurface) {
+          aGeomSh->setImpl(new TopoDS_Shape(aShape));
+          isFromFaceSet ? this->addToShape(aGeomSh) : this->addFromShape(aGeomSh);
+        }
       }
     }
   }