Salome HOME
27.10.2014. Naming data structure for Extrusion feature.
authorszy <szy@opencascade.com>
Mon, 27 Oct 2014 15:45:40 +0000 (18:45 +0300)
committerszy <szy@opencascade.com>
Mon, 27 Oct 2014 15:45:40 +0000 (18:45 +0300)
14 files changed:
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.h
src/GeomAPI/GeomAPI_Shape.h
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.h [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h
src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h [new file with mode: 0644]
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/ModelAPI/ModelAPI_ResultBody.h

index 4d2b643d5eb0b0d7d868ff360f99dc3adec4e58c..ab966dff693de7c0d3dd58afa168fc35561f344c 100644 (file)
@@ -26,9 +26,12 @@ INCLUDE_DIRECTORIES(
   ../ModelAPI
   ../GeomAPI
   ../GeomAlgoAPI
+  ../Events
+  ${CAS_INCLUDE_DIRS}
 )
 
 SET(PROJECT_LIBRARIES
+    Events
     ModelAPI 
     GeomAPI 
     GeomAlgoAPI
index 60ee2b6898bd0f8d6b5e89f9beb9f7de43b227d3..737a563b34aeaa54469b29c06045357c45a75d86 100644 (file)
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
-
+#include <Events_Error.h>
 #include <GeomAlgoAPI_Extrusion.h>
-
+#include <TopoDS_Shape.hxx>
+#include <TopTools_DataMapOfShapeShape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_MapOfShape.hxx>
 using namespace std;
-
+#define _LATERAL_TAG 1
+#define _FIRST_TAG 2
+#define _LAST_TAG 3
+#ifdef _DEBUG
+#include <iostream>
+#include <ostream>
+#endif
 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
 {
 }
@@ -33,14 +42,110 @@ void FeaturesPlugin_Extrusion::execute()
       ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
   if (!aFaceRef)
     return;
+
   boost::shared_ptr<GeomAPI_Shape> aFace = 
     boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
 
+  boost::shared_ptr<GeomAPI_Shape> aContext = 
+    boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->context());
+
   double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
   if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
     aSize = -aSize;
 
-  boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
-  aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
-  setResult(aResult);
+  boost::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
+  //TCollection_AsciiString anError;
+  GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
+  if(!aFeature.isDone()) {
+       std::string aFeatureError = "Extrusion algorithm failed";  
+    Events_Error::send(aFeatureError, this);
+       return;
+  }
+
+   // Check if shape is valid
+  if (!aFeature.shape()->impl<TopoDS_Shape>().IsNull()) {
+    std::string aShapeError = "Resulting shape is Null";     
+    Events_Error::send(aShapeError, this);
+ #ifdef _DEBUG
+    std::cerr << aShapeError << std::endl;
+ #endif
+    return;
+  }
+   if(!aFeature.isValid()) {
+       std::string aFeatureError = "Warning: resulting shape is not valid";  
+    Events_Error::send(aFeatureError, this);
+       return;
+  }  
+  //LoadNamingDS
+  LoadNamingDS(aFeature, aResultBody, aFace, aContext);
+
+  setResult(aResultBody);
 }
