]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Compsolid creation in extrusion
authordbv <dbv@opencascade.com>
Thu, 13 Aug 2015 06:13:17 +0000 (09:13 +0300)
committerdbv <dbv@opencascade.com>
Thu, 13 Aug 2015 10:16:24 +0000 (13:16 +0300)
25 files changed:
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.h
src/FeaturesPlugin/Test/TestExtrusion.py
src/FeaturesPlugin/extrusion_widget.xml
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI.i
src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp
src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h
src/GeomAlgoAPI/GeomAlgoAPI_MakeShapeList.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Movement.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Prism.h
src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.cpp [deleted file]
src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.h [deleted file]
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_Transform.cpp
src/GeomValidators/GeomValidators_ZeroOffset.cpp
src/PartSet/PartSet_WidgetSketchLabel.cpp

index 7f414c613d81e747b8651f91ce16ee372d16cb9b..6393cd42b56fc1a1467825577317017e8e7d6d62 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <GeomAlgoAPI_Boolean.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
 #define FACE 4
 #define _MODIFY_TAG 1
@@ -133,7 +133,7 @@ void FeaturesPlugin_Boolean::execute()
           return;
         }
 
-        if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
+        if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo.shape()) > 1.e-7) {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
           LoadNamingDS(aResultBody, anObject, aTools, aBoolAlgo);
           setResult(aResultBody, aResultIndex);
index 6bc4ae5d04d19406d8c93891cb7b4fe164f1ba14..9d59c3c376b626486ba53c5cb37355283db483e1 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <GeomAlgoAPI_Prism.h>
 #include <GeomAlgoAPI_Revolution.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
 //=================================================================================================
 void FeaturesPlugin_CompositeBoolean::initAttributes()
@@ -162,7 +162,7 @@ void FeaturesPlugin_CompositeBoolean::execute()
           return;
         }
 
-        if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
+        if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo.shape()) > 1.e-7) {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
           loadNamingDS(aResultBody, anObject, aSketchFacesList, theSolidsAlgos, aBooleanTools, aBoolAlgo);
           setResult(aResultBody, aResultIndex);
@@ -237,8 +237,9 @@ void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr<ModelAPI_Resu
         aSubShapes = aPrismAlgo->mapOfShapes();
         aResultBuilder->loadAndOrientGeneratedShapes(aPrismAlgo->makeShape().get(), *aFaceIter, GeomAPI_Shape::EDGE, aGenTag,
                                                     aLatName, *aSubShapes.get());
-        aFromFace = aPrismAlgo->firstShape();
-        aToFace = aPrismAlgo->lastShape();
+        //TODO:fix
+        //aFromFace = aPrismAlgo->firstShape();
+        //aToFace = aPrismAlgo->lastShape();
       } else if(std::dynamic_pointer_cast<GeomAlgoAPI_Revolution>(*aSolidsAlgosIter)) {
         std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_Revolution>(*aSolidsAlgosIter);
         aSubShapes = aRevolAlgo->mapOfShapes();
index 26cb739e9ee9c01cb887505c624732b10f35c92a..a6372cf9a2b8b7064a70843813886feaac6ba1da 100644 (file)
 #include <ModelAPI_AttributeReference.h>
 
 #include <GeomAlgoAPI_Prism.h>
-
-#define _LATERAL_TAG 1
-#define _FIRST_TAG 2
-#define _LAST_TAG 3
-#define EDGE 6
-
-//#define DEBUG_COMPSOLID
-//#define DEBUG_COMPSOLID_SHAPE
+#include <GeomAlgoAPI_ShapeTools.h>
 
 //=================================================================================================
 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
@@ -63,7 +56,43 @@ void FeaturesPlugin_Extrusion::initAttributes()
 //=================================================================================================
 void FeaturesPlugin_Extrusion::execute()
 {
-  AttributeSelectionListPtr aFaceRefs = selectionList(LIST_ID());
+  // Getting faces.
+  ListOfShape aFacesList;
+  AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+  for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> aFaceSel = aFacesSelectionList->value(anIndex);
+    ResultPtr aContext = aFaceSel->context();
+    std::shared_ptr<GeomAPI_Shape> aContextShape = aContext->shape();
+    if(!aContextShape.get()) {
+      static const std::string aContextError = "The selection context is bad";
+      setError(aContextError);
+      break;
+    }
+
+    std::shared_ptr<GeomAPI_Shape> aFaceShape = aFaceSel->value();
+    int aFacesNum = -1; // this mean that "aFace" is used
+    ResultConstructionPtr aConstruction = 
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if(!aFaceShape.get()) { // this may be the whole sketch result selected, check and get faces
+      if (aConstruction.get()) {
+        aFacesNum = aConstruction->facesNum();
+      } else {
+        static const std::string aFaceError = "Can not find basis for extrusion";
+        setError(aFaceError);
+        break;
+      }
+    }
+    for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
+      std::shared_ptr<GeomAPI_Shape> aBaseShape;
+      if (aFacesNum == -1) {
+        aFacesList.push_back(aFaceShape);
+        break;
+      } else {
+        aFaceShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+        aFacesList.push_back(aFaceShape);
+      }
+    }
+  }
 
   // Getting sizes.
   double aToSize = 0.0;
@@ -98,133 +127,88 @@ void FeaturesPlugin_Extrusion::execute()
     }
   }
 
-  // for each selected face generate a result
+  // Searching faces with common edges.
+  ListOfShape aShells;
+  ListOfShape aFreeFaces;
+  GeomAlgoAPI_ShapeTools::combineFacesToShells(aFacesList, aShells, aFreeFaces);
+  aShells.merge(aFreeFaces);
+
+  // Generating result for each shell and face.
   int anIndex = 0, aResultIndex = 0;
