1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : VisuGUI_TimeAnimation.cxx
8 // Author : Vitaly SMETANNIKOV
11 #include "VisuGUI_TimeAnimation.h"
14 #include "VisuGUI_Tools.h"
15 #include "VisuGUI_DeformedShapeDlg.h"
16 #include "VisuGUI_CutPlanesDlg.h"
17 #include "VisuGUI_Plot3DDlg.h"
18 #include "VisuGUI_VectorsDlg.h"
19 #include "VisuGUI_IsoSurfacesDlg.h"
20 #include "VisuGUI_StreamLinesDlg.h"
22 #include "VISU_TimeAnimation.h"
24 #include "VISU_ScalarMap_i.hh"
25 #include "VISU_IsoSurfaces_i.hh"
26 #include "VISU_DeformedShape_i.hh"
27 #include "VISU_CutPlanes_i.hh"
28 #include "VISU_Plot3D_i.hh"
29 #include "VISU_CutLines_i.hh"
30 #include "VISU_Vectors_i.hh"
31 #include "VISU_StreamLines_i.hh"
33 #include "VISU_ViewManager_i.hh"
35 #include "VISU_ScalarBarActor.hxx"
36 #include "VISU_Actor.h"
38 #include "SalomeApp_Study.h"
39 #include "SalomeApp_Application.h"
41 #include "SVTK_ViewWindow.h"
43 #include "SUIT_OverrideCursor.h"
44 #include "SUIT_MessageBox.h"
45 #include "SUIT_Desktop.h"
46 #include "SUIT_FileDlg.h"
48 #include <vtkRenderer.h>
56 #include <qwt_wheel.h>
57 #include <qhgroupbox.h>
58 #include <qlcdnumber.h>
59 #include <qvgroupbox.h>
63 ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator)
64 : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
65 myAnimator(theAnimator), myViewWindow(theAnimator->getViewer())
69 QStringList aFieldNames;
70 // Find names of fields
71 for (int i = 0; i < theAnimator->getNbFields(); i++) {
72 aFieldNames.append(VISU::getValue(theAnimator->getFieldData(i).myField, "myName"));
74 aOffs.myOffset[0] = myAnimator->getFieldData(i).myOffset[0];
75 aOffs.myOffset[1] = myAnimator->getFieldData(i).myOffset[1];
76 aOffs.myOffset[2] = myAnimator->getFieldData(i).myOffset[2];
77 myOffsets.append(aOffs);
79 myFieldLst->insertStringList(aFieldNames);
80 myFieldLst->setSelected(0, true);
83 ArrangeDlg::ArrangeDlg(QWidget* theParent, SVTK_ViewWindow* theViewWindow)
84 : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize |
85 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
86 myAnimator(0), myViewWindow(theViewWindow)
90 QStringList aPrsNames;
92 vtkActorCollection *anActColl = myViewWindow->getRenderer()->GetActors();
93 for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL;) {
94 VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(anActor);
96 if (anVISUActor->GetVisibility() != 0) {
97 VISU::Prs3d_i* aPrs = anVISUActor->GetParent()->GetPrs3d();
99 if (!myPrsMap.contains(aPrs)) {
100 SALOMEDS::SObject_var aSObject = aPrs->GetSObject();
101 if(!aSObject->_is_nil()){
102 SALOMEDS::GenericAttribute_var anAttr;
103 if (aSObject->FindAttribute(anAttr, "AttributeName")) {
104 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
105 string aNam = aName->Value();
106 QString strIn(aNam.c_str());
107 aPrsNames.append(strIn);
108 myPrsMap[aPrs] = myOffsets.count();
110 anVISUActor->GetPosition(aOffs.myOffset);
111 myOffsets.append(aOffs);
118 myFieldLst->insertStringList(aPrsNames);
119 myFieldLst->setSelected(0, true);
122 void ArrangeDlg::init()
124 setCaption("Arrange Presentations");
125 setSizeGripEnabled( TRUE );
127 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
128 aMainLayout->setSpacing(5);
130 QButtonGroup* aBtnGrp = new QButtonGroup(2, Qt::Horizontal, this);
131 aBtnGrp->setExclusive(true);
132 aMainLayout->addWidget(aBtnGrp);
134 QRadioButton* aAutoBtn = new QRadioButton("Auto", aBtnGrp);
135 aBtnGrp->insert(aAutoBtn, AutoMode);
137 QRadioButton* aManualBtn = new QRadioButton("Manual", aBtnGrp);
138 aBtnGrp->insert(aManualBtn, ManualMode);
139 aBtnGrp->setButton(AutoMode);
141 myStackWgt = new QWidgetStack(this);
142 aMainLayout->addWidget(myStackWgt);
145 QVBox* aAutoPane = new QVBox(myStackWgt);
146 aAutoPane->setSpacing(5);
148 myAxisGrp = new QButtonGroup(3, Qt::Horizontal,"Axis", aAutoPane);
150 QRadioButton* aXBtn = new QRadioButton("X",myAxisGrp );
151 myAxisGrp->insert(aXBtn, XAxis);
153 QRadioButton* aYBtn = new QRadioButton("Y",myAxisGrp );
154 myAxisGrp->insert(aYBtn, YAxis);
156 QRadioButton* aZBtn = new QRadioButton("Z",myAxisGrp );
157 myAxisGrp->insert(aZBtn, ZAxis);
159 myAxisGrp->setButton(XAxis);
162 QHBox* aDistPane = new QHBox(aAutoPane);
163 aDistPane->setSpacing(5);
164 new QLabel("Relative Distance", aDistPane);
165 myDistVal = new QtxDblSpinBox (-10,10, 0.5, aDistPane);
166 myDistVal->setValue(1);
168 myStackWgt->addWidget(aAutoPane, AutoMode);
171 QHBox* aManualPane = new QHBox(myStackWgt);
172 aManualPane->setSpacing(10);
174 myFieldLst = new QListBox(aManualPane);
175 connect( myFieldLst, SIGNAL( highlighted(int) ),
176 this, SLOT( onFieldChange(int) ) );
178 QGrid* aCoordPane = new QGrid(2, aManualPane);
179 aCoordPane->setSpacing(5);
181 new QLabel("X", aCoordPane);
182 myCoord[0] = new QtxDblSpinBox(aCoordPane);
183 myCoord[0]->setRange(-MAXVAL, MAXVAL);
185 new QLabel("Y", aCoordPane);
186 myCoord[1] = new QtxDblSpinBox(aCoordPane);
187 myCoord[1]->setRange(-MAXVAL, MAXVAL);
189 new QLabel("Z", aCoordPane);
190 myCoord[2] = new QtxDblSpinBox(aCoordPane);
191 myCoord[2]->setRange(-MAXVAL, MAXVAL);
193 myStackWgt->addWidget(aManualPane, ManualMode);
195 myStackWgt->raiseWidget(AutoMode);
197 connect(aBtnGrp, SIGNAL(clicked(int)), myStackWgt, SLOT(raiseWidget(int)) );
199 SUIT_Study* aSUITStudy = myViewWindow->getViewManager()->study();
200 SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>(aSUITStudy);
201 _PTR(Study) aCStudy = VISU::GetCStudy(anAppStudy);
202 if (!myAnimator && !aCStudy->GetProperties()->IsLocked()) {
203 mySaveChk = new QCheckBox ("Save to presentation", this);
204 mySaveChk->setChecked(false);
205 aMainLayout->addWidget(mySaveChk);
210 // Common buttons ===========================================================
211 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
212 GroupButtons->setColumnLayout(0, Qt::Vertical );
213 GroupButtons->layout()->setSpacing( 0 );
214 GroupButtons->layout()->setMargin( 0 );
215 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
216 GroupButtonsLayout->setAlignment( Qt::AlignTop );
217 GroupButtonsLayout->setSpacing( 6 );
218 GroupButtonsLayout->setMargin( 11 );
220 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
221 buttonOk->setAutoDefault( TRUE );
222 buttonOk->setDefault( TRUE );
223 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
224 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
226 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
227 buttonCancel->setAutoDefault( TRUE );
228 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
230 aMainLayout->addWidget( GroupButtons );
232 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
233 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
236 void ArrangeDlg::accept()
246 void ArrangeDlg::onFieldChange(int theCurrent)
248 if (myCurrent != theCurrent) {
249 Offset& aOffs = myOffsets[myCurrent];
250 aOffs.myOffset[0] = myCoord[0]->value();
251 aOffs.myOffset[1] = myCoord[1]->value();
252 aOffs.myOffset[2] = myCoord[2]->value();
254 myCurrent = theCurrent;
255 const Offset& aNewOffs = myOffsets[myCurrent];
256 myCoord[0]->setValue(aNewOffs.myOffset[0]);
257 myCoord[1]->setValue(aNewOffs.myOffset[1]);
258 myCoord[2]->setValue(aNewOffs.myOffset[2]);
261 void ArrangeDlg::acceptAnimation()
263 if (getMode() == ManualMode) {
265 Offset& aOffs = myOffsets[myCurrent];
266 aOffs.myOffset[0] = myCoord[0]->value();
267 aOffs.myOffset[1] = myCoord[1]->value();
268 aOffs.myOffset[2] = myCoord[2]->value();
270 for (int i = 0; i < myAnimator->getNbFields(); i++) {
271 Offset aOffs = myOffsets[i];
272 myAnimator->getFieldData(i).myOffset[0] = aOffs.myOffset[0];
273 myAnimator->getFieldData(i).myOffset[1] = aOffs.myOffset[1];
274 myAnimator->getFieldData(i).myOffset[2] = aOffs.myOffset[2];
277 QApplication::setOverrideCursor( Qt::waitCursor );
278 FieldData& aData = myAnimator->getFieldData(0);
279 if (aData.myPrs.empty())
280 myAnimator->generatePresentations(0);
281 VISU_Actor* aActor = aActor = aData.myPrs[0]->CreateActor();
283 aActor->GetBounds(aBounds);
286 int aAxis = getAxis();
289 aDist = fabs(aBounds[1] - aBounds[0]);
292 aDist = fabs(aBounds[3] - aBounds[2]);
295 aDist = fabs(aBounds[5] - aBounds[4]);
298 float dx = fabs(aBounds[1] - aBounds[0]);
299 float dy = fabs(aBounds[3] - aBounds[2]);
300 float dz = fabs(aBounds[5] - aBounds[4]);
301 float max = (dx > dy) ? dx : dy;
302 max = (dz > max) ? dz : max;
306 // set base distance between centers of bounding boxes
307 // to minimal (but big enough) size of current bounding box
308 if (dx < max) dx = FLT_MAX;
309 if (dy < max) dy = FLT_MAX;
310 if (dz < max) dz = FLT_MAX;
312 aDist = (dx < dy) ? dx : dy;
313 aDist = (dz < aDist) ? dz : aDist;
315 aDist = aDist * getDistance();
316 for (int i = 0; i < myAnimator->getNbFields(); i++) {
317 myAnimator->getFieldData(i).myOffset[0] = 0;
318 myAnimator->getFieldData(i).myOffset[1] = 0;
319 myAnimator->getFieldData(i).myOffset[2] = 0;
320 myAnimator->getFieldData(i).myOffset[aAxis] = aDist * i;
323 QApplication::restoreOverrideCursor();
327 void ArrangeDlg::acceptViewWindow()
329 if (getMode() == ManualMode) {
331 Offset& aOffs = myOffsets[myCurrent];
332 aOffs.myOffset[0] = myCoord[0]->value();
333 aOffs.myOffset[1] = myCoord[1]->value();
334 aOffs.myOffset[2] = myCoord[2]->value();
336 QMap<VISU::Prs3d_i*, int>::Iterator it;
337 for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it) {
338 VISU::Prs3d_i* aPrs = it.key();
339 Offset& aOffs = myOffsets[it.data()];
340 if (VISU_Actor* anActor = VISU::GetActor(aPrs, myViewWindow)) anActor->SetPosition(aOffs.myOffset);
342 if (mySaveChk->isChecked())
343 aPrs->SetOffset(aOffs.myOffset);
349 float aPrevShift = 0;
350 // bool aInit = true;
352 QMap<VISU::Prs3d_i*, int>::Iterator it;
353 for (it = myPrsMap.begin(), i = 0; it != myPrsMap.end(); ++it, i++) {
354 VISU::Prs3d_i* aPrs = it.key();
355 if (VISU_Actor* aActor = VISU::GetActor(aPrs, myViewWindow)){
356 int aAxis = getAxis();
359 aActor->GetBounds(aBounds);
362 aDist = fabs(aBounds[1] - aBounds[0]);
365 aDist = fabs(aBounds[3] - aBounds[2]);
368 aDist = fabs(aBounds[5] - aBounds[4]);
373 aOffset[0] = aOffset[1] = aOffset[2] = 0;
376 float aCCDist = (aDist + aPrevDist) / 2.0;
378 float dx = fabs(aBounds[1] - aBounds[0]);
379 float dy = fabs(aBounds[3] - aBounds[2]);
380 float dz = fabs(aBounds[5] - aBounds[4]);
381 float max = (dx > dy) ? dx : dy;
382 max = (dz > max) ? dz : max;
386 // set base distance between centers of bounding boxes
387 // to minimal (but big enough) size of current bounding box
388 if (dx < max) dx = FLT_MAX;
389 if (dy < max) dy = FLT_MAX;
390 if (dz < max) dz = FLT_MAX;
392 aCCDist = (dx < dy) ? dx : dy;
393 aCCDist = (dz < aCCDist) ? dz : aCCDist;
396 //-------------------------------->
400 // .--------------. .------.
401 //----------->| | | |
402 // aPrevShift '--------------' '------'
407 // (aDist + aPrevDist) * getDistance() / 2
409 aShift = aPrevShift + aPrevDist/2.0 + aCCDist*getDistance() - aDist/2.0;
412 aOffset[aAxis] = aShift;
413 aActor->SetPosition(aOffset);
415 if (mySaveChk->isChecked())
416 aPrs->SetOffset(aOffset);
423 myViewWindow->getRenderer()->ResetCameraClippingRange();
424 myViewWindow->Repaint();
428 //*****************************************************************************************************
429 //*****************************************************************************************************
430 //*****************************************************************************************************
431 SetupDlg::SetupDlg (VisuGUI* theModule, VISU_TimeAnimation* theAnimator)
432 : QDialog(VISU::GetDesktop(theModule), "SetupDlg", true, WStyle_Customize |
433 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
436 setCaption("Setup Animation");
437 setSizeGripEnabled( TRUE );
438 myAnimator = theAnimator;
440 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
441 aMainLayout->setSpacing(5);
444 QFrame* aRangeGrp = new QFrame(this);
445 QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp );
446 aRangeLayout->setSpacing( 6 );
447 aRangeLayout->setMargin( 11 );
448 aRangeGrp->setFrameStyle(QFrame::Box | QFrame::Raised);
450 myUseRangeChk = new QCheckBox("Use range of time stamps", aRangeGrp);
451 aRangeLayout->addMultiCellWidget(myUseRangeChk, 0, 0, 0, 3);
452 myUseRangeChk->setChecked(myAnimator->isRangeDefined());
454 QLabel* aMinLbl = new QLabel("From", aRangeGrp);
455 aMinLbl->setEnabled(myUseRangeChk->isChecked());
456 aRangeLayout->addWidget(aMinLbl, 1, 0);
457 double aStep = (myAnimator->getMaxTime() - myAnimator->getMinTime())/(theAnimator->getFieldData(0).myNbTimes - 1);
458 myMinVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
459 myMinVal->setEnabled(myUseRangeChk->isChecked());
460 if (myUseRangeChk->isChecked())
461 myMinVal->setValue( myAnimator->getMinRange() );
463 myMinVal->setValue( myAnimator->getMinTime() );
465 connect(myMinVal, SIGNAL( valueChanged(double)),
466 this, SLOT( onMinValue(double) ));
467 aRangeLayout->addWidget(myMinVal, 1, 1);
469 QLabel* aMaxLbl = new QLabel("To", aRangeGrp);
470 aMaxLbl->setEnabled(myUseRangeChk->isChecked());
471 aRangeLayout->addWidget(aMaxLbl, 1, 2);
472 myMaxVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
473 myMaxVal->setEnabled(myUseRangeChk->isChecked());
474 if (myUseRangeChk->isChecked())
475 myMaxVal->setValue( myAnimator->getMaxRange() );
477 myMaxVal->setValue( myAnimator->getMaxTime() );
479 connect(myMaxVal, SIGNAL( valueChanged(double)),
480 this, SLOT( onMaxValue(double) ));
481 aRangeLayout->addWidget(myMaxVal, 1, 3);
483 connect(myUseRangeChk, SIGNAL( toggled(bool)),
484 aMinLbl, SLOT( setEnabled(bool) ));
485 connect(myUseRangeChk, SIGNAL( toggled(bool)),
486 aMaxLbl, SLOT( setEnabled(bool) ));
487 connect(myUseRangeChk, SIGNAL( toggled(bool)),
488 this, SLOT( onRangeCheck(bool) ));
490 aMainLayout->addWidget(aRangeGrp);
493 QHBox* aPropFrame = new QHBox(this);
494 aPropFrame->setSpacing(5);
496 QVGroupBox* aNamesBox = new QVGroupBox("Fields",aPropFrame);
497 myFieldLst = new QListBox(aNamesBox);
498 QStringList aFieldNames;
499 // Find names of fields
500 for (int i = 0; i < theAnimator->getNbFields(); i++) {
501 _PTR(SObject) aSO = theAnimator->getFieldData(i).myField;
502 aFieldNames.append(VISU::getValue(aSO, "myName"));
504 myFieldLst->insertStringList(aFieldNames);
505 myFieldLst->setSelected(0, true);
506 connect( myFieldLst, SIGNAL( highlighted(int) ),
507 this, SLOT( onFieldChange(int) ) );
510 QVBox* aSetupBox = new QVBox(aPropFrame);
511 aSetupBox->setSpacing(5);
513 QVGroupBox* aPropBox = new QVGroupBox("Properties", aSetupBox);
514 //QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame);
515 myTypeCombo = new QComboBox(aPropBox);
516 connect( myTypeCombo, SIGNAL( activated(int) ),
517 this, SLOT( onTypeChanged(int) ) );
519 // QPushButton* aBarBtn = new QPushButton("Scalar Bar...", aPropBox);
520 //connect( aBarBtn, SIGNAL( clicked() ),
521 // this, SLOT( onScalarBarDlg() ) );
523 myPropBtn = new QPushButton("Properties...", aPropBox);
524 // myPropBtn->setEnabled(theAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
525 connect( myPropBtn, SIGNAL( clicked() ),
526 this, SLOT( onPreferencesDlg() ) );
528 if (myAnimator->getNbFields() > 1) {
529 myArrangeBtn = new QPushButton("Arrange...", aSetupBox);
530 connect( myArrangeBtn, SIGNAL( clicked() ), this, SLOT( onArrangeDlg() ) );
533 aMainLayout->addWidget(aPropFrame);
535 QHBox* aBtnBox = new QHBox(this);
536 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
537 aBtnLayout->addStretch();
539 QPushButton* aCloseBtn = new QPushButton(tr("BUT_OK"), aBtnBox);
540 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
542 aMainLayout->addWidget(aBtnBox);
545 //************************************************************************
547 TSCALARMAP_ITEM = 0, // VISU::TSCALARMAP
548 TISOSURFACE_ITEM = 1, // VISU::TISOSURFACE
549 TCUTPLANES_ITEM = 2, // VISU::TCUTPLANES
550 TPLOT3D_ITEM = 3, // VISU::TPLOT3D
551 TDEFORMEDSHAPE_ITEM = 4, // VISU::TDEFORMEDSHAPE
552 TVECTORS_ITEM = 5, // VISU::TVECTORS
553 TSTREAMLINES_ITEM = 6 // VISU::TSTREAMLINES
556 //************************************************************************
557 void SetupDlg::onFieldChange (int theIndex)
559 FieldData& aData = myAnimator->getFieldData(theIndex);
560 myTypeCombo->clear();
561 // ATTENTION: append items in the same order like it is done in the PrsComboItem enumeration
562 myTypeCombo->insertItem("Scalar Map"); // item 0
563 myTypeCombo->insertItem("Iso Surfaces"); // item 1
564 myTypeCombo->insertItem("Cut Planes"); // item 2
565 myTypeCombo->insertItem("Plot 3D"); // item 3
567 _PTR(SObject) aSObject = aData.myField;
568 long aNumComp = VISU::getValue(aSObject, "myNumComponent").toLong();
570 myTypeCombo->insertItem("Deformed Shape"); // item 4
571 myTypeCombo->insertItem("Vectors"); // item 5
572 myTypeCombo->insertItem("Stream Lines"); // item 6
574 switch (aData.myPrsType) {
575 case VISU::TSCALARMAP: //Scalar Map
576 myTypeCombo->setCurrentItem(TSCALARMAP_ITEM);
578 case VISU::TISOSURFACE: //Iso Surfaces
579 myTypeCombo->setCurrentItem(TISOSURFACE_ITEM);
581 case VISU::TCUTPLANES: //Cut Planes
582 myTypeCombo->setCurrentItem(TCUTPLANES_ITEM);
584 case VISU::TPLOT3D: //Plot 3D
585 myTypeCombo->setCurrentItem(TPLOT3D_ITEM);
587 case VISU::TDEFORMEDSHAPE: //Deformed Shape
588 myTypeCombo->setCurrentItem(TDEFORMEDSHAPE_ITEM);
590 case VISU::TVECTORS: //Vectors
591 myTypeCombo->setCurrentItem(TVECTORS_ITEM);
593 case VISU::TSTREAMLINES: //Stream Lines
594 myTypeCombo->setCurrentItem(TSTREAMLINES_ITEM);
595 aData.myPrsType = VISU::TSTREAMLINES;
598 //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
601 //************************************************************************
602 void SetupDlg::onTypeChanged (int theIndex)
604 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
606 case TSCALARMAP_ITEM: //Scalar Map
607 aData.myPrsType = VISU::TSCALARMAP;
609 case TISOSURFACE_ITEM: //Iso Surfaces
610 aData.myPrsType = VISU::TISOSURFACE;
612 case TCUTPLANES_ITEM: //Cut Planes
613 aData.myPrsType = VISU::TCUTPLANES;
615 case TPLOT3D_ITEM: //Plot 3D
616 aData.myPrsType = VISU::TPLOT3D;
618 case TDEFORMEDSHAPE_ITEM: //Deformed Shape
619 aData.myPrsType = VISU::TDEFORMEDSHAPE;
621 case TVECTORS_ITEM: //Vectors
622 aData.myPrsType = VISU::TVECTORS;
624 case TSTREAMLINES_ITEM: //Stream Lines
625 aData.myPrsType = VISU::TSTREAMLINES;
628 myAnimator->clearData(aData);
629 //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
630 //myAnimator->generatePresentations(myFieldLst->currentItem());
633 //************************************************************************
634 /*void SetupDlg::onScalarBarDlg() {
635 QApplication::setOverrideCursor( Qt::waitCursor );
636 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
637 if (aData.myPrs == 0)
638 myAnimator->generatePresentations(myFieldLst->currentItem());
639 QApplication::restoreOverrideCursor();
641 VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg();
642 aScalarBarDlg->initFromPrsObject(aData.myPrs[0]);
643 if (aScalarBarDlg->exec()) {
644 for (int i = 0; i < aData.myNbFrames; i++)
645 aScalarBarDlg->storeToPrsObject(aData.myPrs[i]);
650 //************************************************************************
651 void SetupDlg::onPreferencesDlg()
653 SUIT_OverrideCursor c;
654 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
655 if (aData.myPrs.empty())
656 myAnimator->generatePresentations(myFieldLst->currentItem());
658 // BUG VISU5725 : Compatibility gcc 2.95
659 // #define EDITPRS(TYPE, DLG) \
661 // DLG* aDlg = new DLG(); \
662 // aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(0))); \
663 // if (aDlg->exec()) { \
664 // for (int i = 0; i < aData.myNbFrames; i++) \
665 // aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(i))); \
671 #define EDITPRS(TYPE, DLG) {\
672 DLG* aDlg = new DLG (myModule);\
673 aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs[0]));\
676 for (int i = 0; i < aData.myNbFrames; i++)\
677 aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs[i]));\
681 switch (myTypeCombo->currentItem()) {
682 case TSCALARMAP_ITEM: //Scalar Map
684 EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
686 case TISOSURFACE_ITEM: //Iso Surfaces
688 EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
690 case TCUTPLANES_ITEM: //Cut Planes
692 EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
694 VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg (myModule);
695 //_CS_PhB :operator [] .at aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(0)));
696 aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[0]));
699 for (int i = 0; i < aData.myNbFrames; i++)
700 //_CS_PhB:operator [] .at aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(i)));
701 aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[i]));
706 case TPLOT3D_ITEM: //Plot 3D
708 EDITPRS(VISU::Plot3D_i, VisuGUI_Plot3DDlg);
710 case TDEFORMEDSHAPE_ITEM: //Deformed Shape
712 EDITPRS(VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg);
714 case TVECTORS_ITEM: //Vectors
716 EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg);
718 case TSTREAMLINES_ITEM: //Stream Lines
720 EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
727 //************************************************************************
728 void SetupDlg::onArrangeDlg()
730 ArrangeDlg aDlg(this, myAnimator);
734 //************************************************************************
735 void SetupDlg::onRangeCheck (bool theCheck)
737 for (int i = 0; i < myAnimator->getNbFields(); i++)
738 myAnimator->clearData(myAnimator->getFieldData(i));
740 myMinVal->setEnabled(theCheck);
741 myMaxVal->setEnabled(theCheck);
744 myAnimator->setAnimationRange(0, 0);
746 // if (myMinVal->value() < myMaxVal->value())
747 myAnimator->setAnimationRange(myMinVal->value(), myMaxVal->value());
748 // else if (myMinVal->value() > myMaxVal->value())
749 // myAnimator->setAnimationRange(myMaxVal->value(), myMinVal->value());
750 // else // equal case
751 // myAnimator->setAnimationRange(0, 0);
755 //************************************************************************
756 void SetupDlg::onMinValue (double theVal)
758 if (theVal > myAnimator->getMaxRange()) {
759 myMinVal->setValue( myAnimator->getMinTime() );
760 myMinVal->setFocus();
763 for (int i = 0; i < myAnimator->getNbFields(); i++)
764 myAnimator->clearData(myAnimator->getFieldData(i));
765 myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange());
768 //************************************************************************
769 void SetupDlg::onMaxValue (double theVal)
771 if (theVal < myAnimator->getMinRange()) {
772 myMaxVal->setValue( myAnimator->getMaxTime() );
773 myMaxVal->setFocus();
776 for (int i = 0; i < myAnimator->getNbFields(); i++)
777 myAnimator->clearData(myAnimator->getFieldData(i));
778 myAnimator->setAnimationRange(myAnimator->getMinRange(), theVal);
781 static const char * firstIco[] = {
797 static const char * lastIco[] = {
813 static const char * leftIco[] = {
828 static const char * playIco[] = {
847 static QPixmap MYplayPixmap(playIco);
850 static const char * rightIco[] = {
866 static const char * pauseIco[] = {
885 static QPixmap MYpausePixmap(pauseIco);
888 VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy)
889 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
890 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
894 setCaption("Animation");
895 setSizeGripEnabled( TRUE );
898 myAnimator = new VISU_TimeAnimation (theStudy);
899 myAnimator->setSpeed(1);
900 myAnimator->setViewer(VISU::GetViewWindow());
901 connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double)));
902 connect(myAnimator, SIGNAL(stopped()), this, SLOT(onStop()));
904 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
905 aMainLayout->setSpacing(5);
907 mySetupBtn = new QPushButton("Setup Animation...", this);
908 connect( mySetupBtn, SIGNAL( clicked() ),
909 this, SLOT( onSetupDlg() ) );
910 aMainLayout->addWidget(mySetupBtn);
912 myGenBtn = new QPushButton("Generate frames", this);
913 connect( myGenBtn, SIGNAL( clicked() ),
914 this, SLOT( createFrames() ) );
915 aMainLayout->addWidget(myGenBtn);
917 myPlayFrame = new QFrame(this);
918 myPlayFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
919 myPlayFrame->setLineWidth( 1 );
922 // --- Play controls ---
923 QGridLayout* TopLayout = new QGridLayout( myPlayFrame );
924 TopLayout->setSpacing( 6 );
925 TopLayout->setMargin( 11 );
927 myTimeLbl = new QLabel("0", myPlayFrame);
928 TopLayout->addMultiCellWidget(myTimeLbl, 0, 0, 0, 2, Qt::AlignHCenter);
930 mySlider = new QSlider(Qt::Horizontal, myPlayFrame);
931 mySlider->setMinValue(0);
932 mySlider->setMaxValue(3);
933 mySlider->setTickInterval(1);
934 //mySlider->setTickmarks(QSlider::Below);
935 mySlider->setTracking(false);
936 connect( mySlider, SIGNAL( valueChanged(int) ),
937 this, SLOT( onWindowChanged(int) ) );
938 TopLayout->addMultiCellWidget(mySlider, 1, 1, 0, 2);
940 myPlayBtn = new QToolButton(myPlayFrame);
941 myPlayBtn->setIconSet(MYplayPixmap);
942 myPlayBtn->setToggleButton(true);
943 connect( myPlayBtn, SIGNAL( clicked() ),
944 this, SLOT( onPlayPressed() ) );
945 TopLayout->addMultiCellWidget(myPlayBtn, 2, 2, 0, 1);
947 QToolButton* aBackBtn = new QToolButton(myPlayFrame);
948 aBackBtn->setIconSet(QPixmap(leftIco));
949 connect( aBackBtn, SIGNAL( clicked() ),
950 this, SLOT( onBackPressed() ) );
951 TopLayout->addWidget(aBackBtn, 3, 0);
953 QToolButton* aForvardBtn = new QToolButton(myPlayFrame);
954 aForvardBtn->setIconSet(QPixmap(rightIco));
955 connect( aForvardBtn, SIGNAL( clicked() ),
956 this, SLOT( onForvardPressed() ) );
957 TopLayout->addWidget(aForvardBtn, 3, 1);
959 QToolButton* aFirstBtn = new QToolButton(myPlayFrame);
960 aFirstBtn->setIconSet(QPixmap(firstIco));
961 connect( aFirstBtn, SIGNAL( clicked() ),
962 this, SLOT( onFirstPressed() ) );
963 TopLayout->addWidget(aFirstBtn, 4, 0);
965 QToolButton* aLastBtn = new QToolButton(myPlayFrame);
966 aLastBtn->setIconSet(QPixmap(lastIco));
967 connect( aLastBtn, SIGNAL( clicked() ),
968 this, SLOT( onLastPressed() ) );
969 TopLayout->addWidget(aLastBtn, 4, 1);
971 QLabel* aSpeedLbl = new QLabel("Speed", myPlayFrame);
972 TopLayout->addWidget(aSpeedLbl, 4, 2, Qt::AlignRight);
974 QLCDNumber* aSpeedNum = new QLCDNumber( 2, myPlayFrame );
975 aSpeedNum->setSegmentStyle(QLCDNumber::Flat);
976 aSpeedNum->display(1);
977 TopLayout->addWidget(aSpeedNum, 4, 3);
979 QwtWheel* aWheel = new QwtWheel(myPlayFrame);
980 aWheel->setOrientation(Qt::Vertical);
981 aWheel->setRange(1, 99, 1);
982 connect( aWheel, SIGNAL(valueChanged(double)),
983 aSpeedNum, SLOT(display(double)) );
984 connect( aWheel, SIGNAL(valueChanged(double)),
985 this, SLOT(onSpeedChange(double)) );
986 TopLayout->addMultiCellWidget(aWheel, 1, 3, 3, 3, Qt::AlignRight);
988 QCheckBox* aCycleCheck = new QCheckBox("Cycled animation",myPlayFrame);
989 aCycleCheck->setChecked(myAnimator->isCycling());
990 connect(aCycleCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCyclingSlot(bool)));
991 TopLayout->addMultiCellWidget(aCycleCheck, 5, 5, 0, 3);
993 QCheckBox* aPropCheck = new QCheckBox("Use proportional timing",myPlayFrame);
994 aPropCheck->setChecked(myAnimator->isProportional());
995 connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool)));
996 TopLayout->addMultiCellWidget(aPropCheck, 6, 6, 0, 3);
998 QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame );
999 aSaveBox->setColumnLayout(0, Qt::Horizontal );
1000 QGridLayout* aSaveLay = new QGridLayout(aSaveBox->layout());
1001 aSaveLay->setSpacing( 5 );
1002 aSaveLay->setMargin( 5 );
1004 mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox);
1005 aSaveLay->addMultiCellWidget(mySaveCheck, 0, 0, 0, 2);
1006 connect(mySaveCheck, SIGNAL( toggled(bool)),
1007 aWheel, SLOT( setDisabled(bool) ));
1009 QLabel* aPathLbl = new QLabel("Path:", aSaveBox);
1010 aPathLbl->setEnabled(false);
1011 connect(mySaveCheck, SIGNAL( toggled(bool)),
1012 aPathLbl, SLOT( setEnabled(bool) ));
1013 aSaveLay->addWidget(aPathLbl, 1, 0);
1015 myPathEdit = new QLineEdit(aSaveBox);
1016 myPathEdit->setEnabled(false);
1017 connect(mySaveCheck, SIGNAL( toggled(bool)),
1018 myPathEdit, SLOT( setEnabled(bool) ));
1019 aSaveLay->addWidget(myPathEdit, 1, 1);
1021 QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox);
1022 aBrowseBtn->setEnabled(false);
1023 connect(mySaveCheck, SIGNAL( toggled(bool)),
1024 aBrowseBtn, SLOT( setEnabled(bool) ));
1025 connect(aBrowseBtn, SIGNAL( clicked()),
1026 this, SLOT( onBrowse() ));
1027 mySaveCheck->setChecked(false);
1028 aSaveLay->addWidget(aBrowseBtn, 1, 2);
1030 TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3);
1032 aMainLayout->addWidget(myPlayFrame);
1034 QHBox* aPublishBox = new QHBox(this);
1035 aPublishBox->setSpacing(5);
1037 myPublishBtn = new QPushButton("Publish to study", aPublishBox);
1038 connect(myPublishBtn, SIGNAL(clicked()), this, SLOT(publishToStudy()));
1040 mySaveBtn = new QPushButton("Save Animation", aPublishBox);
1041 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1042 connect(mySaveBtn, SIGNAL(clicked()), this, SLOT(saveToStudy()));
1044 aMainLayout->addWidget(aPublishBox);
1047 QHBox* aBtnBox = new QHBox(this);
1048 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
1049 aBtnLayout->addStretch();
1051 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
1052 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
1054 SUIT_Study* aStudy = VISU::GetAppStudy(myModule);
1055 connect(aStudy, SIGNAL(destroyed()), this, SLOT(close()));
1057 aMainLayout->addWidget(aBtnBox);
1059 myPlayFrame->setEnabled(false);
1062 //************************************************************************
1063 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
1068 //************************************************************************
1069 void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
1072 myPropBtn->setEnabled(index != 0);
1075 myPlayFrame->setEnabled(false);
1078 //************************************************************************
1079 void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject)
1081 myPlayFrame->setEnabled(false);
1082 myAnimator->addField(VISU::GetSObject(theSObject));
1085 //************************************************************************
1086 void VisuGUI_TimeAnimationDlg::createFrames()
1089 SUIT_OverrideCursor c;
1091 for (int i = 0; i < myAnimator->getNbFields(); i++) {
1092 if (myAnimator->getFieldData(i).myPrs.empty())
1093 myAnimator->generatePresentations(i);
1095 if (myAnimator->getNbFrames() == 0) {
1096 myPlayFrame->setEnabled(false);
1098 SUIT_MessageBox::warn1(this,
1100 tr("MSG_NO_ANIMATIONDATA"),
1104 mySlider->setMaxValue(myAnimator->getNbFrames()-1);
1105 myPlayFrame->setEnabled(true);
1106 if (!myAnimator->generateFrames()) {
1108 //myPlayFrame->setEnabled(false);
1109 SUIT_MessageBox::warn1(this,
1111 myAnimator->getLastErrorMsg(),
1115 //myPlayFrame->setEnabled(true);
1118 //************************************************************************
1119 void VisuGUI_TimeAnimationDlg::onPlayPressed()
1121 if (myPlayBtn->isOn() && (!myAnimator->running())) {
1122 myPlayBtn->setIconSet(MYpausePixmap);
1123 if (mySaveCheck->isChecked())
1124 myAnimator->dumpTo(myPathEdit->text());
1126 myAnimator->dumpTo("");
1127 mySetupBtn->setEnabled(false);
1128 myGenBtn->setEnabled(false);
1129 myAnimator->startAnimation();
1131 myPlayBtn->setIconSet(MYplayPixmap);
1132 myAnimator->stopAnimation();
1133 mySetupBtn->setEnabled(true);
1134 myGenBtn->setEnabled(true);
1138 //************************************************************************
1139 void VisuGUI_TimeAnimationDlg::onBackPressed()
1142 myAnimator->prevFrame();
1145 //************************************************************************
1146 void VisuGUI_TimeAnimationDlg::onForvardPressed()
1148 myAnimator->nextFrame();
1151 //************************************************************************
1152 void VisuGUI_TimeAnimationDlg::onLastPressed()
1154 myAnimator->lastFrame();
1157 //************************************************************************
1158 void VisuGUI_TimeAnimationDlg::onFirstPressed()
1160 myAnimator->firstFrame();
1163 //************************************************************************
1164 void VisuGUI_TimeAnimationDlg::clearView()
1166 myAnimator->clearView();
1169 //************************************************************************
1170 void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent)
1172 myAnimator->stopAnimation();
1173 myAnimator->wait(500);
1174 if (myAnimator->running() && (! myAnimator->finished())) {
1178 QDialog::closeEvent(theEvent);
1182 //************************************************************************
1183 void VisuGUI_TimeAnimationDlg::onWindowChanged (int index)
1185 if (myAnimator->isRunning()) return;
1186 myAnimator->gotoFrame(index);
1189 //************************************************************************
1190 void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed)
1192 myAnimator->setSpeed((int)theSpeed);
1195 //************************************************************************
1196 void VisuGUI_TimeAnimationDlg::stopAnimation()
1198 myAnimator->stopAnimation();
1199 myPlayBtn->setOn(false);
1200 myPlayBtn->setIconSet(MYplayPixmap);
1201 mySetupBtn->setEnabled(true);
1202 myGenBtn->setEnabled(true);
1205 //************************************************************************
1206 void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime)
1208 myTimeLbl->setText(QString("%1").arg(theTime));
1209 mySlider->setValue(theNewFrame);
1212 //************************************************************************
1213 void VisuGUI_TimeAnimationDlg::onSetupDlg()
1215 if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame();
1216 SetupDlg* aDlg = new SetupDlg (myModule, myAnimator);
1218 myPlayFrame->setEnabled(false);
1222 //************************************************************************
1223 void VisuGUI_TimeAnimationDlg::onBrowse()
1225 QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/","Select path");
1226 if (!aPath.isEmpty())
1227 myPathEdit->setText(aPath);
1230 //************************************************************************
1231 void VisuGUI_TimeAnimationDlg::onStop()
1234 QDialog::closeEvent(myEvent);
1236 myPlayBtn->setOn(false);
1237 myPlayBtn->setIconSet(MYplayPixmap);
1238 mySetupBtn->setEnabled(true);
1239 myGenBtn->setEnabled(true);
1243 //************************************************************************
1244 void VisuGUI_TimeAnimationDlg::saveToStudy()
1246 myAnimator->saveAnimation();
1247 myModule->updateObjBrowser( true );
1250 //************************************************************************
1251 void VisuGUI_TimeAnimationDlg::publishToStudy()
1253 myAnimator->publishInStudy();
1254 myModule->updateObjBrowser( true );
1255 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1258 //************************************************************************
1259 void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation)
1261 myAnimator->restoreFromStudy(theAnimation);
1262 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());