X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_ExternalObjectsMgr.cpp;h=be1c5722959875e2d359916344d73eb0d37fd7be;hb=3b02241a66e6be241eebbe70df42349293c5f4ab;hp=3128285f1b8b23202dabca00d18ac7d84a26bffc;hpb=1993f63b15d942f2360ee0dabc7d01adf71338b9;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.cpp b/src/PartSet/PartSet_ExternalObjectsMgr.cpp old mode 100755 new mode 100644 index 3128285f1..be1c57229 --- a/src/PartSet/PartSet_ExternalObjectsMgr.cpp +++ b/src/PartSet/PartSet_ExternalObjectsMgr.cpp @@ -1,15 +1,33 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_ExternalObjectsMgr.cpp -// Created: 15 Apr 2015 -// Author: Natalia Ermolaeva +// Copyright (C) 2014-2022 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 "PartSet_ExternalObjectsMgr.h" + +#include "PartSet_CenterPrs.h" #include "PartSet_Tools.h" #include #include +#include +#include + #include #include @@ -22,13 +40,13 @@ PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExt QString aIsExternal(theExternal.c_str()); if (!aIsExternal.isEmpty()) { QString aStr = aIsExternal.toUpper(); - myUseExternal = (aStr == "TRUE") || (aStr == "YES"); + myUseExternal = (aStr == "TRUE") || (aStr == "YES"); } QString aCanCreateExternal(theCanCreateExternal.c_str()); if (!aCanCreateExternal.isEmpty()) { QString aStr = aCanCreateExternal.toUpper(); - myCanCreateExternal = (aStr == "TRUE") || (aStr == "YES"); + myCanCreateExternal = (aStr == "TRUE") || (aStr == "YES"); } } @@ -37,7 +55,7 @@ bool PartSet_ExternalObjectsMgr::isValidObject(const ObjectPtr& theObject) bool aValid = true; FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); // Do check using of external feature - std::shared_ptr aSPFeature = + std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aFeature); // Do check that we can use external feature @@ -55,26 +73,88 @@ ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelecte { ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal( theShape->impl(), theSelectedObject, theSketch); - FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject); - if (aFeature.get()) { - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(aFeature); - /// some sketch entities should be never shown, e.g. projection feature - /// such external features should not be used in selection - if (aSketchFeature.get() && !aSketchFeature->canBeDisplayed()) - return ObjectPtr(); - } - if (!aSelectedObject.get()) { // Processing of external (non-sketch) object - aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), - theSelectedObject, theSketch, theTemporary); - if (aSelectedObject.get() && theTemporary) - myExternalObjectValidated = aSelectedObject; + FeaturePtr aCreatedFeature; + aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape, + theSelectedObject, theSketch, theTemporary, aCreatedFeature); + if (aCreatedFeature.get() && theTemporary) + myExternalObjectValidated = aCreatedFeature; + } + return aSelectedObject; +} + +ObjectPtr PartSet_ExternalObjectsMgr::externalCenterObject(const ModuleBase_ViewerPrsPtr& thePrs, + const CompositeFeaturePtr& theSketch, + const bool theTemporary) +{ + if (!thePrs.get() || thePrs->interactive().IsNull()) + return ObjectPtr(); + + Handle(PartSet_CenterPrs) aAIS = Handle(PartSet_CenterPrs)::DownCast(thePrs->interactive()); + if (aAIS.IsNull()) + return ObjectPtr(); + + gp_Pnt aPntComp = aAIS->Component()->Pnt(); + GeomVertexPtr aVertPtr(new GeomAPI_Vertex(aPntComp.X(), aPntComp.Y(), aPntComp.Z())); + TopoDS_Shape aShape = aVertPtr->impl(); + + ResultPtr aSelectedObject = + PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), theSketch); + if (!aSelectedObject.get()) + { + FeaturePtr aCreatedFeature; + aSelectedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(), + aAIS->centerType(), theSketch, theTemporary, aCreatedFeature); + if (aCreatedFeature.get() && theTemporary) + myExternalObjectValidated = aCreatedFeature; } return aSelectedObject; } +void PartSet_ExternalObjectsMgr::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape, + ModuleBase_IWorkshop* theWorkshop, + const CompositeFeaturePtr& theSketch, + const bool isInValidate) +{ + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject); + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aSelectedFeature); + // there is no a sketch feature is selected, but the shape exists, + // try to create an exernal object + // TODO: unite with the same functionality in PartSet_WidgetShapeSelector + if (aSPFeature.get() == NULL) { + ObjectPtr anExternalObject = ObjectPtr(); + GeomShapePtr anExternalShape = GeomShapePtr(); + if (useExternal()) { + if (canCreateExternal()) { + GeomShapePtr aShape = theShape; + if (!aShape.get()) { + ResultPtr aResult = theWorkshop->selection()->getResult(thePrs); + if (aResult.get()) + aShape = aResult->shape(); + } + if (aShape.get() != NULL && !aShape->isNull()) + anExternalObject = + externalObject(theObject, aShape, theSketch, isInValidate); + if (!anExternalObject.get()) { + anExternalObject = externalCenterObject(thePrs, theSketch, isInValidate); + } + } + else { /// use objects of found selection + anExternalObject = theObject; + anExternalShape = theShape; + } + } + /// the object is null if the selected feature is "external"(not sketch entity feature of the + /// current sketch) and it is not created by object manager + theObject = anExternalObject; + theShape = anExternalShape; + } +} + //******************************************************************** void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch, const FeaturePtr& theFeature, @@ -87,7 +167,7 @@ void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSk void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject, const CompositeFeaturePtr& /*theSketch*/, - const FeaturePtr& theFeature, + const FeaturePtr& /*theFeature*/, ModuleBase_IWorkshop* theWorkshop) { if (theObject.get()) { @@ -96,7 +176,8 @@ void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject if (aFeature.get() != NULL) { QObjectPtrList anObjects; anObjects.append(aFeature); - // the external feature should be removed with all references, composite sketch feature will be ignored + // the external feature should be removed with all references, + // composite sketch feature will be ignored workshop(theWorkshop)->deleteFeatures(anObjects); } }