-#ifdef DEBUG_COMPSOLID
-  ResultCompSolidPtr aCompSolidResult = document()->createCompSolid(data(), aResultIndex);
-  setResult(aCompSolidResult, aResultIndex);
-  aResultIndex++;
-#endif
-#ifdef DEBUG_COMPSOLID_SHAPE
-  bool aFirstShapeInCompsolid = aFaceRefs->size() > 0;
-  if (aFirstShapeInCompsolid)
-    aResultIndex--;
-#endif
-  for(; anIndex < aFaceRefs->size(); anIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(anIndex);
-    ResultPtr aContextRes = aFaceRef->context();
-    std::shared_ptr<GeomAPI_Shape> aContext = aContextRes->shape();
-    if (!aContext.get()) {
-      static const std::string aContextError = "The selection context is bad";
-      setError(aContextError);
+  for(ListOfShape::const_iterator anIter = aShells.cbegin(); anIter != aShells.cend(); anIter++) {
+    std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
+
+    GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aToShape, aToSize, aFromShape, aFromSize);
+    if(!aPrismAlgo.isDone()) {
+      static const std::string aPrismAlgoError = "Extrusion algorithm failed";
+      setError(aPrismAlgoError);
+      aResultIndex = 0;
       break;
     }
 
-    std::shared_ptr<GeomAPI_Shape> aValueFace = aFaceRef->value();
-    int aFacesNum = -1; // this mean that "aFace" is used
-    ResultConstructionPtr aConstruction =
-      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes);
-    if (!aValueFace.get()) { // this may be the whole sketch result selected, check and get faces
-      if (aConstruction.get()) {
-        aFacesNum = aConstruction->facesNum();
-      } else {
-        static const std::string aFaceError = "Can not find basis for extrusion";
-        setError(aFaceError);
-        break;
-      }
+    // Check if shape is valid
+    if(!aPrismAlgo.shape().get() || aPrismAlgo.shape()->isNull()) {
+      static const std::string aShapeError = "Resulting shape is Null";
+      setError(aShapeError);
+      aResultIndex = 0;
+      break;
     }
-    for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
-      ResultBodyPtr aResultBody;
-
-#ifdef DEBUG_COMPSOLID_SHAPE
-      if (aFirstShapeInCompsolid && anIndex == 0)
-        aResultBody = aCompSolidResult;
-      else {
-#endif
-
-#ifdef DEBUG_COMPSOLID
-      aResultBody = aCompSolidResult->addResult(aResultIndex);
-#else
-      aResultBody = document()->createBody(data(), aResultIndex);
-#endif
-
-#ifdef DEBUG_COMPSOLID_SHAPE
-      }
-#endif
-      std::shared_ptr<GeomAPI_Shape> aBaseShape;
-      if (aFacesNum == -1) {
-        aBaseShape = aValueFace;
-      } else {
-        aBaseShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
-      }
-
-      GeomAlgoAPI_Prism aFeature(aBaseShape, aToShape, aToSize, aFromShape, aFromSize);
-      if(!aFeature.isDone()) {
-        static const std::string aFeatureError = "Extrusion algorithm failed";
-        setError(aFeatureError);
-        break;
-      }
-
-      // Check if shape is valid
-      if(!aFeature.shape().get() || aFeature.shape()->isNull()) {
-        static const std::string aShapeError = "Resulting shape is Null";
-        setError(aShapeError);
-        break;
-      }
-      if(!aFeature.isValid()) {
-        std::string aFeatureError = "Warning: resulting shape is not valid";
-        setError(aFeatureError);
-        break;
-      }
-      //LoadNamingDS
-      LoadNamingDS(aFeature, aResultBody, aBaseShape, aContext);
-      setResult(aResultBody, aResultIndex);
-      aResultIndex++;
-
-      if (aFacesNum == -1)
-        break;
+    if(!aPrismAlgo.isValid()) {
+      std::string aPrismAlgoError = "Warning: resulting shape is not valid";
+      setError(aPrismAlgoError);
+      aResultIndex = 0;
+      break;
     }
+
+    ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+    loadNamingDS(aPrismAlgo, aResultBody, aBaseShape);
+    setResult(aResultBody, aResultIndex);
+    aResultIndex++;
   }
-  // remove the rest results if there were produced in the previous pass
+
   removeResults(aResultIndex);
 }
 
 //=================================================================================================
-void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Prism& theFeature,
+void FeaturesPlugin_Extrusion::loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo,
                                             std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                                            std::shared_ptr<GeomAPI_Shape> theBasis,
