Salome HOME
Added checking of the validator pointer.
[modules/gui.git] / src / CAM / CAM_Application.cxx
index 4f276dfa8ea1cbc5545d22de1ea07d47b28ae19a..eb7060abdc573fa8996afa0f0dcf9ce609affbbd 100755 (executable)
@@ -1,3 +1,21 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
 #include "CAM_Application.h"
 
 #include "CAM_Study.h"
@@ -12,6 +30,7 @@
 #include <qtextstream.h>
 #include <qlabel.h>
 #include <qfont.h>
+#include <qapplication.h>
 
 #ifdef WIN32
 #include <windows.h>
@@ -290,20 +309,7 @@ bool CAM_Application::activateModule( CAM_Module* mod )
 
   if ( myModule ){
     // Connect the module to the active study
-    CAM_Study* camStudy = dynamic_cast<CAM_Study*>( activeStudy() );
-    if ( camStudy ){
-      CAM_DataModel* prev = 0;
-      for ( ModuleListIterator it( myModules ); it.current(); ++it ) {
-       CAM_DataModel* dm = it.current()->dataModel();
-       if ( it.current() == myModule && !camStudy->containsDataModel( dm ) ){
-         if ( prev )
-           camStudy->insertDataModel( it.current()->dataModel(), prev );
-         else
-           camStudy->insertDataModel( it.current()->dataModel(), 0 );
-       }
-       prev = dm;
-      }
-    }
+    myModule->connectToStudy( dynamic_cast<CAM_Study*>( activeStudy() ) );
     if ( !myModule->activateModule( activeStudy() ) )
     {
       myModule->setMenuShown( false );
@@ -420,8 +426,34 @@ void CAM_Application::readModuleList()
 
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
 
-  QString modStr = resMgr->stringValue( "launch", "modules", QString::null );
-  QStringList modList = QStringList::split( ",", modStr );
+  QStringList modList;
+
+  // parse command line arguments
+  int nbArgs = qApp->argc();
+  char** CmdLine = qApp->argv();
+  QString CmdStr;
+  for ( int i = 0; i < nbArgs; i++ )
+  {
+    CmdStr.append(CmdLine[i]);
+    CmdStr.append(" ");
+  }
+  int startId = CmdStr.find("--modules (");
+  if ( startId != -1 ) { // application launch with --modules option
+    startId = CmdStr.find("(", startId);
+    int stopId = CmdStr.find(" )", startId);
+    QString ModStr = CmdStr.mid( startId+1, stopId - (startId+1) ).stripWhiteSpace();
+    int i = 0;
+    while ( i < ModStr.length() )
+    {
+      int nextId = ModStr.find( ":", i );
+      modList.append( ModStr.mid( i, nextId - i ).stripWhiteSpace() );
+      i = nextId + 1;
+    }
+  }
+  else {
+    QString modStr = resMgr->stringValue( "launch", "modules", QString::null );
+    modList = QStringList::split( ",", modStr );
+  }
 
   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
   {
@@ -481,12 +513,4 @@ void CAM_Application::createEmptyStudy()
   SUIT_Study* study = activeStudy();
 
   STD_Application::createEmptyStudy();
-
-  SUIT_Study* newStudy = activeStudy();
-  if ( study != newStudy ) 
-  {
-    CAM_Study* camStudy = dynamic_cast<CAM_Study*>( newStudy );
-    for ( ModuleListIterator it( myModules ); it.current(); ++it )
-      camStudy->insertDataModel( it.current()->dataModel() );
-  }
 }