+
+  //============================================================================
+void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, 
+                                    boost::shared_ptr<ModelAPI_ResultBody> theResultBody, 
+                                                                boost::shared_ptr<GeomAPI_Shape> theBasis,
+                                    boost::shared_ptr<GeomAPI_Shape> theContext)
+{  
+
+       
+    //load result
+       if(theBasis->impl<TopoDS_Shape>().IsEqual(theContext->impl<TopoDS_Shape>()))
+         theResultBody->store(theFeature.shape());
+       else
+         theResultBody->storeGenerated(theContext, theFeature.shape());
+
+       TopTools_DataMapOfShapeShape aSubShapes;
+       for (TopExp_Explorer Exp(theFeature.shape()->impl<TopoDS_Shape>(),TopAbs_FACE); Exp.More(); Exp.Next()) {
+         aSubShapes.Bind(Exp.Current(),Exp.Current());
+       }
+
+       //Insert lateral face : Face from Edge
+       //GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes(*myBuilder, myBasis, TopAbs_EDGE, aLateralFaceBuilder, aSubShapes);
+
+
+  TopTools_MapOfShape aView;
+  TopExp_Explorer aShapeExplorer (theFeature.shape()->impl<TopoDS_Shape>(), TopAbs_EDGE);
+  for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+       boost::shared_ptr<GeomAPI_Shape> aRootG(new GeomAPI_Shape());
+       aRootG->setImpl((void *)&aRoot);
+       const ListOfShape& aShapes = theFeature.generated(aRootG);
+       std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();       
+       for (; anIt != aLast; anIt++) {
+      TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>(); 
+      if (aSubShapes.IsBound(aNewShape)) {
+        aNewShape.Orientation((aSubShapes(aNewShape)).Orientation());
+      }
+
+         if (!aRoot.IsSame (aNewShape)) {
+               boost::shared_ptr<GeomAPI_Shape> aNew(new GeomAPI_Shape());
+           aNew->setImpl((void *)&aNewShape);
+                 theResultBody->generated(aRootG, aNew,_LATERAL_TAG); 
+         }
+       }
+  }
+
+  //Insert bottom face
+  const boost::shared_ptr<GeomAPI_Shape>& aBottomFace = theFeature.firstShape();
+  if (!aBottomFace->impl<TopoDS_Shape>().IsNull()) {
+         if (aSubShapes.IsBound(aBottomFace->impl<TopoDS_Shape>())) {
+               aBottomFace->setImpl((void *)&aSubShapes(aBottomFace->impl<TopoDS_Shape>()));
+         }    
+  theResultBody->generated(aBottomFace, _FIRST_TAG);
+  }
+
+  
+
+ //Insert top face
+  boost::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
+  if (!aTopFace->impl<TopoDS_Shape>().IsNull()) {
+       if (aSubShapes.IsBound(aTopFace->impl<TopoDS_Shape>())) {
+               aTopFace->setImpl((void *)&aSubShapes(aTopFace->impl<TopoDS_Shape>()));
+       }
+    theResultBody->generated(aTopFace, _FIRST_TAG);
+  }
+
+}
\ No newline at end of file
index 13a8c226e9ea2bc48ae7d6d936b6290fe656218e..d136c84915156754b490365fc715d73ad09d2d91 100644 (file)
@@ -7,7 +7,8 @@
 
 #include "FeaturesPlugin.h"
 #include <ModelAPI_Feature.h>
-
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_Extrusion.h>
 class FeaturesPlugin_Extrusion : public ModelAPI_Feature
 {
  public:
@@ -51,6 +52,11 @@ class FeaturesPlugin_Extrusion : public ModelAPI_Feature
 
   /// Use plugin manager for features creation
   FeaturesPlugin_Extrusion();
+
+  /// Load Naming data structure of the feature to the document
+  void LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
+                       boost::shared_ptr<GeomAPI_Shape> theBasis,
+                       boost::shared_ptr<GeomAPI_Shape> theContext);
 };
 
 #endif
index 3aa0987f7e2fbaca01552535628838c75ace50f7..acd39c6ec400dbcb37e0d388790647f2e11d6dec 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <GeomAPI_Interface.h>
 #include <boost/shared_ptr.hpp>
