From: jfa Date: Thu, 15 Feb 2007 09:16:05 +0000 (+0000) Subject: NPAL14845: EDF358: Animation: Salome freeze when closing window. X-Git-Tag: V3_2_6a1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=672148f5a5b9de23d0fb8e4d538eeb5badee8d77;p=modules%2Fvisu.git NPAL14845: EDF358: Animation: Salome freeze when closing window. --- diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.cxx b/src/VISUGUI/VisuGUI_TimeAnimation.cxx index 60db3ea3..5bbf1f84 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.cxx +++ b/src/VISUGUI/VisuGUI_TimeAnimation.cxx @@ -1063,7 +1063,6 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), myModule(theModule), - myStudy(theStudy), mySetupDlg(NULL) { if ( theMode == 0 ) @@ -1071,8 +1070,6 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu else if ( theMode == 1 ) setCaption(tr("SUCCESSIVE_ANIMATION")); setSizeGripEnabled( TRUE ); - isClosing = false; - myCloseBtnClicked = false; myAnimator = new VISU_TimeAnimation (theStudy); myAnimator->setViewer(VISU::GetActiveViewWindow(theModule)); @@ -1288,7 +1285,7 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu aBtnLayout->addStretch(); QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox); - connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose())); + connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close())); QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox); connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp())); @@ -1307,7 +1304,7 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu //------------------------------------------------------------------------ VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg() { - if(myAnimator != NULL){ + if (myAnimator != NULL) { delete myAnimator; myAnimator = NULL; if ( VISU::GetActiveViewWindow(myModule) ) @@ -1428,35 +1425,16 @@ void VisuGUI_TimeAnimationDlg::showEvent(QShowEvent* theEvent) mySetupDlg = new SetupDlg(this,myModule, myAnimator); } -void VisuGUI_TimeAnimationDlg::reject() -{ - close(); - QDialog::reject(); -} - -void VisuGUI_TimeAnimationDlg::onClose() -{ - myCloseBtnClicked = true; - close(); -} - //------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent) { - if(myAnimator != NULL){ + if (myAnimator != NULL) { myAnimator->stopAnimation(); myAnimator->wait(500); if (myAnimator->running() && (! myAnimator->finished())) { - isClosing = true; - myEvent = theEvent; - // * Destroing data in myAnimator before study closed. - // * It needed for correcting destroing of myAnimator, which - // * depend from SVTK_RenderWindowInteractor() e.t.c. - if(theEvent->type() == QEvent::Close && !myCloseBtnClicked){ - for (int i = 0; (myAnimator != NULL) && (i < myAnimator->getNbFields()); i++) - myAnimator->clearData(myAnimator->getFieldData(i)); - myAnimator->clearFieldData(); - } + theEvent->ignore(); + QCloseEvent* aNewCloseEvent = new QCloseEvent; + QApplication::postEvent( this, aNewCloseEvent ); } else { QDialog::closeEvent(theEvent); } @@ -1565,14 +1543,10 @@ void VisuGUI_TimeAnimationDlg::onCheckDump(bool) //------------------------------------------------------------------------ void VisuGUI_TimeAnimationDlg::onStop() { - if (isClosing) { - QDialog::closeEvent(myEvent); - } else { - myPlayBtn->setOn(false); - myPlayBtn->setIconSet(MYplayPixmap); - mySetupBtn->setEnabled(true); - myGenBtn->setEnabled(true); - } + myPlayBtn->setOn(false); + myPlayBtn->setIconSet(MYplayPixmap); + mySetupBtn->setEnabled(true); + myGenBtn->setEnabled(true); } //------------------------------------------------------------------------ @@ -1585,7 +1559,8 @@ void VisuGUI_TimeAnimationDlg::onHelp() else { SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"), QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). - arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName), + arg(app->resourceMgr()->stringValue + ("ExternalBrowser", "application")).arg(aHelpFileName), QObject::tr("BUT_OK")); } } @@ -1640,4 +1615,3 @@ void VisuGUI_TimeAnimationDlg::keyPressEvent( QKeyEvent* e ) onHelp(); } } - diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.h b/src/VISUGUI/VisuGUI_TimeAnimation.h index f717b3f6..21d8f471 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.h +++ b/src/VISUGUI/VisuGUI_TimeAnimation.h @@ -155,7 +155,6 @@ class VisuGUI_TimeAnimationDlg: public QDialog virtual void closeEvent(QCloseEvent* theEvent); virtual void showEvent(QShowEvent* theEvent); virtual void keyPressEvent(QKeyEvent* theEvent); - virtual void reject(); void stopAnimation(); private slots: @@ -181,9 +180,13 @@ class VisuGUI_TimeAnimationDlg: public QDialog void onPicsFormatChanged(); /*!Sets path for myAnimator (dumpTo(...)), from myPathEdit.*/ void onPathChanged(); - void onClose(); private: + // Data + VisuGUI* myModule; + VISU_TimeAnimation* myAnimator; + + // widgets QSlider* mySlider; QComboBox* myTypeCombo; QPushButton* myPropBtn; @@ -194,16 +197,10 @@ class VisuGUI_TimeAnimationDlg: public QDialog QFrame* myPlayFrame; SetupDlg* mySetupDlg; - _PTR(Study) myStudy; - VisuGUI* myModule; - VISU_TimeAnimation* myAnimator; QCheckBox* mySaveCheck; QComboBox* myPicsFormat; QLineEdit* myPathEdit; - bool isClosing; - bool myCloseBtnClicked; - QCloseEvent* myEvent; QCheckBox* mySaveAVICheck; QLineEdit* myPathAVIEdit; diff --git a/src/VISU_I/VISU_TimeAnimation.cxx b/src/VISU_I/VISU_TimeAnimation.cxx index a478f55e..574c940b 100644 --- a/src/VISU_I/VISU_TimeAnimation.cxx +++ b/src/VISU_I/VISU_TimeAnimation.cxx @@ -77,13 +77,38 @@ using namespace std; +namespace VISU { + class ExecutionState { + bool myIsActive; + QMutex myIsActiveMutex; + public: + ExecutionState(bool isActive = false) + : myIsActive(isActive) {} + + bool IsActive() { + bool state; + myIsActiveMutex.lock(); + state = myIsActive; + myIsActiveMutex.unlock(); + return state; + } + bool SetActive(bool isActive) { + bool state; + myIsActiveMutex.lock(); + state = myIsActive; + myIsActive = isActive; + myIsActiveMutex.unlock(); + return state; + } + }; +} //------------------------------------------------------------------------ VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy, VISU::View3D_ptr theView3D) { myStudy = theStudy; - myIsActive = false; + myExecutionState = new VISU::ExecutionState(false); myFrame = 0; mySpeed = VISU::GetResourceMgr()->integerValue("VISU", "speed", 1); myProportional = VISU::GetResourceMgr()->booleanValue("VISU", "use_proportional_timing", false); @@ -120,10 +145,24 @@ VISU_TimeAnimation::~VISU_TimeAnimation() return; } + if (QThread::running() && !QThread::finished()) { + //myExecutionState->SetActive(false); + stopAnimation(); + QThread::wait(500); + if (QThread::running() && !QThread::finished()) { + QThread::terminate(); + } + } + for (int i = 0; i < getNbFields(); i++) { clearData(myFieldsLst[i]); } clearFieldData(); + + delete myExecutionState; + + myDumpPath = ""; + /* Terminates the execution of the thread. * The thread may or may not be terminated immediately, * depending on the operating system's scheduling policies. @@ -138,10 +177,9 @@ VISU_TimeAnimation::~VISU_TimeAnimation() * There is no chance for the thread to cleanup after itself, * unlock any held mutexes, etc. In short, use this function only if absolutely necessary. */ - myDumpPath = ""; - QThread::wait(100); - QThread::terminate(); - QThread::wait(400); + //QThread::wait(100); + //QThread::terminate(); + //QThread::wait(400); } @@ -623,22 +661,16 @@ void VISU_TimeAnimation::visibilityOff(int num_field, int num_frame) (this,&VISU_TimeAnimation::_visibilityOff,num_field,num_frame)); } -//------------------------------------------------------------------------ -void VISU_TimeAnimation::_stopAnimation() { - myIsActive = false; -} - //------------------------------------------------------------------------ void VISU_TimeAnimation::stopAnimation() { - ProcessVoidEvent(new TVoidMemFunEvent - (this,&VISU_TimeAnimation::_stopAnimation)); + myExecutionState->SetActive(false); } //------------------------------------------------------------------------ void VISU_TimeAnimation::_startAnimation() { - if (!myIsActive) { - myIsActive = true; + if (!myExecutionState->IsActive()) { + myExecutionState->SetActive(true); QThread::start(); } } @@ -650,6 +682,11 @@ void VISU_TimeAnimation::startAnimation() (this,&VISU_TimeAnimation::_startAnimation)); } +//------------------------------------------------------------------------ +CORBA::Boolean VISU_TimeAnimation::isRunning() +{ + return myExecutionState->IsActive(); +} //------------------------------------------------------------------------ void VISU_TimeAnimation::_nextFrame() { @@ -1014,31 +1051,33 @@ void VISU_TimeAnimation::parallelAnimation( bool& theIsDumping, QValueList& if (myFieldsLst[0].myNbFrames > 2) aOneVal = ( myTimeMax - myTimeMin ) / getNbFrames(); int aNbFiles = 0; - - while (myIsActive) { - ProcessVoidEvent(new TVoidMemFun2ArgEvent(this, &VISU_TimeAnimation::_emitFrameChanged, - myFrame, myFieldsLst[0].myTiming[myFrame])); - if (myIsActive) { - if(!(myFieldsLst[0].myField)) - break; - for (int i = 0; i < getNbFields(); i++) { - FieldData& aData = myFieldsLst[i]; - if (myFrame > 0) { - if (aData.myActors[myFrame-1] != 0) - visibilityOff(i, myFrame-1); - } else { - if (aData.myActors[aData.myNbFrames-1] != 0) - visibilityOff(i, aData.myNbFrames-1); - } - if (aData.myActors[myFrame] != 0) { - ProcessVoidEvent(new TVoidMemFunEvent(aData.myActors[myFrame], - &VISU_Actor::VisibilityOn)); + + bool hasHextFrame = true; + while (hasHextFrame && myExecutionState->IsActive()) { + ProcessVoidEvent(new TVoidMemFun2ArgEvent + (this, &VISU_TimeAnimation::_emitFrameChanged, + myFrame, myFieldsLst[0].myTiming[myFrame])); + if (myExecutionState->IsActive()) { + if (!(myFieldsLst[0].myField)) + break; + for (int i = 0; i < getNbFields(); i++) { + FieldData& aData = myFieldsLst[i]; + if (myFrame > 0) { + if (aData.myActors[myFrame-1] != 0) + visibilityOff(i, myFrame-1); + } else { + if (aData.myActors[aData.myNbFrames-1] != 0) + visibilityOff(i, aData.myNbFrames-1); + } + if (aData.myActors[myFrame] != 0) { + ProcessVoidEvent(new TVoidMemFunEvent(aData.myActors[myFrame], + &VISU_Actor::VisibilityOn)); + } } - } - bool repainArg = false; - ProcessVoidEvent(new TVoidMemFun1ArgEvent(myView, - &SVTK_ViewWindow::Repaint, - repainArg)); + bool repainArg = false; + ProcessVoidEvent(new TVoidMemFun1ArgEvent(myView, + &SVTK_ViewWindow::Repaint, + repainArg)); } k = 1; @@ -1064,44 +1103,39 @@ void VISU_TimeAnimation::parallelAnimation( bool& theIsDumping, QValueList& delay = 1; } msleep(delay); - if (!myIsActive) { - ProcessVoidEvent(new TVoidMemFunEvent(this,&VISU_TimeAnimation::_emitStopped)); - return; - } + if (!myExecutionState->IsActive()) return; if (theIsDumping) { // We must unlock mutex for some time before grabbing to allow view updating msleep(delay); - if (!myIsActive) { // this check was taken from WP_DEB branch - ProcessVoidEvent(new TVoidMemFunEvent(this,&VISU_TimeAnimation::_emitStopped)); - return; - } - if(!(myFieldsLst[0].myField)) // break, if field was deleted. + if (!myExecutionState->IsActive()) return; + + if (!(myFieldsLst[0].myField)) // break, if field was deleted. break; + saveImages( 0, aOneVal, aNbFiles, theIndexList ); } - if (!myIsActive) break; + if (!myExecutionState->IsActive()) break; myFrame++; if (myFrame == myFieldsLst[0].myNbFrames) { if (!myCycling) { - myIsActive = false; + hasHextFrame = false; myFrame--; - break; - } else + } + else myFrame = 0; } - } + } // while (hasHextFrame && myExecutionState->IsActive()) } //------------------------------------------------------------------------ void VISU_TimeAnimation::succcessiveAnimation( bool& theIsDumping, QValueList& theIndexList ) { - if ( myFrame >= getNbFrames() - 1 ) + if (myFrame >= getNbFrames() - 1) { - myIsActive = false; - ProcessVoidEvent(new TVoidMemFunEvent(this,&VISU_TimeAnimation::_emitStopped)); + myExecutionState->SetActive(false); return; } @@ -1112,40 +1146,46 @@ void VISU_TimeAnimation::succcessiveAnimation( bool& theIsDumping, QValueListIsActive()) + { + for (int aFieldId = 0; + (aFieldId < getNbFields()) && (myFieldsLst[aFieldId].myField); + aFieldId++, aFrame = 0) + { + if (!myExecutionState->IsActive()) break; FieldData& aData = myFieldsLst[aFieldId]; if ( !aData.myPrs[0] ) continue; - while (aFrame < aData.myNbFrames) { - - ProcessVoidEvent(new TVoidMemFun2ArgEvent(this, &VISU_TimeAnimation::_emitFrameChanged, - myFrame, myFieldsLst[aFieldId].myTiming[aFrame])); - - if (myIsActive) { - if (aFrame > 0) { - if (aData.myActors[aFrame-1] != 0) - visibilityOff(aFieldId, aFrame-1); - } else if ( myFrame > 0) { - if (myFieldsLst[aFieldId-1].myActors[myFieldsLst[aFieldId-1].myNbFrames-1] != 0) - visibilityOff(aFieldId-1, myFieldsLst[aFieldId-1].myNbFrames-1); - } else if ( myCycling ) { - if (myFieldsLst[getNbFields()-1].myActors[myFieldsLst[getNbFields()-1].myNbFrames-1] != 0) - visibilityOff(getNbFields()-1, myFieldsLst[getNbFields()-1].myNbFrames-1); - } else { - if (aData.myActors[aData.myNbFrames-1] != 0) - visibilityOff(aFieldId, aData.myNbFrames-1); - } - if (aData.myActors[aFrame] != 0) { - ProcessVoidEvent(new TVoidMemFunEvent(aData.myActors[aFrame], - &VISU_Actor::VisibilityOn)); - } + for (; aFrame < aData.myNbFrames && myExecutionState->IsActive(); aFrame++, myFrame++) + { + ProcessVoidEvent(new TVoidMemFun2ArgEvent + (this, &VISU_TimeAnimation::_emitFrameChanged, + myFrame, myFieldsLst[aFieldId].myTiming[aFrame])); + + if (myExecutionState->IsActive()) { + if (aFrame > 0) { + if (aData.myActors[aFrame-1] != 0) + visibilityOff(aFieldId, aFrame-1); + } else if ( myFrame > 0) { + if (myFieldsLst[aFieldId-1].myActors[myFieldsLst[aFieldId-1].myNbFrames-1] != 0) + visibilityOff(aFieldId-1, myFieldsLst[aFieldId-1].myNbFrames-1); + } else if ( myCycling ) { + if (myFieldsLst[getNbFields()-1].myActors[myFieldsLst[getNbFields()-1].myNbFrames-1] != 0) + visibilityOff(getNbFields()-1, myFieldsLst[getNbFields()-1].myNbFrames-1); + } else { + if (aData.myActors[aData.myNbFrames-1] != 0) + visibilityOff(aFieldId, aData.myNbFrames-1); + } + if (aData.myActors[aFrame] != 0) { + ProcessVoidEvent(new TVoidMemFunEvent(aData.myActors[aFrame], + &VISU_Actor::VisibilityOn)); + } - bool repainArg = false; - ProcessVoidEvent(new TVoidMemFun1ArgEvent(myView, - &SVTK_ViewWindow::Repaint, - repainArg)); + bool repainArg = false; + ProcessVoidEvent(new TVoidMemFun1ArgEvent(myView, + &SVTK_ViewWindow::Repaint, + repainArg)); } k = 1; @@ -1171,44 +1211,31 @@ void VISU_TimeAnimation::succcessiveAnimation( bool& theIsDumping, QValueList(this,&VISU_TimeAnimation::_emitStopped)); - return; - } + + if (!myExecutionState->IsActive()) return; if (theIsDumping) { // We must unlock mutex for some time before grabbing to allow view updating msleep(delay); - if (!myIsActive) { // this check was taken from WP_DEB branch - ProcessVoidEvent(new TVoidMemFunEvent(this,&VISU_TimeAnimation::_emitStopped)); - return; - } + if (!myExecutionState->IsActive()) return; - if(!(myFieldsLst[aFieldId].myField)) // break, if field was deleted. + if (!(myFieldsLst[aFieldId].myField)) // break, if field was deleted. break; saveImages( aFieldId, aOneVal, aNbFiles, theIndexList ); } - - if (!myIsActive) break; - - aFrame++; - myFrame++; - } - - aFrame = 0; - } + } // for (; aFrame < aData.myNbFrames && myExecutionState->IsActive(); aFrame++, myFrame++) + } // for (int aFieldId = 0; if (!myCycling) { - myIsActive = false; + hasHextFrame = false; myFrame--; - break; - } else { + } + else { myFrame = 0; aFrame = myFrame; } - } - + } // while (hasHextFrame && myExecutionState->IsActive()) } //------------------------------------------------------------------------ @@ -1297,7 +1324,7 @@ void VISU_TimeAnimation::run() succcessiveAnimation( isDumping, anIndexList ); // make AVI file if need - if (isDumping && myDumpFormat.compare("AVI") == 0) { + if (isDumping && myDumpFormat.compare("AVI") == 0 && myExecutionState->IsActive()) { double aFPS = 17.3 * mySpeed; QFileInfo aFileInfo(myDumpPath); @@ -1347,8 +1374,9 @@ void VISU_TimeAnimation::run() system(aCmd.latin1()); } - ProcessVoidEvent(new TVoidMemFunEvent(this,&VISU_TimeAnimation::_emitStopped)); - QThread::exit(); + if (myExecutionState->IsActive()) + ProcessVoidEvent(new TVoidMemFunEvent(this,&VISU_TimeAnimation::_emitStopped)); + myExecutionState->SetActive(false); } //------------------------------------------------------------------------ diff --git a/src/VISU_I/VISU_TimeAnimation.h b/src/VISU_I/VISU_TimeAnimation.h index b0062a3c..4f359c67 100644 --- a/src/VISU_I/VISU_TimeAnimation.h +++ b/src/VISU_I/VISU_TimeAnimation.h @@ -39,6 +39,7 @@ namespace VISU { class Result_i; class ColoredPrs3d_i; + class ExecutionState; } struct FieldData @@ -63,7 +64,6 @@ class VISU_TimeAnimation: public QObject, public QThread void _visibilityOff(int num_field, int num_frame); void _clearView(); void _clearData(FieldData& theData); - void _stopAnimation(); void _startAnimation(); void _nextFrame(); void _prevFrame(); @@ -116,7 +116,7 @@ class VISU_TimeAnimation: public QObject, public QThread CORBA::Long getNbFields() { return myFieldsLst.size(); } CORBA::Long getNbFrames(); - CORBA::Boolean isRunning() { return myIsActive; } + CORBA::Boolean isRunning(); CORBA::Long getCurrentFrame() { return myFrame; } long getAbsoluteFrameNumber(std::pair theFieldTimeStamp); @@ -188,7 +188,7 @@ class VISU_TimeAnimation: public QObject, public QThread QString myLastError; QValueList myFieldsLst; - bool myIsActive; + VISU::ExecutionState* myExecutionState; long myFrame; std::vector myFieldsAbsFrames; int mySpeed;