-                                            std::shared_ptr<GeomAPI_Shape> theContext)
+                                            std::shared_ptr<GeomAPI_Shape> theBasis)
 {
   //load result
   ModelAPI_BodyBuilder* aResultBuilder = theResultBody->getBodyBuilder();
-  if(theBasis->isEqual(theContext))
-    aResultBuilder->store(theFeature.shape());
-  else
-    aResultBuilder->storeGenerated(theBasis, theFeature.shape());
+  if(thePrismAlgo.shape()->shapeType() == GeomAPI_Shape::COMPSOLID) {
+    int a = 1;
+  }
+  aResultBuilder->storeGenerated(theBasis, thePrismAlgo.shape());
 
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theFeature.mapOfShapes();
+  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = thePrismAlgo.mapOfShapes();
 
   //Insert lateral face : Face from Edge
   std::string aLatName = "LateralFace";
-  aResultBuilder->loadAndOrientGeneratedShapes(theFeature.makeShape().get(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes);
-
-  //Insert bottom face
-  std::string aBotName = "BottomFace";
-  std::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();
-  if(!aBottomFace->isNull()) {
-    if(aSubShapes->isBound(aBottomFace)) {
-      aBottomFace = aSubShapes->find(aBottomFace);
+  const int aLatTag = 1;
+  aResultBuilder->loadAndOrientGeneratedShapes(thePrismAlgo.makeShape().get(), theBasis, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aSubShapes);
+
+  //Insert to faces
+  std::string aToName = "ToFace";
+  const int aToTag = 2;
+  const ListOfShape& aToFaces = thePrismAlgo.toFaces();
+  for(ListOfShape::const_iterator anIt = aToFaces.cbegin(); anIt != aToFaces.cend(); anIt++) {
+    std::shared_ptr<GeomAPI_Shape> aToFace = *anIt;
+    if(aSubShapes->isBound(aToFace)) {
+      aToFace = aSubShapes->find(aToFace);
     }
-    aResultBuilder->generated(aBottomFace, aBotName, _FIRST_TAG);
+    aResultBuilder->generated(aToFace, aToName, aToTag);
   }
 
-  //Insert top face
-  std::string aTopName = "TopFace";
-  std::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
-  if (!aTopFace->isNull()) {
-    if (aSubShapes->isBound(aTopFace)) {
-      aTopFace = aSubShapes->find(aTopFace);
+  //Insert from faces
+  std::string aFromName = "FromFace";
+  const int aFromTag = 3;
+  const ListOfShape& aFromFaces = thePrismAlgo.fromFaces();
+  for(ListOfShape::const_iterator anIt = aFromFaces.cbegin(); anIt != aFromFaces.cend(); anIt++) {
+    std::shared_ptr<GeomAPI_Shape> aFromFace = *anIt;
+    if(aSubShapes->isBound(aFromFace)) {
+      aFromFace = aSubShapes->find(aFromFace);
     }
-    aResultBuilder->generated(aTopFace, aTopName, _LAST_TAG);
+    aResultBuilder->generated(aFromFace, aFromName, aFromTag);
   }
 }
index 96546369188e7e6ade2a294543cc2dce01a4a844..98c9af7c9ddf90f655fba32f66b2e9b8daf61df1 100644 (file)
@@ -113,9 +113,9 @@ class FeaturesPlugin_Extrusion : public ModelAPI_Feature
   FeaturesPlugin_Extrusion();
 private:
   /// Load Naming data structure of the feature to the document
-  void LoadNamingDS(GeomAlgoAPI_Prism& theFeature, std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                    std::shared_ptr<GeomAPI_Shape> theBasis,
-                    std::shared_ptr<GeomAPI_Shape> theContext);
+  void loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo,
+                    std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+                    std::shared_ptr<GeomAPI_Shape> theBasis);
 };
 
 #endif
index 2e8e6312d1bbb48ef7dcb2f5819bb4f11228e63c..cd204d7ed396c2a53f3f8a623778effa126176da 100644 (file)
@@ -148,7 +148,7 @@ assert (anExtrusionResult is not None)
 
 # Check extrusion volume
 aRefVolume = 100530.96491487337
-aResVolume = GeomAlgoAPI_ShapeProps_volume(anExtrusionResult.shape())
+aResVolume = GeomAlgoAPI_ShapeTools_volume(anExtrusionResult.shape())
 assert (math.fabs(aResVolume - aRefVolume) < 10 ** -5)
 
 #=========================================================================
index 95bc4841bc4548de04bdf05f6c6b71f554a6268d..d028dcfa65f62ac042e1f74a8fa876f347d7bd03 100644 (file)
@@ -14,7 +14,6 @@
         <doublevalue
           id="to_size"
           label="Size"
-          min="0"
           step="1.0"
           default="10"
           icon=":icons/dimension_up.png"
@@ -25,7 +24,6 @@
         <doublevalue
           id="from_size"
           label="Size"
-          min="0"
           step="1.0"
           default="0"
           icon=":icons/dimension_down.png"
@@ -46,7 +44,6 @@
         <doublevalue
           id="to_offset"
           label="Offset"
-          min="0"
           step="1.0"
           default="0"
           icon=":icons/dimension_up.png"
@@ -65,7 +62,6 @@
         <doublevalue
           id="from_offset"
           label="Offset"
-          min="0"
           step="1.0"
           default="0"
           icon=":icons/dimension_down.png"
index bbd1de77b3eff2152a5313bdc6bfa2b95bf867c3..a957eb3b6219ca18468d13cdc280234c189cdbcd 100644 (file)
@@ -82,6 +82,12 @@ bool GeomAPI_Shape::isSolid() const
   return !aShape.IsNull() && aShape.ShapeType() == TopAbs_SOLID;
 }
 
+GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const
+{
+  const TopoDS_Shape& aShape = impl<TopoDS_Shape>();
+  return (ShapeType)aShape.ShapeType();
+}
+
 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
                                 double& theXmax, double& theYmax, double& theZmax) const
 {
index 22362e7106455f19cae897b7741e570b359ebabb..13f000fa87f5314419c548d863fbe043fac29a27 100644 (file)
@@ -62,6 +62,10 @@ public:
   GEOMAPI_EXPORT 
   virtual bool isSolid() const;
 
+  /// Returns the shape type
+  GEOMAPI_EXPORT
+  virtual ShapeType shapeType() const;
+
   /// Computes boundary dimensions of the shape
   /// Returns False if it is not possible
   GEOMAPI_EXPORT 
index 6d14a195d8f185caa9012931274b4505609bfb32..5b986ce0a86c305beefa9e1358985469751df4ba 100644 (file)
@@ -21,7 +21,6 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_Movement.h
     GeomAlgoAPI_MakeShape.h
     GeomAlgoAPI_MakeShapeList.h
-    GeomAlgoAPI_ShapeProps.h
     GeomAlgoAPI_DFLoader.h
     GeomAlgoAPI_Placement.h
     GeomAlgoAPI_BREPImport.h
@@ -31,6 +30,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_STEPExport.h
     GeomAlgoAPI_IGESExport.h
     GeomAlgoAPI_Transform.h
+    GeomAlgoAPI_ShapeTools.h
 )
 
 SET(PROJECT_SOURCES
@@ -48,7 +48,6 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_Movement.cpp
     GeomAlgoAPI_MakeShape.cpp
     GeomAlgoAPI_MakeShapeList.cpp
-    GeomAlgoAPI_ShapeProps.cpp
     GeomAlgoAPI_DFLoader.cpp
     GeomAlgoAPI_Placement.cpp
     GeomAlgoAPI_BREPImport.cpp
@@ -58,6 +57,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_STEPExport.cpp
     GeomAlgoAPI_IGESExport.cpp
     GeomAlgoAPI_Transform.cpp
+    GeomAlgoAPI_ShapeTools.cpp
 )
 
 SET(PROJECT_LIBRARIES
@@ -76,7 +76,8 @@ SET(PROJECT_LIBRARIES
     ${CAS_TKSTEPBase}
     ${CAS_TKIGES}
     ${CAS_TKTopAlgo}
-    ${CAS_TKXSBase} 
+    ${CAS_TKXSBase}
+    ${CAS_TKOffset}
 )
 
 ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
index 5d102832a96f9d7ab54b3bf7dd46b770ab55d59d..01c3b71d8f56df248bec4bb9d85dde67f4ce2b49 100644 (file)
@@ -16,7 +16,7 @@
   #include "GeomAlgoAPI_Prism.h"
   #include "GeomAlgoAPI_Revolution.h"
   #include "GeomAlgoAPI_Rotation.h"
-  #include "GeomAlgoAPI_ShapeProps.h"
+  #include "GeomAlgoAPI_ShapeTools.h"
   #include "GeomAlgoAPI_SketchBuilder.h"
   #include "GeomAlgoAPI_BREPExport.h"
   #include "GeomAlgoAPI_IGESExport.h"
@@ -56,7 +56,7 @@
 %include "GeomAlgoAPI_Prism.h"
 %include "GeomAlgoAPI_Revolution.h"
 %include "GeomAlgoAPI_Rotation.h"
-%include "GeomAlgoAPI_ShapeProps.h"
+%include "GeomAlgoAPI_ShapeTools.h"
 %include "GeomAlgoAPI_SketchBuilder.h"
 %include "GeomAlgoAPI_BREPExport.h"
 %include "GeomAlgoAPI_IGESExport.h"
index 22bde17c0ada382ba535d43dd829125f31331e69..b1affac1c70e214eff694c38ba36ef2b550bdacb 100644 (file)
@@ -6,14 +6,25 @@
 
 #include <GeomAlgoAPI_MakeShape.h>
 #include <BRepBuilderAPI_MakeShape.hxx>
+#include <BRepOffsetAPI_MakePipe.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
+
 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape)
   : GeomAPI_Interface(theMkShape),myShape(new GeomAPI_Shape())
 {
   myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
 }
 
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape, const std::shared_ptr<GeomAPI_Shape> theWire)
+: GeomAPI_Interface(theMkShape),
+  myShape(new GeomAPI_Shape()),
+  myWire(theWire)
+{
+  myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
+}
+
 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
   : GeomAPI_Interface(),myShape(new GeomAPI_Shape())
 {}