+#include <list>
 
 /**\class GeomAPI_Shape
  * \ingroup DataModel
@@ -31,4 +32,5 @@ class GEOMAPI_EXPORT GeomAPI_Shape : public GeomAPI_Interface
 
 };
 
+typedef std::list<boost::shared_ptr<GeomAPI_Shape>> ListOfShape;
 #endif
index 05e91eb61f219862c278b69f91a60c1779763eb9..5656a0ad8a5e0227eaa10d12050708099e3a7f12 100644 (file)
@@ -12,6 +12,8 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_SketchBuilder.h
     GeomAlgoAPI_Extrusion.h
     GeomAlgoAPI_Boolean.h
+    GeomAlgoAPI_MakeShape.h
+    GeomAlgoAPI_DFLoader.h
 )
 
 SET(PROJECT_SOURCES
@@ -22,14 +24,18 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_SketchBuilder.cpp
     GeomAlgoAPI_Extrusion.cpp
     GeomAlgoAPI_Boolean.cpp
+    GeomAlgoAPI_MakeShape.cpp
+    GeomAlgoAPI_DFLoader.cpp
 )
 
 SET(PROJECT_LIBRARIES
-    GeomAPI 
+    GeomAPI
+    ModelAPI 
     ${CAS_TKBool} 
     ${CAS_TKBO} 
     ${CAS_TKPrim}
     ${CAS_SHAPE}
+    ${CAS_TKTopAlgo}
 )
 
 ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
@@ -42,6 +48,7 @@ SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
 
 INCLUDE_DIRECTORIES(
   ../GeomAPI
+  ../ModelAPI
   ${CAS_INCLUDE_DIRS}
 )
 
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp
new file mode 100644 (file)
index 0000000..d309de4
--- /dev/null
@@ -0,0 +1,103 @@
+// File:        GeomAlgoAPI_DFLoader.cpp
+// Created:     23 October 2014
+// Author:      Sergey Zaritchny
+
+#include <GeomAlgoAPI_DFLoader.h>
+#include <TopoDS_Iterator.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+//=======================================================================
+//function : refineResult
+//purpose  :
+//=======================================================================
+const TopoDS_Shape GeomAlgoAPI_DFLoader::refineResult(const  TopoDS_Shape& theResult)
+{
+  TopoDS_Shape aResult;
+  if (theResult.ShapeType() == TopAbs_COMPOUND) {
+    Standard_Integer nbSubResults = 0;
+    TopoDS_Iterator itr(theResult);
+    for (; itr.More(); itr.Next()) nbSubResults++;
+    if (nbSubResults == 1) {
+      itr.Initialize(theResult);
+      if (itr.More()) aResult = itr.Value();
+    }
+  }
+  return aResult;
+}
+/*
+//=======================================================================
+//function : loadDeletedShapes
+//purpose  : load deleted shapes in DF
+//=======================================================================
+void GeomAlgoAPI_DFLoader::loadDeletedShapes (BRepBuilderAPI_MakeShape& theMS,
+                                       const TopoDS_Shape&     theShapeIn,
+                                       const TopAbs_ShapeEnum  theKindOfShape,
+                                       TNaming_Builder&        theBuilder)
+{
+  TopTools_MapOfShape aView;
+  TopExp_Explorer ShapeExplorer (theShapeIn, theKindOfShape);
+  for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+    if (theMS.IsDeleted (aRoot)) {
+      theBuilder.Delete (aRoot);
+    }
+  }
+}
+
+//=======================================================================
+//function : loadAndOrientModifiedShapes
+//purpose  : load modified shapes in DF with preliminary orientation adjustment
+//=======================================================================
+void GeomAlgoAPI_DFLoader::loadAndOrientModifiedShapes (BRepBuilderAPI_MakeShape&    theMS,
+                                           const TopoDS_Shape&        theShapeIn,
+                                           const TopAbs_ShapeEnum     theKindOfShape,
+                                           TNaming_Builder&           theBuilder,
+                                           const TopTools_DataMapOfShapeShape& theSubShapes)
+{
+  TopTools_MapOfShape aView;
+  TopExp_Explorer aShapeExplorer (theShapeIn, theKindOfShape);
+  for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+    const TopTools_ListOfShape& aShapes = theMS.Modified (aRoot);
+    TopTools_ListIteratorOfListOfShape aShapesIterator (aShapes);
+    for (;aShapesIterator.More (); aShapesIterator.Next ()) {
+      TopoDS_Shape aNewShape = aShapesIterator.Value ();
+      if (theSubShapes.IsBound(aNewShape)) {
+        aNewShape.Orientation((theSubShapes(aNewShape)).Orientation());
+      }
+      if (!aRoot.IsSame (aNewShape)) theBuilder.Modify (aRoot, aNewShape );
+    }
+  }
+}
+
+//=======================================================================
+//function : loadAndOrientGeneratedShapes
+//purpose  : load generated shapes in DF with preliminary orientation adjustment
+//=======================================================================
+
+void GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes (BRepBuilderAPI_MakeShape&     theMS,
+                                                const TopoDS_Shape&           theShapeIn,
+                                                const TopAbs_ShapeEnum        theKindOfShape,
+                                                TNaming_Builder&              theBuilder,
+                                                const TopTools_DataMapOfShapeShape&    theSubShapes)
+{
+  TopTools_MapOfShape aView;
+  TopExp_Explorer aShapeExplorer (theShapeIn, theKindOfShape);
+  for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+    const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+    if (!aView.Add(aRoot)) continue;
+    const TopTools_ListOfShape& aShapes = theMS.Generated (aRoot);
+    TopTools_ListIteratorOfListOfShape aShapesIterator (aShapes);
+    for (;aShapesIterator.More (); aShapesIterator.Next ()) {
+      TopoDS_Shape aNewShape = aShapesIterator.Value ();
+      if (theSubShapes.IsBound(aNewShape)) {
+        aNewShape.Orientation((theSubShapes(aNewShape)).Orientation());
+      }
+      if (!aRoot.IsSame (aNewShape)) theBuilder.Generated (aRoot,aNewShape );
+    }
+  }
+}
+*/
\ No newline at end of file
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.h b/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.h
new file mode 100644 (file)
index 0000000..815b8cb
--- /dev/null
@@ -0,0 +1,44 @@
+// File:        GeomAlgoAPI_DFLoader.h
+// Created:     23 October 2014
+// Author:      Sergey Zaritchny
+
+#ifndef GeomAlgoAPI_DFLoader_H_
+#define GeomAlgoAPI_DFLoader_H_
+#include <GeomAlgoAPI.h>
+//#include <boost/shared_ptr.hpp>
+#include <BRepBuilderAPI_MakeShape.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TNaming_Builder.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+#include <TopTools_DataMapOfShapeShape.hxx>
+
+/**\class GeomAlgoAPI_DFLoader
+ * \ingroup DataAlgo
+ * \brief Defines several static methods useful for Data Framework filling
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_DFLoader 
+{
+ public:
+        /*
+  /// Loads to DF deleted shapes
+  static void loadDeletedShapes (BRepBuilderAPI_MakeShape& theMS, const TopoDS_Shape& theShapeIn,
+                                 const TopAbs_ShapeEnum  KindOfShape, TNaming_Builder&  theBuilder);
+
+  /// Loads to DF generated shapes
+  static void loadAndOrientGeneratedShapes (BRepBuilderAPI_MakeShape&                  theMS,
+                                            const TopoDS_Shape&                 theShapeIn,
+                                            const TopAbs_ShapeEnum              theKindOfShape,
+                                            TNaming_Builder&                    theBuilder,
+                                            const TopTools_DataMapOfShapeShape& theSubShapes);
+  /// Loads to DF modified shapes 
+  static void loadAndOrientModifiedShapes (BRepBuilderAPI_MakeShape&                   theMS,
+                                           const TopoDS_Shape&                  theShapeIn,
+                                           const TopAbs_ShapeEnum               theKindOfShape,
+                                           TNaming_Builder&                     theBuilder,
+                                           const TopTools_DataMapOfShapeShape&  theSubShapes);
+  */
+  /// Refine result
+  static const TopoDS_Shape refineResult(const TopoDS_Shape& theShape);
+};
+
+#endif
\ No newline at end of file
index a236fc8bb00135cd62e014ec1236d88b2e83b9c2..d5f2c4379debded24d1f39ee735f1efac3cbd172 100644 (file)
 // Author:      Artem ZHIDKOV
 
 #include <GeomAlgoAPI_Extrusion.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_DFLoader.h>
 #include <gp_Pln.hxx>
