X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMBase%2FGEOMBase.cxx;h=257bb3a1e312c2cd1d18da39c216769ac0c494cf;hb=4598d83cc4bb23677f77242525b13228145f468e;hp=230515df9b16b190cf10eb4b3e4b3131649a6168;hpb=239f8109c64fa0c5a2e1d87a420bad5529b57f48;p=modules%2Fgeom.git diff --git a/src/GEOMBase/GEOMBase.cxx b/src/GEOMBase/GEOMBase.cxx index 230515df9..257bb3a1e 100644 --- a/src/GEOMBase/GEOMBase.cxx +++ b/src/GEOMBase/GEOMBase.cxx @@ -1,61 +1,53 @@ -// GEOM GEOMGUI : GUI for Geometry component +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// 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. +// 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. +// 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 +// 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 // -// -// -// File : GEOMBase.cxx -// Author : Damien COQUERET -// Module : GEOM -// $Header$ +// GEOM GEOMGUI : GUI for Geometry component +// File : GEOMBase.cxx +// Author : Damien COQUERET, Open CASCADE S.A.S. +// #include "GEOMBase.h" -#include "GeometryGUI.h" -#include "GEOMBase_aParameterDlg.h" -#include "GEOM_Client.hxx" +#include +#include //// SALOME Includes -#include "Utils_ORB_INIT.hxx" -#include "Utils_SINGLETON.hxx" - -#include "SALOME_LifeCycleCORBA.hxx" - -#include "GEOM_AssemblyBuilder.h" -#include "GEOM_Actor.h" -#include "SVTK_RenderWindowInteractor.h" -#include "SVTK_ViewModel.h" -#include "SVTK_ViewWindow.h" -#include "OCCViewer_ViewPort3d.h" -#include "OCCViewer_ViewModel.h" -#include "OCCViewer_ViewWindow.h" - -#include "SALOME_ListIO.hxx" -#include "SALOME_ListIteratorOfListIO.hxx" -#include "GEOM_AISTrihedron.hxx" - -#include "SUIT_Session.h" -#include "SUIT_ViewWindow.h" -#include "SUIT_MessageBox.h" -#include "SalomeApp_Application.h" -#include "SalomeApp_Study.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include // // Open CASCADE Includes #include @@ -63,70 +55,47 @@ #include #include -#include #include #include #include #include -#include -#include -#include -#include -#include #include +#include #include #include -#include -#include #include -#include "GEOMImpl_Types.hxx" - -using namespace std; - -#include "SALOMEDSClient.hxx" - - //===================================================================================== // function : GetShapeFromIOR() -// purpose : exist also as static method ! +// purpose : Get shape data by the specified IOR //===================================================================================== -TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR) +TopoDS_Shape GEOMBase::GetShapeFromIOR( const QString& IOR ) { - TopoDS_Shape result; - if(IOR.stripWhiteSpace().isEmpty()) - return result; - - CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object((char*)(IOR.latin1())); - if(CORBA::is_nil(obj)) - return result; - GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj ); - if (GeomObject->_is_nil()) - return result; - - result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject); - return result; + GEOM::GEOM_Object_var geomObj = GEOMBase::GetObjectFromIOR( IOR ); + TopoDS_Shape shape; + GetShape( geomObj, shape, TopAbs_SHAPE ); + return shape; } //===================================================================================== // function : GetIndex() -// purpose : Get the index of a sub shape in a main shape : index start at 1 +// purpose : Get the index of a sub-shape in a main shape : index start at 1 //===================================================================================== -int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/) +int GEOMBase::GetIndex( const TopoDS_Shape& subshape, const TopoDS_Shape& shape ) { - if(shape.IsNull() || subshape.IsNull()) - return -1; - - TopTools_IndexedMapOfShape anIndices; - TopExp::MapShapes(shape, anIndices); - if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape); - - return -1; + int idx = -1; + if ( !shape.IsNull() && !subshape.IsNull() ) { + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes( shape, anIndices ); + if ( anIndices.Contains( subshape ) ) + idx = anIndices.FindIndex( subshape ); + } + return idx; } @@ -134,82 +103,64 @@ int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, // function : GetTopoFromSelection() // purpose : Define tds from a single selection and retuen true //======================================================================= -bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds) +TopoDS_Shape GEOMBase::GetTopoFromSelection( const SALOME_ListIO& IObjects ) { - if(aList.Extent() != 1) - return false; - - Handle(SALOME_InteractiveObject) IO = aList.First(); - /* case SObject */ - if(IO->hasEntry()) { - SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return false; - _PTR(Study) aStudy = appStudy->studyDS(); - - _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) ); - _PTR(GenericAttribute) anAttr; - if( obj ) { - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - _PTR(AttributeIOR) anIOR ( anAttr ); - tds = GetShapeFromIOR(anIOR->Value().c_str()); - if(tds.IsNull()) - return false; - else - return true; + TopoDS_Shape shape; + if ( IObjects.Extent() == 1 ){ + Handle(SALOME_InteractiveObject) IO = IObjects.First(); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( IO->hasEntry() && study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj( studyDS->FindObjectID( IO->getEntry() ) ); + _PTR(GenericAttribute) anAttr; + if ( obj && obj->FindAttribute( anAttr, "AttributeIOR" ) ) { + _PTR(AttributeIOR) anIOR( anAttr ); + shape = GetShapeFromIOR( anIOR->Value().c_str() ); } } } - - return false; + return shape; } //======================================================================= // function : GetNameOfSelectedIObjects() // purpose : Define the name geom++ or other name of mono or multi sel. //======================================================================= -int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList, - QString& theName, - const bool theShapesOnly ) +int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& IObjects, + QString& name, + const bool shapesOnly ) { - if ( !theShapesOnly ) - { - int nbSel = aList.Extent(); - if ( nbSel == 1 ) - { - Handle(SALOME_InteractiveObject) anIObj = aList.First(); - if(anIObj->hasEntry()) { - SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return nbSel; - _PTR(Study) aStudy = appStudy->studyDS(); - - _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) ); - - _PTR(GenericAttribute) anAttr; - - if ( obj && obj->FindAttribute( anAttr, "AttributeName") ) - { - _PTR(AttributeName) aNameAttr ( anAttr ); - theName = aNameAttr->Value().c_str(); - } - } - } - else - theName = QObject::tr("%1_objects").arg(nbSel); - - return nbSel; - } - else - { - GEOM::ListOfGO anObjs; - ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly ); - if ( anObjs.length() == 1 ) { - theName = GetName( anObjs[ 0 ] ); + int nbSel = 0; + name = ""; // clear output name + + if ( !shapesOnly ) { + nbSel = IObjects.Extent(); + if ( nbSel == 1 ) { + Handle(SALOME_InteractiveObject) anIObj = IObjects.First(); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( anIObj->hasEntry() && study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj( studyDS->FindObjectID( anIObj->getEntry() ) ); + _PTR(GenericAttribute) anAttr; + if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) { + _PTR(AttributeName) aNameAttr ( anAttr ); + name = aNameAttr->Value().c_str(); + } } - else - theName = QString( "%1_objects" ).arg( anObjs.length() ); - - return anObjs.length(); } + } + else { + GEOM::ListOfGO anObjs; + ConvertListOfIOInListOfGO( IObjects, anObjs, shapesOnly ); + nbSel = anObjs.length(); + if ( nbSel == 1 ) + name = GetName( anObjs[ 0 ] ); + } + + if ( nbSel > 1 ) + name = QObject::tr( "%1_objects" ).arg( nbSel ); + + return nbSel; } @@ -217,101 +168,113 @@ int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList, // function : GetShapeTypeString() // purpose : for a single shape //================================================================================= -bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString) +QString GEOMBase::GetShapeTypeString(const TopoDS_Shape& shape) { - if(aShape.IsNull()) { - aTypeString = "aNullShape"; - return false; - } - switch(aShape.ShapeType()) - { + QString aTypeString; + if ( !shape.IsNull() ) { + switch ( shape.ShapeType() ) { case TopAbs_COMPOUND: { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND")); - return true; + aTypeString = QObject::tr( "GEOM_COMPOUND" ); + break; } - case TopAbs_COMPSOLID: + case TopAbs_COMPSOLID: { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID")) ; - return true ; + aTypeString = QObject::tr( "GEOM_COMPOUNDSOLID" ); + break; } case TopAbs_SOLID: { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID")) ; - return true ; + aTypeString = QObject::tr( "GEOM_SOLID" ); + break; } case TopAbs_SHELL: { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL")) ; - return true ; + aTypeString = QObject::tr( "GEOM_SHELL" ); + break; } case TopAbs_FACE: { - BRepAdaptor_Surface surf(TopoDS::Face(aShape)); - if(surf.GetType() == GeomAbs_Plane) { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE")); - return true; - } - else if(surf.GetType() == GeomAbs_Cylinder) { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER")); - return true; - } - else if(surf.GetType() == GeomAbs_Sphere) { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE")); - return true ; - } - else if(surf.GetType() == GeomAbs_Torus) { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS")); - return true ; - } - else if(surf.GetType() == GeomAbs_Cone) { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE")); - return true ; - } - else { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE")); - return true; - } + BRepAdaptor_Surface surf( TopoDS::Face( shape ) ); + switch ( surf.GetType() ) { + case GeomAbs_Plane: + { + aTypeString = QObject::tr( "GEOM_PLANE" ); + break; + } + case GeomAbs_Cylinder: + { + aTypeString = QObject::tr( "GEOM_SURFCYLINDER" ); + break; + } + case GeomAbs_Sphere: + { + aTypeString = QObject::tr( "GEOM_SURFSPHERE" ); + break; + } + case GeomAbs_Torus: + { + aTypeString = QObject::tr( "GEOM_SURFTORUS" ); + break; + } + case GeomAbs_Cone: + { + aTypeString = QObject::tr( "GEOM_SURFCONE" ); + break; + } + default: + { + aTypeString = QObject::tr( "GEOM_FACE" ); + break; + } + } + break; } case TopAbs_WIRE: { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE")); - return true; + aTypeString = QObject::tr( "GEOM_WIRE" ); + break; } case TopAbs_EDGE: { - BRepAdaptor_Curve curv(TopoDS::Edge(aShape)); - if(curv.GetType() == GeomAbs_Line) { - if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6)) - aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE")); - else - aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE")); - return true; - } - else if(curv.GetType() == GeomAbs_Circle) { - if(curv.IsClosed()) - aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE")); - else - aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC")); - return true; - } - else { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE")); - return true; - } + BRepAdaptor_Curve curv( TopoDS::Edge( shape ) ); + switch ( curv.GetType() ) { + case GeomAbs_Line: + { + aTypeString = ( qAbs( curv.FirstParameter() ) >= 1E6 || qAbs( curv.LastParameter() ) >= 1E6 ) ? + QObject::tr( "GEOM_LINE" ) : QObject::tr( "GEOM_EDGE" ); + break; + } + case GeomAbs_Circle: + { + aTypeString = curv.IsClosed() ? QObject::tr( "GEOM_CIRCLE" ) : QObject::tr( "GEOM_ARC" ); + break; + } + default: + { + aTypeString = QObject::tr( "GEOM_EDGE" ); + break; + } + } + break; } case TopAbs_VERTEX: { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX")); - return true; + aTypeString = QObject::tr( "GEOM_VERTEX" ); + break; } case TopAbs_SHAPE: { - aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE")); - return true; + aTypeString = QObject::tr( "GEOM_SHAPE" ); + break; + } + default: + { + break; } } - return false; + } + return aTypeString; } @@ -319,52 +282,44 @@ bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& // function : ConvertIORinGEOMAISShape() // purpose : //======================================================================= -Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView) +Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const QString& IOR, bool onlyInActiveView) { - Handle(GEOM_AISShape) resultShape; - testResult = false; - - SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return resultShape; - _PTR(Study) aStudy = appStudy->studyDS(); - - _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) ); - if ( !anObj ) - return resultShape; - - QPtrList aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows(); - - for ( QPtrListIterator it( aViewWindowsList ); it.current(); ++it ) { - if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) { - Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while(ite.More()) { - if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if(aSh->hasIO()) { - Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO()); - if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) { - if(!onlyInActiveView || - it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) { - testResult = true; - resultShape = aSh; - return resultShape; - } - } - } - } - ite.Next(); + Handle(GEOM_AISShape) shape; + + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) ); + if ( obj ) { + QList views; + if ( onlyInActiveView ) + views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() ); + else + views = SUIT_Session::session()->activeApplication()->desktop()->windows(); + foreach ( SUIT_ViewWindow* view, views ) { + if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) { + Handle(AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)view->getViewManager()->getViewModel())->getAISContext(); + + AIS_ListOfInteractive displayed; + ic->DisplayedObjects( displayed ); + AIS_ListIteratorOfListOfInteractive it( displayed ); + while ( it.More() && shape.IsNull() ) { + if ( it.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) { + Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() ); + if ( !sh.IsNull() && sh->hasIO() ) { + Handle(SALOME_InteractiveObject) IO = sh->getIO(); + if ( !IO.IsNull() && IO->hasEntry() && obj->GetID() == IO->getEntry() ) + shape = sh; + } + } + it.Next(); + } + } + if ( !shape.IsNull() ) break; } } } - return resultShape; + return shape; } @@ -372,92 +327,83 @@ Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Stand // function : ConvertIORinGEOMActor() // purpose : //======================================================================= -GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView) +GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const QString& IOR, bool onlyInActiveView) { - testResult = false; - - SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return GEOM_Actor::New(); - _PTR(Study) aStudy = appStudy->studyDS(); - - _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) ); - if ( !anObj ) - return GEOM_Actor::New(); - - QPtrList aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows(); - - for ( QPtrListIterator it( aViewWindowsList ); it.current(); ++it ) { - if (it.current()->getViewManager()->getType() == SVTK_Viewer::Type()) { - SVTK_ViewWindow* aVTKViewWindow = dynamic_cast( it.current() ); - if( !aVTKViewWindow ) - continue; - vtkRenderer* Renderer = aVTKViewWindow->getRenderer(); - vtkActorCollection* theActors = Renderer->GetActors(); - theActors->InitTraversal(); - vtkActor *ac = theActors->GetNextActor(); - while(!(ac==NULL)) { - if( ac->IsA("GEOM_Actor")) { - GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac); - if(anActor->hasIO()) { - Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO()); - if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) { - if(!onlyInActiveView || - it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) { - testResult = true; - return anActor; - } - } - } - } - ac = theActors->GetNextActor(); + GEOM_Actor* actor = 0; + + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) ); + if ( obj ) { + QList views; + if ( onlyInActiveView ) + views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() ); + else + views = SUIT_Session::session()->activeApplication()->desktop()->windows(); + foreach ( SUIT_ViewWindow* view, views ) { + if ( view && view->getViewManager()->getType() == SVTK_Viewer::Type() ) { + SVTK_ViewWindow* aVTKViewWindow = dynamic_cast( view ); + if( !aVTKViewWindow ) + continue; + vtkRenderer* Renderer = aVTKViewWindow->getRenderer(); + vtkActorCollection* theActors = Renderer->GetActors(); + theActors->InitTraversal(); + vtkActor* a = theActors->GetNextActor(); + while( a && !actor ) { + if ( a->IsA( "GEOM_Actor" ) ) { + GEOM_Actor* ga = GEOM_Actor::SafeDownCast( a ); + if ( ga && ga->hasIO() ) { + Handle(SALOME_InteractiveObject) IO = ga->getIO(); + if ( !IO.IsNull() && IO->hasEntry() && obj->GetID() == IO->getEntry() ) + actor = ga; + } + } + a = theActors->GetNextActor(); + } + } + if ( actor ) break; } } } - testResult = false; - return GEOM_Actor::New(); + return actor; } //======================================================================= // function : GetAIS() // purpose : //======================================================================= -Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO, - const bool isOnlyInActiveView ) +Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& IO, + bool onlyInActiveView, bool /*onlyGeom*/ ) { - if ( theIO.IsNull() || !theIO->hasEntry() ) - return Handle(AIS_InteractiveObject)(); - - QPtrList aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows(); - - for ( QPtrListIterator it( aViewWindowsList ); it.current(); ++it ) { - if (it.current()->getViewManager()->getType() != OCCViewer_Viewer::Type()) - continue; - Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext(); - - AIS_ListOfInteractive aList; - anIC->DisplayedObjects( aList ); - anIC->ObjectsInCollector( aList ); - - AIS_ListIteratorOfListOfInteractive anIter( aList ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(SALOME_InteractiveObject) anObj = - Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() ); - - if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 ) - { - if( isOnlyInActiveView ) - { - if ( it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() ) - return anIter.Value(); + Handle(AIS_InteractiveObject) aisObject; + + if ( !IO.IsNull() && IO->hasEntry() ) { + QList views; + if ( onlyInActiveView ) + views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() ); + else + views = SUIT_Session::session()->activeApplication()->desktop()->windows(); + + foreach ( SUIT_ViewWindow* view, views ) { + if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) { + OCCViewer_Viewer* occViewer=(OCCViewer_Viewer*)view->getViewManager()->getViewModel(); + SOCC_Viewer* soccViewer = dynamic_cast(occViewer); + if (soccViewer) { + SOCC_Prs* occPrs = dynamic_cast( soccViewer->CreatePrs( IO->getEntry() ) ); + if ( occPrs && !occPrs->IsNull() ) { + AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes ); + if( !shapes.Extent() ) continue; + aisObject=shapes.First(); + delete occPrs; + } } - else - return anIter.Value(); } - } + if ( !aisObject.IsNull() ) break; + } // foreach } - return Handle(AIS_InteractiveObject)(); + return aisObject; } @@ -465,91 +411,9 @@ Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveO // function : ConvertIOinGEOMAISShape() // purpose : //======================================================================= -Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView) +Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape( const Handle(SALOME_InteractiveObject)& IO, bool onlyInActiveView ) { - Handle(GEOM_AISShape) res; - - if ( !IO->hasEntry() ) - { - testResult = false; - return res; - } - - QPtrList aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows(); - - for ( QPtrListIterator it( aViewWindowsList ); it.current(); ++it ) { - if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) { - Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while(ite.More()) - { - if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) - { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if( aSh->hasIO() ) - { - if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 ) - { - if(onlyInActiveView) - { - if(it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) - { - testResult = true; - return aSh; - } - } - else - { - testResult = true; - return aSh; - } - } - } - } - ite.Next(); - } - } - } - testResult = false; - return res; -} - - -//======================================================================= -// function : ConvertIOinGEOMShape() -// purpose : -//======================================================================= -GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult) -{ - GEOM::GEOM_Object_var aShape; - testResult = false; - - /* case SObject */ - if(IO->hasEntry()) { - SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return GEOM::GEOM_Object::_nil(); - _PTR(Study) aStudy = appStudy->studyDS(); - - _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) ); - _PTR(GenericAttribute) anAttr; - if(obj) { - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - _PTR(AttributeIOR) anIOR ( anAttr ); - aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str()); - if(!CORBA::is_nil(aShape)) - testResult = true; - return aShape._retn(); - } - } - } - return GEOM::GEOM_Object::_nil(); + return Handle(GEOM_AISShape)::DownCast( GetAIS( IO, onlyInActiveView, true ) ); } @@ -557,35 +421,20 @@ GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_Interac // function : ConvertListOfIOInListOfIOR() // purpose : //======================================================================= -void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR) +QStringList GEOMBase::ConvertListOfIOInListOfIOR( const SALOME_ListIO& IObjects ) { - int nbSel = aList.Extent(); - listIOR.length(nbSel); - int j=0; - SALOME_ListIteratorOfListIO It(aList); - SalomeApp_Study* appStudy = dynamic_cast - ( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return; - _PTR(Study) aStudy = appStudy->studyDS(); - - for (int i=0; It.More(); It.Next(), i++) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - if (IObject->hasEntry()) { - _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) ); - _PTR(GenericAttribute) anAttr; - if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) { - _PTR(AttributeIOR) anIOR (anAttr); - //CORBA::Object_var theObj = dynamic_cast - // (aStudy.get())->ConvertIORToObject(anIOR->Value()); - CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj); - if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) { - listIOR[j] = CORBA::string_dup(anIOR->Value().c_str()); - j++; - } - } + QStringList iors; + SALOME_ListIteratorOfListIO it( IObjects ); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + for ( ; it.More(); it.Next() ) { + GEOM::GEOM_Object_var geomObj = ConvertIOinGEOMObject( it.Value() ); + if ( !CORBA::is_nil( geomObj ) ) + iors.append( GetIORFromObject( geomObj ) ); } } - listIOR.length(j); + return iors; } @@ -593,29 +442,22 @@ void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::stri // function : ConvertIOinGEOMObject() // purpose : //======================================================================= -GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO, - Standard_Boolean& theResult ) +GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& IO ) { - theResult = Standard_False; - GEOM::GEOM_Object_var aReturnObject; - if ( !theIO.IsNull() ) - { - const char* anEntry = theIO->getEntry(); - - SalomeApp_Study* appStudy = dynamic_cast - ( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return GEOM::GEOM_Object::_nil(); - _PTR(Study) aStudy = appStudy->studyDS(); - - _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) ); - - if (aSObj) - { - aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj)); - theResult = !CORBA::is_nil( aReturnObject ); + GEOM::GEOM_Object_var object; + + if ( !IO.IsNull() && IO->hasEntry() ) { + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj = studyDS->FindObjectID( IO->getEntry() ); + if ( GeometryGUI::IsInGeomComponent( obj )) { + CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj ); + object = GEOM::GEOM_Object::_narrow( corbaObj ); + } } } - return aReturnObject._retn(); + return object._retn(); } @@ -623,34 +465,27 @@ GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_Inter // function : ConvertListOfIOInListOfGO() // purpose : //======================================================================= -void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList, - GEOM::ListOfGO& theListGO, - const bool theShapesOnly ) +void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& IObjects, + GEOM::ListOfGO& geomObjects, + bool shapesOnly ) { - int nbSel = theList.Extent(); - theListGO.length( nbSel ); - SALOME_ListIteratorOfListIO anIter( theList ); + geomObjects.length( 0 ); - SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return; - _PTR(Study) aStudy = appStudy->studyDS(); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); - int j = 0; - for ( int i=0; anIter.More(); anIter.Next(), i++ ) - { - Handle(SALOME_InteractiveObject) anIObj = anIter.Value(); - _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) ); + geomObjects.length( IObjects.Extent() ); + SALOME_ListIteratorOfListIO it( IObjects ); - if ( aSObj ) - { - GEOM::GEOM_Object_var aGeomObj = - GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj)); - if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) ) - theListGO[ j++ ] = aGeomObj; + int i = 0; + for ( ; it.More(); it.Next() ) { + GEOM::GEOM_Object_var geomObj = ConvertIOinGEOMObject( it.Value() ); + if ( !CORBA::is_nil( geomObj ) && ( !shapesOnly || IsShape( geomObj ) ) ) + geomObjects[ i++ ] = geomObj; } + geomObjects.length( i ); } - - theListGO.length( j ); } //================================================================================= @@ -658,48 +493,45 @@ void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList, // purpose : Create a cone topology to be used to display an arrow in the middle // : of an edge showing its orientation. (For simulation and Viewer OCC only) //================================================================================= -bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone) +TopoDS_Shape GEOMBase::CreateArrowForLinearEdge( const TopoDS_Shape& shape ) { - if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() - != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE) - return false; - - OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort(); - Handle( V3d_View) view3d = vp3d->getView(); - Standard_Real Width, Height; - view3d->Size(Width, Height); - const Standard_Real aHeight = (Width + Height) / 50.0; - - try { - Standard_Real first, last; - Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last); - if(!curv->IsCN(1)) - return false; - - const Standard_Real param = (first+last) / 2.0; - gp_Pnt middleParamPoint; - gp_Vec V1; - curv->D1( param, middleParamPoint, V1); - if(V1.Magnitude() < Precision::Confusion()) - return false; - - /* Topology orientation not geom orientation */ - if(tds.Orientation() == TopAbs_REVERSED) - V1 *= -1.0; - - gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1)); - const Standard_Real radius1 = aHeight / 5.0; - if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) { - ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape(); - return true; + TopoDS_Shape ArrowCone; + + SUIT_ViewWindow* view = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() && shape.ShapeType() == TopAbs_EDGE ) { + Handle(V3d_View) view3d = ((OCCViewer_ViewWindow*)view)->getViewPort()->getView(); + Standard_Real Width, Height; + view3d->Size( Width, Height ); + const Standard_Real aHeight = (Width + Height) / 50.0; + + try { + Standard_Real first, last; + Handle(Geom_Curve) curv = BRep_Tool::Curve( TopoDS::Edge( shape ), first, last ); + if ( !curv.IsNull() && curv->IsCN(1) ) { + const Standard_Real param = ( first+last ) / 2.0; + gp_Pnt middleParamPoint; + gp_Vec V1; + curv->D1( param, middleParamPoint, V1 ); + if ( V1.Magnitude() > Precision::Confusion() ) { + /* Topology orientation not geom orientation */ + if ( shape.Orientation() == TopAbs_REVERSED ) + V1 *= -1.0; + + gp_Ax2 anAxis( middleParamPoint, gp_Dir( V1 ) ); + const Standard_Real radius1 = aHeight / 5.0; + if ( radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion() ) + ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape(); + } + } + } + catch ( Standard_Failure& ) { + // OCC failures are hard to catch in GUI. + // This is because of the position for #include that is very critical to find + // in SALOME environment : compilation error ! } } - catch(Standard_Failure) { - // OCC failures are hard to catch in GUI. - // This because of the position for #include that is very critic to find - // in SALOME environment : compilation error ! - } - return false; + + return ArrowCone; } @@ -707,11 +539,11 @@ bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& A // function : VertexToPoint() // purpose : If S can be converted in a gp_Pnt returns true and the result is P //================================================================================= -bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P) +bool GEOMBase::VertexToPoint( const TopoDS_Shape& shape, gp_Pnt& point ) { - if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX) + if ( shape.IsNull() || shape.ShapeType() != TopAbs_VERTEX ) return false; - P = BRep_Tool::Pnt(TopoDS::Vertex(S)); + point = BRep_Tool::Pnt( TopoDS::Vertex( shape ) ); return true; } @@ -720,12 +552,11 @@ bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P) // function : GetBipointDxDyDz() // purpose : //================================================================================= -void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz) +void GEOMBase::GetBipointDxDyDz( const gp_Pnt& point1, const gp_Pnt& point2, double& dx, double& dy, double& dz ) { - dx = P2.X() - P1.X(); - dy = P2.Y() - P1.Y(); - dz = P2.Z() - P1.Z(); - return; + dx = point2.X() - point1.X(); + dy = point2.Y() - point1.Y(); + dz = point2.Z() - point1.Z(); } @@ -735,90 +566,65 @@ void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, do // : distance is sufficient, returns true else returns false. // : Resulting points are respectively P1 and P2 //================================================================================= -bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2) +bool GEOMBase::LinearEdgeExtremities( const TopoDS_Shape& shape, gp_Pnt& point1, gp_Pnt& point2 ) { - if(S.IsNull() || S.ShapeType() != TopAbs_EDGE) + if ( shape.IsNull() || shape.ShapeType() != TopAbs_EDGE ) return false; - BRepAdaptor_Curve curv(TopoDS::Edge(S)); - if(curv.GetType() != GeomAbs_Line) + + BRepAdaptor_Curve curv( TopoDS::Edge( shape ) ); + if ( curv.GetType() != GeomAbs_Line ) return false; + + gp_Pnt p1, p2; - curv.D0(curv.FirstParameter(), P1); - curv.D0(curv.LastParameter(), P2); + curv.D0( curv.FirstParameter(), p1 ); + curv.D0( curv.LastParameter(), p2 ); - if(P1.Distance(P2) <= Precision::Confusion()) + if ( p1.Distance( p2 ) <= Precision::Confusion() ) return false; + point1 = p1; + point2 = p2; return true; } -//======================================================================= -// function : Parameter() -// purpose : return a parameter (float) from a dialog box -// -// avalue1 : is a float or integer used as a default value displayed -// aTitle1 : is the title for aValue1 -// aTitle : is the main title -// bottom : maximum value to be entered -// top : minimum value to be entered -// decimals : number of decimals -//======================================================================= -double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals) -{ - GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(), - aTitle, TRUE, 0, bottom, top, decimals); - int r = Dialog->exec(); - float X = 0.0; - if(r == QDialog::Accepted) { - res = Standard_True; - X = Dialog->getValue(); - } - else - res = Standard_False; - delete Dialog; - return X; -} - - //======================================================================= // function : SelectionByNameInDialogs() // purpose : Called when user has entered a name of object in a LineEdit. // : The selection is changed. Dialog box will receive the // : corresponding signal to manage this event. //======================================================================= -bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList) +bool GEOMBase::SelectionByNameInDialogs( QWidget* widget, const QString& objectUserName, const SALOME_ListIO& /*IObjects*/ ) { /* Find SObject with name in component GEOM */ - SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return false; - _PTR(Study) ST = appStudy->studyDS(); - - std::vector<_PTR(SObject)> listSO; - listSO = ST->FindObjectByName(objectUserName.latin1(), "GEOM"); - - if(listSO.size() < 1) { - const QString caption = QObject::tr("GEOM_WRN_WARNING"); - const QString text = QObject::tr("GEOM_NAME_INCORRECT"); - const QString button0 = QObject::tr("GEOM_BUT_OK"); - SUIT_MessageBox::error1(aWidget, caption, text, button0); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( !study ) return false; + _PTR(Study) studyDS = study->studyDS(); + + std::vector<_PTR(SObject)> listSO = studyDS->FindObjectByName( objectUserName.toStdString(), "GEOM" ); + + if ( listSO.size() < 1 ) { + SUIT_MessageBox::critical( widget, + QObject::tr( "GEOM_WRN_WARNING" ), + QObject::tr( "GEOM_NAME_INCORRECT" ), + QObject::tr( "GEOM_BUT_OK" ) ); return false; } + /* More than one object with same name */ - if(listSO.size() > 1) { - const QString caption = QObject::tr("GEOM_WRN_WARNING"); - const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE"); - const QString button0 = QObject::tr("GEOM_BUT_OK") ; - SUIT_MessageBox::error1(aWidget, caption, text, button0) ; - listSO.clear(); + if ( listSO.size() > 1 ) { + SUIT_MessageBox::critical( widget, + QObject::tr("GEOM_WRN_WARNING"), + QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE"), + QObject::tr("GEOM_BUT_OK") ); return false; } - _PTR(SObject) theObj ( listSO[0] ); /* Create a SALOME_InteractiveObject with a SALOME::SObject */ - char* aCopyobjectUserName = CORBA::string_dup(objectUserName); - Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName); - delete(aCopyobjectUserName); + Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject( listSO[0]->GetID().c_str(), + "GEOM", + objectUserName.toUtf8().constData() ); /* Add as a selected object */ /* Clear any previous selection : */ @@ -833,13 +639,12 @@ bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectU // function : DefineDlgPosition() // purpose : Define x and y the default position for a dialog box //======================================================================= -bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y) +void GEOMBase::DefineDlgPosition( QWidget* dlg, int& x, int& y ) { /* Here the position is on the bottom right corner - 10 */ - SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop(); - x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10); - y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10); - return true; + SUIT_Desktop* d = SUIT_Session::session()->activeApplication()->desktop(); + x = abs( d->x() + d->size().width() - dlg->size().width() - 10 ); + y = abs( d->y() + d->size().height() - dlg->size().height() - 10 ); } @@ -847,35 +652,47 @@ bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y) // function : GetDefaultName() // purpose : Generates default names //======================================================================= -QString GEOMBase::GetDefaultName(const QString& theOperation) +QString GEOMBase::GetDefaultName( const QString& operation, bool extractPrefix ) { QString aName = ""; // collect all object names of GEOM component - SalomeApp_Study* appStudy = - dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return aName; - _PTR(Study) aStudy = appStudy->studyDS(); - - std::set aSet; - _PTR(SComponent) aGeomCompo (aStudy->FindComponent("GEOM")); - if (aGeomCompo) { - _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeomCompo)); - _PTR(SObject) obj; - for (it->InitEx(true); it->More(); it->Next()) { - obj = it->Value(); - aSet.insert(obj->GetName()); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + + std::set names; + _PTR(SComponent) component( studyDS->FindComponent( "GEOM" ) ); + if ( component ) { + _PTR(ChildIterator) it( studyDS->NewChildIterator( component ) ); + for ( it->InitEx( true ); it->More(); it->Next() ) { + names.insert( it->Value()->GetName() ); + } } - } - // build a unique name - int aNumber = 0; - bool isUnique = false; - while (!isUnique) { - aName = theOperation + "_" + QString::number(++aNumber); - isUnique = (aSet.count(aName.latin1()) == 0); + // build a unique name + int aNumber = 0; + bool isUnique = false; + QString prefix = operation; + + if ( extractPrefix ) { + QStringList parts = prefix.split( "_", QString::KeepEmptyParts ); + if ( parts.count() > 1 ) { + bool ok; + aNumber = parts.last().toLong( &ok ); + if ( ok ) { + parts.removeLast(); + prefix = parts.join( "_" ); + aNumber--; + } + } + } + + while ( !isUnique ) { + aName = prefix + "_" + QString::number( ++aNumber ); + isUnique = ( names.count( aName.toStdString()) == 0 ); + } } - return aName; } @@ -884,19 +701,19 @@ QString GEOMBase::GetDefaultName(const QString& theOperation) // function : ShowErrorMessage() // purpose : Shows message box with error code and comment //======================================================================= -void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment) +void GEOMBase::ShowErrorMessage( const QString& errorCode, const QString& comment ) { - QString anErrorCode(theErrorCode); - QString aComment(theComment); - - QString aText = ""; - if (!anErrorCode.isEmpty()) - aText.append("\n" + QObject::tr(anErrorCode)); - if (!aComment.isEmpty()) - aText.append("\n" + QString(theComment)); - - SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), - QObject::tr("GEOM_PRP_ABORT") + aText, "OK" ); + QStringList text; + text << QObject::tr( "GEOM_PRP_ABORT" ); + if ( !errorCode.isEmpty() ) + text << QObject::tr( errorCode.toLatin1().constData() ); + if ( !comment.isEmpty() ) + text << QObject::tr( comment.toUtf8().constData() ); + + SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), + QObject::tr( "GEOM_ERROR" ), + text.join( "\n" ), + QObject::tr( "GEOM_BUT_OK" ) ); } @@ -904,75 +721,186 @@ void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment // function : GetObjectFromIOR() // purpose : returns a GEOM_Object by given IOR (string) //======================================================================= -GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR ) +GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const QString& IOR ) { - GEOM::GEOM_Object_var anObject; - if ( theIOR == NULL || strlen( theIOR ) == 0 ) - return anObject._retn(); // returning nil object - - anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) ); - return anObject._retn(); + return GeometryGUI::GetObjectFromIOR (IOR); } //======================================================================= // function : GetIORFromObject() // purpose : returns IOR of a given GEOM_Object //======================================================================= -char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject ) +QString GEOMBase::GetIORFromObject( GEOM::GEOM_Object_ptr object ) { - if ( CORBA::is_nil( theObject ) ) - return NULL; - - return SalomeApp_Application::orb()->object_to_string( theObject ); + return GeometryGUI::GetIORFromObject (object); } //======================================================================= // function : GetShape() // purpose : returns a TopoDS_Shape stored in GEOM_Object //======================================================================= -bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType ) +bool GEOMBase::GetShape( GEOM::GEOM_Object_ptr object, TopoDS_Shape& shape, const TopAbs_ShapeEnum type ) { - if ( !CORBA::is_nil( theObject ) ) - { - TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject ); - if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) ) + shape = TopoDS_Shape(); + if ( !CORBA::is_nil( object ) ) { + TopAbs_ShapeEnum stype = (TopAbs_ShapeEnum)( object->GetShapeType() ); + if ( type == TopAbs_SHAPE || type == stype ) { - theShape = aTopoDSShape; - return true; + GEOM::GEOM_Gen_var gen = object->GetGen(); + shape = GEOM_Client::get_client().GetShape( gen, object ); } } - return false; + return !shape.IsNull(); } //======================================================================= // function : GetName() // purpose : Get name of object //======================================================================= -QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj ) +QString GEOMBase::GetName( GEOM::GEOM_Object_ptr object ) { - SalomeApp_Study* appStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + QString name; + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + + if ( !CORBA::is_nil( object ) ) { + // 1. search if object is already published in the study + CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( object ); + if ( study && strcmp( IOR.in(), "" ) != 0 ) { + _PTR(SObject) aSObj( study->studyDS()->FindObjectIOR( std::string( IOR.in() ) ) ); + _PTR(GenericAttribute) anAttr; + if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) { + _PTR(AttributeName) aNameAttr( anAttr ); + name = aNameAttr->Value().c_str(); + } + } + + // 2. if object is not found in the study, try default name + if ( name.isEmpty() ) { + if ( object->IsMainShape() ) { + name = GetDefaultName( "geomObj" ); + } + else { + GEOM::GEOM_Object_var mainShape = object->GetMainShape(); + if ( !CORBA::is_nil( mainShape ) ) { + GEOM::ListOfLong_var indices = object->GetSubShapeIndices(); + if ( indices->length() > 0 ) { + TopAbs_ShapeEnum type = (TopAbs_ShapeEnum)( object->GetShapeType() ); + name = QString( "%1:%2_%3" ).arg( GetName( mainShape.in() ) ) + .arg( TypeName( type ) ).arg( indices[0] ); + } + } + } + } + } - if ( appStudy ) - { - CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( theObj ); - if ( strcmp(anIOR.in(), "") != 0 ) - { - _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( string( anIOR ) ) ); + return name; +} - _PTR(GenericAttribute) anAttr; +//======================================================================= +// function : IsShape() +// purpose : Return TRUE if object is valid and has shape +//======================================================================= +bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr object ) +{ + return !object->_is_nil() && object->IsShape(); +} - if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) - { - _PTR(AttributeName) aNameAttr ( anAttr ); - return QString( aNameAttr->Value().c_str() ); - } +//======================================================================= +// function : TypeName() +// purpose : Get string representation for the shape type +//======================================================================= +QString GEOMBase::TypeName( TopAbs_ShapeEnum type, bool capitalize ) +{ + QString name = "shape"; + switch( type ) { + case TopAbs_COMPSOLID: + name = "compsolid"; break; + case TopAbs_COMPOUND: + name = "compound"; break; + case TopAbs_SOLID: + name = "solid"; break; + case TopAbs_SHELL: + name = "shell"; break; + case TopAbs_FACE: + name = "face"; break; + case TopAbs_WIRE: + name = "wire"; break; + case TopAbs_EDGE: + name = "edge"; break; + case TopAbs_VERTEX: + name = "vertex"; break; + default: + break; + } + if ( capitalize && !name.isEmpty() ) + name = name.left(1).toUpper() + name.mid(1); + return name; +} + +//================================================================ +// Function : GetEntry +// Purpose : Get study entry for the given object (if it is published) +//================================================================ +QString GEOMBase::GetEntry( GEOM::GEOM_Object_ptr object ) +{ + QString entry; + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study && !CORBA::is_nil( object ) ) { + QString objIOR = GetIORFromObject( object ); + if ( !objIOR.isEmpty() ) { + _PTR(SObject) SO( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) ); + if ( SO ) + entry = SO->GetID().c_str(); } } + return entry; +} - return QString(""); +//================================================================ +// Function : PublishSubObject +// Purpose : Publish sub-shape under the main object +//================================================================ +void GEOMBase::PublishSubObject( GEOM::GEOM_Object_ptr object, const QString& name ) +{ + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study && !CORBA::is_nil( object ) ) { + _PTR(Study) studyDS = study->studyDS(); + QString entry = GetEntry( object ); + GEOM::GEOM_Object_var father = object->GetMainShape(); + QString fatherEntry = GetEntry( father ); + if ( entry.isEmpty() && !CORBA::is_nil( father ) && !fatherEntry.isEmpty() ) { + QString aName = !name.isEmpty() ? name : GetName( object ); + GeometryGUI::GetGeomGen()->AddInStudy( object, aName.toUtf8().data(), father.in() ); + } + } } -bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj ) +//================================================================ +// Function : synchronize +// Purpose : +//================================================================ +void GEOMBase::Synchronize( QList& left, QList& right ) { - return !theObj->_is_nil() && theObj->IsShape(); + // 1. remove items from the "left" list that are not in the "right" list + QMutableListIterator it1( left ); + while ( it1.hasNext() ) { + GEOM::GeomObjPtr o1 = it1.next(); + bool found = false; + QMutableListIterator it2( right ); + while ( it2.hasNext() && !found ) + found = o1 == it2.next(); + if ( !found ) + it1.remove(); + } + // 2. add items from the "right" list that are not in the "left" list (to keep selection order) + it1 = right; + while ( it1.hasNext() ) { + GEOM::GeomObjPtr o1 = it1.next(); + bool found = false; + QMutableListIterator it2( left ); + while ( it2.hasNext() && !found ) + found = o1 == it2.next(); + if ( !found ) + left << o1; + } }