@@ -26,14 +37,27 @@ const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
 void GeomAlgoAPI_MakeShape::generated(
   const std::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
 {
-  BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
-  if(aBuilder) {
-    const TopTools_ListOfShape& aList =  aBuilder->Generated(theShape->impl<TopoDS_Shape>());
-    TopTools_ListIteratorOfListOfShape it(aList);
-    for(;it.More();it.Next()) {
-      std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
-      aShape->setImpl(new TopoDS_Shape(it.Value()));
-      theHistory.push_back(aShape);
+  if(!myWire.get()) {
+    BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+    if(aBuilder) {
+      const TopTools_ListOfShape& aList =  aBuilder->Generated(theShape->impl<TopoDS_Shape>());
+      TopTools_ListIteratorOfListOfShape it(aList);
+      for(;it.More();it.Next()) {
+        std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+        aShape->setImpl(new TopoDS_Shape(it.Value()));
+        theHistory.push_back(aShape);
+      }
+    }
+  } else { // Pipe builder
+    BRepOffsetAPI_MakePipe* aPipeBuilder = implPtr<BRepOffsetAPI_MakePipe>();
+    if(aPipeBuilder) {
+      TopExp_Explorer aShapeExplorer(myWire->impl<TopoDS_Wire>(), TopAbs_EDGE);
+      for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+        const TopoDS_Shape& aGeneratedShape = aPipeBuilder->Generated(aShapeExplorer.Current(), theShape->impl<TopoDS_Shape>());
+        std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+        aShape->setImpl(new TopoDS_Shape(aGeneratedShape));
+        theHistory.push_back(aShape);
+      }
     }
   }
 }
index 38519b03fa3c9e553100c1ff74e3f1838ec4012a..f028855edb4def81d963382b03a9ce57de7a03ef 100644 (file)
@@ -24,6 +24,9 @@ public:
   /// Constructor by the already stored builder in the interface
   GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(void* theBuilder);
 
+  /// Constructor by the builder and wire. Used for pipe builder.
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(void* theBuilder, const std::shared_ptr<GeomAPI_Shape> theWire);
+
   /// Returns a shape built by the shape construction algorithm
   GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>  shape() const;
 
@@ -40,7 +43,8 @@ public:
 
   protected:
   /// The resulting shape
-       std::shared_ptr<GeomAPI_Shape> myShape;
+  std::shared_ptr<GeomAPI_Shape> myShape;
+  std::shared_ptr<GeomAPI_Shape> myWire;
 };
 
 typedef std::list<std::shared_ptr<GeomAlgoAPI_MakeShape> > ListOfMakeShape;
index 58518ea491c7dedb0607098130171d6eb8d0c0e2..b6270b5943c65f0813385a11b274a18ed733f07b 100644 (file)
@@ -79,25 +79,28 @@ void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theS
   aResultShapes.Add(theShape->impl<TopoDS_Shape>());
 
   for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
-    BRepBuilderAPI_MakeShape* aBuilder = (*aBuilderIt)->implPtr<BRepBuilderAPI_MakeShape>();
+    std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
     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& aGeneratedList = aBuilder->Generated(aShape);
-      for(TopTools_ListIteratorOfListOfShape anIt(aGeneratedList); anIt.More(); anIt.Next()) {
-        aTempShapes.Add(anIt.Value());
-        aResultShapes.Add(anIt.Value());
+      std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+      aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
+      ListOfShape aGeneratedShapes;
+      aMakeShape->generated(aShape, aGeneratedShapes);
+      for(ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
+        aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
+        aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
         hasResults = true;
       }
-      const TopTools_ListOfShape& aModifiedList = aBuilder->Modified(aShape);
-      for(TopTools_ListIteratorOfListOfShape anIt(aModifiedList); anIt.More(); anIt.Next()) {
-        aTempShapes.Add(anIt.Value());
-        aResultShapes.Add(anIt.Value());
+      ListOfShape aModifiedShapes;
+      aMakeShape->modified(aShape, aModifiedShapes);
+      for(ListOfShape::const_iterator anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
+        aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
+        aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
         hasResults = true;
       }
       if(hasResults) {
-        aResultShapes.Remove(aShape);
+        aResultShapes.Remove(aShape->impl<TopoDS_Shape>());
       }
     }
     anAlgoShapes.Unite(aTempShapes);
index 48073be5f519b342bd259ced85e55f18093310b8..ab9b43fc2aa4ec3592b17ae9fe05a52d7cd6069e 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <GeomAlgoAPI_Movement.h>
 
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
 #include <BRepBuilderAPI_Transform.hxx>
 #include <BRepCheck_Analyzer.hxx>
@@ -92,7 +92,7 @@ const bool GeomAlgoAPI_Movement::isValid() const
 const bool GeomAlgoAPI_Movement::hasVolume() const
 {
   bool hasVolume(false);
-  if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
+  if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
     hasVolume = true;
   }
   return hasVolume;
index 0677d7fc6c7a03dedf2f3fba6d9c47118b905561..c084b60a649c37836a07554ca75c5d31e5145949 100644 (file)
@@ -9,19 +9,37 @@
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeExplorer.h>
 #include <GeomAPI_XYZ.h>
 #include <GeomAlgoAPI_DFLoader.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_MakeShapeList.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
+#include <Bnd_Box.hxx>
+#include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
+#include <BRepAlgoAPI_Cut.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
 #include <BRepCheck_Analyzer.hxx>
-#include <BRepFeat_MakePrism.hxx>
+#include <BRepExtrema_ExtCF.hxx>
 #include <BRepGProp.hxx>
+#include <BRepOffsetAPI_MakePipe.hxx>
+#include <BRepTools.hxx>
 #include <Geom_Plane.hxx>
 #include <gp_Pln.hxx>
 #include <GProp_GProps.hxx>
+#include <TCollection_AsciiString.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Shell.hxx>
+#include <TopoDS_Solid.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
 //=================================================================================================
 GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
@@ -52,12 +70,24 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
 {
   if(!theBasis ||
     (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape)))
-    && (theFromSize == 0.0 && theToSize == 0.0))) {
+    && (theFromSize == -theToSize))) {
     return;
   }
 
   // If bounding faces was not set creating them.
