#include "OCCViewer_ViewWindow.h"
#include "OCCViewer_ViewFrame.h"
#endif // DISABLE_OCCVIEWER
+#ifndef DISABLE_VTKVIEWER
+#include "SVTK_ViewWindow.h"
+#endif // DISABLE_VTKVIEWER
#ifndef DISABLE_PLOT2DVIEWER
#include "Plot2d_ViewManager.h"
#include "Plot2d_ViewWindow.h"
#include <QApplication>
#include <QPaintEvent>
#include <QCoreApplication>
+#include <QVBoxLayout>
#include <utilities.h>
+
namespace
{
/*!
ProcessVoidEvent( new TEvent( mySelMgr ) );
}
+/*!
+ \class UserDefinedContent
+ \brief The class represents base class for user defined widget that
+ can be inserted to the Preferences dialog.
+*/
+
+/*!
+ \brief Constructor
+*/
+UserDefinedContent::UserDefinedContent()
+ : QWidget()
+{
+}
+
+/*!
+ \brief Called from Preferences dialog to store settings to the resource file.
+*/
+void UserDefinedContent::store()
+{
+}
+
+/*!
+ \brief Called from Preferences dialog to restore settings from the resource file.
+*/
+void UserDefinedContent::retrieve()
+{
+}
+
+/*!
+ \class SgPyQtUserDefinedContent
+ \brief A Wrapper for UserDefinedContent class.
+ \internal
+*/
+class SgPyQtUserDefinedContent: public QtxUserDefinedContent
+{
+public:
+ SgPyQtUserDefinedContent(UserDefinedContent*);
+ virtual ~SgPyQtUserDefinedContent();
+
+ void store( QtxResourceMgr*, QtxPreferenceMgr* );
+ void retrieve( QtxResourceMgr*, QtxPreferenceMgr* );
+
+private:
+ UserDefinedContent* myContent;
+};
+
+/*!
+ \brief Create custom item for Preferences dialog wrapping widget passed from Python.
+ \internal
+*/
+SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content)
+ : QtxUserDefinedContent( 0 ), myContent( content )
+{
+ QVBoxLayout* l = new QVBoxLayout( this );
+ l->setContentsMargins( 0, 0, 0, 0 );
+ l->addWidget( myContent );
+}
+
+/*!
+ \brief Destructor.
+ \internal
+*/
+SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent()
+{
+}
+
+/*!
+ \brief Called from Preferences dialog to store settings to the resource file.
+ \internal
+*/
+void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* )
+{
+ myContent->store();
+}
+
+/*!
+ \brief Called from Preferences dialog to restore settings from the resource file.
+ \internal
+*/
+void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* )
+{
+ myContent->retrieve();
+}
+
/*!
\class SalomePyQt
\brief The class provides utility functions which can be used in the Python
return ProcessVoidEvent( new TSetSelectionEvent(entryList) );
}
+/*!
+ \fn void SalomePyQt::enableSelector();
+ \brief enable PyQt_Selector (on module activation, for instance)
+*/
+
+class TEnableSelectorEvent: public SALOME_Event
+{
+public:
+ TEnableSelectorEvent() {}
+ virtual void Execute()
+ {
+ SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
+ if ( !module ) return;
+ module->enableSelector();
+ }
+};
+void SalomePyQt::enableSelector()
+{
+ return ProcessVoidEvent( new TEnableSelectorEvent() );
+}
+
+
+/*!
+ \fn void SalomePyQt::disableSelector();
+ \brief disable PyQt_Selector (on module activation, for instance)
+*/
+
+class TdisableSelectorEvent: public SALOME_Event
+{
+public:
+ TdisableSelectorEvent() {}
+ virtual void Execute()
+ {
+ SALOME_PYQT_ModuleLight* module = dynamic_cast<SALOME_PYQT_ModuleLight*>( getActiveModule() );
+ if ( !module ) return;
+ module->disableSelector();
+ }
+};
+void SalomePyQt::disableSelector()
+{
+ return ProcessVoidEvent( new TdisableSelectorEvent() );
+}
+
+
/*!
\fn void SalomePyQt::putInfo( const QString& msg, const int sec );
\brief Put an information message to the current application's
ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
}
+/*!
+ \fn int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec );
+ \brief Show notification in the application's desktop window.
+
+ Optional third delay parameter (\a sec) can be used to specify
+ time of the notification diplaying in seconds. If this parameter is less
+ or equal to zero, the permanent notification will be put.
+
+ Notification can be forcibly hidden via hideNotification() method.
+
+ \param msg message text
+ \param title title text
+ \param sec notification displaying time in seconds
+ \return unique ID of the notification (can be used to hide notification)
+ \sa hideNotification()
+*/
+
+class TShowNotifyEvent: public SALOME_Event
+{
+ QString myMsg;
+ QString myTitle;
+ int mySecs;
+
+public:
+ typedef int TResult;
+ TResult myResult;
+
+public:
+ TShowNotifyEvent( const QString& msg, const QString& title, const int sec = -1 ) : myMsg( msg ), myTitle( title), mySecs( sec ), myResult( -1 ) {}
+ virtual void Execute()
+ {
+ if ( LightApp_Application* anApp = getApplication() ) {
+ myResult = anApp->showNotification( myMsg, myTitle, mySecs * 1000 );
+ }
+ }
+};
+
+int SalomePyQt::showNotification( const QString& msg, const QString& title, const int sec )
+{
+ return ProcessEvent( new TShowNotifyEvent( msg, title, sec ) );
+}
+
+/*!
+ \fn void SalomePyQt::hideNotification( const QString& msg );
+ \brief Remove notification with given message text from the application's desktop.
+
+ \param msg message text
+ \sa showNotification()
+*/
+
+/*!
+ \fn void SalomePyQt::hideNotification( const int id );
+ \brief Remove notification with given \a id from the application's desktop.
+
+ \param id notification id
+ \sa showNotification()
+*/
+
+class THideNotifyEvent: public SALOME_Event
+{
+ int myId;
+ QString myMsg;
+
+public:
+ THideNotifyEvent( const QString& msg ) : myId( -1 ), myMsg( msg ) {}
+ THideNotifyEvent( const int id ) : myId( id ) {}
+ virtual void Execute()
+ {
+ if ( LightApp_Application* anApp = getApplication() ) {
+ if ( myId >= 0 )
+ anApp->hideNotification( myId );
+ else
+ anApp->hideNotification( myMsg );
+ }
+ }
+};
+
+void SalomePyQt::hideNotification( const QString& msg )
+{
+ ProcessVoidEvent( new THideNotifyEvent( msg ) );
+}
+
+void SalomePyQt::hideNotification( const int id )
+{
+ ProcessVoidEvent( new THideNotifyEvent( id ) );
+}
+
/*!
\fn const QString SalomePyQt::getActiveComponent();
\brief Get the currently active module name (for the current study).
ProcessVoidEvent( new TEvent( section, name, value ) );
}
+/*!
+ \brief Add font setting to the application preferences.
+ \param section resources file section name
+ \param name setting name
+ \param value new setting value
+*/
+void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value )
+{
+ class TEvent: public SALOME_Event
+ {
+ QString mySection;
+ QString myName;
+ QFont myValue;
+ public:
+ TEvent( const QString& section, const QString& name, const QFont& value )
+ : mySection( section ), myName( name ), myValue( value ) {}
+ virtual void Execute()
+ {
+ if ( SUIT_Session::session() ) {
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ if ( !mySection.isEmpty() && !myName.isEmpty() )
+ resMgr->setValue( mySection, myName, myValue );
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent( section, name, value ) );
+}
+
/*!
\fn int SalomePyQt::integerSetting( const QString& section,
const QString& name,
/*!
\fn QByteArray SalomePyQt::byteArraySetting( const QString& section,
const QString& name,
- const QByteArray def );
+ const QByteArray& def );
\brief Get byte array setting from the application preferences.
\param section resources file section name
\param name setting name
return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) );
}
+/*!
+ \fn QByteArray SalomePyQt::fontSetting( const QString& section,
+ const QString& name,
+ const QFont& def );
+ \brief Get font setting from the application preferences.
+ \param section resources file section name
+ \param name setting name
+ \param def default value which is returned if the setting is not found
+ \return setting value
+*/
+
+class TGetFontSettingEvent: public SALOME_Event
+{
+public:
+ typedef QFont TResult;
+ TResult myResult;
+ QString mySection;
+ QString myName;
+ TResult myDefault;
+ TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def )
+ : mySection( section ), myName( name ), myDefault( def ) {}
+ virtual void Execute()
+ {
+ if ( SUIT_Session::session() ) {
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault;
+ }
+ }
+};
+QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def )
+{
+ return ProcessEvent( new TGetFontSettingEvent( section, name, def ) );
+}
+
/*!
\brief Remove setting from the application preferences.
\param section resources file section name
}
}
};
- ProcessVoidEvent( new TEvent( id, prop, var) );
+ ProcessVoidEvent( new TEvent( id, prop, var ) );
+}
+
+/*!
+ \brief Set specific widget as a custom preferences item.
+ \param id preferences identifier
+ \param prop preferences property name
+ \param widget custom widget
+*/
+void SalomePyQt::setPreferencePropertyWg( const int id,
+ const QString& prop,
+ UserDefinedContent* widget )
+{
+ class TEvent: public SALOME_Event
+ {
+ int myId;
+ QString myProp;
+ UserDefinedContent* myWidget;
+ public:
+ TEvent( const int id, const QString& prop, UserDefinedContent* widget )
+ : myId( id ), myProp( prop ), myWidget( widget ) {}
+ virtual void Execute()
+ {
+ LightApp_Module* module = getActiveModule();
+ if ( module ) {
+ LightApp_Preferences* pref = module->getApp()->preferences();
+ if ( pref ) {
+ pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId );
+ }
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent( id, prop, widget ) );
}
/*!
return ProcessEvent( new TSetViewSize( w, h, id ) );
}
+/*!
+ \fn bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id );
+ \brief Set view rotation point
+ \param x coordinate X view rotation point
+ \param y coordinate Y view rotation point
+ \param z coordinate Z view rotation point
+ \param id window identifier
+ \return \c true if operation is completed successfully and \c false otherwise
+*/
+
+class TSetViewRotationPoint: public SALOME_Event
+{
+public:
+ typedef bool TResult;
+ TResult myResult;
+ double myX;
+ double myY;
+ double myZ;
+ int myWndId;
+ TSetViewRotationPoint( const double x, const double y, const double z, const int id )
+ : myResult( false ),
+ myX( x ),
+ myY( y ),
+ myZ( z ),
+ myWndId( id ) {}
+ virtual void Execute()
+ {
+ SUIT_ViewWindow* wnd = 0;
+ if ( !myWndId ) {
+ if ( LightApp_Application* anApp = getApplication() ) {
+ SUIT_ViewManager* vm = anApp->activeViewManager();
+ if ( vm )
+ wnd = vm->getActiveView();
+ }
+ }
+ else {
+ wnd = dynamic_cast<SUIT_ViewWindow*>( getWnd( myWndId ) );
+ }
+ if ( wnd ) {
+ SUIT_ViewManager* viewMgr = wnd->getViewManager();
+ if ( viewMgr ) {
+ QString type = viewMgr->getType();
+ if ( type == "OCCViewer") {
+#ifndef DISABLE_OCCVIEWER
+ // specific processing for OCC viewer:
+ // OCC view can embed up to 4 sub-views, split according to the specified layout;
+ // - if there is only one sub-view active; its rotation point will be changed;
+ // - if there are several sub-views, rotaion points of each of them will be changed.
+ OCCViewer_ViewWindow* occView = qobject_cast<OCCViewer_ViewWindow*>( wnd );
+ if ( occView ) {
+ for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
+ if ( occView && occView->getView( i ) ) {
+ occView->getView( i )->activateSetRotationSelected( myX, myY, myZ );
+ myResult = true;
+ }
+ }
+ }
+#endif // DISABLE_OCCVIEWER
+ }
+ else if ( type == "VTKViewer") {
+#ifndef DISABLE_VTKVIEWER
+ SVTK_ViewWindow* vtkView = qobject_cast<SVTK_ViewWindow*>( wnd );
+ if ( vtkView )
+ {
+ double aCenter[3] = { myX, myY, myZ };
+ vtkView->activateSetRotationSelected( (void*)aCenter );
+ myResult = true;
+ }
+#endif // DISABLE_VTKVIEWER
+ }
+ }
+ }
+ }
+};
+bool SalomePyQt::setViewRotationPoint( const double x, const double y, const double z, const int id )
+{
+ return ProcessEvent( new TSetViewRotationPoint( x, y, z, id ) );
+}
+
/*!
\fn QString SalomePyQt::getViewTitle( const int id );
\brief Get view caption
bool myVisible;
int myWidth;
int myHeight;
- TCreateView( const QString& theType, bool visible, const int width, const int height )
+ bool myDetached;
+ TCreateView( const QString& theType, bool visible, const int width, const int height, bool detached )
: myResult( -1 ),
myType( theType ),
myVisible(visible),
myWidth(width),
- myHeight(height) {}
+ myHeight(height),
+ myDetached(detached) {}
virtual void Execute()
{
LightApp_Application* app = getApplication();
if ( app ) {
- SUIT_ViewManager* viewMgr = app->createViewManager( myType );
+ SUIT_ViewManager* viewMgr = app->createViewManager( myType, myDetached );
if ( viewMgr ) {
QWidget* wnd = viewMgr->getActiveView();
myResult = viewMgr->getActiveView()->getId();
}
}
};
-int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height )
+int SalomePyQt::createView( const QString& type, bool visible, const int width, const int height, bool detached )
{
- int ret = ProcessEvent( new TCreateView( type, visible, width, height ) );
+ int ret = ProcessEvent( new TCreateView( type, visible, width, height, detached ) );
QCoreApplication::processEvents();
return ret;
}