Salome HOME
PAL10332 - references are interpreted as original objects in filters, dialogs, etc.
authorasl <asl@opencascade.com>
Tue, 25 Oct 2005 08:19:21 +0000 (08:19 +0000)
committerasl <asl@opencascade.com>
Tue, 25 Oct 2005 08:19:21 +0000 (08:19 +0000)
src/SMESHFiltersSelection/SMESH_NumberFilter.cxx
src/SMESHFiltersSelection/SMESH_NumberFilter.hxx
src/SMESHFiltersSelection/SMESH_TypeFilter.cxx
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI_Selection.cxx
src/SMESHGUI/SMESHGUI_Selection.h
src/SMESHGUI/SMESHGUI_SelectionOp.cxx

index 517d45053e655064f435bd93975bcf24983b5d43..a44dcf87fd037c076d7001ca36c0bfaaac417a89 100644 (file)
@@ -127,7 +127,7 @@ bool SMESH_NumberFilter::isOk (const SUIT_DataOwner* theDataOwner) const
 // Purpose : Retrieve geom object from SALOME_InteractiveObject
 //=======================================================================
 GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom
-  (const SUIT_DataOwner* theDataOwner) const
+  (const SUIT_DataOwner* theDataOwner, const bool extractReference ) const
 {
   const SalomeApp_DataOwner* owner =
     dynamic_cast<const SalomeApp_DataOwner*>(theDataOwner);
@@ -142,7 +142,10 @@ GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom
   _PTR(Study) study = appStudy->studyDS();
   QString entry = owner->entry();
 
-  _PTR(SObject) aSO(study->FindObjectID(entry.latin1()));
+  _PTR(SObject) aSO( study->FindObjectID( entry.latin1() ) ), aRefSO;
+  if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
+    aSO = aRefSO;
+
   if (!aSO)
     return GEOM::GEOM_Object::_nil();
 
index 6b341129374162fae8959a730f6e289440bff7f9..4f6602e5f4a2162ce231665df73855310b8cc032 100644 (file)
@@ -55,7 +55,7 @@ class SMESH_NumberFilter : public SUIT_SelectionFilter
   void SetMainShape    (GEOM::GEOM_Object_ptr);
 
  private:
-  GEOM::GEOM_Object_ptr getGeom (const SUIT_DataOwner*) const;
+  GEOM::GEOM_Object_ptr getGeom (const SUIT_DataOwner*, const bool extractReference = true ) const;
 
  private:
   char*                 myKind;
index acf7cb815df2119aba9ee34ffbe9c2a594285b18..b99f4d1d7d1798c9414ef20ae51f0ec130a13346 100644 (file)
@@ -16,7 +16,7 @@ SMESH_TypeFilter::~SMESH_TypeFilter()
 
 bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
 {
-  bool Ok = false;
+  bool Ok = false, extractReference = true;
 
   const SalomeApp_DataOwner* owner =
     dynamic_cast<const SalomeApp_DataOwner*>(theDataOwner);
@@ -27,7 +27,9 @@ bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
     _PTR(Study) study = appStudy->studyDS();
     QString entry = owner->entry();
 
-    _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
+    _PTR(SObject) obj (study->FindObjectID(entry.latin1())), aRefSO;
+    if( extractReference && obj && obj->ReferencedObject( aRefSO ) )
+      obj = aRefSO;
     if (!obj) return false;
 
     _PTR(SObject) objFather = obj->GetFather();
index e53d67a7974a339d83043b31df990702dec90476..d802648e4de6e240f19cf1eeb495d5b6adf6d151 100644 (file)
@@ -667,7 +667,7 @@ namespace{
   {
     // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
     SalomeApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
-    SALOME_ListIO selected; aSel->selectedObjects( selected );
+    SALOME_ListIO selected; aSel->selectedObjects( selected, QString::null, false );
 
     QString aParentComponent = QString::null;
     for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
@@ -1829,7 +1829,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
       SALOME_ListIO selected;
       if( aSel )
-        aSel->selectedObjects( selected );
+        aSel->selectedObjects( selected, QString::null, false );
 
       SALOME_ListIteratorOfListIO It(selected);
       for (int i = 0; It.More(); It.Next(), i++) {
index 33f01403f46fb1df5a0e5ee31d98d3b923a7f1d4..1b281d27f2fbe22edd697f66034c1d1b247bd84f 100644 (file)
@@ -49,23 +49,25 @@ void SMESHGUI_Selection::init( const QString& client, SalomeApp_SelectionMgr* mg
   {
     _PTR(Study) aStudy = study()->studyDS();
 
-    SUIT_DataOwnerPtrList sel;
-    mgr->selected( sel, client );
-    myDataOwners = sel;
-    SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(),
-                                          aLast = sel.end();
-    for( ; anIt!=aLast; anIt++ )
-    {
-      SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() );
-      SalomeApp_DataOwner* sowner = dynamic_cast<SalomeApp_DataOwner*>( owner );
-      if( sowner )
-        myTypes.append( typeName( type( sowner, aStudy ) ) );
-      else
-        myTypes.append( "Unknown" );
-    }
+    for( int i=0, n=count(); i<n; i++ )
+      myTypes.append( typeName( type( entry( i ), aStudy ) ) );
   }
 }
 
+//=======================================================================
+//function : processOwner
+//purpose  : 
+//=======================================================================
+void SMESHGUI_Selection::processOwner( const SalomeApp_DataOwner* ow )
+{
+  const SalomeApp_SVTKDataOwner* owner = 
+    dynamic_cast<const SalomeApp_SVTKDataOwner*> ( ow );
+  if( owner )
+    myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
+  else
+    myActors.append( 0 );
+}
+
 //=======================================================================
 //function : param
 //purpose  : 
@@ -103,13 +105,10 @@ QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
 
 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
 {
-  if ( ind >= 0 && ind < myDataOwners.count() ) {
-    const SalomeApp_SVTKDataOwner* owner = 
-      dynamic_cast<const SalomeApp_SVTKDataOwner*> ( myDataOwners[ ind ].get() );
-    if ( owner )    
-      return dynamic_cast<SMESH_Actor*>( owner->GetActor() );
-  }
-  return 0;
+  if( ind >= 0 && ind < count() )
+    return ((QPtrList<SMESH_Actor>&)myActors).at( ind );
+  else
+    return 0;
 }
 
 //=======================================================================
@@ -240,8 +239,9 @@ int SMESHGUI_Selection::numberOfNodes( int ind ) const
 {
   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
   {
-    CORBA::Object_var obj =
-      SMESH::DataOwnerToObject( static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() ));
+    _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
+    CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
+
     if ( ! CORBA::is_nil( obj )) {
       SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
       if ( ! mesh->_is_nil() )
@@ -266,18 +266,19 @@ QVariant SMESHGUI_Selection::isComputable( int ind ) const
 {
   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
   {
-    Handle(SALOME_InteractiveObject) io =
+/*    Handle(SALOME_InteractiveObject) io =
       static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
     if ( !io.IsNull() ) {
       SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io) ; // m,sm,gr->m
-      if ( !mesh->_is_nil() ) {
-        _PTR(SObject) so = SMESH::FindSObject( mesh );
+      if ( !mesh->_is_nil() ) {*/
+        _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ) );
+       //FindSObject( mesh );
         if ( so ) {
           GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
           return QVariant( !shape->_is_nil(), 0 );
         }
-      }
-    }
+//      }
+//    }
   }
   return QVariant( false, 0 );
 }
@@ -289,16 +290,7 @@ QVariant SMESHGUI_Selection::isComputable( int ind ) const
 
 QVariant SMESHGUI_Selection::hasReference( int ind ) const
 {
-  if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
-  {
-    SalomeApp_DataOwner* owner = dynamic_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].operator->() );
-    if( owner )
-    {
-      _PTR(SObject) obj ( study()->studyDS()->FindObjectID( owner->entry().latin1() ) ), ref;
-      return QVariant( obj->ReferencedObject( ref ), 0 );
-    }
-  }
-  return QVariant( false, 0 );
+  return QVariant( isReference( ind ), 0 );
 }
 
 //=======================================================================
