From: nds Date: Thu, 3 Nov 2005 07:23:45 +0000 (+0000) Subject: Has functionality from SalomeApp without dependency from CORBA X-Git-Tag: V3_1_0a3~81 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=642cc0c19c61be7fde4b0574db044d6551d139e9;p=modules%2Fgui.git Has functionality from SalomeApp without dependency from CORBA --- diff --git a/src/LightApp/LightApp.h b/src/LightApp/LightApp.h new file mode 100644 index 000000000..bfbe7e24a --- /dev/null +++ b/src/LightApp/LightApp.h @@ -0,0 +1,28 @@ +// File: LightApp.h +// Created: June, 2005 +// Author: OCC team +// Copyright (C) CEA 2005 + + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the LightApp_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// LightApp_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. +#ifdef WNT + +#ifdef LIGHTAPP_EXPORTS +#define LIGHTAPP_EXPORT __declspec(dllexport) +#else +#define LIGHTAPP_EXPORT __declspec(dllimport) +#endif + +#else +#define LIGHTAPP_EXPORT +#endif //WNT + +#define APP_VERSION "0.1" + +#pragma warning ( disable:4251 ) +#pragma warning ( disable:4786 ) diff --git a/src/LightApp/LightApp_AboutDlg.cxx b/src/LightApp/LightApp_AboutDlg.cxx new file mode 100644 index 000000000..689d4165c --- /dev/null +++ b/src/LightApp/LightApp_AboutDlg.cxx @@ -0,0 +1,130 @@ +// File: LightApp_AboutDlg.cxx +// Created: 03.06.2005 13:52:45 +// Author: Sergey TELKOV +// Copyright (C) CEA 2005 + +#include "LightApp_AboutDlg.h" + +#include +#include + +#include +#include +#include +#include + +/*!Constructor.*/ +LightApp_AboutDlg::LightApp_AboutDlg( const QString& defName, const QString& defVer, QWidget* parent ) +: QtxDialog( parent, "salome_about_dialog", true, false, None ) +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + + QPixmap ico = resMgr->loadPixmap( "LightApp", tr( "ICO_ABOUT" ), false ); + if ( !ico.isNull() ) + setIcon( ico ); + + QPalette pal = palette(); + QColorGroup cg = pal.active(); + cg.setColor( QColorGroup::Foreground, Qt::darkBlue ); + cg.setColor( QColorGroup::Background, Qt::white ); + pal.setActive( cg ); pal.setInactive( cg ); pal.setDisabled( cg ); + setPalette(pal); + + QVBoxLayout* main = new QVBoxLayout( mainFrame() ); + QGroupBox* base = new QGroupBox( 1, Qt::Horizontal, "", mainFrame() ); + base->setFrameStyle( QFrame::NoFrame ); + base->setInsideMargin( 0 ); + main->addWidget( base ); + + QLabel* screen = new QLabel( base ); + screen->setScaledContents( true ); + screen->setAlignment( Qt::AlignCenter ); + screen->setFrameStyle( QFrame::Box | QFrame::Plain ); + + QLabel* title = new QLabel( base ); + title->setAlignment( Qt::AlignCenter ); + changeFont( title, true, false, false, 5 ); + + QLabel* version = new QLabel( base ); + version->setAlignment( Qt::AlignCenter ); + changeFont( version, false, true, false, 2 ); + + QLabel* copyright = new QLabel( base ); + copyright->setAlignment( Qt::AlignCenter ); + changeFont( copyright, false, false, false, 1 ); + + QLabel* license = new QLabel( base ); + license->setAlignment( Qt::AlignCenter ); + changeFont( license, false, false, false, 1 ); + + screen->setPixmap( resMgr->loadPixmap( "LightApp", tr( "ABOUT" ), false ) ); + checkLabel( screen ); + + QString titleText = tr( "ABOUT_TITLE" ); + if ( titleText == "ABOUT_TITLE" ) + titleText = defName; + title->setText( titleText ); + checkLabel( title ); + + QString verText = tr( "ABOUT_VERSION" ); + if ( verText.contains( "%1" ) ) + verText = verText.arg( defVer ); + version->setText( verText ); + checkLabel( version ); + + copyright->setText( tr( "ABOUT_COPYRIGHT" ) ); + checkLabel( copyright ); + + license->setText( tr( "ABOUT_LICENSE" ) ); + checkLabel( license ); + + QString capText = tr( "ABOUT_CAPTION" ); + if ( capText.contains( "%1" ) ) + capText = capText.arg( defName ); + setCaption( capText ); + + setSizeGripEnabled( false ); +} + +/*!Destructor.*/ +LightApp_AboutDlg::~LightApp_AboutDlg() +{ + //! Do nothing. +} + +/*!On mouse press event.*/ +void LightApp_AboutDlg::mousePressEvent( QMouseEvent* ) +{ + accept(); +} + +/*!Change font of widget \a wid. + *\param wid - QWidget + *\param bold - boolean value + *\param italic - boolean value + *\param underline - boolean value + *\param inc - integer increment for font point size. + */ +void LightApp_AboutDlg::changeFont( QWidget* wid, const bool bold, const bool italic, + const bool underline, const int inc ) const +{ + if ( !wid ) + return; + + QFont widFont = wid->font(); + widFont.setBold( bold ); + widFont.setItalic( italic ); + widFont.setUnderline( underline ); + widFont.setPointSize( widFont.pointSize() + inc ); +} + +/*!Check lable \a lab.*/ +void LightApp_AboutDlg::checkLabel( QLabel* lab ) const +{ + if ( !lab ) + return; + + bool vis = !lab->text().stripWhiteSpace().isEmpty() || + ( lab->pixmap() && !lab->pixmap()->isNull() ); + vis ? lab->show() : lab->hide(); +} diff --git a/src/LightApp/LightApp_AboutDlg.h b/src/LightApp/LightApp_AboutDlg.h new file mode 100644 index 000000000..c59cc938b --- /dev/null +++ b/src/LightApp/LightApp_AboutDlg.h @@ -0,0 +1,36 @@ +// File: LightApp_AboutDlg.h +// Created: 03.06.2005 13:49:25 +// Author: Sergey TELKOV +// Copyright (C) CEA 2005 + +#ifndef LIGHTAPP_ABOUTDLG_H +#define LIGHTAPP_ABOUTDLG_H + +#include "LightApp.h" + +#include + +/*! + Descr: LightApp help about dialog +*/ + +class QLabel; + +class LIGHTAPP_EXPORT LightApp_AboutDlg : public QtxDialog +{ + Q_OBJECT + +public: + LightApp_AboutDlg( const QString&, const QString&, QWidget* = 0 ); + virtual ~LightApp_AboutDlg(); + +protected: + virtual void mousePressEvent( QMouseEvent* ); + +private: + void checkLabel( QLabel* ) const; + void changeFont( QWidget*, const bool = false, const bool = false, + const bool = false, const int = 0 ) const; +}; + +#endif diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx new file mode 100644 index 000000000..2a7cce67f --- /dev/null +++ b/src/LightApp/LightApp_Application.cxx @@ -0,0 +1,1811 @@ +// File: LightApp_Application.cxx +// Created: 6/20/2005 18:39:45 PM +// Author: Natalia Donis +// Copyright (C) CEA 2005 + +#include "PythonConsole_PyInterp.h" // WARNING! This include must be the first! + +#include "LightApp_Application.h" +#include "LightApp_WidgetContainer.h" +#include "LightApp_Module.h" +#include "LightApp_DataModel.h" +#include "LightApp_Study.h" +#include "LightApp_Preferences.h" +#include "LightApp_PreferencesDlg.h" +#include "LightApp_ModuleDlg.h" +#include "LightApp_AboutDlg.h" + +#include "LightApp_OBFilter.h" + +#include "LightApp_GLSelector.h" +#include "LightApp_OBSelector.h" +#include "LightApp_OCCSelector.h" +#include "LightApp_VTKSelector.h" +#include "LightApp_SelectionMgr.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define OBJECT_BROWSER_WIDTH 300 +#define OBJECT_COLUMN_WIDTH 150 + +#define DEFAULT_BROWSER "mozilla" + +#define FIRST_HELP_ID 1000000 + +#include "SALOME_InteractiveObject.hxx" +#include "SALOME_ListIO.hxx" + +static const char* imageEmptyIcon[] = { +"20 20 1 1", +". c None", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"....................", +"...................."}; + +/*!Create new instance of LightApp_Application.*/ +extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication() +{ + return new LightApp_Application(); +} + +LightApp_Preferences* LightApp_Application::_prefs_ = 0; + +/* + Class : LightApp_Application + Description : Application containing LightApp module +*/ + +/*!Constructor.*/ +LightApp_Application::LightApp_Application() +: CAM_Application( false ), +myPrefs( 0 ) +{ + STD_TabDesktop* desk = new STD_TabDesktop(); + + setDesktop( desk ); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ); + + desktop()->setIcon( aLogo ); + desktop()->setDockableMenuBar( true ); + desktop()->setDockableStatusBar( false ); + + // base logo (salome itself) + desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) ); + // extra logo (salome-based application) + desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) ); + + clearViewManagers(); + + mySelMgr = new LightApp_SelectionMgr( this ); + + myAccel = new SUIT_Accel( desktop() ); + myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() ); + + connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) ); +} + +/*!Destructor. + *\li Save window geometry. + *\li Save desktop geometry. + *\li Save resource maneger. + *\li Delete selection manager. + */ +LightApp_Application::~LightApp_Application() +{ + saveWindowsGeometry(); + + if ( resourceMgr() ) + { + if ( desktop() ) + desktop()->saveGeometry( resourceMgr(), "desktop" ); + resourceMgr()->save(); + } + delete mySelMgr; +} + +/*!Start application.*/ +void LightApp_Application::start() +{ + if ( desktop() ) + desktop()->loadGeometry( resourceMgr(), "desktop" ); + + CAM_Application::start(); + + QAction* a = action( ViewWindowsId ); + if ( a && a->inherits( "QtxDockAction" ) ) + ((QtxDockAction*)a)->setAutoPlace( true ); + + updateWindows(); + updateViewManagers(); + + putInfo( "" ); + desktop()->statusBar()->message( "" ); +} + +/*!Gets application name.*/ +QString LightApp_Application::applicationName() const +{ + return tr( "APP_NAME" ); +} + +/*!Gets application version.*/ +QString LightApp_Application::applicationVersion() const +{ + static QString _app_version; + + if ( _app_version.isEmpty() ) + { + QString resVersion = tr( "APP_VERSION" ); + if ( resVersion != "APP_VERSION" ) + { + _app_version = resVersion; + } + else + { + QString path( ::getenv( "GUI_ROOT_DIR" ) ); + if ( !path.isEmpty() ) + path += QDir::separator(); + path += QString( "bin/salome/VERSION" ); + + QFile vf( path ); + if ( vf.open( IO_ReadOnly ) ) + { + QString line; + vf.readLine( line, 1024 ); + vf.close(); + + if ( !line.isEmpty() ) + { + while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) ) + line.remove( line.length() - 1, 1 ); + + int idx = line.findRev( ":" ); + if ( idx != -1 ) + _app_version = line.mid( idx + 1 ).stripWhiteSpace(); + } + } + } + } + return _app_version; +} + +/*!Load module by \a name.*/ +CAM_Module* LightApp_Application::loadModule( const QString& name ) +{ + CAM_Module* mod = CAM_Application::loadModule( name ); + if ( mod ) + { + connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) ); + connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) ); + connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) ); + } + return mod; +} + +/*!Activate module by \a modName*/ +bool LightApp_Application::activateModule( const QString& modName ) +{ + QString actName; + CAM_Module* prevMod = activeModule(); + + if ( prevMod ) + actName = prevMod->moduleName(); + + if ( actName == modName ) + return true; + + putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) ); + + saveWindowsGeometry(); + + bool status = CAM_Application::activateModule( modName ); + + updateModuleActions(); + + putInfo( "" ); + + if ( !status ) + return false; + + updateWindows(); + updateViewManagers(); + + return true; +} + +bool LightApp_Application::useStudy(const QString& theName) +{ + createEmptyStudy(); + LightApp_Study* aStudy = dynamic_cast(activeStudy()); + bool res = false; + if (aStudy) + res = aStudy->loadDocument( theName ); + updateDesktopTitle(); + updateCommandsStatus(); + return res; +} + +/*!Gets selection manager.*/ +LightApp_SelectionMgr* LightApp_Application::selectionMgr() const +{ + return mySelMgr; +} + +/*!Create actions:*/ +void LightApp_Application::createActions() +{ + STD_Application::createActions(); + + SUIT_Desktop* desk = desktop(); + SUIT_ResourceMgr* resMgr = resourceMgr(); + + //! Preferences + createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(), + tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ), + CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) ); + + //! Help for modules + int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 ); + int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 ); + createMenu( separator(), helpMenu, -1, 1 ); + + QStringList aModuleList; + modules( aModuleList, false ); + + int id = LightApp_Application::UserID + FIRST_HELP_ID; + // help for KERNEL and GUI + QCString dir; + QAction* a; + if (dir = getenv("GUI_ROOT_DIR")) { + a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(), + tr( QString("Kernel && GUI Help") ), + tr( QString("Kernel & GUI Help") ), + 0, desk, false, this, SLOT( onHelpContentsModule() ) ); + a->setName( QString("GUI") ); + createMenu( a, helpModuleMenu, -1 ); + id++; + } + // help for other existing modules + for ( QStringList::Iterator it = aModuleList.begin(); it != aModuleList.end(); ++it ) + { + if ( (*it).isEmpty() ) + continue; + + QString modName = moduleName( *it ); + if ( modName.compare("GEOM") == 0 ) { // to be removed when documentation for other modules will be done + QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(), + tr( moduleTitle(modName) + QString(" Help") ), + tr( moduleTitle(modName) + QString(" Help") ), + 0, desk, false, this, SLOT( onHelpContentsModule() ) ); + a->setName( modName ); + createMenu( a, helpModuleMenu, -1 ); + id++; + } + } + + //! MRU + QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk ); + connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) ); + registerAction( MRUId, mru ); + + // default icon for neutral point ('SALOME' module) + QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ); + if ( defIcon.isNull() ) + defIcon = QPixmap( imageEmptyIcon ); + + //! default icon for any module + QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false ); + if ( modIcon.isNull() ) + modIcon = QPixmap( imageEmptyIcon ); + + QToolBar* modTBar = new QtxToolBar( true, desk ); + modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) ); + + QActionGroup* modGroup = new QActionGroup( this ); + modGroup->setExclusive( true ); + modGroup->setUsesDropDown( true ); + + a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ), + tr( "PRP_APP_MODULE" ), 0, desk, true ); + modGroup->add( a ); + myActions.insert( QString(), a ); + + QMap iconMap; + moduleIconNames( iconMap ); + + const int iconSize = 20; + + modGroup->addTo( modTBar ); + modTBar->addSeparator(); + + QStringList modList; + modules( modList, false ); + + for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it ) + { + if ( (*it).isEmpty() ) + continue; + + QString iconName; + if ( iconMap.contains( *it ) ) + iconName = iconMap[*it]; + + QString modName = moduleName( *it ); + + QPixmap icon = resMgr->loadPixmap( modName, iconName, false ); + if ( icon.isNull() ) + icon = modIcon; + + icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) ); + + QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true ); + a->addTo( modTBar ); + modGroup->add( a ); + + myActions.insert( *it, a ); + } + + SUIT_Tools::simplifySeparators( modTBar ); + + // New window + int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 ); + int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 ); + createMenu( separator(), windowMenu, -1, 1 ); + + QMap accelMap; + accelMap[NewGLViewId] = ALT+Key_G; + accelMap[NewPlot2dId] = ALT+Key_P; + accelMap[NewOCCViewId] = ALT+Key_O; + accelMap[NewVTKViewId] = ALT+Key_K; + + for ( int id = NewGLViewId; id <= NewVTKViewId; id++ ) + { + QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(), + tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), + tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), + accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) ); + createMenu( a, newWinMenu, -1 ); + } + + connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) ); + + int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); + createMenu( PreferencesId, fileMenu, 15, -1 ); + createMenu( separator(), fileMenu, -1, 15, -1 ); + + /* + createMenu( separator(), fileMenu, -1, 100, -1 ); + createMenu( MRUId, fileMenu, 100, -1 ); + createMenu( separator(), fileMenu, -1, 100, -1 ); + */ +} + +/*!On module activation action.*/ +void LightApp_Application::onModuleActivation( QAction* a ) +{ + if ( !a ) + return; + + QString modName = a->menuText(); + if ( modName == tr( "APP_NAME" ) ) + modName = QString::null; + + // Force user to create/open a study before module activation + QMap iconMap; + moduleIconNames( iconMap ); + QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false ); + if ( icon.isNull() ) + icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module + + bool cancelled = false; + while ( !modName.isEmpty() && !activeStudy() && !cancelled ){ + LightApp_ModuleDlg aDlg( desktop(), modName, icon ); + int res = aDlg.exec(); + + switch ( res ){ + case 1: + onNewDoc(); + break; + case 2: + onOpenDoc(); + break; + case 3: + //onLoadStudy(); + //break; + case 0: + default: + putInfo( tr("INF_CANCELLED") ); + myActions[QString()]->setOn( true ); + cancelled = true; + } + } + + if ( !cancelled ) + activateModule( modName ); +} + +/*!Default module activation.*/ +QString LightApp_Application::defaultModule() const +{ + QStringList aModuleNames; + modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration + //! If there's the one and only module --> activate it automatically + //! TODO: Possible improvement - default module can be taken from preferences + return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" ); +} + +/*!On new window slot.*/ +void LightApp_Application::onNewWindow() +{ + const QObject* obj = sender(); + if ( !obj || !obj->inherits( "QAction" ) ) + return; + + QString type; + int id = actionId( (QAction*)obj ); + switch ( id ) + { + case NewGLViewId: + type = GLViewer_Viewer::Type(); + break; + case NewPlot2dId: + type = Plot2d_Viewer::Type(); + break; + case NewOCCViewId: + type = OCCViewer_Viewer::Type(); + break; + case NewVTKViewId: + type = VTKViewer_Viewer::Type(); + break; + } + + if ( !type.isEmpty() ) + createViewManager( type ); +} + +//======================================================================= +// name : onNewDoc +/*! Purpose : SLOT. Create new document*/ +//======================================================================= +void LightApp_Application::onNewDoc() +{ + SUIT_Study* study = activeStudy(); + + saveWindowsGeometry(); + + CAM_Application::onNewDoc(); + + if ( !study ) // new study will be create in THIS application + { + updateWindows(); + updateViewManagers(); + } +} + +//======================================================================= +// name : onOpenDoc +/*! Purpose : SLOT. Open new document*/ +//======================================================================= +void LightApp_Application::onOpenDoc() +{ + SUIT_Study* study = activeStudy(); + saveWindowsGeometry(); + + CAM_Application::onOpenDoc(); + + if ( !study ) // new study will be create in THIS application + { + updateWindows(); + updateViewManagers(); + } +} + +#include "SUIT_MessageBox.h" +/*! Purpose : SLOT. Open new document with \a aName.*/ +bool LightApp_Application::onOpenDoc( const QString& aName ) +{ + bool isAlreadyOpen = false; + + // Look among opened studies + if (activeStudy()) { // at least one study is opened + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList aAppList = aSession->applications(); + QPtrListIterator it (aAppList); + SUIT_Application* aApp = 0; + // iterate on all applications + for (; (aApp = it.current()) && !isAlreadyOpen; ++it) { + if (aApp->activeStudy()->studyName() == aName) { + isAlreadyOpen = true; // Already opened, ask user what to do + + // The document ... is already open. + // Do you want to reload it? + int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"), + tr("QUE_DOC_ALREADYOPEN").arg(aName), + tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2); + if (aAnswer == 1) { // reload + if (activeStudy()->studyName() == aName && aAppList.count() > 1) { + // Opened in THIS (active) application. + STD_Application* app1 = (STD_Application*)aAppList.at(0); + STD_Application* app2 = (STD_Application*)aAppList.at(1); + if (!app1 || !app2) { + // Error + return false; + } + if (app1->activeStudy()->studyName() == aName) { + // app1 is this application, we need another one + app1 = app2; + } + // Close document of this application. This application will be destroyed. + onCloseDoc(/*ask = */false); + // Open the file with another application, as this one will be destroyed. + return app1->onOpenDoc(aName); + } else { + // Opened in another application. + STD_Application* app = (STD_Application*)aApp; + if (app) + app->onCloseDoc(/*ask = */false); + } + } else { // do not reload + // OK, the study will not be reloaded, but we call + // CAM_Application::onOpenDoc( aName ) all the same. + // It will activate a desktop of the study . + } + } + } + } + + bool res = CAM_Application::onOpenDoc( aName ); + + QAction* a = action( MRUId ); + if ( a && a->inherits( "QtxMRUAction" ) ) + { + QtxMRUAction* mru = (QtxMRUAction*)a; + if ( res ) + mru->insert( aName ); + else + mru->remove( aName ); + } + return res; +} + +//======================================================================= +// name : onHelpAbout +/*! Purpose : SLOT. Display "About" message box*/ +//======================================================================= +void LightApp_Application::onHelpAbout() +{ + LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() ); + dlg->exec(); + delete dlg; +} + +/*!SLOT. Load document with \a aName.*/ +bool LightApp_Application::onLoadDoc( const QString& aName ) +{ + bool res = CAM_Application::onLoadDoc( aName ); + + /*jfa tmp:QAction* a = action( MRUId ); + if ( a && a->inherits( "QtxMRUAction" ) ) + { + QtxMRUAction* mru = (QtxMRUAction*)a; + if ( res ) + mru->insert( aName ); + else + mru->remove( aName ); + }*/ + return res; +} + +/*!Private SLOT. Selection.*/ +void LightApp_Application::onSelection() +{ + onSelectionChanged(); + + if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) ) + ((LightApp_Module*)activeModule())->selectionChanged(); +} + +/*!Set active study. + *\param study - SUIT_Study. + */ +void LightApp_Application::setActiveStudy( SUIT_Study* study ) +{ + CAM_Application::setActiveStudy( study ); + + activateWindows(); +} + +//======================================================================= +// name : updateCommandsStatus +/*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/ +//======================================================================= +void LightApp_Application::updateCommandsStatus() +{ + CAM_Application::updateCommandsStatus(); + + for ( int id = NewGLViewId; id <= NewVTKViewId; id++ ) + { + QAction* a = action( id ); + if ( a ) + a->setEnabled( activeStudy() ); + } +} + +// Helps to execute command +class RunBrowser: public QThread { +public: + + RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL): + myApp(theApp), myParams(theParams), myHelpFile("file:" + theHelpFile + theContext), myStatus(0) {}; + + virtual void run() + { + QString aCommand; + + if ( !myApp.isEmpty()) + { + aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1()); + myStatus = system(aCommand); + if(myStatus != 0) + { + QCustomEvent* ce2000 = new QCustomEvent (2000); + postEvent (qApp, ce2000); + } + } + + if( myStatus != 0 || myApp.isEmpty()) + { + myParams = ""; + aCommand.sprintf("%s %s %s", QString(DEFAULT_BROWSER).latin1(),myParams.latin1(), myHelpFile.latin1()); + myStatus = system(aCommand); + if(myStatus != 0) + { + QCustomEvent* ce2001 = new QCustomEvent (2001); + postEvent (qApp, ce2001); + } + } + } + +private: + QString myApp; + QString myParams; + QString myHelpFile; + int myStatus; + +}; + +//======================================================================= +// name : onHelpContentsModule +/*! Purpose : SLOT. Display help contents for choosen module*/ +//======================================================================= +void LightApp_Application::onHelpContentsModule() +{ + const QAction* obj = (QAction*) sender(); + + QString aComponentName = obj->name(); + QString aFileName = aComponentName.lower() + ".htm"; + + QCString dir; + QString root; + QString homeDir; + if (dir = getenv( aComponentName + "_ROOT_DIR")) { + root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") + Qtx::addSlash(aComponentName)); + if ( QFileInfo( root + aFileName ).exists() ) { + homeDir = root; + } else { + SUIT_MessageBox::warn1( desktop(), tr("WRN_WARNING"), + QString( "%1"+ aFileName + " doesn't exist." ).arg(root), tr ("BUT_OK") ); + return; + } + } + + QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath(); + SUIT_ResourceMgr* resMgr = resourceMgr(); + QString anApp = resMgr->stringValue("ExternalBrowser", "application"); + QString aParams = resMgr->stringValue("ExternalBrowser", "parameters"); + + RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile); + rs->start(); +} + +/*!Sets enable or disable some actions on selection changed.*/ +void LightApp_Application::onSelectionChanged() +{ +} + +/*!Return window. + *\param flag - key for window + *\param studyId - study id + * Flag used how identificator of window in windows list. + */ +QWidget* LightApp_Application::window( const int flag, const int studyId ) const +{ + QWidget* wid = 0; + + int sId = studyId; + if ( sId < 0 ) + { + if ( !activeStudy() ) + return 0; + else + sId = activeStudy()->id(); + } + + if ( myWindows.contains( flag ) ) + wid = myWindows[flag]->widget( sId ); + + return wid; +} + +/*!Adds window to application. + *\param wid - QWidget + *\param flag - key wor window + *\param studyId - study id + * Flag used how identificator of window in windows list. + */ +void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId ) +{ + if ( !wid ) + return; + + int sId = studyId; + if ( sId < 0 ) + { + if ( !activeStudy() ) + return; + else + sId = activeStudy()->id(); + } + + if ( !myWindows.contains( flag ) ) + { + QMap winMap; + currentWindows( winMap ); + + myWindows.insert( flag, new LightApp_WidgetContainer( flag, desktop() ) ); + if ( winMap.contains( flag ) ) + desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] ); + + myWindows[flag]->setResizeEnabled( true ); + myWindows[flag]->setCloseMode( QDockWindow::Always ); + myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) ); + } + + QFont f; + if( wid->inherits( "PythonConsole" ) ) + f = ( ( PythonConsole* )wid )->font(); + else + f = wid->font(); + + myWindows[flag]->insert( sId, wid ); + wid->setFont(f); + + setWindowShown( flag, !myWindows[flag]->isEmpty() ); +} + +/*!Remove window from application. + *\param flag - key wor window + *\param studyId - study id + * Flag used how identificator of window in windows list. + */ +void LightApp_Application::removeWindow( const int flag, const int studyId ) +{ + if ( !myWindows.contains( flag ) ) + return; + + int sId = studyId; + if ( sId < 0 ) + { + if ( !activeStudy() ) + return; + else + sId = activeStudy()->id(); + } + + QWidget* wid = myWindows[flag]->widget( sId ); + myWindows[flag]->remove( sId ); + delete wid; + + setWindowShown( flag, !myWindows[flag]->isEmpty() ); +} + +/*!Gets window. + *\param flag - key wor window + *\param studyId - study id + * Flag used how identificator of window in windows list. + */ +QWidget* LightApp_Application::getWindow( const int flag, const int studyId ) +{ + QWidget* wid = window( flag, studyId ); + if ( !wid ) + addWindow( wid = createWindow( flag ), flag, studyId ); + + return wid; +} + +/*!Check is window visible?(with identificator \a type)*/ +bool LightApp_Application::isWindowVisible( const int type ) const +{ + bool res = false; + if ( myWindows.contains( type ) ) + { + SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop(); + res = desk && desk->appropriate( myWindows[type] ); + } + return res; +} + +/*!Sets window show or hide. + *\param type - window identificator. + *\param on - true/false (window show/hide) + */ +void LightApp_Application::setWindowShown( const int type, const bool on ) +{ + if ( !desktop() || !myWindows.contains( type ) ) + return; + + QDockWindow* dw = myWindows[type]; + desktop()->setAppropriate( dw, on ); + on ? dw->show() : dw->hide(); +} + +/*!Gets "ObjectBrowser".*/ +OB_Browser* LightApp_Application::objectBrowser() +{ + OB_Browser* ob = 0; + QWidget* wid = getWindow( WT_ObjectBrowser ); + if ( wid->inherits( "OB_Browser" ) ) + ob = (OB_Browser*)wid; + return ob; +} + +/*!Gets "LogWindow".*/ +LogWindow* LightApp_Application::logWindow() +{ + LogWindow* lw = 0; + QWidget* wid = getWindow( WT_LogWindow ); + if ( wid->inherits( "LogWindow" ) ) + lw = (LogWindow*)wid; + return lw; +} + +/*!Get "PythonConsole"*/ +PythonConsole* LightApp_Application::pythonConsole() +{ + PythonConsole* console = 0; + QWidget* wid = getWindow( WT_PyConsole ); + if ( wid->inherits( "PythonConsole" ) ) + console = (PythonConsole*)wid; + return console; +} + +/*!Update obect browser*/ +void LightApp_Application::updateObjectBrowser( const bool updateModels ) +{ + // update existing data models + if ( updateModels ) + { + LightApp_Study* study = dynamic_cast(activeStudy()); + if ( study ) { + CAM_Study::ModelList dm_list; + study->dataModels( dm_list ); + for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) { + CAM_DataModel* camDM = it.current(); + if ( camDM && camDM->inherits( "LightApp_DataModel" ) ) + ((LightApp_DataModel*)camDM)->update(); + } + } + } + if ( objectBrowser() ) + { + objectBrowser()->updateGeometry(); + objectBrowser()->updateTree(); + } +} + +/*!Gets preferences.*/ +LightApp_Preferences* LightApp_Application::preferences() const +{ + return preferences( false ); +} + +/*!Gets view manager*/ +SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create ) +{ + SUIT_ViewManager* aVM = viewManager( vmType ); + SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager(); + + if ( anActiveVM && anActiveVM->getType() == vmType ) + aVM = anActiveVM; + + if ( aVM && create ) + { + if ( !aVM->getActiveView() ) + aVM->createView(); + else + aVM->getActiveView()->setFocus(); + } + else if ( create ) + aVM = createViewManager( vmType ); + + return aVM; +} + +/*!Create view manager.*/ +SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType ) +{ + SUIT_ResourceMgr* resMgr = resourceMgr(); + + SUIT_ViewManager* viewMgr = 0; + if ( vmType == GLViewer_Viewer::Type() ) + { + viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() ); + new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr ); + } + else if ( vmType == Plot2d_Viewer::Type() ) + { + viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() ); + viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface + } + else if ( vmType == OCCViewer_Viewer::Type() ) + { + viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() ); + SOCC_Viewer* vm = new SOCC_Viewer(); + vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) ); + vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) ); + int u( 1 ), v( 1 ); + vm->isos( u, v ); + u = resMgr->integerValue( "OCCViewer", "iso_number_u", u ); + v = resMgr->integerValue( "OCCViewer", "iso_number_v", v ); + vm->setIsos( u, v ); + viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface + new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr ); + } + else if ( vmType == SVTK_Viewer::Type() ) + { + viewMgr = new SVTK_ViewManager( activeStudy(), desktop() ); + SVTK_Viewer* vm = dynamic_cast( viewMgr->getViewModel() ); + if( vm ) + { + vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) ); + vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) ); + new LightApp_VTKSelector( vm, mySelMgr ); + } + } + + if ( !viewMgr ) + return 0; + + addViewManager( viewMgr ); + SUIT_ViewWindow* viewWin = viewMgr->createViewWindow(); + + if ( viewWin && desktop() ) + viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) ); + + connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), + this, SLOT( onCloseView( SUIT_ViewManager* ) ) ); + + return viewMgr; +} + +//======================================================================= +// name : onCloseView +/*! Purpose : SLOT. Remove view manager from application*/ +//======================================================================= +void LightApp_Application::onCloseView( SUIT_ViewManager* theVM ) +{ + removeViewManager( theVM ); +} + +/*!Protected SLOT. On study created.*/ +void LightApp_Application::onStudyCreated( SUIT_Study* theStudy ) +{ + SUIT_DataObject* aRoot = 0; + if ( theStudy && theStudy->root() ) + { + aRoot = theStudy->root(); + //aRoot->setName( tr( "DATA_MODELS" ) ); + } + if ( objectBrowser() != 0 ) + objectBrowser()->setRootObject( aRoot ); + + activateModule( defaultModule() ); + + activateWindows(); +} + +/*!Protected SLOT. On study opened.*/ +void LightApp_Application::onStudyOpened( SUIT_Study* theStudy ) +{ + SUIT_DataObject* aRoot = 0; + if ( theStudy && theStudy->root() ) + { + aRoot = theStudy->root(); + //aRoot->dump(); + } + if ( objectBrowser() != 0 ) { + objectBrowser()->setRootObject( aRoot ); + } + + activateModule( defaultModule() ); + + activateWindows(); + + emit studyOpened(); +} + +/*!Protected SLOT. On study saved.*/ +void LightApp_Application::onStudySaved( SUIT_Study* ) +{ + emit studySaved(); +} + +/*!Protected SLOT. On study closed.*/ +void LightApp_Application::onStudyClosed( SUIT_Study* ) +{ + emit studyClosed(); + + activateModule( "" ); + + // Bug 10396: remove all selectors + delete mySelMgr; + mySelMgr = new LightApp_SelectionMgr( this ); + + saveWindowsGeometry(); +} + +/*!Protected SLOT.On desktop activated.*/ +void LightApp_Application::onDesktopActivated() +{ + CAM_Application::onDesktopActivated(); + LightApp_Module* aModule = dynamic_cast(activeModule()); + if(aModule) + aModule->studyActivated(); +} + +/*!Gets file filter. + *\retval QString "(*.bin)" + */ +QString LightApp_Application::getFileFilter() const +{ + return "(*.bin)"; +} + +/*! Gets file name*/ +QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ) +{ + if ( !parent ) + parent = desktop(); + QStringList fls = QStringList::split( ";;", filters, false ); + return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true ); +} + +/*! Gets directory*/ +QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent ) +{ + if ( !parent ) + parent = desktop(); + return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true ); +} + +/*! Get open file names*/ +QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ) +{ + if ( !parent ) + parent = desktop(); + QStringList fls = QStringList::split( ";;", filters, false ); + return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true ); +} + +/*!Private SLOT. Update object browser.*/ +void LightApp_Application::onRefresh() +{ + updateObjectBrowser( true ); +} + +/*!Private SLOT. On preferences.*/ +void LightApp_Application::onPreferences() +{ + QApplication::setOverrideCursor( Qt::waitCursor ); + + LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop()); + + QApplication::restoreOverrideCursor(); + + if ( !prefDlg ) + return; + + prefDlg->exec(); + + delete prefDlg; +} + +/*!Protected SLOT. On preferences changed.*/ +void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param ) +{ + LightApp_Module* sMod = 0; + CAM_Module* mod = module( modName ); + if ( mod && mod->inherits( "LightApp_Module" ) ) + sMod = (LightApp_Module*)mod; + + if ( sMod ) + sMod->preferencesChanged( section, param ); + else + preferencesChanged( section, param ); +} + +/*!Private SLOT. On open document with name \a aName.*/ +void LightApp_Application::onMRUActivated( QString aName ) +{ + onOpenDoc( aName ); +} + +/*!Remove all windows from study.*/ +void LightApp_Application::beforeCloseDoc( SUIT_Study* s ) +{ + CAM_Application::beforeCloseDoc( s ); + + for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr ) + removeWindow( itr.key(), s->id() ); +} + +/*!Update actions.*/ +void LightApp_Application::updateActions() +{ + updateCommandsStatus(); +} + +//======================================================================= +// name : createNewStudy +/*! Purpose : Create new study*/ +//======================================================================= +SUIT_Study* LightApp_Application::createNewStudy() +{ + LightApp_Study* aStudy = new LightApp_Study( this ); + + // Set up processing of major study-related events + connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) ); + connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) ); + connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) ); + connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) ); + + return aStudy; +} + +/*!Create window.*/ +QWidget* LightApp_Application::createWindow( const int flag ) +{ + QWidget* wid = 0; + if ( flag == WT_ObjectBrowser ) + { + OB_Browser* ob = new OB_Browser( desktop() ); + ob->setAutoUpdate( true ); + ob->setAutoOpenLevel( 1 ); + ob->setCaption( tr( "OBJECT_BROWSER" ) ); + ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH ); + ob->resize( OBJECT_BROWSER_WIDTH, ob->height() ); + ob->setFilter( new LightApp_OBFilter( selectionMgr() ) ); + + ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) ); + + // Create OBSelector + new LightApp_OBSelector( ob, mySelMgr ); + + wid = ob; + + ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + } + else if ( flag == WT_PyConsole ) + { + PythonConsole* pyCons = new PythonConsole( desktop() ); + pyCons->setCaption( tr( "PYTHON_CONSOLE" ) ); + wid = pyCons; + // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + } + else if ( flag == WT_LogWindow ) + { + LogWindow* logWin = new LogWindow( desktop() ); + logWin->setCaption( tr( "LOG_WINDOW" ) ); + wid = logWin; + logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + } + return wid; +} + +/*!Default windows(Object Browser, Python Console). + * Adds to map \a aMap. + */ +void LightApp_Application::defaultWindows( QMap& aMap ) const +{ + aMap.insert( WT_ObjectBrowser, Qt::DockLeft ); + aMap.insert( WT_PyConsole, Qt::DockBottom ); + // aMap.insert( WT_LogWindow, Qt::DockBottom ); +} + +/*!Default view manager.*/ +void LightApp_Application::defaultViewManagers( QStringList& ) const +{ + /*!Do nothing.*/ +} + +/*!Gets preferences. + * Create preferences, if \a crt = true. + */ +LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const +{ + if ( myPrefs ) + return myPrefs; + + LightApp_Application* that = (LightApp_Application*)this; + + if ( !_prefs_ && crt ) + { + _prefs_ = new LightApp_Preferences( resourceMgr() ); + that->createPreferences( _prefs_ ); + } + + that->myPrefs = _prefs_; + + QPtrList appList = SUIT_Session::session()->applications(); + for ( QPtrListIterator appIt ( appList ); appIt.current(); ++appIt ) + { + if ( !appIt.current()->inherits( "LightApp_Application" ) ) + continue; + + LightApp_Application* app = (LightApp_Application*)appIt.current(); + + QStringList modNameList; + app->modules( modNameList, false ); + for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it ) + { + int id = _prefs_->addPreference( *it ); + _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) ); + } + + ModuleList modList; + app->modules( modList ); + for ( ModuleListIterator itr( modList ); itr.current(); ++itr ) + { + LightApp_Module* mod = 0; + if ( itr.current()->inherits( "LightApp_Module" ) ) + mod = (LightApp_Module*)itr.current(); + + if ( mod && !_prefs_->hasModule( mod->moduleName() ) ) + { + int modCat = _prefs_->addPreference( mod->moduleName() ); + _prefs_->setItemProperty( modCat, "info", QString::null ); + mod->createPreferences(); + } + } + } + + connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ), + this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) ); + + return myPrefs; +} + +/*!Add new module to application.*/ +void LightApp_Application::moduleAdded( CAM_Module* mod ) +{ + CAM_Application::moduleAdded( mod ); + + LightApp_Module* lightMod = 0; + if ( mod && mod->inherits( "LightApp_Module" ) ) + lightMod = (LightApp_Module*)mod; + + if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() )) + { + int modCat = myPrefs->addPreference( mod->moduleName() ); + myPrefs->setItemProperty( modCat, "info", QString::null ); + lightMod->createPreferences(); + } +} + +/*!Create preferences.*/ +void LightApp_Application::createPreferences( LightApp_Preferences* pref ) +{ + if ( !pref ) + return; + + int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) ); + + int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat ); + int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab ); + pref->setItemProperty( studyGroup, "columns", 1 ); + + pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" ); + pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" ); + int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" ); + pref->setItemProperty( undoPref, "min", 1 ); + pref->setItemProperty( undoPref, "max", 100 ); + + int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab ); + pref->setItemProperty( extgroup, "columns", 1 ); + int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" ); + pref->setItemProperty( apppref, "existing", true ); + pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser ); + + pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" ); + + int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab ); + pref->setItemProperty( pythonConsoleGroup, "columns", 1 ); + pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" ); + + int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat ); + + int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab ); + + int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab ); + + int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab ); + + pref->setItemProperty( occGroup, "columns", 1 ); + pref->setItemProperty( vtkGroup, "columns", 1 ); + pref->setItemProperty( plot2dGroup, "columns", 1 ); + + int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup, + LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" ); + pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup, + LightApp_Preferences::Color, "OCCViewer", "background" ); + + pref->setItemProperty( occTS, "min", 1 ); + pref->setItemProperty( occTS, "max", 150 ); + + int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup, + LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" ); + int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup, + LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" ); + + pref->setItemProperty( isoU, "min", 0 ); + pref->setItemProperty( isoU, "max", 100000 ); + + pref->setItemProperty( isoV, "min", 0 ); + pref->setItemProperty( isoV, "max", 100000 ); + + int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup, + LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" ); + pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup, + LightApp_Preferences::Color, "VTKViewer", "background" ); + + pref->setItemProperty( vtkTS, "min", 1 ); + pref->setItemProperty( vtkTS, "max", 150 ); + + pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup, + LightApp_Preferences::Bool, "Plot2d", "ShowLegend" ); + + int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup, + LightApp_Preferences::Selector, "Plot2d", "LegendPos" ); + QStringList aLegendPosList; + aLegendPosList.append( tr("PREF_LEFT") ); + aLegendPosList.append( tr("PREF_RIGHT") ); + aLegendPosList.append( tr("PREF_TOP") ); + aLegendPosList.append( tr("PREF_BOTTOM") ); + + QValueList anIndexesList; + anIndexesList.append(0); + anIndexesList.append(1); + anIndexesList.append(2); + anIndexesList.append(3); + + pref->setItemProperty( legendPosition, "strings", aLegendPosList ); + pref->setItemProperty( legendPosition, "indexes", anIndexesList ); + + int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup, + LightApp_Preferences::Selector, "Plot2d", "CurveType" ); + QStringList aCurveTypesList; + aCurveTypesList.append( tr("PREF_POINTS") ); + aCurveTypesList.append( tr("PREF_LINES") ); + aCurveTypesList.append( tr("PREF_SPLINE") ); + + anIndexesList.clear(); + anIndexesList.append(0); + anIndexesList.append(1); + anIndexesList.append(2); + + pref->setItemProperty( curveType, "strings", aCurveTypesList ); + pref->setItemProperty( curveType, "indexes", anIndexesList ); + + int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup, + LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" ); + + pref->setItemProperty( markerSize, "min", 0 ); + pref->setItemProperty( markerSize, "max", 100 ); + + QStringList aScaleModesList; + aScaleModesList.append( tr("PREF_LINEAR") ); + aScaleModesList.append( tr("PREF_LOGARITHMIC") ); + + anIndexesList.clear(); + anIndexesList.append(0); + anIndexesList.append(1); + + int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup, + LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" ); + + pref->setItemProperty( horScale, "strings", aScaleModesList ); + pref->setItemProperty( horScale, "indexes", anIndexesList ); + + int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup, + LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" ); + + pref->setItemProperty( verScale, "strings", aScaleModesList ); + pref->setItemProperty( verScale, "indexes", anIndexesList ); + + pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup, + LightApp_Preferences::Color, "Plot2d", "Background" ); + + int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat ); + int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab ); + pref->setItemProperty( dirGroup, "columns", 1 ); + pref->addPreference( tr( "" ), dirGroup, + LightApp_Preferences::DirList, "FileDlg", "QuickDirList" ); +} + +/*!Changed preferences */ +void LightApp_Application::preferencesChanged( const QString& sec, const QString& param ) +{ + SUIT_ResourceMgr* resMgr = resourceMgr(); + if ( !resMgr ) + return; + + if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) ) + { + int sz = resMgr->integerValue( sec, param, -1 ); + QPtrList lst; + viewManagers( OCCViewer_Viewer::Type(), lst ); + for ( QPtrListIterator it( lst ); it.current() && sz >= 0; ++it ) + { + SUIT_ViewModel* vm = it.current()->getViewModel(); + if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) ) + continue; + + OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm; + occVM->setTrihedronSize( sz ); + occVM->getAISContext()->UpdateCurrentViewer(); + } + } + + if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) ) + { + int sz = resMgr->integerValue( sec, param, -1 ); + QPtrList lst; + viewManagers( SVTK_Viewer::Type(), lst ); + for ( QPtrListIterator it( lst ); it.current() && sz >= 0; ++it ) + { + SUIT_ViewModel* vm = it.current()->getViewModel(); + if ( !vm || !vm->inherits( "SVTK_Viewer" ) ) + continue; + + SVTK_Viewer* vtkVM = dynamic_cast( vm ); + if( vtkVM ) + { + vtkVM->setTrihedronSize( sz ); + vtkVM->Repaint(); + } + } + } + + if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) ) + { + QPtrList lst; + viewManagers( OCCViewer_Viewer::Type(), lst ); + int u = resMgr->integerValue( sec, "iso_number_u" ); + int v = resMgr->integerValue( sec, "iso_number_v" ); + for ( QPtrListIterator it( lst ); it.current(); ++it ) + ((OCCViewer_Viewer*)it.current())->setIsos( u, v ); + } + + if( sec=="ObjectBrowser" ) + { + if( param=="auto_size" ) + { + OB_Browser* ob = objectBrowser(); + if( !ob ) + return; + + bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); + ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); + + updateObjectBrowser( false ); + } + } + + if( sec=="PyConsole" ) + { + if( param=="font" ) + if( pythonConsole() ) + pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) ); + } +} + +/*!Update desktop title.*/ +void LightApp_Application::updateDesktopTitle() { + QString aTitle = applicationName(); + QString aVer = applicationVersion(); + if ( !aVer.isEmpty() ) + aTitle += QString( " " ) + aVer; + + desktop()->setCaption( aTitle ); +} + +/*!Update windows after close document.*/ +void LightApp_Application::afterCloseDoc() +{ + updateWindows(); + + CAM_Application::afterCloseDoc(); +} + +/*!Update module action.*/ +void LightApp_Application::updateModuleActions() +{ + QString modName; + if ( activeModule() ) + modName = activeModule()->moduleName(); + + if ( myActions.contains( modName ) ) + myActions[modName]->setOn( true ); +} + +/*!Gets current windows. + *\param winMap - output current windows map. + */ +void LightApp_Application::currentWindows( QMap& winMap ) const +{ + winMap.clear(); + if ( !activeStudy() ) + return; + + if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) ) + ((LightApp_Module*)activeModule())->windows( winMap ); + else + defaultWindows( winMap ); +} + +/*!Gets current view managers. + *\param lst - output current view managers list. + */ +void LightApp_Application::currentViewManagers( QStringList& lst ) const +{ + lst.clear(); + if ( !activeStudy() ) + return; + + if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) ) + ((LightApp_Module*)activeModule())->viewManagers( lst ); + else + defaultViewManagers( lst ); +} + +/*!Update windows.*/ +void LightApp_Application::updateWindows() +{ + QMap winMap; + currentWindows( winMap ); + + for ( QMap::ConstIterator it = winMap.begin(); it != winMap.end(); ++it ) + getWindow( it.key() ); + + loadWindowsGeometry(); + + for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) + setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) ); +} + +/*!Update view managers.*/ +void LightApp_Application::updateViewManagers() +{ + QStringList lst; + currentViewManagers( lst ); + + for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it ) + getViewManager( *it, true ); +} + +/*!Load windows geometry.*/ +void LightApp_Application::loadWindowsGeometry() +{ + QtxDockAction* dockMgr = 0; + + QAction* a = action( ViewWindowsId ); + if ( a && a->inherits( "QtxDockAction" ) ) + dockMgr = (QtxDockAction*)a; + + if ( !dockMgr ) + return; + + QString modName; + if ( activeModule() ) + modName = activeModule()->name(""); + + QString section = QString( "windows_geometry" ); + if ( !modName.isEmpty() ) + section += QString( "." ) + modName; + + dockMgr->loadGeometry( resourceMgr(), section, false ); + dockMgr->restoreGeometry(); +} + +/*!Save windows geometry.*/ +void LightApp_Application::saveWindowsGeometry() +{ + QtxDockAction* dockMgr = 0; + + QAction* a = action( ViewWindowsId ); + if ( a && a->inherits( "QtxDockAction" ) ) + dockMgr = (QtxDockAction*)a; + + if ( !dockMgr ) + return; + + QString modName; + if ( activeModule() ) + modName = activeModule()->name(""); + + QString section = QString( "windows_geometry" ); + if ( !modName.isEmpty() ) + section += QString( "." ) + modName; + + dockMgr->storeGeometry(); + dockMgr->saveGeometry( resourceMgr(), section, false ); +} + +/*!Activate windows.*/ +void LightApp_Application::activateWindows() +{ + if ( activeStudy() ) + { + for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) + itr.data()->activate( activeStudy()->id() ); + } +} + +/*!Adds icon names for modules.*/ +void LightApp_Application::moduleIconNames( QMap& iconMap ) const +{ + iconMap.clear(); + + SUIT_ResourceMgr* resMgr = resourceMgr(); + if ( !resMgr ) + return; + + QStringList modList; + modules( modList, false ); + + for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it ) + { + QString modName = *it; + QString modIntr = moduleName( modName ); + QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null ); + + if ( modIcon.isEmpty() ) + continue; + + if ( SUIT_Tools::extension( modIcon ).isEmpty() ) + modIcon += QString( ".png" ); + + iconMap.insert( modName, modIcon ); + } +} + +/*!Insert items in popup, which necessary for current application*/ +void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title ) +{ + CAM_Application::contextMenuPopup( type, thePopup, title ); + + OB_Browser* ob = objectBrowser(); + if ( !ob || type != ob->popupClientType() ) + return; + + thePopup->insertSeparator(); + thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) ); +} + +/*!Create empty study.*/ +void LightApp_Application::createEmptyStudy() +{ + CAM_Application::createEmptyStudy(); + if ( objectBrowser() ) + objectBrowser()->updateTree(); +} + +/*!Activate module \a mod.*/ +bool LightApp_Application::activateModule( CAM_Module* mod ) +{ + bool res = CAM_Application::activateModule( mod ); + if ( objectBrowser() ) + objectBrowser()->updateTree(); + return res; +} + +/*!return keyborad accelerators manager object */ +SUIT_Accel* LightApp_Application::accel() const +{ + return myAccel; +} diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h new file mode 100644 index 000000000..cfb459fba --- /dev/null +++ b/src/LightApp/LightApp_Application.h @@ -0,0 +1,188 @@ +// File: LightApp_Application.h +// Created: 6/20/2005 18:39:25 PM +// Author: OCC team +// Copyright (C) CEA 2005 + +#ifndef LIGHTAPP_APPLICATION_H +#define LIGHTAPP_APPLICATION_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "LightApp.h" +#include + +class LogWindow; +class OB_Browser; +class PythonConsole; +class STD_Application; +class LightApp_WidgetContainer; +class LightApp_Preferences; +class LightApp_SelectionMgr; +class SUIT_Study; +class SUIT_Accel; +class CAM_Module; + +class QString; +class QWidget; +class QStringList; +class QPixmap; + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +/*! + Description : Application containing only LightApp module +*/ + +class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application +{ + Q_OBJECT + +public: + typedef enum { WT_ObjectBrowser, WT_PyConsole, WT_LogWindow, WT_User } WindowTypes; + + enum { NewGLViewId = STD_Application::UserID, NewPlot2dId, NewOCCViewId, NewVTKViewId, + PreferencesId, MRUId, UserID }; +public: + LightApp_Application(); + virtual ~LightApp_Application(); + + virtual QString applicationName() const; + virtual QString applicationVersion() const; + + virtual CAM_Module* loadModule( const QString& ); + virtual bool activateModule( const QString& ); + + virtual bool useStudy( const QString& ); + + LightApp_SelectionMgr* selectionMgr() const; + + LogWindow* logWindow(); + OB_Browser* objectBrowser(); + PythonConsole* pythonConsole(); + + virtual void updateObjectBrowser( const bool = true ); + + LightApp_Preferences* preferences() const; + + virtual QString getFileFilter() const; + + virtual QString getFileName( bool open, const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ); + virtual QString getDirectory( const QString& initial, const QString& caption, QWidget* parent ); + virtual QStringList getOpenFileNames( const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ); + + void updateActions(); + + SUIT_ViewManager* getViewManager( const QString&, const bool ); + QWidget* getWindow( const int, const int = -1 ); + QWidget* window( const int, const int = -1 ) const; + void addWindow( QWidget*, const int, const int = -1 ); + void removeWindow( const int, const int = -1 ); + + bool isWindowVisible( const int ) const; + void setWindowShown( const int, const bool ); + + virtual void start(); + + virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& ); + + virtual void createEmptyStudy(); + + SUIT_Accel* accel() const; + +signals: + void studyOpened(); + void studySaved(); + void studyClosed(); + +public slots: + virtual void onHelpContentsModule(); + virtual void onNewDoc(); + virtual void onOpenDoc(); + virtual void onHelpAbout(); + virtual bool onOpenDoc( const QString& ); + virtual bool onLoadDoc( const QString& ); + +protected: + virtual void createActions(); + virtual SUIT_Study* createNewStudy(); + virtual QWidget* createWindow( const int ); + virtual void defaultWindows( QMap& ) const; + void defaultViewManagers( QStringList& ) const; + + virtual void setActiveStudy( SUIT_Study* ); + virtual void updateCommandsStatus(); + virtual void onSelectionChanged(); + + virtual void beforeCloseDoc( SUIT_Study* ); + virtual void afterCloseDoc(); + virtual void moduleAdded( CAM_Module* ); + virtual bool activateModule( CAM_Module* = 0 ); + + LightApp_Preferences* preferences( const bool ) const; + virtual void createPreferences( LightApp_Preferences* ); + virtual void preferencesChanged( const QString&, const QString& ); + virtual void updateDesktopTitle(); + +protected slots: + virtual void onDesktopActivated(); + + void onNewWindow(); + void onModuleActivation( QAction* ); + void onCloseView( SUIT_ViewManager* ); + + void onStudyCreated( SUIT_Study* ); + void onStudyOpened( SUIT_Study* ); + void onStudySaved( SUIT_Study* ); + void onStudyClosed( SUIT_Study* ); + +private slots: + void onSelection(); + void onRefresh(); + void onPreferences(); + void onMRUActivated( QString ); + void onPreferenceChanged( QString&, QString&, QString& ); + +protected: + void updateWindows(); + void updateViewManagers(); + void updateModuleActions(); + + void loadWindowsGeometry(); + void saveWindowsGeometry(); + + void updatePreference( const QString&, const QString&, const QString& ); + + QString defaultModule() const; + void currentWindows( QMap& ) const; + void currentViewManagers( QStringList& ) const; + virtual SUIT_ViewManager* createViewManager( const QString& vmType ); + void moduleIconNames( QMap& ) const; + + void activateWindows(); + +protected: + typedef QMap ActionMap; + typedef QMap WindowMap; + +protected: + LightApp_Preferences* myPrefs; + LightApp_SelectionMgr* mySelMgr; + ActionMap myActions; + WindowMap myWindows; + + SUIT_Accel* myAccel; + + static LightApp_Preferences* _prefs_; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/LightApp/LightApp_DataModel.cxx b/src/LightApp/LightApp_DataModel.cxx new file mode 100644 index 000000000..6ccba618b --- /dev/null +++ b/src/LightApp/LightApp_DataModel.cxx @@ -0,0 +1,122 @@ +// File: LightApp_DataModel.cxx +// Created: 10/25/2004 10:36:06 AM +// Author: Sergey LITONIN +// Copyright (C) CEA 2004 + +#include "LightApp_DataModel.h" +#include "LightApp_Study.h" +#include "LightApp_RootObject.h" +#include "LightApp_Module.h" +#include "LightApp_Application.h" + +#include + +#include +#include +#include +#include + +//======================================================================= +// name : LightApp_DataModel::LightApp_DataModel +/*!Purpose : Constructor*/ +//======================================================================= +LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule ) +: CAM_DataModel( theModule ) +{ +} + +//======================================================================= +// name : LightApp_DataModel::~LightApp_DataModel +/*! Purpose : Destructor*/ +//======================================================================= +LightApp_DataModel::~LightApp_DataModel() +{ +} + +//================================================================ +// Function : open +/*! Purpose : Emit opened()*/ +//================================================================ +bool LightApp_DataModel::open( const QString&, CAM_Study* study, QStringList ) +{ + emit opened(); //TODO: is it really needed? to be removed maybe... + return true; +} + +//================================================================ +// Function : save +/*! Purpose : Emit saved()*/ +//================================================================ +bool LightApp_DataModel::save( QStringList& ) +{ + emit saved(); + return true; +} + +//================================================================ +// Function : saveAs +/*! Purpose : Emit saved()*/ +//================================================================ +bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& ) +{ + emit saved(); + return true; +} + +//================================================================ +// Function : close +/*! Purpose : Emit closed()*/ +//================================================================ +bool LightApp_DataModel::close() +{ + emit closed(); + return true; +} + +//================================================================ +// Function : update +/*! Purpose : Update application (empty virtual function).*/ +//================================================================ +void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) +{ +} + +//================================================================ +// Function : getModule +/*! Purpose : gets module*/ +//================================================================ + +LightApp_Module* LightApp_DataModel::getModule() const +{ + return dynamic_cast( module() ); +} + +//================================================================ +// Function : getStudy +/*! Purpose : gets study */ +//================================================================ +LightApp_Study* LightApp_DataModel::getStudy() const +{ + LightApp_RootObject* aRoot = dynamic_cast( root()->root() ); + if ( !aRoot ) + return 0; + return aRoot->study(); +} + +//================================================================ +// Function : isModified +/*! Purpose : default implementation, always returns false so as not to mask study's isModified()*/ +//================================================================ +bool LightApp_DataModel::isModified() const +{ + return false; +} + +//================================================================ +// Function : isSaved +/*! Purpose : default implementation, always returns true so as not to mask study's isSaved()*/ +//================================================================ +bool LightApp_DataModel::isSaved() const +{ + return true; +} diff --git a/src/LightApp/LightApp_DataModel.h b/src/LightApp/LightApp_DataModel.h new file mode 100644 index 000000000..7b1f92d6c --- /dev/null +++ b/src/LightApp/LightApp_DataModel.h @@ -0,0 +1,53 @@ +// File: LightApp_DataModel.h +// Created: 10/25/2004 10:32:33 AM +// Author: Sergey LITONIN +// Copyright (C) CEA 2004 + +#ifndef LIGHTAPP_DATAMODEL_H +#define LIGHTAPP_DATAMODEL_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "LightApp.h" +#include "CAM_DataModel.h" + +class LightApp_Module; +class LightApp_Study; +class LightApp_DataObject; + +/*! + Description : Base class of data model +*/ +class LIGHTAPP_EXPORT LightApp_DataModel : public CAM_DataModel +{ + Q_OBJECT + +public: + LightApp_DataModel ( CAM_Module* theModule ); + virtual ~LightApp_DataModel(); + + virtual bool open( const QString&, CAM_Study*, QStringList ); + virtual bool save( QStringList& ); + virtual bool saveAs( const QString&, CAM_Study*, QStringList& ); + virtual bool close(); + + virtual void update( LightApp_DataObject* = 0, LightApp_Study* = 0 ); + + virtual bool isModified() const; + virtual bool isSaved() const; + + LightApp_Module* getModule() const; + +signals: + void opened(); + void saved(); + void closed(); + +protected: + LightApp_Study* getStudy() const; + +}; + +#endif diff --git a/src/LightApp/LightApp_DataObject.cxx b/src/LightApp/LightApp_DataObject.cxx new file mode 100644 index 000000000..9320c256d --- /dev/null +++ b/src/LightApp/LightApp_DataObject.cxx @@ -0,0 +1,163 @@ +#include "LightApp_DataObject.h" + +#include "LightApp_Study.h" +#include "LightApp_RootObject.h" + +#include "CAM_DataModel.h" +#include "CAM_Module.h" + +#include +#include +#include + +#include + +/*! + Class: LightApp_DataObject::Key + Level: Internal +*/ +class LightApp_DataObject::Key : public SUIT_DataObjectKey +{ +public: + Key( const QString& ); + virtual ~Key(); + + virtual bool isLess( const SUIT_DataObjectKey* ) const; + virtual bool isEqual( const SUIT_DataObjectKey* ) const; + +private: + QString myEntry; +}; + +/*!Constructor. Initialize by \a entry.*/ +LightApp_DataObject::Key::Key( const QString& entry ) +: SUIT_DataObjectKey(), + myEntry( entry ) +{ +} + +/*!Destructor. Do nothing.*/ +LightApp_DataObject::Key::~Key() +{ +} + +/*!Checks: Is current key less than \a other.*/ +bool LightApp_DataObject::Key::isLess( const SUIT_DataObjectKey* other ) const +{ + Key* that = (Key*)other; + return myEntry < that->myEntry; +} + +/*!Checks: Is current key equal with \a other.*/ +bool LightApp_DataObject::Key::isEqual( const SUIT_DataObjectKey* other ) const +{ + Key* that = (Key*)other; + return myEntry == that->myEntry; +} + +/* + Class: LightApp_DataObject + Level: Public +*/ +/*!Constructor. Initialize by \a parent*/ +LightApp_DataObject::LightApp_DataObject( SUIT_DataObject* parent ) +: CAM_DataObject( parent ) +{ +} + +/*!Destructor. Do nothing.*/ +LightApp_DataObject::~LightApp_DataObject() +{ +} + +/*!Gets object ID. + *\retval QString + */ +QString LightApp_DataObject::entry() const +{ + return QString::null; +} + +/*!Create and return new key object.*/ +SUIT_DataObjectKey* LightApp_DataObject::key() const +{ + QString str = entry(); + return new Key( str ); +} + +/*!Gets component object. + *\retval SUIT_DataObject. + */ +SUIT_DataObject* LightApp_DataObject::componentObject() const +{ + SUIT_DataObject* compObj = 0; // for root object + + if ( parent() && parent() == root() ) + compObj = (SUIT_DataObject*)this; // for component-level objects + else + { + compObj = parent(); // for lower level objects + while ( compObj && compObj->parent() != root() ) + compObj = compObj->parent(); + } + return compObj; +} + +/*!Get component type.*/ +QString LightApp_DataObject::componentDataType() const +{ + SUIT_DataObject* aCompObj = componentObject(); + LightApp_ModuleObject* anObj = dynamic_cast( aCompObj ); + if ( anObj ) { + CAM_DataModel* aModel = anObj->dataModel(); + if ( aModel ) + return aModel->module()->name(); + } + return ""; +} + +/* + Class: LightApp_ModuleObject + Level: Public +*/ + +/*!Constructor.Initialize by \a parent.*/ +LightApp_ModuleObject::LightApp_ModuleObject( SUIT_DataObject* parent ) +: CAM_RootObject( parent ), + CAM_DataObject( parent ) +{ +} + +/*!Constructor.Initialize by \a module and parent.*/ +LightApp_ModuleObject::LightApp_ModuleObject( CAM_DataModel* dm, SUIT_DataObject* parent ) +: CAM_RootObject( dm, parent ), + CAM_DataObject( parent ) +{ +} + +/*!Destructor. Do nothing.*/ +LightApp_ModuleObject::~LightApp_ModuleObject() +{ +} + +/*!Returns module name */ +QString LightApp_ModuleObject::name() const +{ + return CAM_RootObject::name(); +} + +/*!Insert new child object to the children list at specified position + *\add component in Study for this module object if it necessary*/ +void LightApp_ModuleObject::insertChild( SUIT_DataObject* theObj, int thePosition ) +{ + CAM_RootObject::insertChild(theObj, thePosition); + + CAM_DataModel* aModel = dataModel(); + + LightApp_RootObject* aRoot = dynamic_cast(parent()); + + if (aRoot) + aRoot->study()->addComponent(aModel); + + +} diff --git a/src/LightApp/LightApp_DataObject.h b/src/LightApp/LightApp_DataObject.h new file mode 100644 index 000000000..e338a218f --- /dev/null +++ b/src/LightApp/LightApp_DataObject.h @@ -0,0 +1,51 @@ +#ifndef LIGHTAPP_DATAOBJECT_H +#define LIGHTAPP_DATAOBJECT_H + +#include "LightApp.h" + +#include "CAM_DataObject.h" +#include "CAM_DataModel.h" +#include "CAM_RootObject.h" + +class LightApp_Study; + +/*!Description : Data Object has empty entry so it's children must redefine metod entry() and return some unique string*/ +// to do : decomment virtual inheritance +class LIGHTAPP_EXPORT LightApp_DataObject : public virtual CAM_DataObject +{ + class Key; + +public: + enum { CT_Value, CT_Entry, CT_IOR, CT_RefEntry }; + +public: + LightApp_DataObject( SUIT_DataObject* = 0 ); + virtual ~LightApp_DataObject(); + + virtual SUIT_DataObjectKey* key() const; + virtual QString entry() const; + + virtual SUIT_DataObject* componentObject() const; + virtual QString componentDataType() const; + +}; + +/*! + * LightApp_ModuleObject - class for optimized access to DataModel from + * CAM_RootObject.h. + * In modules which will be redefine LightApp_DataObject, LightApp_ModuleObject must be children from rederined DataObject for having necessary properties and children from LightApp_ModuleObject. + */ + +class LIGHTAPP_EXPORT LightApp_ModuleObject : public CAM_RootObject +{ +public: + LightApp_ModuleObject( SUIT_DataObject* = 0 ); + LightApp_ModuleObject ( CAM_DataModel*, SUIT_DataObject* = 0 ); + + virtual ~LightApp_ModuleObject(); + + virtual QString name() const; + virtual void insertChild( SUIT_DataObject*, int thePosition ); +}; + +#endif diff --git a/src/LightApp/LightApp_DataOwner.cxx b/src/LightApp/LightApp_DataOwner.cxx new file mode 100644 index 000000000..647b5d328 --- /dev/null +++ b/src/LightApp/LightApp_DataOwner.cxx @@ -0,0 +1,56 @@ +#include "LightApp_DataOwner.h" + +#include "LightApp_DataObject.h" + +#ifdef WNT +#include +#endif + +#include + +/*!Constructor. Initialize by \a theEntry.*/ +LightApp_DataOwner +::LightApp_DataOwner( const QString& theEntry ): + myEntry( theEntry ) +{ +} + +/*!Constructor. Initialize by \a SALOME_InteractiveObject.*/ +LightApp_DataOwner +::LightApp_DataOwner( const Handle(SALOME_InteractiveObject)& theIO ): + myEntry(!theIO.IsNull()? theIO->getEntry(): ""), + myIO(theIO) +{ +} + +/*!Destructor. Do nothing.*/ +LightApp_DataOwner +::~LightApp_DataOwner() +{ +} + +/*!Checks: Is current data owner equal \a obj.*/ +bool +LightApp_DataOwner +::isEqual( const SUIT_DataOwner& obj ) const +{ + const LightApp_DataOwner* other = dynamic_cast( &obj ); + + return other && entry() == other->entry(); +} + +/*!Gets entry.*/ +QString +LightApp_DataOwner +::entry() const +{ + return myEntry; +} + +/*!Gets SALOME_InteractiveObject.*/ +const Handle(SALOME_InteractiveObject)& +LightApp_DataOwner +::IO() const +{ + return myIO; +} diff --git a/src/LightApp/LightApp_DataOwner.h b/src/LightApp/LightApp_DataOwner.h new file mode 100644 index 000000000..6ec43e08d --- /dev/null +++ b/src/LightApp/LightApp_DataOwner.h @@ -0,0 +1,30 @@ + +#ifndef LIGHTAPP_DATAOWNER_H +#define LIGHTAPP_DATAOWNER_H + +#include "LightApp.h" +#include "SUIT_DataOwner.h" +#include "SALOME_InteractiveObject.hxx" + +/*! + This class provide data owner objects. +*/ +class LIGHTAPP_EXPORT LightApp_DataOwner : public SUIT_DataOwner +{ +public: + LightApp_DataOwner( const Handle(SALOME_InteractiveObject)& theIO ); + LightApp_DataOwner( const QString& ); + virtual ~LightApp_DataOwner(); + + virtual bool isEqual( const SUIT_DataOwner& ) const; + const Handle(SALOME_InteractiveObject)& IO() const; + QString entry() const; + +private: + QString myEntry; + Handle(SALOME_InteractiveObject) myIO; +}; + +typedef SMART(LightApp_DataOwner) LightApp_DataOwnerPtr; + +#endif diff --git a/src/LightApp/LightApp_DataSubOwner.cxx b/src/LightApp/LightApp_DataSubOwner.cxx new file mode 100644 index 000000000..50c5ca3a3 --- /dev/null +++ b/src/LightApp/LightApp_DataSubOwner.cxx @@ -0,0 +1,33 @@ +#include "LightApp_DataSubOwner.h" + +#include "LightApp_DataObject.h" + +#ifdef WNT +#include +#endif + +/*!Constructor.Initialize by \a entry and \a index*/ +LightApp_DataSubOwner::LightApp_DataSubOwner( const QString& entry, const int index ) +: LightApp_DataOwner( entry ), +myIndex( index ) +{ +} + +/*!Destructor. Do nothing.*/ +LightApp_DataSubOwner::~LightApp_DataSubOwner() +{ +} + +/*!Checks: Is current data sub owner equal \a obj.*/ +bool LightApp_DataSubOwner::isEqual( const SUIT_DataOwner& obj ) const +{ + const LightApp_DataSubOwner* other = dynamic_cast( &obj ); + + return other && entry() == other->entry() && index() == other->index(); +} + +/*!Gets index.*/ +int LightApp_DataSubOwner::index() const +{ + return myIndex; +} diff --git a/src/LightApp/LightApp_DataSubOwner.h b/src/LightApp/LightApp_DataSubOwner.h new file mode 100644 index 000000000..5240409b6 --- /dev/null +++ b/src/LightApp/LightApp_DataSubOwner.h @@ -0,0 +1,24 @@ + +#ifndef LIGHTAPP_DATASUBOWNER_H +#define LIGHTAPP_DATASUBOWNER_H + +#include +#include + +/*! + Class provide sub owner. + */ +class LIGHTAPP_EXPORT LightApp_DataSubOwner : public LightApp_DataOwner +{ +public: + LightApp_DataSubOwner( const QString&, const int ); + virtual ~LightApp_DataSubOwner(); + + virtual bool isEqual( const SUIT_DataOwner& ) const; + int index() const; + +private: + int myIndex; +}; + +#endif diff --git a/src/LightApp/LightApp_Dialog.cxx b/src/LightApp/LightApp_Dialog.cxx new file mode 100644 index 000000000..a79b5da46 --- /dev/null +++ b/src/LightApp/LightApp_Dialog.cxx @@ -0,0 +1,860 @@ +// File: LightApp_Dialog.cxx +// Author: Alexander SOLOVYOV + +#include +#include + +#include +#include +#include + +/* + Class : LightApp_Dialog + Description : Base class for all dialogs +*/ + +//======================================================================= +// name : LightApp_Dialog +// Purpose : Constructor +//======================================================================= +LightApp_Dialog::LightApp_Dialog( QWidget* parent, const char* name, bool modal, + bool allowResize, const int f, WFlags wf ) +: QtxDialog( parent, name, modal, allowResize, f, wf ), + myIsExclusive( true ), + myIsBusy( false ) +{ + setObjectPixmap( "LightApp", tr( "ICON_SELECT" ) ); +} + +//======================================================================= +// name : ~LightApp_Dialog +// Purpose : Destructor +//======================================================================= +LightApp_Dialog::~LightApp_Dialog() +{ +} + +//======================================================================= +// name : show +// Purpose : +//======================================================================= +void LightApp_Dialog::show() +{ + QtxDialog::show(); +} + +//======================================================================= +// name : isExclusive +// Purpose : +//======================================================================= +bool LightApp_Dialog::isExclusive() const +{ + return myIsExclusive; +} + +//======================================================================= +// name : updateButtons +// Purpose : +//======================================================================= +void LightApp_Dialog::updateButtons( const int _id ) +{ + if( !myIsExclusive ) + return; + + int id = _id; + + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + QToolButton* but = (QToolButton*)anIt.data().myBtn; + if( but && but->isOn() ) + { + if( id==-1 ) + id = anIt.key(); + + if( anIt.key()!=id ) + but->setOn( false ); + } + } +} + +//======================================================================= +// name : setExclusive +// Purpose : +//======================================================================= +void LightApp_Dialog::setExclusive( const bool ex ) +{ + myIsExclusive = ex; + updateButtons(); +} + +//======================================================================= +// name : showObject +// Purpose : +//======================================================================= +void LightApp_Dialog::showObject( const int id ) +{ + setObjectShown( id, true ); +} + +//======================================================================= +// name : hideObject +// Purpose : +//======================================================================= +void LightApp_Dialog::hideObject( const int id ) +{ + setObjectShown( id, false ); +} + +//======================================================================= +// name : setObjectShown +// Purpose : +//======================================================================= +void LightApp_Dialog::setObjectShown( const int id, const bool shown ) +{ + if( myObjects.contains( id ) && isObjectShown( id )!=shown ) + { + Object& obj = myObjects[ id ]; + obj.myEdit->setShown( shown ); + obj.myBtn->setShown( shown ); + obj.myLabel->setShown( shown ); + if( !shown ) + ( ( QToolButton* )obj.myBtn )->setOn( false ); + } +} + +//======================================================================= +// name : isObjectShown +// Purpose : +//======================================================================= +bool LightApp_Dialog::isObjectShown( const int id ) const +{ + return myObjects.contains( id ) && myObjects[ id ].myEdit->isShown(); +} + +//======================================================================= +// name : setObjectEnabled +// Purpose : +//======================================================================= +void LightApp_Dialog::setObjectEnabled( const int id, const bool en ) +{ + if( myObjects.contains( id ) && isObjectEnabled( id )!=en ) + { + Object& obj = myObjects[ id ]; + obj.myEdit->setEnabled( en ); + obj.myBtn->setEnabled( en ); +// obj.myLabel->setEnabled( en ); + if( !en ) + ( ( QToolButton* )obj.myBtn )->setOn( false ); + } +} + +//======================================================================= +// name : isObjectEnabled +// Purpose : +//======================================================================= +bool LightApp_Dialog::isObjectEnabled( const int id ) const +{ + return myObjects.contains( id ) && myObjects[ id ].myEdit->isEnabled(); +} + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void LightApp_Dialog::selectObject( const QString& name, const int type, const QString& id, const bool update ) +{ + QStringList names; names.append( name ); + TypesList types; types.append( type ); + QStringList ids; ids.append( id ); + selectObject( names, types, ids, update ); +} + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void LightApp_Dialog::selectObject( const QStringList& _names, + const TypesList& _types, + const QStringList& _ids, + const bool update ) +{ + ObjectMap::iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data().myBtn->isOn() ) + selectObject( anIt.key(), _names, _types, _ids, update ); +} + +//======================================================================= +// name : hasSelection +// Purpose : +//======================================================================= +bool LightApp_Dialog::hasSelection( const int id ) const +{ + return myObjects.contains( id ) && !myObjects[ id ].myIds.isEmpty(); +} + +//======================================================================= +// name : clearSelection +// Purpose : +//======================================================================= +void LightApp_Dialog::clearSelection( const int id ) +{ + if( id==-1 ) + { + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + clearSelection( anIt.key() ); + } + + else if( myObjects.contains( id ) ) + { + myObjects[ id ].myIds.clear(); + myObjects[ id ].myTypes.clear(); + myObjects[ id ].myNames.clear(); + + myObjects[ id ].myEdit->setText( QString::null ); + emit selectionChanged( id ); + } +} + +//======================================================================= +// name : objectWg +// Purpose : +//======================================================================= +QWidget* LightApp_Dialog::objectWg( const int theId, const int theWgId ) const +{ + QWidget* aResWg = 0; + if( myObjects.contains( theId ) ) + { + if ( theWgId == Label ) + aResWg = myObjects[ theId ].myLabel; + else if ( theWgId == Btn ) + aResWg = myObjects[ theId ].myBtn; + else if ( theWgId == Control ) + aResWg = myObjects[ theId ].myEdit; + } + return aResWg; +} + +//======================================================================= +// name : objectText +// Purpose : +//======================================================================= +QString LightApp_Dialog::objectText( const int theId ) const +{ + return myObjects.contains( theId ) ? myObjects[ theId ].myEdit->text() : ""; +} + +//======================================================================= +// name : setObjectText +// Purpose : +//======================================================================= +void LightApp_Dialog::setObjectText( const int theId, const QString& theText ) +{ + if ( myObjects.contains( theId ) ) + myObjects[ theId ].myEdit->setText( theText ); +} + +//======================================================================= +// name : selectedObject +// Purpose : +//======================================================================= +void LightApp_Dialog::selectedObject( const int id, QStringList& list ) const +{ + if( myObjects.contains( id ) ) + list = myObjects[ id ].myIds; +} + +//======================================================================= +// name : selectedObject +// Purpose : +//======================================================================= +QString LightApp_Dialog::selectedObject( const int id ) const +{ + if ( myObjects.contains( id ) && myObjects[ id ].myIds.count() > 0 ) + return myObjects[ id ].myIds.first(); + else + return ""; +} + +//======================================================================= +// name : objectSelection +// Purpose : +//======================================================================= +void LightApp_Dialog::objectSelection( SelectedObjects& objs ) const +{ + //objs.clear(); + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + QStringList ids; + selectedObject( anIt.key(), ids ); + if( !ids.isEmpty() ) + objs.insert( anIt.key(), ids ); + } +} + +//======================================================================= +// name : createObject +// Purpose : +//======================================================================= +int LightApp_Dialog::createObject( const QString& label, QWidget* parent, const int id ) +{ + int nid = id; + if( nid<0 ) + for( nid=0; myObjects.contains( nid ); nid++ ); + + if( !myObjects.contains( nid ) ) + { + QLabel* lab = new QLabel( label, parent ); + myObjects[ nid ].myLabel = lab; + + QToolButton* but = new QToolButton( parent ); + but->setIconSet( QIconSet( myPixmap ) ); + but->setToggleButton( true ); + but->setMaximumWidth( but->height() ); + but->setMinimumWidth( but->height() ); + connect( but, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) ); + myObjects[ nid ].myBtn = but; + + QLineEdit* ne = new QLineEdit( parent ); + ne->setReadOnly( true ); + ne->setMinimumWidth( 150 ); + connect( ne, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + myObjects[ nid ].myEdit = ne; + + myObjects[ nid ].myNI = OneNameOrCount; + } + return nid; +} + +//======================================================================= +// name : renameObject +// Purpose : +//======================================================================= +void LightApp_Dialog::renameObject( const int id, const QString& label ) +{ + if( myObjects.contains( id ) ) + myObjects[ id ].myLabel->setText( label ); +} + +//======================================================================= +// name : setObjectType +// Purpose : +//======================================================================= +void LightApp_Dialog::setObjectType( const int id, const int type1, ... ) +{ + TypesList types; + + const int* tt = &type1; + while( *tt>=0 ) + { + types.append( *tt ); + tt++; + } + + setObjectType( id, types ); +} + +//======================================================================= +// name : setObjectType +// Purpose : +//======================================================================= +void LightApp_Dialog::setObjectType( const int id, const TypesList& list ) +{ + if( !myObjects.contains( id ) ) + return; + + TypesList& internal = myObjects[ id ].myPossibleTypes; + + QMap types; + TypesList::const_iterator anIt = list.begin(), + aLast = list.end(); + for( ; anIt!=aLast; anIt++ ) + types.insert( *anIt, 0 ); + + + internal.clear(); + QMap::const_iterator aMIt = types.begin(), + aMLast = types.end(); + for( ; aMIt!=aMLast; aMIt++ ) + internal.append( aMIt.key() ); + + updateObject( id ); +} + +//======================================================================= +// name : addObjectType +// Purpose : +//======================================================================= +void LightApp_Dialog::addObjectType( const int id, const int type1, const int, ... ) +{ + TypesList types; objectTypes( id, types ); + + const int* tt = &type1; + while( *tt>=0 ) + { + types.append( *tt ); + tt++; + } + + setObjectType( id, types ); +} + +//======================================================================= +// name : addObjectType +// Purpose : +//======================================================================= +void LightApp_Dialog::addObjectType( const int id, const TypesList& list ) +{ + TypesList types = list; objectTypes( id, types ); + setObjectType( id, types ); +} + +//======================================================================= +// name : addObjectType +// Purpose : +//======================================================================= +void LightApp_Dialog::addObjectType( const int id, const int type ) +{ + TypesList types; objectTypes( id, types ); + types.append( type ); + setObjectType( id, types ); +} + +//======================================================================= +// name : removeObjectType +// Purpose : +//======================================================================= +void LightApp_Dialog::removeObjectType( const int id ) +{ + TypesList types; + setObjectType( id, types ); +} + +//======================================================================= +// name : removeObjectType +// Purpose : +//======================================================================= +void LightApp_Dialog::removeObjectType( const int id, const TypesList& list ) +{ + if( !myObjects.contains( id ) ) + return; + + TypesList& internal = myObjects[ id ].myPossibleTypes; + + QMap types; + TypesList::const_iterator anIt = internal.begin(), + aLast = internal.end(); + for( ; anIt!=aLast; anIt++ ) + types.insert( *anIt, 0 ); + anIt = list.begin(); aLast = list.end(); + for( ; anIt!=aLast; anIt++ ) + types.remove( *anIt ); + + + internal.clear(); + QMap::const_iterator aMIt = types.begin(), + aMLast = types.end(); + for( ; aMIt!=aMLast; aMIt++ ) + internal.append( aMIt.key() ); + + updateObject( id ); +} + +//======================================================================= +// name : removeObjectType +// Purpose : +//======================================================================= +void LightApp_Dialog::removeObjectType( const int id, const int type ) +{ + TypesList list; list.append( type ); + removeObjectType( id, list ); +} + +//======================================================================= +// name : hasObjectType +// Purpose : +//======================================================================= +bool LightApp_Dialog::hasObjectType( const int id, const int type ) const +{ + if( myObjects.contains( id ) ) + return myObjects[ id ].myPossibleTypes.contains( type ); + else + return false; +} + +//======================================================================= +// name : objectTypes +// Purpose : +//======================================================================= +void LightApp_Dialog::objectTypes( const int id, TypesList& list ) const +{ + if( myObjects.contains( id ) ) + { + TypesList::const_iterator anIt = myObjects[ id ].myPossibleTypes.begin(), + aLast = myObjects[ id ].myPossibleTypes.end(); + for( ; anIt!=aLast; anIt++ ) + list.append( *anIt ); + } +} + +//======================================================================= +// name : onToggled +// Purpose : +//======================================================================= +void LightApp_Dialog::onToggled( bool on ) +{ + QButton* but = ( QButton* )sender(); + int id = -1; + + if( !but ) + return; + + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast && id==-1; anIt++ ) + if( anIt.data().myBtn==but ) + id = anIt.key(); + + if( id!=-1 ) + if( on ) + { + updateButtons( id ); + emit objectActivated( id ); + } + else + emit objectDeactivated( id ); +} + +//======================================================================= +// name : updateObject +// Purpose : +//======================================================================= +void LightApp_Dialog::updateObject( const int id, bool emit_signal ) +{ + if( hasSelection( id ) ) + { + Object& obj = myObjects[ id ]; + filterTypes( id, obj.myNames, obj.myTypes, obj.myIds ); + obj.myEdit->setText( selectionDescription( obj.myNames, obj.myTypes, obj.myNI ) ); + if( emit_signal ) + emit selectionChanged( id ); + } +} + +//======================================================================= +// name : filterTypes +// Purpose : +//======================================================================= +void LightApp_Dialog::filterTypes( const int id, QStringList& names, TypesList& types, QStringList& ids ) const +{ + if( !myObjects.contains( id ) ) + return; + + const Object& obj = myObjects[ id ]; + if( obj.myPossibleTypes.isEmpty() ) + return; + + QStringList new_names, new_ids; + TypesList new_types; + + TypesList::const_iterator anIt1 = types.begin(), + aLast = types.end(); + QStringList::const_iterator anIt2 = names.begin(), + anIt3 = ids.begin(); + for( ; anIt1!=aLast; anIt1++, anIt2++, anIt3++ ) + if( obj.myPossibleTypes.contains( *anIt1 ) ) + { + if( new_types.count()==1 && !multipleSelection( id ) ) + break; + + new_names.append( *anIt2 ); + new_types.append( *anIt1 ); + new_ids.append( *anIt3 ); + } + names = new_names; + types = new_types; + ids = new_ids; +} + +//======================================================================= +// name : resMgr +// Purpose : +//======================================================================= +SUIT_ResourceMgr* LightApp_Dialog::resMgr() const +{ + return SUIT_Session::session()->resourceMgr(); +} + +//======================================================================= +// name : setObjectPixmap +// Purpose : +//======================================================================= +void LightApp_Dialog::setObjectPixmap( const QPixmap& p ) +{ + myPixmap = p; + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + ( ( QToolButton* )anIt.data().myBtn )->setIconSet( p ); +} + +//======================================================================= +// name : setObjectPixmap +// Purpose : +//======================================================================= +void LightApp_Dialog::setObjectPixmap( const QString& section, const QString& file ) +{ + SUIT_ResourceMgr* mgr = resMgr(); + if( mgr ) + setObjectPixmap( mgr->loadPixmap( section, file ) ); +} + +//======================================================================= +// name : multipleSelection +// Purpose : +//======================================================================= +bool LightApp_Dialog::multipleSelection( const int id ) const +{ + return nameIndication( id )!=OneName; +} + +//======================================================================= +// name : nameIndication +// Purpose : +//======================================================================= +LightApp_Dialog::NameIndication LightApp_Dialog::nameIndication( const int id ) const +{ + if( myObjects.contains( id ) ) + return myObjects[ id ].myNI; + else + return OneNameOrCount; +} + +//======================================================================= +// name : setNameIndication +// Purpose : +//======================================================================= +void LightApp_Dialog::setNameIndication( const int id, const NameIndication ni ) +{ + if( id==-1 ) + { + ObjectMap::iterator anIt = myObjects.begin(), + aNext, + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + anIt.data().myNI = ni; + setReadOnly( anIt.key(), isReadOnly( anIt.key() ) ); + aNext = anIt; aNext++; + updateObject( anIt.key(), aNext==aLast ); + } + } + else if( myObjects.contains( id ) ) + { + myObjects[ id ].myNI = ni; + setReadOnly( id, isReadOnly( id ) ); + updateObject( id, true ); + } +} + +//======================================================================= +// name : selectionDescription +// Purpose : +//======================================================================= +QString LightApp_Dialog::selectionDescription( const QStringList& names, const TypesList& types, const NameIndication ni ) const +{ + if( names.count()!=types.count() ) + return "LightApp_Dialog::selectionDescription(): Error!!!"; + + if( names.isEmpty() ) + return QString::null; + + switch( ni ) + { + case OneName: + return names.first(); + break; + + case OneNameOrCount: + if( names.count()==1 ) + return names.first(); + else + return countOfTypes( types ); + break; + + case ListOfNames: + return names.join( " " ); + break; + + case Count: + return countOfTypes( types ); + break; + }; + return QString::null; +} + +//======================================================================= +// name : countOfTypes +// Purpose : +//======================================================================= +QString LightApp_Dialog::countOfTypes( const TypesList& types ) const +{ + QMap typesCount; + QStringList typeCount; + + TypesList::const_iterator anIt = types.begin(), + aLast = types.end(); + for( ; anIt!=aLast; anIt++ ) + if( typesCount.contains( *anIt ) ) + typesCount[ *anIt ]++; + else + typesCount[ *anIt ] = 1; + + QMap::const_iterator aMIt = typesCount.begin(), + aMLast = typesCount.end(); + for( ; aMIt!=aMLast; aMIt++ ) + typeCount.append( QString( "%1 %2" ).arg( aMIt.data() ).arg( typeName( aMIt.key() ) ) ); + + return typeCount.join( ", " ); +} + +//======================================================================= +// name : typeName +// Purpose : +//======================================================================= +QString& LightApp_Dialog::typeName( const int type ) +{ + return myTypeNames[ type ]; +} + +//======================================================================= +// name : typeName +// Purpose : +//======================================================================= +const QString& LightApp_Dialog::typeName( const int type ) const +{ + return myTypeNames[ type ]; +} + + +//======================================================================= +// name : activateObject +// Purpose : +//======================================================================= +void LightApp_Dialog::activateObject( const int theId ) +{ + if ( myObjects.contains( theId ) && !myObjects[ theId ].myBtn->isOn() ) + myObjects[ theId ].myBtn->toggle(); +} + +//======================================================================= +// name : deactivateAll +// Purpose : +//======================================================================= +void LightApp_Dialog::deactivateAll() +{ + ObjectMap::iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + QToolButton* btn = ( QToolButton* )anIt.data().myBtn; + btn->setOn( false ); + } +} + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void LightApp_Dialog::selectObject( const int id, const QString& name, const int type, const QString& selid, const bool update ) +{ + QStringList names; names.append( name ); + TypesList types; types.append( type ); + QStringList ids; ids.append( selid ); + selectObject( id, names, types, ids, update ); +} + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void LightApp_Dialog::selectObject( const int id, const QStringList& _names, const TypesList& _types, + const QStringList& _ids, const bool update ) +{ + if( !myObjects.contains( id ) ) + return; + + QStringList names = _names, ids = _ids; + TypesList types = _types; + + filterTypes( id, names, types, ids ); + + Object& obj = myObjects[ id ]; + if( update ) + obj.myEdit->setText( selectionDescription( names, types, obj.myNI ) ); + obj.myTypes = types; + obj.myIds = ids; + obj.myNames = names; + + emit selectionChanged( id ); +} + +//======================================================================= +// name : setReadOnly +// Purpose : +//======================================================================= +void LightApp_Dialog::setReadOnly( const int id, const bool ro ) +{ + if( myObjects.contains( id ) ) + myObjects[ id ].myEdit->setReadOnly( nameIndication( id )==ListOfNames || nameIndication( id )==OneName ? ro : true ); +} + +//======================================================================= +// name : isReadOnly +// Purpose : +//======================================================================= +bool LightApp_Dialog::isReadOnly( const int id ) const +{ + if( myObjects.contains( id ) ) + return myObjects[ id ].myEdit->isReadOnly(); + else + return true; +} + +//======================================================================= +// name : onTextChanged +// Purpose : +//======================================================================= +void LightApp_Dialog::onTextChanged( const QString& text ) +{ + if( myIsBusy ) + return; + + myIsBusy = true; + + if( sender() && sender()->inherits( "QLineEdit" ) ) + { + QLineEdit* edit = ( QLineEdit* )sender(); + int id = -1; + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data().myEdit == edit ) + id = anIt.key(); + + if( id>=0 && !isReadOnly( id ) ) + { + QStringList list = QStringList::split( " ", text ); + emit objectChanged( id, list ); + } + } + + myIsBusy = false; +} diff --git a/src/LightApp/LightApp_Dialog.h b/src/LightApp/LightApp_Dialog.h new file mode 100644 index 000000000..b13a0f835 --- /dev/null +++ b/src/LightApp/LightApp_Dialog.h @@ -0,0 +1,267 @@ +// File: LightApp_Dialog.h +// Author: Alexander SOLOVYOV + +#ifndef LIGHTAPP_DIALOG_H +#define LIGHTAPP_DIALOG_H + +#include "LightApp.h" +#include + +#include +#include +#include + +class QLineEdit; +class QButton; +class QLabel; + +class SUIT_ResourceMgr; + +/* + Class : LightApp_Dialog + Description : Base class for all LightApp dialogs +*/ +class LIGHTAPP_EXPORT LightApp_Dialog : public QtxDialog +{ + Q_OBJECT + +public: + typedef QValueList TypesList; + typedef QMap SelectedObjects; + + enum ObjectWg + { + Label = 0x00000001, + Btn = 0x00000002, + Control = 0x00000004 + }; + + typedef enum + { + OneName, // " is shown + ListOfNames, //! list of all names is shown + Count //! In every case " " is shown + + } NameIndication; + //! The enumeration describing how names of selected objects will be shown in line edit + //! For more details see above + +public: + LightApp_Dialog( QWidget* = 0, const char* = 0, bool = false, + bool = false, const int = Standard, WFlags = 0 ); + virtual ~LightApp_Dialog(); + + virtual void show(); + + //! Check if buttons is exclusive (as radiobuttons) + bool isExclusive() const; + + //! Set exclusive state + void setExclusive( const bool ); + + //! Check if operation according to dialog will be resumed automatically when mouse enter the dialog + bool isAutoResumed() const; + + //! Set auto resumed state + void setAutoResumed( const bool ); + + //! Show widgets corresponding to id + void showObject( const int ); + + //! Hide widgets corresponding to id + void hideObject( const int ); + + //! Change the shown state of widgets corresponding to id + void setObjectShown( const int, const bool ); + + //! Check the shown state + bool isObjectShown( const int ) const; + + //! Change the enabled state of widgets corresponding to id + void setObjectEnabled( const int, const bool ); + + //! Check the enabled state + bool isObjectEnabled( const int ) const; + + //! Get widget of object (see ObjectWg enumeration) + QWidget* objectWg( const int theId, const int theWgId ) const; + + //! Pass to all active widgets name, type and id of selected object + void selectObject( const QString&, const int, const QString&, const bool = true ); + + /*! + Pass to all active widgets list of names, types and ids of selected objects + Every active widget filters list and accept only objects with possible types + */ + void selectObject( const QStringList&, const TypesList&, const QStringList&, const bool = true ); + + //! Get text of object's control + QString objectText( const int ) const; + + //! Set text of object's control + void setObjectText( const int, const QString& ); + + //! Select in certain widget avoiding check if there is active widget + void selectObject( const int, const QString&, const int, const QString&, const bool = true ); + void selectObject( const int, const QStringList&, const TypesList&, const QStringList&, const bool = true ); + + //! Check if certain widget has selection + bool hasSelection( const int ) const; + + //! Clear selection in widgets. If parameter is -1, then selection in all widgets will be cleared + void clearSelection( const int = -1 ); + + //! Get ids list of object selected in certain widget + void selectedObject( const int, QStringList& ) const; + + //! Get ids list of object selected in certain widget + QString selectedObject( const int ) const; + + //! Get map "widget id -> ids list" + void objectSelection( SelectedObjects& ) const; + + //! Activate object selection button + void activateObject( const int ); + + //! Set all object selection buttons to inactive state + void deactivateAll(); + +signals: + //! selection in certain widget is changed + void selectionChanged ( int ); + + //! selection in certain widget is on + void objectActivated ( int ); + + //! selection in certain widget is off + void objectDeactivated( int ); + + /* + text representation of selection is changed + it is emitted only if "read only" state of line edit is false + */ + void objectChanged( int, const QStringList& ); + +protected: + //! Finds and returns resource manager + SUIT_ResourceMgr* resMgr() const; + + /*! Create label, button and line edit for object selection + * If passed id is negative, then id will be calculated automatically (first free id) + * Returns the same id (if id>=0) or calculated + */ + int createObject ( const QString&, QWidget*, const int = -1 ); + + //! Set pixmap as icon for all selection buttons + void setObjectPixmap ( const QPixmap& ); + + //! Load pixmap with section, name using resource manager and set as icon for all selection buttons + void setObjectPixmap ( const QString&, const QString& ); + + //! Change label + void renameObject ( const int, const QString& ); + + //! Set possible types for certain id. The list of arguments must be finished by negative integer + void setObjectType ( const int, const int, ... ); + + //! Set list as possible types for object selection + void setObjectType ( const int, const TypesList& ); + + /*! + Add types to list of possible types + The list of arguments must be finished by negative integer + */ + void addObjectType ( const int, const int, const int, ... ); + + //! Add types to list of possible types + void addObjectType ( const int, const TypesList& ); + + //! Add type to list of possible types + void addObjectType ( const int, const int ); + + //! Clear list of possible types (it means, that all types are welcome) + void removeObjectType( const int ); + + //! Remove types in list from list of possible types + void removeObjectType( const int, const TypesList& ); + + //! Remove a type from list of possible types + void removeObjectType( const int, const int ); + + //! Check if list of possible types contains this one + bool hasObjectType ( const int, const int ) const; + + //! Return list of possible types + void objectTypes ( const int, TypesList& ) const; + + //!Change and get type name for indicating in selection widget + QString& typeName( const int ); + const QString& typeName( const int ) const; + + //! Create string contains selection list by list of names, list of types and current name indication state + virtual QString selectionDescription( const QStringList&, const TypesList&, const NameIndication ) const; + + //! Create string by pattern " " for current list of types + virtual QString countOfTypes( const TypesList& ) const; + + //! Get and set name indication for certain widget + NameIndication nameIndication( const int ) const; + void setNameIndication( const int, const NameIndication ); + + //! Check using name indication if multiple selection in possible + bool multipleSelection( const int ) const; + + //! Set the "read only" state of object selection line edit + //! The "read only" will be false only if name indication is ListOfNames + void setReadOnly( const int, const bool ); + + //! Check the "read only" state of object selection line edit + bool isReadOnly( const int ) const; + +private slots: + //! emits if the object selection button changes state + void onToggled( bool ); + + //! text in some line edit is changed + void onTextChanged( const QString& ); + +private: + /*! + If buttons are exclusive, set to "off" all buttons except one with id + If id=-1, then all buttons, except first with "on" state, will be set to "off" + */ + void updateButtons( const int = -1 ); + + /*! + Filter types and update selection string in line edit + If bool is true, then signal is emitted + */ + void updateObject( const int, bool = true ); + + //! Remove from list not possible types and remove from names and ids lists the corresponding items + void filterTypes( const int, QStringList&, TypesList&, QStringList& ) const; + +private: + typedef struct + { + QLineEdit* myEdit; + QButton* myBtn; + QLabel* myLabel; + QStringList myNames, myIds; + TypesList myTypes, myPossibleTypes; + NameIndication myNI; + + } Object; + + typedef QMap ObjectMap; + +private: + ObjectMap myObjects; + QMap myTypeNames; + bool myIsExclusive, myIsBusy; + QPixmap myPixmap; +}; + +#endif diff --git a/src/LightApp/LightApp_Displayer.cxx b/src/LightApp/LightApp_Displayer.cxx new file mode 100644 index 000000000..f2952de04 --- /dev/null +++ b/src/LightApp/LightApp_Displayer.cxx @@ -0,0 +1,145 @@ + +#include "LightApp_Displayer.h" +#include "LightApp_Application.h" + +#include + +#include +#include +#include +#include +#include + +#include + +LightApp_Displayer::LightApp_Displayer() +{ +} + +LightApp_Displayer::~LightApp_Displayer() +{ +} + +void LightApp_Displayer::Display( const QString& entry, const bool updateViewer, SALOME_View* theViewFrame ) +{ + SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); + if ( vf ) + { + SALOME_Prs* prs = buildPresentation( entry, vf ); + + if ( prs ) + { + vf->BeforeDisplay( this ); + vf->Display( prs ); + vf->AfterDisplay( this ); + + if ( updateViewer ) + vf->Repaint(); + + delete prs; // delete presentation because displayer is its owner + } + } +} + +void LightApp_Displayer::Redisplay( const QString& entry, const bool updateViewer ) +{ + // Remove the object permanently ( == true) + SUIT_Session* ses = SUIT_Session::session(); + SUIT_Application* app = ses->activeApplication(); + if ( app ) + { + SUIT_Desktop* desk = app->desktop(); + QPtrList wnds = desk->windows(); + SUIT_ViewWindow* wnd; + for ( wnd = wnds.first(); wnd; wnd = wnds.next() ) + { + SUIT_ViewManager* vman = wnd->getViewManager(); + if( !vman ) + continue; + + SUIT_ViewModel* vmodel = vman->getViewModel(); + if( !vmodel ) + continue; + + SALOME_View* view = dynamic_cast(vmodel); + if( view && ( IsDisplayed( entry, view ) || view == GetActiveView() ) ) + { + Erase( entry, true, false, view ); + Display( entry, updateViewer, view ); + } + } + } +} + +void LightApp_Displayer::Erase( const QString& entry, const bool forced, + const bool updateViewer, SALOME_View* theViewFrame ) +{ + SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); + + if ( vf ) { + SALOME_Prs* prs = vf->CreatePrs( entry.latin1() ); + if ( prs ) { + vf->Erase( prs, forced ); + if ( updateViewer ) + vf->Repaint(); + delete prs; // delete presentation because displayer is its owner + } + } +} + +void LightApp_Displayer::EraseAll( const bool forced, const bool updateViewer, SALOME_View* theViewFrame ) const +{ + SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); + + if ( vf ) { + vf->EraseAll( forced ); + if ( updateViewer ) + vf->Repaint(); + } +} + +bool LightApp_Displayer::IsDisplayed( const QString& entry, SALOME_View* theViewFrame ) const +{ + SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); + if( vf ) + { + Handle( SALOME_InteractiveObject ) temp = new SALOME_InteractiveObject(); + temp->setEntry( entry.latin1() ); + return vf->isVisible( temp ); + } + else + return false; +} + +void LightApp_Displayer::UpdateViewer() const +{ + SALOME_View* vf = GetActiveView(); + if ( vf ) + vf->Repaint(); +} + +SALOME_Prs* LightApp_Displayer::buildPresentation( const QString& entry, SALOME_View* theViewFrame ) +{ + SALOME_Prs* prs = 0; + + SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); + + if ( vf ) + prs = vf->CreatePrs( entry.latin1() ); + + return prs; +} + +SALOME_View* LightApp_Displayer::GetActiveView() +{ + SUIT_Session* session = SUIT_Session::session(); + if ( SUIT_Application* app = session->activeApplication() ) { + if ( LightApp_Application* sApp = dynamic_cast( app ) ) { + if( SUIT_ViewManager* vman = sApp->activeViewManager() ) { + if ( SUIT_ViewModel* vmod = vman->getViewModel() ) + return dynamic_cast( vmod ); + } + } + } + return 0; +} diff --git a/src/LightApp/LightApp_Displayer.h b/src/LightApp/LightApp_Displayer.h new file mode 100644 index 000000000..94ccd4f90 --- /dev/null +++ b/src/LightApp/LightApp_Displayer.h @@ -0,0 +1,28 @@ + +#ifndef LIGHTAPP_DISPLAYER_HEADER +#define LIGHTAPP_DISPLAYER_HEADER + +#include + +class QString; + +class LightApp_Displayer : public SALOME_Displayer +{ +public: + LightApp_Displayer(); + virtual ~LightApp_Displayer(); + + void Display( const QString&, const bool = true, SALOME_View* = 0 ); + void Redisplay( const QString&, const bool = true ); + void Erase( const QString&, const bool forced = false, const bool updateViewer = true, SALOME_View* = 0 ); + void EraseAll( const bool forced = false, const bool updateViewer = true, SALOME_View* = 0 ) const; + bool IsDisplayed( const QString&, SALOME_View* = 0 ) const; + void UpdateViewer() const; + + static SALOME_View* GetActiveView(); + +protected: + virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 ); +}; + +#endif diff --git a/src/LightApp/LightApp_Driver.cxx b/src/LightApp/LightApp_Driver.cxx new file mode 100644 index 000000000..a37f4f5d2 --- /dev/null +++ b/src/LightApp/LightApp_Driver.cxx @@ -0,0 +1,486 @@ +#include "LightApp_Driver.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +#include +#endif + +/*! Constructor.*/ +LightApp_Driver::LightApp_Driver() +{ +} + +/*! Destructor.*/ +LightApp_Driver::~LightApp_Driver() +{ +} + +using namespace std; + +//================================================================ +// Function : SaveDatasInFile +/*! Purpose : save in file 'theFileName' datas from this driver*/ +//================================================================ +bool LightApp_Driver::SaveDatasInFile( const char* theFileName, bool isMultiFile ) +{ + int aNbModules = 0; + std::map::const_iterator it; + for (it = myMap.begin(); it != myMap.end(); ++it) + aNbModules++; + + unsigned char** aBuffer = new unsigned char*[aNbModules]; + long* aBufferSize = new long[aNbModules]; + char** aModuleName = new char*[aNbModules]; + + if(aBuffer == NULL || aBufferSize == NULL || aModuleName == NULL) + return false; + + int aFileBufferSize = 4; //4 bytes for a number of the modules that will be written to the stream; + int i = 0; + for (it = myMap.begin(); it != myMap.end(); ++it) { + aModuleName[i] = const_cast(it->first.c_str());//(it->first); + aFileBufferSize += 4; //Add 4 bytes: a length of the module name + aFileBufferSize += strlen(aModuleName[i])+1; + std::string aName(aModuleName[i]); + PutFilesToStream(aName, aBuffer[i], aBufferSize[i], isMultiFile); + aFileBufferSize += 8; //Add 8 bytes: a length of the buffer + aFileBufferSize += aBufferSize[i]; + // Remove the files and tmp directory, created by the component storage procedure + if (!isMultiFile) + RemoveTemporaryFiles(aModuleName[i], true); + i++; + } + int n = i; + + unsigned char* aFileBuffer = new unsigned char[aFileBufferSize]; + if(aFileBuffer == NULL) + return false; + + int aCurrentPos = 0; + + //Initialize 4 bytes of the buffer by 0 + memset(aFileBuffer, 0, 4); + //Copy the number of modules that will be written to the stream + memcpy(aFileBuffer, &aNbModules, ((sizeof(int) > 4) ? 4 : sizeof(int))); + aCurrentPos += 4; + + int aBufferNameSize = 0; + for (i = 0; i < n; i++) { + aBufferNameSize = strlen(aModuleName[i])+1; + //Initialize 4 bytes of the buffer by 0 + memset((aFileBuffer + aCurrentPos), 0, 4); + //Copy the length of the module name to the buffer + memcpy((aFileBuffer + aCurrentPos), &aBufferNameSize, ((sizeof(int) > 4) ? 4 : sizeof(int))); + aCurrentPos += 4; + //Copy the module name to the buffer + memcpy((aFileBuffer + aCurrentPos), aModuleName[i], aBufferNameSize); + aCurrentPos += aBufferNameSize; + + //Initialize 8 bytes of the buffer by 0 + memset((aFileBuffer + aCurrentPos), 0, 8); + //Copy the length of the module buffer to the buffer + memcpy((aFileBuffer + aCurrentPos), (aBufferSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long))); + aCurrentPos += 8; + //Copy the module buffer to the buffer + memcpy((aFileBuffer + aCurrentPos), aBuffer[i], aBufferSize[i]); + aCurrentPos += aBufferSize[i]; + } + + ofstream aFile(theFileName); + aFile.write((char*)aFileBuffer, aFileBufferSize); + aFile.close(); + + delete[] aBuffer; + delete[] aBufferSize; + delete[] aModuleName; + delete[] aFileBuffer; + return true; +} + +//======================================================================= +// name : ReaDatasFromFile +/*! Purpose : filling current driver from file 'theFileName'*/ +//======================================================================= +bool LightApp_Driver::ReadDatasFromFile( const char* theFileName, bool isMultiFile ) +{ +#ifdef WNT + ifstream aFile(theFileName, ios::binary); +#else + ifstream aFile(theFileName); +#endif + + aFile.seekg(0, ios::end); + int aFileBufferSize = aFile.tellg(); + unsigned char* aFileBuffer = new unsigned char[aFileBufferSize]; + aFile.seekg(0, ios::beg); + aFile.read((char*)aFileBuffer, aFileBufferSize); + aFile.close(); + + int aNbModules = 0; + //Copy the number of files in the stream + memcpy(&aNbModules, aFileBuffer, sizeof(int)); + long aCurrentPos = 4; + int aModuleNameSize; + + for (int i = 0; i < aNbModules; i++) { + //Put a length of the module name to aModuleNameSize + memcpy(&aModuleNameSize, (aFileBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); + aCurrentPos += 4; + + char *aModuleName = new char[aModuleNameSize]; + //Put a module name to aModuleName + memcpy(aModuleName, (aFileBuffer + aCurrentPos), aModuleNameSize); + aCurrentPos += aModuleNameSize; + + //Put a length of the file buffer to aBufferSize + long aBufferSize; + memcpy(&aBufferSize, (aFileBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); + aCurrentPos += 8; + unsigned char *aBuffer = new unsigned char[aBufferSize]; + + //Put a buffer for current module to aBuffer + memcpy(aBuffer, (aFileBuffer + aCurrentPos), aBufferSize); + aCurrentPos += aBufferSize; + + // Put buffer to aListOfFiles and set to myMap + ListOfFiles aListOfFiles = PutStreamToFiles(aBuffer, aBufferSize, isMultiFile); + SetListOfFiles(aModuleName, aListOfFiles); + + delete[] aModuleName; + delete[] aBuffer; + } + delete[] aFileBuffer; + return true; +} + +//================================================================ +// Function : GetTmpDir +/*! Purpose : returns temp directory for path 'theURL'*/ +//================================================================ +std::string LightApp_Driver::GetTmpDir (const char* theURL, const bool isMultiFile) +{ + std::string anURLDir = GetDirFromPath(theURL); + std::string aTmpDir = isMultiFile ? anURLDir : GetTmpDir(); + + return aTmpDir; +} + +//================================================================ +// Function : GetListOfFiles +/*! Purpose : returns list of files for module with name 'theModuleName'*/ +//================================================================ +LightApp_Driver::ListOfFiles LightApp_Driver::GetListOfFiles( const char* theModuleName ) +{ + ListOfFiles aListOfFiles; + + std::string aName(theModuleName); + if (myMap.count(aName)) + aListOfFiles = myMap[aName]; + + return aListOfFiles; +} + +//================================================================ +// Function : SetListOfFiles +/*! Purpose : sets list of files for module with name 'theModuleName'*/ +//================================================================ +void LightApp_Driver::SetListOfFiles( const char* theModuleName, const ListOfFiles theListOfFiles ) +{ + std::string aName (theModuleName); + myMap[aName] = theListOfFiles; +} + +//============================================================================ +// function : PutFilesToStream +/*! Purpose : converts files which was created from module into a byte sequence unsigned char*/ +//============================================================================ +void LightApp_Driver::PutFilesToStream( const std::string& theModuleName, unsigned char*& theBuffer, + long& theBufferSize, bool theNamesOnly ) +{ + ListOfFiles aFiles = myMap[theModuleName]; + // aFiles must contain temporary directory name in its first item + // and names of files (relatively the temporary directory) in the others + + int i, aLength = aFiles.size() - 1; + if(aLength <= 0) { + theBufferSize = 0; + theBuffer = new unsigned char[theBufferSize]; + return; + } + //Get a temporary directory for saved a file + TCollection_AsciiString aTmpDir(const_cast(aFiles[0].c_str())); + + long aBufferSize = 0; + long aCurrentPos; + int aNbFiles = 0; + int* aFileNameSize= new int[aLength]; + long* aFileSize= new long[aLength]; + + //Determine the required size of the buffer + TCollection_AsciiString aFileName; + for (i = 0; i < aLength; i++) { + char* aFName = const_cast(aFiles[i+1].c_str()); + aFileName = aFName; + //Check if the file exists + if (!theNamesOnly) { // mpv 15.01.2003: if only file names must be stroed, then size of files is zero + TCollection_AsciiString aFullPath = aTmpDir + aFileName; + OSD_Path anOSDPath(aFullPath); + OSD_File anOSDFile(anOSDPath); + if(!anOSDFile.Exists()) continue; +#ifdef WNT + ifstream aFile(aFullPath.ToCString(), ios::binary); +#else + ifstream aFile(aFullPath.ToCString()); +#endif + aFile.seekg(0, ios::end); + aFileSize[i] = aFile.tellg(); + aBufferSize += aFileSize[i]; //Add a space to store the file + } + aFileNameSize[i] = strlen(aFName) + 1; + aBufferSize += aFileNameSize[i]; //Add a space to store the file name + aBufferSize += (theNamesOnly)?4:12; //Add 4 bytes: a length of the file name, + // 8 bytes: length of the file itself + aNbFiles++; + delete[] aFName; + } + + aBufferSize += 4; //4 bytes for a number of the files that will be written to the stream; + theBuffer = new unsigned char[aBufferSize]; + if(theBuffer == NULL) { + theBufferSize = 0; + theBuffer = 0; + return; + } + //Initialize 4 bytes of the buffer by 0 + memset(theBuffer, 0, 4); + //Copy the number of files that will be written to the stream + memcpy(theBuffer, &aNbFiles, ((sizeof(int) > 4) ? 4 : sizeof(int))); + + aCurrentPos = 4; + + for(i = 0; i < aLength; i++) { + ifstream *aFile; + if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true + TCollection_AsciiString aName(const_cast(aFiles[i+1].c_str())); + TCollection_AsciiString aFullPath = aTmpDir + aName; + OSD_Path anOSDPath(aFullPath); + OSD_File anOSDFile(anOSDPath); + if(!anOSDFile.Exists()) continue; +#ifdef WNT + aFile = new ifstream(aFullPath.ToCString(), ios::binary); +#else + aFile = new ifstream(aFullPath.ToCString()); +#endif + } + //Initialize 4 bytes of the buffer by 0 + memset((theBuffer + aCurrentPos), 0, 4); + //Copy the length of the file name to the buffer + memcpy((theBuffer + aCurrentPos), (aFileNameSize + i), ((sizeof(int) > 4) ? 4 : sizeof(int))); + aCurrentPos += 4; + + //Copy the file name to the buffer + char* aFName = const_cast(aFiles[i+1].c_str()); + memcpy((theBuffer + aCurrentPos), aFName, aFileNameSize[i]); + aCurrentPos += aFileNameSize[i]; + + if (!theNamesOnly) { // mpv 15.01.2003: we don't copy file content to the buffer if !theNamesOnly + //Initialize 8 bytes of the buffer by 0 + memset((theBuffer + aCurrentPos), 0, 8); + //Copy the length of the file to the buffer + memcpy((theBuffer + aCurrentPos), (aFileSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long))); + aCurrentPos += 8; + + aFile->seekg(0, ios::beg); + aFile->read((char *)(theBuffer + aCurrentPos), aFileSize[i]); + aFile->close(); + delete(aFile); + aCurrentPos += aFileSize[i]; + } + } + delete[] aFileNameSize; + delete[] aFileSize; + + theBufferSize = aBufferSize; +} + +//============================================================================ +// function : PutStreamToFile +/*! Purpose : converts a byte sequence to files and return list of them*/ +//============================================================================ +LightApp_Driver::ListOfFiles LightApp_Driver::PutStreamToFiles( const unsigned char* theBuffer, + const long theBufferSize, bool theNamesOnly ) +{ + if(theBufferSize == 0 || theBuffer == 0) + return ListOfFiles(); + + // Create a temporary directory for the component's data files + std::string aDir = GetTmpDir(); + + //Get a temporary directory for saving a file + TCollection_AsciiString aTmpDir(const_cast(aDir.c_str())); + + long aFileSize, aCurrentPos = 4; + int i, aFileNameSize, aNbFiles = 0; + + //Copy the number of files in the stream + memcpy(&aNbFiles, theBuffer, sizeof(int)); + + const int n = aNbFiles + 1; + ListOfFiles aFiles(n); + aFiles[0] = aDir; + + for(i = 0; i < aNbFiles; i++) { + //Put a length of the file name to aFileNameSize + memcpy(&aFileNameSize, (theBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); + aCurrentPos += 4; + + char *aFileName = new char[aFileNameSize]; + //Put a file name to aFileName + memcpy(aFileName, (theBuffer + aCurrentPos), aFileNameSize); + aCurrentPos += aFileNameSize; + + //Put a length of the file to aFileSize + if (!theNamesOnly) { + memcpy(&aFileSize, (theBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); + aCurrentPos += 8; + + TCollection_AsciiString aFullPath = aTmpDir + aFileName; + ofstream aFile(aFullPath.ToCString()); + aFile.write((char *)(theBuffer+aCurrentPos), aFileSize); + aFile.close(); + aCurrentPos += aFileSize; + } + std::string aStrFileName(aFileName); + aFiles[i+1] = aStrFileName; + delete[] aFileName; + } + return aFiles; +} + +//============================================================================ +// function : RemoveTemporaryFiles +/*! Purpose : removes files which was created from module theModuleName if is true tmp directory is also deleted if it is empty*/ +//============================================================================ +void LightApp_Driver::RemoveTemporaryFiles( const char* theModuleName, const bool IsDirDeleted ) +{ + std::string aModuleName(theModuleName); + ListOfFiles aFiles = myMap[aModuleName]; + // aFiles must contain temporary directory name in its first item + // and names of files (relatively the temporary directory) in the others + + int i, aLength = aFiles.size() - 1; + if(aLength <= 0) { + return; + } + //Get a temporary directory for saved a file + TCollection_AsciiString aDirName(const_cast(aFiles[0].c_str())); + + for(i = 0; i < aLength; i++) { + TCollection_AsciiString aFile(aDirName); + aFile += const_cast(aFiles[i+1].c_str()); + OSD_Path anOSDPath(aFile); + OSD_File anOSDFile(anOSDPath); + if(!anOSDFile.Exists()) continue; + + OSD_Protection aProtection = anOSDFile.Protection(); + aProtection.SetUser(OSD_RW); + anOSDFile.SetProtection(aProtection); + + anOSDFile.Remove(); + } + + if(IsDirDeleted) { + OSD_Path aPath(aDirName); + OSD_Directory aDir(aPath); + OSD_FileIterator anIterator(aPath, '*'); + + if(aDir.Exists() && !anIterator.More()) aDir.Remove(); + } +} + +//============================================================================ +// function : ClearDriverContents +/*! Purpose : clear map of list files*/ +//============================================================================ +void LightApp_Driver::ClearDriverContents() +{ + myMap.clear(); +} + +//============================================================================ +// function : GetTempDir +/*! Purpose : return a temp directory to store created files like "/tmp/sub_dir/" */ +//============================================================================ +std::string LightApp_Driver::GetTmpDir() +{ + //Find a temporary directory to store a file + TCollection_AsciiString aTmpDir; + + char *Tmp_dir = getenv("SALOME_TMP_DIR"); + if(Tmp_dir != NULL) { + aTmpDir = TCollection_AsciiString(Tmp_dir); +#ifdef WIN32 + if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; +#else + if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; +#endif + } + else { +#ifdef WIN32 + aTmpDir = TCollection_AsciiString("C:\\"); +#else + aTmpDir = TCollection_AsciiString("/tmp/"); +#endif + } + + srand((unsigned int)time(NULL)); + int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory + TCollection_AsciiString aSubDir(aRND); + if(aSubDir.Length() <= 1) aSubDir = TCollection_AsciiString("123409876"); + + aTmpDir += aSubDir; //Get RND sub directory + +#ifdef WIN32 + if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; +#else + if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; +#endif + + OSD_Path aPath(aTmpDir); + OSD_Directory aDir(aPath); + + for(aRND = 0; aDir.Exists(); aRND++) { + aTmpDir.Insert((aTmpDir.Length() - 1), TCollection_AsciiString(aRND)); //Build a unique directory name + aPath = OSD_Path(aTmpDir); + aDir = OSD_Directory(aPath); + } + + OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); + aDir.Build(aProtection); + + return aTmpDir.ToCString(); +} + +//============================================================================ +// function : GetDirFromPath +/*! Purpose : returns the dir by the path*/ +//============================================================================ +std::string LightApp_Driver::GetDirFromPath( const std::string& thePath ) { + if(thePath == "") + return ""; + OSD_Path aPath = OSD_Path(TCollection_AsciiString(const_cast(thePath.c_str()))); + TCollection_AsciiString aDirString(aPath.Trek()); + aDirString.ChangeAll('|','/'); + return aDirString.ToCString(); +} + diff --git a/src/LightApp/LightApp_Driver.h b/src/LightApp/LightApp_Driver.h new file mode 100644 index 000000000..eb26e5633 --- /dev/null +++ b/src/LightApp/LightApp_Driver.h @@ -0,0 +1,49 @@ +#ifndef LIGHTAPP_DRIVER_H +#define LIGHTAPP_DRIVER_H + +#include + +#include "string" +#include "vector" +#include "map" + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +/*!Description : Driver can save to file and read from file list of files for light modules*/ + +class LIGHTAPP_EXPORT LightApp_Driver +{ +public: + LightApp_Driver(); + virtual ~LightApp_Driver(); + + + typedef std::vector ListOfFiles; + + bool SaveDatasInFile (const char* theFileName, bool isMultiFile ); + bool ReadDatasFromFile (const char* theFileName, bool isMultiFile ); + virtual std::string GetTmpDir (const char* theURL, const bool isMultiFile); + + ListOfFiles GetListOfFiles (const char* theModuleName); + virtual void SetListOfFiles (const char* theModuleName, const ListOfFiles theListOfFiles); + virtual void RemoveTemporaryFiles(const char* theModuleName, const bool IsDirDeleted); + + virtual void ClearDriverContents(); + +private: + void PutFilesToStream(const std::string& theModuleName, unsigned char*& theBuffer, + long& theBufferSize, bool theNamesOnly = false); + ListOfFiles PutStreamToFiles(const unsigned char* theBuffer, + const long theBufferSize, bool theNamesOnly = false); + + std::string GetTmpDir(); + std::string GetDirFromPath(const std::string& thePath); + +private: + typedef std::map MapOfListOfFiles; + MapOfListOfFiles myMap; +}; + +#endif diff --git a/src/LightApp/LightApp_GLSelector.cxx b/src/LightApp/LightApp_GLSelector.cxx new file mode 100644 index 000000000..b49ce51c1 --- /dev/null +++ b/src/LightApp/LightApp_GLSelector.cxx @@ -0,0 +1,99 @@ +#include "LightApp_GLSelector.h" + +#include "LightApp_DataOwner.h" + +#include + +#include + +/*!Constructor. Initialize by GLViewer_Viewer2d and SUIT_SelectionMgr.*/ +LightApp_GLSelector::LightApp_GLSelector( GLViewer_Viewer2d* viewer, SUIT_SelectionMgr* mgr ) +: SUIT_Selector( mgr, viewer ), + myViewer( viewer ) +{ + if ( myViewer ) + connect( myViewer, SIGNAL( selectionChanged( SelectionChangeStatus ) ), + this, SLOT( onSelectionChanged() ) ); +} + +/*!Destructor. Do nothing.*/ +LightApp_GLSelector::~LightApp_GLSelector() +{ +} + +/*!Gets viewer*/ +GLViewer_Viewer2d* LightApp_GLSelector::viewer() const +{ + return myViewer; +} + +/*!On selection changed event.*/ +void LightApp_GLSelector::onSelectionChanged() +{ + selectionChanged(); +} + +/*!Gets list of selected Data Owner objects.*/ +void LightApp_GLSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const +{ + if ( !myViewer ) + return; + + GLViewer_Context* cont = myViewer->getGLContext(); + if ( !cont ) + return; + + for ( cont->InitSelected(); cont->MoreSelected(); cont->NextSelected() ) + { + GLViewer_Object* obj = cont->SelectedObject(); + if ( obj ) + { + SALOME_GLOwner* owner = dynamic_cast< SALOME_GLOwner* >( obj->owner() ); + if( owner ) + aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( owner->entry() ) ) ); + } + } +} + +/*!Sets to selected list of Data Owner objects.*/ +void LightApp_GLSelector::setSelection( const SUIT_DataOwnerPtrList& aList ) +{ + if ( !myViewer ) + return; + + GLViewer_Context* cont = myViewer->getGLContext(); + if ( !cont ) + return; + + QMap aDisplayed; + const ObjList& displayed = cont->getObjects(); + for ( ObjList::const_iterator it = displayed.begin(); it != displayed.end(); ++it ) + { + GLViewer_Object* obj = *it; + if ( obj && obj->getVisible() ) + { + SALOME_GLOwner* owner = dynamic_cast< SALOME_GLOwner* >( obj->owner() ); + if ( owner ) + aDisplayed.insert( owner->entry(), obj ); + } + } + + int Nb = 0; + cont->clearSelected( false ); + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) + { + const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); + + if ( !owner ) + continue; + + if ( aDisplayed.contains( owner->entry() ) ) + { + cont->setSelected( aDisplayed[owner->entry()], false ); + Nb++; + } + } + + if ( Nb > 0 ) + myViewer->updateAll(); +} diff --git a/src/LightApp/LightApp_GLSelector.h b/src/LightApp/LightApp_GLSelector.h new file mode 100644 index 000000000..50a783ecb --- /dev/null +++ b/src/LightApp/LightApp_GLSelector.h @@ -0,0 +1,33 @@ +#ifndef LIGHTAPP_GLSELECTOR_H +#define LIGHTAPP_GLSELECTOR_H + +#include "LightApp.h" + +#include + +#include + +class LIGHTAPP_EXPORT LightApp_GLSelector : public SUIT_Selector +{ + Q_OBJECT + +public: + LightApp_GLSelector( GLViewer_Viewer2d*, SUIT_SelectionMgr* ); + virtual ~LightApp_GLSelector(); + + GLViewer_Viewer2d* viewer() const; + + virtual QString type() const { return GLViewer_Viewer2d::Type(); } + +private slots: + void onSelectionChanged(); + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); + +private: + GLViewer_Viewer2d* myViewer; +}; + +#endif diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx new file mode 100644 index 000000000..6e6c68158 --- /dev/null +++ b/src/LightApp/LightApp_Module.cxx @@ -0,0 +1,412 @@ +// File: LightApp_Module.cxx +// Created: 6/20/2005 16:30:56 AM +// Author: OCC team +// Copyright (C) CEA 2005 + +#include "LightApp_Module.h" + +#include "CAM_Application.h" + +#include "LightApp_Application.h" +#include "LightApp_DataModel.h" +#include "LightApp_Study.h" +#include "LightApp_Preferences.h" +#include "LightApp_Selection.h" +#include "LightApp_Operation.h" +#include "LightApp_SwitchOp.h" +#include "LightApp_UpdateFlags.h" +#include "LightApp_ShowHideOp.h" + +#include "SUIT_Operation.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +/*!Constructor.*/ +LightApp_Module::LightApp_Module( const QString& name ) +: CAM_Module( name ), + myPopupMgr( 0 ), + mySwitchOp( 0 ), + myDisplay( -1 ), + myErase( -1 ), + myDisplayOnly( -1 ) +{ +} + +/*!Destructor.*/ +LightApp_Module::~LightApp_Module() +{ + if ( mySwitchOp ) + delete mySwitchOp; +} + +/*!Initialize module.*/ +void LightApp_Module::initialize( CAM_Application* app ) +{ + CAM_Module::initialize( app ); + + SUIT_ResourceMgr* resMgr = app ? app->resourceMgr() : 0; + if ( resMgr ) + resMgr->raiseTranslators( name() ); +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::windows( QMap& ) const +{ +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::viewManagers( QStringList& ) const +{ +} + +/*!Context menu popup.*/ +void LightApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ ) +{ + LightApp_Selection* sel = createSelection(); + sel->init( client, getApp()->selectionMgr() ); + popupMgr()->updatePopup( menu, sel ); + delete sel; +} + +/*!Update object browser. + * For updating model or whole object browser use update() method can be used. +*/ +void LightApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root ) +{ + if( updateDataModel ) + if( CAM_DataModel* aDataModel = dataModel() ) + if( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) + aModel->update( 0, dynamic_cast( getApp()->activeStudy() ) ); + getApp()->objectBrowser()->updateTree( root ); +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::selectionChanged() +{ +} + +/*!Activate module.*/ +bool LightApp_Module::activateModule( SUIT_Study* study ) +{ + bool res = CAM_Module::activateModule( study ); + + if ( res && application() && application()->resourceMgr() ) + application()->resourceMgr()->raiseTranslators( name() ); + + if ( mySwitchOp == 0 ) + mySwitchOp = new LightApp_SwitchOp( this ); + + return res; +} + +/*!Deactivate module.*/ +bool LightApp_Module::deactivateModule( SUIT_Study* ) +{ + delete mySwitchOp; + mySwitchOp = 0; + + return true; +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::MenuItem() +{ +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::createPreferences() +{ +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::preferencesChanged( const QString&, const QString& ) +{ +} + +/*!Gets application.*/ +LightApp_Application* LightApp_Module::getApp() const +{ + return (LightApp_Application*)application(); +} + +/*! + * \brief Update something in accordance with update flags + * \param theFlags - update flags +* +* Update viewer or/and object browser etc. in accordance with update flags ( see +* LightApp_UpdateFlags enumeration ). Derived modules can redefine this method for their +* own purposes +*/ +void LightApp_Module::update( const int theFlags ) +{ + if ( theFlags & UF_Model ) + { + if( CAM_DataModel* aDataModel = dataModel() ) + if( LightApp_DataModel* aModel = dynamic_cast( aDataModel ) ) + aModel->update( 0, dynamic_cast( getApp()->activeStudy() ) ); + } + if ( theFlags & UF_ObjBrowser ) + getApp()->objectBrowser()->updateTree( 0 ); + if ( theFlags & UF_Controls ) + updateControls(); + if ( theFlags & UF_Viewer ) + { + if ( SUIT_ViewManager* viewMgr = getApp()->activeViewManager() ) + if ( SUIT_ViewWindow* viewWnd = viewMgr->getActiveView() ) + { + if ( viewWnd->inherits( "SVTK_ViewWindow" ) ) + ( (SVTK_ViewWindow*)viewWnd )->Repaint(); + else if ( viewWnd->inherits( "OCCViewer_ViewWindow" ) ) + ( (OCCViewer_ViewWindow*)viewWnd )->getViewPort()->onUpdate(); + else if ( viewWnd->inherits( "Plot2d_ViewWindow" ) ) + ( (Plot2d_ViewWindow*)viewWnd )->getViewFrame()->Repaint(); + else if ( viewWnd->inherits( "GLViewer_ViewFrame" ) ) + ( (GLViewer_ViewFrame*)viewWnd )->getViewPort()->onUpdate(); + } + } +} +/*! + * \brief Updates controls +* +* Updates (i.e. disable/enable) controls states (menus, tool bars etc.). This method is +* called from update( UF_Controls ). You may redefine it in concrete module. +*/ +void LightApp_Module::updateControls() +{ +} + +/*!Create new instance of data model and return it.*/ +CAM_DataModel* LightApp_Module::createDataModel() +{ + return new LightApp_DataModel(this); +} + +/*!Create and return instance of LightApp_Selection.*/ +LightApp_Selection* LightApp_Module::createSelection() const +{ + return new LightApp_Selection(); +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::onModelOpened() +{ +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::onModelSaved() +{ +} + +/*!NOT IMPLEMENTED*/ +void LightApp_Module::onModelClosed() +{ +} + +/*!Gets popup manager.(create if not exist)*/ +QtxPopupMgr* LightApp_Module::popupMgr() +{ + if ( !myPopupMgr ) + { + myPopupMgr = new QtxPopupMgr( 0, this ); + + QPixmap p; + SUIT_Desktop* d = application()->desktop(); + + QAction + *disp = createAction( -1, tr( "TOP_DISPLAY" ), p, tr( "MEN_DISPLAY" ), tr( "STB_DISPLAY" ), + 0, d, false, this, SLOT( onShowHide() ) ), + *erase = createAction( -1, tr( "TOP_ERASE" ), p, tr( "MEN_ERASE" ), tr( "STB_ERASE" ), + 0, d, false, this, SLOT( onShowHide() ) ), + *dispOnly = createAction( -1, tr( "TOP_DISPLAY_ONLY" ), p, tr( "MEN_DISPLAY_ONLY" ), tr( "STB_DISPLAY_ONLY" ), + 0, d, false, this, SLOT( onShowHide() ) ); + myDisplay = actionId( disp ); + myErase = actionId( erase ); + myDisplayOnly = actionId( dispOnly ); + + myPopupMgr->insert( disp, -1, 0 ); + myPopupMgr->insert( erase, -1, 0 ); + myPopupMgr->insert( dispOnly, -1, 0 ); + myPopupMgr->insert( separator(), -1, 0 ); + + QString uniform = "( count( $component ) = 1 ) and ( component != activeModule ) and ( activeModule = '%1' )"; + uniform = uniform.arg( name() ); + myPopupMgr->setRule( disp, QString( "( not isVisible ) and " ) + uniform, true ); + myPopupMgr->setRule( erase, QString( "( isVisible ) and " ) + uniform, true ); + myPopupMgr->setRule( dispOnly, uniform, true ); + } + return myPopupMgr; +} + +/*!Gets preferences.*/ +LightApp_Preferences* LightApp_Module::preferences() const +{ + LightApp_Preferences* pref = 0; + if ( getApp() ) + pref = getApp()->preferences(); + return pref; +} + +/*!Add preference to preferences.*/ +int LightApp_Module::addPreference( const QString& label ) +{ + LightApp_Preferences* pref = preferences(); + if ( !pref ) + return -1; + + int catId = pref->addPreference( moduleName(), -1 ); + if ( catId == -1 ) + return -1; + + return pref->addPreference( label, catId ); +} + +/*!Add preference to preferences.*/ +int LightApp_Module::addPreference( const QString& label, const int pId, const int type, + const QString& section, const QString& param ) +{ + LightApp_Preferences* pref = preferences(); + if ( !pref ) + return -1; + + return pref->addPreference( moduleName(), label, pId, type, section, param ); +} + +/*!Gets property of preferences.*/ +QVariant LightApp_Module::preferenceProperty( const int id, const QString& prop ) const +{ + QVariant var; + LightApp_Preferences* pref = preferences(); + if ( pref ) + var = pref->itemProperty( id, prop ); + return var; +} + +/*!Set property of preferences.*/ +void LightApp_Module::setPreferenceProperty( const int id, const QString& prop, const QVariant& var ) +{ + LightApp_Preferences* pref = preferences(); + if ( pref ) + pref->setItemProperty( id, prop, var ); +} + +/*! + * \brief Starts operation with given identifier + * \param id - identifier of operation to be started +* +* Module stores operations in map. This method starts operation by id. +* If operation isn't in map, then it will be created by createOperation method +* and will be inserted to map +*/ +void LightApp_Module::startOperation( const int id ) +{ + LightApp_Operation* op = 0; + if( myOperations.contains( id ) ) + op = myOperations[ id ]; + else + { + op = createOperation( id ); + if( op ) + { + myOperations.insert( id, op ); + op->setModule( this ); + connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) ); + connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) ); + } + } + + if( op ) + op->start(); +} + +/*! + * \brief Creates operation with given identifier + * \param id - identifier of operation to be started + * \return Pointer on created operation or NULL if operation is not created +* +* Creates operation with given id. You should not call this method, it will be called +* automatically from startOperation. You may redefine this method in concrete module to +* create operations. +*/ +LightApp_Operation* LightApp_Module::createOperation( const int id ) const +{ + if( id==-1 ) + return 0; + + if( id==myDisplay ) + return new LightApp_ShowHideOp( LightApp_ShowHideOp::DISPLAY ); + else if( id==myErase ) + return new LightApp_ShowHideOp( LightApp_ShowHideOp::ERASE ); + else if( id==myDisplayOnly ) + return new LightApp_ShowHideOp( LightApp_ShowHideOp::DISPLAY_ONLY ); + else + return 0; +} + +/*! + * \brief Virtual protected slot called when operation stopped + * \param theOp - stopped operation +* +* Virtual protected slot called when operation stopped. Redefine this slot if you want to +* perform actions after stopping operation +*/ +void LightApp_Module::onOperationStopped( SUIT_Operation* /*theOp*/ ) +{ +} + +/*! + * \brief Virtual protected slot called when operation destroyed + * \param theOp - destroyed operation +* +* Virtual protected slot called when operation destroyed. Redefine this slot if you want to +* perform actions after destroying operation. Base implementation removes pointer on +* destroyed operation from the map of operations +*/ +void LightApp_Module::onOperationDestroyed() +{ + const QObject* s = sender(); + if( s && s->inherits( "LightApp_Operation" ) ) + { + const LightApp_Operation* op = ( LightApp_Operation* )s; + MapOfOperation::const_iterator anIt = myOperations.begin(), + aLast = myOperations.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data()==op ) + { + myOperations.remove( anIt.key() ); + break; + } + } +} + +LightApp_Displayer* LightApp_Module::displayer() +{ + return 0; +} + +void LightApp_Module::onShowHide() +{ + if( !sender()->inherits( "QAction" ) || !popupMgr() ) + return; + + QAction* act = ( QAction* )sender(); + int id = actionId( act ); + if( id!=-1 ) + startOperation( id ); +} diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h new file mode 100644 index 000000000..e881547da --- /dev/null +++ b/src/LightApp/LightApp_Module.h @@ -0,0 +1,119 @@ +// File: LightApp_Module.h +// Created: 6/20/2005 16:25:06 AM +// Author: OCC team +// Copyright (C) CEA 2005 + +#ifndef LIGHTAPP_MODULE_H +#define LIGHTAPP_MODULE_H + +#include "LightApp.h" +#include + +class LightApp_Application; +class LightApp_Preferences; +class LightApp_Selection; +class LightApp_Operation; +class LightApp_SwitchOp; +class LightApp_Displayer; + +class SUIT_Study; +class SUIT_DataObject; +class SUIT_Operation; +class CAM_Application; + +class QtxPopupMgr; + +class QString; +class QVariant; + +/* + Class : LightApp_Module + Description : Base class for all light modules +*/ + +class LIGHTAPP_EXPORT LightApp_Module : public CAM_Module +{ + Q_OBJECT + +public: + LightApp_Module( const QString& ); + virtual ~LightApp_Module(); + + virtual void initialize( CAM_Application* ); + virtual void windows( QMap& ) const; + virtual void viewManagers( QStringList& ) const; + + virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& ); + + virtual void createPreferences(); + + LightApp_Application* getApp() const; + + virtual void update( const int ); + // Update viewer or/and object browser etc. in accordance with update flags + // ( see SalomeApp_UpdateFlags enumeration ). Derived modules can redefine this method + // for their own purposes + + virtual void updateObjBrowser( bool = true, SUIT_DataObject* = 0 ); + // Update object bropwser ( for updating model or whole object browser use update() method + // can be used ) + + virtual void selectionChanged(); + virtual void preferencesChanged( const QString&, const QString& ); + + virtual void studyActivated() {}; + + virtual LightApp_Displayer* displayer(); + +public slots: + virtual bool activateModule( SUIT_Study* ); + virtual bool deactivateModule( SUIT_Study* ); + + void MenuItem(); + +protected slots: + virtual void onModelSaved(); + virtual void onModelOpened(); + virtual void onModelClosed(); + + virtual void onOperationStopped( SUIT_Operation* ); + virtual void onOperationDestroyed(); + virtual void onShowHide(); + +protected: + virtual QtxPopupMgr* popupMgr(); + LightApp_Preferences* preferences() const; + + virtual CAM_DataModel* createDataModel(); + virtual LightApp_Selection* createSelection() const; + + int addPreference( const QString& label ); + int addPreference( const QString& label, const int pId, const int = -1, + const QString& section = QString::null, + const QString& param = QString::null ); + QVariant preferenceProperty( const int, const QString& ) const; + void setPreferenceProperty( const int, const QString&, const QVariant& ); + + /*! Module stores operations in map. This method starts operation by id. + * If operation isn't in map, then it will be created by createOperation method + * and will be inserted to map + */ + void startOperation( const int ); + /*! Create operation by its id. You must not call this method, it will be called automatically + * by startOperation. Please redefine this method in current module + */ + virtual LightApp_Operation* createOperation( const int ) const; + + virtual void updateControls(); + +private: + typedef QMap MapOfOperation; + +private: + QtxPopupMgr* myPopupMgr; + MapOfOperation myOperations; + LightApp_SwitchOp* mySwitchOp; + int myDisplay, myErase, myDisplayOnly; +}; + +#endif diff --git a/src/LightApp/LightApp_ModuleDlg.cxx b/src/LightApp/LightApp_ModuleDlg.cxx new file mode 100644 index 000000000..5faa1e189 --- /dev/null +++ b/src/LightApp/LightApp_ModuleDlg.cxx @@ -0,0 +1,198 @@ +// File : LightApp_ModuleDlg.cxx +// Author : Michael Zorin (mzn) +// Module : LightApp + +#include + +#include +#include +#include +#include +#include + +#ifndef WIN32 +using namespace std; +#endif + +/*!Default icon*/ +static const char* const default_icon[] = { +"48 48 17 1", +". c None", +"# c #161e4c", +"b c #1d3638", +"e c #2f585b", +"i c #345b5e", +"c c #386266", +"g c #3f7477", +"d c #4d8589", +"m c #519099", +"o c #6abbc1", +"a c #70c9d3", +"f c #79ddea", +"n c #7adff2", +"k c #7ce2f4", +"j c #993550", +"h c #d84b71", +"l c #ef537d", +"................................................", +"................................................", +"................................................", +"................................................", +"................................................", +"................########.########.########......", +"...............#aaaaaa###aaaaaa###aaaaaa##......", +"..............#aaaaaa#b#aaaaaa#b#aaaaaa#c#......", +".............########b########b########cc#......", +".............#dddddd#b#dddddd#b#dddddd#cc#......", +"...........########d########d########d#cc#......", +"..........#aaaaaa###aaaaaa###aaaaaa##d#cc#......", +".........#aaaaaa#b#aaaaaa#b#aaaaaa#c#d#cc#......", +"........########b########e########cc#d#c#.......", +"........#dddddd#b#dddddd#e#ffffff#cc#d####......", +"......########d########d########f#cc###g##......", +".....#aaaaaa###aaaaaa###hhhhhh##f#cc#gg#c#......", +"....#aaaaaa#b#aaaaaa#i#hhhhhh#j#f#cc###cc#......", +"...########b########i########jj#f#c#gg#cc#......", +"...#kkkkkk#b#kkkkkk#i#llllll#jj#f####g#cc#......", +"...#kkkkkk#b#kkkkkk#i#llllll#jj###m##g#cc#......", +"...#knnkkk#b#kkkkkk#i#llllll#jj#mm#c#g#cc#......", +"...#knnkkk#b#kkkkkk#i#llllll#jj###cc#g#c#.......", +"...#kkkkkk#b#kkkkkk#i#llllll#j#dd#cc#g####......", +"...#kkkkkk###kkkkkk###llllll####d#cc###g##......", +"...########g########g########o##d#cc#gg#c#......", +"....#gggggg#b#gggggg#b#oooooo#c#d#cc###cc#......", +"...########b########b########cc#d#c#gg#cc#......", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#d####g#cc#......", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###g##g#cc#......", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#gg#c#g#cc#......", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###cc#g#c#.......", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#c#gg#cc#g##........", +"...#kkkkkk###kkkkkk###kkkkkk####g#cc###.........", +"...########g########g########g##g#cc#...........", +"....#gggggg#b#gggggg#b#gggggg#c#g#cc#...........", +"...########b########b########cc#g#c#............", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#g##.............", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###..............", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................", +"...#kkkkkk#b#kkkkkk#b#kkkkkk#c#.................", +"...#kkkkkk###kkkkkk###kkkkkk##..................", +"...########.########.########...................", +"................................................", +"................................................", +"................................................", +"................................................"}; + +//============================================================================================================================== +/*! + * LightApp_ModuleDlg::LightApp_ModuleDlg \n + * + * Constructor. + */ +//============================================================================================================================== +LightApp_ModuleDlg::LightApp_ModuleDlg ( QWidget * parent, const QString& component, const QPixmap icon ) + : QDialog ( parent, "ActivateModuleDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) +{ + QPixmap defaultIcon( ( const char** ) default_icon ); + setCaption( tr( "CAPTION" ) ); + setSizeGripEnabled( TRUE ); + + QGridLayout* ActivateModuleDlgLayout = new QGridLayout( this ); + ActivateModuleDlgLayout->setMargin( 11 ); ActivateModuleDlgLayout->setSpacing( 6 ); + + // Module's name and icon + myComponentFrame = new QFrame( this, "myComponentFrame" ); + myComponentFrame->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding ) ); + myComponentFrame->setMinimumHeight( 100 ); + myComponentFrame->setFrameStyle( QFrame::Box | QFrame::Sunken ); + + QGridLayout* myComponentFrameLayout = new QGridLayout( myComponentFrame ); + myComponentFrameLayout->setMargin( 11 ); myComponentFrameLayout->setSpacing( 6 ); + + // --> icon + myComponentIcon = new QLabel( myComponentFrame, "myComponentIcon" ); + myComponentIcon->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + myComponentIcon->setPixmap( !icon.isNull() ? icon : defaultIcon ); + myComponentIcon->setScaledContents( false ); + myComponentIcon->setAlignment( AlignCenter ); + // --> name + myComponentLab = new QLabel( component, myComponentFrame, "myComponentLab" ); + QFont fnt = myComponentLab->font(); fnt.setBold( TRUE ); myComponentLab->setFont( fnt ); + myComponentLab->setAlignment( AlignCenter ); + + myComponentFrameLayout->addWidget( myComponentIcon, 0, 0 ); + myComponentFrameLayout->addWidget( myComponentLab, 0, 1 ); + + // Info + QVBoxLayout* infoLayout = new QVBoxLayout(); + infoLayout->setMargin( 0 ); infoLayout->setSpacing( 6 ); + + // --> top line + QFrame* myLine1 = new QFrame( this, "myLine1" ); + myLine1->setFrameStyle( QFrame::HLine | QFrame::Plain ); + // --> info label + myInfoLabel = new QLabel( tr ("ActivateComponent_DESCRIPTION"), this, "myInfoLabel" ); + myInfoLabel->setAlignment( AlignCenter ); + // --> bottom line + QFrame* myLine2 = new QFrame( this, "myLine2" ); + myLine2->setFrameStyle( QFrame::HLine | QFrame::Plain ); + + infoLayout->addStretch(); + infoLayout->addWidget( myLine1 ); + infoLayout->addWidget( myInfoLabel ); + infoLayout->addWidget( myLine2 ); + infoLayout->addStretch(); + + // Buttons + QHBoxLayout* btnLayout = new QHBoxLayout(); + btnLayout->setMargin( 0 ); btnLayout->setSpacing( 6 ); + + // --> New + myNewBtn = new QPushButton( tr( "NEW" ), this, "myNewBtn" ); + myNewBtn->setDefault( true ); myNewBtn->setAutoDefault( true ); + // --> Open + myOpenBtn = new QPushButton( tr( "OPEN" ), this, "myOpenBtn" ); + myOpenBtn->setAutoDefault( true ); + // --> Load + myLoadBtn = new QPushButton( tr( "LOAD" ), this, "myLoadBtn" ); + myLoadBtn->setAutoDefault( true ); + // --> Cancel + myCancelBtn = new QPushButton( tr( "CANCEL" ), this, "myCancelBtn" ); + myCancelBtn->setAutoDefault( true ); + + btnLayout->addWidget( myNewBtn ); + btnLayout->addWidget( myOpenBtn ); + btnLayout->addWidget( myLoadBtn ); + btnLayout->addStretch(); + btnLayout->addSpacing( 70 ); + btnLayout->addStretch(); + btnLayout->addWidget( myCancelBtn ); + + ActivateModuleDlgLayout->addWidget( myComponentFrame, 0, 0 ); + ActivateModuleDlgLayout->addLayout( infoLayout, 0, 1 ); + ActivateModuleDlgLayout->addMultiCellLayout( btnLayout, 1, 1, 0, 1 ); + + // signals and slots connections + connect( myNewBtn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); + connect( myOpenBtn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); + connect( myLoadBtn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + +//============================================================================================================================== +/*! + * LightApp_ModuleDlg::onButtonClicked + * + * Buttons slot + */ +//============================================================================================================================== +void LightApp_ModuleDlg::onButtonClicked() +{ + QPushButton* btn = ( QPushButton* )sender(); + if ( btn == myNewBtn ) + done( 1 ); + if ( btn == myOpenBtn ) + done( 2 ); + if ( btn == myLoadBtn ) + done( 3 ); +} diff --git a/src/LightApp/LightApp_ModuleDlg.h b/src/LightApp/LightApp_ModuleDlg.h new file mode 100644 index 000000000..526f16f22 --- /dev/null +++ b/src/LightApp/LightApp_ModuleDlg.h @@ -0,0 +1,45 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// Copyright (C) 2005 CEA/DEN, EDF R&D +// +// +// +// File : LightApp_ModuleDlg.h +// Author : Michael ZORIN (mzn) +// Module : SALOME + +#ifndef LIGHTAPP_MODULEDLG_H +#define LIGHTAPP_MODULEDLG_H + +#include "LightApp.h" +#include +#include + +class QFrame; +class QLabel; +class QPushButton; + +class LIGHTAPP_EXPORT LightApp_ModuleDlg : public QDialog +{ + Q_OBJECT + +public: + LightApp_ModuleDlg ( QWidget* parent, const QString& component, const QPixmap icon = QPixmap() ) ; + ~LightApp_ModuleDlg ( ) { }; + +private slots: + void onButtonClicked(); + +private: + QFrame* myComponentFrame; + QLabel* myComponentLab; + QLabel* myComponentIcon; + QLabel* myInfoLabel; + QPushButton* myNewBtn; + QPushButton* myOpenBtn; + QPushButton* myLoadBtn; + QPushButton* myCancelBtn; +}; + +#endif + diff --git a/src/LightApp/LightApp_NameDlg.cxx b/src/LightApp/LightApp_NameDlg.cxx new file mode 100644 index 000000000..daa4e31cf --- /dev/null +++ b/src/LightApp/LightApp_NameDlg.cxx @@ -0,0 +1,128 @@ +// File : LightApp_NameDlg.cxx +// Author : Vadim SANDLER +// $Header$ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifndef WIN32 +using namespace std; +#endif + +/*! + Constructor +*/ +LightApp_NameDlg::LightApp_NameDlg( QWidget* parent ) +: QDialog( parent ? parent : NULL,//application()->desktop(), +"LightApp_NameDlg", +true, +WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) +{ + setCaption( tr("TLT_RENAME") ); + setSizeGripEnabled( TRUE ); + + QVBoxLayout* topLayout = new QVBoxLayout( this ); + topLayout->setMargin( 11 ); topLayout->setSpacing( 6 ); + + /***************************************************************/ + QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" ); + GroupC1->setColumnLayout(0, Qt::Vertical ); + GroupC1->layout()->setMargin( 0 ); GroupC1->layout()->setSpacing( 0 ); + QHBoxLayout* GroupC1Layout = new QHBoxLayout( GroupC1->layout() ); + GroupC1Layout->setAlignment( Qt::AlignTop ); + GroupC1Layout->setMargin( 11 ); GroupC1Layout->setSpacing( 6 ); + + QLabel* TextLabel = new QLabel( GroupC1, "TextLabel1" ); + TextLabel->setText( tr( "NAME_LBL" ) ); + GroupC1Layout->addWidget( TextLabel ); + + myLineEdit = new QLineEdit( GroupC1, "LineEdit1" ); + myLineEdit->setMinimumSize( 250, 0 ); + GroupC1Layout->addWidget( myLineEdit ); + + /***************************************************************/ + QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); + GroupButtons->setColumnLayout(0, Qt::Vertical ); + GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 ); + QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 ); + + myButtonOk = new QPushButton( GroupButtons, "buttonOk" ); + myButtonOk->setText( tr( "BUT_OK" ) ); + myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE ); + GroupButtonsLayout->addWidget( myButtonOk ); + + GroupButtonsLayout->addStretch(); + + myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" ); + myButtonCancel->setText( tr( "BUT_CANCEL" ) ); + myButtonCancel->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( myButtonCancel ); + /***************************************************************/ + + topLayout->addWidget( GroupC1 ); + topLayout->addWidget( GroupButtons ); + + // signals and slots connections + connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); + + /* Move widget on the botton right corner of main widget */ + SUIT_Tools::centerWidget( this, parent ); +} + +/*! + Destructor +*/ +LightApp_NameDlg::~LightApp_NameDlg() +{ +} + +/*! + Sets name +*/ +void LightApp_NameDlg::setName( const QString& name ) +{ + myLineEdit->setText( name ); + myLineEdit->end(false); + myLineEdit->home(true); +} + +/*! + Returns name entered by user +*/ +QString LightApp_NameDlg::name() +{ + return myLineEdit->text(); +} + +void LightApp_NameDlg::accept() +{ + if ( name().stripWhiteSpace().isEmpty() ) + return; + QDialog::accept(); +} + +/*! + Creates modal dialog and returns name entered [ static ] +*/ +QString LightApp_NameDlg::getName( QWidget* parent, const QString& oldName ) +{ + QString n; + LightApp_NameDlg* dlg = new LightApp_NameDlg( parent ); + if ( !oldName.isNull() ) + dlg->setName( oldName ); + if ( dlg->exec() == QDialog::Accepted ) + n = dlg->name(); + delete dlg; + return n; +} diff --git a/src/LightApp/LightApp_NameDlg.h b/src/LightApp/LightApp_NameDlg.h new file mode 100644 index 000000000..c0309c0f2 --- /dev/null +++ b/src/LightApp/LightApp_NameDlg.h @@ -0,0 +1,47 @@ +// SALOME SalomeApp : implementation of desktop and GUI kernel +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : LightApp_NameDlg.h +// Author : Vadim SANDLER +// Module : SALOME +// $Header$ + +#ifndef LIGHTAPP_NAMEDLG_H +#define LIGHTAPP_NAMEDLG_H + +#include "LightApp.h" +#include + +class QLineEdit; +class QPushButton; + +//================================================================================= +// class : LightApp_NameDlg +/*! purpose : Common dialog box class*/ +//================================================================================= +class LIGHTAPP_EXPORT LightApp_NameDlg : public QDialog +{ + Q_OBJECT + +public: + LightApp_NameDlg( QWidget* parent = 0 ); + ~LightApp_NameDlg(); + + void setName( const QString& name ); + QString name(); + + static QString getName( QWidget* parent = 0, const QString& oldName = QString::null ); + +protected slots: + void accept(); + +private: + QPushButton* myButtonOk; + QPushButton* myButtonCancel; + QLineEdit* myLineEdit; +}; + +#endif // LightApp_NAMEDLG_H diff --git a/src/LightApp/LightApp_OBFilter.cxx b/src/LightApp/LightApp_OBFilter.cxx new file mode 100644 index 000000000..489ec3428 --- /dev/null +++ b/src/LightApp/LightApp_OBFilter.cxx @@ -0,0 +1,29 @@ +#include "LightApp_OBFilter.h" + +#include "LightApp_SelectionMgr.h" +#include "LightApp_DataObject.h" +#include "LightApp_DataOwner.h" + +/*! + Constructor. +*/ +LightApp_OBFilter::LightApp_OBFilter( LightApp_SelectionMgr* theSelMgr ) +{ + mySelMgr = theSelMgr; +} + +/*!Destructor.*/ +LightApp_OBFilter::~LightApp_OBFilter() +{ +} + +/*!Checks: data object is ok?*/ +bool LightApp_OBFilter::isOk( const SUIT_DataObject* theDataObj ) const +{ + const LightApp_DataObject* obj = dynamic_cast( theDataObj ); + if ( obj ) + return mySelMgr->isOk( new LightApp_DataOwner( obj->entry() ) ); + + return true; +} + diff --git a/src/LightApp/LightApp_OBFilter.h b/src/LightApp/LightApp_OBFilter.h new file mode 100644 index 000000000..21a8b674a --- /dev/null +++ b/src/LightApp/LightApp_OBFilter.h @@ -0,0 +1,22 @@ +#ifndef LIGHTAPP_OBFILTER_H +#define LIGHTAPP_OBFILTER_H + +#include "LightApp.h" +#include "OB_Filter.h" + +class LightApp_SelectionMgr; + +class LIGHTAPP_EXPORT LightApp_OBFilter: public OB_Filter +{ +public: + LightApp_OBFilter( LightApp_SelectionMgr* theSelMgr ); + ~LightApp_OBFilter(); + + virtual bool isOk( const SUIT_DataObject* ) const; + +private: + LightApp_SelectionMgr* mySelMgr; + +}; + +#endif diff --git a/src/LightApp/LightApp_OBSelector.cxx b/src/LightApp/LightApp_OBSelector.cxx new file mode 100644 index 000000000..3129b240e --- /dev/null +++ b/src/LightApp/LightApp_OBSelector.cxx @@ -0,0 +1,101 @@ +#include "LightApp_OBSelector.h" + +#include "LightApp_DataOwner.h" +#include "LightApp_DataObject.h" + +#include + +#include + +/*! + Constructor +*/ +LightApp_OBSelector::LightApp_OBSelector( OB_Browser* ob, SUIT_SelectionMgr* mgr ) +: SUIT_Selector( mgr, ob ), + myBrowser( ob ) +{ + if ( myBrowser ) { + connect( myBrowser, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); + } +} + +/*! + Destructor +*/ +LightApp_OBSelector::~LightApp_OBSelector() +{ +} + +/*! + Gets browser. +*/ +OB_Browser* LightApp_OBSelector::browser() const +{ + return myBrowser; +} + +/*! + Gets selection. +*/ +void LightApp_OBSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const +{ + if ( !myBrowser ) + return; + + DataObjectList objlist; + myBrowser->getSelected( objlist ); + for ( DataObjectListIterator it( objlist ); it.current(); ++it ) + { + LightApp_DataObject* obj = dynamic_cast( it.current() ); + if ( obj ) + { + Handle( SALOME_InteractiveObject ) aSObj = new SALOME_InteractiveObject + ( obj->entry(), obj->componentDataType(), obj->name() ); + LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj ); + theList.append( SUIT_DataOwnerPtr( owner ) ); + } + } +} + +/*!Sets selection.*/ +void LightApp_OBSelector::setSelection( const SUIT_DataOwnerPtrList& theList ) +{ + if ( !myBrowser ) + return; + + QMap themap; + fillEntries( themap ); + + DataObjectList objList; + for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) + { + const LightApp_DataOwner* owner = dynamic_cast( (*it).operator->() ); + if ( owner && themap.contains( owner->entry() ) ) + objList.append( themap[owner->entry()] ); + } + + myBrowser->setSelected( objList ); +} + +/*!On selection changed.*/ +void LightApp_OBSelector::onSelectionChanged() +{ + selectionChanged(); +} + +/*!Fill entries.*/ +void LightApp_OBSelector::fillEntries( QMap& entires ) +{ + entires.clear(); + + if ( !myBrowser ) + return; + + for ( SUIT_DataObjectIterator it( myBrowser->getRootObject(), + SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) + { + LightApp_DataObject* obj = dynamic_cast( it.current() ); + if ( obj ) + entires.insert( obj->entry(), obj ); + } +} diff --git a/src/LightApp/LightApp_OBSelector.h b/src/LightApp/LightApp_OBSelector.h new file mode 100644 index 000000000..22e4eae50 --- /dev/null +++ b/src/LightApp/LightApp_OBSelector.h @@ -0,0 +1,38 @@ +#ifndef LIGHTAPP_OBSELECTOR_H +#define LIGHTAPP_OBSELECTOR_H + +#include "LightApp.h" + +#include + +class OB_Browser; +class LightApp_DataObject; + +class LIGHTAPP_EXPORT LightApp_OBSelector : public SUIT_Selector +{ + Q_OBJECT + +public: + LightApp_OBSelector( OB_Browser*, SUIT_SelectionMgr* ); + virtual ~LightApp_OBSelector(); + + OB_Browser* browser() const; + + /*!Return "ObjectBrowser"*/ + virtual QString type() const { return "ObjectBrowser"; } + +private slots: + void onSelectionChanged(); + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); + +private: + void fillEntries( QMap& ); + +private: + OB_Browser* myBrowser; +}; + +#endif diff --git a/src/LightApp/LightApp_OCCSelector.cxx b/src/LightApp/LightApp_OCCSelector.cxx new file mode 100644 index 000000000..45b26585a --- /dev/null +++ b/src/LightApp/LightApp_OCCSelector.cxx @@ -0,0 +1,103 @@ + +#include "LightApp_DataOwner.h" +#include "LightApp_OCCSelector.h" + +#include + +#include +#include + +/*! + Constructor +*/ +LightApp_OCCSelector::LightApp_OCCSelector( OCCViewer_Viewer* viewer, SUIT_SelectionMgr* mgr ) +: SUIT_Selector( mgr, viewer ), + myViewer( viewer ) +{ + if ( myViewer ) + connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); +} + +/*! + Destructor. +*/ +LightApp_OCCSelector::~LightApp_OCCSelector() +{ +} + +/*! + Gets viewer. +*/ +OCCViewer_Viewer* LightApp_OCCSelector::viewer() const +{ + return myViewer; +} + +/*!On selection changed.*/ +void LightApp_OCCSelector::onSelectionChanged() +{ + selectionChanged(); +} + +/*!Gets selection list.*/ +void LightApp_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const +{ + if ( !myViewer ) + return; + + AIS_ListOfInteractive aSelList; + myViewer->getSelectedObjects( aSelList ); + for ( AIS_ListIteratorOfListOfInteractive anIt( aSelList ); anIt.More(); anIt.Next() ) + if ( !anIt.Value().IsNull() ) + { + Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anIt.Value()->GetOwner()); + if( !anObj.IsNull() ) + aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( anObj ) ) ); + } +} + +/*!Sets selection list.*/ +void LightApp_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList ) +{ + if ( !myViewer ) + return; + + QMap aDisplayed; + Handle(AIS_InteractiveContext) aContext = myViewer->getAISContext(); + if ( aContext.IsNull() ) + return; + + AIS_ListOfInteractive aDispList, aSelList; + aContext->DisplayedObjects( aDispList ); + + for ( AIS_ListIteratorOfListOfInteractive it( aDispList ); it.More(); it.Next() ) + { + QString entryStr = entry( it.Value() ); + if ( !entryStr.isEmpty() ) + aDisplayed.insert( entryStr, it.Value() ); + } + + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) + { + const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); + if ( owner && aDisplayed.contains( owner->entry() ) ) + aSelList.Append( aDisplayed[owner->entry()] ); + } + + myViewer->unHighlightAll( false ); + myViewer->setObjectsSelected( aSelList ); +} + +/*!Gets entry ob object.*/ +QString LightApp_OCCSelector::entry( const Handle(AIS_InteractiveObject)& anAIS ) const +{ + if ( anAIS.IsNull() || !anAIS->HasOwner() ) + return QString::null; + + Handle(SALOME_InteractiveObject) anObj = Handle(SALOME_InteractiveObject)::DownCast(anAIS->GetOwner()); + + QString res; + if ( !anObj.IsNull() ) + res = QString( anObj->getEntry() ); + return res; +} diff --git a/src/LightApp/LightApp_OCCSelector.h b/src/LightApp/LightApp_OCCSelector.h new file mode 100644 index 000000000..1d00cd0f4 --- /dev/null +++ b/src/LightApp/LightApp_OCCSelector.h @@ -0,0 +1,37 @@ +#ifndef LIGHTAPP_OCCSELECTOR_H +#define LIGHTAPP_OCCSELECTOR_H + +#include "LightApp.h" + +#include + +#include + +class Handle_AIS_InteractiveObject; + +class LIGHTAPP_EXPORT LightApp_OCCSelector : public SUIT_Selector +{ + Q_OBJECT + +public: + LightApp_OCCSelector( OCCViewer_Viewer*, SUIT_SelectionMgr* ); + virtual ~LightApp_OCCSelector(); + + OCCViewer_Viewer* viewer() const; + + virtual QString type() const { return OCCViewer_Viewer::Type(); } + +private slots: + virtual void onSelectionChanged(); + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); + + QString entry( const Handle_AIS_InteractiveObject& ) const; + +private: + OCCViewer_Viewer* myViewer; +}; + +#endif diff --git a/src/LightApp/LightApp_Operation.cxx b/src/LightApp/LightApp_Operation.cxx new file mode 100755 index 000000000..197eb93ee --- /dev/null +++ b/src/LightApp/LightApp_Operation.cxx @@ -0,0 +1,290 @@ +// LIGHT LightApp +// +// Copyright (C) 2005 CEA/DEN, EDF R&D +// +// +// +// File : LightApp_Operation.h +// Author : Sergey LITONIN +// Module : LIGHT + +#include +#include +#include +#include +#include +#include + +#include + +#include + + +/*! + * \brief Constructor +* +* Constructor sets myModule in NULL and myIsAutoResumed in TRUE +*/ +LightApp_Operation::LightApp_Operation() +: SUIT_Operation( 0 ), + myModule( 0 ), + myIsAutoResumed( true ) +{ +} + +/*! + * \brief Destructor +* +* Destructor does nothing +*/ +LightApp_Operation::~LightApp_Operation() +{ + +} + +/*! + * \brief Gets module of operation + * \return Pointer to the module +* +* Gets pointer to the module or NULL if module was not set. It is strongly recomended to +* set valid pointer on the module before start of operation +*/ +LightApp_Module* LightApp_Operation::module() const +{ + return myModule; +} + + +/*! + * \brief Sets module of operation + * \param theModule - module to be set +* +* Sets pointer to the module. It is strongly recomended to set valid pointer on the +* module before start of operation +*/ +void LightApp_Operation::setModule( LightApp_Module* theModule ) +{ + myModule = theModule; + setApplication( myModule ? myModule->application() : 0 ); + setStudy( application() ? application()->activeStudy() : 0 ); +} + +/*! + * \brief Gets desktop of operation + * \return Pointer to the desktop +* +* Gets pointer to the desktop or NULL if application was not set. It is strongly recomended +* to set valid pointer on the application before start of operation +*/ +SUIT_Desktop* LightApp_Operation::desktop() const +{ + return application() != 0 ? application()->desktop() : 0; +} + +/*! + * \brief Enable dialog of operation +* +* Virtual method redefined from the base class. Enable dialog if it was desabled (in +* suspend method) and activate selection +*/ +void LightApp_Operation::resumeOperation() +{ + SUIT_Operation::resumeOperation(); + setDialogActive( true ); +} + +/*! + * \brief Performs actions needed for starting operation +* +* Virtual method redefined from the base class. Connect signal of selection manager to +* onSelectionDone() slot +*/ +void LightApp_Operation::startOperation() +{ + if( selectionMgr() ) + connect( selectionMgr(), SIGNAL( selectionChanged() ), SLOT( onSelectionDone() ) ); + + //If suspended operation was stopped during starting other operation, + //the dialog is inactive now, We must activate it + setDialogActive( true ); +} + +/*! + * \brief Performs actions needed for suspending operation +* +* Virtual method redefined from the base class. This implementation calls corresponding +* method of base class and cals setDialogActive( false ) +*/ +void LightApp_Operation::suspendOperation() +{ + SUIT_Operation::suspendOperation(); + setDialogActive( false ); +} + +//======================================================================= +// name : abortOperation +// Purpose : Hide dialog box (if it is exists) +//======================================================================= +/*! + * \brief Performs actions needed for aborting operation +* +* Virtual method redefined from the base class calls corresponding method of base class +* and hides dialog box (if it is exists), disconnect slots from selection manager +*/ +void LightApp_Operation::abortOperation() +{ + SUIT_Operation::abortOperation(); + setDialogActive( true ); + if ( dlg() ) + dlg()->hide(); + + if( selectionMgr() ) + disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) ); +} + +/*! + * \brief Performs actions needed for committing operation +* +* Virtual method redefined from the base class calls corresponding method of base class +* and hides dialog box (if it is exists), disconnect slots from selection manager +*/ +void LightApp_Operation::commitOperation() +{ + SUIT_Operation::commitOperation(); + setDialogActive( true ); + if ( dlg() ) + dlg()->hide(); + + if( selectionMgr() ) + disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) ); +} + +/*! + * \brief Gets dialog + * \return Pointer to the dialog of this operation or NULL if it does not exist +* +* This method should be redefined in derived classes if they use dialogs. If this +* function returns pointer to dialog then dialog will be correctly +* -# deactivated in suspendOperation method +* -# activated in resumeOperation method +* -# hidden in abortOperation and commitOperation methods +*/ +LightApp_Dialog* LightApp_Operation::dlg() const +{ + return 0; +} + +/*! + * \brief Activates selection +* +* Virtual method should be redefined in derived classes if they use own selection modes +* (different from default) +*/ +void LightApp_Operation::activateSelection() +{ +} + +/*! + * \brief Virtual method called when selection is changed +* +* Virtual method should be redefined in derived classes if they works with selection +* to provide reaction on the change of selection +*/ +void LightApp_Operation::selectionDone() +{ +} + +/*! + * \brief Gets active operation +* +* This method provided for convinience calls SUIT_Study::activeOperation() one +*/ +SUIT_Operation* LightApp_Operation::activeOperation() const +{ + return study() != 0 ? study()->activeOperation() : 0; +} + +/*! + * \brief Gets selection manager +* +* This method provided for convinience calls LightApp_Application::selectionMgr() one +*/ +LightApp_SelectionMgr* LightApp_Operation::selectionMgr() const +{ + SUIT_Application* app = application(); + if ( app != 0 && app->inherits( "LightApp_Application" ) ) + return ( (LightApp_Application*)app )->selectionMgr(); + else + return 0; +} + +/*! + * \brief Call selectionDone() method +* +* Call selectionDone() method if operator is an active one (see selectionDone() for more +* description ) +*/ +void LightApp_Operation::onSelectionDone() +{ + if ( isActive() ) + selectionDone(); +} + +/*! + * \brief Update object browser or/and viewer etc. + * \param flags - update flags +* +* This method provided for convinience calls LightApp_Module::update() one (see +* LightApp_Module::update() for more description) +*/ +void LightApp_Operation::update( const int flags ) +{ + if ( myModule != 0 ) + myModule->update( flags ); +} + +/*! + * \brief Activate/Deactivate dialog of operation + * \param active - State of the dialog to be set +* +* Activate/Deactivate dialog of operation. This method called from startOperation(), +* suspendOperation() ones and so on +*/ +void LightApp_Operation::setDialogActive( const bool active ) +{ + if( dlg() ) + { + if( active ) + { + activateSelection(); + dlg()->setActiveWindow(); + } + } +} + +/*! + * \brief Gets autoresume property + * \return Autoresume property. +* +* Autoresume property is used during automatic resuming operation. If operation is +* suspended and cursor is moved above dialog of the operation then operation is resumed +* automatically (if possible). It can be resumed only program call otherwise (see +* LightApp_SwitchOp for more description). This property is TRUE by default and may be +* changed with setAutoResumed() method call. +*/ +bool LightApp_Operation::isAutoResumed() const +{ + return myIsAutoResumed; +} + +/*! + * \brief Sets autoresume property + * \param on - Value to be set + * \return Autoresume property. +* +* Sets autoresume property (see isAutoResumed() for more description) +*/ +void LightApp_Operation::setAutoResumed( const bool on ) +{ + myIsAutoResumed = on; +} diff --git a/src/LightApp/LightApp_Operation.h b/src/LightApp/LightApp_Operation.h new file mode 100755 index 000000000..4b07bd7b2 --- /dev/null +++ b/src/LightApp/LightApp_Operation.h @@ -0,0 +1,91 @@ +// LIGHT LightApp +// +// Copyright (C) 2005 CEA/DEN, EDF R&D +// +// +// +// File : LightApp_Operation.h +// Author : Sergey LITONIN +// Module : LIGHT + + +#ifndef LightApp_Operation_H +#define LightApp_Operation_H + +#include "LightApp.h" +#include + +class LightApp_Module; +class LightApp_Application; +class LightApp_Operation; +class LightApp_SelectionMgr; +class LightApp_Dialog; +class SUIT_Desktop; + +/* + Class : LightApp_Operation + Description : Base class for all operations +*/ + +/*! + * \brief Base class for all operations + * + * Base class for all operations (see SUIT_Operation for more description) +*/ +class LIGHTAPP_EXPORT LightApp_Operation : public SUIT_Operation +{ + Q_OBJECT + +public: + LightApp_Operation(); + virtual ~LightApp_Operation(); + + virtual void setModule( LightApp_Module* ); + LightApp_Module* module() const; + + bool isAutoResumed() const; + + virtual LightApp_Dialog* dlg() const; + +protected: + + // Methods redefined from base class + + virtual void startOperation(); + virtual void suspendOperation(); + virtual void resumeOperation(); + virtual void abortOperation(); + virtual void commitOperation(); + + // Additional virtual methods may be redefined by derived classes + + virtual void setDialogActive( const bool ); + virtual void activateSelection(); + virtual void selectionDone(); + + + // Axiluary methods + + SUIT_Desktop* desktop() const; + SUIT_Operation* activeOperation() const; + LightApp_SelectionMgr* selectionMgr() const; + void update( const int ); + void setAutoResumed( const bool ); + +private slots: + + virtual void onSelectionDone(); + +private: + + LightApp_Module* myModule; + bool myIsAutoResumed; +}; + +#endif + + + + + + diff --git a/src/LightApp/LightApp_Preferences.cxx b/src/LightApp/LightApp_Preferences.cxx new file mode 100644 index 000000000..95ea10457 --- /dev/null +++ b/src/LightApp/LightApp_Preferences.cxx @@ -0,0 +1,87 @@ +// File: LightApp_Preferences.cxx +// Author: Sergey TELKOV + +#include "LightApp_Preferences.h" + +#include + +#include + +/*! + Constructor.Initialize by resource manager and parent QWidget. +*/ +LightApp_Preferences::LightApp_Preferences( QtxResourceMgr* resMgr, QWidget* parent ) +: QtxListResourceEdit( resMgr, parent ) +{ +} + +/*! + Destructor. +*/ +LightApp_Preferences::~LightApp_Preferences() +{ +} + +/*! + Adds preference. +*/ +int LightApp_Preferences::addPreference( const QString& label, const int pId, const int type, + const QString& section, const QString& param ) +{ + return addItem( label, pId, type, section, param ); +} + +/*! + Adds preference. +*/ +int LightApp_Preferences::addPreference( const QString& mod, const QString& label, const int pId, + const int type, const QString& section, const QString& param ) +{ + int id = addItem( label, pId, type, section, param ); + if ( id != -1 && !mod.isEmpty() ) + myPrefMod.insert( id, mod ); + return id; +} + +/* + Checks: is preferences has module with name \a mod. +*/ +bool LightApp_Preferences::hasModule( const QString& mod ) const +{ + bool res = false; + for ( PrefModuleMap::ConstIterator it = myPrefMod.begin(); it != myPrefMod.end() && !res; ++it ) + res = it.data() == mod; + return res; +} + +/*!Do nothing.*/ +void LightApp_Preferences::onHelp() +{ +} + +/*!Store preferences on apply.*/ +void LightApp_Preferences::onApply() +{ + store(); +} + +/*!Emit preference changed.*/ +void LightApp_Preferences::changedResources( const QMap& map ) +{ + for ( QMap::ConstIterator it = map.begin(); it != map.end(); ++it ) + { + QString sec, param; + it.key()->resource( sec, param ); + QString mod = module( it.key()->id() ); + emit preferenceChanged( mod, sec, param ); + } +} + +/*!Gets module name by \a id, if exist.*/ +QString LightApp_Preferences::module( const int id ) const +{ + QString mod; + if ( myPrefMod.contains( id ) ) + mod = myPrefMod[id]; + return mod; +} diff --git a/src/LightApp/LightApp_Preferences.h b/src/LightApp/LightApp_Preferences.h new file mode 100644 index 000000000..75655e1ec --- /dev/null +++ b/src/LightApp/LightApp_Preferences.h @@ -0,0 +1,49 @@ +// File: LightApp_Preferences.h +// Author: Sergey TELKOV + +#ifndef LIGHTAPP_PREFERENCES_H +#define LIGHTAPP_PREFERENCES_H + +#include + +#include +#include + +#include + +class QtxResourceMgr; + +class LIGHTAPP_EXPORT LightApp_Preferences : public QtxListResourceEdit +{ + Q_OBJECT + +public: + LightApp_Preferences( QtxResourceMgr*, QWidget* = 0 ); + virtual ~LightApp_Preferences(); + + int addPreference( const QString& label, const int pId = -1, const int = -1, + const QString& section = QString::null, const QString& param = QString::null ); + int addPreference( const QString& modName, const QString& label, const int pId = -1, const int = -1, + const QString& section = QString::null, const QString& param = QString::null ); + + bool hasModule( const QString& ) const; + +signals: + void preferenceChanged( QString&, QString&, QString& ); + +private slots: + void onHelp(); + void onApply(); + virtual void changedResources( const QMap& ); + +private: + QString module( const int ) const; + +private: + typedef QMap PrefModuleMap; + +private: + PrefModuleMap myPrefMod; +}; + +#endif diff --git a/src/LightApp/LightApp_PreferencesDlg.cxx b/src/LightApp/LightApp_PreferencesDlg.cxx new file mode 100644 index 000000000..12815c4a5 --- /dev/null +++ b/src/LightApp/LightApp_PreferencesDlg.cxx @@ -0,0 +1,84 @@ +// File: LightApp_PreferencesDlg.cxx +// Author: Sergey TELKOV + +#include "LightApp_PreferencesDlg.h" + +#include "LightApp_Preferences.h" + +#include +#include + +/*! + Constructor. +*/ +LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent ) +: QtxDialog( parent, 0, true, false, OK | Close | Apply ), +myPrefs( prefs ) +{ + setCaption( tr( "CAPTION" ) ); + + QVBoxLayout* main = new QVBoxLayout( mainFrame(), 5 ); + + QVBox* base = new QVBox( mainFrame() ); + main->addWidget( base ); + + myPrefs->reparent( base, QPoint( 0, 0 ), true ); + + setFocusProxy( myPrefs ); + + setButtonPosition( Right, Close ); + + setDialogFlags( AlignOnce ); + + connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) ); + connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) ); +} + +/*! + Destructor. +*/ +LightApp_PreferencesDlg::~LightApp_PreferencesDlg() +{ + if ( !myPrefs ) + return; + + myPrefs->reparent( 0, QPoint( 0, 0 ), false ); + myPrefs = 0; +} + +/*!Show dialog.*/ +void LightApp_PreferencesDlg::show() +{ + myPrefs->retrieve(); + myPrefs->toBackup(); + + QtxDialog::show(); +} + +/*!Store preferences on accept.*/ +void LightApp_PreferencesDlg::accept() +{ + QtxDialog::accept(); + + myPrefs->store(); +} + +/*!Reject. Restore preferences from backup.*/ +void LightApp_PreferencesDlg::reject() +{ + QtxDialog::reject(); + + myPrefs->fromBackup(); +} + +/*!Do nothing.*/ +void LightApp_PreferencesDlg::onHelp() +{ +} + +/*!Store preferences on apply.*/ +void LightApp_PreferencesDlg::onApply() +{ + myPrefs->store(); + myPrefs->toBackup(); +} diff --git a/src/LightApp/LightApp_PreferencesDlg.h b/src/LightApp/LightApp_PreferencesDlg.h new file mode 100644 index 000000000..9ccaafd35 --- /dev/null +++ b/src/LightApp/LightApp_PreferencesDlg.h @@ -0,0 +1,33 @@ +// File: LightApp_PreferencesDlg.h +// Author: Sergey TELKOV + +#ifndef LIGHTAPP_PREFERENCESDLG_H +#define LIGHTAPP_PREFERENCESDLG_H + +#include + +#include + +class LightApp_Preferences; + +class LIGHTAPP_EXPORT LightApp_PreferencesDlg : public QtxDialog +{ + Q_OBJECT + +public: + LightApp_PreferencesDlg( LightApp_Preferences*, QWidget* = 0 ); + virtual ~LightApp_PreferencesDlg(); + + virtual void show(); + virtual void accept(); + virtual void reject(); + +private slots: + void onHelp(); + void onApply(); + +private: + LightApp_Preferences* myPrefs; +}; + +#endif diff --git a/src/LightApp/LightApp_RootObject.h b/src/LightApp/LightApp_RootObject.h new file mode 100644 index 000000000..38ca460f9 --- /dev/null +++ b/src/LightApp/LightApp_RootObject.h @@ -0,0 +1,33 @@ +#ifndef LIGHTAPP_ROOTOBJECT_H +#define LIGHTAPP_ROOTOBJECT_H + +#include "LightApp.h" +#include "SUIT_DataObject.h" + +class LightApp_Study; + +/*! + LightApp_RootObject - class to be instanciated by only one object - + root object of LightApp data object tree. This object is not shown + in object browser (invisible), so it has no re-definition of name(), icon(), + etc. methods. The goal of this class is to provide a unified access + to LightApp_Study object from LightApp_DataObject instances. +*/ +class LIGHTAPP_EXPORT LightApp_RootObject : public SUIT_DataObject +{ +public: + LightApp_RootObject( LightApp_Study* study ) + : myStudy( study ) + {} + + virtual ~LightApp_RootObject() {} + + void setStudy( LightApp_Study* study ) { myStudy = study; } + LightApp_Study* study() const { return myStudy; } + +private: + LightApp_Study* myStudy; + +}; + +#endif diff --git a/src/LightApp/LightApp_Selection.cxx b/src/LightApp/LightApp_Selection.cxx new file mode 100644 index 000000000..bf2d2198b --- /dev/null +++ b/src/LightApp/LightApp_Selection.cxx @@ -0,0 +1,177 @@ + +#include "LightApp_Selection.h" +#include "LightApp_SelectionMgr.h" +#include "LightApp_DataOwner.h" +#include "LightApp_Study.h" +#include "LightApp_Application.h" +#include "LightApp_Displayer.h" + +#include "SUIT_Session.h" +#include "SUIT_ViewWindow.h" + +/*! + Constructor +*/ +LightApp_Selection::LightApp_Selection() +: myStudy( 0 ) +{ +} + +/*! + Destructor. +*/ +LightApp_Selection::~LightApp_Selection() +{ +} + +/*! + Initializetion. +*/ +void LightApp_Selection::init( const QString& client, LightApp_SelectionMgr* mgr) +{ + myPopupClient = client; + + if( mgr ) + { + if ( mgr->application() ) + myStudy = dynamic_cast( mgr->application()->activeStudy() ); + if ( !myStudy ) + return; + + SUIT_DataOwnerPtrList sel; + mgr->selected( sel, client ); + SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(), aLast = sel.end(); + + QString entry, curEntry; + for( ; anIt!=aLast; anIt++ ) + { + SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() ); + LightApp_DataOwner* sowner = dynamic_cast( owner ); + if( sowner ) { + curEntry = sowner->entry(); + entry = myStudy->referencedToEntry( curEntry ); + myEntries.append( entry ); + if ( curEntry == entry ) + myIsReferences.append( true ); + else + myIsReferences.append( false ); + processOwner( sowner ); + } + } + } +} + +/*! + Gets count of entries. +*/ +int LightApp_Selection::count() const +{ + return myEntries.count(); +} + +/*! + Gets QtxValue(); +*/ +QtxValue LightApp_Selection::param( const int ind, const QString& p ) const +{ + if( !( ind>=0 && indcomponentDataType( myEntries[ ind ] ); + } + else if( p=="isReference" ) + return QtxValue( isReference( ind ), false ); + + return QtxValue(); +} + +/*! + Gets global parameters. client, isActiveView, activeView etc. +*/ +QtxValue LightApp_Selection::globalParam( const QString& p ) const +{ + if ( p == "client" ) return QtxValue( myPopupClient ); + else if ( p == "activeModule" ) + { + LightApp_Application* app = dynamic_cast( myStudy->application() ); + QString mod_name = app ? QString( app->activeModule()->name() ) : QString::null; + //cout << "activeModule : " << mod_name.latin1() << endl; + if( !mod_name.isEmpty() ) + return mod_name; + else + return QtxValue(); + } + else if ( p == "isActiveView" ) return QtxValue( (bool)activeVW() ); + else if ( p == "activeView" ) return QtxValue( activeViewType() ); +#ifndef WNT + else return QtxPopupMgr::Selection::globalParam( p ); +#else + else return Selection::globalParam( p ); +#endif +} + +/*! + Do nothing. +*/ +void LightApp_Selection::processOwner( const LightApp_DataOwner* ) +{ +} + +/*! + Gets entry with index \a index. +*/ +QString LightApp_Selection::entry( const int index ) const +{ + if ( index >= 0 && index < count() ) + return myEntries[ index ]; + return QString(); +} + +/*! + Returns true if i-th selected object was reference to object with entry( i ) +*/ +bool LightApp_Selection::isReference( const int index ) const +{ + if( index >= 0 && index < count() ) + return myIsReferences[ index ]; + else + return false; +} + +/*! + Gets type of active view manager. +*/ +QString LightApp_Selection::activeViewType() const +{ + SUIT_ViewWindow* win = activeVW(); + if ( win ) { + SUIT_ViewManager* vm = win->getViewManager(); + if ( vm ) + return vm->getType(); + } + return QString::null; +} + +/*! + Gets active view window. +*/ +SUIT_ViewWindow* LightApp_Selection::activeVW() const +{ + SUIT_Session* session = SUIT_Session::session(); + if ( session ) { + SUIT_Application* app = session->activeApplication(); + if ( app ) { + SUIT_Desktop* desk = app->desktop(); + if ( desk ) + return desk->activeWindow(); + } + } + return 0; +} diff --git a/src/LightApp/LightApp_Selection.h b/src/LightApp/LightApp_Selection.h new file mode 100644 index 000000000..fc92b8ca5 --- /dev/null +++ b/src/LightApp/LightApp_Selection.h @@ -0,0 +1,70 @@ +// LightApp_Selection +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : LightApp_Selection.h +// Author : Alexander SOLOVYOV +// Module : GUI +// $Header$ + +#ifndef LIGHTAPP_SELECTION_HeaderFile +#define LIGHTAPP_SELECTION_HeaderFile + +#include "LightApp.h" +#include + +class LightApp_SelectionMgr; +class LightApp_DataOwner; +class LightApp_Study; +class SUIT_ViewWindow; + + +class LIGHTAPP_EXPORT LightApp_Selection : public QtxPopupMgr::Selection +{ +public: + LightApp_Selection(); + virtual ~LightApp_Selection(); + + virtual void init( const QString&, LightApp_SelectionMgr* ); + virtual void processOwner( const LightApp_DataOwner* ); + + virtual int count() const; + virtual QtxValue param( const int, const QString& ) const; + virtual QtxValue globalParam( const QString& ) const; + void setModuleName( const QString ); + +protected: + QString entry( const int ) const; + bool isReference( const int ) const; + /*!Gets study.*/ + LightApp_Study* study() const { return myStudy; } + QString activeViewType() const; + SUIT_ViewWindow* activeVW() const; + +protected: + QString myPopupClient; + QStringList myEntries; // entries of selected objects + QValueList myIsReferences; // whether i-th selected object was a reference + LightApp_Study* myStudy; +}; + +#endif diff --git a/src/LightApp/LightApp_SelectionMgr.cxx b/src/LightApp/LightApp_SelectionMgr.cxx new file mode 100644 index 000000000..5c9b48f0a --- /dev/null +++ b/src/LightApp/LightApp_SelectionMgr.cxx @@ -0,0 +1,271 @@ +#include "LightApp_SelectionMgr.h" + +#include "LightApp_Study.h" +#include "LightApp_DataOwner.h" +#include "LightApp_DataSubOwner.h" +#include "LightApp_Application.h" + +#include + +#include +#include + +// Open CASCADE Include +#include +#include +#include + +/*! + Constructor. +*/ +LightApp_SelectionMgr::LightApp_SelectionMgr( LightApp_Application* app, const bool fb ) +: SUIT_SelectionMgr( fb ), +myApp( app ) +{ +} + +/*! + Destructor. +*/ +LightApp_SelectionMgr::~LightApp_SelectionMgr() +{ +} + +/*! + Gets application. +*/ +LightApp_Application* LightApp_SelectionMgr::application() const +{ + return myApp; +} + +/*! + Get all selected objects from selection manager +*/ +void LightApp_SelectionMgr::selectedObjects( SALOME_ListIO& theList, const QString& theType, + const bool convertReferences ) const +{ + theList.Clear(); + + SUIT_DataOwnerPtrList aList; + selected( aList, theType ); + + QMap entryMap; + + QString entry; + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) + { + const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); + if( !owner ) + continue; + + LightApp_Study* study = dynamic_cast( application()->activeStudy() ); + if ( !study ) + return; + + entry = owner->entry(); + if ( convertReferences ) { + QString refEntry = study->referencedToEntry( entry ); + if( !entryMap.contains( entry ) ) { + if ( refEntry != entry ) { + QString component = study->componentDataType( refEntry ); + theList.Append( new SALOME_InteractiveObject( refEntry, component, ""/*refobj->Name().c_str()*/ ) ); + } + else + theList.Append( owner->IO() ); + } + } + else { + if( !entryMap.contains( entry ) ) + theList.Append( owner->IO() ); + } + + entryMap.insert(owner->entry(), 1); + } +} + +/*! + Append selected objects. +*/ +void LightApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append ) +{ + SUIT_DataOwnerPtrList owners; + for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() ) + { + if ( it.Value()->hasEntry() ) + owners.append( new LightApp_DataOwner( it.Value() ) ); + } + + setSelected( owners, append ); +} + +/*! + Emit current selection changed. +*/ +void LightApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel ) +{ + SUIT_SelectionMgr::selectionChanged( theSel ); + + emit currentSelectionChanged(); +} + +/*! + get map of indexes for the given SALOME_InteractiveObject +*/ +void LightApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject, + TColStd_IndexedMapOfInteger& theIndex) +{ + theIndex.Clear(); + + SUIT_DataOwnerPtrList aList; + selected( aList ); + + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) + { + const LightApp_DataSubOwner* subOwner = dynamic_cast( (*itr).operator->() ); + if ( subOwner ) + if ( subOwner->entry() == QString(IObject->getEntry()) ) + theIndex.Add( subOwner->index() ); + } + +} + +/*! + get map of indexes for the given entry of SALOME_InteractiveObject +*/ +void LightApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex ) +{ + theIndex.Clear(); + + SUIT_DataOwnerPtrList aList; + selected( aList ); + + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) + { + const LightApp_DataSubOwner* subOwner = dynamic_cast( (*itr).operator->() ); + if ( subOwner ) + if ( subOwner->entry() == theEntry ) + theIndex.Add( subOwner->index() ); + } + +} + +/*! + Add or remove interactive objects from selection manager. +*/ +bool LightApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, + const TColStd_MapOfInteger& theIndexes, + bool modeShift) +{ + SUIT_DataOwnerPtrList remainsOwners; + + SUIT_DataOwnerPtrList aList; + selected( aList ); + + if ( !modeShift ) { + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) + { + const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); + if ( owner ) + { + if ( owner->entry() != QString(IObject->getEntry()) ) + { + const LightApp_DataSubOwner* subOwner = dynamic_cast( owner ); + if ( subOwner ) + remainsOwners.append( new LightApp_DataSubOwner( subOwner->entry(), subOwner->index() ) ); + else + remainsOwners.append( new LightApp_DataOwner( owner->entry() ) ); + } + } + } + } + else + remainsOwners = aList; + + TColStd_MapIteratorOfMapOfInteger It; + It.Initialize(theIndexes); + for(;It.More();It.Next()) + remainsOwners.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) ); + + bool append = false; + setSelected( remainsOwners, append ); + + emit currentSelectionChanged(); + + TColStd_IndexedMapOfInteger anIndexes; + GetIndexes( IObject, anIndexes ); + return !anIndexes.IsEmpty(); + +} + +/*! + select 'subobjects' with given indexes +*/ +void LightApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject, + TColStd_IndexedMapOfInteger theIndex, bool append ) +{ + SUIT_DataOwnerPtrList aList; + + if ( theIndex.IsEmpty() ) + aList.append( new LightApp_DataOwner( QString(IObject->getEntry()) ) ); + else + { + int i; + for ( i = 1; i <= theIndex.Extent(); i++ ) + aList.append( new LightApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) ); + } + + setSelected( aList, append ); + +} + +/*! + select 'subobjects' with given indexes +*/ +void LightApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append ) +{ + SUIT_DataOwnerPtrList aList; + + MapIOOfMapOfInteger::Iterator it; + for ( it = theMapIO.begin(); it != theMapIO.end(); ++it ) + { + if ( it.data().IsEmpty() ) + aList.append( new LightApp_DataOwner( QString(it.key()->getEntry()) ) ); + else + { + int i; + for ( i = 1; i <= it.data().Extent(); i++ ) + aList.append( new LightApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) ); + } + } + + setSelected( aList, append ); + +} + +/*! + get map of selected subowners : object's entry <-> map of indexes +*/ +void LightApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap ) +{ + theMap.clear(); + + TColStd_IndexedMapOfInteger anIndexes; + + SUIT_DataOwnerPtrList aList; + selected( aList ); + + for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr ) + { + const LightApp_DataSubOwner* subOwner = dynamic_cast( (*itr).operator->() ); + if ( subOwner ) + { + if ( !theMap.contains( subOwner->entry() ) ) + { + anIndexes.Clear(); + GetIndexes( subOwner->entry(), anIndexes ); + theMap.insert( subOwner->entry(), anIndexes ); + } + } + } +} diff --git a/src/LightApp/LightApp_SelectionMgr.h b/src/LightApp/LightApp_SelectionMgr.h new file mode 100644 index 000000000..7f69ed6bf --- /dev/null +++ b/src/LightApp/LightApp_SelectionMgr.h @@ -0,0 +1,57 @@ +#ifndef LIGHTAPP_SELECTIONMGR_H +#define LIGHTAPP_SELECTIONMGR_H + +#include "LightApp.h" + +#include +#include + +#include + +class SALOME_ListIO; +class LightApp_Application; +class TColStd_IndexedMapOfInteger; +class TColStd_MapOfInteger; + +class LIGHTAPP_EXPORT LightApp_SelectionMgr : public SUIT_SelectionMgr +{ + Q_OBJECT + +public: + LightApp_SelectionMgr( LightApp_Application*, const bool = true ); + virtual ~LightApp_SelectionMgr(); + + typedef QMap< Handle(SALOME_InteractiveObject), TColStd_IndexedMapOfInteger > MapIOOfMapOfInteger; + typedef QMap< QString, TColStd_IndexedMapOfInteger > MapEntryOfMapOfInteger; + + LightApp_Application* application() const; + + void selectedObjects( SALOME_ListIO&, const QString& = QString::null, const bool = true ) const; + void setSelectedObjects( const SALOME_ListIO&, const bool = false ); + + void GetIndexes( const Handle(SALOME_InteractiveObject)& IObject, + TColStd_IndexedMapOfInteger& theIndex ); + void GetIndexes( const QString& theEntry, + TColStd_IndexedMapOfInteger& theIndex ); + + bool AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, + const TColStd_MapOfInteger& theIndices, + bool modeShift ); + + void selectObjects( const Handle(SALOME_InteractiveObject)& IObject, + TColStd_IndexedMapOfInteger theIndex, bool append ); + void selectObjects( MapIOOfMapOfInteger theMapIO, bool append ); + + void selectedSubOwners( MapEntryOfMapOfInteger& theMap ); + +signals: + void currentSelectionChanged(); + +private: + virtual void selectionChanged( SUIT_Selector* ); + +private: + LightApp_Application* myApp; +}; + +#endif diff --git a/src/LightApp/LightApp_ShowHideOp.cxx b/src/LightApp/LightApp_ShowHideOp.cxx new file mode 100644 index 000000000..6d2ae9d56 --- /dev/null +++ b/src/LightApp/LightApp_ShowHideOp.cxx @@ -0,0 +1,80 @@ + +#include "LightApp_ShowHideOp.h" +#include "LightApp_Application.h" +#include "LightApp_DataOwner.h" +#include "LightApp_Module.h" +#include "LightApp_Displayer.h" +#include "CAM_Study.h" + +#include "LightApp_SelectionMgr.h" +#include "LightApp_Selection.h" + +#include +#include + +LightApp_ShowHideOp::LightApp_ShowHideOp( ActionType type ) +: LightApp_Operation(), + myActionType( type ) +{ +} + +LightApp_ShowHideOp::~LightApp_ShowHideOp() +{ +} + +void LightApp_ShowHideOp::startOperation() +{ + LightApp_Application* app = dynamic_cast( application() ); + if( !app ) + { + abort(); + return; + } + + LightApp_SelectionMgr* mgr = app->selectionMgr(); + LightApp_Selection sel; sel.init( "", mgr ); + if( sel.count()==0 ) + { + abort(); + return; + } + QString aStr = sel.param( 0, "component" ).toString(); + QString mod_name = app->moduleTitle( aStr );//sel.param( 0, "component" ).toString() ); + LightApp_Module* m = dynamic_cast( app ? app->module( mod_name ) : 0 ); + if( !m ) + { + m = dynamic_cast( app->loadModule( mod_name ) ); + app->addModule( m ); + m->connectToStudy( dynamic_cast( app->activeStudy() ) ); + m->setMenuShown( false ); + m->setToolShown( false ); + } + + LightApp_Displayer* d = m ? m->displayer(): 0; + if( !d ) + { + abort(); + return; + } + + if( myActionType==DISPLAY_ONLY ) + d->EraseAll( false, false, 0 ); + + SALOME_ListIO selObjs; + mgr->selectedObjects( selObjs ); + SALOME_ListIteratorOfListIO anIt( selObjs ); + for( ; anIt.More(); anIt.Next() ) + { + if( anIt.Value().IsNull() ) + + continue; + + if( myActionType==DISPLAY || myActionType==DISPLAY_ONLY ) + d->Display( anIt.Value()->getEntry(), false, 0 ); + else if( myActionType==ERASE ) + d->Erase( anIt.Value()->getEntry(), false, false, 0 ); + } + d->UpdateViewer(); + commit(); +} + diff --git a/src/LightApp/LightApp_ShowHideOp.h b/src/LightApp/LightApp_ShowHideOp.h new file mode 100644 index 000000000..7f2667f71 --- /dev/null +++ b/src/LightApp/LightApp_ShowHideOp.h @@ -0,0 +1,26 @@ + +#ifndef LIGHTAPP_SHOW_HIDE_OPERATION_HEADER +#define LIGHTAPP_SHOW_HIDE_OPERATION_HEADER + +#include "LightApp_Operation.h" + +class LightApp_ShowHideOp : public LightApp_Operation +{ + Q_OBJECT + +public: + typedef enum { DISPLAY, ERASE, DISPLAY_ONLY } ActionType; + +public: + LightApp_ShowHideOp( ActionType ); + ~LightApp_ShowHideOp(); + +protected: + virtual void startOperation(); + +private: + ActionType myActionType; +}; + +#endif + diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx new file mode 100644 index 000000000..9b05ef2b2 --- /dev/null +++ b/src/LightApp/LightApp_Study.cxx @@ -0,0 +1,393 @@ +#include "LightApp_Study.h" + +#include "CAM_DataModel.h" +#include "LightApp_Application.h" +#include "LightApp_DataModel.h" +#include "LightApp_DataObject.h" +#include "LightApp_RootObject.h" +#include "LightApp_Driver.h" + +#include "SUIT_ResourceMgr.h" +#include "SUIT_DataObjectIterator.h" + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/*! + Constructor. +*/ +LightApp_Study::LightApp_Study( SUIT_Application* app ) +: CAM_Study( app ) +{ + myDriver = new LightApp_Driver(); +} + +/*! + Destructor. +*/ +LightApp_Study::~LightApp_Study() +{ +} + +/*! + Create document. +*/ +void LightApp_Study::createDocument() +{ + // create myRoot + setRoot( new LightApp_RootObject( this ) ); + + CAM_Study::createDocument(); + + emit created( this ); +} + +//======================================================================= +// name : openDocument +/*! Purpose : Open document*/ +//======================================================================= +bool LightApp_Study::openDocument( const QString& theFileName ) +{ + myDriver->ClearDriverContents(); + // create files for models from theFileName + if( !openStudyData(theFileName)) + return false; + + setRoot( new LightApp_RootObject( this ) ); // create myRoot + + // update loaded data models: call open() and update() on them. + ModelList dm_s; + dataModels( dm_s ); + for ( ModelListIterator it( dm_s ); it.current(); ++it ) + openDataModel( studyName(), it.current() ); + // this will build a SUIT_DataObject-s tree under myRoot member field + // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step + // but tree that corresponds to not-loaded data models will be updated any way. + ((LightApp_Application*)application())->updateObjectBrowser( false ); + + bool res = CAM_Study::openDocument( theFileName ); + + emit opened( this ); + return res; +} + +//======================================================================= +// name : loadDocument +/*! Purpose : Load document */ +//======================================================================= +bool LightApp_Study::loadDocument( const QString& theStudyName ) +{ + myDriver->ClearDriverContents(); + if( !openStudyData(theStudyName)) + return false; + + setRoot( new LightApp_RootObject( this ) ); // create myRoot + + //SRN: BugID IPAL9021, put there the same code as in a method openDocument + + // update loaded data models: call open() and update() on them. + ModelList dm_s; + dataModels( dm_s ); + + for ( ModelListIterator it( dm_s ); it.current(); ++it ) + openDataModel( studyName(), it.current() ); + + // this will build a SUIT_DataObject-s tree under myRoot member field + // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step + // but tree that corresponds to not-loaded data models will be updated any way. + ((LightApp_Application*)application())->updateObjectBrowser( false ); + + bool res = CAM_Study::openDocument( theStudyName ); + emit opened( this ); + //SRN: BugID IPAL9021: End + return res; +} + +//======================================================================= +// name : saveDocumentAs +/*! Purpose : Save document */ +//======================================================================= +bool LightApp_Study::saveDocumentAs( const QString& theFileName ) +{ + ModelList list; dataModels( list ); + + LightApp_DataModel* aModel = (LightApp_DataModel*)list.first(); + + myDriver->ClearDriverContents(); + QStringList listOfFiles; + for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) { + listOfFiles.clear(); + aModel->saveAs( theFileName, this, listOfFiles ); + if ( !listOfFiles.isEmpty() ) + saveModuleData(aModel->module()->name(), listOfFiles); + } + + bool res = saveStudyData(theFileName); + res = res && CAM_Study::saveDocumentAs( theFileName ); + //SRN: BugID IPAL9377, removed usage of uninitialized variable + if ( res ) + emit saved( this ); + + return res; +} + +//======================================================================= +// name : saveDocument +/*! Purpose : Save document */ +//======================================================================= +bool LightApp_Study::saveDocument() +{ + ModelList list; dataModels( list ); + + LightApp_DataModel* aModel = (LightApp_DataModel*)list.first(); + + myDriver->ClearDriverContents(); + QStringList listOfFiles; + for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) { + listOfFiles.clear(); + aModel->save( listOfFiles ); + saveModuleData(aModel->module()->name(), listOfFiles); + } + + bool res = saveStudyData(studyName()); + res = res && CAM_Study::saveDocument(); + if (res) + emit saved( this ); + + return res; +} + +//================================================================ +// Function : closeDocument +/*! Purpose : Close document */ +//================================================================ +void LightApp_Study::closeDocument(bool permanently) +{ + // Inform everybody that this study is going to close when it's most safe to, + // i.e. in the very beginning + emit closed( this ); + + CAM_Study::closeDocument(permanently); +} + +//================================================================ +// Function : referencedToEntry +/*! Purpose : Return current entry*/ +//================================================================ +QString LightApp_Study::referencedToEntry( const QString& entry ) +{ + return entry; +} +//================================================================ +// Function : componentDataType +/*! Purpose : Return component data type from entry*/ +//================================================================ +QString LightApp_Study::componentDataType( const QString& entry ) +{ + LightApp_DataObject* aCurObj; + for ( SUIT_DataObjectIterator it( root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) { + aCurObj = dynamic_cast( it.current() ); + if ( aCurObj && aCurObj->entry() == entry ) { + return aCurObj->componentDataType(); + } + } + return ""; +} + +//================================================================ +// Function : isModified +// Purpose : +//================================================================ +bool LightApp_Study::isModified() const +{ + bool isAnyChanged = CAM_Study::isModified(); + ModelList list; dataModels( list ); + + LightApp_DataModel* aModel = 0; + for ( QPtrListIterator it( list ); it.current() && !isAnyChanged; ++it ){ + aModel = dynamic_cast( it.current() ); + if ( aModel ) + isAnyChanged = aModel->isModified(); + } + return isAnyChanged; +} + +//================================================================ +// Function : isSaved +/*! Purpose : Check: data model is saved?*/ +//================================================================ +bool LightApp_Study::isSaved() const +{ + bool isAllSaved = CAM_Study::isSaved(); + ModelList list; dataModels( list ); + + LightApp_DataModel* aModel = 0; + for ( QPtrListIterator it( list ); it.current() && isAllSaved; ++it ){ + aModel = dynamic_cast( it.current() ); + if ( aModel ) + isAllSaved = aModel->isSaved(); + } + return isAllSaved; +} + +//======================================================================= +// name : saveModuleData +/*! Purpose : Create SComponent for module, necessary for SalomeApp study */ +//======================================================================= +void LightApp_Study::addComponent(const CAM_DataModel* dm) +{ +} + +//======================================================================= +// name : saveModuleData +/*! Purpose : save list file for module 'theModuleName' */ +//======================================================================= +void LightApp_Study::saveModuleData(QString theModuleName, QStringList theListOfFiles) +{ + int aNb = theListOfFiles.count(); + if ( aNb == 0 ) + return; + + std::vector aListOfFiles ( aNb ); + int anIndex = 0; + for ( QStringList::Iterator it = theListOfFiles.begin(); it != theListOfFiles.end(); ++it ) { + if ( (*it).isEmpty() ) + continue; + aListOfFiles[anIndex] = (*it).latin1(); + anIndex++; + } + myDriver->SetListOfFiles(theModuleName, aListOfFiles); +} + +//======================================================================= +// name : openModuleData +/*! Purpose : gets list of file for module 'theModuleNam' */ +//======================================================================= +void LightApp_Study::openModuleData(QString theModuleName, QStringList& theListOfFiles) +{ + std::vector aListOfFiles = myDriver->GetListOfFiles(theModuleName); + int i, aLength = aListOfFiles.size() - 1; + if (aLength < 0) + return; + + //Get a temporary directory for saved a file + theListOfFiles.append(aListOfFiles[0].c_str()); + for(i = 0; i < aLength; i++) + theListOfFiles.append(aListOfFiles[i+1].c_str()); +} + +//======================================================================= +// name : saveStudyData +/*! Purpose : save data from study */ +//======================================================================= +bool LightApp_Study::saveStudyData( const QString& theFileName ) +{ + ModelList list; dataModels( list ); + SUIT_ResourceMgr* resMgr = application()->resourceMgr(); + if( !resMgr ) + return false; + bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ); + + bool aRes = myDriver->SaveDatasInFile(theFileName.latin1(), isMultiFile); + // clear map + std::vector aList(0); + for ( ModelListIterator it( list ); it.current(); ++it ) + myDriver->SetListOfFiles(it.current()->module()->name(), aList); + + return aRes; +} + +//======================================================================= +// name : openStudyData +/*! Purpose : open data for study */ +//======================================================================= +bool LightApp_Study::openStudyData( const QString& theFileName ) +{ + SUIT_ResourceMgr* resMgr = application()->resourceMgr(); + if( !resMgr ) + return false; + bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ); + + bool aRes = myDriver->ReadDatasFromFile(theFileName.latin1(), isMultiFile); + return aRes; +} + +//================================================================ +// Function : openDataModel +/*! Purpose : Open data model */ +//================================================================ +bool LightApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm ) +{ + if (!dm) + return false; + + QStringList listOfFiles; + openModuleData(dm->module()->name(), listOfFiles); + if (dm && dm->open(studyName, this, listOfFiles)) { + // Remove the files and temporary directory, created + // for this module by LightApp_Driver::OpenStudyData() + bool isMultiFile = false; // TODO: decide, how to access this parameter + RemoveTemporaryFiles( dm->module()->name(), isMultiFile ); + + // Something has been read -> create data model tree + LightApp_DataModel* aDM = dynamic_cast( dm ); + if ( aDM ) + aDM->update(NULL, this); + return true; + } + return false; +} + +//================================================================ +// Function : GetTmpDir +/*! Purpose : to be used by modules*/ +//================================================================ +std::string LightApp_Study::GetTmpDir (const char* theURL, + const bool isMultiFile) +{ + return myDriver->GetTmpDir(theURL, isMultiFile); +} + +//================================================================ +// Function : GetListOfFiles +/*! Purpose : to be used by modules*/ +//================================================================ +std::vector LightApp_Study::GetListOfFiles(const char* theModuleName) const +{ + std::vector aListOfFiles; + aListOfFiles = myDriver->GetListOfFiles(theModuleName); + return aListOfFiles; +} + +//================================================================ +// Function : SetListOfFiles +/*! Purpose : to be used by modules*/ +//================================================================ +void LightApp_Study::SetListOfFiles (const char* theModuleName, const std::vector theListOfFiles) +{ + myDriver->SetListOfFiles(theModuleName, theListOfFiles); +} + +//================================================================ +// Function : RemoveTemporaryFiles +/*! Purpose : to be used by modules*/ +//================================================================ +void LightApp_Study::RemoveTemporaryFiles (const char* theModuleName, const bool isMultiFile) const +{ + if (isMultiFile) + return; + bool isDirDeleted = true; + myDriver->RemoveTemporaryFiles(theModuleName, isDirDeleted); +} diff --git a/src/LightApp/LightApp_Study.h b/src/LightApp/LightApp_Study.h new file mode 100644 index 000000000..4c206cc09 --- /dev/null +++ b/src/LightApp/LightApp_Study.h @@ -0,0 +1,70 @@ +#ifndef LIGHTAPP_STUDY_H +#define LIGHTAPP_STUDY_H + +#include +#include + +#include +#include +#include + +#include "string" +#include "vector" + +class SUIT_Application; +class CAM_DataModel; + +class LIGHTAPP_EXPORT LightApp_Study : public CAM_Study +{ + Q_OBJECT + +public: + LightApp_Study( SUIT_Application* ); + virtual ~LightApp_Study(); + + virtual void createDocument(); + virtual bool openDocument( const QString& ); + virtual bool loadDocument( const QString& ); + + virtual bool saveDocument(); + virtual bool saveDocumentAs( const QString& ); + + virtual void closeDocument(bool permanently = true); + + virtual bool isSaved() const; + virtual bool isModified() const; + + virtual void addComponent ( const CAM_DataModel* dm); + + virtual std::string GetTmpDir ( const char* theURL, const bool isMultiFile ); + + virtual QString componentDataType( const QString& ); + virtual QString referencedToEntry( const QString& ); + +protected: + virtual void saveModuleData ( QString theModuleName, QStringList theListOfFiles ); + virtual void openModuleData ( QString theModuleName, QStringList& theListOfFiles ); + virtual bool saveStudyData ( const QString& theFileName ); + virtual bool openStudyData ( const QString& theFileName ); + + virtual std::vector GetListOfFiles ( const char* theModuleName ) const; + virtual void SetListOfFiles ( const char* theModuleName, + const std::vector theListOfFiles ); + + virtual void RemoveTemporaryFiles ( const char* theModuleName, const bool isMultiFile ) const; + +protected: + virtual bool openDataModel ( const QString&, CAM_DataModel* ); + +signals: + void saved ( SUIT_Study* ); + void opened ( SUIT_Study* ); + void closed ( SUIT_Study* ); + void created( SUIT_Study* ); + + +private: + LightApp_Driver* myDriver; +}; + +#endif diff --git a/src/LightApp/LightApp_SwitchOp.cxx b/src/LightApp/LightApp_SwitchOp.cxx new file mode 100755 index 000000000..4232ced87 --- /dev/null +++ b/src/LightApp/LightApp_SwitchOp.cxx @@ -0,0 +1,164 @@ +/** +* LIGHT LightApp +* +* Copyright (C) 2005 CEA/DEN, EDF R&D +* +* +* +* File : LightApp_SwitchOp.h +* Author : Sergey LITONIN +* Module : LIGHT +*/ + +#include "LightApp_SwitchOp.h" +#include "LightApp_Module.h" +#include "LightApp_Operation.h" +#include "LightApp_Dialog.h" +#include +#include +#include +#include +#include +#include +#include + +/*! + * \brief Constructor + * \param theParent - parent of object +* +* Creates instance of the object. Connects signals and slots. Install eveny filter +* on application +*/ +LightApp_SwitchOp::LightApp_SwitchOp( LightApp_Module* theModule ) +: QObject( 0 ), + myModule( theModule ) +{ + qApp->installEventFilter( this ); +} + +/*! + * \brief Destructor +*/ +LightApp_SwitchOp::~LightApp_SwitchOp() +{ + +} + +/*! + * \brief Get module +* +* Get module. Module is a parent of this class +*/ +LightApp_Module* LightApp_SwitchOp::module() const +{ + return myModule; +} + +/*! + * \brief Get study + * \return Active study of application (in current realisation) +* +* Get study +*/ +SUIT_Study* LightApp_SwitchOp::study() const +{ + return module()->application()->activeStudy(); +} + +/*! + * \brief Get operation by widget + * \param theWg - key widget to find operation + * \return Pointer to the operations if it is found or zero +* +* Find operation containing dialog with given widget +*/ +LightApp_Operation* LightApp_SwitchOp::operation( QWidget* theWg ) const +{ + // get dialog from widget + LightApp_Dialog* aDlg = 0; + QWidget* aParent = theWg; + while( aParent && !aParent->inherits( "LightApp_Dialog" ) ) + aParent = aParent->parentWidget(); + + if ( aParent && aParent->inherits( "LightApp_Dialog" ) ) + aDlg = (LightApp_Dialog*)aParent; + + // try to find operation corresponding to the dialog + if ( aDlg != 0 && study() != 0 ) + { + QPtrListIterator anIter( study()->operations() ); + while( SUIT_Operation* anOp = anIter.current() ) + { + if ( anOp->inherits( "LightApp_Operation" ) && + ((LightApp_Operation*)anOp)->dlg() == aDlg ) + return ((LightApp_Operation*)anOp); + ++anIter; + } + } + + return 0; +} + +/*! + * \brief Event filter + * \param theObj - object + * \param theEv - event +* +* Event filter. Catched signals off application. If event concerns to dialog then +* corresponding operation is found and activated. +*/ +bool LightApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv ) +{ + if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) ) + { + QEvent::Type aType = theEv->type(); + LightApp_Operation* anOp = operation( (QWidget*)theObj ); + if ( anOp ) + { + switch ( aType ) + { + case QEvent::Enter: + { + if ( !anOp->isActive() && anOp->isAutoResumed() && + study() && !study()->blockingOperation( anOp ) ) + study()->resume( anOp ); + } + break; + + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + case QEvent::MouseMove: + case QEvent::KeyPress: + case QEvent::KeyRelease: + { + if ( !anOp->isActive() ) + return true; + } + break; + + } + } + } + + return QObject::eventFilter( theObj, theEv ); +} + + + + + + + + + + + + + + + + + + + diff --git a/src/LightApp/LightApp_SwitchOp.h b/src/LightApp/LightApp_SwitchOp.h new file mode 100755 index 000000000..7c725ebf5 --- /dev/null +++ b/src/LightApp/LightApp_SwitchOp.h @@ -0,0 +1,72 @@ +/** +* LIGHT LightApp +* +* Copyright (C) 2005 CEA/DEN, EDF R&D +* +* +* +* File : LightApp_SwitchOp.h +* Author : Sergey LITONIN +* Module : LIGHT +*/ + + + +#ifndef LightApp_SwitchOp_H +#define LightApp_SwitchOp_H + +#include "LightApp.h" +#include + +class LightApp_Module; +class LightApp_Operation; +class QEvent; +class SUIT_Study; + +/*! + * \brief This class is intended for controling switching between operation + * + * Several operation may be launched simultaneously. This class is intended for + * controlling switching between such operations. This class works with operations having + * dialogs (activation of other operations is performed by SUIT_Study). When several + * operations is launched simultaneously corresponding dialogs are shown on the screen. + * Only one operation from the launched ones can be active (active operation). Other + * operations are suspended. As result only one dialog from shown ones can be active too. + * Other dialogs are disabled. This class installs event filter on application. When mouse + * cursor is moved above disabled dialog corresponding event is catched by this class. + * It finds corresponding operation and verify whether operation can be resumed (see + * SUIT_Study::isDenied( SUIT_Operation* ) method). If yes then current active + * operation is suspended and new operation activated. Module contains this class as a + * field. Then module is created instance of this class created too. + */ +class LIGHTAPP_EXPORT LightApp_SwitchOp : public QObject +{ + Q_OBJECT + +public: + + LightApp_SwitchOp( LightApp_Module* ); + virtual ~LightApp_SwitchOp(); + + // Redefined from base class + bool eventFilter( QObject*, QEvent* ); + +private: + + LightApp_Module* module() const; + LightApp_Operation* operation( QWidget* ) const; + SUIT_Study* study() const; + +private: + + LightApp_Module* myModule; + +}; + +#endif + + + + + + diff --git a/src/LightApp/LightApp_UpdateFlags.h b/src/LightApp/LightApp_UpdateFlags.h new file mode 100755 index 000000000..2fc7fa780 --- /dev/null +++ b/src/LightApp/LightApp_UpdateFlags.h @@ -0,0 +1,37 @@ +// LIGHT LightApp +// +// Copyright (C) 2005 CEA/DEN, EDF R&D +// +// +// +// File : LightApp_UpdateFlags.h +// Author : Sergey LITONIN +// Module : LIGHT + + +#ifndef LightApp_UpdateFlags_H +#define LightApp_UpdateFlags_H + +/* + Enum : UpdateFlags + Description : Enumeration for update flags. First byte is reserved for LightApp_Module. + Modules derived from this model must use other 3 bytes to define their + own update flags +*/ + +typedef enum +{ + UF_Forced = 0x00000001, + UF_Model = 0x00000002, + UF_Viewer = 0x00000004, + UF_ObjBrowser = 0x00000008, + UF_Controls = 0x00000010, +} UpdateFlags; + +#endif + + + + + + diff --git a/src/LightApp/LightApp_VTKSelector.cxx b/src/LightApp/LightApp_VTKSelector.cxx new file mode 100644 index 000000000..c31cc4341 --- /dev/null +++ b/src/LightApp/LightApp_VTKSelector.cxx @@ -0,0 +1,187 @@ +#include "LightApp_VTKSelector.h" +#include "LightApp_DataOwner.h" + +#include "SVTK_ViewModel.h" +#include "SVTK_Selector.h" +#include "SVTK_ViewWindow.h" +#include "SVTK_Functor.h" + +#include "SALOME_Actor.h" +#include "SALOME_ListIteratorOfListIO.hxx" + +#include "VTKViewer_Algorithm.h" + +#include + +/*! + Constructor. +*/ +LightApp_SVTKDataOwner +::LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO, + const TColStd_IndexedMapOfInteger& theIds, + Selection_Mode theMode, + SALOME_Actor* theActor): + LightApp_DataOwner( theIO ), + mySelectionMode(theMode), + myActor(theActor) +{ + myIds = theIds; // workaround - there is no constructor copy for the container +} + +/*! + Destuctor. +*/ +LightApp_SVTKDataOwner +::~LightApp_SVTKDataOwner() +{ +} + +/*! + Gets actor pointer. +*/ +SALOME_Actor* +LightApp_SVTKDataOwner +::GetActor() const +{ + return myActor.GetPointer(); +} + +/*! + Constructor. +*/ +LightApp_VTKSelector +::LightApp_VTKSelector( SVTK_Viewer* viewer, + SUIT_SelectionMgr* mgr ): + SUIT_Selector( mgr, viewer ), + myViewer( viewer ) +{ + if ( myViewer ) + connect( myViewer, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) ); +} + +/*! + Destructor. +*/ +LightApp_VTKSelector +::~LightApp_VTKSelector() +{ +} + +/*! + Gets viewer. +*/ +SVTK_Viewer* +LightApp_VTKSelector +::viewer() const +{ + return myViewer; +} + +/*! + Gets type of vtk viewer. +*/ +QString +LightApp_VTKSelector +::type() const +{ + return SVTK_Viewer::Type(); +} + +/*! + On selection changed. +*/ +void +LightApp_VTKSelector +::onSelectionChanged() +{ + selectionChanged(); +} + +/*! + Gets list of selected data owners.(output \a aList). +*/ +void +LightApp_VTKSelector +::getSelection( SUIT_DataOwnerPtrList& aList ) const +{ + if(myViewer){ + if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){ + if(SVTK_ViewWindow* aView = dynamic_cast(aViewMgr->getActiveView())){ + if(SVTK_Selector* aSelector = aView->GetSelector()){ + Selection_Mode aMode = aSelector->SelectionMode(); + const SALOME_ListIO& aListIO = aSelector->StoredIObjects(); + SALOME_ListIteratorOfListIO anIter(aListIO); + for(; anIter.More(); anIter.Next()){ + Handle(SALOME_InteractiveObject) anIO = anIter.Value(); + if(anIO->hasEntry()){ + TColStd_IndexedMapOfInteger anIds; + aSelector->GetIndex(anIO,anIds); + SALOME_Actor* anActor = aSelector->GetActor(anIO); + if( !anActor ) + anActor = VTK::Find(aView->getRenderer()->GetActors(),VTK::TIsSameIObject(anIO)); + + aList.append(new LightApp_SVTKDataOwner(anIO,anIds,aMode,anActor)); + } + } + } + } + } + } +} + +/*! + Sets selection to selector from data owner list \a theList. +*/ +void +LightApp_VTKSelector +::setSelection( const SUIT_DataOwnerPtrList& theList ) +{ + if(myViewer){ + if(SUIT_ViewManager* aViewMgr = myViewer->getViewManager()){ + if(SVTK_ViewWindow* aView = dynamic_cast(aViewMgr->getActiveView())){ + if(SVTK_Selector* aSelector = aView->GetSelector()){ + SALOME_ListIO anAppendList; + const SALOME_ListIO& aStoredList = aSelector->StoredIObjects(); + SUIT_DataOwnerPtrList::const_iterator anIter = theList.begin(); + for(; anIter != theList.end(); ++anIter){ + const SUIT_DataOwner* aDataOwner = (*anIter).get(); + if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast(aDataOwner)){ + aSelector->SetSelectionMode(anOwner->GetMode()); + Handle(SALOME_InteractiveObject) anIO = anOwner->IO(); + + if( anOwner->GetActor() ) + aSelector->AddIObject( anOwner->GetActor() ); + else + aSelector->AddIObject(anIO); + + anAppendList.Append(anIO); + aSelector->AddOrRemoveIndex(anIO,anOwner->GetIds(),false); + }else if(const LightApp_DataOwner* anOwner = dynamic_cast(aDataOwner)){ + Handle(SALOME_InteractiveObject) anIO = + new SALOME_InteractiveObject(anOwner->entry().latin1(),""); + aSelector->AddIObject(anIO); + anAppendList.Append(anIO); + } + } + // To remove IOs, which is not selected. + QMap< QString, Handle( SALOME_InteractiveObject )> toRemove; + SALOME_ListIteratorOfListIO anIt( aStoredList ); + for( ; anIt.More(); anIt.Next() ) + if( !anIt.Value().IsNull() ) + toRemove[ anIt.Value()->getEntry() ] = anIt.Value(); + + anIt = SALOME_ListIteratorOfListIO(anAppendList); + for( ; anIt.More(); anIt.Next() ) + toRemove.remove( anIt.Value()->getEntry() ); + + QMap< QString, Handle( SALOME_InteractiveObject )>::const_iterator RIt = toRemove.begin(), + REnd = toRemove.end(); + for( ; RIt!=REnd; RIt++ ) + aSelector->RemoveIObject( RIt.data() ); + + aView->onSelectionChanged(); + } + } + } + } +} diff --git a/src/LightApp/LightApp_VTKSelector.h b/src/LightApp/LightApp_VTKSelector.h new file mode 100644 index 000000000..25c4ac44e --- /dev/null +++ b/src/LightApp/LightApp_VTKSelector.h @@ -0,0 +1,78 @@ +#ifndef LIGHTAPP_VTKSELECTOR_H +#define LIGHTAPP_VTKSELECTOR_H + +#include + +#include + +#include "SUIT_Selector.h" + +#include "LightApp.h" +#include "LightApp_DataOwner.h" + +#include "SVTK_Selection.h" +#include "SALOME_InteractiveObject.hxx" + +class SALOME_Actor; +class SVTK_Viewer; + +/*! + Provide salome vtk data owner list. +*/ +class LIGHTAPP_EXPORT LightApp_SVTKDataOwner : public LightApp_DataOwner +{ + public: + LightApp_SVTKDataOwner( const Handle(SALOME_InteractiveObject)& theIO, + const TColStd_IndexedMapOfInteger& theIds, + Selection_Mode theMode = ActorSelection, + SALOME_Actor* theActor = NULL); + virtual ~LightApp_SVTKDataOwner(); + + /*!Gets dataowners ids list.*/ + const TColStd_IndexedMapOfInteger& GetIds() const + { + return myIds; + } + + /*!Gets selection mode.*/ + Selection_Mode GetMode() const + { + return mySelectionMode; + } + + SALOME_Actor* GetActor() const; + + protected: + TColStd_IndexedMapOfInteger myIds; + Selection_Mode mySelectionMode; + vtkSmartPointer myActor; +}; + + +/*! + Provide vtk selection of data owners. +*/ +class LIGHTAPP_EXPORT LightApp_VTKSelector : public SUIT_Selector +{ + Q_OBJECT; + +public: + LightApp_VTKSelector( SVTK_Viewer*, SUIT_SelectionMgr* ); + virtual ~LightApp_VTKSelector(); + + SVTK_Viewer* viewer() const; + + virtual QString type() const; + +private slots: + void onSelectionChanged(); + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); + +private: + SVTK_Viewer* myViewer; +}; + +#endif diff --git a/src/LightApp/LightApp_WidgetContainer.cxx b/src/LightApp/LightApp_WidgetContainer.cxx new file mode 100644 index 000000000..3dd8d1f9b --- /dev/null +++ b/src/LightApp/LightApp_WidgetContainer.cxx @@ -0,0 +1,133 @@ +#include "LightApp_WidgetContainer.h" + +#include +#include + +/*! + Constructor. +*/ +LightApp_WidgetContainer::LightApp_WidgetContainer( const int type, QWidget* parent ) +: QDockWindow( QDockWindow::InDock, parent ), +myType( type ) +{ + setWidget( myStack = new QWidgetStack( this ) ); + myStack->show(); +} + +/*! + Destructor. +*/ +LightApp_WidgetContainer::~LightApp_WidgetContainer() +{ +} + +/*! + Checks: is widget container is empty? +*/ +bool LightApp_WidgetContainer::isEmpty() const +{ + const QObjectList* lst = myStack->children(); + if ( !lst ) + return true; + + bool res = true; + for ( QObjectListIt it( *lst ); it.current() && res; ++it ) + { + if ( it.current()->isWidgetType() && myStack->id( (QWidget*)it.current() ) != -1 ) + res = false; + } + return res; +} + +/*! + Gets type of widget container. +*/ +int LightApp_WidgetContainer::type() const +{ + return myType; +} + +/*! + Checks: is container contains widget with id \a id. +*/ +bool LightApp_WidgetContainer::contains( const int id ) const +{ + return myStack->widget( id ) != 0; +} + +/*! + * Insert widget(\a wid with id \a id) to container.And return id of widget in stack. + *\warning remove widget with id = \a id , if it was in container. + */ +int LightApp_WidgetContainer::insert( const int id, QWidget* wid ) +{ + if ( id == -1 || !wid ) + return -1; + + if ( contains( id ) ) + remove( id ); + + int stackId = myStack->addWidget( wid, id ); + if ( !myStack->visibleWidget() ) + myStack->raiseWidget( wid ); + + setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null ); + + return stackId; +} + +/*! + Remove widget(\a wid) from stack. +*/ +void LightApp_WidgetContainer::remove( const int id ) +{ + remove( myStack->widget( id ) ); + + setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null ); +} + +/*! + Remove widget(\a wid) from stack. +*/ +void LightApp_WidgetContainer::remove( QWidget* wid ) +{ + myStack->removeWidget( wid ); + + setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null ); +} + +/*! + Raise widget with id = \a id. +*/ +void LightApp_WidgetContainer::activate( const int id ) +{ + myStack->raiseWidget( id ); + + setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null ); +} + +/*! + Raise widget (\a wid). +*/ +void LightApp_WidgetContainer::activate( QWidget* wid ) +{ + myStack->raiseWidget( wid ); + + setCaption( myStack->visibleWidget() ? myStack->visibleWidget()->caption() : QString::null ); +} + +/*! + Gets widget from container list(stack) by id = \a id. +*/ +QWidget* LightApp_WidgetContainer::widget( const int id ) const +{ + return myStack->widget( id ); +} + +/*! + Gets visible widget. +*/ +QWidget* LightApp_WidgetContainer::active() const +{ + return myStack->visibleWidget(); +} diff --git a/src/LightApp/LightApp_WidgetContainer.h b/src/LightApp/LightApp_WidgetContainer.h new file mode 100644 index 000000000..6479eb949 --- /dev/null +++ b/src/LightApp/LightApp_WidgetContainer.h @@ -0,0 +1,42 @@ +#ifndef LIGHTAPP_WIDGETCONTAINER_H +#define LIGHTAPP_WIDGETCONTAINER_H + +#include "LightApp.h" + +#include + +class QWidget; +class QWidgetStack; + +/*! + Class which privade widget container. +*/ +class LIGHTAPP_EXPORT LightApp_WidgetContainer : public QDockWindow +{ + Q_OBJECT + +public: + LightApp_WidgetContainer( const int, QWidget* = 0 ); + virtual ~LightApp_WidgetContainer(); + + bool isEmpty() const; + + int type() const; + + int insert( const int, QWidget* ); + void remove( QWidget* ); + void remove( const int ); + bool contains( const int ) const; + + void activate( QWidget* ); + void activate( const int ); + + QWidget* active() const; + QWidget* widget( const int ) const; + +private: + int myType; + QWidgetStack* myStack; +}; + +#endif diff --git a/src/LightApp/Makefile.in b/src/LightApp/Makefile.in new file mode 100755 index 000000000..dc1d74cda --- /dev/null +++ b/src/LightApp/Makefile.in @@ -0,0 +1,114 @@ +# File : Makefile.in +# Author : OCC team (OCN) +# Module : LightApp +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@srcdir@/resources + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= LightApp.h \ + LightApp_AboutDlg.h \ + LightApp_Application.h \ + LightApp_DataModel.h \ + LightApp_DataObject.h \ + LightApp_DataOwner.h \ + LightApp_DataSubOwner.h \ + LightApp_Dialog.h \ + LightApp_Displayer.h \ + LightApp_Driver.h \ + LightApp_GLSelector.h \ + LightApp_Module.h \ + LightApp_ModuleDlg.h \ + LightApp_NameDlg.h \ + LightApp_OBFilter.h \ + LightApp_OBSelector.h \ + LightApp_OCCSelector.h \ + LightApp_Operation.h \ + LightApp_Selection.h \ + LightApp_SelectionMgr.h \ + LightApp_ShowHideOp.h \ + LightApp_Study.h \ + LightApp_SwitchOp.h \ + LightApp_Preferences.h \ + LightApp_PreferencesDlg.h \ + LightApp_RootObject.h \ + LightApp_UpdateFlags.h \ + LightApp_VTKSelector.h \ + LightApp_WidgetContainer.h + +# .po files to transform in .qm +PO_FILES = LightApp_images.po \ + LightApp_msg_en.po + +# Libraries targets +LIB = libLightApp.la + +LIB_SRC= LightApp_AboutDlg.cxx \ + LightApp_Application.cxx \ + LightApp_DataModel.cxx \ + LightApp_DataObject.cxx \ + LightApp_DataOwner.cxx \ + LightApp_DataSubOwner.cxx \ + LightApp_Dialog.cxx \ + LightApp_Displayer.cxx \ + LightApp_Driver.cxx \ + LightApp_GLSelector.cxx \ + LightApp_Module.cxx \ + LightApp_ModuleDlg.cxx \ + LightApp_NameDlg.cxx \ + LightApp_OBFilter.cxx \ + LightApp_OBSelector.cxx \ + LightApp_OCCSelector.cxx \ + LightApp_Operation.cxx \ + LightApp_Selection.cxx \ + LightApp_SelectionMgr.cxx \ + LightApp_ShowHideOp.cxx \ + LightApp_Study.cxx \ + LightApp_SwitchOp.cxx \ + LightApp_Preferences.cxx \ + LightApp_PreferencesDlg.cxx \ + LightApp_VTKSelector.cxx \ + LightApp_WidgetContainer.cxx + +LIB_MOC = LightApp_AboutDlg.h \ + LightApp_Application.h \ + LightApp_DataModel.h \ + LightApp_Dialog.h \ + LightApp_Driver.h \ + LightApp_GLSelector.h \ + LightApp_OBSelector.h \ + LightApp_OCCSelector.h \ + LightApp_Operation.h \ + LightApp_Module.h \ + LightApp_ModuleDlg.h \ + LightApp_NameDlg.h \ + LightApp_SelectionMgr.h \ + LightApp_ShowHideOp.h \ + LightApp_Study.h \ + LightApp_SwitchOp.h \ + LightApp_Preferences.h \ + LightApp_PreferencesDlg.h \ + LightApp_VTKSelector.h \ + LightApp_WidgetContainer.h + +RESOURCES_FILES = icon_about.png \ + icon_applogo.png \ + icon_default.png \ + icon_module.png \ + icon_module_big.png \ + icon_select.png \ + LightApp.ini \ + LightApp.xml + +CPPFLAGS+=$(PYTHON_INCLUDES) $(QT_INCLUDES) $(QWT_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) + +LDFLAGS+=$(PYTHON_LIBS) $(QT_MT_LIBS) +LIBS+= -lsuit -lstd -lCAM -lObjBrowser -lLogWindow $(CAS_KERNEL) -lPlot2d -lGLViewer -lOCCViewer -lVTKViewer -lSalomeObject -lSOCC -lSVTK -lPyInterp -lPythonConsole + +@CONCLUDE@ diff --git a/src/LightApp/resources/LightApp.ini b/src/LightApp/resources/LightApp.ini new file mode 100755 index 000000000..814a5ec84 --- /dev/null +++ b/src/LightApp/resources/LightApp.ini @@ -0,0 +1,21 @@ +# The resources mapping file for LightApp application + +[language] +language = en + +[launch] +modules = LIGHT + +[resources] +SUIT = $(SUITRoot)/resources +STD = $(SUITRoot)/resources +LightApp = $(SUITRoot)/resources +Plot2d = $(SUITRoot)/resources +GLViewer = $(SUITRoot)/resources +OCCViewer = $(SUITRoot)/resources +VTKViewer = $(SUITRoot)/resources +LIGHT = $(LIGHT_ROOT_DIR)/share/salome/resources + +[LIGHT] +name = Light +icon = LIGHT diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml new file mode 100644 index 000000000..b5884f858 --- /dev/null +++ b/src/LightApp/resources/LightApp.xml @@ -0,0 +1,70 @@ + +
+ + + + + +
+
+ + + + + + +
+
+ + +
+
+ + + + + + + + + + + + + +
+
+ + +
+ + +
+ + +
+
+ + + + +
+
+ + +
+
+ + + + + + + +
+ +
+ + +
+
diff --git a/src/LightApp/resources/LightApp_images.po b/src/LightApp/resources/LightApp_images.po new file mode 100644 index 000000000..c1ee44b39 --- /dev/null +++ b/src/LightApp/resources/LightApp_images.po @@ -0,0 +1,33 @@ +// File: LightApp_images.po +// Created: May, 2005 +// Author: OCC team +// Copyright (C) CEA 2005 + +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2002-05-28 10:57:43 AM CEST\n" +"PO-Revision-Date: YYYY-MM-DD\n" +"Last-Translator: FULLNAME \n" +"Content-Type: text/plain; charset=iso-8859-1\n" + +msgid "ABOUT" +msgstr "icon_about.png" + +msgid "ABOUT_SPLASH" +msgstr "icon_about.png" + +msgid "APP_DEFAULT_ICO" +msgstr "icon_default.png" + +msgid "APP_MODULE_ICO" +msgstr "icon_module.png" + +msgid "APP_MODULE_BIG_ICO" +msgstr "icon_module_big.png" + +msgid "ICON_SELECT" +msgstr "icon_select.png" + +msgid "APP_BASE_LOGO" +msgstr "icon_applogo.png" diff --git a/src/LightApp/resources/LightApp_msg_en.po b/src/LightApp/resources/LightApp_msg_en.po new file mode 100644 index 000000000..f5c4a8f89 --- /dev/null +++ b/src/LightApp/resources/LightApp_msg_en.po @@ -0,0 +1,252 @@ +# This is a Qt message file in .po format. Each msgid starts with +# a scope. This scope should *NOT* be translated - eg. "Foo::Bar" +# would be translated to "Pub", not "Foo::Pub". +msgid "" +msgstr "" +"Project-Id-Version: example-Qt-message-extraction\n" +"POT-Creation-Date: 1999-02-23 15:38+0200\n" +"PO-Revision-Date: 1999-02-23 15:38+0200\n" +"Last-Translator: \n" +"Content-Type: text/plain; charset=iso-8859-1\n" + +msgid "LightApp_Application::ACTIVATING_MODULE" +msgstr "Trying to activate module \"%1\"" + +msgid "LightApp_Application::TOT_DESK_PREFERENCES" +msgstr "Preferences" + +msgid "LightApp_Application::MEN_DESK_PREFERENCES" +msgstr "Preferences..." + +msgid "LightApp_Application::TOT_DESK_MRU" +msgstr "Most recently used" + +msgid "LightApp_Application::MEN_DESK_MRU" +msgstr "Most recently used" + +msgid "LightApp_Application::PRP_DESK_PREFERENCES" +msgstr "Allow to change the preferences" + +msgid "LightApp_Application::INF_TOOLBAR_MODULES" +msgstr "Modules" + +msgid "LightApp_Application::APP_NAME" +msgstr "SALOME" + +msgid "LightApp_Application::PRP_APP_MODULE" +msgstr "Switch to SALOME platform neutral point" + +msgid "LightApp_Application::PRP_MODULE" +msgstr "Switch to the mocule \"%1\"" + +msgid "LightApp_Application::NEW_WINDOW_0" +msgstr "GL view" + +msgid "LightApp_Application::NEW_WINDOW_1" +msgstr "Plot2d view" + +msgid "LightApp_Application::NEW_WINDOW_2" +msgstr "OCC view" + +msgid "LightApp_Application::NEW_WINDOW_3" +msgstr "VTK view" + +msgid "LightApp_Application::INF_CANCELLED" +msgstr "Module activation cancelled" + +msgid "LightApp_Application::DATA_MODELS" +msgstr "Data models" + +msgid "LightApp_Application::OBJECT_BROWSER" +msgstr "Object Browser" + +msgid "LightApp_Application::OBJ_BROWSER_NAME" +msgstr "Object" + +msgid "LightApp_Application::LOG_WINDOW" +msgstr "Message Window" + +//======================================================================================= + +msgid "LightApp_Application::MEN_DESK_MODULE_HELP" +msgstr "Module help" + +//======================================================================================= + +msgid "LightApp_Application::PREFERENCES_NOT_LOADED" +msgstr "Preferences for module \"%1\" will be available when the module will be loaded" + +msgid "LightApp_Application::PREF_CATEGORY_SALOME" +msgstr "SALOME" + +msgid "LightApp_Application::PREF_TAB_GENERAL" +msgstr "General" + +msgid "LightApp_Application::PREF_GROUP_STUDY" +msgstr "Study properties" + +msgid "LightApp_Application::PREF_MULTI_FILE" +msgstr "Multi file save" + +msgid "LightApp_Application::PREF_ASCII_FILE" +msgstr "ASCII save" + +msgid "LightApp_Application::PREF_UNDO_LEVEL" +msgstr "Undo level" + +msgid "LightApp_Application::PREF_GROUP_EXT_BROWSER" +msgstr "External browser" + +msgid "LightApp_Application::PREF_APP" +msgstr "Application" + +msgid "LightApp_Application::PREF_PARAM" +msgstr "Parameters" + +msgid "LightApp_Application::PREF_GROUP_PY_CONSOLE" +msgstr "Python console properties" + +msgid "LightApp_Application::PREF_FONT" +msgstr "Font" + +msgid "LightApp_Application::PREF_TAB_OBJBROWSER" +msgstr "Object browser" + +msgid "LightApp_Application::PREF_GROUP_DEF_COLUMNS" +msgstr "Default columns" + +msgid "LightApp_Application::PREF_TAB_VIEWERS" +msgstr "Viewers" + +msgid "LightApp_Application::PREF_GROUP_OCCVIEWER" +msgstr "OCC Viewer 3d" + +msgid "LightApp_Application::PREF_GROUP_VTKVIEWER" +msgstr "VTK Viewer 3d" + +msgid "LightApp_Application::PREF_VIEWER_BACKGROUND" +msgstr "Background color" + +msgid "LightApp_Application::PREF_TRIHEDRON_SIZE" +msgstr "Trihedron size" + +msgid "LightApp_Application::PREF_ISOS_U" +msgstr "Number of isolines along U" +msgid "LightApp_Application::PREF_ISOS_V" +msgstr "Number of isolines along V" + +msgid "LightApp_Application::PREF_TRIHEDRON_SHOW" +msgstr "Show trihedron" + +msgid "LightApp_Application::PREF_GROUP_PLOT2DVIEWER" +msgstr "Plot2d Viewer" + +msgid "LightApp_Application::PREF_SHOW_LEGEND" +msgstr "Show legend" + +msgid "LightApp_Application::PREF_LEGEND_POSITION" +msgstr "Legend position:" + +msgid "LightApp_Application::PREF_LEFT" +msgstr "Left" + +msgid "LightApp_Application::PREF_RIGHT" +msgstr "Right" + +msgid "LightApp_Application::PREF_TOP" +msgstr "Top" + +msgid "LightApp_Application::PREF_BOTTOM" +msgstr "Bottom" + +msgid "LightApp_Application::PREF_CURVE_TYPE" +msgstr "Curve type:" + +msgid "LightApp_Application::PREF_POINTS" +msgstr "Points" + +msgid "LightApp_Application::PREF_LINES" +msgstr "Lines" + +msgid "LightApp_Application::PREF_SPLINE" +msgstr "Spline" + +msgid "LightApp_Application::PREF_MARKER_SIZE" +msgstr "Marker size:" + +msgid "LightApp_Application::PREF_LINEAR" +msgstr "Linear" + +msgid "LightApp_Application::PREF_LOGARITHMIC" +msgstr "Logarithmic" + +msgid "LightApp_Application::PREF_HOR_AXIS_SCALE" +msgstr "Horizontal axis scale:" + +msgid "LightApp_Application::PREF_VERT_AXIS_SCALE" +msgstr "Vertical axis scale:" + +msgid "LightApp_Application::PREF_TAB_DIRECTORIES" +msgstr "Directories" + +msgid "LightApp_Application::PREF_GROUP_DIRECTORIES" +msgstr "Quick directory list" + +msgid "LightApp_Application::MEN_REFRESH" +msgstr "Refresh" + +//======================================================================================= + +msgid "LightApp_PreferencesDlg::CAPTION" +msgstr "Preferences" + +//======================================================================================= + +msgid "LightApp_Module::TOP_DISPLAY" +msgstr "Display" + +msgid "LightApp_Module::MEN_DISPLAY" +msgstr "Display" + +msgid "LightApp_Module::STB_DISPLAY" +msgstr "Display" + +msgid "LightApp_Module::TOP_ERASE" +msgstr "Erase" + +msgid "LightApp_Module::MEN_ERASE" +msgstr "Erase" + +msgid "LightApp_Module::STB_ERASE" +msgstr "Erase" + +msgid "LightApp_Module::TOP_DISPLAY_ONLY" +msgstr "Display only" + +msgid "LightApp_Module::MEN_DISPLAY_ONLY" +msgstr "Display only" + +msgid "LightApp_Module::STB_DISPLAY_ONLY" +msgstr "Display only" + +//======================================================================================= + + +msgid "LightApp_ModuleDlg::CAPTION" +msgstr "Activate module" + +msgid "LightApp_ModuleDlg::NEW" +msgstr "&New" + +msgid "LightApp_ModuleDlg::OPEN" +msgstr "&Open" + +msgid "LightApp_ModuleDlg::LOAD" +msgstr "&Load" + +msgid "LightApp_ModuleDlg::CANCEL" +msgstr "&Cancel" + +msgid "LightApp_ModuleDlg::ActivateComponent_DESCRIPTION" +msgstr "Create, open or load study." + diff --git a/src/LightApp/resources/icon_about.png b/src/LightApp/resources/icon_about.png new file mode 100755 index 000000000..287b4f766 Binary files /dev/null and b/src/LightApp/resources/icon_about.png differ diff --git a/src/LightApp/resources/icon_applogo.png b/src/LightApp/resources/icon_applogo.png new file mode 100755 index 000000000..7be65180a Binary files /dev/null and b/src/LightApp/resources/icon_applogo.png differ diff --git a/src/LightApp/resources/icon_default.png b/src/LightApp/resources/icon_default.png new file mode 100644 index 000000000..0140a6667 Binary files /dev/null and b/src/LightApp/resources/icon_default.png differ diff --git a/src/LightApp/resources/icon_module.png b/src/LightApp/resources/icon_module.png new file mode 100644 index 000000000..9fdd5fb01 Binary files /dev/null and b/src/LightApp/resources/icon_module.png differ diff --git a/src/LightApp/resources/icon_module_big.png b/src/LightApp/resources/icon_module_big.png new file mode 100755 index 000000000..99e10b1ff Binary files /dev/null and b/src/LightApp/resources/icon_module_big.png differ diff --git a/src/LightApp/resources/icon_select.png b/src/LightApp/resources/icon_select.png new file mode 100644 index 000000000..99ebde65e Binary files /dev/null and b/src/LightApp/resources/icon_select.png differ