]> SALOME platform Git repositories - samples/light.git/blobdiff - src/LIGHTGUI/LIGHTGUI.cxx
Salome HOME
Preparation of 3.1.0a2 - come back old implementation
[samples/light.git] / src / LIGHTGUI / LIGHTGUI.cxx
index f182850674a00d10bb87d1a038b332ef738307a7..39cdf5a47433c18c861a6523d3f182bc6713da61 100644 (file)
@@ -29,27 +29,22 @@ using namespace std;
 
 #include "LIGHTGUI_Selection.h"
 #include "LIGHTGUI_DataModel.h"
-#include "LightApp_DataOwner.h"
+#include "LIGHTGUI_OBSelector.h"
+#include "LIGHTGUI_DataOwner.h"
 
 #include <SUIT_MessageBox.h>
-#include <LightApp_Application.h>
-#include <LightApp_SelectionMgr.h>
-#include "LightApp_Selection.h"
+#include <SalomeApp_Application.h>
+#include <SalomeApp_SelectionMgr.h>
 
 #include <qinputdialog.h>
 #include <qstringlist.h>
 
-#include <LIGHTGUI_TextPrs.hxx>
-#include <OCCViewer_ViewManager.h>
-#include <SOCC_ViewModel.h>
-#include <SOCC_Prs.h>
-
 //=================================================================================
 // function : LIGHTGUI()
 // purpose  : Constructor : sets the default name for the module
 //=================================================================================
 LIGHTGUI::LIGHTGUI()
-     : LightApp_Module( "LIGHTGUI" )
+     : SalomeApp_Module( "LIGHTGUI" )
 {
 }
 
@@ -59,7 +54,7 @@ LIGHTGUI::LIGHTGUI()
 //=================================================================================
 void LIGHTGUI::initialize ( CAM_Application* app )
 {
-  LightApp_Module::initialize( app );
+  SalomeApp_Module::initialize( app );
 
   QWidget* parent = application()->desktop();
 
@@ -67,8 +62,6 @@ void LIGHTGUI::initialize ( CAM_Application* app )
                 tr( "STB_LOAD_FILE" ), 0, parent, false, this, SLOT( onLoadFile() ) );
   createAction( lgSaveFile, tr( "TOP_SAVE_FILE" ), QIconSet(), tr( "MEN_SAVE_FILE" ),
                 tr( "STB_SAVE_FILE" ), 0, parent, false, this, SLOT( onSaveFile() ) );
