Salome HOME
Copyrights update
[modules/gui.git] / src / CAM / CAM_Application.cxx
index f8ca14f3b13b36336438e7ea4f1dc52ea9f6a8da..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>
 #include <dlfcn.h>
 #endif
 
+/*!Create new instance of CAM_Application*/
 extern "C" CAM_EXPORT SUIT_Application* createApplication()
 {
   return new CAM_Application();
 }
 
+/*!Constructor. read module list.
+ * \param autoLoad - auto load flag.
+ */
 CAM_Application::CAM_Application( const bool autoLoad )
 : STD_Application(),
 myModule( 0 ),
@@ -32,10 +55,14 @@ myAutoLoad( autoLoad )
   readModuleList();
 }
 
+/*!Destructor. Do nothing.*/
 CAM_Application::~CAM_Application()
 {
 }
 
+/*! Load modules, if \a myAutoLoad flag is true.\n
+ * Start application - call start() method from parent class.
+ */
 void CAM_Application::start()
 {
   if ( myAutoLoad )
@@ -44,11 +71,17 @@ void CAM_Application::start()
   STD_Application::start();
 }
 
+/*!Get active module.
+ * \retval CAM_Module - active module.
+ */
 CAM_Module* CAM_Application::activeModule() const
 {
   return myModule;
 }
 
+/*!Get module with name \a modName from modules list.
+ * \retval CAM_Module pointer - module.
+ */
 CAM_Module* CAM_Application::module(  const QString& modName ) const
 {
   CAM_Module* mod = 0;
@@ -58,11 +91,15 @@ CAM_Module* CAM_Application::module(  const QString& modName ) const
   return mod;
 }
 
+/*!Gets modules iterator.*/
 CAM_Application::ModuleListIterator CAM_Application::modules() const
 {
   return ModuleListIterator( myModules );
 }
 
+/*!Gets modules list.
+ * \param out - output list of modules.
+ */
 void CAM_Application::modules( CAM_Application::ModuleList& out ) const
 {
   out.setAutoDelete( false );
@@ -72,6 +109,12 @@ void CAM_Application::modules( CAM_Application::ModuleList& out ) const
     out.append( it.current() );
 }
 
+/*!Gets list of names for modules.\n
+ * Get loaded modules names, if \a loaded is true, else \n
+ * get names from information list.
+ * \param lst - output list of names.
+ * \param loaded - boolean flag.
+ */
 void CAM_Application::modules( QStringList& lst, const bool loaded ) const
 {
   lst.clear();
@@ -84,6 +127,9 @@ void CAM_Application::modules( QStringList& lst, const bool loaded ) const
       lst.append( (*it).title );
 }
 
+/*!Adding module \a mod to list.
+ *\param mod - module.
+ */
 void CAM_Application::addModule( CAM_Module* mod )
 {
   if ( !mod || myModules.contains( mod ) )
@@ -122,6 +168,9 @@ void CAM_Application::addModule( CAM_Module* mod )
   moduleAdded( mod );
 }
 
+/*!Load modules from information list.
+ * \warning If some of modules not loaded, error message appear on desktop.
+ */
 void CAM_Application::loadModules()
 {
   for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end(); ++it )
@@ -135,6 +184,12 @@ void CAM_Application::loadModules()
   }
 }
 
+/*!Load module with name \a modName.
+ *\param modName - module name for loading.
+ *\warning If information list is empty.
+ *\warning If module library (for module with \a modName) is empty.
+ *\warning If module library is not loaded.
+ */
 CAM_Module* CAM_Application::loadModule( const QString& modName )
 {
   if ( myInfoList.isEmpty() )
@@ -200,6 +255,12 @@ CAM_Module* CAM_Application::loadModule( const QString& modName )
   return module;
 }
 
+/**@name Activate module group.*/
+//@{
+/*!Activate module with name \a modName.
+ *\param modName - module name.
+ *\ratval true, if module loaded and activated successful, else false.
+ */
 bool CAM_Application::activateModule( const QString& modName )
 {
   if ( !modName.isEmpty() && !activeStudy() )
@@ -224,6 +285,11 @@ bool CAM_Application::activateModule( const QString& modName )
   return res;
 }
 
