From: dbv Date: Wed, 10 Jun 2015 15:05:37 +0000 (+0300) Subject: Extrusion cut execute draft version. No naming! X-Git-Tag: V_1.3.0~253 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=78bdd669b016f0432f876101189276e8558770ff;p=modules%2Fshaper.git Extrusion cut execute draft version. No naming! --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index c2a4ea46b..555590596 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -99,7 +99,6 @@ void FeaturesPlugin_Boolean::execute() int aResultIndex = 0; ListOfMakeShape aListOfMakeShape; - std::shared_ptr aResShape; std::shared_ptr aDataMapOfShapes; switch(aType) { @@ -110,7 +109,6 @@ void FeaturesPlugin_Boolean::execute() std::shared_ptr anObject = *anObjectsIt; ListOfShape aListWithObject; aListWithObject.push_back(anObject); - aResShape = anObject; GeomAlgoAPI_Boolean aBoolAlgo(aListWithObject, aTools, aType); // Checking that the algorithm worked properly. diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index fa7484b65..ac82eefc1 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -53,10 +53,10 @@ void FeaturesPlugin_Extrusion::execute() { AttributeSelectionListPtr aFaceRefs = selectionList(FeaturesPlugin_Extrusion::LIST_ID()); + // Getting bounding planes. std::shared_ptr aFromShape; std::shared_ptr aToShape; - // Getting bounding planes. std::shared_ptr anObjRef = selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID()); if (anObjRef) { aFromShape = std::dynamic_pointer_cast(anObjRef->value()); diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp index 09d56a486..63409d438 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp @@ -13,6 +13,12 @@ #include #include #include +#include +#include + +#include +#include +#include //================================================================================================= 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 aFromShape; + std::shared_ptr aToShape; + std::shared_ptr anObjRef = selection(FROM_OBJECT_ID()); + if (anObjRef) { + aFromShape = std::dynamic_pointer_cast(anObjRef->value()); + } + anObjRef = selection(TO_OBJECT_ID()); + if (anObjRef) { + aToShape = std::dynamic_pointer_cast(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 aSketchFeature = std::dynamic_pointer_cast( + reference(SKETCH_OBJECT_ID())->value()); + if(!aSketchFeature) { + return; + } + ResultPtr aSketchRes = aSketchFeature->results().front(); + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSketchRes); + if(!aConstruction.get()) { + return; + } + int aSketchFacesNum = aConstruction->facesNum(); + + // Extrude faces. + ListOfShape anExtrusionList; + for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) { + std::shared_ptr aBaseShape = std::dynamic_pointer_cast(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 anObjectAttr = anObjectsSelList->value(anObjectsIndex); + std::shared_ptr 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 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 aResultBody = document()->createBody(data(), aResultIndex); + if(anObject->isEqual(aBoolAlgo.shape())) { + aResultBody->store(aBoolAlgo.shape()); + } else { + aResultBody->storeModified(anObject, aBoolAlgo.shape()); + setResult(aResultBody, aResultIndex); + aResultIndex++; + } + } + } } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp index 41bb42be3..9dbdb045c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp @@ -26,24 +26,24 @@ //================================================================================================= GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const std::shared_ptr& theBasis, const std::shared_ptr& theFromShape, - double theFromDistance, + double theFromSize, const std::shared_ptr& 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& theBasis, const std::shared_ptr& theFromShape, - double theFromDistance, + double theFromSize, const std::shared_ptr& 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& theBasis, bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz()); std::shared_ptr 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 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()); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h index 2631e4bc2..91096aa88 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.h @@ -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& theBasis, const std::shared_ptr& theFromShape, - double theFromDistance, + double theFromSize, const std::shared_ptr& 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& theBasis, const std::shared_ptr& theFromShape, - double theFromDistance, + double theFromSize, const std::shared_ptr& theToShape, - double theToDistance); + double theToSize); private: /// Fields.