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_VectorsDlg.h"
18 #include "VisuGUI_IsoSurfacesDlg.h"
19 #include "VisuGUI_StreamLinesDlg.h"
21 #include "VISU_TimeAnimation.h"
23 #include "VISU_ScalarMap_i.hh"
24 #include "VISU_IsoSurfaces_i.hh"
25 #include "VISU_DeformedShape_i.hh"
26 #include "VISU_CutPlanes_i.hh"
27 #include "VISU_CutLines_i.hh"
28 #include "VISU_Vectors_i.hh"
29 #include "VISU_StreamLines_i.hh"
31 #include "VISU_ViewManager_i.hh"
33 #include "VISU_ScalarBarActor.hxx"
34 #include "VISU_Actor.h"
36 #include "SalomeApp_Study.h"
37 #include "SalomeApp_Application.h"
39 #include "SVTK_ViewWindow.h"
41 #include "SUIT_OverrideCursor.h"
42 #include "SUIT_MessageBox.h"
43 #include "SUIT_Desktop.h"
44 #include "SUIT_FileDlg.h"
46 #include <vtkRenderer.h>
54 #include <qwt_wheel.h>
55 #include <qhgroupbox.h>
56 #include <qlcdnumber.h>
57 #include <qvgroupbox.h>
62 ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator)
63 : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
64 myAnimator(theAnimator), myViewWindow(theAnimator->getViewer())
68 QStringList aFieldNames;
69 // Find names of fields
70 for (int i = 0; i < theAnimator->getNbFields(); i++) {
71 aFieldNames.append(VISU::getValue(theAnimator->getFieldData(i).myField, "myName"));
73 aOffs.myOffset[0] = myAnimator->getFieldData(i).myOffset[0];
74 aOffs.myOffset[1] = myAnimator->getFieldData(i).myOffset[1];
75 aOffs.myOffset[2] = myAnimator->getFieldData(i).myOffset[2];
76 myOffsets.append(aOffs);
78 myFieldLst->insertStringList(aFieldNames);
79 myFieldLst->setSelected(0, true);
82 ArrangeDlg::ArrangeDlg(QWidget* theParent, SVTK_ViewWindow* theViewWindow)
83 : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize |
84 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
85 myAnimator(0), myViewWindow(theViewWindow)
89 QStringList aPrsNames;
91 vtkActorCollection *anActColl = myViewWindow->getRenderer()->GetActors();
92 for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL;) {
93 VISU_Actor* anVISUActor = dynamic_cast<VISU_Actor*>(anActor);
95 if (anVISUActor->GetVisibility() != 0) {
96 VISU::Prs3d_i* aPrs = anVISUActor->GetParent()->GetPrs3d();
98 if (!myPrsMap.contains(aPrs)) {
99 SALOMEDS::SObject_var aSObject = aPrs->GetSObject();
100 if(!aSObject->_is_nil()){
101 SALOMEDS::GenericAttribute_var anAttr;
102 if (aSObject->FindAttribute(anAttr, "AttributeName")) {
103 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
104 string aNam = aName->Value();
105 QString strIn(aNam.c_str());
106 aPrsNames.append(strIn);
107 myPrsMap[aPrs] = myOffsets.count();
109 anVISUActor->GetPosition(aOffs.myOffset);
110 myOffsets.append(aOffs);
117 myFieldLst->insertStringList(aPrsNames);
118 myFieldLst->setSelected(0, true);
121 void ArrangeDlg::init()
123 setCaption("Arrange Presentations");
124 setSizeGripEnabled( TRUE );
126 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
127 aMainLayout->setSpacing(5);
129 QButtonGroup* aBtnGrp = new QButtonGroup(2, Qt::Horizontal, this);
130 aBtnGrp->setExclusive(true);
131 aMainLayout->addWidget(aBtnGrp);
133 QRadioButton* aAutoBtn = new QRadioButton("Auto", aBtnGrp);
134 aBtnGrp->insert(aAutoBtn, AutoMode);
136 QRadioButton* aManualBtn = new QRadioButton("Manual", aBtnGrp);
137 aBtnGrp->insert(aManualBtn, ManualMode);
138 aBtnGrp->setButton(AutoMode);
140 myStackWgt = new QWidgetStack(this);
141 aMainLayout->addWidget(myStackWgt);
144 QVBox* aAutoPane = new QVBox(myStackWgt);
145 aAutoPane->setSpacing(5);
147 myAxisGrp = new QButtonGroup(3, Qt::Horizontal,"Axis", aAutoPane);
149 QRadioButton* aXBtn = new QRadioButton("X",myAxisGrp );
150 myAxisGrp->insert(aXBtn, XAxis);
152 QRadioButton* aYBtn = new QRadioButton("Y",myAxisGrp );
153 myAxisGrp->insert(aYBtn, YAxis);
155 QRadioButton* aZBtn = new QRadioButton("Z",myAxisGrp );
156 myAxisGrp->insert(aZBtn, ZAxis);
158 myAxisGrp->setButton(XAxis);
161 QHBox* aDistPane = new QHBox(aAutoPane);
162 aDistPane->setSpacing(5);
163 new QLabel("Relative Distance", aDistPane);
164 myDistVal = new QtxDblSpinBox (-10,10, 0.5, aDistPane);
165 myDistVal->setValue(1);
167 myStackWgt->addWidget(aAutoPane, AutoMode);
170 QHBox* aManualPane = new QHBox(myStackWgt);
171 aManualPane->setSpacing(10);
173 myFieldLst = new QListBox(aManualPane);
174 connect( myFieldLst, SIGNAL( highlighted(int) ),
175 this, SLOT( onFieldChange(int) ) );
177 QGrid* aCoordPane = new QGrid(2, aManualPane);
178 aCoordPane->setSpacing(5);
180 new QLabel("X", aCoordPane);
181 myCoord[0] = new QtxDblSpinBox(aCoordPane);
182 myCoord[0]->setRange(-MAXVAL, MAXVAL);
184 new QLabel("Y", aCoordPane);
185 myCoord[1] = new QtxDblSpinBox(aCoordPane);
186 myCoord[1]->setRange(-MAXVAL, MAXVAL);
188 new QLabel("Z", aCoordPane);
189 myCoord[2] = new QtxDblSpinBox(aCoordPane);
190 myCoord[2]->setRange(-MAXVAL, MAXVAL);
192 myStackWgt->addWidget(aManualPane, ManualMode);
194 myStackWgt->raiseWidget(AutoMode);
196 connect(aBtnGrp, SIGNAL(clicked(int)), myStackWgt, SLOT(raiseWidget(int)) );
198 SUIT_Study* aSUITStudy = myViewWindow->getViewManager()->study();
199 SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>(aSUITStudy);
200 _PTR(Study) aCStudy = VISU::GetCStudy(anAppStudy);
201 if (!myAnimator && !aCStudy->GetProperties()->IsLocked()) {
202 mySaveChk = new QCheckBox ("Save to presentation", this);
203 mySaveChk->setChecked(false);
204 aMainLayout->addWidget(mySaveChk);
209 // Common buttons ===========================================================
210 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
211 GroupButtons->setColumnLayout(0, Qt::Vertical );
212 GroupButtons->layout()->setSpacing( 0 );
213 GroupButtons->layout()->setMargin( 0 );
214 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
215 GroupButtonsLayout->setAlignment( Qt::AlignTop );
216 GroupButtonsLayout->setSpacing( 6 );
217 GroupButtonsLayout->setMargin( 11 );
219 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
220 buttonOk->setAutoDefault( TRUE );
221 buttonOk->setDefault( TRUE );
222 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
223 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
225 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
226 buttonCancel->setAutoDefault( TRUE );
227 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
229 aMainLayout->addWidget( GroupButtons );
231 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
232 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
235 void ArrangeDlg::accept()
245 void ArrangeDlg::onFieldChange(int theCurrent)
247 if (myCurrent != theCurrent) {
248 Offset& aOffs = myOffsets[myCurrent];
249 aOffs.myOffset[0] = myCoord[0]->value();
250 aOffs.myOffset[1] = myCoord[1]->value();
251 aOffs.myOffset[2] = myCoord[2]->value();
253 myCurrent = theCurrent;
254 const Offset& aNewOffs = myOffsets[myCurrent];
255 myCoord[0]->setValue(aNewOffs.myOffset[0]);
256 myCoord[1]->setValue(aNewOffs.myOffset[1]);
257 myCoord[2]->setValue(aNewOffs.myOffset[2]);
260 void ArrangeDlg::acceptAnimation()
262 if (getMode() == ManualMode) {
264 Offset& aOffs = myOffsets[myCurrent];
265 aOffs.myOffset[0] = myCoord[0]->value();
266 aOffs.myOffset[1] = myCoord[1]->value();
267 aOffs.myOffset[2] = myCoord[2]->value();
269 for (int i = 0; i < myAnimator->getNbFields(); i++) {
270 Offset aOffs = myOffsets[i];
271 myAnimator->getFieldData(i).myOffset[0] = aOffs.myOffset[0];
272 myAnimator->getFieldData(i).myOffset[1] = aOffs.myOffset[1];
273 myAnimator->getFieldData(i).myOffset[2] = aOffs.myOffset[2];
276 QApplication::setOverrideCursor( Qt::waitCursor );
277 FieldData& aData = myAnimator->getFieldData(0);
278 if (aData.myPrs.empty())
279 myAnimator->generatePresentations(0);
280 VISU_Actor* aActor = aActor = aData.myPrs[0]->CreateActor();
282 aActor->GetBounds(aBounds);
285 int aAxis = getAxis();
288 aDist = fabs(aBounds[1] - aBounds[0]);
291 aDist = fabs(aBounds[3] - aBounds[2]);
294 aDist = fabs(aBounds[5] - aBounds[4]);
296 aDist = aDist*getDistance();
297 for (int i = 0; i < myAnimator->getNbFields(); i++) {
298 myAnimator->getFieldData(i).myOffset[0] = 0;
299 myAnimator->getFieldData(i).myOffset[1] = 0;
300 myAnimator->getFieldData(i).myOffset[2] = 0;
301 myAnimator->getFieldData(i).myOffset[aAxis] = aDist * i;
304 QApplication::restoreOverrideCursor();
308 void ArrangeDlg::acceptViewWindow()
310 if (getMode() == ManualMode) {
312 Offset& aOffs = myOffsets[myCurrent];
313 aOffs.myOffset[0] = myCoord[0]->value();
314 aOffs.myOffset[1] = myCoord[1]->value();
315 aOffs.myOffset[2] = myCoord[2]->value();
317 QMap<VISU::Prs3d_i*, int>::Iterator it;
318 for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it) {
319 VISU::Prs3d_i* aPrs = it.key();
320 Offset& aOffs = myOffsets[it.data()];
321 if (VISU_Actor* anActor = VISU::GetActor(aPrs, myViewWindow)) anActor->SetPosition(aOffs.myOffset);
323 if (mySaveChk->isChecked())
324 aPrs->SetOffset(aOffs.myOffset);
330 // bool aInit = true;
332 QMap<VISU::Prs3d_i*, int>::Iterator it;
333 for (it = myPrsMap.begin(), i = 0; it != myPrsMap.end(); ++it, i++) {
334 VISU::Prs3d_i* aPrs = it.key();
335 if (VISU_Actor* aActor = VISU::GetActor(aPrs, myViewWindow)){
336 int aAxis = getAxis();
339 aActor->GetBounds(aBounds);
342 aDist = fabs(aBounds[1] - aBounds[0]);
345 aDist = fabs(aBounds[3] - aBounds[2]);
348 aDist = fabs(aBounds[5] - aBounds[4]);
353 aOffset[0] = aOffset[1] = aOffset[2] = 0;
355 aShift = (i == 0)? 0 : aShift + (aDist + aPrevDist) * getDistance() / 2;
357 aOffset[aAxis] = aShift;
358 aActor->SetPosition(aOffset);
360 if (mySaveChk->isChecked())
361 aPrs->SetOffset(aOffset);
366 myViewWindow->getRenderer()->ResetCameraClippingRange();
367 myViewWindow->Repaint();
371 //*****************************************************************************************************
372 //*****************************************************************************************************
373 //*****************************************************************************************************
374 SetupDlg::SetupDlg (QWidget* theParent, VISU_TimeAnimation* theAnimator)
375 : QDialog(theParent, "SetupDlg", true, WStyle_Customize |
376 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
378 setCaption("Setup Animation");
379 setSizeGripEnabled( TRUE );
380 myAnimator = theAnimator;
382 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
383 aMainLayout->setSpacing(5);
386 QFrame* aRangeGrp = new QFrame(this);
387 QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp );
388 aRangeLayout->setSpacing( 6 );
389 aRangeLayout->setMargin( 11 );
390 aRangeGrp->setFrameStyle(QFrame::Box | QFrame::Raised);
392 myUseRangeChk = new QCheckBox("Use range of time stamps", aRangeGrp);
393 aRangeLayout->addMultiCellWidget(myUseRangeChk, 0, 0, 0, 3);
394 myUseRangeChk->setChecked(myAnimator->isRangeDefined());
396 QLabel* aMinLbl = new QLabel("From", aRangeGrp);
397 aMinLbl->setEnabled(myUseRangeChk->isChecked());
398 aRangeLayout->addWidget(aMinLbl, 1, 0);
399 double aStep = (myAnimator->getMaxTime() - myAnimator->getMinTime())/(theAnimator->getFieldData(0).myNbTimes - 1);
400 myMinVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
401 myMinVal->setEnabled(myUseRangeChk->isChecked());
402 if (myUseRangeChk->isChecked())
403 myMinVal->setValue( myAnimator->getMinRange() );
405 myMinVal->setValue( myAnimator->getMinTime() );
407 connect(myMinVal, SIGNAL( valueChanged(double)),
408 this, SLOT( onMinValue(double) ));
409 aRangeLayout->addWidget(myMinVal, 1, 1);
411 QLabel* aMaxLbl = new QLabel("To", aRangeGrp);
412 aMaxLbl->setEnabled(myUseRangeChk->isChecked());
413 aRangeLayout->addWidget(aMaxLbl, 1, 2);
414 myMaxVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
415 myMaxVal->setEnabled(myUseRangeChk->isChecked());
416 if (myUseRangeChk->isChecked())
417 myMaxVal->setValue( myAnimator->getMaxRange() );
419 myMaxVal->setValue( myAnimator->getMaxTime() );
421 connect(myMaxVal, SIGNAL( valueChanged(double)),
422 this, SLOT( onMaxValue(double) ));
423 aRangeLayout->addWidget(myMaxVal, 1, 3);
425 connect(myUseRangeChk, SIGNAL( toggled(bool)),
426 aMinLbl, SLOT( setEnabled(bool) ));
427 connect(myUseRangeChk, SIGNAL( toggled(bool)),
428 aMaxLbl, SLOT( setEnabled(bool) ));
429 connect(myUseRangeChk, SIGNAL( toggled(bool)),
430 this, SLOT( onRangeCheck(bool) ));
432 aMainLayout->addWidget(aRangeGrp);
435 QHBox* aPropFrame = new QHBox(this);
436 aPropFrame->setSpacing(5);
438 QVGroupBox* aNamesBox = new QVGroupBox("Fields",aPropFrame);
439 myFieldLst = new QListBox(aNamesBox);
440 QStringList aFieldNames;
441 // Find names of fields
442 for (int i = 0; i < theAnimator->getNbFields(); i++) {
443 _PTR(SObject) aSO = theAnimator->getFieldData(i).myField;
444 aFieldNames.append(VISU::getValue(aSO, "myName"));
446 myFieldLst->insertStringList(aFieldNames);
447 myFieldLst->setSelected(0, true);
448 connect( myFieldLst, SIGNAL( highlighted(int) ),
449 this, SLOT( onFieldChange(int) ) );
452 QVBox* aSetupBox = new QVBox(aPropFrame);
453 aSetupBox->setSpacing(5);
455 QVGroupBox* aPropBox = new QVGroupBox("Properties", aSetupBox);
456 //QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame);
457 myTypeCombo = new QComboBox(aPropBox);
458 connect( myTypeCombo, SIGNAL( activated(int) ),
459 this, SLOT( onTypeChanged(int) ) );
461 // QPushButton* aBarBtn = new QPushButton("Scalar Bar...", aPropBox);
462 //connect( aBarBtn, SIGNAL( clicked() ),
463 // this, SLOT( onScalarBarDlg() ) );
465 myPropBtn = new QPushButton("Properties...", aPropBox);
466 // myPropBtn->setEnabled(theAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
467 connect( myPropBtn, SIGNAL( clicked() ),
468 this, SLOT( onPreferencesDlg() ) );
470 if (myAnimator->getNbFields() > 1) {
471 myArrangeBtn = new QPushButton("Arrange...", aSetupBox);
472 connect( myArrangeBtn, SIGNAL( clicked() ), this, SLOT( onArrangeDlg() ) );
475 aMainLayout->addWidget(aPropFrame);
477 QHBox* aBtnBox = new QHBox(this);
478 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
479 aBtnLayout->addStretch();
481 QPushButton* aCloseBtn = new QPushButton(tr("BUT_OK"), aBtnBox);
482 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
484 aMainLayout->addWidget(aBtnBox);
487 //************************************************************************
488 void SetupDlg::onFieldChange (int theIndex)
490 FieldData& aData = myAnimator->getFieldData(theIndex);
491 myTypeCombo->clear();
492 myTypeCombo->insertItem("Scalar Map");
493 myTypeCombo->insertItem("Iso Surfaces");
494 myTypeCombo->insertItem("Cut Planes");
496 _PTR(SObject) aSObject = aData.myField;
497 long aNumComp = VISU::getValue(aSObject, "myNumComponent").toLong();
499 myTypeCombo->insertItem("Deformed Shape");
500 myTypeCombo->insertItem("Vectors");
501 myTypeCombo->insertItem("Stream Lines");
503 switch (aData.myPrsType) {
504 case VISU::TSCALARMAP: //Scalar Map
505 myTypeCombo->setCurrentItem(0);
507 case VISU::TISOSURFACE: //Iso Surfaces
508 myTypeCombo->setCurrentItem(1);
510 case VISU::TCUTPLANES: //Cut Planes
511 myTypeCombo->setCurrentItem(2);
513 case VISU::TDEFORMEDSHAPE: //Deformed Shape
514 myTypeCombo->setCurrentItem(3);
516 case VISU::TVECTORS: //Vectors
517 myTypeCombo->setCurrentItem(4);
519 case VISU::TSTREAMLINES: //Stream Lines
520 myTypeCombo->setCurrentItem(5);
521 aData.myPrsType = VISU::TSTREAMLINES;
524 //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
527 //************************************************************************
528 void SetupDlg::onTypeChanged (int theIndex)
530 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
533 aData.myPrsType = VISU::TSCALARMAP;
535 case 1: //Iso Surfaces
536 aData.myPrsType = VISU::TISOSURFACE;
539 aData.myPrsType = VISU::TCUTPLANES;
541 case 3: //Deformed Shape
542 aData.myPrsType = VISU::TDEFORMEDSHAPE;
545 aData.myPrsType = VISU::TVECTORS;
547 case 5: //Stream Lines
548 aData.myPrsType = VISU::TSTREAMLINES;
551 myAnimator->clearData(aData);
552 //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
553 //myAnimator->generatePresentations(myFieldLst->currentItem());
556 //************************************************************************
557 /*void SetupDlg::onScalarBarDlg() {
558 QApplication::setOverrideCursor( Qt::waitCursor );
559 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
560 if (aData.myPrs == 0)
561 myAnimator->generatePresentations(myFieldLst->currentItem());
562 QApplication::restoreOverrideCursor();
564 VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg();
565 aScalarBarDlg->initFromPrsObject(aData.myPrs[0]);
566 if (aScalarBarDlg->exec()) {
567 for (int i = 0; i < aData.myNbFrames; i++)
568 aScalarBarDlg->storeToPrsObject(aData.myPrs[i]);
573 //************************************************************************
574 void SetupDlg::onPreferencesDlg()
576 MESSAGE("SetupDlg::onPreferencesDlg() is not implemented");
577 SUIT_OverrideCursor c;
578 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
579 if (aData.myPrs.empty())
580 myAnimator->generatePresentations(myFieldLst->currentItem());
582 // BUG VISU5725 : Compatibility gcc 2.95
583 // #define EDITPRS(TYPE, DLG) \
585 // DLG* aDlg = new DLG(); \
586 // aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(0))); \
587 // if (aDlg->exec()) { \
588 // for (int i = 0; i < aData.myNbFrames; i++) \
589 // aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(i))); \
595 #define EDITPRS(TYPE, DLG) {\
596 DLG* aDlg = new DLG(this);\
597 aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs[0]));\
600 for (int i = 0; i < aData.myNbFrames; i++)\
601 aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs[i]));\
605 switch (myTypeCombo->currentItem()) {
608 EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
610 case 1: //Iso Surfaces
612 EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
615 // EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
618 VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg(false, true);
619 //_CS_PhB :operator [] .at aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(0)));
620 aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[0]));
623 for (int i = 0; i < aData.myNbFrames; i++)
624 //_CS_PhB:operator [] .at aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(i)));
625 aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[i]));
630 case 3: //Deformed Shape
632 EDITPRS(VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg);
636 EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg);
638 case 5: //Stream Lines
640 EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
648 //************************************************************************
649 void SetupDlg::onArrangeDlg()
651 ArrangeDlg aDlg(this, myAnimator);
655 //************************************************************************
656 void SetupDlg::onRangeCheck (bool theCheck)
658 for (int i = 0; i < myAnimator->getNbFields(); i++)
659 myAnimator->clearData(myAnimator->getFieldData(i));
661 myMinVal->setEnabled(theCheck);
662 myMaxVal->setEnabled(theCheck);
665 myAnimator->setAnimationRange(0, 0);
667 // if (myMinVal->value() < myMaxVal->value())
668 myAnimator->setAnimationRange(myMinVal->value(), myMaxVal->value());
669 // else if (myMinVal->value() > myMaxVal->value())
670 // myAnimator->setAnimationRange(myMaxVal->value(), myMinVal->value());
671 // else // equal case
672 // myAnimator->setAnimationRange(0, 0);
676 //************************************************************************
677 void SetupDlg::onMinValue (double theVal)
679 if (theVal > myAnimator->getMaxRange()) {
680 myMinVal->setValue( myAnimator->getMinTime() );
681 myMinVal->setFocus();
684 for (int i = 0; i < myAnimator->getNbFields(); i++)
685 myAnimator->clearData(myAnimator->getFieldData(i));
686 myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange());
689 //************************************************************************
690 void SetupDlg::onMaxValue (double theVal)
692 if (theVal < myAnimator->getMinRange()) {
693 myMaxVal->setValue( myAnimator->getMaxTime() );
694 myMaxVal->setFocus();
697 for (int i = 0; i < myAnimator->getNbFields(); i++)
698 myAnimator->clearData(myAnimator->getFieldData(i));
699 myAnimator->setAnimationRange(myAnimator->getMinRange(), theVal);
702 static const char * firstIco[] = {
718 static const char * lastIco[] = {
734 static const char * leftIco[] = {
749 static const char * playIco[] = {
768 static QPixmap MYplayPixmap(playIco);
771 static const char * rightIco[] = {
787 static const char * pauseIco[] = {
806 static QPixmap MYpausePixmap(pauseIco);
809 //VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (QWidget* parent, _PTR(Study) theStudy)
810 // : QDialog(parent, "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
811 VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy)
812 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
813 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose)
815 setCaption("Animation");
816 setSizeGripEnabled( TRUE );
817 myModule = theModule;
821 //myAnimator = new VISU_TimeAnimation (VISU::GetDSStudy(theStudy));
822 myAnimator = new VISU_TimeAnimation (theStudy);
823 myAnimator->setSpeed(1);
824 myAnimator->setViewer(VISU::GetViewWindow());
825 connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double)));
826 connect(myAnimator, SIGNAL(stopped()), this, SLOT(onStop()));
828 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
829 aMainLayout->setSpacing(5);
831 mySetupBtn = new QPushButton("Setup Animation...", this);
832 connect( mySetupBtn, SIGNAL( clicked() ),
833 this, SLOT( onSetupDlg() ) );
834 aMainLayout->addWidget(mySetupBtn);
836 myGenBtn = new QPushButton("Generate frames", this);
837 connect( myGenBtn, SIGNAL( clicked() ),
838 this, SLOT( createFrames() ) );
839 aMainLayout->addWidget(myGenBtn);
841 myPlayFrame = new QFrame(this);
842 myPlayFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
843 myPlayFrame->setLineWidth( 1 );
846 // --- Play controls ---
847 QGridLayout* TopLayout = new QGridLayout( myPlayFrame );
848 TopLayout->setSpacing( 6 );
849 TopLayout->setMargin( 11 );
851 myTimeLbl = new QLabel("0", myPlayFrame);
852 TopLayout->addMultiCellWidget(myTimeLbl, 0, 0, 0, 2, Qt::AlignHCenter);
854 mySlider = new QSlider(Qt::Horizontal, myPlayFrame);
855 mySlider->setMinValue(0);
856 mySlider->setMaxValue(3);
857 mySlider->setTickInterval(1);
858 //mySlider->setTickmarks(QSlider::Below);
859 mySlider->setTracking(false);
860 connect( mySlider, SIGNAL( valueChanged(int) ),
861 this, SLOT( onWindowChanged(int) ) );
862 TopLayout->addMultiCellWidget(mySlider, 1, 1, 0, 2);
864 myPlayBtn = new QToolButton(myPlayFrame);
865 myPlayBtn->setIconSet(MYplayPixmap);
866 myPlayBtn->setToggleButton(true);
867 connect( myPlayBtn, SIGNAL( clicked() ),
868 this, SLOT( onPlayPressed() ) );
869 TopLayout->addMultiCellWidget(myPlayBtn, 2, 2, 0, 1);
871 QToolButton* aBackBtn = new QToolButton(myPlayFrame);
872 aBackBtn->setIconSet(QPixmap(leftIco));
873 connect( aBackBtn, SIGNAL( clicked() ),
874 this, SLOT( onBackPressed() ) );
875 TopLayout->addWidget(aBackBtn, 3, 0);
877 QToolButton* aForvardBtn = new QToolButton(myPlayFrame);
878 aForvardBtn->setIconSet(QPixmap(rightIco));
879 connect( aForvardBtn, SIGNAL( clicked() ),
880 this, SLOT( onForvardPressed() ) );
881 TopLayout->addWidget(aForvardBtn, 3, 1);
883 QToolButton* aFirstBtn = new QToolButton(myPlayFrame);
884 aFirstBtn->setIconSet(QPixmap(firstIco));
885 connect( aFirstBtn, SIGNAL( clicked() ),
886 this, SLOT( onFirstPressed() ) );
887 TopLayout->addWidget(aFirstBtn, 4, 0);
889 QToolButton* aLastBtn = new QToolButton(myPlayFrame);
890 aLastBtn->setIconSet(QPixmap(lastIco));
891 connect( aLastBtn, SIGNAL( clicked() ),
892 this, SLOT( onLastPressed() ) );
893 TopLayout->addWidget(aLastBtn, 4, 1);
895 QLabel* aSpeedLbl = new QLabel("Speed", myPlayFrame);
896 TopLayout->addWidget(aSpeedLbl, 4, 2, Qt::AlignRight);
898 QLCDNumber* aSpeedNum = new QLCDNumber( 2, myPlayFrame );
899 aSpeedNum->setSegmentStyle(QLCDNumber::Flat);
900 aSpeedNum->display(1);
901 TopLayout->addWidget(aSpeedNum, 4, 3);
903 QwtWheel* aWheel = new QwtWheel(myPlayFrame);
904 aWheel->setOrientation(Qt::Vertical);
905 aWheel->setRange(1, 99, 1);
906 connect( aWheel, SIGNAL(valueChanged(double)),
907 aSpeedNum, SLOT(display(double)) );
908 connect( aWheel, SIGNAL(valueChanged(double)),
909 this, SLOT(onSpeedChange(double)) );
910 TopLayout->addMultiCellWidget(aWheel, 1, 3, 3, 3, Qt::AlignRight);
912 QCheckBox* aCycleCheck = new QCheckBox("Cycled animation",myPlayFrame);
913 aCycleCheck->setChecked(myAnimator->isCycling());
914 connect(aCycleCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCyclingSlot(bool)));
915 TopLayout->addMultiCellWidget(aCycleCheck, 5, 5, 0, 3);
917 QCheckBox* aPropCheck = new QCheckBox("Use proportional timing",myPlayFrame);
918 aPropCheck->setChecked(myAnimator->isProportional());
919 connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool)));
920 TopLayout->addMultiCellWidget(aPropCheck, 6, 6, 0, 3);
922 QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame );
923 aSaveBox->setColumnLayout(0, Qt::Horizontal );
924 QGridLayout* aSaveLay = new QGridLayout(aSaveBox->layout());
925 aSaveLay->setSpacing( 5 );
926 aSaveLay->setMargin( 5 );
928 mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox);
929 aSaveLay->addMultiCellWidget(mySaveCheck, 0, 0, 0, 2);
930 connect(mySaveCheck, SIGNAL( toggled(bool)),
931 aWheel, SLOT( setDisabled(bool) ));
933 QLabel* aPathLbl = new QLabel("Path:", aSaveBox);
934 aPathLbl->setEnabled(false);
935 connect(mySaveCheck, SIGNAL( toggled(bool)),
936 aPathLbl, SLOT( setEnabled(bool) ));
937 aSaveLay->addWidget(aPathLbl, 1, 0);
939 myPathEdit = new QLineEdit(aSaveBox);
940 myPathEdit->setEnabled(false);
941 connect(mySaveCheck, SIGNAL( toggled(bool)),
942 myPathEdit, SLOT( setEnabled(bool) ));
943 aSaveLay->addWidget(myPathEdit, 1, 1);
945 QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox);
946 aBrowseBtn->setEnabled(false);
947 connect(mySaveCheck, SIGNAL( toggled(bool)),
948 aBrowseBtn, SLOT( setEnabled(bool) ));
949 connect(aBrowseBtn, SIGNAL( clicked()),
950 this, SLOT( onBrowse() ));
951 mySaveCheck->setChecked(false);
952 aSaveLay->addWidget(aBrowseBtn, 1, 2);
954 TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3);
956 aMainLayout->addWidget(myPlayFrame);
958 QHBox* aPublishBox = new QHBox(this);
959 aPublishBox->setSpacing(5);
961 myPublishBtn = new QPushButton("Publish to study", aPublishBox);
962 connect(myPublishBtn, SIGNAL(clicked()), this, SLOT(publishToStudy()));
964 mySaveBtn = new QPushButton("Save Animation", aPublishBox);
965 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
966 connect(mySaveBtn, SIGNAL(clicked()), this, SLOT(saveToStudy()));
968 aMainLayout->addWidget(aPublishBox);
971 QHBox* aBtnBox = new QHBox(this);
972 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
973 aBtnLayout->addStretch();
975 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
976 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
978 aMainLayout->addWidget(aBtnBox);
980 myPlayFrame->setEnabled(false);
983 //************************************************************************
984 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
989 //************************************************************************
990 void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
993 myPropBtn->setEnabled(index != 0);
996 myPlayFrame->setEnabled(false);
999 //************************************************************************
1000 void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject)
1002 myPlayFrame->setEnabled(false);
1003 myAnimator->addField(VISU::GetSObject(theSObject));
1006 //************************************************************************
1007 void VisuGUI_TimeAnimationDlg::createFrames()
1010 SUIT_OverrideCursor c;
1012 for (int i = 0; i < myAnimator->getNbFields(); i++) {
1013 if (myAnimator->getFieldData(i).myPrs.empty())
1014 myAnimator->generatePresentations(i);
1016 if (myAnimator->getNbFrames() == 0) {
1017 myPlayFrame->setEnabled(false);
1019 SUIT_MessageBox::warn1(this,
1021 tr("MSG_NO_ANIMATIONDATA"),
1025 mySlider->setMaxValue(myAnimator->getNbFrames()-1);
1026 myPlayFrame->setEnabled(true);
1027 if (!myAnimator->generateFrames()) {
1029 //myPlayFrame->setEnabled(false);
1030 SUIT_MessageBox::warn1(this,
1032 myAnimator->getLastErrorMsg(),
1036 //myPlayFrame->setEnabled(true);
1039 //************************************************************************
1040 void VisuGUI_TimeAnimationDlg::onPlayPressed()
1042 if (myPlayBtn->isOn() && (!myAnimator->running())) {
1043 myPlayBtn->setIconSet(MYpausePixmap);
1044 if (mySaveCheck->isChecked())
1045 myAnimator->dumpTo(myPathEdit->text());
1047 myAnimator->dumpTo("");
1048 mySetupBtn->setEnabled(false);
1049 myGenBtn->setEnabled(false);
1050 myAnimator->startAnimation();
1052 myPlayBtn->setIconSet(MYplayPixmap);
1053 myAnimator->stopAnimation();
1054 mySetupBtn->setEnabled(true);
1055 myGenBtn->setEnabled(true);
1059 //************************************************************************
1060 void VisuGUI_TimeAnimationDlg::onBackPressed()
1063 myAnimator->prevFrame();
1066 //************************************************************************
1067 void VisuGUI_TimeAnimationDlg::onForvardPressed()
1069 myAnimator->nextFrame();
1072 //************************************************************************
1073 void VisuGUI_TimeAnimationDlg::onLastPressed()
1075 myAnimator->lastFrame();
1078 //************************************************************************
1079 void VisuGUI_TimeAnimationDlg::onFirstPressed()
1081 myAnimator->firstFrame();
1084 //************************************************************************
1085 void VisuGUI_TimeAnimationDlg::clearView()
1087 myAnimator->clearView();
1090 //************************************************************************
1091 void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent)
1093 myAnimator->stopAnimation();
1094 myAnimator->wait(500);
1095 if (myAnimator->running() && (! myAnimator->finished())) {
1099 QDialog::closeEvent(theEvent);
1103 //************************************************************************
1104 void VisuGUI_TimeAnimationDlg::onWindowChanged (int index)
1106 if (myAnimator->isRunning()) return;
1107 myAnimator->gotoFrame(index);
1110 //************************************************************************
1111 void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed)
1113 myAnimator->setSpeed((int)theSpeed);
1116 //************************************************************************
1117 void VisuGUI_TimeAnimationDlg::stopAnimation()
1119 myAnimator->stopAnimation();
1120 myPlayBtn->setOn(false);
1121 myPlayBtn->setIconSet(MYplayPixmap);
1122 mySetupBtn->setEnabled(true);
1123 myGenBtn->setEnabled(true);
1126 //************************************************************************
1127 void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime)
1129 myTimeLbl->setText(QString("%1").arg(theTime));
1130 mySlider->setValue(theNewFrame);
1133 //************************************************************************
1134 void VisuGUI_TimeAnimationDlg::onSetupDlg()
1136 if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame();
1137 SetupDlg* aDlg = new SetupDlg(this, myAnimator);
1139 myPlayFrame->setEnabled(false);
1143 //************************************************************************
1144 void VisuGUI_TimeAnimationDlg::onBrowse()
1146 QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/","Select path");
1147 if (!aPath.isEmpty())
1148 myPathEdit->setText(aPath);
1151 //************************************************************************
1152 void VisuGUI_TimeAnimationDlg::onStop()
1155 QDialog::closeEvent(myEvent);
1157 myPlayBtn->setOn(false);
1158 myPlayBtn->setIconSet(MYplayPixmap);
1159 mySetupBtn->setEnabled(true);
1160 myGenBtn->setEnabled(true);
1164 //************************************************************************
1165 void VisuGUI_TimeAnimationDlg::saveToStudy()
1167 myAnimator->saveAnimation();
1168 myModule->updateObjBrowser( true );
1171 //************************************************************************
1172 void VisuGUI_TimeAnimationDlg::publishToStudy()
1174 myAnimator->publishInStudy();
1175 myModule->updateObjBrowser( true );
1176 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1179 //************************************************************************
1180 void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation)
1182 myAnimator->restoreFromStudy(theAnimation);
1183 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());