1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : VisuGUI_TimeAnimation.cxx
23 // Author : Vitaly SMETANNIKOV
26 #include "VisuGUI_TimeAnimation.h"
29 #include "VisuGUI_Tools.h"
30 #include "VisuGUI_ViewTools.h"
31 #include "VisuGUI_ScalarBarDlg.h"
32 #include "VisuGUI_DeformedShapeDlg.h"
33 #include "VisuGUI_CutPlanesDlg.h"
34 #include "VisuGUI_CutLinesDlg.h"
35 #include "VisuGUI_Plot3DDlg.h"
36 #include "VisuGUI_VectorsDlg.h"
37 #include "VisuGUI_IsoSurfacesDlg.h"
38 #include "VisuGUI_StreamLinesDlg.h"
39 #include "VisuGUI_DeformedShapeAndScalarMapDlg.h"
40 #include "VisuGUI_GaussPointsDlg.h"
42 #include "VISU_TimeAnimation.h"
44 #include "VISU_ScalarMap_i.hh"
45 #include "VISU_IsoSurfaces_i.hh"
46 #include "VISU_DeformedShape_i.hh"
47 #include "VISU_CutPlanes_i.hh"
48 #include "VISU_Plot3D_i.hh"
49 #include "VISU_CutLines_i.hh"
50 #include "VISU_Vectors_i.hh"
51 #include "VISU_StreamLines_i.hh"
52 #include "VISU_DeformedShapeAndScalarMap_i.hh"
53 #include "VISU_GaussPoints_i.hh"
55 #include "VISU_ViewManager_i.hh"
57 #include "VISU_ScalarBarActor.hxx"
58 #include "VISU_Actor.h"
60 #include "SalomeApp_Study.h"
61 #include "LightApp_Application.h"
63 #include "SVTK_ViewWindow.h"
65 #include "SUIT_OverrideCursor.h"
66 #include "SUIT_MessageBox.h"
67 #include "SUIT_ResourceMgr.h"
68 #include "SUIT_Session.h"
69 #include "SUIT_Desktop.h"
70 #include "SUIT_FileDlg.h"
72 #include <vtkRenderer.h>
73 #include <vtkMapper.h>
75 #include <QGridLayout>
77 #include <QImageWriter>
81 #include <QListWidget>
83 #include <QToolButton>
87 #include <QRadioButton>
89 #include <QPushButton>
92 #include <qwt_wheel.h>
95 #define VALPRECISION 8
98 void GeneratePresentations(int theFieldId, VISU_TimeAnimation* theAnimator)
100 if(theAnimator->getNbFields() == 0)
103 theAnimator->generatePresentations(theFieldId);
104 FieldData& aFieldData = theAnimator->getFieldData(theFieldId);
107 int aRefFieldId = ( theAnimator->getAnimationMode() == VISU::Animation::PARALLEL ) ? theFieldId : 0;
108 if(VISU::ColoredPrs3d_i* aInitialPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(theAnimator->getFieldData(aRefFieldId).myPrs[0])){
109 for (long aFrameId = 0; aFrameId < aFieldData.myNbFrames; aFrameId++) {
110 VISU::ColoredPrs3d_i* aColoredPrs3d = aFieldData.myPrs[aFrameId];
112 // Special case for DeformedShape And ScalarMap presentation
113 // Restore time stamp number for all presentations
114 VISU::DeformedShapeAndScalarMap_i* aDeformedAndScalPrs = dynamic_cast<VISU::DeformedShapeAndScalarMap_i*>(aColoredPrs3d);
115 int aTimeStampNum = -1;
116 if(aDeformedAndScalPrs){
117 aTimeStampNum = aDeformedAndScalPrs->GetScalarTimeStampNumber();
119 aColoredPrs3d->SameAs(aInitialPrs3d);
121 if(aDeformedAndScalPrs){
122 aDeformedAndScalPrs->SetScalarField(aDeformedAndScalPrs->GetScalarEntity(),
123 aDeformedAndScalPrs->GetScalarFieldName(),
127 std::string aTitle = aColoredPrs3d->GetCTitle();
128 if ( aFrameId != 0 && theAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE ) {
129 aColoredPrs3d->SetTitle(aTitle.c_str());
136 ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator)
137 : QDialog(theParent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
138 myAnimator(theAnimator),
139 myViewWindow(theAnimator->getViewer())
144 QStringList aFieldNames;
145 // Find names of fields
146 for (int i = 0; i < myAnimator->getNbFields(); i++) {
147 _PTR(SObject) aSObject = myAnimator->getFieldData(i).myField;
148 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSObject);
149 aFieldNames.append(aRestoringMap["myName"]);
151 aOffs.myOffset[0] = myAnimator->getFieldData(i).myOffset[0];
152 aOffs.myOffset[1] = myAnimator->getFieldData(i).myOffset[1];
153 aOffs.myOffset[2] = myAnimator->getFieldData(i).myOffset[2];
154 myOffsets.append(aOffs);
156 myFieldLst->addItems(aFieldNames);
157 myFieldLst->setCurrentRow(0);
160 ArrangeDlg::ArrangeDlg(QWidget* theParent,
161 const SalomeApp_Module* theModule,
162 SVTK_ViewWindow* theViewWindow)
163 : QDialog(theParent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
165 myViewWindow(theViewWindow)
170 QStringList aPrsNames;
171 vtkActorCollection *aCollection = myViewWindow->getRenderer()->GetActors();
172 aCollection->InitTraversal();
173 while(vtkActor* anActor = aCollection->GetNextActor()){
174 if (VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(anActor)) {
175 if(anVISUActor->GetVisibility() != 0){
176 if (VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d()){
177 if(!myPrsMap.contains(aPrs)){
178 Handle(SALOME_InteractiveObject) anIO = aPrs->GetIO();
179 if(!anIO->hasEntry())
181 SalomeApp_Study* aStudy = VISU::GetAppStudy(theModule);
182 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, anIO->getEntry());
183 if(_PTR(SObject) aSObject = anObjectInfo.mySObject){
184 _PTR(GenericAttribute) anAttr;
185 if (aSObject->FindAttribute(anAttr, "AttributeName")) {
186 _PTR(AttributeName) aName(anAttr);
187 QString strIn(aName->Value().c_str());
188 aPrsNames.append(strIn);
189 myPrsMap[aPrs] = myOffsets.count();
191 anVISUActor->GetPosition(aOffs.myOffset);
192 myOffsets.append(aOffs);
198 } else { //if PointMap3d Actor
199 if (VISU_ActorBase* anActorBase = dynamic_cast<VISU_ActorBase*>(anActor))
200 if(anActorBase->GetVisibility() != 0)
201 if (VISU::PointMap3d_i* aPrs = dynamic_cast<VISU::PointMap3d_i*>(anActorBase->GetFactory())) {
202 if(!myPointMapPrsMap.contains(aPrs)){
203 Handle(SALOME_InteractiveObject) anIO = aPrs->GetIO();
204 if(!anIO->hasEntry())
206 SalomeApp_Study* aStudy = VISU::GetAppStudy(theModule);
207 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, anIO->getEntry());
208 if(_PTR(SObject) aSObject = anObjectInfo.mySObject){
209 _PTR(GenericAttribute) anAttr;
210 if (aSObject->FindAttribute(anAttr, "AttributeName")) {
211 _PTR(AttributeName) aName(anAttr);
212 QString strIn(aName->Value().c_str());
213 aPrsNames.append(strIn);
214 myPointMapPrsMap[aPrs] = myOffsets.count();
216 anActorBase->GetPosition(aOffs.myOffset);
217 myOffsets.append(aOffs);
224 myFieldLst->addItems(aPrsNames);
225 myFieldLst->setCurrentRow(0);
228 void ArrangeDlg::init()
230 setWindowTitle("Arrange Presentations");
231 setSizeGripEnabled( TRUE );
233 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
234 aMainLayout->setMargin( 7 );
235 aMainLayout->setSpacing(5);
237 QButtonGroup* aBtnGrp = new QButtonGroup( this);
238 aBtnGrp->setExclusive(true);
239 //aMainLayout->addWidget(aBtnGrp);
241 QGroupBox* aBtnGB = new QGroupBox( this );
242 QHBoxLayout* aHBLay = new QHBoxLayout( aBtnGB );
243 aMainLayout->addWidget(aBtnGB);
245 QRadioButton* aAutoBtn = new QRadioButton("Auto", aBtnGB);
246 aHBLay->addWidget( aAutoBtn );
247 aBtnGrp->addButton(aAutoBtn, AutoMode);
249 QRadioButton* aManualBtn = new QRadioButton("Manual", aBtnGB);
250 aHBLay->addWidget( aManualBtn );
251 aBtnGrp->addButton(aManualBtn, ManualMode);
253 aAutoBtn->setChecked( true );
255 myStackWgt = new QStackedWidget(this);
256 aMainLayout->addWidget(myStackWgt);
259 QWidget* aAutoPane = new QWidget(myStackWgt);
260 QVBoxLayout* aAutoLay = new QVBoxLayout( aAutoPane );
261 aAutoLay->setSpacing(5);
264 myAxisGrp = new QButtonGroup(aAutoPane);
266 QGroupBox* aAxisGB = new QGroupBox( "Axis", aAutoPane );
267 QHBoxLayout* aVBLay = new QHBoxLayout( aAxisGB );
268 aAutoLay->addWidget( aAxisGB );
270 QRadioButton* aXBtn = new QRadioButton("X",aAxisGB );
271 aVBLay->addWidget( aXBtn );
272 myAxisGrp->addButton(aXBtn, XAxis);
274 QRadioButton* aYBtn = new QRadioButton("Y",aAxisGB );
275 aVBLay->addWidget( aYBtn );
276 myAxisGrp->addButton(aYBtn, YAxis);
278 QRadioButton* aZBtn = new QRadioButton("Z",aAxisGB );
279 aVBLay->addWidget( aZBtn );
280 myAxisGrp->addButton(aZBtn, ZAxis);
282 aXBtn->setChecked( true );
285 QWidget* aDistPane = new QWidget(aAutoPane);
286 QHBoxLayout* aHLay = new QHBoxLayout( aDistPane );
287 aHLay->setSpacing(5);
288 aHLay->addWidget( new QLabel("Relative Distance", aDistPane) );
289 myDistVal = new QtxDoubleSpinBox (-10,10, 0.5, aDistPane);
290 myDistVal->setValue(1);
291 aHLay->addWidget( myDistVal );
293 aAutoLay->addWidget( aDistPane );
295 myStackWgt->insertWidget( AutoMode, aAutoPane);
298 QWidget* aManualPane = new QWidget(myStackWgt);
299 aHLay = new QHBoxLayout( aManualPane );
300 aHLay->setSpacing(10);
302 myFieldLst = new QListWidget(aManualPane);
303 aHLay->addWidget( myFieldLst );
304 connect( myFieldLst, SIGNAL( currentRowChanged(int) ),
305 this, SLOT( onFieldChange(int) ) );
307 QWidget* aCoordPane = new QWidget( aManualPane);
308 aHLay->addWidget( aCoordPane );
309 QGridLayout* aCoordLayout = new QGridLayout( aCoordPane );
310 aCoordLayout->setSpacing(5);
312 aCoordLayout->addWidget( new QLabel("X", aCoordPane), 0, 0 );
313 myCoord[0] = new QtxDoubleSpinBox(aCoordPane);
314 myCoord[0]->setRange(-MAXVAL, MAXVAL);
315 aCoordLayout->addWidget( myCoord[0], 0, 1 );
317 aCoordLayout->addWidget( new QLabel("Y", aCoordPane), 1, 0 );
318 myCoord[1] = new QtxDoubleSpinBox(aCoordPane);
319 myCoord[1]->setRange(-MAXVAL, MAXVAL);
320 aCoordLayout->addWidget( myCoord[1], 1, 1 );
322 aCoordLayout->addWidget( new QLabel("Z", aCoordPane), 2, 0 );
323 myCoord[2] = new QtxDoubleSpinBox(aCoordPane);
324 myCoord[2]->setRange(-MAXVAL, MAXVAL);
325 aCoordLayout->addWidget( myCoord[2], 2, 1 );
327 myStackWgt->insertWidget(ManualMode, aManualPane );
329 myStackWgt->setCurrentIndex(AutoMode);
331 connect(aBtnGrp, SIGNAL(buttonClicked(int)), myStackWgt, SLOT(setCurrentIndex(int)) );
333 SUIT_Study* aSUITStudy = myViewWindow->getViewManager()->study();
334 SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>(aSUITStudy);
335 _PTR(Study) aCStudy = VISU::GetCStudy(anAppStudy);
336 if (!myAnimator && !aCStudy->GetProperties()->IsLocked()) {
337 mySaveChk = new QCheckBox ("Save to presentation", this);
338 mySaveChk->setChecked(false);
339 aMainLayout->addWidget(mySaveChk);
344 // Common buttons ===========================================================
345 QGroupBox* GroupButtons = new QGroupBox( this );
346 //GroupButtons->setColumnLayout(0, Qt::Vertical );
347 //GroupButtons->layout()->setSpacing( 0 );
348 //GroupButtons->layout()->setMargin( 0 );
349 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
350 GroupButtonsLayout->setAlignment( Qt::AlignTop );
351 GroupButtonsLayout->setSpacing( 6 );
352 GroupButtonsLayout->setMargin( 11 );
354 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
355 buttonOk->setAutoDefault( TRUE );
356 buttonOk->setDefault( TRUE );
357 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
358 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
360 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons );
361 buttonCancel->setAutoDefault( TRUE );
362 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
364 aMainLayout->addWidget( GroupButtons );
366 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
367 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
370 void ArrangeDlg::accept()
372 if (myAnimator != NULL) {
380 void ArrangeDlg::onFieldChange(int theCurrent)
382 if (myCurrent != theCurrent) {
383 Offset& aOffs = myOffsets[myCurrent];
384 aOffs.myOffset[0] = myCoord[0]->value();
385 aOffs.myOffset[1] = myCoord[1]->value();
386 aOffs.myOffset[2] = myCoord[2]->value();
388 myCurrent = theCurrent;
389 const Offset& aNewOffs = myOffsets[myCurrent];
390 myCoord[0]->setValue(aNewOffs.myOffset[0]);
391 myCoord[1]->setValue(aNewOffs.myOffset[1]);
392 myCoord[2]->setValue(aNewOffs.myOffset[2]);
395 void ArrangeDlg::acceptAnimation()
397 if (getMode() == ManualMode) {
399 Offset& aOffs = myOffsets[myCurrent];
400 aOffs.myOffset[0] = myCoord[0]->value();
401 aOffs.myOffset[1] = myCoord[1]->value();
402 aOffs.myOffset[2] = myCoord[2]->value();
404 for (int i = 0; i < myAnimator->getNbFields(); i++) {
405 Offset aOffs = myOffsets[i];
406 myAnimator->getFieldData(i).myOffset[0] = aOffs.myOffset[0];
407 myAnimator->getFieldData(i).myOffset[1] = aOffs.myOffset[1];
408 myAnimator->getFieldData(i).myOffset[2] = aOffs.myOffset[2];
411 QApplication::setOverrideCursor( Qt::WaitCursor );
412 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentRow());
413 if (aData.myPrs.empty())
414 GeneratePresentations(myFieldLst->currentRow(),myAnimator);
415 vtkFloatingPointType aBounds[6];
416 aData.myPrs[0]->GetBounds(aBounds);
417 vtkFloatingPointType aDist = 0;
418 int aAxis = getAxis();
421 aDist = fabs(aBounds[1] - aBounds[0]);
424 aDist = fabs(aBounds[3] - aBounds[2]);
427 aDist = fabs(aBounds[5] - aBounds[4]);
430 vtkFloatingPointType dx = fabs(aBounds[1] - aBounds[0]);
431 vtkFloatingPointType dy = fabs(aBounds[3] - aBounds[2]);
432 vtkFloatingPointType dz = fabs(aBounds[5] - aBounds[4]);
433 vtkFloatingPointType max = (dx > dy) ? dx : dy;
434 max = (dz > max) ? dz : max;
438 // set base distance between centers of bounding boxes
439 // to minimal (but big enough) size of current bounding box
440 if (dx < max) dx = FLT_MAX;
441 if (dy < max) dy = FLT_MAX;
442 if (dz < max) dz = FLT_MAX;
444 aDist = (dx < dy) ? dx : dy;
445 aDist = (dz < aDist) ? dz : aDist;
447 aDist = aDist * getDistance();
448 for (int i = 0; i < myAnimator->getNbFields(); i++) {
449 myAnimator->getFieldData(i).myOffset[0] = 0;
450 myAnimator->getFieldData(i).myOffset[1] = 0;
451 myAnimator->getFieldData(i).myOffset[2] = 0;
452 myAnimator->getFieldData(i).myOffset[aAxis] = aDist * i;
455 QApplication::restoreOverrideCursor();
459 void ArrangeDlg::acceptViewWindow()
461 if (getMode() == ManualMode) {
463 Offset& aOffs = myOffsets[myCurrent];
464 aOffs.myOffset[0] = myCoord[0]->value();
465 aOffs.myOffset[1] = myCoord[1]->value();
466 aOffs.myOffset[2] = myCoord[2]->value();
468 QMap<VISU::Prs3d_i*, int>::Iterator it;
469 for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it) {
470 VISU::Prs3d_i* aPrs = it.key();
471 Offset& aOffs = myOffsets[it.value()];
472 if (VISU_Actor* anActor = VISU::FindActor(myViewWindow, aPrs))
473 anActor->SetPosition(aOffs.myOffset);
475 if (mySaveChk->isChecked())
476 aPrs->SetOffset(aOffs.myOffset[0],aOffs.myOffset[1],aOffs.myOffset[2]);
478 QMap<VISU::PointMap3d_i*, int>::Iterator itt;
479 for (itt = myPointMapPrsMap.begin(); itt != myPointMapPrsMap.end(); ++itt) {
480 VISU::PointMap3d_i* aPrs = itt.key();
481 Offset& aOffs = myOffsets[itt.value()];
482 if (VISU_ActorBase* anActor = VISU::FindActorBase(myViewWindow, aPrs))
483 anActor->SetPosition(aOffs.myOffset);
485 if (mySaveChk->isChecked())
486 aPrs->SetOffset(aOffs.myOffset[0],aOffs.myOffset[1],aOffs.myOffset[2]);
489 vtkFloatingPointType aDist = 0;
490 vtkFloatingPointType aShift = 0;
491 vtkFloatingPointType aPrevDist = 0;
492 vtkFloatingPointType aPrevShift = 0;
494 QMap<VISU::Prs3d_i*, int>::Iterator it;
495 for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it, i++) {
496 VISU::Prs3d_i* aPrs = it.key();
497 if (VISU_Actor* aActor = VISU::FindActor(myViewWindow, aPrs)) {
498 int aAxis = getAxis();
500 vtkFloatingPointType aZeroOffset[3];
501 aZeroOffset[0] = aZeroOffset[1] = aZeroOffset[2] = 0;
502 aActor->SetPosition(aZeroOffset);
503 aActor->GetMapper()->Update();
505 vtkFloatingPointType aBounds[6];
506 aActor->GetBounds(aBounds);
509 aDist = fabs(aBounds[1] - aBounds[0]);
512 aDist = fabs(aBounds[3] - aBounds[2]);
515 aDist = fabs(aBounds[5] - aBounds[4]);
517 vtkFloatingPointType aOffset[3];
518 aOffset[0] = aOffset[1] = aOffset[2] = 0;
520 (aBounds[2*aAxis+1] < aBounds[2*aAxis]) ? -aBounds[2*aAxis+1] : -aBounds[2*aAxis];
523 vtkFloatingPointType aCCDist = (aDist + aPrevDist) / 2.0;
525 vtkFloatingPointType dx = fabs(aBounds[1] - aBounds[0]);
526 vtkFloatingPointType dy = fabs(aBounds[3] - aBounds[2]);
527 vtkFloatingPointType dz = fabs(aBounds[5] - aBounds[4]);
528 vtkFloatingPointType max = (dx > dy) ? dx : dy;
529 max = (dz > max) ? dz : max;
533 // set base distance between centers of bounding boxes
534 // to minimal (but big enough) size of current bounding box
535 if (dx < max) dx = FLT_MAX;
536 if (dy < max) dy = FLT_MAX;
537 if (dz < max) dz = FLT_MAX;
539 aCCDist = (dx < dy) ? dx : dy;
540 aCCDist = (dz < aCCDist) ? dz : aCCDist;
543 //-------------------------------->
547 // .--------------. .------.
548 //----------->| | | |
549 // aPrevShift '--------------' '------'
554 // (aDist + aPrevDist) * getDistance() / 2
556 aShift = aPrevShift + aPrevDist/2.0 + aCCDist*getDistance() - aDist/2.0;
559 aOffset[aAxis] += aShift;
560 aActor->SetPosition(aOffset);
562 if (mySaveChk->isChecked())
563 aPrs->SetOffset(aOffset[0],aOffset[1],aOffset[2]);
568 } // end of myPrsMap loop
569 // Loop in PointMap3D the same as previous loop
570 QMap<VISU::PointMap3d_i*, int>::Iterator itt;
571 for (itt = myPointMapPrsMap.begin(); itt != myPointMapPrsMap.end(); ++itt, i++) {
572 VISU::PointMap3d_i* aPrs = itt.key();
573 if (VISU_ActorBase* aActor = VISU::FindActorBase(myViewWindow, aPrs)) {
574 int aAxis = getAxis();
576 vtkFloatingPointType aZeroOffset[3];
577 aZeroOffset[0] = aZeroOffset[1] = aZeroOffset[2] = 0;
578 aActor->SetPosition(aZeroOffset);
579 aActor->GetMapper()->Update();
581 vtkFloatingPointType aBounds[6];
582 aActor->GetBounds(aBounds);
585 aDist = fabs(aBounds[1] - aBounds[0]);
588 aDist = fabs(aBounds[3] - aBounds[2]);
591 aDist = fabs(aBounds[5] - aBounds[4]);
593 vtkFloatingPointType aOffset[3];
594 aOffset[0] = aOffset[1] = aOffset[2] = 0;
596 (aBounds[2*aAxis+1] < aBounds[2*aAxis]) ? -aBounds[2*aAxis+1] : -aBounds[2*aAxis];
599 vtkFloatingPointType aCCDist = (aDist + aPrevDist) / 2.0;
601 vtkFloatingPointType dx = fabs(aBounds[1] - aBounds[0]);
602 vtkFloatingPointType dy = fabs(aBounds[3] - aBounds[2]);
603 vtkFloatingPointType dz = fabs(aBounds[5] - aBounds[4]);
604 vtkFloatingPointType max = (dx > dy) ? dx : dy;
605 max = (dz > max) ? dz : max;
609 // set base distance between centers of bounding boxes
610 // to minimal (but big enough) size of current bounding box
611 if (dx < max) dx = FLT_MAX;
612 if (dy < max) dy = FLT_MAX;
613 if (dz < max) dz = FLT_MAX;
615 aCCDist = (dx < dy) ? dx : dy;
616 aCCDist = (dz < aCCDist) ? dz : aCCDist;
618 aShift = aPrevShift + aPrevDist/2.0 + aCCDist*getDistance() - aDist/2.0;
621 aOffset[aAxis] += aShift;
622 aActor->SetPosition(aOffset);
624 if (mySaveChk->isChecked())
625 aPrs->SetOffset(aOffset[0],aOffset[1],aOffset[2]);
630 } // end of myPointMapPrsMap loop
632 myViewWindow->getRenderer()->ResetCameraClippingRange();
633 myViewWindow->Repaint();
637 //------------------------------------------------------------------------
638 //------------------------------------------------------------------------
640 class SetupDlg::LineEdit : public QLineEdit
643 LineEdit( QWidget* p = 0 ) : QLineEdit( p ) {}
644 virtual ~LineEdit() {}
647 void focusOutEvent( QFocusEvent* e )
649 QLineEdit::focusOutEvent( e );
651 if ( text().isEmpty() )
652 emit editingFinished();
654 void keyPressEvent( QKeyEvent* e )
656 QLineEdit::keyPressEvent( e );
658 if ( text().isEmpty() && e->key() == Qt::Key_Return )
659 emit returnPressed();
664 //------------------------------------------------------------------------
665 //------------------------------------------------------------------------
667 SetupDlg::SetupDlg (QWidget* theParent,
669 VISU_TimeAnimation* theAnimator) :
671 Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
672 myAnimator(theAnimator),
674 myIsRegenerate( false )
677 setWindowTitle("Setup Animation");
678 setSizeGripEnabled( TRUE );
680 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
681 aMainLayout->setMargin( 7 );
682 aMainLayout->setSpacing(5);
684 // Range of time stamps
685 myUseRangeBox = new QGroupBox("Use range of time stamps", this);
686 myUseRangeBox->setCheckable( true );
687 myUseRangeBox->setChecked(myAnimator->isRangeDefined());
689 QHBoxLayout* aRangeLayout = new QHBoxLayout( myUseRangeBox );
690 aRangeLayout->setMargin( 11 );
691 aRangeLayout->setSpacing( 6 );
693 double aMaxTime = myAnimator->getMaxTime();
694 double aMinTime = myAnimator->getMinTime();
696 if( myAnimator->getNbFields() > 0 ) {
697 if ( myAnimator->getAnimationMode() == VISU::Animation::PARALLEL )
698 aStep = (aMaxTime - aMinTime) / (myAnimator->getFieldData(0).myNbTimes - 1);
699 else { // successive animation mode
700 std::pair<int,long> aLastFieldFrame(myAnimator->getNbFields() - 1,
701 myAnimator->getFieldData(myAnimator->getNbFields() - 1).myNbTimes - 1);
702 aStep = (aMaxTime - aMinTime) / myAnimator->getAbsoluteFrameNumber(aLastFieldFrame);
706 QLabel* aMinLbl = new QLabel("From", myUseRangeBox);
707 aRangeLayout->addWidget(aMinLbl);
708 //myMinVal = new QtxDoubleSpinBox( aMinTime, aMaxTime, aStep, myUseRangeBox );
709 myMinVal = new LineEdit( myUseRangeBox );
710 myMinVal->setValidator( new QDoubleValidator( myMinVal ) );
711 if ( myUseRangeBox->isChecked() )
712 myMinVal->setText( QString::number( myAnimator->getMinRange() ) );
714 myMinVal->setText( QString::number( aMinTime ) );
716 // connect(myMinVal, SIGNAL( valueChanged(double)),
717 // this, SLOT( onMinValue(double) ));
718 connect( myMinVal, SIGNAL( returnPressed() ), this, SLOT( onMinValue() ) );
719 connect( myMinVal, SIGNAL( editingFinished() ), this, SLOT( onMinValue() ) );
720 // connect( myMinVal, SIGNAL( textChanged(const QString&)),
721 // this, SLOT( onMinValueEdit(const QString&) ));
722 aRangeLayout->addWidget(myMinVal);
724 QLabel* aMaxLbl = new QLabel("To", myUseRangeBox);
725 aRangeLayout->addWidget(aMaxLbl);
726 //myMaxVal = new QtxDoubleSpinBox( aMinTime, aMaxTime, aStep, myUseRangeBox );
727 myMaxVal = new LineEdit( myUseRangeBox );
728 myMaxVal->setValidator( new QDoubleValidator( myMaxVal ) );
729 if ( myUseRangeBox->isChecked() )
730 myMaxVal->setText( QString::number( myAnimator->getMaxRange() ) );
732 myMaxVal->setText( QString::number( aMaxTime ) );
734 // connect(myMaxVal, SIGNAL( valueChanged(double)),
735 // this, SLOT( onMaxValue(double) ));
736 connect( myMaxVal, SIGNAL( returnPressed() ), this, SLOT( onMaxValue() ) );
737 connect( myMaxVal, SIGNAL( editingFinished() ), this, SLOT( onMaxValue() ) );
738 // connect(myMaxVal, SIGNAL( textChanged(const QString&)),
739 // this, SLOT( onMaxValueEdit(const QString&) ));
740 aRangeLayout->addWidget(myMaxVal);
742 connect(myUseRangeBox, SIGNAL( toggled(bool)),
743 this, SLOT( onRangeCheck(bool) ));
745 aMainLayout->addWidget(myUseRangeBox);
747 // Sequence of time stamps
748 myUseSequenceBox = new QGroupBox("Use sequence of time stamps", this);
749 myUseSequenceBox->setCheckable( true );
750 myUseSequenceBox->setChecked( myAnimator->isSequenceDefined() );
752 QGridLayout* aUseSequenceLayout = new QGridLayout( myUseSequenceBox );
753 aUseSequenceLayout->setAlignment( Qt::AlignTop );
754 aUseSequenceLayout->setSpacing( 6 );
755 aUseSequenceLayout->setMargin( 11 );
757 QLabel* anIndicesLbl = new QLabel("Indices", myUseSequenceBox);
758 myIndices = new QLineEdit( myUseSequenceBox );
760 myValues = new QListWidget( myUseSequenceBox );
761 myValues->setSelectionMode( QAbstractItemView::ExtendedSelection );
763 connect(myIndices, SIGNAL( textChanged(const QString&)),
764 this, SLOT( onIndicesChanged(const QString&) ));
766 connect(myValues, SIGNAL( itemSelectionChanged() ),
767 this, SLOT( onValuesChanged() ) );
769 connect(myUseSequenceBox, SIGNAL( toggled(bool)),
770 this, SLOT( onSequenceCheck(bool) ));
772 aUseSequenceLayout->addWidget( anIndicesLbl, 0, 0 );
773 aUseSequenceLayout->addWidget( myIndices, 0, 1 );
774 aUseSequenceLayout->addWidget( myValues, 1, 1, 1, 2 );
776 aMainLayout->addWidget(myUseSequenceBox);
778 // Fields and Properties
779 QWidget* aPropFrame = new QWidget(this);
780 QHBoxLayout* aHPropLayout = new QHBoxLayout( aPropFrame );
781 aHPropLayout->setSpacing(5);
782 aHPropLayout->setMargin(0);
784 QGroupBox* aNamesBox = new QGroupBox("Fields",aPropFrame);
785 aHPropLayout->addWidget( aNamesBox );
786 QVBoxLayout* aVBoxLayout = new QVBoxLayout( aNamesBox );
788 myFieldLst = new QListWidget(aNamesBox);
789 aVBoxLayout->addWidget( myFieldLst );
790 QStringList aFieldNames;
791 // Find names of fields
792 for (int i = 0; i < myAnimator->getNbFields(); i++) {
793 _PTR(SObject) aSO = myAnimator->getFieldData(i).myField;
794 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSO);
795 QString aFieldName(aRestoringMap["myName"]);
796 if ( myAnimator->getAnimationMode() == VISU::Animation::PARALLEL )
797 aFieldNames.append(aFieldName);
798 else if ( myAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE ) {
799 _PTR(SObject) aSObject = aSO->GetFather()->GetFather()->GetFather();
800 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSObject);
801 QString aFileName(aRestoringMap["myInitFileName"]);
802 aFileName = aFileName.right(aFileName.length() - (aFileName.lastIndexOf("/") + 1));
803 aFieldNames.append(aFileName + QString(" : ") + aFieldName);
806 myFieldLst->addItems(aFieldNames);
808 if ( myAnimator->getAnimationMode() == VISU::Animation::PARALLEL ) {
809 myFieldLst->setCurrentRow(0);
810 connect( myFieldLst, SIGNAL( currentRowChanged(int) ),
811 this, SLOT( onFieldChange(int) ) );
813 else if ( myAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE )
814 myFieldLst->setSelectionMode(QAbstractItemView::NoSelection);
816 QWidget* aSetupBox = new QWidget(aPropFrame);
817 aHPropLayout->addWidget( aSetupBox );
818 aVBoxLayout = new QVBoxLayout( aSetupBox );
819 aVBoxLayout->setSpacing(5);
820 aVBoxLayout->setMargin(0);
822 QGroupBox* aPropBox = new QGroupBox("Properties", aSetupBox);
823 aVBoxLayout->addWidget( aPropBox );
824 QVBoxLayout* aPropVBLay = new QVBoxLayout( aPropBox );
826 //QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame);
827 myTypeCombo = new QComboBox(aPropBox);
828 aPropVBLay->addWidget( myTypeCombo );
829 connect( myTypeCombo, SIGNAL( activated(int) ),
830 this, SLOT( onTypeChanged(int) ) );
832 // QPushButton* aBarBtn = new QPushButton("Scalar Bar...", aPropBox);
833 //connect( aBarBtn, SIGNAL( clicked() ),
834 // this, SLOT( onScalarBarDlg() ) );
836 myPropBtn = new QPushButton("Properties...", aPropBox);
837 myPropBtn->setAutoDefault( false );
838 aPropVBLay->addWidget( myPropBtn );
839 // myPropBtn->setEnabled(myAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
840 connect( myPropBtn, SIGNAL( clicked() ),
841 this, SLOT( onPreferencesDlg() ) );
843 if (myAnimator->getNbFields() > 1 ) {
844 if( myAnimator->getAnimationMode() == VISU::Animation::PARALLEL ) {
845 myArrangeBtn = new QPushButton("Arrange...", aSetupBox);
846 aVBoxLayout->addWidget( myArrangeBtn );
847 connect( myArrangeBtn, SIGNAL( clicked() ), this, SLOT( onArrangeDlg() ) );
851 aMainLayout->addWidget(aPropFrame);
853 QWidget* aBtnBox = new QWidget(this);
854 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox);
855 aBtnLayout->setContentsMargins( 5, 5, 0, 5 );
856 // aBtnLayout->addStretch();
858 QPushButton* closeBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
859 closeBtn->setAutoDefault( false );
860 aBtnLayout->addStretch();
861 aBtnLayout->addWidget( closeBtn );
862 connect( closeBtn, SIGNAL( clicked() ), this, SLOT( onClose() ) );
864 aMainLayout->addWidget( aBtnBox );
867 //------------------------------------------------------------------------
868 void SetupDlg::initialize()
872 _PTR(Study) aStudy = myAnimator->getStudy();
874 if( myAnimator->getNbFields() == 0 )
877 FieldData& aData = myAnimator->getFieldData( 0 );
878 _PTR(SObject) aField = aData.myField;
883 _PTR(ChildIterator) anIter = aStudy->NewChildIterator(aField);
884 anIter->Next(); // First is reference on support
885 for(int index = 1; anIter->More(); anIter->Next(), index++)
887 double aTime = VISU_TimeAnimation::getTimeValue(anIter->Value());
888 QString itemText = QString("[%1] - %2").arg( index ).arg( aTime );
890 myValues->addItem( itemText );
893 QString anIndices( myAnimator->getAnimationSequence() );
894 myIndices->setText( anIndices );
897 //------------------------------------------------------------------------
899 TSCALARMAP_ITEM = 0, // VISU::TSCALARMAP
900 TISOSURFACES_ITEM = 1, // VISU::TISOSURFACES
901 TCUTPLANES_ITEM = 2, // VISU::TCUTPLANES
902 TCUTLINES_ITEM = 3, // VISU::TCUTLINES
903 TPLOT3D_ITEM = 4, // VISU::TPLOT3D
904 TDEFORMEDSHAPE_ITEM = 5, // VISU::TDEFORMEDSHAPE
905 TVECTORS_ITEM = 6, // VISU::TVECTORS
906 TSTREAMLINES_ITEM = 7, // VISU::TSTREAMLINES
907 TGAUSSPOINTS_ITEM = 8, // VISU::TGAUSSPOINTS
908 TDEFORMEDSHAPEANDSCALARMAP_ITEM = 9 // VISU::TDEFORMEDSHAPEANDSCALARMAP
911 //------------------------------------------------------------------------
912 void SetupDlg::onClose()
914 if ( !myUseRangeBox->isChecked() )
915 myAnimator->setAnimationRange( 0, 0 );
918 double min = myMinVal->text().toDouble();
919 double max = myMaxVal->text().toDouble();
920 myAnimator->setAnimationRange( qMin( min, max ), qMax( min, max ) );
923 if ( !myUseSequenceBox->isChecked() )
924 myAnimator->setAnimationSequence( 0 );
929 //------------------------------------------------------------------------
930 void SetupDlg::onFieldChange (int theIndex)
932 myTypeCombo->clear();
933 myTypeId2ComboId.clear();
934 myComboId2TypeId.clear();
936 if( myAnimator->getNbFields() == 0 )
939 // ATTENTION: append items in the same order like it is done in the PrsComboItem enumeration
940 myTypeCombo->addItem("Scalar Map"); // item 0
941 myTypeId2ComboId[TSCALARMAP_ITEM] = myComboId2TypeId.size();
942 myComboId2TypeId.push_back(TSCALARMAP_ITEM);;
944 myTypeCombo->addItem("Iso Surfaces"); // item 1
945 myTypeId2ComboId[TISOSURFACES_ITEM] = myComboId2TypeId.size();
946 myComboId2TypeId.push_back(TISOSURFACES_ITEM);;
948 myTypeCombo->addItem("Cut Planes"); // item 2
949 myTypeId2ComboId[TCUTPLANES_ITEM] = myComboId2TypeId.size();
950 myComboId2TypeId.push_back(TCUTPLANES_ITEM);;
952 myTypeCombo->addItem("Cut Lines"); // item 3
953 myTypeId2ComboId[TCUTLINES_ITEM] = myComboId2TypeId.size();
954 myComboId2TypeId.push_back(TCUTLINES_ITEM);;
956 myTypeCombo->addItem("Plot 3D"); // item 4
957 myTypeId2ComboId[TPLOT3D_ITEM] = myComboId2TypeId.size();
958 myComboId2TypeId.push_back(TPLOT3D_ITEM);;
960 bool anEnableItems = false;
961 bool anEnableGP = false;
962 VISU::VISUType aPrsType;
963 if ( myAnimator->getAnimationMode() == VISU::Animation::PARALLEL ) { // parallel animation mode
965 FieldData& aData = myAnimator->getFieldData(theIndex);
966 _PTR(SObject) aSObject = aData.myField;
967 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSObject);
968 long aNumComp = aRestoringMap["myNumComponent"].toLong();
969 anEnableItems = (aNumComp > 1);
971 long anEntityId = aRestoringMap["myEntityId"].toLong();
972 anEnableGP = (anEntityId == VISU::CELL);
974 aPrsType = aData.myPrsType;
977 else if ( myAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE ) { // successive animation mode
979 for (int i = 0; i < myAnimator->getNbFields(); i++) {
980 _PTR(SObject) aSO = myAnimator->getFieldData(i).myField;
981 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSO);
982 long aNumComp = aRestoringMap["myNumComponent"].toLong();
983 anEnableItems = (aNumComp > 1);
985 long anEntityId = aRestoringMap["myEntityId"].toLong();
986 anEnableGP = (anEntityId == VISU::CELL);
988 if ( !anEnableItems && !anEnableGP ) break;
991 aPrsType = myAnimator->getFieldData(0).myPrsType;
996 myTypeCombo->addItem("Deformed Shape"); // item 5
997 myTypeId2ComboId[TDEFORMEDSHAPE_ITEM] = myComboId2TypeId.size();
998 myComboId2TypeId.push_back(TDEFORMEDSHAPE_ITEM);;
1000 myTypeCombo->addItem("Vectors"); // item 6
1001 myTypeId2ComboId[TVECTORS_ITEM] = myComboId2TypeId.size();
1002 myComboId2TypeId.push_back(TVECTORS_ITEM);;
1004 myTypeCombo->addItem("Stream Lines"); // item 7
1005 myTypeId2ComboId[TSTREAMLINES_ITEM] = myComboId2TypeId.size();
1006 myComboId2TypeId.push_back(TSTREAMLINES_ITEM);;
1008 myTypeCombo->addItem("Deformed shape and Scalar map"); // item 9
1009 myTypeId2ComboId[TDEFORMEDSHAPEANDSCALARMAP_ITEM] = myComboId2TypeId.size();
1010 myComboId2TypeId.push_back(TDEFORMEDSHAPEANDSCALARMAP_ITEM);;
1014 myTypeCombo->addItem("Gauss Points"); // item 8
1015 myTypeId2ComboId[TGAUSSPOINTS_ITEM] = myComboId2TypeId.size();
1016 myComboId2TypeId.push_back(TGAUSSPOINTS_ITEM);;
1020 case VISU::TSCALARMAP: //Scalar Map
1021 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TSCALARMAP_ITEM]);
1023 case VISU::TISOSURFACES: //Iso Surfaces
1024 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TISOSURFACES_ITEM]);
1026 case VISU::TCUTPLANES: //Cut Planes
1027 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TCUTPLANES_ITEM]);
1029 case VISU::TCUTLINES: //Cut Lines
1030 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TCUTLINES_ITEM]);
1032 case VISU::TPLOT3D: //Plot 3D
1033 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TPLOT3D_ITEM]);
1035 case VISU::TDEFORMEDSHAPE: //Deformed Shape
1036 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TDEFORMEDSHAPE_ITEM]);
1038 case VISU::TSCALARMAPONDEFORMEDSHAPE: //Scalar Map on Deformed Shape
1039 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1040 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TDEFORMEDSHAPEANDSCALARMAP_ITEM]);
1042 case VISU::TVECTORS: //Vectors
1043 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TVECTORS_ITEM]);
1045 case VISU::TSTREAMLINES: //Stream Lines
1046 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TSTREAMLINES_ITEM]);
1048 case VISU::TGAUSSPOINTS: //Gauss Points
1049 myTypeCombo->setCurrentIndex(myTypeId2ComboId[TGAUSSPOINTS_ITEM]);
1052 //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
1055 //------------------------------------------------------------------------
1056 void SetupDlg::onTypeChanged (int theIndex)
1058 int aType = myComboId2TypeId[theIndex];
1060 for (int i = 0; i < myAnimator->getNbFields(); i++) {
1061 FieldData& aData = ( myAnimator->getAnimationMode() == VISU::Animation::PARALLEL ) ?
1062 myAnimator->getFieldData(myFieldLst->currentRow()) :
1063 myAnimator->getFieldData(i);
1066 case TSCALARMAP_ITEM: //Scalar Map
1067 aData.myPrsType = VISU::TSCALARMAP;
1069 case TISOSURFACES_ITEM: //Iso Surfaces
1070 aData.myPrsType = VISU::TISOSURFACES;
1072 case TCUTPLANES_ITEM: //Cut Planes
1073 aData.myPrsType = VISU::TCUTPLANES;
1075 case TCUTLINES_ITEM: //Cut Lines
1076 aData.myPrsType = VISU::TCUTLINES;
1078 case TPLOT3D_ITEM: //Plot 3D
1079 aData.myPrsType = VISU::TPLOT3D;
1081 case TDEFORMEDSHAPE_ITEM: //Deformed Shape
1082 aData.myPrsType = VISU::TDEFORMEDSHAPE;
1084 case TDEFORMEDSHAPEANDSCALARMAP_ITEM: //Scalar Map on Deformed Shape
1085 aData.myPrsType = VISU::TDEFORMEDSHAPEANDSCALARMAP;
1087 case TVECTORS_ITEM: //Vectors
1088 aData.myPrsType = VISU::TVECTORS;
1090 case TSTREAMLINES_ITEM: //Stream Lines
1091 aData.myPrsType = VISU::TSTREAMLINES;
1093 case TGAUSSPOINTS_ITEM: //Gauss Points
1094 aData.myPrsType = VISU::TGAUSSPOINTS;
1097 myAnimator->clearData(aData);
1099 if ( myAnimator->getAnimationMode() == VISU::Animation::PARALLEL ) // parallel animation mode
1102 //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
1103 //myAnimator->generatePresentations(myFieldLst->currentItem());
1107 //------------------------------------------------------------------------
1110 template<class TPrs3d, class TDialog>
1112 EditPrs(VisuGUI* theModule,
1114 VISU_TimeAnimation* theAnimator)
1116 TDialog* aDlg = new TDialog(theModule);
1117 TPrs3d* aPrs3d = dynamic_cast<TPrs3d*>(theData.myPrs[0]);
1118 aDlg->initFromPrsObject(aPrs3d, true);
1119 if (aDlg->exec() && aDlg->storeToPrsObject(dynamic_cast<TPrs3d*>(aPrs3d))) {
1121 for (long aFrameId = 1; aFrameId < theData.myNbFrames; aFrameId++){
1122 VISU::ColoredPrs3d_i* aColoredPrs3d = theData.myPrs[aFrameId];
1123 aColoredPrs3d->SameAs(aPrs3d);
1126 if ( theAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE ) {
1127 for (int aFieldId = 1; aFieldId < theAnimator->getNbFields(); aFieldId++) {
1128 FieldData& aFieldData = theAnimator->getFieldData(aFieldId);
1129 for (long aFrameId = 0; aFrameId < aFieldData.myNbFrames; aFrameId++) {
1130 VISU::ColoredPrs3d_i* aColoredPrs3d = aFieldData.myPrs[aFrameId];
1131 std::string aTitle = aColoredPrs3d->GetCTitle();
1132 aColoredPrs3d->SameAs(aPrs3d);
1133 aColoredPrs3d->SetTitle(aTitle.c_str());
1143 void SetupDlg::onPreferencesDlg()
1145 if(myAnimator->getNbFields() == 0){
1146 SUIT_MessageBox::warning(this,
1148 VisuGUI_TimeAnimationDlg::tr("MSG_NO_ANIMATIONDATA"),
1153 SUIT_OverrideCursor c;
1155 VISU::Animation::AnimationMode aMode = myAnimator->getAnimationMode();
1156 int aRefFieldId = ( aMode == VISU::Animation::PARALLEL ) ? myFieldLst->currentRow() : 0;
1157 FieldData& aData = myAnimator->getFieldData(aRefFieldId);
1158 if (aData.myPrs.empty())
1159 myAnimator->generatePresentations(aRefFieldId);
1161 if ( myAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE ) {
1162 for (int i = 0; i < myAnimator->getNbFields(); i++) {
1163 if ( i != aRefFieldId && myAnimator->getFieldData(i).myPrs.empty() )
1164 myAnimator->generatePresentations(i);
1168 if(!aData.myNbFrames || aData.myPrs.empty() || !aData.myPrs[0]){
1169 QApplication::restoreOverrideCursor();
1170 SUIT_MessageBox::warning(this,
1172 VisuGUI_TimeAnimationDlg::tr("MSG_NO_ANIMATIONDATA"),
1177 int aType = myComboId2TypeId[myTypeCombo->currentIndex()];
1179 case TSCALARMAP_ITEM: //Scalar Map
1181 EditPrs<VISU::ScalarMap_i,VisuGUI_ScalarBarDlg>(myModule,aData,myAnimator);
1183 case TISOSURFACES_ITEM: //Iso Surfaces
1185 EditPrs<VISU::IsoSurfaces_i,VisuGUI_IsoSurfacesDlg>(myModule,aData,myAnimator);
1187 case TCUTPLANES_ITEM: //Cut Planes
1189 EditPrs<VISU::CutPlanes_i,VisuGUI_CutPlanesDlg>(myModule,aData,myAnimator);
1191 case TCUTLINES_ITEM: //Cut Lines
1193 EditPrs<VISU::CutLines_i,VisuGUI_CutLinesDlg>(myModule,aData,myAnimator);
1195 case TPLOT3D_ITEM: //Plot 3D
1197 EditPrs<VISU::Plot3D_i,VisuGUI_Plot3DDlg>(myModule,aData,myAnimator);
1199 case TDEFORMEDSHAPE_ITEM: //Deformed Shape
1201 EditPrs<VISU::DeformedShape_i,VisuGUI_DeformedShapeDlg>(myModule,aData,myAnimator);
1203 case TDEFORMEDSHAPEANDSCALARMAP_ITEM: //Scalar Map on Deformed Shape
1206 typedef VisuGUI_DeformedShapeAndScalarMapDlg DLG;
1207 typedef VISU::DeformedShapeAndScalarMap_i TYPE;
1208 DLG* aDlg = new DLG (myModule);
1209 TYPE* aPrs3d = dynamic_cast<TYPE*>(aData.myPrs[0]);
1210 aDlg->initFromPrsObject(aPrs3d, true);
1211 if (aDlg->exec() && aDlg->storeToPrsObject(aData.myPrs[0])) {
1212 for (long aFrameId = 1; aFrameId < aData.myNbFrames; aFrameId++){
1213 TYPE* aDeformedPrs3d = dynamic_cast<TYPE*>(aData.myPrs[aFrameId]);
1214 //Set correct time stamp number
1215 int aTimeStampNum = aDeformedPrs3d->GetScalarTimeStampNumber();
1216 aDeformedPrs3d->SameAs(aPrs3d);
1217 aDeformedPrs3d->SetScalarField(aDeformedPrs3d->GetScalarEntity(),
1218 aDeformedPrs3d->GetScalarFieldName(),
1223 if ( myAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE ) {
1224 for (int aFieldId = 1; aFieldId < myAnimator->getNbFields(); aFieldId++) {
1225 FieldData& aFieldData = myAnimator->getFieldData(aFieldId);
1226 for (long aFrameId = 0; aFrameId < aFieldData.myNbFrames; aFrameId++) {
1227 TYPE* aDeformedPrs3d = dynamic_cast<TYPE*>(aFieldData.myPrs[aFrameId]);
1228 std::string aTitle = aDeformedPrs3d->GetCTitle();
1229 //Set correct time stamp number
1230 int aTimeStampNum = aDeformedPrs3d->GetScalarTimeStampNumber();
1231 aDeformedPrs3d->SameAs(aPrs3d);
1232 aDeformedPrs3d->SetTitle(aTitle.c_str());
1233 aDeformedPrs3d->SetScalarField(aDeformedPrs3d->GetScalarEntity(),
1234 aDeformedPrs3d->GetScalarFieldName(),
1244 case TVECTORS_ITEM: //Vectors
1246 EditPrs<VISU::Vectors_i,VisuGUI_VectorsDlg>(myModule,aData,myAnimator);
1248 case TSTREAMLINES_ITEM: //Stream Lines
1250 EditPrs<VISU::StreamLines_i,VisuGUI_StreamLinesDlg>(myModule,aData,myAnimator);
1252 case TGAUSSPOINTS_ITEM: //Gauss Points
1254 EditPrs<VISU::GaussPoints_i,VisuGUI_GaussPointsDlg>(myModule,aData,myAnimator);
1260 //------------------------------------------------------------------------
1261 void SetupDlg::onArrangeDlg()
1263 ArrangeDlg aDlg(this, myAnimator);
1267 //------------------------------------------------------------------------
1268 void SetupDlg::onRangeCheck (bool theCheck)
1272 myUseSequenceBox->blockSignals( true );
1273 myUseSequenceBox->setChecked( false );
1274 myUseSequenceBox->blockSignals( false );
1278 myAnimator->setAnimationRange(0, 0);
1280 myAnimator->setAnimationRange(myMinVal->text().toDouble(), myMaxVal->text().toDouble());
1282 setIsRegenerate( true );
1285 //------------------------------------------------------------------------
1286 void SetupDlg::onMinValue()
1288 double aVal = myMinVal->text().toDouble();
1289 aVal = qMax( qMin( aVal, myAnimator->getMaxRange() ), myAnimator->getMinTime() );
1290 myAnimator->setAnimationRange( aVal, myAnimator->getMaxRange() );
1291 myMinVal->setText( QString::number( aVal ) );
1292 myMinVal->setFocus();
1294 setIsRegenerate( true );
1297 //------------------------------------------------------------------------
1298 void SetupDlg::onMaxValue()
1300 double aVal = myMaxVal->text().toDouble();
1301 aVal = qMin( qMax( aVal, myAnimator->getMinRange() ), myAnimator->getMaxTime() );
1302 myAnimator->setAnimationRange( myAnimator->getMinRange(), aVal );
1303 myMaxVal->setText( QString::number( aVal ) );
1304 myMaxVal->setFocus();
1306 setIsRegenerate( true );
1309 //------------------------------------------------------------------------
1310 void SetupDlg::onMinValueEdit (const QString& theVal)
1312 double aVal = theVal.toDouble();
1313 if ((aVal > myAnimator->getMaxRange()) || (aVal < myAnimator->getMinRange())){
1314 myMinVal->setText( QString::number(myAnimator->getMinTime()) );
1315 myMinVal->setFocus();
1320 //------------------------------------------------------------------------
1321 void SetupDlg::onMaxValueEdit (const QString& theVal)
1323 double aVal = theVal.toDouble();
1324 if ((aVal > myAnimator->getMaxRange()) || (aVal < myAnimator->getMinRange())) {
1325 myMaxVal->setText( QString::number(myAnimator->getMaxTime()) );
1326 myMaxVal->setFocus();
1330 //------------------------------------------------------------------------
1331 void SetupDlg::onSequenceCheck( bool theCheck )
1335 myUseRangeBox->blockSignals( true );
1336 myUseRangeBox->setChecked( false );
1337 myUseRangeBox->blockSignals( false );
1340 QString anIndices = myIndices->text();
1341 myAnimator->setAnimationSequence( anIndices.toLatin1().data() );
1343 setIsRegenerate( true );
1346 //------------------------------------------------------------------------
1347 void SetupDlg::onIndicesChanged( const QString& theIndices )
1349 bool aCorrect = true;
1350 int aLimit = myValues->count();
1352 QList<long> anIndicesList;
1353 aCorrect = myAnimator->getIndicesFromSequence( theIndices, anIndicesList );
1355 myValues->blockSignals( true );
1356 myValues->clearSelection();
1358 QList<long>::iterator indIt = anIndicesList.begin();
1359 QList<long>::iterator indItEnd = anIndicesList.end();
1360 for( int i = 0; indIt != indItEnd; ++indIt, i++ )
1362 long anIndex = *indIt;
1363 if( anIndex < 1 || anIndex > aLimit )
1366 myValues->clearSelection();
1369 myValues->item( anIndex-1 )->setSelected( true );
1372 myValues->blockSignals( false );
1374 QPalette palette = myIndices->palette();
1378 palette.setColor(myIndices->foregroundRole(), Qt::red);
1379 myIndices->setPalette(palette);
1383 palette.setColor(myIndices->foregroundRole(), Qt::black);
1384 myIndices->setPalette(palette);
1386 myAnimator->setAnimationSequence( theIndices.toLatin1().data() );
1388 setIsRegenerate( true );
1391 //------------------------------------------------------------------------
1392 void SetupDlg::onValuesChanged()
1394 int aLimit = myValues->count();
1398 for( int i = 0; i < aLimit; i++ )
1400 if( !myValues->item( i )->isSelected() )
1403 QString aString = QString::number( i+1 );
1405 bool aPrevSelected = i != 0 && myValues->item( i-1 )->isSelected();
1406 bool aNextSelected = i != aLimit - 1 && myValues->item( i+1 )->isSelected();
1422 anIndices += aString;
1425 if( anIndices.right( 1 ) == "," )
1426 anIndices.truncate( anIndices.length() - 1 );
1428 myIndices->blockSignals( true );
1430 QPalette palette = myIndices->palette();
1431 palette.setColor(myIndices->foregroundRole(), Qt::black);
1432 myIndices->setPalette(palette);
1434 myIndices->setText( anIndices );
1435 myIndices->blockSignals( false );
1437 myAnimator->setAnimationSequence( anIndices.toLatin1().data() );
1439 setIsRegenerate( true );
1442 //------------------------------------------------------------------------
1443 static const char * firstIco[] = {
1459 static const char * lastIco[] = {
1475 static const char * leftIco[] = {
1490 static const char * playIco[] = {
1509 static QPixmap MYplayPixmap(playIco);
1512 static const char * rightIco[] = {
1528 static const char * pauseIco[] = {
1547 static QPixmap MYpausePixmap(pauseIco);
1550 VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule,
1551 _PTR(Study) theStudy,
1552 VISU::Animation::AnimationMode theMode) :
1553 QDialog(VISU::GetDesktop(theModule),
1554 Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
1555 myModule(theModule),
1558 setAttribute( Qt::WA_DeleteOnClose, true );
1560 if ( theMode == VISU::Animation::PARALLEL )
1561 setWindowTitle(tr("PARALLEL_ANIMATION"));
1563 setWindowTitle(tr("SUCCESSIVE_ANIMATION"));
1564 setSizeGripEnabled( TRUE );
1566 myAnimator = new VISU_TimeAnimation (theStudy);
1567 myAnimator->setViewer(VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule));
1568 connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double)));
1569 connect(myAnimator, SIGNAL(stopped()), this, SLOT(onStop()));
1570 myAnimator->setAnimationMode(theMode);
1572 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
1573 aMainLayout->setMargin( 7 );
1574 aMainLayout->setSpacing(5);
1576 mySetupBtn = new QPushButton("Setup Animation...", this);
1577 connect( mySetupBtn, SIGNAL( clicked() ),
1578 this, SLOT( onSetupDlg() ) );
1579 aMainLayout->addWidget(mySetupBtn);
1581 myGenBtn = new QPushButton("Generate frames", this);
1582 connect( myGenBtn, SIGNAL( clicked() ),
1583 this, SLOT( createFrames() ) );
1584 aMainLayout->addWidget(myGenBtn);
1586 myPlayFrame = new QFrame(this);
1587 myPlayFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
1588 myPlayFrame->setLineWidth( 1 );
1591 // --- Play controls ---
1592 QGridLayout* TopLayout = new QGridLayout( myPlayFrame );
1593 TopLayout->setSpacing( 6 );
1594 TopLayout->setMargin( 11 );
1596 myTimeLbl = new QLabel("0", myPlayFrame);
1597 TopLayout->addWidget(myTimeLbl, 0, 0, 1, 3, Qt::AlignHCenter);
1599 mySlider = new QSlider( myPlayFrame);
1600 mySlider->setOrientation(Qt::Horizontal);
1601 mySlider->setMinimum(0);
1602 mySlider->setMaximum(3);
1603 mySlider->setTickInterval(1);
1604 //mySlider->setTickmarks(QSlider::Below);
1605 mySlider->setTracking(false);
1606 connect( mySlider, SIGNAL( sliderMoved(int) ),
1607 this, SLOT( onWindowChanged(int) ) );
1608 TopLayout->addWidget(mySlider, 1, 0, 1, 3);
1610 myPlayBtn = new QPushButton(myPlayFrame);
1611 myPlayBtn->setIcon(MYplayPixmap);
1612 myPlayBtn->setCheckable(true);
1613 connect( myPlayBtn, SIGNAL( clicked() ),
1614 this, SLOT( onPlayPressed() ) );
1615 TopLayout->addWidget(myPlayBtn, 2, 0, 1, 2);
1617 QPushButton* aBackBtn = new QPushButton(myPlayFrame);
1618 aBackBtn->setIcon(QPixmap(leftIco));
1619 connect( aBackBtn, SIGNAL( clicked() ),
1620 this, SLOT( onBackPressed() ) );
1621 TopLayout->addWidget(aBackBtn, 3, 0);
1623 QPushButton* aForvardBtn = new QPushButton(myPlayFrame);
1624 aForvardBtn->setIcon(QPixmap(rightIco));
1625 connect( aForvardBtn, SIGNAL( clicked() ),
1626 this, SLOT( onForvardPressed() ) );
1627 TopLayout->addWidget(aForvardBtn, 3, 1);
1629 QPushButton* aFirstBtn = new QPushButton(myPlayFrame);
1630 aFirstBtn->setIcon(QPixmap(firstIco));
1631 connect( aFirstBtn, SIGNAL( clicked() ),
1632 this, SLOT( onFirstPressed() ) );
1633 TopLayout->addWidget(aFirstBtn, 4, 0);
1635 QPushButton* aLastBtn = new QPushButton(myPlayFrame);
1636 aLastBtn->setIcon(QPixmap(lastIco));
1637 connect( aLastBtn, SIGNAL( clicked() ),
1638 this, SLOT( onLastPressed() ) );
1639 TopLayout->addWidget(aLastBtn, 4, 1);
1641 QLabel* aSpeedLbl = new QLabel("Speed", myPlayFrame);
1642 TopLayout->addWidget(aSpeedLbl, 4, 2, Qt::AlignRight);
1644 QLCDNumber* aSpeedNum = new QLCDNumber( 2, myPlayFrame );
1645 aSpeedNum->setSegmentStyle(QLCDNumber::Flat);
1646 aSpeedNum->display((int)myAnimator->getSpeed());
1647 TopLayout->addWidget(aSpeedNum, 4, 3);
1649 QwtWheel* aWheel = new QwtWheel(myPlayFrame);
1650 aWheel->setOrientation(Qt::Vertical);
1651 aWheel->setRange(1, 99, 1);
1652 aWheel->setValue((int)myAnimator->getSpeed());
1653 connect( aWheel, SIGNAL(valueChanged(double)),
1654 aSpeedNum, SLOT(display(double)) );
1655 connect( aWheel, SIGNAL(valueChanged(double)),
1656 this, SLOT(onSpeedChange(double)) );
1657 TopLayout->addWidget(aWheel, 1, 3, 3, 1, Qt::AlignRight);
1659 QCheckBox* aCycleCheck = new QCheckBox("Cycled animation",myPlayFrame);
1660 aCycleCheck->setChecked(myAnimator->isCycling());
1661 connect(aCycleCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCyclingSlot(bool)));
1662 TopLayout->addWidget(aCycleCheck, 5, 0, 1, 4);
1664 QCheckBox* aPropCheck = new QCheckBox("Use proportional timing",myPlayFrame);
1665 aPropCheck->setChecked(myAnimator->isProportional());
1666 connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool)));
1667 TopLayout->addWidget(aPropCheck, 6, 0, 1, 4);
1669 // Pictures saving on disk
1670 QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame );
1671 //aSaveBox->setColumnLayout(0, Qt::Horizontal );
1672 QGridLayout* aSaveLay = new QGridLayout(aSaveBox);
1673 aSaveLay->setSpacing( 5 );
1674 aSaveLay->setMargin( 5 );
1676 mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox);
1677 connect(mySaveCheck, SIGNAL( toggled(bool)),
1678 this, SLOT( onCheckDump(bool) ));
1679 aSaveLay->addWidget(mySaveCheck, 0, 0, 1, 3);
1681 QLabel* aFormatLbl = new QLabel("Saving format:", aSaveBox);
1682 aFormatLbl->setEnabled(false);
1683 connect(mySaveCheck, SIGNAL( toggled(bool)),
1684 aFormatLbl, SLOT( setEnabled(bool) ));
1685 aSaveLay->addWidget(aFormatLbl, 1, 0, 1, 2);
1687 myPicsFormat = new QComboBox(aSaveBox);
1688 QList<QByteArray> aDumpFormats = QImageWriter::supportedImageFormats();
1689 for (unsigned int i = 0; i < aDumpFormats.count(); i++) {
1690 myPicsFormat->addItem(aDumpFormats.at(i));
1692 if (aDumpFormats.indexOf("jpeg") >= 0)
1693 myPicsFormat->setCurrentIndex(aDumpFormats.indexOf("jpeg"));
1695 myPicsFormat->setCurrentIndex(0);
1697 myPicsFormat->setEnabled(false);
1698 aSaveLay->addWidget(myPicsFormat, 1, 2);
1699 connect(mySaveCheck, SIGNAL( toggled(bool)),
1700 myPicsFormat, SLOT( setEnabled(bool) ));
1701 connect(myPicsFormat, SIGNAL( activated (int)),
1702 this, SLOT( onPicsFormatChanged()));
1704 QLabel* aPathLbl = new QLabel("Path:", aSaveBox);
1705 aPathLbl->setEnabled(false);
1706 connect(mySaveCheck, SIGNAL( toggled(bool)),
1707 aPathLbl, SLOT( setEnabled(bool) ));
1708 aSaveLay->addWidget(aPathLbl, 2, 0);
1710 myPathEdit = new QLineEdit(aSaveBox);
1711 myPathEdit->setReadOnly(true);
1712 myPathEdit->setEnabled(false);
1713 connect(mySaveCheck, SIGNAL( toggled(bool)),
1714 myPathEdit, SLOT( setEnabled(bool) ));
1715 aSaveLay->addWidget(myPathEdit, 2, 1);
1717 QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox);
1718 aBrowseBtn->setEnabled(false);
1719 connect(mySaveCheck, SIGNAL( toggled(bool)),
1720 aBrowseBtn, SLOT( setEnabled(bool) ));
1721 connect(aBrowseBtn, SIGNAL( clicked()),
1722 this, SLOT( onBrowse() ));
1723 mySaveCheck->setChecked(false);
1724 aSaveLay->addWidget(aBrowseBtn, 2, 2);
1726 mySaveAVICheck = new QCheckBox("Save animation to AVI file", aSaveBox);
1727 connect(mySaveAVICheck, SIGNAL( toggled(bool)),
1728 this, SLOT( onCheckDump(bool) ));
1729 aSaveLay->addWidget(mySaveAVICheck, 3, 0, 1, 3);
1731 myPathAVILbl = new QLabel("Path:", aSaveBox);
1732 myPathAVILbl->setEnabled(false);
1733 //connect(mySaveAVICheck, SIGNAL( toggled(bool)),
1734 // myPathAVILbl, SLOT( setEnabled(bool) ));
1735 aSaveLay->addWidget(myPathAVILbl, 4, 0);
1737 myPathAVIEdit = new QLineEdit(aSaveBox);
1738 myPathAVIEdit->setReadOnly(true);
1739 myPathAVIEdit->setEnabled(false);
1740 //connect(mySaveAVICheck, SIGNAL( toggled(bool)),
1741 // myPathAVIEdit, SLOT( setEnabled(bool) ));
1742 aSaveLay->addWidget(myPathAVIEdit, 4, 1);
1744 myBrowseAVIBtn = new QPushButton("Browse...", aSaveBox);
1745 myBrowseAVIBtn->setEnabled(false);
1746 //connect(mySaveAVICheck, SIGNAL( toggled(bool)),
1747 // myBrowseAVIBtn, SLOT( setEnabled(bool) ));
1748 connect(myBrowseAVIBtn, SIGNAL( clicked()),
1749 this, SLOT( onBrowseAVI() ));
1750 aSaveLay->addWidget(myBrowseAVIBtn, 4, 2);
1752 mySaveAVICheck->setChecked(false);
1753 //mySaveAVICheck->setEnabled(myAnimator->checkAVIMaker());
1755 TopLayout->addWidget(aSaveBox, 7, 0, 1, 4);
1757 QCheckBox* aCleanMemCheck = new QCheckBox("Clean memory at each frame",myPlayFrame);
1758 aCleanMemCheck->setChecked(myAnimator->isCleaningMemoryAtEachFrame());
1759 connect(aCleanMemCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCleaningMemoryAtEachFrameSlot(bool)));
1760 TopLayout->addWidget(aCleanMemCheck, 8, 0, 1, 4);
1762 aMainLayout->addWidget(myPlayFrame);
1764 // Animation publishing in study
1765 QWidget* aPublishBox = new QWidget(this);
1766 QHBoxLayout* aPubHBLay = new QHBoxLayout( aPublishBox );
1767 aPubHBLay->setMargin( 0 );
1769 myPublishBtn = new QPushButton("Publish to study", aPublishBox);
1770 aPubHBLay->addWidget( myPublishBtn );
1771 connect(myPublishBtn, SIGNAL(clicked()), this, SLOT(publishToStudy()));
1773 mySaveBtn = new QPushButton("Save Animation", aPublishBox);
1774 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1775 aPubHBLay->addWidget( mySaveBtn );
1776 connect(mySaveBtn, SIGNAL(clicked()), this, SLOT(saveToStudy()));
1778 aMainLayout->addWidget(aPublishBox);
1781 QWidget* aBtnBox = new QWidget(this);
1782 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox);
1783 aBtnLayout->setContentsMargins( 5, 5, 0, 5 );
1784 aBtnLayout->addStretch();
1786 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
1787 aBtnLayout->addWidget( aCloseBtn );
1788 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
1790 QPushButton* aHelpBtn = new QPushButton(tr("BUT_HELP"), aBtnBox);
1791 aBtnLayout->addWidget( aHelpBtn );
1792 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
1794 SUIT_Study* aStudy = VISU::GetAppStudy(myModule);
1795 connect(aStudy, SIGNAL(destroyed()), this, SLOT(close()));
1797 connect(myAnimator->getViewer(), SIGNAL(destroyed()), this, SLOT(close()));
1798 connect(myAnimator->getViewer(), SIGNAL(closing(SUIT_ViewWindow*)), this, SLOT(close()));
1800 aMainLayout->addWidget(aBtnBox);
1802 myPlayFrame->setEnabled(false);
1805 //------------------------------------------------------------------------
1806 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
1808 if (myAnimator != NULL) {
1811 if ( VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule) )
1812 VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule)->Repaint();
1816 //------------------------------------------------------------------------
1817 void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
1820 myPropBtn->setEnabled(index != 0);
1823 myPlayFrame->setEnabled(false);
1826 //------------------------------------------------------------------------
1827 bool VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject)
1829 myPlayFrame->setEnabled(false);
1830 return myAnimator->addField(theSObject);
1833 //------------------------------------------------------------------------
1834 void VisuGUI_TimeAnimationDlg::createFrames()
1837 SUIT_OverrideCursor c;
1839 bool isRegenerate = mySetupDlg->isRegenerate();
1841 for (int i = 0; i < myAnimator->getNbFields(); i++) {
1842 FieldData& aFieldData = myAnimator->getFieldData(i);
1843 if( aFieldData.myPrs.empty() )
1845 //myAnimator->generatePresentations(i);
1846 GeneratePresentations(i,myAnimator);
1851 // even if aFieldData is not empty, we must regenerate presentations,
1852 // when a range or a sequence of the animation has been changed
1855 GeneratePresentations(i,myAnimator);
1857 VISU::ColoredPrs3d_i* aPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(aFieldData.myPrs[0]);
1861 myAnimator->generatePresentations(i);
1863 aFieldData = myAnimator->getFieldData(i);
1864 for (long aFrameId = 0; aFrameId < aFieldData.myNbFrames; aFrameId++) {
1865 VISU::ColoredPrs3d_i* aColoredPrs3d = aFieldData.myPrs[aFrameId];
1866 std::string aTitle = aColoredPrs3d->GetCTitle();
1867 aColoredPrs3d->SameAs(aPrs3d);
1868 if ( aFrameId != 0 && myAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE ) {
1869 aColoredPrs3d->SetTitle(aTitle.c_str());
1876 mySetupDlg->setIsRegenerate( false );
1878 if (myAnimator->getNbFrames() == 0) {
1879 myPlayFrame->setEnabled(false);
1881 SUIT_MessageBox::warning(this,
1883 tr("MSG_NO_ANIMATIONDATA"),
1887 mySlider->setMaximum(myAnimator->getNbFrames()-1);
1888 myPlayFrame->setEnabled(true);
1889 if (!myAnimator->generateFrames()) {
1891 //myPlayFrame->setEnabled(false);
1892 SUIT_MessageBox::warning(this,
1894 myAnimator->getLastErrorMsg(),
1898 //myPlayFrame->setEnabled(true);
1901 //------------------------------------------------------------------------
1902 void VisuGUI_TimeAnimationDlg::onPlayPressed()
1904 if (myPlayBtn->isChecked() && (!myAnimator->isRunning())) {
1905 myPlayBtn->setIcon(MYpausePixmap);
1906 if (mySaveCheck->isChecked()) {
1907 onPicsFormatChanged();
1910 } else if (mySaveAVICheck->isChecked()) {
1911 myAnimator->setDumpFormat("AVI");
1912 myAnimator->dumpTo(myPathAVIEdit->text().toLatin1().data());
1914 myAnimator->dumpTo("");
1916 mySetupBtn->setEnabled(false);
1917 myGenBtn->setEnabled(false);
1918 myAnimator->startAnimation();
1920 myPlayBtn->setIcon(MYplayPixmap);
1921 myAnimator->stopAnimation();
1922 mySetupBtn->setEnabled(true);
1923 myGenBtn->setEnabled(true);
1927 //------------------------------------------------------------------------
1928 void VisuGUI_TimeAnimationDlg::onBackPressed()
1931 myAnimator->prevFrame();
1934 //------------------------------------------------------------------------
1935 void VisuGUI_TimeAnimationDlg::onForvardPressed()
1938 myAnimator->nextFrame();
1941 //------------------------------------------------------------------------
1942 void VisuGUI_TimeAnimationDlg::onLastPressed()
1945 myAnimator->lastFrame();
1948 //------------------------------------------------------------------------
1949 void VisuGUI_TimeAnimationDlg::onFirstPressed()
1952 myAnimator->firstFrame();
1955 //------------------------------------------------------------------------
1956 void VisuGUI_TimeAnimationDlg::clearView()
1958 myAnimator->clearView();
1961 //------------------------------------------------------------------------
1962 void VisuGUI_TimeAnimationDlg::showEvent(QShowEvent* theEvent)
1964 mySetupDlg = new SetupDlg(this,myModule, myAnimator);
1965 mySetupDlg->initialize();
1968 //------------------------------------------------------------------------
1969 void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent)
1971 if (myAnimator != NULL) {
1972 myAnimator->stopAnimation();
1973 myAnimator->wait(500);
1974 if (myAnimator->isRunning() && (! myAnimator->isFinished())) {
1976 QCloseEvent* aNewCloseEvent = new QCloseEvent;
1977 QApplication::postEvent( this, aNewCloseEvent );
1979 QDialog::closeEvent(theEvent);
1982 QDialog::closeEvent(theEvent);
1986 //------------------------------------------------------------------------
1987 void VisuGUI_TimeAnimationDlg::onWindowChanged (int index)
1989 if (myAnimator->isRunning()) return;
1990 myAnimator->gotoFrame(index);
1993 //------------------------------------------------------------------------
1994 void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed)
1996 myAnimator->setSpeed((int)theSpeed);
1999 //------------------------------------------------------------------------
2000 void VisuGUI_TimeAnimationDlg::stopAnimation()
2002 myAnimator->stopAnimation();
2003 myPlayBtn->setChecked(false);
2004 myPlayBtn->setIcon(MYplayPixmap);
2005 mySetupBtn->setEnabled(true);
2006 myGenBtn->setEnabled(true);
2009 //------------------------------------------------------------------------
2010 void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime)
2012 myTimeLbl->setText(QString("%1").arg(theTime));
2013 mySlider->setValue(theNewFrame);
2016 //------------------------------------------------------------------------
2017 void VisuGUI_TimeAnimationDlg::onSetupDlg()
2019 if (myAnimator->getNbFrames() > 0)
2020 myAnimator->firstFrame();
2022 myPlayFrame->setEnabled(false);
2025 //------------------------------------------------------------------------
2026 void VisuGUI_TimeAnimationDlg::onBrowse()
2028 // QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/", "Select path");
2030 if (myPathEdit->text().isEmpty())
2031 aDir = getenv("HOME");
2033 aDir = myPathEdit->text();
2034 QString aPath = SUIT_FileDlg::getExistingDirectory(this, aDir, "Select path");
2035 if (!aPath.isEmpty())
2036 myPathEdit->setText(Qtx::addSlash(aPath));
2040 //------------------------------------------------------------------------
2041 void VisuGUI_TimeAnimationDlg::onBrowseAVI()
2043 QStringList aFilter;
2044 aFilter.append( "AVI Files (*.avi)" );
2045 aFilter.append( "All Files (*.*)" );
2048 if (myPathAVIEdit->text().isEmpty())
2049 aDir = getenv("HOME");
2051 QFileInfo aFile(myPathAVIEdit->text());
2052 aDir = aFile.absoluteDir().absolutePath();
2054 QString aPath = SUIT_FileDlg::getFileName(this, aDir, aFilter, "Select file", false);
2055 if (!aPath.isEmpty())
2056 myPathAVIEdit->setText(aPath);
2059 //------------------------------------------------------------------------
2060 void VisuGUI_TimeAnimationDlg::onCheckDump(bool)
2062 const QObject* source = sender();
2063 if (source == mySaveCheck) {
2064 if (mySaveCheck->isChecked()) {
2065 onPicsFormatChanged();
2067 if (mySaveAVICheck->isChecked())
2068 mySaveAVICheck->setChecked(false);
2070 myAnimator->dumpTo("");
2072 //mySaveAVICheck->setEnabled(!mySaveCheck->isChecked() && myAnimator->checkAVIMaker());
2073 mySaveAVICheck->setEnabled(!mySaveCheck->isChecked());
2075 else if (source == mySaveAVICheck) {
2076 if (mySaveAVICheck->isChecked()) {
2077 if (!myAnimator->checkAVIMaker()) {
2078 // AVI maker is not available
2079 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER"), tr("&OK"));
2080 mySaveAVICheck->setChecked(false);
2083 if (mySaveCheck->isChecked()) {
2084 mySaveCheck->setChecked(false);
2086 myPathAVILbl->setEnabled(true);
2087 myPathAVIEdit->setEnabled(true);
2088 myBrowseAVIBtn->setEnabled(true);
2092 // it is necessary in case of not available AVI maker,
2093 // because otherwise they will stay enabled
2094 // (??? slots, connected on SIGNAL(toggled(bool)) of mySaveAVICheck,
2095 // works in wrong order ???)
2096 myPathAVILbl->setEnabled(false);
2097 myPathAVIEdit->setEnabled(false);
2098 myBrowseAVIBtn->setEnabled(false);
2100 mySaveCheck->setEnabled(!mySaveAVICheck->isChecked());
2104 //------------------------------------------------------------------------
2105 void VisuGUI_TimeAnimationDlg::onStop()
2107 myPlayBtn->setChecked(false);
2108 myPlayBtn->setIcon(MYplayPixmap);
2109 mySetupBtn->setEnabled(true);
2110 myGenBtn->setEnabled(true);
2113 //------------------------------------------------------------------------
2114 void VisuGUI_TimeAnimationDlg::onHelp()
2116 QString aHelpFileName = "animating_page.html";
2117 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2119 app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
2123 platform = "winapplication";
2125 platform = "application";
2127 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
2128 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2129 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
2130 QObject::tr("BUT_OK"));
2134 //------------------------------------------------------------------------
2135 void VisuGUI_TimeAnimationDlg::saveToStudy()
2137 myAnimator->saveAnimation();
2138 VISU::UpdateObjBrowser(myModule, true);
2141 //------------------------------------------------------------------------
2142 void VisuGUI_TimeAnimationDlg::publishToStudy()
2144 myAnimator->publishInStudy();
2145 VISU::UpdateObjBrowser(myModule, true);
2146 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
2149 //------------------------------------------------------------------------
2150 void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation)
2152 myAnimator->restoreFromStudy(theAnimation);
2153 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
2154 if ( myAnimator->getAnimationMode() == VISU::Animation::SUCCESSIVE )
2155 setWindowTitle(tr("SUCCESSIVE_ANIMATION"));
2158 //------------------------------------------------------------------------
2159 void VisuGUI_TimeAnimationDlg::onPicsFormatChanged()
2161 QList<QByteArray> aDumpFormats = QImageWriter::supportedImageFormats();
2162 if (aDumpFormats.count() < 1) {
2163 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_SUPPORTED_IMAGE_FORMATS"), tr("&OK"));
2166 if (myPicsFormat->currentIndex() < 0 || aDumpFormats.count() <= myPicsFormat->currentIndex()) {
2167 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_INVALID_IMAGE_FORMAT_INDEX"), tr("&OK"));
2170 myAnimator->setDumpFormat(aDumpFormats.at(myPicsFormat->currentIndex()));
2173 //------------------------------------------------------------------------
2174 void VisuGUI_TimeAnimationDlg::onPathChanged()
2176 myAnimator->dumpTo(myPathEdit->text().toLatin1().data());
2179 //------------------------------------------------------------------------
2180 void VisuGUI_TimeAnimationDlg::keyPressEvent( QKeyEvent* e )
2182 QDialog::keyPressEvent( e );
2183 if ( e->isAccepted() )
2186 if ( e->key() == Qt::Key_F1 )