Salome HOME
This commit was generated by cvs2git to create branch 'CCAR_br1'.
[modules/kernel.git] / src / SALOMEGUI / QAD_Desktop.cxx
index fc6cd157ce628de24d62d35e08be62f108bbf967..a53dca619efbb2ce462ddccc60ac6434958321ad 100644 (file)
@@ -81,6 +81,8 @@ using namespace std;
 #include <OSD_Function.hxx>
 #include <TCollection_AsciiString.hxx>
 
+static const char* SEPARATOR    = ":";
+
 extern "C"
 {
 # include <string.h>
@@ -245,14 +247,27 @@ myQueryClose( true )
     /* find component icon */
     QString iconfile = strdup(list_composants[ind].moduleicone) ;
     QString modulename = strdup(list_composants[ind].modulename) ;
+    QString moduleusername = strdup(list_composants[ind].moduleusername) ;
+
+    //    MESSAGE ( " MODULE = " << modulename )
+    //    MESSAGE ( " MODULE icon = " << iconfile )
+    //    MESSAGE ( " MODULE username = " << moduleusername )
+
+    if ( mapComponentName.contains( moduleusername ) ) {
+      QMessageBox::warning( this, tr("WRN_WARNING"), QString( moduleusername + " is already associated with " + mapComponentName[moduleusername] + ".\nPlease, change the component username of " + modulename) , tr ("BUT_OK") );
+      continue;
+    }
+    mapComponentName.insert( moduleusername, modulename );
+      
     resDir = resMgr->findFile(iconfile,modulename) ;
     if (resDir)
       {
+       MESSAGE ( "resDir" << resDir )
        //resDir = QAD_Tools::addSlash(resDir) ;
        //QPixmap Icone(resDir+iconfile) ;
        QPixmap Icone( QAD_Tools::addSlash( resDir ) + iconfile );
        QToolButton * toolb = 
-         new QToolButton( QIconSet( Icone ), modulename, QString::null, this, 
+         new QToolButton( QIconSet( Icone ), moduleusername, QString::null, this, 
                           SLOT( onButtonActiveComponent () ),tbComponent );
        toolb->setToggleButton( true );
        myComponentButton.append(toolb);
@@ -265,7 +280,7 @@ myQueryClose( true )
       }
 
     if ( !QString(list_composants[ind].modulename).isEmpty() )
-      myCombo->insertItem( strdup(list_composants[ind].modulename) );
+      myCombo->insertItem( strdup(list_composants[ind].moduleusername) );
 
   }
 
@@ -757,7 +772,7 @@ void QAD_Desktop::createActions()
     
     myPrefPopup.insertSeparator();
 
-    QAction* dirAction = new QAction( "", tr("MEN_DESK_PREF_DIRICTORIES"), 0, this );
+    QAction* dirAction = new QAction( "", tr("MEN_DESK_PREF_DIRICTORIES"), ALT+Key_D, this );
     QAD_ASSERT(connect( dirAction, SIGNAL(activated()), this, SLOT(onDirList() )));
     dirAction->addTo( &myPrefPopup );
     myStdActions.insert( PrefDirsId, dirAction );
@@ -774,17 +789,17 @@ void QAD_Desktop::createActions()
     //NRI : SAL2214
     myWindowPopup.insertItem( tr("MEN_DESK_WINDOW_NEW3D"), &myNewViewPopup, WindowNew3dId );
     
-    QAction* viewOCCAction = new QAction( "", tr("MEN_DESK_VIEW_OCC"), 0, this );
+    QAction* viewOCCAction = new QAction( "", tr("MEN_DESK_VIEW_OCC"), ALT+Key_O, this );
     QAD_ASSERT(connect( viewOCCAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
     viewOCCAction->addTo( &myNewViewPopup );
     myStdActions.insert( ViewOCCId, viewOCCAction );
 
-    QAction* viewVTKAction = new QAction( "", tr("MEN_DESK_VIEW_VTK"), 0, this );
+    QAction* viewVTKAction = new QAction( "", tr("MEN_DESK_VIEW_VTK"), ALT+Key_V, this );
     QAD_ASSERT(connect( viewVTKAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
     viewVTKAction->addTo( &myNewViewPopup );
     myStdActions.insert( ViewVTKId, viewVTKAction );
 
-    QAction* viewPlot2dAction = new QAction( "", tr("MEN_DESK_VIEW_PLOT2D"), 0, this );
+    QAction* viewPlot2dAction = new QAction( "", tr("MEN_DESK_VIEW_PLOT2D"), ALT+Key_P, this );
     QAD_ASSERT(connect( viewPlot2dAction, SIGNAL(activated()), this, SLOT(onNewWindow3d() )));
     viewPlot2dAction->addTo( &myNewViewPopup );
     myStdActions.insert( ViewPlot2dId, viewPlot2dAction );
@@ -819,7 +834,7 @@ void QAD_Desktop::createActions()
     /* 'Help' actions
      */
     /* contents */
-    QAction* helpContentsAction = new QAction( "", tr("MEN_DESK_HELP_CONTENTS"), 0, this );
+    QAction* helpContentsAction = new QAction( "", tr("MEN_DESK_HELP_CONTENTS"), Key_F1, this );
     helpContentsAction->setStatusTip ( tr("PRP_DESK_HELP_CONTENTS") );
     QAD_ASSERT(connect( helpContentsAction, SIGNAL(activated()),
                        this, SLOT( onHelpContents() )));
@@ -1117,6 +1132,23 @@ Engines::Component_var QAD_Desktop::getEngine(const char *containerName,
   return eng._retn();
 }
 
+QString QAD_Desktop::getComponentName(const char *componentUserName)
+{
+  if ( mapComponentName.contains(componentUserName) )
+    return mapComponentName[ componentUserName ] ;
+  else
+    return "";
+}
+
+QString QAD_Desktop::getComponentUserName(const char *componentName)
+{
+  QMap<QString,QString>::Iterator it;
+  for( it = mapComponentName.begin(); it != mapComponentName.end(); ++it )
+    if (it.data() == componentName )
+      return it.key();
+  return "";
+}
+
 /*!
   gets application Help Window (and creates if necessary)
 */
@@ -1124,6 +1156,37 @@ QAD_HelpWindow* QAD_Desktop::getHelpWindow()
 {
   if (!myHelpWindow) {
     myHelpWindow = new QAD_HelpWindow();  
+    
+    QMap<QString,QString>::Iterator it;
+    for( it = mapComponentName.begin(); it != mapComponentName.end(); ++it ) {
+      QCString dir;
+      QString root;
+      
+      // look for index.html and set homeDir
+      // 1. $(MODULE_ROOT_DIR)/doc/index.html
+      // 2. $(MODULE_ROOT_DIR)/doc/html/index.html
+      // 3. $(MODULE_ROOT_DIR)/doc/html/html/index.html
+
+      if (dir = getenv( QString( it.data() + "_ROOT_DIR")) ) {
+       root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share")  + QAD_Tools::addSlash("salome")  + "doc" );
+       if ( QFileInfo( root + "index.html" ).exists() ) {
+         helpContext( root + "index.html", "" );
+       }
+       else {
+         root = QAD_Tools::addSlash( root + "html" );
+         if ( QFileInfo( root + "index.html" ).exists() ) {
+           helpContext( root + "index.html", "" );
+         }
+         else {
+           root = QAD_Tools::addSlash( root + "html" );
+           if ( QFileInfo( root + "index.html" ).exists() ) {
+             helpContext( root + "index.html", "" );
+           }
+         }
+       }
+      }
+    }
+    
     connect(myHelpWindow, SIGNAL(helpWindowClosed()), this, SLOT(onHelpWindowClosed()));
   }
   return myHelpWindow;
@@ -1415,7 +1478,7 @@ void QAD_Desktop::onOpenStudy()
                                      tr("BUT_OK") );
            } else if (myActiveComp != "") {
              QApplication::setOverrideCursor( Qt::waitCursor );
-             loadComponentData(myActiveComp);
+             loadComponentData(mapComponentName[myActiveComp]);
              openStudy->updateObjBrowser(true);
              QApplication::restoreOverrideCursor();
            }
@@ -1436,14 +1499,14 @@ void QAD_Desktop::onOpenStudy()
 bool QAD_Desktop::loadComponentData( const QString& compName )
 {
   // Open component's data in active study if any
-  MESSAGE("loadComponentData(): Opening component data")
+  MESSAGE("loadComponentData(): Opening " << compName << " component data ")
   if (!myActiveStudy) {
     MESSAGE("loadComponentData(): No active study exists")
     return false;
   }
 
   Engines::Component_var comp ;
-  if ( compName.compare("Supervision") == 0 ) {
+  if ( compName.compare("SUPERV") == 0 ) {
     comp = getEngine( "SuperVisionContainer", compName) ;
   }
   else {
@@ -1456,7 +1519,7 @@ bool QAD_Desktop::loadComponentData( const QString& compName )
   }
 
   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
-  SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject(compName));
+  SALOMEDS::SComponent_var SCO = SALOMEDS::SComponent::_narrow(aStudy->FindObject( getComponentUserName(compName) ));
           
   if (!SCO->_is_nil()) {
     if (!CORBA::is_nil(comp)) {
@@ -2106,7 +2169,7 @@ void QAD_Desktop::onOpenWith()
     if (SCO->FindAttribute(anAttr, "AttributeName")) {
       aName = SALOMEDS::AttributeName::_narrow(anAttr);
       name = aName->Value();
-      SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( name );
+      SALOME_ModuleCatalog::Acomponent_var Comp = myCatalogue->GetComponent( mapComponentName[name] );
       if ( !Comp->_is_nil() ) {
        
        SALOME_ModuleCatalog::ListOfComponents_var list_type_composants =
@@ -2184,7 +2247,7 @@ bool QAD_Desktop::loadComponent(QString Component)
   QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
   if ( resMgr ) {
     QString msg;
-    if (!resMgr->loadResources( Component + "GUI", msg ))
+    if (!resMgr->loadResources( Component, msg ))
       {
        //NRI   QCString errMsg;
        //      errMsg.sprintf( "Do not load all resources for module %sGUI.\n" ,
@@ -2198,14 +2261,14 @@ bool QAD_Desktop::loadComponent(QString Component)
   /* Parse xml file */
   myXmlHandler = new QAD_XmlHandler();
   myXmlHandler->setMainWindow(this);
-  if (!myXmlHandler->setComponent(resMgr->resources(Component + "GUI"))) return false;
+  if (!myXmlHandler->setComponent(resMgr->resources( Component ))) return false;
 
-  QString language = resMgr->language( Component + "GUI" );
+  QString language = resMgr->language( Component );
 
   QString ComponentXml = Component + "_" + language + ".xml";
   //ComponentXml = resMgr->resources(Component + "GUI") ;
   //ComponentXml = QAD_Tools::addSlash(ComponentXml) ;
-  ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component + "GUI" ) ) + ComponentXml;
+  ComponentXml = QAD_Tools::addSlash( resMgr->findFile( ComponentXml, Component ) ) + ComponentXml;
   QFile file( ComponentXml );
 
   if ( !file.exists() || !file.open( IO_ReadOnly ) )  {
@@ -2245,40 +2308,36 @@ bool QAD_Desktop::loadComponent(QString Component)
   mySharedLibrary = OSD_SharedLibrary();
 
   QString ComponentLib;
-  QCString dir;
+  QCString libs;
   QFileInfo fileInfo ;
-  bool found = false;
-  if ( dir = getenv("SALOME_SITE_DIR")) {
-    dir = QAD_Tools::addSlash(dir) ;
-    dir = dir + "lib" ;
-    dir = QAD_Tools::addSlash(dir) ;
+  QString fileString ;
+  QString dir;
+
+  if ( libs = getenv("LD_LIBRARY_PATH")) {
+    //    MESSAGE ( " LD_LIBRARY_PATH : " << libs )
+    QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries
+    bool found = false;
+    for ( int i = dirList.count()-1; i >= 0; i-- ) {
+      dir = dirList[ i ];
 #ifdef WNT
-    dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
+      fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ;
 #else
-    dir = dir + "lib" + Component.latin1() + "GUI.so" ;
+      fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ;
 #endif
-    MESSAGE ( " GUI library = " << dir )
-    fileInfo.setFile(dir) ;
-    if (fileInfo.exists()) {
-      ComponentLib = fileInfo.fileName() ;
-      found = true;
+    
+      fileInfo.setFile(fileString) ;
+      if (fileInfo.exists()) {
+       //      MESSAGE ( " GUI library = " << fileString )
+       ComponentLib = fileInfo.fileName() ;
+       found = true;
+       break;
+      }
     }
-  }
-  
-  if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
-    dir = QAD_Tools::addSlash(dir) ;
-    dir = dir + "lib" ;
-    dir = QAD_Tools::addSlash(dir) ;
-#ifdef WNT
-    dir = dir + "lib" + Component.latin1() + "GUI.dll" ;
-#else
-    dir = dir + "lib" + Component.latin1() + "GUI.so" ;
-#endif
-    MESSAGE ( " GUI library = " << dir )
-    fileInfo.setFile(dir) ;
-    if (fileInfo.exists()) {
-      ComponentLib = fileInfo.fileName() ;
-      found = true;
+    if ( !found ) {
+      QMessageBox::critical( this,
+                            tr("ERR_ERROR"),
+                            tr("ERR_LIBGUI" ).arg(Component) );
+      return false;
     }
   }
 
@@ -2309,7 +2368,7 @@ bool QAD_Desktop::loadComponent(QString Component)
   }
 
   myActiveStudy->setMessage(QString("Component : ") +
-                           aComponent->componentname() + " created " );
+                           aComponent->componentusername() + " created " );
   myActiveStudy->setMessage(QString("Type : ") +
                            QString::number(aComponent->component_type()));
   myActiveStudy->setMessage(QString("Constraint : ") +
@@ -2401,6 +2460,8 @@ void QAD_Desktop::onDispatchTools(int id)
       dir = QAD_Tools::addSlash(dir) ;
       dir = dir + "lib" ;
       dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + "salome" ;
+      dir = QAD_Tools::addSlash(dir) ;
 #ifdef WNT
       dir = dir + "libToolsGUI.dll" ;
 #else
@@ -2418,6 +2479,27 @@ void QAD_Desktop::onDispatchTools(int id)
       dir = QAD_Tools::addSlash(dir) ;
       dir = dir + "lib" ;
       dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + "salome" ;
+      dir = QAD_Tools::addSlash(dir) ;
+#ifdef WNT
+      dir = dir + "libToolsGUI.dll" ;
+#else
+      dir = dir + "libToolsGUI.so" ;
+#endif
+      MESSAGE ( " GUI library = " << dir );
+      fileInfo.setFile(dir) ;
+      if (fileInfo.exists()) {
+       ToolsLib = fileInfo.fileName() ;
+       found = true;
+      }
+    }
+    
+    if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
+      dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + "lib" ;
+      dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + "salome" ;
+      dir = QAD_Tools::addSlash(dir) ;
 #ifdef WNT
       dir = dir + "libToolsGUI.dll" ;
 #else
@@ -2438,6 +2520,8 @@ void QAD_Desktop::onDispatchTools(int id)
       dir = QAD_Tools::addSlash(dir) ;
       dir = dir + "lib" ;
       dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + "salome" ;
+      dir = QAD_Tools::addSlash(dir) ;
       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
       MESSAGE ( " GUI library = " << dir );
       fileInfo.setFile(dir) ;
@@ -2451,6 +2535,23 @@ void QAD_Desktop::onDispatchTools(int id)
       dir = QAD_Tools::addSlash(dir) ;
       dir = dir + "lib" ;
       dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + "salome" ;
+      dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
+      MESSAGE ( " GUI library = " << dir );
+      fileInfo.setFile(dir) ;
+      if (fileInfo.exists()) {
+       ToolsLib = fileInfo.fileName() ;
+       found = true;
+      }
+    }
+    
+    if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
+      dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + "lib" ;
+      dir = QAD_Tools::addSlash(dir) ;
+      dir = dir + "salome" ;
+      dir = QAD_Tools::addSlash(dir) ;
       dir = dir + QAD_XmlHandler::_bibmap[ id ].latin1() ;
       MESSAGE ( " GUI library = " << dir );
       fileInfo.setFile(dir) ;
@@ -2519,7 +2620,8 @@ void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoad
       if (!myXmlHandler->myIdList.IsEmpty()) clearMenus();
       if ( myCombo->currentText() != component )
        myCombo->setCurrentText( component );
-      if (component.compare(QString("Salome"))!= 0) {
+      //NRI if (component.compare(QString("Salome"))!= 0) {
+      if (component.compare( getComponentUserName( "KERNEL" ) )!= 0) {
 //     QApplication::setOverrideCursor( Qt::waitCursor );
        myActiveComp = component;
 
@@ -2533,7 +2635,7 @@ void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoad
        }
 
        myActiveStudy->Selection( component );
-       if ( !loadComponent(component) ) {
+       if ( !loadComponent(mapComponentName[component]) ) {
          myCombo->setCurrentItem (0);
          for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
            aButton->setOn(false);
@@ -2554,7 +2656,7 @@ void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoad
        }
 
        // Open new component's data in active study if any
-       if(isLoadData) loadComponentData(component);
+       if(isLoadData) loadComponentData(mapComponentName[component]);
 
        oldSel->Clear();
        myActiveStudy->updateObjBrowser(true);
@@ -2563,7 +2665,8 @@ void QAD_Desktop::onComboActiveComponent( const QString & component, bool isLoad
 
       } else {  // component == "Salome"
        myActiveComp = "";
-       myActiveStudy->Selection( "Salome" );
+       //NRI   myActiveStudy->Selection( "Salome" );
+       myActiveStudy->Selection( getComponentUserName( "KERNEL" ) );
        SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
        Sel->ClearIObjects();
        for ( QToolButton* aButton=myComponentButton.first(); aButton; aButton=myComponentButton.next() ) {
@@ -3154,7 +3257,31 @@ void QAD_Desktop::helpSearch()
 /* Help Contents */
 void QAD_Desktop::helpContents()
 {
-  getHelpWindow()->contents();
+  if (myActiveComp == "")
+    myActiveComp = getComponentUserName( "KERNEL" ); //NRI "Salome";
+
+  QCString dir;
+  QString root;
+  if (dir = getenv( getComponentName( myActiveComp ) + "_ROOT_DIR")) {
+    root = QAD_Tools::addSlash( QAD_Tools::addSlash(dir) + QAD_Tools::addSlash("share")  + QAD_Tools::addSlash("salome")  + "doc" );
+    if ( QFileInfo( root + "index.html" ).exists() ) {
+      helpContext( root + "index.html", "" );
+    }
+    else {
+      root = QAD_Tools::addSlash( root + "html" );
+      if ( QFileInfo( root + "index.html" ).exists() ) {
+       helpContext( root + "index.html", "" );
+      }
+      else {
+       root = QAD_Tools::addSlash( root + "html" );
+       if ( QFileInfo( root + "index.html" ).exists() ) {
+         helpContext( root + "index.html", "" );
+       }
+      }
+    }
+  }
+  
+  //NRI getHelpWindow()->contents();
   getHelpWindow()->show();
   getHelpWindow()->raise();
   getHelpWindow()->setActiveWindow();