-  createAction( lgDisplayLine, tr( "TOP_DISPLAY_LINE" ), QIconSet(), tr( "MEN_DISPLAY_LINE" ),
-                tr( "STB_DISPLAY_LINE" ), 0, parent, false, this, SLOT( onDisplayLine() ) );
   createAction( lgEditLine, tr( "TOP_EDIT_LINE" ), QIconSet(), tr( "MEN_EDIT_LINE" ),
                 tr( "STB_EDIT_LINE" ), 0, parent, false, this, SLOT( onEditLine() ) );
   createAction( lgAddLine,  tr( "TOP_ADD_LINE" ),  QIconSet(), tr( "MEN_ADD_LINE" ),
@@ -84,7 +77,6 @@ void LIGHTGUI::initialize ( CAM_Application* app )
   createMenu( lgSaveFile,  aFileMnu, 10 );
 
   int aLightMnu = createMenu( tr( "MEN_LIGHT" ), -1, -1, 50 );
-  createMenu( lgDisplayLine,  aLightMnu, 10 );
   createMenu( lgEditLine,  aLightMnu, 10 );
   createMenu( lgAddLine,   aLightMnu, 10 );
   createMenu( separator(), aLightMnu, -1, 10 );
@@ -95,9 +87,6 @@ void LIGHTGUI::initialize ( CAM_Application* app )
   int parentId = -1;
   QString rule = "client='ObjectBrowser' and selcount=1 and type='TextLine'";
 
-  popupMgr()->insert ( action( lgDisplayLine ), parentId, 0 );
-  popupMgr()->setRule( action( lgDisplayLine ), rule, true  );
-
   popupMgr()->insert ( action( lgEditLine ), parentId, 0 );
   popupMgr()->setRule( action( lgEditLine ), rule, true  );
 
@@ -116,12 +105,10 @@ void LIGHTGUI::initialize ( CAM_Application* app )
 // function : contextMenuPopup()
 // purpose  : defines context popup menu
 //=================================================================================
-void LIGHTGUI::contextMenuPopup ( const QString& client, QPopupMenu* menu, QString& str)
+void LIGHTGUI::contextMenuPopup ( const QString& client, QPopupMenu* menu, QString& )
 {
-  LIGHTGUI_Selection* sel = new LIGHTGUI_Selection();
-  sel->init( client, getApp()->selectionMgr() );
-  popupMgr()->updatePopup( menu, sel );
-  delete sel;
+  LIGHTGUI_Selection sel ( client, getApp()->selectionMgr() );
+  popupMgr()->updatePopup( menu, &sel );
 }
 
 //=================================================================================
@@ -130,8 +117,18 @@ void LIGHTGUI::contextMenuPopup ( const QString& client, QPopupMenu* menu, QStri
 //=================================================================================
 void LIGHTGUI::windows ( QMap<int, int>& aMap ) const
 {
-  aMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::DockLeft );
-  aMap.insert( LightApp_Application::WT_PyConsole, Qt::DockBottom );
+  aMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
+  aMap.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
+}
+
+//=================================================================================
+// function : engineIOR()
+// purpose  : Returns empty string. It means that this module
+//            should use default engine for its persistence.
+//=================================================================================
+QString LIGHTGUI::engineIOR() const
+{
+  return QString( "" );
 }
 
 //=================================================================================
@@ -152,19 +149,17 @@ int LIGHTGUI::selectedLine()
   int aPosition = 0; // bad value
   
   // Look for selected lines
-  LightApp_Application* app = getApp();
-  LightApp_SelectionMgr* mgr = app ? app->selectionMgr() : NULL;
+  SalomeApp_Application* app = getApp();
+  SalomeApp_SelectionMgr* mgr = app ? app->selectionMgr() : NULL;
   if ( mgr ) {
     SUIT_DataOwnerPtrList anOwnersList;
     mgr->selected( anOwnersList );
     
     // Get index of the single selected line
     if ( anOwnersList.size() == 1 ) {
-      const LightApp_DataOwner* owner =
-       dynamic_cast<const LightApp_DataOwner*>( anOwnersList[0].get() );
-      QString anEntry = owner->entry();
-      int anIndex = anEntry.find("_");
-      aPosition = (anEntry.mid(anIndex+1, anEntry.length() - anIndex)).toInt();//lineNb();
+      const LIGHTGUI_DataOwner* owner =
+       dynamic_cast<const LIGHTGUI_DataOwner*>( anOwnersList[0].get() );
+      aPosition = owner->lineNb();
     }
   }
   return aPosition;
@@ -176,11 +171,36 @@ int LIGHTGUI::selectedLine()
 //=================================================================================
 bool LIGHTGUI::activateModule ( SUIT_Study* study )
 {
-  bool isDone = LightApp_Module::activateModule( study );
+  bool isDone = SalomeApp_Module::activateModule( study );
   if ( !isDone ) return false;
 
   setMenuShown( true );
 
+  // enable own ObjectBrowser selector an disable another ones
+  bool isOwnSelector = false;
+  QPtrList<SUIT_Selector> lst;
+  getApp()->selectionMgr()->selectors( lst );
+  for ( QPtrListIterator<SUIT_Selector> it( lst ); it.current(); ++it ) {
+    if ( it.current()->type() == "ObjectBrowser" ) {
+      LIGHTGUI_OBSelector* anOwnSelector = dynamic_cast<LIGHTGUI_OBSelector*>( it.current() );
+      // restore own selector
+      if ( anOwnSelector ) {
+        // enable own
+        anOwnSelector->setEnabled( true );
+       isOwnSelector = true;
+      } 
+      else {
+        // disable other
+        it.current()->setEnabled( false );
+      }
+    }
+  }
+
+  // create own selector, if it was not found in selection manager
+  if ( !isOwnSelector ) {
+    new LIGHTGUI_OBSelector ( getApp()->objectBrowser(), getApp()->selectionMgr() );
+  }
+
   return isDone;
 }
 
@@ -193,7 +213,24 @@ bool LIGHTGUI::deactivateModule ( SUIT_Study* study )
   // hide menus
   setMenuShown( false );
 
-  return LightApp_Module::deactivateModule( study );
+  // disable own ObjectBrowser selector an enable another ones
+  QPtrList<SUIT_Selector> lst;
+  getApp()->selectionMgr()->selectors( lst );
+  for ( QPtrListIterator<SUIT_Selector> it( lst ); it.current(); ++it ) {
+    if ( it.current()->type() == "ObjectBrowser" ) {
+      LIGHTGUI_OBSelector* anOwnSelector = dynamic_cast<LIGHTGUI_OBSelector*>( it.current() );
+      if ( anOwnSelector ) {
+        // disable own selector
+        anOwnSelector->setEnabled( false );
+      } 
+      else {
+        // enable other
+        it.current()->setEnabled( true );
+      }
+    }
+  }
+
+  return SalomeApp_Module::deactivateModule( study );
 }
 
 //=================================================================================
@@ -250,35 +287,6 @@ void LIGHTGUI::onSaveFile()
       }
   }
 }
-//=================================================================================
-// function : onDisplayLine()
-// purpose  : "Display Line" action slot
-//=================================================================================
-void LIGHTGUI::onDisplayLine()
-{
-  OCCViewer_ViewManager* aMgr = (OCCViewer_ViewManager*)getApp()->getViewManager("OCCViewer", true);
-  SOCC_Viewer* aViewer = (SOCC_Viewer*)aMgr->getViewModel();  
-  if ( !aViewer )
-    return;
-
-  LIGHTGUI_DataModel* dm = dynamic_cast<LIGHTGUI_DataModel*>( dataModel() );
-  if ( !dm ) return;
-  int aPosition = selectedLine();
-  QString aLine =  dm->getLineText( aPosition );
-  double aX = 0, aY = 0, aZ = 0;
-  QString aStrId = QString("LIGHTGUI_%1").arg(aPosition);
-
-  Handle(LIGHTGUI_TextPrs) aPrs = new LIGHTGUI_TextPrs( aLine, gp_Pnt( aX, aY, aZ ) );
-  aPrs->SetOwner(new SALOME_InteractiveObject( aStrId, "" ) );
-  SOCC_Prs* prs = dynamic_cast<SOCC_Prs*>( aViewer->CreatePrs() ); // aStringID is an "entry"
-  if ( prs ) {
-    aViewer->EraseAll();
-    prs->AddObject( aPrs );
-    aViewer->Display( prs );
-    aViewer->Repaint();
-    getApp()->updateObjectBrowser();
-  } 
-}
 
 //=================================================================================
 // function : onEditLine()