-  std::shared_ptr<GeomAPI_Face>  aBaseFace(new GeomAPI_Face(theBasis));
+  std::shared_ptr<GeomAPI_Face> aBaseFace;
+  if(theBasis->shapeType() == GeomAPI_Shape::SHELL) {
+    GeomAPI_ShapeExplorer anExp(theBasis, GeomAPI_Shape::FACE);
+    if(anExp.more()) {
+      std::shared_ptr<GeomAPI_Shape> aFaceOnShell = anExp.current();
+      aBaseFace = std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(aFaceOnShell));
+    }
+  } else {
+    aBaseFace = std::shared_ptr<GeomAPI_Face>(new GeomAPI_Face(theBasis));
+  }
+  if(!aBaseFace.get()) {
+    return;
+  }
   std::shared_ptr<GeomAPI_Pln>   aBasePln = aBaseFace->getPlane();
   std::shared_ptr<GeomAPI_Dir>   aBaseDir = aBasePln->direction();
   std::shared_ptr<GeomAPI_Pnt>   aBaseLoc = aBasePln->location();
@@ -87,46 +117,165 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
                                                       aSign ? -theToSize : theToSize))));
   aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
 
-  TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
-  Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aBasis));
-  if(aPlane.IsNull()) { // non-planar shapes is not supported for extrusion yet
+  // Getting bounding box for base shape.
+  const TopoDS_Shape& aBasisShape = theBasis->impl<TopoDS_Shape>();
+  Bnd_Box aBndBox;
+  BRepBndLib::Add(aBasisShape, aBndBox);
+  Standard_Real aXArr[2] = {aBndBox.CornerMin().X(), aBndBox.CornerMax().X()};
+  Standard_Real aYArr[2] = {aBndBox.CornerMin().Y(), aBndBox.CornerMax().Y()};
+  Standard_Real aZArr[2] = {aBndBox.CornerMin().Z(), aBndBox.CornerMax().Z()};
+  gp_Pnt aPoints[8];
+  int aNum = 0;
+  for(int i = 0; i < 2; i++) {
+    for(int j = 0; j < 2; j++) {
+      for(int k = 0; k < 2; k++) {
+        aPoints[aNum] = gp_Pnt(aXArr[i], aYArr[j], aZArr[k]);
+        aNum++;
+      }
+    }
+  }
+
+  // Project points to bounding planes. Search max distance to them.
+  const TopoDS_Shape& aBndToShape = aBoundingToShape->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aBndFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
+  Standard_Real aMaxToDist = 0, aMaxFromDist = 0;
+  gp_Vec aNormal(aBaseDir->impl<gp_Dir>());
+  for(int i = 0; i < 8; i++) {
+    gp_Lin aLine(aPoints[i], aNormal);
+    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aLine).Edge();
+    BRepExtrema_ExtCF aToExt(anEdge, TopoDS::Face(aBndToShape));
+    BRepExtrema_ExtCF aFromExt(anEdge, TopoDS::Face(aBndFromShape));
+    if(aToExt.NbExt() == 0 || aFromExt.NbExt() == 0) {
+      return;
+    }
+    const gp_Pnt& aPntOnToFace = aToExt.PointOnFace(1);
+    const gp_Pnt& aPntOnFromFace = aFromExt.PointOnFace(1);
+    if(aPoints[i].Distance(aPntOnToFace) > aMaxToDist) {
+      aMaxToDist = aPoints[i].Distance(aPntOnToFace);
+    }
+    if(aPoints[i].Distance(aPntOnFromFace) > aMaxFromDist) {
+      aMaxFromDist = aPoints[i].Distance(aPntOnFromFace);
+    }
+  }
+  Standard_Real aPipeLength = aMaxToDist + aMaxFromDist;
+
+  // Making wire for pipe.
+  std::shared_ptr<GeomAPI_Pnt> aCentreOfMass = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis);
+  const gp_Pnt aCentrePnt = aCentreOfMass->impl<gp_Pnt>();
+  TopoDS_Face aFace = TopoDS::Face(aBaseFace->impl<TopoDS_Shape>());
+  gp_Pnt aPipeStartPnt = aCentrePnt.Translated(aNormal.Scaled(aPipeLength));
+  gp_Pnt aPipeEndPnt = aCentrePnt.Translated(aNormal.Scaled(-aPipeLength));
+  TopoDS_Edge aPipeEdge = BRepBuilderAPI_MakeEdge(aPipeStartPnt, aPipeEndPnt);
+  TopoDS_Wire aPipeWire = BRepBuilderAPI_MakeWire(aPipeEdge).Wire();
+
+  // Making pipe.
+  ListOfMakeShape aListOfMakeShape;
+  BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPipeWire, aBasisShape);
+  if(!aPipeBuilder) {
     return;
   }
+  std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
+  aWire->setImpl(new TopoDS_Shape(aPipeWire));
+  aListOfMakeShape.push_back(std::make_shared<GeomAlgoAPI_MakeShape>(aPipeBuilder, aWire));
+  TopoDS_Shape aResult = aPipeBuilder->Shape();
 