-
 #include <BRepPrimAPI_MakePrism.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
 #include <Geom_Plane.hxx>
 #include <Geom_Surface.hxx>
 #include <TopExp_Explorer.hxx>
-#include <BRep_Builder.hxx>
-
+#include <BRepCheck_Analyzer.hxx>
+#include <GProp_GProps.hxx>
+#include <BRepGProp.hxx>
+#include <TopoDS.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <Precision.hxx>
+#include <TDF_TagSource.hxx>
+#include <boost/shared_ptr.hpp>
+
 const double tolerance = Precision::Angular();
+  // Constructor
+GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion (boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
+         : mySize(theSize), myBuilder(NULL), myDone(false), myShape(new GeomAPI_Shape())
+  {
+    myBasis = theBasis->impl<TopoDS_Shape>();
+       build();
+  }
 
-boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
-    boost::shared_ptr<GeomAPI_Shape> theShape, boost::shared_ptr<GeomAPI_Dir> theDir,
-    double theSize)
-{
-  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
-  gp_Vec aDir(theDir->impl<gp_Dir>().XYZ() * theSize);
+  //============================================================================
+  void GeomAlgoAPI_Extrusion::build()
+  {
+    bool isFirstNorm = true;
+    gp_Dir aShapeNormal;
 
-  TopoDS_Shape aPrism = BRepPrimAPI_MakePrism(aShape, aDir);
-  if (aPrism.IsNull())
-    return boost::shared_ptr<GeomAPI_Shape>();
+    //const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>(); 
+    Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(TopoDS::Face(myBasis)));
+    if (aPlane.IsNull())  // non-planar shapes is not supported for extrusion yet
+      return;
 
-  boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
-  aResult->setImpl(new TopoDS_Shape(aPrism));
-  return aResult;
-}
+    const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();  
+    gp_Vec aVec(aNormal);
+       aVec = aVec * mySize;
 
-boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
-    boost::shared_ptr<GeomAPI_Shape> theShape, double theSize)
+    myBuilder = new BRepPrimAPI_MakePrism(myBasis, aVec);
+       if(myBuilder != NULL) {
+         myDone = myBuilder->IsDone();
+         if(myDone) {
+               if(myBuilder->Shape().ShapeType() == TopAbs_COMPOUND) 
+                 myResult = GeomAlgoAPI_DFLoader::refineResult(myBuilder->Shape());
+               else
+                 myResult = myBuilder->Shape();                
+               myShape->setImpl((void *)&myResult);  
+               myFirst->setImpl((void *)&(myBuilder->FirstShape()));
+               myLast->setImpl((void *)&(myBuilder-> LastShape()));
+         }
+       }       
+  }
+
+  //============================================================================
+const bool GeomAlgoAPI_Extrusion::isDone() const
+{return myDone;}
+
+  //============================================================================
+const bool GeomAlgoAPI_Extrusion::isValid() const
 {
-  bool isFirstNorm = true;
-  gp_Dir aShapeNormal;
-
-  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
-  TopExp_Explorer aFaceExp(aShape, TopAbs_FACE);
-  TopoDS_Compound aFaces; // use only faces from the shape: make compound for this
-  BRep_Builder aBuilder;
-  aBuilder.MakeCompound(aFaces);
-  for (; aFaceExp.More(); aFaceExp.Next()) {
-    const TopoDS_Face& aFace = (const TopoDS_Face&) aFaceExp.Current();
-    Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aFace));
-    if (aPlane.IsNull())  // non-planar shapes is not supported for extrusion yet
-      continue;
-
-    const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
-    if (isFirstNorm) {
-      aShapeNormal = aNormal;
-      isFirstNorm = false;
-    } else if (!aShapeNormal.IsEqual(aNormal, tolerance))  // non-planar shapes is not supported for extrusion yet
-      return boost::shared_ptr<GeomAPI_Shape>();
-    aBuilder.Add(aFaces, aFace);
+       bool isValid(false);
+       if(myDone && !myBuilder->Shape().IsNull()) {
+         BRepCheck_Analyzer aChecker(myBuilder->Shape());
+         isValid = aChecker.IsValid();
+       }
+       return isValid;
+  }
+
+  //============================================================================
+  const bool GeomAlgoAPI_Extrusion::hasVolume() const
+  {
+       bool hasVolume(false);
+       if(isValid()) {
+         const TopoDS_Shape& aRShape = myBuilder->Shape();
+         GProp_GProps aGProp;
+      BRepGProp::VolumeProperties(aRShape, aGProp);
+      if(aGProp.Mass() > Precision::Confusion()) 
+               hasVolume = true;       
+       }
+       return hasVolume;
   }
-  if (aFaces.IsNull())
-    return boost::shared_ptr<GeomAPI_Shape>();
 
-  boost::shared_ptr<GeomAPI_Dir> aDir(
-      new GeomAPI_Dir(aShapeNormal.X(), aShapeNormal.Y(), aShapeNormal.Z()));
+  //============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const 
+{return myShape;}
 