@@ -310,8 +302,8 @@ QVariant SMESHGUI_Selection::isVisible( int ind ) const
 {
   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
   {
-    QString entry = static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->entry();
-    SMESH_Actor* actor = SMESH::FindActorByEntry( entry.latin1() );
+    QString ent = entry( ind );
+    SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() );
     if ( actor && actor->hasIO() ) {
       SVTK_RenderWindowInteractor* renderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
       return QVariant( renderInter->isVisible( actor->getIO() ), 0 );
@@ -320,16 +312,6 @@ QVariant SMESHGUI_Selection::isVisible( int ind ) const
   return QVariant( false, 0 );
 }
 
-
-//=======================================================================
-//function : type
-//purpose  :
-//=======================================================================
-int SMESHGUI_Selection::type( SalomeApp_DataOwner* owner, _PTR(Study) study )
-{
-  return type( owner->entry(), study );
-}
-
 //=======================================================================
 //function : type
 //purpose  : 
index 524aa26a253fcbcaa2ffe0c7e53b9d5351e0b9b2..833dde674e894f4a5277ee2c0ef549945f8de30b 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "SalomeApp_Selection.h"
 #include "SALOMEDSClient_definitions.hxx"
-#include "SUIT_DataOwner.h"
 
 class SalomeApp_SelectionMgr;
 class SALOMEDSClient_Study;
@@ -46,6 +45,7 @@ public:
 
   virtual void     init( const QString&, SalomeApp_SelectionMgr* );
   virtual QtxValue param( const int , const QString& paramName ) const;
+  virtual void     processOwner( const SalomeApp_DataOwner* );
 
   // got from object, not from actor
   virtual int numberOfNodes( int ind ) const;
@@ -64,12 +64,11 @@ public:
   SMESH_Actor* getActor( int ind ) const;
 
   static int       type( const QString&, _PTR(Study) );
-  static int       type( SalomeApp_DataOwner* owner, _PTR(Study) study);
   static QString   typeName( const int type);
 
 private:
-  QStringList           myTypes;
-  SUIT_DataOwnerPtrList myDataOwners;
+  QStringList            myTypes;
+  QPtrList<SMESH_Actor>  myActors;
 };
 
 #endif
