X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_ExtrusionCut.cpp;h=d4320c3408d148921ee63afb0032ddabf936cc4f;hb=d5c7ad3c50f89a2ddc2de1866ffb7f09397f3be2;hp=63409d43821b02f93d376deeb6aa2e8fb0e8505e;hpb=78bdd669b016f0432f876101189276e8558770ff;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp old mode 100755 new mode 100644 index 63409d438..d4320c340 --- a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionCut.cpp @@ -1,183 +1,33 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: FeaturesPlugin_ExtrusionCut.cpp -// Created: 12 May 2015 -// Author: Dmitry Bobylev - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "FeaturesPlugin_ExtrusionCut.h" //================================================================================================= FeaturesPlugin_ExtrusionCut::FeaturesPlugin_ExtrusionCut() { -} - -//================================================================================================= -void FeaturesPlugin_ExtrusionCut::initAttributes() -{ - - data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId()); - - data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId()); - - data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId()); - - 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()); - - // extrusion works with faces always - AttributeSelectionListPtr aSelection = data()->selectionList(CUTLIST_ID()); - aSelection->setSelectionType("SOLID"); -} - - -std::shared_ptr FeaturesPlugin_ExtrusionCut::addFeature(std::string theID) -{ - std::shared_ptr aNew = document()->addFeature(theID, false); - if (aNew) { - data()->reference(SKETCH_OBJECT_ID())->setValue(aNew); - } - // set as current also after it becomes sub to set correctly enabled for other sketch subs - //document()->setCurrentFeature(aNew, false); - return aNew; -} - - -int FeaturesPlugin_ExtrusionCut::numberOfSubs() const -{ - ObjectPtr aObj = data()->reference(SKETCH_OBJECT_ID())->value(); - return aObj.get()? 1 : 0; -} - -std::shared_ptr FeaturesPlugin_ExtrusionCut::subFeature(const int theIndex) const -{ - if (theIndex == 0) - return std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); - return std::shared_ptr(); -} - -int FeaturesPlugin_ExtrusionCut::subFeatureId(const int theIndex) const -{ - std::shared_ptr aFeature = subFeature(theIndex); - if (aFeature.get()) - return aFeature->data()->featureId(); - return -1; -} - -bool FeaturesPlugin_ExtrusionCut::isSub(ObjectPtr theObject) const -{ - // check is this feature of result - FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); - if (!aFeature) - return false; - - ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value(); - return aSub == theObject; -} - -void FeaturesPlugin_ExtrusionCut::removeFeature(std::shared_ptr theFeature) -{ + myFeature = this; + myOperationType = BOOL_CUT; } //================================================================================================= void FeaturesPlugin_ExtrusionCut::execute() { - // Getting extrusion bounding planes. - 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++; - } - } - } + executeCompositeBoolean(); }