+/*!Activate module \a mod
+ *\param mod - module for activation.
+ *\retval true - if all sucessful.
+ *\warning Error message if module not activated in active study.
+ */
 bool CAM_Application::activateModule( CAM_Module* mod )
 {
   if ( mod && !activeStudy() )
@@ -243,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 );
@@ -271,12 +324,17 @@ bool CAM_Application::activateModule( CAM_Module* mod )
 
   return true;
 }
+//@}
 
+/*!Create new study for current application.
+ *\retval study pointer.
+ */
 SUIT_Study* CAM_Application::createNewStudy() 
 { 
   return new CAM_Study( this );
 }
 
+/*!Update commands status for parent class and for current class(if module is active)*/
 void CAM_Application::updateCommandsStatus()
 {
   STD_Application::updateCommandsStatus();
@@ -285,17 +343,24 @@ void CAM_Application::updateCommandsStatus()
     activeModule()->updateCommandsStatus();
 }
 
+/*!Close all modules in study \a theDoc.
+ *\param theDoc - study
+ */
 void CAM_Application::beforeCloseDoc( SUIT_Study* theDoc )
 {
   for ( ModuleListIterator it( myModules ); it.current(); ++it )
     it.current()->studyClosed( theDoc );
 }
 
+/*!Sets active study for parent class.
+ *\param study - study.
+ */
 void CAM_Application::setActiveStudy( SUIT_Study* study )
 {
   STD_Application::setActiveStudy( study );
 }
 
+/*!Do nothing.*/
 void CAM_Application::moduleAdded( CAM_Module* mod )
 {
 //  CAM_Study* study = dynamic_cast<CAM_Study*>( activeStudy() );
@@ -305,6 +370,10 @@ void CAM_Application::moduleAdded( CAM_Module* mod )
 //  study->insertDataModel( mod->dataModel() );
 }
 
+/*!Gets module name by title \a title
+ *\param title - title name
+ *\retval QString module name.
+ */
 QString CAM_Application::moduleName( const QString& title ) const
 {
   QString res;
@@ -316,6 +385,10 @@ QString CAM_Application::moduleName( const QString& title ) const
   return res;
 }
 
+/*!Gets module title by module name \a name
+ *\param name - module name
+ *\retval QString module title.
+ */
 QString CAM_Application::moduleTitle( const QString& name ) const
 {
   QString res;
@@ -327,6 +400,11 @@ QString CAM_Application::moduleTitle( const QString& name ) const
   return res;
 }
 
+/*!Get library name for module with title \a title.
+ *\param title - module title name.
+ *\param full  - boolean flag (if true - return full library name, else internal name)
+ *\retval QString - library name.
+ */
 QString CAM_Application::moduleLibrary( const QString& title, const bool full ) const
 {
   QString res;
@@ -340,6 +418,7 @@ QString CAM_Application::moduleLibrary( const QString& title, const bool full )
   return res;
 }
 
+/*!Read modules list*/
 void CAM_Application::readModuleList()
 {
   if ( !myInfoList.isEmpty() )
@@ -347,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 )
   {
@@ -390,9 +495,22 @@ void CAM_Application::readModuleList()
     SUIT_MessageBox::error1( 0, tr( "Error" ), tr( "Can not load modules configuration file " ), tr( "Ok" ) );
 }
 
+/*!Add common items for popup menu ( if they are exist )
+ *\param type - type of popup menu
+ *\param thePopup - popup menu
+ *\param title - title of popup menu
+ */
 void CAM_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
 {
   // to do : add common items for popup menu ( if they are exist )
   if ( activeModule() ) 
     activeModule()->contextMenuPopup( type, thePopup, title );
 }
+
+/*!Create empty study.*/
+void CAM_Application::createEmptyStudy()
+{
+  SUIT_Study* study = activeStudy();
+
+  STD_Application::createEmptyStudy();
+}