-  boost::shared_ptr<GeomAPI_Shape> aFacesShape(new (GeomAPI_Shape));
-  aFacesShape->setImpl(new TopoDS_Shape(aFaces));
-  return GeomAlgoAPI_Extrusion::makeExtrusion(aFacesShape, aDir, theSize);
-}
+  //============================================================================
+  const ListOfShape& GeomAlgoAPI_Extrusion::generated(const boost::shared_ptr<GeomAPI_Shape> theShape)
+  {
+       myHistory.clear();
+    if(myDone) {
+       const TopTools_ListOfShape& aList =  myBuilder->Generated(theShape->impl<TopoDS_Shape>());
+    TopTools_ListIteratorOfListOfShape it(aList);
+       for(;it.More();it.Next()) {
+               boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+               aShape->setImpl(&(it.Value()));
+               myHistory.push_back(aShape);
+       }
+  }
+  return myHistory;
+  }
+  
+  //============================================================================
+   const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
+   {
+        return myFirst;
+   }
+
+   //============================================================================
+   const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
+   {
+        return myLast;
+   }
+
+  //============================================================================
+   /*
+  void GeomAlgoAPI_Extrusion::LoadNamingDS(boost::shared_ptr<ModelAPI_ResultBody> theResultBody, 
+         boost::shared_ptr<GeomAPI_Shape> theContext)
+{
+  if(isValid()) {
+       const TopoDS_Shape& aShape = myBuilder->Shape();
+       TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aShape);
+       boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(theResultBody->data());
+       if (aData) {
+      const TDF_Label& aShapeLab = aData->shapeLab();
+         const Handle(TDF_TagSource)& Tagger = TDF_TagSource::Set(aShapeLab);
+         if (Tagger.IsNull()) return;
+         Tagger->Set(0);
+
+      TNaming_Builder aBuilder (aShapeLab);
+         if(myBasis.IsEqual(theContext->impl<TopoDS_Shape>()))
+           aBuilder.Generated(aResult);
+         else
+        aBuilder.Generated(theContext->impl<TopoDS_Shape>(), aResult);
+
+         TopTools_DataMapOfShapeShape aSubShapes;
+         for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
+           aSubShapes.Bind(Exp.Current(),Exp.Current());
+         }
+
+          //Insert lateral face : Face from Edge
+         TNaming_Builder  aLateralFaceBuilder(aShapeLab.NewChild());
+         GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes(*myBuilder, myBasis, TopAbs_EDGE, aLateralFaceBuilder, aSubShapes);
+
+         //Insert bottom face
+         TopoDS_Shape aBottomFace = myBuilder->FirstShape();
+      if (!aBottomFace.IsNull()) {
+               if (aBottomFace.ShapeType() != TopAbs_COMPOUND) {
+                 TNaming_Builder aBottomBuilder(aShapeLab.NewChild());  //2
+          if (aSubShapes.IsBound(aBottomFace)) {
+                       aBottomFace = aSubShapes(aBottomFace);
+                 }
+        aBottomBuilder.Generated(aBottomFace);
+               } else {
+          TopoDS_Iterator itr(aBottomFace);
+          for (; itr.More(); itr.Next()) {
+            TNaming_Builder aBottomBuilder(aShapeLab.NewChild());
+                   aBottomBuilder.Generated(itr.Value());
+                 }
+               }
+
+         }
+
+         //Insert top face
+         TopoDS_Shape aTopFace = myBuilder->LastShape();
+         if (!aTopFace.IsNull()) {
+       if (aTopFace.ShapeType() != TopAbs_COMPOUND) {
+         TNaming_Builder aTopBuilder(aShapeLab.NewChild()); //3
+         if (aSubShapes.IsBound(aTopFace)) {
+           aTopFace = aSubShapes(aTopFace);
+                }
+        aTopBuilder.Generated(aTopFace);
+          } else {
+        TopoDS_Iterator itr(aTopFace);
+        for (; itr.More(); itr.Next()) {
+          TNaming_Builder aTopBuilder(aShapeLab.NewChild());
+          aTopBuilder.Generated(itr.Value());
+               }
+          }
+         }
+       }
+  }
+  */
\ No newline at end of file
index 31b3d4406378d519d1f7b78d4c79c3c83c3c66d9..03d704d5dd6a4fdafe5276f845d0b4b16c5f924b 100644 (file)
@@ -1,6 +1,6 @@
 // File:        GeomAlgoAPI_Extrusion.h
-// Created:     06 Jun 2014
-// Author:      Artem ZHIDKOV
+// Created:     22 October 2014
+// Author:      Sergey Zaritchny
 
 #ifndef GeomAlgoAPI_Extrusion_H_
 #define GeomAlgoAPI_Extrusion_H_
@@ -8,33 +8,65 @@
 #include <GeomAlgoAPI.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_Dir.h>
+#include <ModelAPI_ResultBody.h>
 #include <boost/shared_ptr.hpp>
-
+#include <BRepPrimAPI_MakePrism.hxx>
+#include <TopoDS_Shape.hxx>
 /**\class GeomAlgoAPI_Extrusion
  * \ingroup DataAlgo
  * \brief Allows to create the prism based on a given face and a direction
  */
 
