]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Extrusion cut execute draft version. No naming!
authordbv <dbv@opencascade.com>
Wed, 10 Jun 2015 15:05:37 +0000 (18:05 +0300)
committerdbv <dbv@opencascade.com>
Wed, 10 Jun 2015 15:05:54 +0000 (18:05 +0300)
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Prism.h

index c2a4ea46b02c6eeeb91437110c2438c28094272c..555590596688b4b109c84552220276b6da397fa6 100644 (file)
@@ -99,7 +99,6 @@ void FeaturesPlugin_Boolean::execute()
 
   int aResultIndex = 0;
   ListOfMakeShape aListOfMakeShape;
-  std::shared_ptr<GeomAPI_Shape> aResShape;
   std::shared_ptr<GeomAPI_DataMapOfShapeShape> aDataMapOfShapes;
 
   switch(aType) {
@@ -110,7 +109,6 @@ void FeaturesPlugin_Boolean::execute()
         std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
         ListOfShape aListWithObject;
         aListWithObject.push_back(anObject);
-        aResShape = anObject;
         GeomAlgoAPI_Boolean aBoolAlgo(aListWithObject, aTools, aType);
 
         // Checking that the algorithm worked properly.
index fa7484b657f0350a272577f2fd859f4df364c759..ac82eefc157ba622f2a44ca9483e043e8f493259 100644 (file)
@@ -53,10 +53,10 @@ void FeaturesPlugin_Extrusion::execute()
 {
   AttributeSelectionListPtr aFaceRefs = selectionList(FeaturesPlugin_Extrusion::LIST_ID());
 
+  // Getting bounding planes.
   std::shared_ptr<GeomAPI_Shape> aFromShape;
   std::shared_ptr<GeomAPI_Shape> aToShape;
 
-  // Getting bounding planes.
   std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID());
   if (anObjRef) {
     aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
index 09d56a48671f14f59a05d69dbcf5c858a93ebb1c..63409d43821b02f93d376deeb6aa2e8fb0e8505e 100755 (executable)
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <GeomAlgoAPI_Boolean.h>
+#include <GeomAlgoAPI_Prism.h>
+#include <GeomAlgoAPI_ShapeProps.h>
 
 //=================================================================================================
 FeaturesPlugin_ExtrusionCut::FeaturesPlugin_ExtrusionCut()
@@ -31,8 +37,8 @@ void FeaturesPlugin_ExtrusionCut::initAttributes()
   data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
 
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_ExtrusionCut::FROM_OBJECT_ID());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_ExtrusionCut::TO_OBJECT_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
 
   data()->addAttribute(CUTLIST_ID(), ModelAPI_AttributeSelectionList::typeId());
 
@@ -93,4 +99,85 @@ void FeaturesPlugin_ExtrusionCut::removeFeature(std::shared_ptr<ModelAPI_Feature
 //=================================================================================================
 void FeaturesPlugin_ExtrusionCut::execute()
 {
+  // Getting extrusion bounding planes.
+  std::shared_ptr<GeomAPI_Shape> aFromShape;
+  std::shared_ptr<GeomAPI_Shape> aToShape;
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FROM_OBJECT_ID());
+  if (anObjRef) {
+    aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  }
+  anObjRef = selection(TO_OBJECT_ID());
+  if (anObjRef) {
+    aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  }
+
+  // Getting extrusion sizes.
+  double aFromSize = real(FROM_SIZE_ID())->value();
+  double aToSize = real(TO_SIZE_ID())->value();
+
+  // Getting faces to extrude.
+  std::shared_ptr<ModelAPI_Feature> aSketchFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
+                                                     reference(SKETCH_OBJECT_ID())->value());
+  if(!aSketchFeature) {
+    return;
+  }
+  ResultPtr aSketchRes = aSketchFeature->results().front();
+  ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSketchRes);
+  if(!aConstruction.get()) {
+    return;
+  }
+  int aSketchFacesNum = aConstruction->facesNum();
+
+  // Extrude faces.
+  ListOfShape anExtrusionList;
+  for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) {
+    std::shared_ptr<GeomAPI_Shape> aBaseShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+    GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aFromShape, aFromSize, aToShape, aToSize);
+
+    // Checking that the algorithm worked properly.
+    if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
+      return;
+    }
+    anExtrusionList.push_back(aPrismAlgo.shape());
+  }
+
+  // Getting objects to cut from.
+  ListOfShape aCutList;
+  AttributeSelectionListPtr anObjectsSelList = selectionList(CUTLIST_ID());
+  if (anObjectsSelList->size() == 0) {
+    return;
+  }
+  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
+    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+    if(!anObject.get()) {
+      return;
+    }
+    aCutList.push_back(anObject);
+  }
+
+  // Cut from each objec result of extrusion.
+  int aResultIndex = 0;
+  for(ListOfShape::iterator aCutListIt = aCutList.begin(); aCutListIt != aCutList.end(); aCutListIt++) {
+    std::shared_ptr<GeomAPI_Shape> anObject = *aCutListIt;
+    ListOfShape aListWithObject;
+    aListWithObject.push_back(anObject);
+    GeomAlgoAPI_Boolean aBoolAlgo(aListWithObject, anExtrusionList, GeomAlgoAPI_Boolean::BOOL_CUT);
+
+    // Checking that the algorithm worked properly.
+    if(!aBoolAlgo.isDone() || aBoolAlgo.shape()->isNull() || !aBoolAlgo.isValid()) {
+      return;
+    }
+
+    if(GeomAlgoAPI_ShapeProps::volume(aBoolAlgo.shape()) > 1.e-7) {
+      std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+      if(anObject->isEqual(aBoolAlgo.shape())) {
+        aResultBody->store(aBoolAlgo.shape());
+      } else {
+        aResultBody->storeModified(anObject, aBoolAlgo.shape());
+        setResult(aResultBody, aResultIndex);
+        aResultIndex++;
+      }
+    }
+  }
 }
