From 585060429da969e09b7edf65e2cbc77157378e13 Mon Sep 17 00:00:00 2001 From: smh Date: Tue, 20 Apr 2004 08:16:06 +0000 Subject: [PATCH] Merge from QT_EVENT branch --- src/SALOMEGUI/Makefile.in | 6 +- src/SALOMEGUI/QAD_Desktop.cxx | 358 +++++++++++++----------- src/SALOMEGUI/QAD_Desktop.h | 17 +- src/SALOMEGUI/QAD_PyEditor.cxx | 224 +++++++++------ src/SALOMEGUI/QAD_PyEditor.h | 22 +- src/SALOMEGUI/SALOMEGUI.cxx | 261 ++++++++++------- src/SALOMEGUI/SALOMEGUI.h | 81 ++++++ src/SALOMEGUI/SALOMEGUI_Application.cxx | 112 ++------ 8 files changed, 625 insertions(+), 456 deletions(-) create mode 100644 src/SALOMEGUI/SALOMEGUI.h diff --git a/src/SALOMEGUI/Makefile.in b/src/SALOMEGUI/Makefile.in index 08d0682d3..3f7bc1c78 100644 --- a/src/SALOMEGUI/Makefile.in +++ b/src/SALOMEGUI/Makefile.in @@ -92,6 +92,7 @@ EXPORT_HEADERS = \ Handle_SALOME_NumberFilter.hxx \ SALOME_DataMapOfIOMapOfInteger.hxx \ Handle_SALOME_DataMapNodeOfDataMapOfIOMapOfInteger.hxx \ + SALOMEGUI.h \ SALOMEGUI_LoadStudiesDlg.h \ SALOMEGUI_TableDlg.h \ SALOMEGUI_NameDlg.h \ @@ -99,7 +100,6 @@ EXPORT_HEADERS = \ SALOMEGUI_SetupCurveDlg.h \ SALOMEGUI_CloseDlg.h - # .po files to transform in .qm PO_FILES = \ QAD_icons.po \ @@ -150,6 +150,7 @@ LIB_SRC = \ QAD_StudyFrame.cxx \ QAD_Tools.cxx \ QAD_ViewFrame.cxx \ + SALOMEGUI.cxx \ SALOMEGUI_Application.cxx \ SALOMEGUI_Desktop.cxx \ SALOMEGUI_ImportOperation.cxx \ @@ -182,6 +183,7 @@ LIB_SRC = \ SALOMEGUI_CloseDlg.cxx \ SALOMEGUI_ActivateComponentDlg.cxx LIB_MOC = \ + SALOMEGUI.h \ SALOMEGUI_Application.h \ SALOMEGUI_Desktop.h \ QAD_Application.h \ @@ -218,7 +220,7 @@ LIB_CLIENT_IDL = SALOMEDS.idl \ SALOME_Exception.idl CPPFLAGS+=$(QT_INCLUDES) $(PYTHON_INCLUDES) $(OCC_INCLUDES) -LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lqsplitterP -lSalomeLifeCycleCORBA -lOpUtil -lSalomeObject +LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lqsplitterP -lSalomeLifeCycleCORBA -lOpUtil -lSalomeObject -lEvent LIBS+= $(PYTHON_LIBS) diff --git a/src/SALOMEGUI/QAD_Desktop.cxx b/src/SALOMEGUI/QAD_Desktop.cxx index 380702a0d..892cc2e52 100644 --- a/src/SALOMEGUI/QAD_Desktop.cxx +++ b/src/SALOMEGUI/QAD_Desktop.cxx @@ -55,6 +55,7 @@ //NRI #include "QAD_HelpWindow.h" #include "QAD_DirListDlg.h" #include "QAD_WaitCursor.h" +#include "SALOMEGUI.h" #include "SALOMEGUI_OpenWith.h" #include "SALOMEGUI_StudyPropertiesDlg.h" #include "SALOMEGUI_TrihedronSizeDlg.h" @@ -71,6 +72,8 @@ #include "SALOMEGUI_CloseDlg.h" #include "SALOMEGUI_ActivateComponentDlg.h" +#include "SALOME_Event.hxx" + // QT Includes #include #include @@ -101,6 +104,7 @@ #endif // Open CASCADE Includes +#include #include #include #include @@ -446,9 +450,43 @@ bool QAD_Desktop::eventFilter( QObject* o, QEvent* e ) } } } + else if ( e->type() == SALOME_EVENT ) { + SALOME_Event* aSE = (SALOME_Event*)((QCustomEvent*)e)->data(); + MESSAGE( "QAD_Desktop::eventFilter - SALOME_Event handling - 1 : o = " << o << ", e = " << aSE); + + processEvent( aSE ); + MESSAGE( "QAD_Desktop::eventFilter - SALOME_Event handling - 2" ); + + // Signal the calling thread that the event has been processed + aSE->processed(); + MESSAGE( "QAD_Desktop::eventFilter - SALOME_Event handling - 3" ); + + ((QCustomEvent*)e)->setData( 0 ); + delete aSE; + return TRUE; + } return QMainWindow::eventFilter( o, e ); } +/*! + Dispatches to the target component GUI +*/ +void QAD_Desktop::processEvent( SALOME_Event* theEvent ) +{ + if ( !theEvent ) + return; + + if(theEvent->Execute()) + return; + + // san - temporary code - to be removed together with VISU_Event and test operations in VISU_I... + for ( ComponentMap::iterator it = myComponents.begin(); it != myComponents.end(); it++ ) { + if ( it.data()->CanProcessEvent( theEvent ) && it.data()->ProcessEvent( theEvent ) ) + break; + } + // san - temporary code - to be removed together with VISU_Event and test operations in VISU_I... +} + /*! Creates and initializes the standard file operations such as 'New/Open/Save/SaveAs/Close' and 'Help'. @@ -2580,28 +2618,20 @@ void QAD_Desktop::onOpenWith() QApplication::restoreOverrideCursor(); } -typedef bool OneDim1(QAD_Desktop*); -typedef bool OneDim2(QAD_Desktop*, char*); /*! Called to define settings of component. */ void QAD_Desktop::setSettings() { - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings"); - if ( osdF != NULL ) - if (_islibso) - { - OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF; - (*f1)(this); - } - else - { - QString Component =mapComponentName[myActiveComp]; - OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF; - (*f1)(this, (char*)Component.latin1()); - } + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) { + if (_islibso) + anActiveGUI->SetSettings( this ); + else { + QString Component = mapComponentName[myActiveComp]; + anActiveGUI->SetSettings( this, (char*)Component.latin1() ); + } } } @@ -2681,95 +2711,19 @@ bool QAD_Desktop::loadComponent(QString Component) int nbToolbars = 0; if (myActiveMenus) nbToolbars = myActiveMenus->getToolBarList().count(); - /* Open Shared Library */ - mySharedLibrary = OSD_SharedLibrary(); - _islibso = false; - - QString ComponentLib; - QCString libs; - QFileInfo fileInfo ; - QString fileString ; - QString dir; - - if ( libs = getenv("LD_LIBRARY_PATH")) { - // MESSAGE ( " LD_LIBRARY_PATH : " << libs ); - QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries - for ( int i = dirList.count()-1; i >= 0; i-- ) { - dir = dirList[ i ]; -#ifdef WNT - fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.dll" ; -#else - fileString = QAD_Tools::addSlash( dir ) + "lib" + Component + "GUI.so" ; -#endif - - fileInfo.setFile(fileString) ; - if (fileInfo.exists()) { - // MESSAGE ( " GUI library = " << fileString ); - ComponentLib = fileInfo.fileName() ; - _islibso = true; - break; - } - } - } - - if (!_islibso) // component GUI could be in PyQt, use generic library - { - MESSAGE("GUI library not found, trying generic library for PyQt GUI"); - bool found = false; - if (dir = getenv("KERNEL_ROOT_DIR")) - { - dir = QAD_Tools::addSlash(dir) ; - dir = dir + "lib" ; - dir = QAD_Tools::addSlash(dir) ; - dir = dir + "salome" ; - dir = QAD_Tools::addSlash(dir) ; -#ifdef WNT - dir = dir + "libSalomePyQtcmodule.dll" ; -#else - dir = dir + "libSalomePyQtcmodule.so" ; -#endif - MESSAGE ( " GUI library = " << dir ); - fileInfo.setFile(dir) ; - if (fileInfo.exists()) - { - ComponentLib = fileInfo.fileName() ; - found = true; - } - } - if ( !found ) - { - QMessageBox::critical( this, - tr("ERR_ERROR"), - tr("ERR_LIBGUI" ).arg(Component) ); - return false; - } - } - mySharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString()); - ok = mySharedLibrary.DlOpen(OSD_RTLD_LAZY); - if (!ok) { - wc.stop(); - QMessageBox::critical( this, - tr("ERR_ERROR"), - tr( mySharedLibrary.DlError() ) ); + // san - avoid loading component GUI library multiple times + QString aUserName( getComponentUserName( Component ) ); + + SALOMEGUI* anActiveGUI = getComponentGUI(aUserName); + if ( !anActiveGUI ) return false; - } /* SETTINGS */ - OSD_Function osdF = mySharedLibrary.DlSymb("SetSettings"); - if ( osdF != NULL ) - if (_islibso) - { - OneDim1 (*f1) = (bool (*) (QAD_Desktop*)) osdF; - (*f1)(this); - } - else - { - OneDim2 (*f1) = (bool (*) (QAD_Desktop*, char*)) osdF; - (*f1)(this, (char*)Component.latin1()); - } - - + if (_islibso) + anActiveGUI->SetSettings( this ); + else + anActiveGUI->SetSettings( this, (char*)Component.latin1() ); /* COMPONENT INTERFACE */ SALOME_ModuleCatalog::Acomponent_ptr aComponent = @@ -3048,14 +3002,9 @@ void QAD_Desktop::onDispatchTools(int id) */ void QAD_Desktop::onDispatch(int id) { - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("OnGUIEvent"); - OneDim (*f1) = NULL; - if ( osdF != NULL ) { - f1 = (bool (*) (int, QAD_Desktop*)) osdF; - (*f1)(id,this); - } - } + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) + anActiveGUI->OnGUIEvent(id,this); } /*! @@ -3246,13 +3195,9 @@ typedef bool TwoDim1(QKeyEvent* pe, QAD_Desktop*, QAD_StudyFrame*); void QAD_Desktop::onKeyPress( QKeyEvent* pe ) { // MESSAGE ( "QAD_Desktop::onKeyPress" ) - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("OnKeyPress"); - if ( osdF != NULL ) { - TwoDim1 (*f1) = (bool (*) (QKeyEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF; - (*f1)(pe,this,myActiveStudy->getActiveStudyFrame()); - } - } + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) + anActiveGUI->OnKeyPress(pe,this,myActiveStudy->getActiveStudyFrame()); } typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*); @@ -3262,13 +3207,9 @@ typedef bool TwoDim(QMouseEvent* pe, QAD_Desktop*, QAD_StudyFrame*); bool QAD_Desktop::onMousePress( QMouseEvent* pe ) { // MESSAGE ( "QAD_Desktop::onMousePress" ) - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("OnMousePress"); - if ( osdF != NULL ) { - TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF; - return (*f1)(pe,this,myActiveStudy->getActiveStudyFrame()); - } - } + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) + return anActiveGUI->OnMousePress(pe,this,myActiveStudy->getActiveStudyFrame()); return false; } @@ -3277,13 +3218,9 @@ bool QAD_Desktop::onMousePress( QMouseEvent* pe ) */ void QAD_Desktop::onMouseMove( QMouseEvent* pe ) { - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("OnMouseMove"); - if ( osdF != NULL ) { - TwoDim (*f1) = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF; - (*f1)(pe,this,myActiveStudy->getActiveStudyFrame()); - } - } + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) + anActiveGUI->OnMouseMove(pe,this,myActiveStudy->getActiveStudyFrame()); } /*! @@ -3294,20 +3231,129 @@ const QString& QAD_Desktop::getActiveComponent() const return myActiveComp; } +SALOMEGUI* QAD_Desktop::getActiveGUI() +{ + SALOMEGUI* anActiveGUI = 0; + if ( myComponents.find( myActiveComp ) != myComponents.end() ) + anActiveGUI = myComponents[myActiveComp]; + return anActiveGUI; +} -typedef bool defineP( QString & theContext, QString & theParent, QString & theObject); +typedef SALOMEGUI* (*ComponentGUI)(); -void QAD_Desktop::definePopup(QString & theContext, - QString & theParent, - QString & theObject ) +SALOMEGUI* QAD_Desktop::getComponentGUI( const QString& component ) { - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("definePopup"); + SALOMEGUI* aCompGUI = 0; + + // Load component GUI if requested for the first time + if ( myComponents.find( component ) == myComponents.end() ) { + OSD_SharedLibrary aSharedLibrary; + QString ComponentLib; + QCString libs; + QFileInfo fileInfo ; + QString fileString ; + QString dir; + + QAD_WaitCursor wc; + + if ( libs = getenv("LD_LIBRARY_PATH")) { + // MESSAGE ( " LD_LIBRARY_PATH : " << libs ); + QStringList dirList = QStringList::split( SEPARATOR, libs, false ); // skip empty entries + for ( int i = dirList.count()-1; i >= 0; i-- ) { + dir = dirList[ i ]; +#ifdef WNT + fileString = QAD_Tools::addSlash( dir ) + "lib" + getComponentName( component ) + "GUI.dll" ; +#else + fileString = QAD_Tools::addSlash( dir ) + "lib" + getComponentName( component ) + "GUI.so" ; +#endif + + fileInfo.setFile(fileString) ; + if (fileInfo.exists()) { + // MESSAGE ( " GUI library = " << fileString ); + ComponentLib = fileInfo.fileName() ; + _islibso = true; + break; + } + } + } + + if (!_islibso) // component GUI could be in PyQt, use generic library + { + MESSAGE("GUI library not found, trying generic library for PyQt GUI"); + bool found = false; + if (dir = getenv("KERNEL_ROOT_DIR")) + { + dir = QAD_Tools::addSlash(dir) ; + dir = dir + "lib" ; + dir = QAD_Tools::addSlash(dir) ; + dir = dir + "salome" ; + dir = QAD_Tools::addSlash(dir) ; +#ifdef WNT + dir = dir + "libSalomePyQtcmodule.dll" ; +#else + dir = dir + "libSalomePyQtcmodule.so" ; +#endif + MESSAGE ( " GUI library = " << dir ); + fileInfo.setFile(dir) ; + if (fileInfo.exists()) + { + ComponentLib = fileInfo.fileName() ; + found = true; + } + } + if ( !found ) + { + QMessageBox::critical( this, + tr("ERR_ERROR"), + tr("ERR_LIBGUI" ).arg(component) ); + return aCompGUI; + } + } + + aSharedLibrary.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString()); + bool ok = aSharedLibrary.DlOpen(OSD_RTLD_LAZY); + if (!ok) { + wc.stop(); + QMessageBox::critical( this, + tr("ERR_ERROR"), + tr( aSharedLibrary.DlError() ) ); + return aCompGUI; + } + + OSD_Function osdF = aSharedLibrary.DlSymb("GetComponentGUI"); if ( osdF != NULL ) { - defineP (*f1) = (bool (*) (QString &, QString &, QString &)) osdF; - (*f1)(theContext, theParent, theObject); + ComponentGUI f1 = (SALOMEGUI* (*) ()) osdF; + SALOMEGUI* aCompGUI = (*f1)(); + if ( aCompGUI ) + myComponents.insert( component, aCompGUI ); + else { + wc.stop(); + QMessageBox::critical( this, + tr("ERR_ERROR"), + tr("ERR_LIBGUI" ).arg(component) ); + return aCompGUI; + } + } + else { + wc.stop(); + QMessageBox::critical( this, + tr("ERR_ERROR"), + tr("ERR_LIBGUI" ).arg(component) ); + return aCompGUI; } } + aCompGUI = myComponents[component]; + return aCompGUI; +} + + +void QAD_Desktop::definePopup(QString & theContext, + QString & theParent, + QString & theObject ) +{ + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) + anActiveGUI->DefinePopup(theContext, theParent, theObject); } @@ -3388,47 +3434,29 @@ void QAD_Desktop::createPopup(QPopupMenu* popup, const QString & theContext, } -typedef bool activeStudyChanged(QAD_Desktop*); -typedef void deactivate(); - void QAD_Desktop::onActiveStudyChanged() { - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("activeStudyChanged"); - if ( osdF != NULL ) { - activeStudyChanged (*f1) = (bool (*) (QAD_Desktop*)) osdF; - (*f1)(this); - } - } + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) + anActiveGUI->ActiveStudyChanged(this); } void QAD_Desktop::deactivateComponent() { - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("deactivate"); - if ( osdF != NULL ) { - deactivate (*f1) = (void (*)()) osdF; - (*f1)(); - } - } + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) + anActiveGUI->Deactivate(); } -typedef bool customP(QAD_Desktop*, QPopupMenu*, const QString & theContext, - const QString & theParent, const QString & theObject); /*! Custom popup ( GUI Library ) */ void QAD_Desktop::customPopup(QPopupMenu* popup, const QString & theContext, const QString & theParent, const QString & theObject) { - if (!myActiveComp.isEmpty()) { - OSD_Function osdF = mySharedLibrary.DlSymb("customPopup"); - if ( osdF != NULL ) { - customP (*f1) = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString &, - const QString &, const QString &)) osdF; - (*f1)(this, popup, theContext, theParent, theObject); - } - } + SALOMEGUI* anActiveGUI = getActiveGUI(); + if ( anActiveGUI ) + anActiveGUI->CustomPopup(this, popup, theContext, theParent, theObject); } void QAD_Desktop::onObjectBrowser() diff --git a/src/SALOMEGUI/QAD_Desktop.h b/src/SALOMEGUI/QAD_Desktop.h index 2f1fab179..96d3b9089 100644 --- a/src/SALOMEGUI/QAD_Desktop.h +++ b/src/SALOMEGUI/QAD_Desktop.h @@ -60,10 +60,9 @@ #include #include -// Open CASCADE Includes -#include - class QAD_XmlHandler; +class SALOMEGUI; +class SALOME_Event; class QAD_EXPORT QAD_Desktop : public QMainWindow { @@ -163,8 +162,9 @@ public: QAD_Menus* getActiveMenus() {return myActiveMenus;} QAD_OperatorMenus* getOperatorMenus() {return myOperatorMenus;} - const OSD_SharedLibrary& getHandle() const {return mySharedLibrary;}// never return sych objects "by value" const QString& getActiveComponent() const; + SALOMEGUI* getActiveGUI(); + SALOMEGUI* getComponentGUI( const QString& ); // accepts component`s user name SALOME_NamingService* getNameService() {return myNameService;} Engines::Component_var getEngine(const char *containerName, @@ -324,12 +324,17 @@ protected: QMap mapComponentName; +private: + void processEvent( SALOME_Event* ); + +private: + typedef QMap ComponentMap; + private: static QAD_ResourceMgr* resourceMgr; static QPalette* palette; void createActions(); void updateActions(); - OSD_SharedLibrary mySharedLibrary; QAD_XmlHandler* myXmlHandler; QString myActiveComp; SALOME_NamingService* myNameService; @@ -338,6 +343,8 @@ private: QComboBox * myCombo; bool myQueryClose; bool _islibso; + + ComponentMap myComponents; }; /******************************************************************** diff --git a/src/SALOMEGUI/QAD_PyEditor.cxx b/src/SALOMEGUI/QAD_PyEditor.cxx index a125e4fa7..8c4744d28 100644 --- a/src/SALOMEGUI/QAD_PyEditor.cxx +++ b/src/SALOMEGUI/QAD_PyEditor.cxx @@ -26,7 +26,6 @@ // Module : SALOME // $Header$ -using namespace std; #include "QAD_PyEditor.h" #include "QAD_PyInterp.h" #include "QAD_Application.h" @@ -35,10 +34,12 @@ using namespace std; #include "QAD_Tools.h" #include "QAD_MessageBox.h" //#include "QAD_RightFrame.h" +using namespace std; #include #include #include +#include // NRI : Temporary added // IDL Headers @@ -50,17 +51,51 @@ using namespace std; #define SIZEPR 4 enum { IdCopy, IdPaste, IdClear, IdSelectAll }; +class PythonThread : public QThread +{ +public: + PythonThread( PyInterp_base* interp, QAD_PyEditor* listener ) + : QThread(), myInterp( interp ), myListener( listener ), myCommand( 0 ) + {} + + virtual ~PythonThread() {} + + void exec( const char* command ) + { + myCommand = (char*)command; + start(); + } + +protected: + virtual void run() + { + if ( myInterp && myCommand && myListener ) { + myListener->viewport()->setCursor( waitCursor ); + int ret = myInterp->run( myCommand ); + QThread::postEvent( myListener, + new QCustomEvent( ret < 0 ? QAD_PyEditor::PYTHON_ERROR : ( ret ? QAD_PyEditor::PYTHON_INCOMPLETE : QAD_PyEditor::PYTHON_OK ) ) ); + myListener->viewport()->unsetCursor(); + } + } + +private: + PyInterp_base* myInterp; + QAD_PyEditor* myListener; + char* myCommand; +}; + /*! Constructor */ QAD_PyEditor::QAD_PyEditor(QAD_PyInterp* interp, QWidget *parent, const char *name) - : QMultiLineEdit(parent,name) + : QTextEdit(parent,name) { QString fntSet = QAD_CONFIG->getSetting("Viewer:ConsoleFont"); QFont myFont = QAD_Tools::stringToFont( fntSet ); // QFont myFont("Courier",11); setFont(myFont); + setTextFormat(QTextEdit::PlainText); _interp = interp; string banner = _interp->getbanner(); setText(banner.c_str()); @@ -72,6 +107,9 @@ QAD_PyEditor::QAD_PyEditor(QAD_PyInterp* interp, setText(_currentPrompt); setPalette( QAD_Application::getPalette(true) ); setWordWrap(NoWrap); + + _thread = new PythonThread( interp, this ); + connect(this,SIGNAL(returnPressed()),this,SLOT(handleReturn()) ); } @@ -80,6 +118,8 @@ QAD_PyEditor::QAD_PyEditor(QAD_PyInterp* interp, */ QAD_PyEditor::~QAD_PyEditor() { + if ( _thread->wait( 1000 ) ) + delete _thread; } /*! @@ -88,11 +128,11 @@ QAD_PyEditor::~QAD_PyEditor() void QAD_PyEditor::setText(QString s) { // MESSAGE("setText"); - int line=numLines()-1; - int col=lineLength(line); - insertAt(s,line,col); - int n = numLines()-1; - setCursorPosition( n, textLine(n).length()); + int para=paragraphs()-1; + int col=paragraphLength(para); + insertAt(s,para,col); + int n = paragraphs()-1; + setCursorPosition( n, paragraphLength(n)); } /*! @@ -100,9 +140,8 @@ void QAD_PyEditor::setText(QString s) */ void QAD_PyEditor::handleReturn() { - QApplication::setOverrideCursor( Qt::waitCursor ); int ret; - int line=numLines()-2; + int para=paragraphs()-2; // NRI : Temporary added SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); @@ -121,24 +160,10 @@ void QAD_PyEditor::handleReturn() } // NRI - _buf.append(textLine(line).remove(0,SIZEPR)); - ret = _interp->run(_buf); - if(ret <= 0) - { - _buf.truncate(0); - setText(_interp->getvout()); - setText(_interp->getverr()); - _currentPrompt = ">>> "; - setText(_currentPrompt); - } - if(ret == 1) - { - _buf.append("\n"); - _currentPrompt = "... "; - setText(_currentPrompt); - } - _isInHistory = false; - QApplication::restoreOverrideCursor(); + _buf.append(text(para).remove(0,SIZEPR)); + _buf.truncate( _buf.length() - 1 ); + setReadOnly( true ); + _thread->exec(_buf.latin1()); } /* @@ -150,10 +175,10 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event) QPopupMenu *popup = new QPopupMenu( this ); QMap idMap; - int line1, col1, line2, col2; - getMarkedRegion(&line1, &col1, &line2, &col2); - bool allSelected = getMarkedRegion(&line1, &col1, &line2, &col2) && - line1 == 0 && line2 == numLines()-1 && col1 == 0 && col2 == lineLength(line2); + int para1, col1, para2, col2; + getSelection(¶1, &col1, ¶2, &col2); + bool allSelected = hasSelectedText() && + para1 == 0 && para2 == paragraphs()-1 && col1 == 0 && para2 == paragraphLength(para2); int id; id = popup->insertItem( tr( "EDIT_COPY_CMD" ) ); idMap.insert(IdCopy, id); @@ -164,7 +189,7 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event) popup->insertSeparator(); id = popup->insertItem( tr( "EDIT_SELECTALL_CMD" ) ); idMap.insert(IdSelectAll, id); - popup->setItemEnabled( idMap[ IdCopy ], hasMarkedText() ); + popup->setItemEnabled( idMap[ IdCopy ], hasSelectedText() ); popup->setItemEnabled( idMap[ IdPaste ], !isReadOnly() && (bool)QApplication::clipboard()->text().length() ); popup->setItemEnabled( idMap[ IdSelectAll ], @@ -191,7 +216,7 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event) return; } else { - QMultiLineEdit::mousePressEvent(event); + QTextEdit::mousePressEvent(event); } } @@ -201,14 +226,14 @@ void QAD_PyEditor::mousePressEvent (QMouseEvent * event) void QAD_PyEditor::mouseReleaseEvent ( QMouseEvent * e ) { // MESSAGE("mouseReleaseEvent"); - int curLine, curCol; // for cursor position - int endLine, endCol; // for last edited line - getCursorPosition(&curLine, &curCol); - endLine = numLines() -1; + int curPara, curCol; // for cursor position + int endPara, endCol; // for last edited line + getCursorPosition(&curPara, &curCol); + endPara = paragraphs() -1; if (e->button() != MidButton) - QMultiLineEdit::mouseReleaseEvent(e); - else if ((curLine == endLine) && (curCol >= SIZEPR)) - QMultiLineEdit::mouseReleaseEvent(e); + QTextEdit::mouseReleaseEvent(e); + else if ((curPara == endPara) && (curCol >= SIZEPR)) + QTextEdit::mouseReleaseEvent(e); } /*! @@ -239,7 +264,7 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) int curLine, curCol; // for cursor position int endLine, endCol; // for last edited line getCursorPosition(&curLine, &curCol); - endLine = numLines() -1; + endLine = paragraphs() -1; //MESSAGE("current position " << curLine << ", " << curCol); //MESSAGE("last line " << endLine); //MESSAGE(e->key()); @@ -257,34 +282,30 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) { case 0 : { - if (curLine 0 ){ - setCursorPosition(curLine-1, curCol, true); + moveCursor(QTextEdit::MoveUp, true); } // scroll the commands stack up else { @@ -292,18 +313,18 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) if (! _isInHistory) { _isInHistory = true; - _currentCommand = textLine(endLine).remove(0,SIZEPR); + _currentCommand = text(endLine).remove(0,SIZEPR); + _currentCommand.truncate( _currentCommand.length() - 1 ); SCRUTE(_currentCommand); } QString previousCommand = _interp->getPrevious(); if (previousCommand.compare(BEGIN_HISTORY_PY) != 0) { - removeLine(endLine); + removeParagraph(endLine); histLine.append(previousCommand); - insertLine(histLine); + insertParagraph(histLine, -1); } - endLine = numLines() -1; - setCursorPosition(endLine, lineLength(endLine)); + moveCursor(QTextEdit::MoveEnd, false); } break; } @@ -311,11 +332,11 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) { // if Cntr+Key_Down event then move cursor down if (ctrlPressed) { - QMultiLineEdit::cursorDown( ); + moveCursor(QTextEdit::MoveDown, false); } // if Shift+Key_Down event then move cursor down and select the text else if ( shftPressed && curLine < endLine ) { - setCursorPosition(curLine+1, curCol, true); + moveCursor(QTextEdit::MoveDown, true); } // scroll the commands stack down else { @@ -323,62 +344,79 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) QString nextCommand = _interp->getNext(); if (nextCommand.compare(TOP_HISTORY_PY) != 0) { - removeLine(endLine); + removeParagraph(endLine); histLine.append(nextCommand); - insertLine(histLine); + insertParagraph(histLine, -1); } else if (_isInHistory) { _isInHistory = false; - removeLine(endLine); + removeParagraph(endLine); histLine.append(_currentCommand); - insertLine(histLine); + insertParagraph(histLine, -1); } - endLine = numLines() -1; - setCursorPosition(endLine, lineLength(endLine)); + moveCursor(QTextEdit::MoveEnd, false); } break; } case Key_Left: { - if (!shftPressed && isCommand(textLine(curLine)) && curCol <= SIZEPR ) + if (!shftPressed && isCommand(text(curLine)) && curCol <= SIZEPR ) { setCursorPosition((curLine -1), SIZEPR); - end(); + moveCursor(QTextEdit::MoveLineEnd, false); } - else QMultiLineEdit::keyPressEvent( e ); + else QTextEdit::keyPressEvent( e ); break; } case Key_Right: { - if (!shftPressed && isCommand(textLine(curLine)) - && curCol < SIZEPR) setCursorPosition(curLine, SIZEPR-1); - QMultiLineEdit::keyPressEvent( e ); + if (!shftPressed && isCommand(text(curLine)) + && curCol < SIZEPR) setCursorPosition(curLine, SIZEPR); + QTextEdit::keyPressEvent( e ); break; } case Key_Home: { - if (isCommand(textLine(curLine)) && curCol <= SIZEPR) - setCursorPosition(curLine, SIZEPR, shftPressed); - else setCursorPosition(curLine, 0, shftPressed); + horizontalScrollBar()->setValue( horizontalScrollBar()->minValue() ); + if (isCommand(text(curLine))) { + setCursorPosition(curLine, SIZEPR); + if ( curCol > SIZEPR && shftPressed ) + setSelection( curLine, SIZEPR, curLine, curCol ); + else + selectAll( false ); + } + else moveCursor(QTextEdit::MoveLineStart, shftPressed); break; } case Key_End: { - setCursorPosition(curLine, textLine(curLine).length(), shftPressed); + moveCursor(QTextEdit::MoveLineEnd, shftPressed); break; } case Key_Backspace : { if ((curLine == endLine) && (curCol > SIZEPR)) - QMultiLineEdit::keyPressEvent( e ); + QTextEdit::keyPressEvent( e ); break; } case Key_Delete : { if ((curLine == endLine) && (curCol > SIZEPR-1)) - QMultiLineEdit::keyPressEvent( e ); + QTextEdit::keyPressEvent( e ); + break; + } + case Key_Insert : + { + if ( ctrlPressed ) + copy(); + else if ( shftPressed ) { + moveCursor(QTextEdit::MoveEnd, false); + paste(); + } + else + QTextEdit::keyPressEvent( e ); break; } } @@ -398,3 +436,31 @@ void QAD_PyEditor::keyPressEvent( QKeyEvent *e ) QAD_Application::getDesktop()->onKeyPress( e ); // NRI // } + +void QAD_PyEditor::customEvent(QCustomEvent *e) +{ + switch( e->type() ) { + case PYTHON_OK: + case PYTHON_ERROR: + { + _buf.truncate(0); + setText(_interp->getvout()); + setText(_interp->getverr()); + _currentPrompt = ">>> "; + setText(_currentPrompt); + break; + } + case PYTHON_INCOMPLETE: + { + _buf.append("\n"); + _currentPrompt = "... "; + setText(_currentPrompt); + break; + } + default: + QTextEdit::customEvent( e ); + } + + setReadOnly( false ); + _isInHistory = false; +} diff --git a/src/SALOMEGUI/QAD_PyEditor.h b/src/SALOMEGUI/QAD_PyEditor.h index 5086b7d94..6e8c8d3d4 100644 --- a/src/SALOMEGUI/QAD_PyEditor.h +++ b/src/SALOMEGUI/QAD_PyEditor.h @@ -29,26 +29,32 @@ #ifndef QAD_PyEditor_H #define QAD_PyEditor_H -#include +#include +#include class QAD_PyInterp; +class PythonThread; -class QAD_PyEditor : public QMultiLineEdit +class QAD_PyEditor : public QTextEdit { Q_OBJECT +public: + enum { PYTHON_OK = QEvent::User + 5000, PYTHON_ERROR, PYTHON_INCOMPLETE }; + public: QAD_PyEditor(QAD_PyInterp* interp, QWidget *parent=0, const char *name=0); ~QAD_PyEditor(); - void setText(QString s); + virtual void setText(QString s); bool isCommand(const QString& str) const; protected: - void keyPressEvent (QKeyEvent * e); - void mousePressEvent (QMouseEvent * e); - void mouseReleaseEvent (QMouseEvent * e); - void dropEvent (QDropEvent *e); + virtual void keyPressEvent (QKeyEvent * e); + virtual void mousePressEvent (QMouseEvent * e); + virtual void mouseReleaseEvent (QMouseEvent * e); + virtual void dropEvent (QDropEvent *e); + virtual void customEvent (QCustomEvent *e); public slots: void handleReturn(); @@ -59,6 +65,8 @@ private: QString _currentCommand; QString _currentPrompt; bool _isInHistory; + + PythonThread* _thread; }; #endif diff --git a/src/SALOMEGUI/SALOMEGUI.cxx b/src/SALOMEGUI/SALOMEGUI.cxx index 69a3b241b..e3843bd25 100644 --- a/src/SALOMEGUI/SALOMEGUI.cxx +++ b/src/SALOMEGUI/SALOMEGUI.cxx @@ -22,109 +22,166 @@ // // // File : SALOMEGUI.cxx -// Author : Nicolas REJNERI +// Author : Sergey ANIKIN // Module : SALOME // $Header$ -using namespace std; -#include -#include CORBA_SERVER_HEADER(SALOMEDS) - -#include "QAD.h" -#include "QAD_MessageBox.h" -#include "QAD_Application.h" -#include "SALOMEGUI_Application.h" - -#include -#include - -#include "SALOME_NamingService.hxx" - -int main(int argc, char* argv[]) -{ - QApplication a( argc, argv ); - - // Setting up the CORBA environment - // Initializing omniORB - SALOME_NamingService * name_service; - CORBA::ORB_var orb; - - // orb = CORBA::ORB_init(argc, argv, "omniORB4"); - orb = CORBA::ORB_init(argc, argv, "omniORB3"); - - // Get the reference the server. - name_service = new SALOME_NamingService(orb); - - QAD_ASSERT ( QObject::connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ) ); - - /* Initialize the desktop and 'SALOMEGUI' application */ - SALOMEGUI_Application* app = - new SALOMEGUI_Application ( "MDTV-Standard", "HDF","hdf" ); - - if ( !SALOMEGUI_Application::addToDesktop ( app, name_service ) ) - { - QAD_MessageBox::error1 ( 0, - QObject::tr("ERR_ERROR"), - QObject::tr("ERR_APP_INITFAILED"), - QObject::tr("BUT_OK") ); - return -1; - } - - QPalette pal; - QColorGroup cg; - cg.setColor( QColorGroup::Foreground, Qt::black ); - cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) ); - cg.setColor( QColorGroup::Light, Qt::white ); - cg.setColor( QColorGroup::Midlight, QColor( 223, 223, 223) ); - cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) ); - cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) ); - cg.setColor( QColorGroup::Text, Qt::black ); - cg.setColor( QColorGroup::BrightText, Qt::white ); - cg.setColor( QColorGroup::ButtonText, Qt::black ); - cg.setColor( QColorGroup::Base, Qt::white ); - cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) ); - cg.setColor( QColorGroup::Shadow, Qt::black ); - cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) ); - cg.setColor( QColorGroup::HighlightedText, Qt::white ); - pal.setActive( cg ); - cg.setColor( QColorGroup::Foreground, Qt::black ); - cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) ); - cg.setColor( QColorGroup::Light, Qt::white ); - cg.setColor( QColorGroup::Midlight, QColor( 220, 220, 220) ); - cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) ); - cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) ); - cg.setColor( QColorGroup::Text, Qt::black ); - cg.setColor( QColorGroup::BrightText, Qt::white ); - cg.setColor( QColorGroup::ButtonText, Qt::black ); - cg.setColor( QColorGroup::Base, Qt::white ); - cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) ); - cg.setColor( QColorGroup::Shadow, Qt::black ); - cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) ); - cg.setColor( QColorGroup::HighlightedText, Qt::white ); - pal.setInactive( cg ); - cg.setColor( QColorGroup::Foreground, QColor( 128, 128, 128) ); - cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) ); - cg.setColor( QColorGroup::Light, Qt::white ); - cg.setColor( QColorGroup::Midlight, QColor( 220, 220, 220) ); - cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) ); - cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) ); - cg.setColor( QColorGroup::Text, Qt::black ); - cg.setColor( QColorGroup::BrightText, Qt::white ); - cg.setColor( QColorGroup::ButtonText, QColor( 128, 128, 128) ); - cg.setColor( QColorGroup::Base, Qt::white ); - cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) ); - cg.setColor( QColorGroup::Shadow, Qt::black ); - cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) ); - cg.setColor( QColorGroup::HighlightedText, Qt::white ); - pal.setDisabled( cg ); - qApp->setPalette( pal ); - - /* Run 'SALOMEGUI' application */ - QAD_Application::run(); - a.exec(); - - delete name_service; - orb->destroy(); - - return 0; +#include "SALOMEGUI.h" + +//============================================================================= +/*! + * + */ +//============================================================================= +SALOMEGUI::SALOMEGUI( const QString& name, QObject* parent ) +: QObject( parent ), + myName( name ) +{ +} + +//============================================================================= +/*! + * + */ +//============================================================================= +SALOMEGUI::~SALOMEGUI() +{ +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent) +{ + return true; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::CanProcessEvent(SALOME_Event* se) +{ + return false; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::ProcessEvent(SALOME_Event* se) +{ + return false; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) +{ + return true; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) +{ + return true; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) +{ + return true; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::SetSettings( QAD_Desktop* parent ) +{ + return true; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::SetSettings( QAD_Desktop* parent, char* compName ) +{ + return true; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::CustomPopup( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext, + const QString & theParent, const QString & theObject ) +{ + return true; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void SALOMEGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject ) +{ +} + +//============================================================================= +/*! + * + */ +//============================================================================= +bool SALOMEGUI::ActiveStudyChanged( QAD_Desktop* parent ) +{ +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void SALOMEGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& theIO ) +{ +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void SALOMEGUI::SupportedViewType(int* buffer, int bufferSize) +{ +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void SALOMEGUI::Deactivate() +{ + emit SignalCloseAllDialogs(); } + diff --git a/src/SALOMEGUI/SALOMEGUI.h b/src/SALOMEGUI/SALOMEGUI.h new file mode 100644 index 000000000..0594487d4 --- /dev/null +++ b/src/SALOMEGUI/SALOMEGUI.h @@ -0,0 +1,81 @@ +// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// +// 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 : SALOMEGUI.hxx +// Author : Sergey ANIKIN +// Module : SALOME +// $Header$ + +#ifndef SALOMEGUI_HeaderFile +#define SALOMEGUI_HeaderFile + +#include + +#include +#include + +class QAD_Desktop; +class QAD_StudyFrame; +class SALOME_Event; + +class Handle_SALOME_InteractiveObject; + +class QKeyEvent; +class QMouseEvent; +class QPopupMenu; +class QString; + + +class Standard_EXPORT SALOMEGUI : public QObject +{ + Q_OBJECT + +public: + SALOMEGUI( const QString& name, QObject* parent = 0 ); + virtual ~SALOMEGUI(); + + virtual bool OnGUIEvent (int theCommandID, QAD_Desktop* parent); + virtual bool CanProcessEvent (SALOME_Event* se); + virtual bool ProcessEvent (SALOME_Event* se); + virtual bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame); + virtual bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame); + virtual bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame); + virtual bool SetSettings ( QAD_Desktop* parent ); + virtual bool SetSettings ( QAD_Desktop* parent, char* compName ); + virtual bool CustomPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext, + const QString & theParent, const QString & theObject ); + virtual void DefinePopup ( QString & theContext, QString & theParent, QString & theObject ); + virtual bool ActiveStudyChanged( QAD_Desktop* parent ); + virtual void BuildPresentation ( const Handle(SALOME_InteractiveObject)& theIO ); + virtual void SupportedViewType (int* buffer, int bufferSize); + virtual void Deactivate (); + +signals: + void SignalDeactivateActiveDialog(); + void SignalCloseAllDialogs (); + +private: + QString myName; +}; + +#endif diff --git a/src/SALOMEGUI/SALOMEGUI_Application.cxx b/src/SALOMEGUI/SALOMEGUI_Application.cxx index fa67befd6..8d95761e9 100644 --- a/src/SALOMEGUI/SALOMEGUI_Application.cxx +++ b/src/SALOMEGUI/SALOMEGUI_Application.cxx @@ -26,10 +26,10 @@ // Module : SALOME // $Header$ -using namespace std; #include "SALOMEGUI_Application.h" #include "SALOMEGUI_Desktop.h" #include "SALOMEGUI_ImportOperation.h" +#include "SALOMEGUI.h" #include "SALOME_Selection.h" #include "SALOME_ListIO.hxx" #include "SALOME_ListIteratorOfListIO.hxx" @@ -51,6 +51,7 @@ using namespace std; // Open CASCADE Include #include #include +using namespace std; /*! Constructor @@ -429,104 +430,26 @@ void SALOMEGUI_Application::onDisplay(int id) return; } - // Obtain the component's GUI library - // Library cashing will be implemented soon in QAD_Desktop to increase performance - OSD_Function osdF, osdViewTypeFunc; - OSD_SharedLibrary foreignGUI; - void (*builder)(const Handle(SALOME_InteractiveObject)&); - bool isForeignGUIUsed = false; bool isViewTypeOK = true; int viewTypes[VIEW_TYPE_MAX]; for (int i = 0; i < VIEW_TYPE_MAX; i++) viewTypes[i] = -1; - if (parentComp.compare(desktop->getActiveComponent()) == 0) { // use active GUI library - const OSD_SharedLibrary& compGUI = desktop->getHandle(); - osdF = compGUI.DlSymb("buildPresentation"); - if ( osdF == NULL ) { - MESSAGE("BuildPresentation method not found in component's GUI") - return; - } - osdViewTypeFunc = compGUI.DlSymb("supportedViewType"); - if ( osdViewTypeFunc == NULL ) { - MESSAGE("supportedViewType method not found in component's GUI") - } - MESSAGE("onDisplay(): using active GUI to build presentations") - } else { // use native GUI library - QString ComponentLib; - QCString dir; - QFileInfo fileInfo ; - bool found = false; - if ( getenv( QAD_Application::getDesktop()->getComponentName(parentComp) + "_ROOT_DIR") ) { - dir.fill('\0'); - dir.sprintf("%s", getenv( QAD_Application::getDesktop()->getComponentName(parentComp) + "_ROOT_DIR")); - dir = QAD_Tools::addSlash(dir) ; - dir = dir + "lib" ; - dir = QAD_Tools::addSlash(dir) ; - dir = dir + "salome" ; - dir = QAD_Tools::addSlash(dir) ; -#ifdef WNT - dir = dir + "lib" + QAD_Application::getDesktop()->getComponentName(parentComp).latin1() + "GUI.dll" ; -#else - dir = dir + "lib" + QAD_Application::getDesktop()->getComponentName(parentComp).latin1() + "GUI.so" ; -#endif - MESSAGE ( " GUI library = " << dir ) - fileInfo.setFile(dir) ; - if (fileInfo.exists()) { - ComponentLib = fileInfo.fileName() ; - found = true; - MESSAGE ( " found " ) - } else { - MESSAGE ( " Not found " ) - } - } - - if (ComponentLib.isEmpty()) { - waitCursor.stop(); - QMessageBox::critical( desktop, - tr("ERR_ERROR"), - "Empty name of component "+ parentComp + " library"); - return; - } - - foreignGUI.SetName(TCollection_AsciiString((char*)ComponentLib.latin1()).ToCString()); - - bool ok = foreignGUI.DlOpen(OSD_RTLD_LAZY); - if (!ok) { - waitCursor.stop(); - QMessageBox::critical( desktop, - tr("ERR_ERROR"), - tr( foreignGUI.DlError() ) ); - return; - } - - osdF = foreignGUI.DlSymb("buildPresentation"); - if ( osdF == NULL ) { - MESSAGE("BuildPresentation method not found in component's GUI") - foreignGUI.DlClose(); - return; - } - osdViewTypeFunc = foreignGUI.DlSymb("supportedViewType"); - if ( osdViewTypeFunc == NULL ) { - MESSAGE("supportedViewType method not found in component's GUI") - } - isForeignGUIUsed = true; - MESSAGE("onDisplay(): using parent component's GUI to build presentations") - } + // Obtain the component's GUI + SALOMEGUI* aGUI = desktop->getComponentGUI( parentComp ); + if ( !aGUI ) + return; // Check if another view type is required (if viewToActivate < 0 then any type of view is acceptable) - if (osdViewTypeFunc) { - void (*viewTypeChecker)(int*, int) = (void (*)(int*, int)) osdViewTypeFunc; - (*viewTypeChecker)(viewTypes, VIEW_TYPE_MAX); - if (viewTypes[0] >= 0) { // not all the view types are supported - for (int i = 0; i < VIEW_TYPE_MAX; i++) { - if (viewTypes[i] < 0) // no more types supported - break; - isViewTypeOK = ((int)myActiveStudy->getActiveStudyFrame()->getTypeView() == viewTypes[i]); - if (isViewTypeOK) // one of supported views is already active - break; - } + aGUI->SupportedViewType(viewTypes, VIEW_TYPE_MAX); + if (viewTypes[0] >= 0) { // not all the view types are supported + for (int i = 0; i < VIEW_TYPE_MAX; i++) { + if (viewTypes[i] < 0) // no more types supported + break; + isViewTypeOK = ((int)myActiveStudy->getActiveStudyFrame()->getTypeView() == viewTypes[i]); + if (isViewTypeOK) // one of supported views is already active + break; } } @@ -557,7 +480,6 @@ void SALOMEGUI_Application::onDisplay(int id) QAD_ViewFrame* viewFrame = myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame(); // Build the graphic presentation (it is stored in the corresponding viewer) - builder = (void (*) (const Handle(SALOME_InteractiveObject)&)) osdF; // Copy the selection SALOME_ListIteratorOfListIO itInit( Sel->StoredIObjects() ); @@ -598,13 +520,13 @@ void SALOMEGUI_Application::onDisplay(int id) childIObject->setEntry(child->GetID()); // Ensure that proper 3D presentation exists for IObject - (*builder)(childIObject); + aGUI->BuildPresentation(childIObject); viewFrame->Display(childIObject, false); needRepaint = true; } } else { // for child object -> simply display it (no children are displayed) // Ensure that proper 3D presentation exists for IObject - (*builder)(IObject); + aGUI->BuildPresentation(IObject); viewFrame->Display(IObject, false); needRepaint = true; } @@ -614,8 +536,6 @@ void SALOMEGUI_Application::onDisplay(int id) if (needRepaint) viewFrame->Repaint(); - if (isForeignGUIUsed) - ;//foreignGUI.DlClose(); // VSR: Fix crash on Display objects from non-parent components myActiveStudy->updateObjBrowser(true); } -- 2.39.2