X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ViewerFilters.cpp;h=91d582b06da711f621563a380304047f1c4b1af0;hb=fc72d43b677baa05ae7fd317346fd8b723b799ed;hp=1e56112a7ebf23a03a1c47737af88e9a23831ca2;hpb=3874b57fe5aba25ff5aee2a07654fc23c1ee8eb0;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ViewerFilters.cpp b/src/ModuleBase/ModuleBase_ViewerFilters.cpp index 1e56112a7..91d582b06 100644 --- a/src/ModuleBase/ModuleBase_ViewerFilters.cpp +++ b/src/ModuleBase/ModuleBase_ViewerFilters.cpp @@ -1,19 +1,49 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_ViewerFilters.cpp -// Created: 07 Okt 2014 -// Author: Vitaly SMETANNIKOV - +// Copyright (C) 2014-2023 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 "ModuleBase_ViewerFilters.h" #include "ModuleBase_IWorkshop.h" +#include "ModuleBase_IModule.h" +#include "ModuleBase_Operation.h" +#include "ModuleBase_IPropertyPanel.h" +#include "ModuleBase_ModelWidget.h" #include #include #include +#include + #include #include +#ifdef BEFORE_TRIHEDRON_PATCH +#include +#include +#include +#else +#include +#include +#include +#endif +#include +#include +#include #include @@ -21,103 +51,129 @@ #include #include #include +#include -IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter); IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter); //TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340) -Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const +Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk( + const Handle(SelectMgr_EntityOwner)& theOwner) const { - if (theOwner->HasSelectable()) { - Handle(AIS_InteractiveObject) aAisObj = - Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); - if (!aAisObj.IsNull()) { - std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj)); - ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj); - if (aObj) { - DocumentPtr aDoc = aObj->document(); - SessionPtr aMgr = ModelAPI_Session::get(); - return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument()); + bool aValid = true; + + ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation(); + // the shapes from different documents should be provided if there is no started operation + // in order to show/hide results + if (anOperation) { + aValid = Standard_False; + std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + if (theOwner->HasSelectable()) { + Handle(AIS_InteractiveObject) aAisObj = + Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); + if (!aAisObj.IsNull()) { + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj)); } - else { - // This is not object controlled by the filter - return Standard_True; + } + ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj); + if (aObj) { + DocumentPtr aDoc = aObj->document(); + SessionPtr aMgr = ModelAPI_Session::get(); + + if (anOperation->propertyPanel()) { + ModuleBase_ModelWidget* aWidget = anOperation->propertyPanel()->activeWidget(); + if (aWidget && aWidget->canUseExternalParts()) + return Standard_True; } + return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument()); + } + else { + // This object is not controlled by the filter + aValid = Standard_True; } } - return Standard_False; -} +#ifdef DEBUG_FILTERS + qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str()); +#endif + return aValid; +} -IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter); IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter); -Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const +Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk( + const Handle(SelectMgr_EntityOwner)& theOwner) const { - if (theOwner->HasSelectable()) { - Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner); - if (!aShapeOwner.IsNull()) { - TopoDS_Shape aShape = aShapeOwner->Shape(); - TopAbs_ShapeEnum aType = aShape.ShapeType(); - switch (aType) { - case TopAbs_VERTEX: - { - gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape)); - return myPlane.Distance(aPnt) < Precision::Confusion(); + bool aValid = true; + + if (myPlane.get()) { + aValid = Standard_False; + // selectable may be empty if the object is selected in Object Browser and is not visualized + // in the viewer(virtual owner is created for this case) + //if (theOwner->HasSelectable()) + { + gp_Pln aPlane = myPlane->impl(); + Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner); + if (!aShapeOwner.IsNull() && aShapeOwner->HasShape()) { + TopoDS_Shape aShape = aShapeOwner->Shape(); + TopAbs_ShapeEnum aType = aShape.ShapeType(); + switch (aType) { + case TopAbs_VERTEX: + { + gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape)); + return aPlane.SquareDistance(aPnt) < Precision::SquareConfusion(); + } + case TopAbs_EDGE: + { + std::shared_ptr anEdge(new GeomAPI_Edge); + anEdge->setImpl(new TopoDS_Shape(aShape)); + return anEdge->isInPlane(myPlane); + } + default: + // The object can be selected in Object browser and contain, for example, compound. + // The compound could not belong to any plane, so the result is false + aValid = Standard_False; + break; } - case TopAbs_EDGE: - { - TopoDS_Edge aEdge = TopoDS::Edge(aShape); - Standard_Real aFirst, aLast; - Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast); - gp_Pnt aFirstPnt = aCurve->Value(aFirst); - gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.); - gp_Pnt aLastPnt = aCurve->Value(aLast); - bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion(); - bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion(); - bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion(); - return aD1 && aD2 && aD3; + } else { + if (theOwner->HasSelectable()) { + // Check Trihedron sub-objects + Handle(SelectMgr_SelectableObject) aSelObj = theOwner->Selectable(); + Handle(Standard_Type) aType = aSelObj->DynamicType(); + if (aType == STANDARD_TYPE(AIS_Trihedron)) { + Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aSelObj); + Handle(AIS_TrihedronOwner) aTrOwner = Handle(AIS_TrihedronOwner)::DownCast(theOwner); + if (!aTrOwner.IsNull()) { + const Prs3d_DatumParts& aPart = aTrOwner->DatumPart(); + if (aPart >= Prs3d_DP_XAxis && aPart <= Prs3d_DP_ZAxis) { + gp_Ax2 anAxis = aTrihedron->Component()->Ax2(); + gp_Dir aDir; + switch (aPart) { + case Prs3d_DP_XAxis: + aDir = anAxis.XDirection(); + break; + case Prs3d_DP_YAxis: + aDir = anAxis.YDirection(); + break; + case Prs3d_DP_ZAxis: + aDir = anAxis.Direction(); + break; + default: // [to avoid compilation warning] + break; + } + gp_Lin aLine(aTrihedron->Component()->Location(), aDir); + return aPlane.Contains(aLine, Precision::Confusion(), Precision::Angular()); + } + } + } + // This is not object controlled by the filter + aValid = Standard_True; } - default: - // This is not object controlled by the filter - return Standard_True; - break; - } - } else { - // This is not object controlled by the filter - return Standard_True; - } - } - return Standard_False; -} - - -IMPLEMENT_STANDARD_HANDLE(ModuleBase_ObjectTypesFilter, SelectMgr_Filter); -IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ObjectTypesFilter, SelectMgr_Filter); - - -//TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340) -Standard_Boolean ModuleBase_ObjectTypesFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const -{ - Standard_Boolean isOk = ModuleBase_ShapeDocumentFilter::IsOk(theOwner); - if (isOk && theOwner->HasSelectable()) { - Handle(AIS_InteractiveObject) aAisObj = - Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); - if (!aAisObj.IsNull()) { - std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj)); - ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj); - - foreach (QString aType, myTypes) { - if (aType.toLower() == "construction") { - ResultConstructionPtr aConstr = - std::dynamic_pointer_cast(aObj); - return (aConstr != NULL); - } // ToDo: Process other types of objects } } } - return Standard_False; +#ifdef DEBUG_FILTERS + qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str()); +#endif + return aValid; }