index 1bc466c6a2c7d3a5fdef41355bd1da7d3f4939ae..6992319581dfa5c7bfbf82eb7c29229d10160c5e 100644 (file)
@@ -43,6 +43,8 @@
 #include CORBA_SERVER_HEADER(GEOM_Gen)
 #include <SALOMEDS_SObject.hxx>
 
+#include <SALOME_ListIteratorOfListIO.hxx>
+
 /*
   Class       : SMESHGUI_SelectionOp
   Description : Base operation for all operations using object selection in viewer or objectbrowser
@@ -357,7 +359,7 @@ void SMESHGUI_SelectionOp::selected( QStringList& names,
                                      SalomeApp_Dialog::TypesList& types,
                                      QStringList& ids ) const
 {
-  SUIT_DataOwnerPtrList list; selectionMgr()->selected( list );
+/*  SUIT_DataOwnerPtrList list; selectionMgr()->selected( list );
   SUIT_DataOwnerPtrList::const_iterator anIt = list.begin(),
                                         aLast = list.end();
   for( ; anIt!=aLast; anIt++ )
@@ -389,6 +391,37 @@ void SMESHGUI_SelectionOp::selected( QStringList& names,
       types.append( typeById( id, Object ) );
       names.append( owner->IO()->getName() );
     }
+  }*/
+
+  SALOME_ListIO selObjs;
+  TColStd_IndexedMapOfInteger selIndices;
+  selectionMgr()->selectedObjects( selObjs );
+  Selection_Mode mode = selectionMode();
+  EntityType objtype = mode == NodeSelection ? MeshNode : MeshElement;
+
+  for( SALOME_ListIteratorOfListIO anIt( selObjs ); anIt.More(); anIt.Next() )
+  {
+    selIndices.Clear();
+    selectionMgr()->GetIndexes( anIt.Value(), selIndices );
+    if( selIndices.Extent()==0 )
+    {
+      QString id_str = QString( "%1%2%3" ).arg( anIt.Value()->getEntry() ).arg( idChar() ), current_id_str;
+      for( int i=1, n=selIndices.Extent(); i<=n; i++ )
+      {
+        int curid = selIndices( i );
+        current_id_str = id_str.arg( curid );
+        ids.append( current_id_str );
+        types.append( typeById( current_id_str, objtype ) );
+        names.append( QString( "%1" ).arg( curid ) );
+      }
+    }
+    else
+    {
+      QString id = anIt.Value()->getEntry();
+      ids.append( id );
+      types.append( typeById( id, Object ) );
+      names.append( anIt.Value()->getName() );
+    }
   }
 }