Salome HOME
Algo fixes
authordbv <dbv@opencascade.com>
Fri, 29 May 2015 11:40:52 +0000 (14:40 +0300)
committerdbv <dbv@opencascade.com>
Fri, 29 May 2015 15:35:07 +0000 (18:35 +0300)
src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp
src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp
src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.h
src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp

index 304d3748a13058c397f4858784ae520aa58cda4f..edf556918281231a509b37055225d29a1a677995 100644 (file)
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
 
-#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<GeomAPI_Shape> theBasis,
                                              std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> 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<GeomAPI_Shape> 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<GeomAPI_Shape> 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<GeomAPI_Shape> aTopFace = theFeature.lastShape();
+  if (!aTopFace->isNull()) {
+    if (aSubShapes->isBound(aTopFace)) {
+      aTopFace = aSubShapes->find(aTopFace);
+    }
+    theResultBody->generated(aTopFace, aTopName, _LAST_TAG);
+  }
+
 }
index d5c050caad8497bcba19ee72a6fec4a70dbb9613..618bc7c96e1372abc6e3be6c76c4006a8a65ada1 100644 (file)
@@ -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<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
 {
-  if(myMakeShapeList.empty()) {
+  if(myListOfMakeShape.empty()) {
     return std::shared_ptr<GeomAPI_Shape>();
   } else {
-    return myMakeShapeList.back()->shape();
+    return myListOfMakeShape.back()->shape();
   }
 }
 
@@ -53,34 +53,54 @@ void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr<GeomAPI_Shape> th
   result(theShape, theHistory, GeomAlgoAPI_MakeShapeList::Modified);
 }
 
+bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
+    BRepBuilderAPI_MakeShape* aBuilder = (*aBuilderIt)->implPtr<BRepBuilderAPI_MakeShape>();
+    if(aBuilder && (aBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True)) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
                                        ListOfShape& theHistory,
                                        OperationType theOperationType)
 {
-  if(myMakeShapeList.empty()) {
+  if(myListOfMakeShape.empty()) {
     return;
   }
 
-  NCollection_Map<TopoDS_Shape> aTempShapes;
+  NCollection_Map<TopoDS_Shape> anAlgoShapes;
   NCollection_Map<TopoDS_Shape> aResultShapes;
-  aTempShapes.Add(theShape->impl<TopoDS_Shape>());
+  anAlgoShapes.Add(theShape->impl<TopoDS_Shape>());
+  aResultShapes.Add(theShape->impl<TopoDS_Shape>());
 
-  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<BRepBuilderAPI_MakeShape>();
-    for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(aTempShapes); aShapeIt.More(); aShapeIt.Next()) {
+    NCollection_Map<TopoDS_Shape> aTempShapes;
+    bool hasResults = false;
+    for(NCollection_Map<TopoDS_Shape>::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<TopoDS_Shape>::Iterator aShapeIt(aResultShapes); aShapeIt.More(); aShapeIt.Next()) {
index 8d7975071f5ba92fa724022ffdc569c009f6cd47..7de5773503df3e456d68b4733eaa6fcebeb4b887 100644 (file)
@@ -48,6 +48,9 @@ public:
   GEOMALGOAPI_EXPORT virtual void modified(const std::shared_ptr<GeomAPI_Shape> theShape,
                                            ListOfShape& theHistory);
 
+  /// Returns whether the shape is deleted
+  GEOMALGOAPI_EXPORT virtual bool isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape);
+
 private:
   void result(const std::shared_ptr<GeomAPI_Shape> theShape,
               ListOfShape& theHistory,
@@ -55,7 +58,7 @@ private:
 
 
 protected:
-  ListOfMakeShape myMakeShapeList;
+  ListOfMakeShape myListOfMakeShape;
 };
 
 #endif
index a608373d752498ea89b8e9c0fb38a5d1b3428b41..9c60540a9c058c247d8e68255ebd6bffe1527b1f 100644 (file)
@@ -7,6 +7,7 @@
 #include <GeomAlgoAPI_Revolution.h>
 
 #include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_MakeShapeList.h>
 #include <GeomAlgoAPI_Rotation.h>
 #include <GeomAlgoAPI_ShapeProps.h>
 
@@ -117,24 +118,33 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr<GeomAPI_Shape>& theBasi
   gp_Pln aBasisPln = isBasisPlanar.Plan();
   gp_Ax1 anAxis = myAxis->impl<gp_Ax1>();
 
+  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<TopoDS_Shape>();
+    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<GeomAlgoAPI_MakeShape>(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<GeomAlgoAPI_MakeShape>(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<TopoDS_Shape>());
@@ -169,28 +179,42 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr<GeomAPI_Shape>& 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<GeomAlgoAPI_MakeShape>(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<GeomAlgoAPI_MakeShape>(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<GeomAlgoAPI_MakeShape>(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<TopoDS_Shape>()).Extent() > 0) {
+      myFirst->setImpl(new TopoDS_Shape(aToCutBuilder->Modified(myFirst->impl<TopoDS_Shape>()).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<GeomAPI_Shape>& 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<GeomAlgoAPI_MakeShape>(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<GeomAlgoAPI_MakeShape>(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<GeomAPI_Shape>& 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<GeomAlgoAPI_MakeShape>(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<GeomAPI_Shape>& 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<GeomAPI_Shape> 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<GeomAPI_Shape> 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;
 }