-class GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion  
 {
  public:
-  /* \brief Creates extrusion for the given shape
-   * \param[in] theShape face or wire to be extruded
-   * \param[in] theDir   direction of extrusion
-   * \param[in] theSize  the length of extrusion (if the value is less than 0, the extrusion in opposite direction)
-   * \return a solid or a face which is obtained from specified one
-   */
-  static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<GeomAPI_Shape> theShape,
-                                                        boost::shared_ptr<GeomAPI_Dir> theDir,
-                                                        double theSize);
 
   /* \brief Creates extrusion for the given shape along the normal for this shape
    * \param[in] theShape face or wire to be extruded
    * \param[in] theSize  the length of extrusion (if the value is less than 0, the extrusion in opposite normal)
    * \return a solid or a face which is obtained from specified one
-   */
-  static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<GeomAPI_Shape> theShape,
-                                                        double theSize);
+  
+  static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<ModelAPI_ResultBody> theResult,
+                                                                                                               boost::shared_ptr<GeomAPI_Shape> theBasis,
+                                                                                                               boost::shared_ptr<GeomAPI_Shape> theContext,
+                                                        double theSize); */
+  /// Constructor
+  GeomAlgoAPI_Extrusion (boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize);
+
+  /// Returns True if algorithm succeed
+  const bool isDone() const;
+
+  ///  Returns True if resulting shape is valid
+  const bool isValid() const;
+
+  /// Returns True if resulting shape has volume
+  const bool hasVolume() const;
+
+  /// Returns result of the Extrusion algorithm which may be a Solid or a Face
+  const boost::shared_ptr<GeomAPI_Shape>& shape () const;
+
+  /// Returns list of shapes generated from theShape
+  const ListOfShape& generated(const boost::shared_ptr<GeomAPI_Shape> theShape);
+
+  /// Returns the first shape 
+  const boost::shared_ptr<GeomAPI_Shape>& firstShape();
+
+  /// returns last shape
+  const boost::shared_ptr<GeomAPI_Shape>& lastShape();  
+
+private:
+  /// builds resulting shape
+  void build();
+
+  BRepPrimAPI_MakePrism * myBuilder;
+  TopoDS_Shape myBasis;
+  double mySize;
+  bool myDone;
+  TopoDS_Shape myResult;
+  ListOfShape myHistory;
+  boost::shared_ptr<GeomAPI_Shape> myShape;
+  boost::shared_ptr<GeomAPI_Shape> myFirst;
+  boost::shared_ptr<GeomAPI_Shape> myLast;
 };
 
 #endif
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp
new file mode 100644 (file)
index 0000000..d743b56
--- /dev/null
@@ -0,0 +1,58 @@
+// File:        GeomAlgoAPI_MakeShape.cpp
+// Created:     20 Oct 2014
+// Author:      Sergey ZARITCHNY
+
+#include <GeomAlgoAPI_MakeShape.h>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(BRepBuilderAPI_MakeShape *  theMkShape)
+{ myBuilder = theMkShape;}
+
+const boost::shared_ptr<GeomAPI_Shape>  GeomAlgoAPI_MakeShape::shape() const
+{
+  boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+  if(myBuilder != NULL) 
+    aShape->setImpl(new TopoDS_Shape(myBuilder->Shape()));
+  return aShape;
+}
+
+  /// Returns the  list   of shapes generated   from the shape <theShape>
+const ListOfShape& GeomAlgoAPI_MakeShape::generated(const boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+  myHistory.clear();
+  if(myBuilder != NULL) {
+       const TopTools_ListOfShape& aList =  myBuilder->Generated(theShape->impl<TopoDS_Shape>());
+    TopTools_ListIteratorOfListOfShape it(aList);
+       for(;it.More();it.Next()) {
+               boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+               aShape->setImpl(&(it.Value()));
+               myHistory.push_back(aShape);
+       }
+  }
+  return myHistory;
+}
+
+  /// Returns the  list   of shapes modified   from the shape <theShape>
+const ListOfShape& GeomAlgoAPI_MakeShape::modified(const boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+  myHistory.clear();
+  if(myBuilder != NULL) {
+       const TopTools_ListOfShape& aList =  myBuilder->Modified(theShape->impl<TopoDS_Shape>());
+       TopTools_ListIteratorOfListOfShape it(aList);
+       for(;it.More();it.Next()) {
+               boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+               aShape->setImpl(&(it.Value()));
+               myHistory.push_back(aShape);
+       }
+  }
+  return myHistory;
+}
+
+  /// Returns whether the shape is an edge
+bool GeomAlgoAPI_MakeShape::isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+  bool isDeleted(false);
+  if (myBuilder != NULL) 
+       isDeleted = (bool) myBuilder->IsDeleted(theShape->impl<TopoDS_Shape>());        
+  return isDeleted;
+}
\ No newline at end of file
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h
new file mode 100644 (file)
index 0000000..9357ff4
--- /dev/null
@@ -0,0 +1,38 @@
+// File:        GeomAlgoAPI_MakeShape.h
+// Created:     17 Oct 2014
+// Author:      Sergey ZARITCHNY
+#ifndef GeomAlgoAPI_MakeShape_H_
+#define GeomAlgoAPI_MakeShape_H_
+
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+#include <GeomAlgoAPI.h>
+#include <BRepBuilderAPI_MakeShape.hxx>
+/**\class GeomAlgoAPI_MakeShape
+ * \ingroup DataModel
+ * \Interface to the root class of all topological shapes constructions
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape
+{
+ public:
+   /// Constructor
+  GeomAlgoAPI_MakeShape(BRepBuilderAPI_MakeShape * theBuilder);
+  /// Returns a shape built by the shape construction algorithm
+  const boost::shared_ptr<GeomAPI_Shape>  shape() const;
+
+  /// Returns the  list   of shapes generated   from the shape <theShape>
+  virtual const ListOfShape& generated(const boost::shared_ptr<GeomAPI_Shape> theShape);
+
+  /// Returns the  list   of shapes modified   from the shape <theShape>
+  virtual const ListOfShape& modified(const boost::shared_ptr<GeomAPI_Shape> theShape);
+
+  /// Returns whether the shape is an edge
+  virtual bool isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape);
+
+  protected:
+       boost::shared_ptr<GeomAPI_Shape> myShape;
+       ListOfShape myHistory;
+       BRepBuilderAPI_MakeShape * myBuilder;
+};
+
+#endif
\ No newline at end of file
index f5c8cb223d1d0438fc78fc0210628e840328add0..090de2d9e3200da44225803c0a25ebd440b16e40 100644 (file)
@@ -19,12 +19,8 @@ void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
   if (aData) {
     TDF_Label& aShapeLab = aData->shapeLab();
-    // remove the previous history
-    clean();
-    aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
-    for(TDF_ChildIterator anIter(aShapeLab); anIter.More(); anIter.Next()) {
-      anIter.Value().ForgetAllAttributes();
-    }
+    // clean builders
+    clean();   
     // store the new shape as primitive
     TNaming_Builder aBuilder(aShapeLab);
     if (!theShape)
@@ -37,6 +33,50 @@ void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
   }
 }
 
+void Model_ResultBody::storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                         const boost::shared_ptr<GeomAPI_Shape>& theToShape)
+{
+  boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+  if (aData) {
+    TDF_Label& aShapeLab = aData->shapeLab();
+    // clean builders
+    clean();   
+    // store the new shape as primitive
+    TNaming_Builder aBuilder(aShapeLab);
+    if (!theFromShape || !theToShape)
+      return;  // bad shape
+    TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
+    if (aShapeBasis.IsNull())
+      return;  // null shape inside
+       TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
+    if (aShapeNew.IsNull())
+      return;  // null shape inside
+    aBuilder.Generated(aShapeBasis, aShapeNew);
+  }
+}
+
+void Model_ResultBody::storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+                                         const boost::shared_ptr<GeomAPI_Shape>& theNewShape)
+{
+  boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+  if (aData) {
+    TDF_Label& aShapeLab = aData->shapeLab();
+    // clean builders
+    clean();   
+    // store the new shape as primitive
+    TNaming_Builder aBuilder(aShapeLab);
+    if (!theOldShape || !theNewShape)
+      return;  // bad shape
+    TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
+    if (aShapeOld.IsNull())
+      return;  // null shape inside
+       TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
+    if (aShapeNew.IsNull())
+      return;  // null shape inside
+    aBuilder.Generated(aShapeOld, aShapeNew);
+  }
+}
+
 boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
 {
   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
index c4ffbea314ba5af26a775103d1083496091a0e32..f6174cdee1cb82798e836f80e67b954754e331e3 100644 (file)
@@ -28,6 +28,15 @@ class Model_ResultBody : public ModelAPI_ResultBody
 public:
   /// Stores the shape (called by the execution method).
   MODEL_EXPORT virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape);
+
+  /// Stores the generated shape (called by the execution method).
+  MODEL_EXPORT virtual void storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                              const boost::shared_ptr<GeomAPI_Shape>& theToShape);
+
+  /// Stores the modified shape (called by the execution method).
+  MODEL_EXPORT virtual void storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+                                              const boost::shared_ptr<GeomAPI_Shape>& theNewShape);
+
   /// Returns the shape-result produced by this feature
   MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
   /// Returns the source feature of this result
index bcd45b354aa721d90e17cd7b32121c47f21fb2b9..36154744134df671ddee40c329eb2dd67a51c920 100644 (file)
@@ -36,6 +36,15 @@ public:
 
   /// Stores the shape (called by the execution method).
   virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+
+  /// Stores the generated shape (called by the execution method).
+  virtual void storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+                                 const boost::shared_ptr<GeomAPI_Shape>& theToShape) = 0;
+
+  /// Stores the modified shape (called by the execution method).
+  virtual void storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+                                 const boost::shared_ptr<GeomAPI_Shape>& theNewShape) = 0;
+
   /// Returns the shape-result produced by this feature
   virtual boost::shared_ptr<GeomAPI_Shape> shape() = 0;