-//=============================================================================
-// File : SalomePyQt.cxx
-// Created : 25/04/05
-// Author : Vadim SANDLER
-// Project : SALOME
-// Copyright : 2003-2005 CEA/DEN, EDF R&D
-// $Header : $
-//=============================================================================
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
#include "SALOME_PYQT_Module.h" // this include must be first!!!
#include "SalomePyQt.h"
#include <qmenubar.h>
#include <qwidget.h>
#include <qpopupmenu.h>
+#include <qimage.h>
#include <qstringlist.h>
#include "SALOME_Event.hxx"
#include "STD_MDIDesktop.h"
#include "SalomeApp_Application.h"
#include "SalomeApp_Study.h"
-#include "SalomeApp_SelectionMgr.h"
+#include "LightApp_SelectionMgr.h"
#include "OB_Browser.h"
#include "QtxAction.h"
using namespace std;
-//====================================================================================
-// static functions
-//====================================================================================
/*!
- getApplication()
- Returns active application object [ static ]
+ \return active application object [ static ]
*/
static SalomeApp_Application* getApplication() {
if ( SUIT_Session::session() )
}
/*!
- getActiveStudy()
- Gets active study or 0 if there is no study opened [ static ]
+ \return active study or 0 if there is no study opened [ static ]
*/
static SalomeApp_Study* getActiveStudy()
{
return 0;
}
-//====================================================================================
-// SALOME_Selection class.
-//====================================================================================
static QMap<SalomeApp_Application*, SALOME_Selection*> SelMap;
/*!
- SALOME_Selection::GetSelection
Creates or finds the selection object (one per study).
*/
SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app )
}
/*!
- SALOME_Selection::SALOME_Selection
Selection constructor.
*/
SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 )
}
}
/*!
- SALOME_Selection::~SALOME_Selection
Selection destructor. Removes selection object from the map.
*/
SALOME_Selection::~SALOME_Selection()
}
/*!
- SALOME_Selection::onSelMgrDestroyed
Watches for the selection manager destroying when study is closed.
*/
void SALOME_Selection::onSelMgrDestroyed()
}
/*!
- SALOME_Selection::Clear
Clears the selection.
*/
void SALOME_Selection::Clear()
{
class TEvent: public SALOME_Event {
- SalomeApp_SelectionMgr* mySelMgr;
+ LightApp_SelectionMgr* mySelMgr;
public:
- TEvent( SalomeApp_SelectionMgr* selMgr )
+ TEvent( LightApp_SelectionMgr* selMgr )
: mySelMgr( selMgr ) {}
virtual void Execute() {
if ( mySelMgr )
}
/*!
- SALOME_Selection::ClearIObjects
Clears the selection.
*/
void SALOME_Selection::ClearIObjects()
}
/*!
- SALOME_Selection::ClearFilters
Removes all selection filters.
*/
void SALOME_Selection::ClearFilters()
{
class TEvent: public SALOME_Event {
- SalomeApp_SelectionMgr* mySelMgr;
+ LightApp_SelectionMgr* mySelMgr;
public:
- TEvent( SalomeApp_SelectionMgr* selMgr )
+ TEvent( LightApp_SelectionMgr* selMgr )
: mySelMgr( selMgr ) {}
virtual void Execute() {
if ( mySelMgr )
ProcessVoidEvent( new TEvent( mySelMgr ) );
}
-//====================================================================================
-// SalomePyQt class
-//====================================================================================
-
/*!
- SalomePyQt::getDesktop
- Gets desktop. Returns 0 in error.
+ \return desktop (0 if error)
*/
class TGetDesktopEvent: public SALOME_Event {
public:
myResult = (QWidget*)( getApplication()->desktop() );
}
};
+
+/*!
+ \return desktop
+*/
QWidget* SalomePyQt::getDesktop()
{
return ProcessEvent( new TGetDesktopEvent() );
}
/*!
- SalomePyQt::getMainFrame
- Gets workspace widget. Returns 0 in error.
+ \return workspace widget (0 if error)
*/
class TGetMainFrameEvent: public SALOME_Event {
public:
}
}
};
+
+/*!
+ \return workspace widget (0 if error)
+*/
QWidget* SalomePyQt::getMainFrame()
{
return ProcessEvent( new TGetMainFrameEvent() );
}
}
};
+
+/*!
+ \return main menu
+ \retval 0 in error.
+*/
QMenuBar* SalomePyQt::getMainMenuBar()
{
return ProcessEvent( new TGetMainMenuBarEvent() );
}
}
};
+
+/*!
+ \return popup menu
+ \param menu - menu name
+*/
QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
{
return ProcessEvent( new TGetPopupMenuEvent( menu ) );
}
}
};
+
+/*!
+ SalomePyQt::getStudyId
+ Returns active study's ID or 0 if there is no active study.
+*/
int SalomePyQt::getStudyId()
{
return ProcessEvent( new TGetStudyIdEvent() );
myResult = SALOME_Selection::GetSelection( getApplication() );
}
};
+
+/*!
+ Creates a Selection object (to provide a compatibility with previous SALOME GUI).
+ \return just created selection object
+*/
SALOME_Selection* SalomePyQt::getSelection()
{
return ProcessEvent( new TGetSelectionEvent() );
}
}
};
+
+/*!
+ Puts an information message to the desktop's status bar
+ (with optional delay parameter given in seconds)
+ \param msg - message text
+ \param sec - delay in seconds
+*/
void SalomePyQt::putInfo( const QString& msg, const int sec )
{
ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
}
}
};
+
+/*!
+ \return an active component name or empty string if there is no active component
+*/
const QString SalomePyQt::getActiveComponent()
{
return ProcessEvent( new TGetActiveComponentEvent() );
}
}
};
+
+/*!
+ \return a setting value (as string)
+ This function is obsolete. Use stringSetting(), integerSetting(),
+ boolSetting(), stringSetting() or colorSetting() instead.
+*/
QString SalomePyQt::getSetting( const QString& name )
{
return ProcessEvent( new TGetSettingEvent( name ) );
}
}
};
+
+/*!
+ \return an integer setting from the application preferences
+*/
int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
{
return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ \return an double setting from the application preferences
+*/
double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def )
{
return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ \return an boolean setting from the application preferences
+*/
bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
{
return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ \return an string setting from the application preferences
+*/
QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
{
return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ \return a color setting from the application preferences
+*/
QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
{
return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
}
}
};
+
+/*!
+ Displays 'Open/Save file' dialog box and returns a user's choice (file name)
+*/
QString SalomePyQt::getFileName( QWidget* parent,
const QString& initial,
const QStringList& filters,
}
}
};
+
+/*!
+ Displays 'Open files' dialog box and returns a user's choice (a list of file names)
+*/
QStringList SalomePyQt::getOpenFileNames( QWidget* parent,
const QString& initial,
const QStringList& filters,
}
}
};
+
+/*!
+ Displays 'Get Directory' dialog box and returns a user's choice (a directory name)
+*/
QString SalomePyQt::getExistingDirectory( QWidget* parent,
const QString& initial,
const QString& caption )
}
}
};
+
+/*!
+ Dumps the contents of the currently active view to the image file
+ in the given format (JPEG, PNG, BMP are supported)
+*/
bool SalomePyQt::dumpView( const QString& filename )
{
return ProcessEvent( new TDumpViewEvent( filename ) );
}
+/*!
+ SalomePyQt::defaultMenuGroup
+ Returns default menu group
+*/
+class TDefMenuGroupEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ TDefMenuGroupEvent() : myResult( -1 ) {}
+ virtual void Execute() {
+ myResult = SALOME_PYQT_Module::defaultMenuGroup();
+ }
+};
+
+/*!
+ \return default menu group
+*/
+int SalomePyQt::defaultMenuGroup()
+{
+ return ProcessEvent( new TDefMenuGroupEvent() );
+}
+
/*!
SalomePyQt::createTool
These methods allow operating with the toolbars:
}
}
};
-// create new toolbar or get existing by name
+
+/*!
+ create new toolbar or get existing by name
+*/
int SalomePyQt::createTool( const QString& tBar )
{
return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
}
-// add action with id and index to the existing tollbar
+/*! add action with id and index to the existing tollbar
+*/
int SalomePyQt::createTool( const int id, const int tBar, const int idx )
{
return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
}
-// add action with id and index to the existing tollbar
+/*! add action with id and index to the existing tollbar
+*/
int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
{
return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
}
-// add action with id and index to the existing tollbar
+/*! add action with id and index to the existing tollbar
+*/
int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx )
{
return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
}
-// add action with id and index to the existing tollbar
+/*! add action with id and index to the existing tollbar
+*/
int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx )
{
return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
class CrMenu
{
public:
- CrMenu( const QString& subMenu, const int menu, const int group, const int idx )
- : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
- CrMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
- : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
+ : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
+ CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
+ : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
CrMenu( const int id, const int menu, const int group, const int idx )
: myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
CrMenu( const int id, const QString& menu, const int group, const int idx )
if ( module ) {
switch ( myCase ) {
case 0:
- return module->createMenu( mySubMenuName, myMenuId, -1, myGroup, myIndex );
+ return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
case 1:
- return module->createMenu( mySubMenuName, myMenuName, -1, myGroup, myIndex );
+ return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
case 2:
return module->createMenu( myId, myMenuId, myGroup, myIndex );
case 3:
}
}
};
-int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int group, const int idx )
+int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
{
- return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
}
-int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int group, const int idx )
+int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
{
- return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, group, idx ) ) );
+ return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
}
int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
{
return ProcessEvent( new TActionIdEvent( a ) );
}
+
+/*!
+ SalomePyQt::clearMenu
+ Clears given menu (recursively if necessary)
+*/
+class TClearMenuEvent: public SALOME_Event {
+public:
+ typedef bool TResult;
+ TResult myResult;
+ int myId;
+ int myMenu;
+ bool myRemoveActions;
+ TClearMenuEvent( const int id, const int menu, const bool removeActions )
+ : myResult( false ), myId( id ), myMenu( menu ), myRemoveActions( removeActions ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->clearMenu( myId, myMenu, myRemoveActions );
+ }
+ }
+};
+bool SalomePyQt::clearMenu( const int id, const int menu, const bool removeActions )
+{
+ return ProcessEvent( new TClearMenuEvent( id, menu, removeActions ) );
+}
+