-  const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
-  BRepFeat_MakePrism* aBuilder = new BRepFeat_MakePrism(aBasis, aBasis, aBasis, aNormal, 2, Standard_True);
-
-  if(aBuilder) {
-    const TopoDS_Shape& aFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
-    const TopoDS_Shape& aToShape   = aBoundingToShape->impl<TopoDS_Shape>();
-    aBuilder->Perform(aFromShape, aToShape);
-    myDone = aBuilder->IsDone() == Standard_True;
-    if(myDone){
-      TopoDS_Shape aResult = aBuilder->Shape();
-      TopExp_Explorer anExp(aResult, TopAbs_SOLID);
-      if(!anExp.More()) {
-        return;
-      }
-      if(aResult.ShapeType() == TopAbs_COMPOUND) {
-        aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
-      }
-      // fill data map to keep correct orientation of sub-shapes
-      myMap = std::shared_ptr<GeomAPI_DataMapOfShapeShape>(new GeomAPI_DataMapOfShapeShape());
-      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 = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-      myShape->setImpl(new TopoDS_Shape(aResult));
-      myFirst = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-      myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First()));
-      myLast = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
-      myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First()));
-      myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape());
-      myMkShape->setImpl(aBuilder);
+  // Orienting bounding planes.
+  gp_Lin aLine(aCentrePnt, aNormal);
+  TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aLine).Edge();
+  BRepExtrema_ExtCF aToExt(anEdge, TopoDS::Face(aBndToShape));
+  BRepExtrema_ExtCF aFromExt(anEdge, TopoDS::Face(aBndFromShape));
+  Standard_Real aToParameter = aToExt.ParameterOnEdge(1);
+  Standard_Real aFromParameter = aFromExt.ParameterOnEdge(1);
+  if(aToParameter > aFromParameter) {
+    gp_Vec aVec = aToDir->impl<gp_Dir>();
+    if((aVec * aNormal) > 0) {
+      aToDir->setImpl(new gp_Dir(aVec.Reversed()));
+      aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
+    }
+    aVec = aFromDir->impl<gp_Dir>();
+    if((aVec * aNormal) < 0) {
+      aFromDir->setImpl(new gp_Dir(aVec.Reversed()));
+      aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
+    }
+  } else {
+    gp_Vec aVec = aToDir->impl<gp_Dir>();
+    if((aVec * aNormal) < 0) {
+      aToDir->setImpl(new gp_Dir(aVec.Reversed()));
+      aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
     }
+    aVec = aFromDir->impl<gp_Dir>();
+    if((aVec * aNormal) > 0) {
+      aFromDir->setImpl(new gp_Dir(aVec.Reversed()));
+      aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
+    }
+  }
+
+  // Making solids from bounding planes.
+  TopoDS_Shell aToShell, aFromShell;
+  TopoDS_Solid aToSolid, aFromSolid;
+  const TopoDS_Shape& aToShape   = aBoundingToShape->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
+  BRep_Builder aBoundingBuilder;
+  aBoundingBuilder.MakeShell(aToShell);
+  aBoundingBuilder.MakeShell(aFromShell);
+  aBoundingBuilder.Add(aToShell, aToShape);
+  aBoundingBuilder.Add(aFromShell, aFromShape);
+  aBoundingBuilder.MakeSolid(aToSolid);
+  aBoundingBuilder.MakeSolid(aFromSolid);
+  aBoundingBuilder.Add(aToSolid, aToShell);
+  aBoundingBuilder.Add(aFromSolid, aFromShell);
+
+  // Cutting with to plane.
+  BRepAlgoAPI_Cut* aToCutBuilder = new BRepAlgoAPI_Cut(aResult, aToSolid);
+  aToCutBuilder->Build();
+  if(!aToCutBuilder->IsDone()) {
+    return;
+  }
+  aListOfMakeShape.push_back(std::make_shared<GeomAlgoAPI_MakeShape>(aToCutBuilder));
+  const TopTools_ListOfShape& aToShapes = aToCutBuilder->Modified(aToShape);
+  for(TopTools_ListIteratorOfListOfShape anIt(aToShapes); anIt.More(); anIt.Next()) {
+    std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+    aShape->setImpl(new TopoDS_Shape(anIt.Value()));
+    myToFaces.push_back(aShape);
+  }
+  aResult = aToCutBuilder->Shape();
+
+  // Cutting with from plane.
+  BRepAlgoAPI_Cut* aFromCutBuilder = new BRepAlgoAPI_Cut(aResult, aFromSolid);
+  aFromCutBuilder->Build();
+  if(!aFromCutBuilder->IsDone()) {
+    return;
   }
+  aListOfMakeShape.push_back(std::make_shared<GeomAlgoAPI_MakeShape>(aFromCutBuilder));
+  const TopTools_ListOfShape& aFromShapes = aFromCutBuilder->Modified(aFromShape);
+  for(TopTools_ListIteratorOfListOfShape anIt(aFromShapes); anIt.More(); anIt.Next()) {
+    std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+    aShape->setImpl(new TopoDS_Shape(anIt.Value()));
+    myFromFaces.push_back(aShape);
+  }
+  aResult = aFromCutBuilder->Shape();
+
+  TopExp_Explorer anExp(aResult, TopAbs_SOLID);
+  if(!anExp.More()) {
+    return;
+  }
+  if(aResult.ShapeType() == TopAbs_COMPOUND) {
+    aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+  }
+
+  myShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+  myShape->setImpl(new TopoDS_Shape(aResult));
+
+  // Fill data map to keep correct orientation of sub-shapes.
+  myMap = std::shared_ptr<GeomAPI_DataMapOfShapeShape>(new GeomAPI_DataMapOfShapeShape);
+  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);
+  }
+
+  myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
+  myDone = true;
 }
 
 //=================================================================================================
@@ -163,15 +312,15 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::shape() const
 }
 
 //=================================================================================================
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::firstShape() const
+const ListOfShape& GeomAlgoAPI_Prism::fromFaces() const
 {
-  return myFirst;
+  return myFromFaces;
 }
 
 //=================================================================================================
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::lastShape() const
+const ListOfShape& GeomAlgoAPI_Prism::toFaces() const
 {
-  return myLast;
+  return myToFaces;
 }
 
 //=================================================================================================
index 9a5cf59cba607f4076c6f0de53f876059130f164..cb0747181f34d74fad2cb08c539d55c8ba4efe5b 100644 (file)
@@ -56,11 +56,11 @@ public:
   /// \return result of the Prism algorithm.
   GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape() const;
 
-  /// \returns the first shape.
-  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> firstShape() const;
+  /// \returns the list of from faces.
+  GEOMALGOAPI_EXPORT const ListOfShape& fromFaces() const;
 
-  /// \return the last shape.
-  GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> lastShape() const;
+  /// \return the list of to faces.
+  GEOMALGOAPI_EXPORT const ListOfShape& toFaces() const;
 
   /// \return map of sub-shapes of the result. To be used for History keeping.
   GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfShapes() const;
@@ -80,8 +80,8 @@ private:
   /// Fields.
   bool myDone;
   std::shared_ptr<GeomAPI_Shape> myShape;
-  std::shared_ptr<GeomAPI_Shape> myFirst;
-  std::shared_ptr<GeomAPI_Shape> myLast;
+  ListOfShape myFromFaces;
+  ListOfShape myToFaces;
   std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
   std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
 };
index f47d8a06ff23c56be6f87a4ce88c238bbbf1791c..11c8091b0e301d021dc4b4c4d9a8af12d1c07988 100644 (file)
@@ -9,7 +9,7 @@
 #include <GeomAlgoAPI_DFLoader.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
 #include <GeomAlgoAPI_Rotation.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
@@ -173,7 +173,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr<GeomAPI_Shape>& theBasi
 
     // Orienting bounding planes properly so that the center of mass of the base face stays
     // on the result shape after cut.
-    gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeProps::centreOfMass(theBasis)->impl<gp_Pnt>();
+    gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis)->impl<gp_Pnt>();
     aFromFace = makeFaceFromPlane(aFromPln, aBasisCentr);
     aToFace   = makeFaceFromPlane(aToPln, aBasisCentr);
 