index 41bb42be31e2a4a7f2aa3fee4fbf8c1ee4751ee1..9dbdb045c6404fb69f187df6784692661bf7c8cd 100644 (file)
 //=================================================================================================
 GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const std::shared_ptr<GeomAPI_Shape>& theBasis,
                                      const std::shared_ptr<GeomAPI_Shape>& theFromShape,
-                                     double               theFromDistance,
+                                     double                                theFromSize,
                                      const std::shared_ptr<GeomAPI_Shape>& theToShape,
-                                     double               theToDistance)
+                                     double                                theToSize)
 : myDone(false)
 {
-  build(theBasis, theFromShape, theFromDistance, theToShape, theToDistance);
+  build(theBasis, theFromShape, theFromSize, theToShape, theToSize);
 }
 
 //=================================================================================================
 void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
                               const std::shared_ptr<GeomAPI_Shape>& theFromShape,
-                              double                                theFromDistance,
+                              double                                theFromSize,
                               const std::shared_ptr<GeomAPI_Shape>& theToShape,
-                              double                                theToDistance)
+                              double                                theToSize)
 {
   if(!theBasis ||
     (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape)))
-    && (theFromDistance == 0.0 && theToDistance == 0.0))) {
+    && (theFromSize == 0.0 && theToSize == 0.0))) {
     return;
   }
 
@@ -71,11 +71,11 @@ void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
   bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz());
 
   std::shared_ptr<GeomAPI_Pnt> aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied(
-                                                        aSign ? theFromDistance : -theFromDistance))));
+                                                        aSign ? theFromSize : -theFromSize))));
   aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
 
   std::shared_ptr<GeomAPI_Pnt> aToPnt(new GeomAPI_Pnt(aToLoc->xyz()->added(aBaseDir->xyz()->multiplied(
-                                                      aSign ? -theToDistance : theToDistance))));
+                                                      aSign ? -theToSize : theToSize))));
   aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
 
   TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
index 2631e4bc276b385d614ac6c94fe3dce8474d4a3c..91096aa88ff0bff3dae3f83b6e010437ef93c89c 100644 (file)
@@ -25,15 +25,15 @@ public:
   /** \brief Creates extrusion for the given shape along the normal for this shape.
    *  \param[in] theBasis face or wire to be extruded.
    *  \param[in] theFromShape bottom bounding shape.
-   *  \param[in] theFromDistance offset for "from" plane.
+   *  \param[in] theFromSize offset for "from" plane.
    *  \param[in] theToShape top bounding shape.
-   *  \param[in] theToDistance offset for "to" plane.
+   *  \param[in] theToSize offset for "to" plane.
    */
   GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const std::shared_ptr<GeomAPI_Shape>& theBasis,
                                        const std::shared_ptr<GeomAPI_Shape>& theFromShape,
-                                       double               theFromDistance,
+                                       double                                theFromSize,
                                        const std::shared_ptr<GeomAPI_Shape>& theToShape,
-                                       double               theToDistance);
+                                       double                                theToSize);
 
   /// \return true if algorithm succeed.
   GEOMALGOAPI_EXPORT bool isDone() const;
@@ -63,9 +63,9 @@ private:
   /// Builds resulting shape.
   void build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
              const std::shared_ptr<GeomAPI_Shape>& theFromShape,
-             double               theFromDistance,
+             double                                theFromSize,
              const std::shared_ptr<GeomAPI_Shape>& theToShape,
-             double               theToDistance);
+             double                                theToSize);
 
 private:
   /// Fields.