+// 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"
#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 ),
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 )
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;
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 );
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();
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 ) )
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 )
}
}
+/*!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() )
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() )
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() )
return true;
if ( myModule )
- myModule->deactivateModule( activeStudy() );
-
+ {
+ if ( !myModule->deactivateModule( activeStudy() ) )
+ {
+ // ....
+ }
+ }
myModule = 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 );
+ myModule->setToolShown( false );
+ SUIT_MessageBox::error1( desktop(), tr( "ERROR_TLT" ), tr( "ERROR_ACTIVATE_MODULE_MSG" ).arg( myModule->moduleName() ), tr( "BUT_OK" ) );
+ myModule = 0;
+ return false;
}
- myModule->activateModule( activeStudy() );
}
updateCommandsStatus();
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();
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() );
// 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;
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;
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;
return res;
}
+/*!Read modules list*/
void CAM_Application::readModuleList()
{
if ( !myInfoList.isEmpty() )
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 )
{
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();
+}