@@ -255,7 +255,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr<GeomAPI_Shape>& theBasi
 
     // Orienting bounding plane properly so that the center of mass of the base face stays
     // on the result shape after cut.
-    gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeProps::centreOfMass(theBasis)->impl<gp_Pnt>();
+    gp_Pnt aBasisCentr = GeomAlgoAPI_ShapeTools::centreOfMass(theBasis)->impl<gp_Pnt>();
     aBoundingFace = makeFaceFromPlane(aBoundingPln, aBasisCentr);
 
     // Making solid from bounding plane.
@@ -362,7 +362,7 @@ void GeomAlgoAPI_Revolution::build(const std::shared_ptr<GeomAPI_Shape>& theBasi
   }
   myShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
   myShape->setImpl(new TopoDS_Shape(aResult));
-  myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(new GeomAlgoAPI_MakeShapeList());
+  myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
   myDone = true;
   return;
 }
index 17c88e408cc942d164eaa83d6f03430d97f8afce..3b24af85bb92f9399f6c5f0492eaac967f980aa9 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <GeomAlgoAPI_Rotation.h>
 
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
 #include <BRepBuilderAPI_Transform.hxx>
 #include <BRepCheck_Analyzer.hxx>
@@ -90,7 +90,7 @@ const bool GeomAlgoAPI_Rotation::isValid() const
 const bool GeomAlgoAPI_Rotation::hasVolume() const
 {
   bool hasVolume(false);
-  if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
+  if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
     hasVolume = true;
   }
   return hasVolume;
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.cpp
deleted file mode 100644 (file)
index fcec982..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomAlgoAPI_ShapeProps.cpp
-// Created:     8 May 2015
-// Author:      Dmitry Bobylev
-
-#include <GeomAlgoAPI_ShapeProps.h>
-
-#include <BRepGProp.hxx>
-#include <GProp_GProps.hxx>
-#include <TopoDS_Shape.hxx>
-
-//=================================================================================================
-double GeomAlgoAPI_ShapeProps::volume(std::shared_ptr<GeomAPI_Shape> theShape)
-{
-  GProp_GProps aGProps;
-  if(!theShape) {
-    return 0.0;
-  }
-  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
-  if(aShape.IsNull()) {
-    return 0.0;
-  }
-  BRepGProp::VolumeProperties(aShape, aGProps);
-  return aGProps.Mass();
-}
-
-//=================================================================================================
-std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeProps::centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape)
-{
-  GProp_GProps aGProps;
-  if(!theShape) {
-    return std::shared_ptr<GeomAPI_Pnt>();
-  }
-  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
-  if(aShape.IsNull()) {
-    return std::shared_ptr<GeomAPI_Pnt>();
-  }
-  BRepGProp::SurfaceProperties(aShape, aGProps);
-  gp_Pnt aCentre = aGProps.CentreOfMass();
-  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
-}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeProps.h
deleted file mode 100644 (file)
index d802840..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomAlgoAPI_ShapeProps.h
-// Created:     8 May 2015
-// Author:      Dmitry Bobylev
-
-#ifndef GeomAlgoAPI_ShapeProps_H_
-#define GeomAlgoAPI_ShapeProps_H_
-
-#include <GeomAlgoAPI.h>
-
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Shape.h>
-
-/** \class GeomAlgoAPI_ShapeProps
- *  \ingroup DataAlgo
- *  \brief Allows to compute different shape props.
- */
-class GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeProps
-{
-public:
-  /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
-  static double volume(std::shared_ptr<GeomAPI_Shape> theShape);
-
-  /// \return the centre of mass of the current face. The coordinates returned for the center of mass
-  /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
-  static std::shared_ptr<GeomAPI_Pnt> centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape);
-};
-
-#endif
-
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
new file mode 100644 (file)
index 0000000..aa54868
--- /dev/null
@@ -0,0 +1,142 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAlgoAPI_ShapeTools.h
+// Created:     3 August 2015
+// Author:      Dmitry Bobylev
+
+#include <GeomAlgoAPI_ShapeTools.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <BOPTools.hxx>
+#include <BRepGProp.hxx>
+#include <BRepTools.hxx>
+#include <GProp_GProps.hxx>
+#include <NCollection_Vector.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TopoDS_Builder.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Shell.hxx>
+
+//=================================================================================================
+double GeomAlgoAPI_ShapeTools::volume(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  GProp_GProps aGProps;
+  if(!theShape) {
+    return 0.0;
+  }
+  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+  if(aShape.IsNull()) {
+    return 0.0;
+  }
+  BRepGProp::VolumeProperties(aShape, aGProps);
+  return aGProps.Mass();
+}
+
+//=================================================================================================
+std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeTools::centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  GProp_GProps aGProps;
+  if(!theShape) {
+    return std::shared_ptr<GeomAPI_Pnt>();
+  }
+  const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+  if(aShape.IsNull()) {
+    return std::shared_ptr<GeomAPI_Pnt>();
+  }
+  BRepGProp::SurfaceProperties(aShape, aGProps);
+  gp_Pnt aCentre = aGProps.CentreOfMass();
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
+}
+
+//=================================================================================================
+void GeomAlgoAPI_ShapeTools::combineFacesToShells(const ListOfShape& theFacesList,
+                                                  ListOfShape& theShells,
+                                                  ListOfShape& theFreeFaces)
+{
+  if(theFacesList.empty()) {
+    return;
+  }
+
+  // Adding all faces to compoud.
+  std::shared_ptr<GeomAPI_Shape> aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(theFacesList);
+  if(!aFacesCompound.get()) {
+    return;
+  }
+
+  // Map edges and faces.
+  const TopoDS_Shape& aFacesComp = aFacesCompound->impl<TopoDS_Shape>();
+  BOPCol_IndexedDataMapOfShapeListOfShape aMapEF;
+  BOPTools::MapShapesAndAncestors(aFacesComp, TopAbs_EDGE, TopAbs_FACE, aMapEF);
+  if(aMapEF.IsEmpty()) {
+    return;
+  }
+
+  // Get all faces with common edges and free faces.
+  NCollection_Map<TopoDS_Shape> aFreeFaces;
+  NCollection_Vector<NCollection_Map<TopoDS_Shape>> aFacesWithCommonEdges;
+  for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapEF); anIter.More(); anIter.Next()) {
+    const TopoDS_Shape& aShape = anIter.Key();
+    BOPCol_ListOfShape& aListOfShape = anIter.ChangeValue();
+    if(aListOfShape.IsEmpty()) {
+      continue;
+    }
+    else if(aListOfShape.Size() == 1) {
+      aFreeFaces.Add(aListOfShape.First());
+      aListOfShape.Clear();
+    } else {
+      NCollection_Map<TopoDS_Shape> aTempMap;
+      aTempMap.Add(aListOfShape.First());
+      aTempMap.Add(aListOfShape.Last());
+      aFreeFaces.Remove(aListOfShape.First());
+      aFreeFaces.Remove(aListOfShape.Last());
+      aListOfShape.Clear();
+      for(NCollection_Map<TopoDS_Shape>::Iterator aTempIter(aTempMap); aTempIter.More(); aTempIter.Next()) {
+        const TopoDS_Shape& aTempShape = aTempIter.Value();
+        for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapEF); anIter.More(); anIter.Next()) {
+          BOPCol_ListOfShape& aTempListOfShape = anIter.ChangeValue();
+          if(aTempListOfShape.IsEmpty()) {
+            continue;
+          } else if(aTempListOfShape.Size() == 1 && aTempListOfShape.First() == aTempShape) {
+            aTempListOfShape.Clear();
+          } else if(aTempListOfShape.Size() > 1) {
+            if(aTempListOfShape.First() == aTempShape) {
+              aTempMap.Add(aTempListOfShape.Last());
+              aFreeFaces.Remove(aTempListOfShape.Last());
+              aTempListOfShape.Clear();
+            } else if(aTempListOfShape.Last() == aTempShape) {
+              aTempMap.Add(aTempListOfShape.First());
+              aFreeFaces.Remove(aTempListOfShape.First());
+              aTempListOfShape.Clear();
+            }
+          }
+        }
+      }
+      aFacesWithCommonEdges.Append(aTempMap);
+    }
+  }
+
+  // Make shells from faces with common edges.
+  NCollection_Vector<TopoDS_Shape> aShells;
+  for(NCollection_Vector<NCollection_Map<TopoDS_Shape>>::Iterator anIter(aFacesWithCommonEdges); anIter.More(); anIter.Next()) {
+    TopoDS_Shell aShell;
+    TopoDS_Builder aBuilder;
+    aBuilder.MakeShell(aShell);
+    const NCollection_Map<TopoDS_Shape>& aShapesMap = anIter.Value();
+    for(NCollection_Map<TopoDS_Shape>::Iterator aShIter(aShapesMap); aShIter.More(); aShIter.Next()) {
+      const TopoDS_Shape& aFace = aShIter.Value();
+      aBuilder.Add(aShell, aFace);
+    }
+    std::shared_ptr<GeomAPI_Shape> aGeomShell(std::make_shared<GeomAPI_Shape>());
+    aGeomShell->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShell));
+    theShells.push_back(aGeomShell);
+  }
+
+  // Adding free faces.
+  for(NCollection_Map<TopoDS_Shape>::Iterator aShIter(aFreeFaces); aShIter.More(); aShIter.Next()) {
+    const TopoDS_Shape& aFace = aShIter.Value();
+    std::shared_ptr<GeomAPI_Shape> aGeomFace(std::make_shared<GeomAPI_Shape>());
+    aGeomFace->setImpl<TopoDS_Shape>(new TopoDS_Shape(aFace));
+    theFreeFaces.push_back(aGeomFace);
+  }
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
new file mode 100644 (file)
index 0000000..9dce03c
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAlgoAPI_ShapeTools.h
+// Created:     3 August 2015
+// Author:      Dmitry Bobylev
+
+#ifndef GeomAlgoAPI_ShapeTools_H_
+#define GeomAlgoAPI_ShapeTools_H_
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
+
+#include <map>
+
+/** \class GeomAlgoAPI_ShapeTools
+ *  \ingroup DataAlgo
+ *  \brief
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeTools
+{
+public:
+  /// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
+  static double volume(std::shared_ptr<GeomAPI_Shape> theShape);
+
+  /// \return the centre of mass of the current face. The coordinates returned for the center of mass
+  /// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
+  static std::shared_ptr<GeomAPI_Pnt> centreOfMass(std::shared_ptr<GeomAPI_Shape> theShape);
+
+  /** \brief Combines faces with common edges to shells
+   *  \param[in] theFacesList list of faces to be combined.
+   *  \param[out] theShells resulting shells.
+   *  \param[out] theFreeFaces faces that does not have common edges.
+   */
+  static void combineFacesToShells(const ListOfShape& theFacesList,
+                                   ListOfShape& theShells,
+                                   ListOfShape& theFreeFaces);
+};
+
+#endif
index 65840c27357c821b210229751b1f7ac995c314ce..e5409c49e64b11c9004af9470f42712db042abbf 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <GeomAlgoAPI_Transform.h>
 
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
 #include <BRepBuilderAPI_Transform.hxx>
 #include <BRepCheck_Analyzer.hxx>
