false,
WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
myModule(theModule),
- myStudy(theStudy),
mySetupDlg(NULL)
{
if ( theMode == 0 )
else if ( theMode == 1 )
setCaption(tr("SUCCESSIVE_ANIMATION"));
setSizeGripEnabled( TRUE );
- isClosing = false;
- myCloseBtnClicked = false;
myAnimator = new VISU_TimeAnimation (theStudy);
myAnimator->setViewer(VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule));
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()));
//------------------------------------------------------------------------
VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
{
- if(myAnimator != NULL){
+ if (myAnimator != NULL) {
delete myAnimator;
myAnimator = NULL;
if ( VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule) )
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);
}
//------------------------------------------------------------------------
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);
}
//------------------------------------------------------------------------
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"));
}
}
onHelp();
}
}
-
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);
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.
* 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);
}
(this,&VISU_TimeAnimation::_visibilityOff,num_field,num_frame));
}
-//------------------------------------------------------------------------
-void VISU_TimeAnimation::_stopAnimation() {
- myIsActive = false;
-}
-
//------------------------------------------------------------------------
void VISU_TimeAnimation::stopAnimation()
{
- ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
- (this,&VISU_TimeAnimation::_stopAnimation));
+ myExecutionState->SetActive(false);
}
//------------------------------------------------------------------------
void VISU_TimeAnimation::_startAnimation() {
- if (!myIsActive) {
- myIsActive = true;
+ if (!myExecutionState->IsActive()) {
+ myExecutionState->SetActive(true);
QThread::start();
}
}
(this,&VISU_TimeAnimation::_startAnimation));
}
+//------------------------------------------------------------------------
+CORBA::Boolean VISU_TimeAnimation::isRunning()
+{
+ return myExecutionState->IsActive();
+}
//------------------------------------------------------------------------
void VISU_TimeAnimation::_nextFrame() {
if (myFieldsLst[0].myNbFrames > 2)
aOneVal = ( myTimeMax - myTimeMin ) / getNbFrames();
int aNbFiles = 0;
-
- while (myIsActive) {
- ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(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<VISU_Actor>(aData.myActors[myFrame],
- &VISU_Actor::VisibilityOn));
+
+ bool hasHextFrame = true;
+ while (hasHextFrame && myExecutionState->IsActive()) {
+ ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>
+ (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<VISU_Actor>(aData.myActors[myFrame],
+ &VISU_Actor::VisibilityOn));
+ }
}
- }
- bool repainArg = false;
- ProcessVoidEvent(new TVoidMemFun1ArgEvent<SVTK_ViewWindow,bool>(myView,
- &SVTK_ViewWindow::Repaint,
- repainArg));
+ bool repainArg = false;
+ ProcessVoidEvent(new TVoidMemFun1ArgEvent<SVTK_ViewWindow,bool>(myView,
+ &SVTK_ViewWindow::Repaint,
+ repainArg));
}
k = 1;
delay = 1;
}
msleep(delay);
- if (!myIsActive) {
- ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>(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<VISU_TimeAnimation>(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<int>& theIndexList )
{
- if ( myFrame >= getNbFrames() - 1 )
+ if (myFrame >= getNbFrames() - 1)
{
- myIsActive = false;
- ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>(this,&VISU_TimeAnimation::_emitStopped));
+ myExecutionState->SetActive(false);
return;
}
int aNbFiles = 0;
long aFrame = myFrame;
- while (myIsActive) {
-
- for (int aFieldId = 0; (aFieldId < getNbFields()) && (myFieldsLst[aFieldId].myField); aFieldId++) {
+ bool hasHextFrame = true;
+ while (hasHextFrame && myExecutionState->IsActive())
+ {
+ 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<VISU_TimeAnimation,long,double>(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<VISU_Actor>(aData.myActors[aFrame],
- &VISU_Actor::VisibilityOn));
- }
+ for (; aFrame < aData.myNbFrames && myExecutionState->IsActive(); aFrame++, myFrame++)
+ {
+ ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>
+ (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<VISU_Actor>(aData.myActors[aFrame],
+ &VISU_Actor::VisibilityOn));
+ }
- bool repainArg = false;
- ProcessVoidEvent(new TVoidMemFun1ArgEvent<SVTK_ViewWindow,bool>(myView,
- &SVTK_ViewWindow::Repaint,
- repainArg));
+ bool repainArg = false;
+ ProcessVoidEvent(new TVoidMemFun1ArgEvent<SVTK_ViewWindow,bool>(myView,
+ &SVTK_ViewWindow::Repaint,
+ repainArg));
}
k = 1;
delay = 1;
}
msleep(delay);
- if (!myIsActive) {
- ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>(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<VISU_TimeAnimation>(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())
}
//------------------------------------------------------------------------
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);
system(aCmd.latin1());
}
- ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>(this,&VISU_TimeAnimation::_emitStopped));
- QThread::exit();
+ if (myExecutionState->IsActive())
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>(this,&VISU_TimeAnimation::_emitStopped));
+ myExecutionState->SetActive(false);
}
//------------------------------------------------------------------------