@@ -74,7 +74,7 @@ const bool GeomAlgoAPI_Transform::isValid() const
 const bool GeomAlgoAPI_Transform::hasVolume() const
 {
   bool hasVolume(false);
-  if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
+  if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
     hasVolume = true;
   }
   return hasVolume;
index 63e6d5f89a8f49a27b7f21ab8524db6dbcc02f50..f2857f935bee26f0f55f7f702796e1e20dd4e8a0 100644 (file)
@@ -43,7 +43,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>&
   anIt++;
 
   if(aSelectedMethod == aCreationMethod) {
-    if(aToSize == 0.0 && aFromSize == 0.0) {
+    if(aToSize == -aFromSize) {
       return false;
     } else {
       return true;
@@ -83,7 +83,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>&
   }
 
   if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
-    && (aFromSize == 0.0 && aToSize == 0.0)) {
+    && (aFromSize == -aToSize)) {
     return false;
   }
 
index f0bfdc8a20b8a9985c67359e8620bd66f3ff819d..b2883760df632b2c29792fdeac1c0df86d8ca02c 100644 (file)
@@ -26,7 +26,7 @@
 #include <ModelAPI_Tools.h>
 
 #include <GeomAlgoAPI_FaceBuilder.h>
-#include <GeomAlgoAPI_ShapeProps.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomAPI_XYZ.h>
@@ -155,7 +155,7 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
 
     // orienting projection
     if(aBaseShape.get() != NULL) {
-      std::shared_ptr<GeomAPI_Pnt> aCenterPnt = GeomAlgoAPI_ShapeProps::centreOfMass(aGShape);
+      std::shared_ptr<GeomAPI_Pnt> aCenterPnt = GeomAlgoAPI_ShapeTools::centreOfMass(aGShape);
       gp_Pnt aPnt = aCenterPnt->impl<gp_Pnt>();
       aPnt.Translate(aDir->impl<gp_Dir>().XYZ() * (10 * Precision::Confusion()));