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 = 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))
341 anActor->SetPosition(aOffs.myOffset);
343 if (mySaveChk->isChecked())
344 aPrs->SetOffset(aOffs.myOffset);
350 float aPrevShift = 0;
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();
358 aActor->GetBounds(aBounds);
361 aDist = fabs(aBounds[1] - aBounds[0]);
364 aDist = fabs(aBounds[3] - aBounds[2]);
367 aDist = fabs(aBounds[5] - aBounds[4]);
370 aOffset[0] = (aBounds[1] < aBounds[0]) ? -aBounds[1] : -aBounds[0];
371 aOffset[1] = (aBounds[3] < aBounds[2]) ? -aBounds[3] : -aBounds[2];
372 aOffset[2] = (aBounds[5] < aBounds[4]) ? -aBounds[5] : -aBounds[4];
375 float aCCDist = (aDist + aPrevDist) / 2.0;
377 float dx = fabs(aBounds[1] - aBounds[0]);
378 float dy = fabs(aBounds[3] - aBounds[2]);
379 float dz = fabs(aBounds[5] - aBounds[4]);
380 float max = (dx > dy) ? dx : dy;
381 max = (dz > max) ? dz : max;
385 // set base distance between centers of bounding boxes
386 // to minimal (but big enough) size of current bounding box
387 if (dx < max) dx = FLT_MAX;
388 if (dy < max) dy = FLT_MAX;
389 if (dz < max) dz = FLT_MAX;
391 aCCDist = (dx < dy) ? dx : dy;
392 aCCDist = (dz < aCCDist) ? dz : aCCDist;
395 //-------------------------------->
399 // .--------------. .------.
400 //----------->| | | |
401 // aPrevShift '--------------' '------'
406 // (aDist + aPrevDist) * getDistance() / 2
408 aShift = aPrevShift + aPrevDist/2.0 + aCCDist*getDistance() - aDist/2.0;
411 aOffset[aAxis] += aShift;
412 aActor->SetPosition(aOffset);
414 if (mySaveChk->isChecked())
415 aPrs->SetOffset(aOffset);
422 myViewWindow->getRenderer()->ResetCameraClippingRange();
423 myViewWindow->Repaint();
427 //*****************************************************************************************************
428 //*****************************************************************************************************
429 //*****************************************************************************************************
430 SetupDlg::SetupDlg (VisuGUI* theModule, VISU_TimeAnimation* theAnimator)
431 : QDialog(VISU::GetDesktop(theModule), "SetupDlg", true, WStyle_Customize |
432 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
435 setCaption("Setup Animation");
436 setSizeGripEnabled( TRUE );
437 myAnimator = theAnimator;
439 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
440 aMainLayout->setSpacing(5);
443 QFrame* aRangeGrp = new QFrame(this);
444 QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp );
445 aRangeLayout->setSpacing( 6 );
446 aRangeLayout->setMargin( 11 );
447 aRangeGrp->setFrameStyle(QFrame::Box | QFrame::Raised);
449 myUseRangeChk = new QCheckBox("Use range of time stamps", aRangeGrp);
450 aRangeLayout->addMultiCellWidget(myUseRangeChk, 0, 0, 0, 3);
451 myUseRangeChk->setChecked(myAnimator->isRangeDefined());
453 QLabel* aMinLbl = new QLabel("From", aRangeGrp);
454 aMinLbl->setEnabled(myUseRangeChk->isChecked());
455 aRangeLayout->addWidget(aMinLbl, 1, 0);
456 double aStep = (myAnimator->getMaxTime() - myAnimator->getMinTime())/(theAnimator->getFieldData(0).myNbTimes - 1);
457 myMinVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
458 myMinVal->setEnabled(myUseRangeChk->isChecked());
459 if (myUseRangeChk->isChecked())
460 myMinVal->setValue( myAnimator->getMinRange() );
462 myMinVal->setValue( myAnimator->getMinTime() );
464 connect(myMinVal, SIGNAL( valueChanged(double)),
465 this, SLOT( onMinValue(double) ));
466 aRangeLayout->addWidget(myMinVal, 1, 1);
468 QLabel* aMaxLbl = new QLabel("To", aRangeGrp);
469 aMaxLbl->setEnabled(myUseRangeChk->isChecked());
470 aRangeLayout->addWidget(aMaxLbl, 1, 2);
471 myMaxVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp );
472 myMaxVal->setEnabled(myUseRangeChk->isChecked());
473 if (myUseRangeChk->isChecked())
474 myMaxVal->setValue( myAnimator->getMaxRange() );
476 myMaxVal->setValue( myAnimator->getMaxTime() );
478 connect(myMaxVal, SIGNAL( valueChanged(double)),
479 this, SLOT( onMaxValue(double) ));
480 aRangeLayout->addWidget(myMaxVal, 1, 3);
482 connect(myUseRangeChk, SIGNAL( toggled(bool)),
483 aMinLbl, SLOT( setEnabled(bool) ));
484 connect(myUseRangeChk, SIGNAL( toggled(bool)),
485 aMaxLbl, SLOT( setEnabled(bool) ));
486 connect(myUseRangeChk, SIGNAL( toggled(bool)),
487 this, SLOT( onRangeCheck(bool) ));
489 aMainLayout->addWidget(aRangeGrp);
492 QHBox* aPropFrame = new QHBox(this);
493 aPropFrame->setSpacing(5);
495 QVGroupBox* aNamesBox = new QVGroupBox("Fields",aPropFrame);
496 myFieldLst = new QListBox(aNamesBox);
497 QStringList aFieldNames;
498 // Find names of fields
499 for (int i = 0; i < theAnimator->getNbFields(); i++) {
500 _PTR(SObject) aSO = theAnimator->getFieldData(i).myField;
501 aFieldNames.append(VISU::getValue(aSO, "myName"));
503 myFieldLst->insertStringList(aFieldNames);
504 myFieldLst->setSelected(0, true);
505 connect( myFieldLst, SIGNAL( highlighted(int) ),
506 this, SLOT( onFieldChange(int) ) );
509 QVBox* aSetupBox = new QVBox(aPropFrame);
510 aSetupBox->setSpacing(5);
512 QVGroupBox* aPropBox = new QVGroupBox("Properties", aSetupBox);
513 //QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame);
514 myTypeCombo = new QComboBox(aPropBox);
515 connect( myTypeCombo, SIGNAL( activated(int) ),
516 this, SLOT( onTypeChanged(int) ) );
518 // QPushButton* aBarBtn = new QPushButton("Scalar Bar...", aPropBox);
519 //connect( aBarBtn, SIGNAL( clicked() ),
520 // this, SLOT( onScalarBarDlg() ) );
522 myPropBtn = new QPushButton("Properties...", aPropBox);
523 // myPropBtn->setEnabled(theAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP);
524 connect( myPropBtn, SIGNAL( clicked() ),
525 this, SLOT( onPreferencesDlg() ) );
527 if (myAnimator->getNbFields() > 1) {
528 myArrangeBtn = new QPushButton("Arrange...", aSetupBox);
529 connect( myArrangeBtn, SIGNAL( clicked() ), this, SLOT( onArrangeDlg() ) );
532 aMainLayout->addWidget(aPropFrame);
534 QHBox* aBtnBox = new QHBox(this);
535 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
536 aBtnLayout->addStretch();
538 QPushButton* aCloseBtn = new QPushButton(tr("BUT_OK"), aBtnBox);
539 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
541 aMainLayout->addWidget(aBtnBox);
544 //************************************************************************
546 TSCALARMAP_ITEM = 0, // VISU::TSCALARMAP
547 TISOSURFACE_ITEM = 1, // VISU::TISOSURFACE
548 TCUTPLANES_ITEM = 2, // VISU::TCUTPLANES
549 TPLOT3D_ITEM = 3, // VISU::TPLOT3D
550 TDEFORMEDSHAPE_ITEM = 4, // VISU::TDEFORMEDSHAPE
551 TVECTORS_ITEM = 5, // VISU::TVECTORS
552 TSTREAMLINES_ITEM = 6 // VISU::TSTREAMLINES
555 //************************************************************************
556 void SetupDlg::onFieldChange (int theIndex)
558 FieldData& aData = myAnimator->getFieldData(theIndex);
559 myTypeCombo->clear();
560 // ATTENTION: append items in the same order like it is done in the PrsComboItem enumeration
561 myTypeCombo->insertItem("Scalar Map"); // item 0
562 myTypeCombo->insertItem("Iso Surfaces"); // item 1
563 myTypeCombo->insertItem("Cut Planes"); // item 2
564 myTypeCombo->insertItem("Plot 3D"); // item 3
566 _PTR(SObject) aSObject = aData.myField;
567 long aNumComp = VISU::getValue(aSObject, "myNumComponent").toLong();
569 myTypeCombo->insertItem("Deformed Shape"); // item 4
570 myTypeCombo->insertItem("Vectors"); // item 5
571 myTypeCombo->insertItem("Stream Lines"); // item 6
573 switch (aData.myPrsType) {
574 case VISU::TSCALARMAP: //Scalar Map
575 myTypeCombo->setCurrentItem(TSCALARMAP_ITEM);
577 case VISU::TISOSURFACE: //Iso Surfaces
578 myTypeCombo->setCurrentItem(TISOSURFACE_ITEM);
580 case VISU::TCUTPLANES: //Cut Planes
581 myTypeCombo->setCurrentItem(TCUTPLANES_ITEM);
583 case VISU::TPLOT3D: //Plot 3D
584 myTypeCombo->setCurrentItem(TPLOT3D_ITEM);
586 case VISU::TDEFORMEDSHAPE: //Deformed Shape
587 myTypeCombo->setCurrentItem(TDEFORMEDSHAPE_ITEM);
589 case VISU::TVECTORS: //Vectors
590 myTypeCombo->setCurrentItem(TVECTORS_ITEM);
592 case VISU::TSTREAMLINES: //Stream Lines
593 myTypeCombo->setCurrentItem(TSTREAMLINES_ITEM);
594 aData.myPrsType = VISU::TSTREAMLINES;
597 //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
600 //************************************************************************
601 void SetupDlg::onTypeChanged (int theIndex)
603 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
605 case TSCALARMAP_ITEM: //Scalar Map
606 aData.myPrsType = VISU::TSCALARMAP;
608 case TISOSURFACE_ITEM: //Iso Surfaces
609 aData.myPrsType = VISU::TISOSURFACE;
611 case TCUTPLANES_ITEM: //Cut Planes
612 aData.myPrsType = VISU::TCUTPLANES;
614 case TPLOT3D_ITEM: //Plot 3D
615 aData.myPrsType = VISU::TPLOT3D;
617 case TDEFORMEDSHAPE_ITEM: //Deformed Shape
618 aData.myPrsType = VISU::TDEFORMEDSHAPE;
620 case TVECTORS_ITEM: //Vectors
621 aData.myPrsType = VISU::TVECTORS;
623 case TSTREAMLINES_ITEM: //Stream Lines
624 aData.myPrsType = VISU::TSTREAMLINES;
627 myAnimator->clearData(aData);
628 //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP);
629 //myAnimator->generatePresentations(myFieldLst->currentItem());
632 //************************************************************************
633 /*void SetupDlg::onScalarBarDlg() {
634 QApplication::setOverrideCursor( Qt::waitCursor );
635 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
636 if (aData.myPrs == 0)
637 myAnimator->generatePresentations(myFieldLst->currentItem());
638 QApplication::restoreOverrideCursor();
640 VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg();
641 aScalarBarDlg->initFromPrsObject(aData.myPrs[0]);
642 if (aScalarBarDlg->exec()) {
643 for (int i = 0; i < aData.myNbFrames; i++)
644 aScalarBarDlg->storeToPrsObject(aData.myPrs[i]);
649 //************************************************************************
650 void SetupDlg::onPreferencesDlg()
652 SUIT_OverrideCursor c;
653 FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem());
654 if (aData.myPrs.empty())
655 myAnimator->generatePresentations(myFieldLst->currentItem());
657 // BUG VISU5725 : Compatibility gcc 2.95
658 // #define EDITPRS(TYPE, DLG) \
660 // DLG* aDlg = new DLG(); \
661 // aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(0))); \
662 // if (aDlg->exec()) { \
663 // for (int i = 0; i < aData.myNbFrames; i++) \
664 // aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs.at(i))); \
670 #define EDITPRS(TYPE, DLG) {\
671 DLG* aDlg = new DLG (myModule);\
672 aDlg->initFromPrsObject(dynamic_cast<TYPE*>(aData.myPrs[0]));\
675 for (int i = 0; i < aData.myNbFrames; i++)\
676 aDlg->storeToPrsObject(dynamic_cast<TYPE*>(aData.myPrs[i]));\
680 switch (myTypeCombo->currentItem()) {
681 case TSCALARMAP_ITEM: //Scalar Map
683 EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg);
685 case TISOSURFACE_ITEM: //Iso Surfaces
687 EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg);
689 case TCUTPLANES_ITEM: //Cut Planes
691 EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg);
693 VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg (myModule);
694 //_CS_PhB :operator [] .at aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(0)));
695 aDlg->initFromPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[0]));
698 for (int i = 0; i < aData.myNbFrames; i++)
699 //_CS_PhB:operator [] .at aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs.at(i)));
700 aDlg->storeToPrsObject(dynamic_cast<VISU::CutPlanes_i*>(aData.myPrs[i]));
705 case TPLOT3D_ITEM: //Plot 3D
707 EDITPRS(VISU::Plot3D_i, VisuGUI_Plot3DDlg);
709 case TDEFORMEDSHAPE_ITEM: //Deformed Shape
711 EDITPRS(VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg);
713 case TVECTORS_ITEM: //Vectors
715 EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg);
717 case TSTREAMLINES_ITEM: //Stream Lines
719 EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg);
726 //************************************************************************
727 void SetupDlg::onArrangeDlg()
729 ArrangeDlg aDlg(this, myAnimator);
733 //************************************************************************
734 void SetupDlg::onRangeCheck (bool theCheck)
736 for (int i = 0; i < myAnimator->getNbFields(); i++)
737 myAnimator->clearData(myAnimator->getFieldData(i));
739 myMinVal->setEnabled(theCheck);
740 myMaxVal->setEnabled(theCheck);
743 myAnimator->setAnimationRange(0, 0);
745 // if (myMinVal->value() < myMaxVal->value())
746 myAnimator->setAnimationRange(myMinVal->value(), myMaxVal->value());
747 // else if (myMinVal->value() > myMaxVal->value())
748 // myAnimator->setAnimationRange(myMaxVal->value(), myMinVal->value());
749 // else // equal case
750 // myAnimator->setAnimationRange(0, 0);
754 //************************************************************************
755 void SetupDlg::onMinValue (double theVal)
757 if (theVal > myAnimator->getMaxRange()) {
758 myMinVal->setValue( myAnimator->getMinTime() );
759 myMinVal->setFocus();
762 for (int i = 0; i < myAnimator->getNbFields(); i++)
763 myAnimator->clearData(myAnimator->getFieldData(i));
764 myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange());
767 //************************************************************************
768 void SetupDlg::onMaxValue (double theVal)
770 if (theVal < myAnimator->getMinRange()) {
771 myMaxVal->setValue( myAnimator->getMaxTime() );
772 myMaxVal->setFocus();
775 for (int i = 0; i < myAnimator->getNbFields(); i++)
776 myAnimator->clearData(myAnimator->getFieldData(i));
777 myAnimator->setAnimationRange(myAnimator->getMinRange(), theVal);
780 static const char * firstIco[] = {
796 static const char * lastIco[] = {
812 static const char * leftIco[] = {
827 static const char * playIco[] = {
846 static QPixmap MYplayPixmap(playIco);
849 static const char * rightIco[] = {
865 static const char * pauseIco[] = {
884 static QPixmap MYpausePixmap(pauseIco);
887 VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy)
888 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize |
889 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
893 setCaption("Animation");
894 setSizeGripEnabled( TRUE );
897 myAnimator = new VISU_TimeAnimation (theStudy);
898 myAnimator->setSpeed(1);
899 myAnimator->setViewer(VISU::GetViewWindow());
900 connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double)));
901 connect(myAnimator, SIGNAL(stopped()), this, SLOT(onStop()));
903 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6);
904 aMainLayout->setSpacing(5);
906 mySetupBtn = new QPushButton("Setup Animation...", this);
907 connect( mySetupBtn, SIGNAL( clicked() ),
908 this, SLOT( onSetupDlg() ) );
909 aMainLayout->addWidget(mySetupBtn);
911 myGenBtn = new QPushButton("Generate frames", this);
912 connect( myGenBtn, SIGNAL( clicked() ),
913 this, SLOT( createFrames() ) );
914 aMainLayout->addWidget(myGenBtn);
916 myPlayFrame = new QFrame(this);
917 myPlayFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
918 myPlayFrame->setLineWidth( 1 );
921 // --- Play controls ---
922 QGridLayout* TopLayout = new QGridLayout( myPlayFrame );
923 TopLayout->setSpacing( 6 );
924 TopLayout->setMargin( 11 );
926 myTimeLbl = new QLabel("0", myPlayFrame);
927 TopLayout->addMultiCellWidget(myTimeLbl, 0, 0, 0, 2, Qt::AlignHCenter);
929 mySlider = new QSlider(Qt::Horizontal, myPlayFrame);
930 mySlider->setMinValue(0);
931 mySlider->setMaxValue(3);
932 mySlider->setTickInterval(1);
933 //mySlider->setTickmarks(QSlider::Below);
934 mySlider->setTracking(false);
935 connect( mySlider, SIGNAL( valueChanged(int) ),
936 this, SLOT( onWindowChanged(int) ) );
937 TopLayout->addMultiCellWidget(mySlider, 1, 1, 0, 2);
939 myPlayBtn = new QToolButton(myPlayFrame);
940 myPlayBtn->setIconSet(MYplayPixmap);
941 myPlayBtn->setToggleButton(true);
942 connect( myPlayBtn, SIGNAL( clicked() ),
943 this, SLOT( onPlayPressed() ) );
944 TopLayout->addMultiCellWidget(myPlayBtn, 2, 2, 0, 1);
946 QToolButton* aBackBtn = new QToolButton(myPlayFrame);
947 aBackBtn->setIconSet(QPixmap(leftIco));
948 connect( aBackBtn, SIGNAL( clicked() ),
949 this, SLOT( onBackPressed() ) );
950 TopLayout->addWidget(aBackBtn, 3, 0);
952 QToolButton* aForvardBtn = new QToolButton(myPlayFrame);
953 aForvardBtn->setIconSet(QPixmap(rightIco));
954 connect( aForvardBtn, SIGNAL( clicked() ),
955 this, SLOT( onForvardPressed() ) );
956 TopLayout->addWidget(aForvardBtn, 3, 1);
958 QToolButton* aFirstBtn = new QToolButton(myPlayFrame);
959 aFirstBtn->setIconSet(QPixmap(firstIco));
960 connect( aFirstBtn, SIGNAL( clicked() ),
961 this, SLOT( onFirstPressed() ) );
962 TopLayout->addWidget(aFirstBtn, 4, 0);
964 QToolButton* aLastBtn = new QToolButton(myPlayFrame);
965 aLastBtn->setIconSet(QPixmap(lastIco));
966 connect( aLastBtn, SIGNAL( clicked() ),
967 this, SLOT( onLastPressed() ) );
968 TopLayout->addWidget(aLastBtn, 4, 1);
970 QLabel* aSpeedLbl = new QLabel("Speed", myPlayFrame);
971 TopLayout->addWidget(aSpeedLbl, 4, 2, Qt::AlignRight);
973 QLCDNumber* aSpeedNum = new QLCDNumber( 2, myPlayFrame );
974 aSpeedNum->setSegmentStyle(QLCDNumber::Flat);
975 aSpeedNum->display(1);
976 TopLayout->addWidget(aSpeedNum, 4, 3);
978 QwtWheel* aWheel = new QwtWheel(myPlayFrame);
979 aWheel->setOrientation(Qt::Vertical);
980 aWheel->setRange(1, 99, 1);
981 connect( aWheel, SIGNAL(valueChanged(double)),
982 aSpeedNum, SLOT(display(double)) );
983 connect( aWheel, SIGNAL(valueChanged(double)),
984 this, SLOT(onSpeedChange(double)) );
985 TopLayout->addMultiCellWidget(aWheel, 1, 3, 3, 3, Qt::AlignRight);
987 QCheckBox* aCycleCheck = new QCheckBox("Cycled animation",myPlayFrame);
988 aCycleCheck->setChecked(myAnimator->isCycling());
989 connect(aCycleCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCyclingSlot(bool)));
990 TopLayout->addMultiCellWidget(aCycleCheck, 5, 5, 0, 3);
992 QCheckBox* aPropCheck = new QCheckBox("Use proportional timing",myPlayFrame);
993 aPropCheck->setChecked(myAnimator->isProportional());
994 connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool)));
995 TopLayout->addMultiCellWidget(aPropCheck, 6, 6, 0, 3);
997 QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame );
998 aSaveBox->setColumnLayout(0, Qt::Horizontal );
999 QGridLayout* aSaveLay = new QGridLayout(aSaveBox->layout());
1000 aSaveLay->setSpacing( 5 );
1001 aSaveLay->setMargin( 5 );
1003 mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox);
1004 aSaveLay->addMultiCellWidget(mySaveCheck, 0, 0, 0, 2);
1005 connect(mySaveCheck, SIGNAL( toggled(bool)),
1006 aWheel, SLOT( setDisabled(bool) ));
1008 QLabel* aPathLbl = new QLabel("Path:", aSaveBox);
1009 aPathLbl->setEnabled(false);
1010 connect(mySaveCheck, SIGNAL( toggled(bool)),
1011 aPathLbl, SLOT( setEnabled(bool) ));
1012 aSaveLay->addWidget(aPathLbl, 1, 0);
1014 myPathEdit = new QLineEdit(aSaveBox);
1015 myPathEdit->setEnabled(false);
1016 connect(mySaveCheck, SIGNAL( toggled(bool)),
1017 myPathEdit, SLOT( setEnabled(bool) ));
1018 aSaveLay->addWidget(myPathEdit, 1, 1);
1020 QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox);
1021 aBrowseBtn->setEnabled(false);
1022 connect(mySaveCheck, SIGNAL( toggled(bool)),
1023 aBrowseBtn, SLOT( setEnabled(bool) ));
1024 connect(aBrowseBtn, SIGNAL( clicked()),
1025 this, SLOT( onBrowse() ));
1026 mySaveCheck->setChecked(false);
1027 aSaveLay->addWidget(aBrowseBtn, 1, 2);
1029 TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3);
1031 aMainLayout->addWidget(myPlayFrame);
1033 QHBox* aPublishBox = new QHBox(this);
1034 aPublishBox->setSpacing(5);
1036 myPublishBtn = new QPushButton("Publish to study", aPublishBox);
1037 connect(myPublishBtn, SIGNAL(clicked()), this, SLOT(publishToStudy()));
1039 mySaveBtn = new QPushButton("Save Animation", aPublishBox);
1040 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1041 connect(mySaveBtn, SIGNAL(clicked()), this, SLOT(saveToStudy()));
1043 aMainLayout->addWidget(aPublishBox);
1046 QHBox* aBtnBox = new QHBox(this);
1047 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
1048 aBtnLayout->addStretch();
1050 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
1051 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
1053 SUIT_Study* aStudy = VISU::GetAppStudy(myModule);
1054 connect(aStudy, SIGNAL(destroyed()), this, SLOT(close()));
1056 aMainLayout->addWidget(aBtnBox);
1058 myPlayFrame->setEnabled(false);
1061 //************************************************************************
1062 VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg()
1067 //************************************************************************
1068 void VisuGUI_TimeAnimationDlg::onTypeChange (int index)
1071 myPropBtn->setEnabled(index != 0);
1074 myPlayFrame->setEnabled(false);
1077 //************************************************************************
1078 void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject)
1080 myPlayFrame->setEnabled(false);
1081 myAnimator->addField(VISU::GetSObject(theSObject));
1084 //************************************************************************
1085 void VisuGUI_TimeAnimationDlg::createFrames()
1088 SUIT_OverrideCursor c;
1090 for (int i = 0; i < myAnimator->getNbFields(); i++) {
1091 if (myAnimator->getFieldData(i).myPrs.empty())
1092 myAnimator->generatePresentations(i);
1094 if (myAnimator->getNbFrames() == 0) {
1095 myPlayFrame->setEnabled(false);
1097 SUIT_MessageBox::warn1(this,
1099 tr("MSG_NO_ANIMATIONDATA"),
1103 mySlider->setMaxValue(myAnimator->getNbFrames()-1);
1104 myPlayFrame->setEnabled(true);
1105 if (!myAnimator->generateFrames()) {
1107 //myPlayFrame->setEnabled(false);
1108 SUIT_MessageBox::warn1(this,
1110 myAnimator->getLastErrorMsg(),
1114 //myPlayFrame->setEnabled(true);
1117 //************************************************************************
1118 void VisuGUI_TimeAnimationDlg::onPlayPressed()
1120 if (myPlayBtn->isOn() && (!myAnimator->running())) {
1121 myPlayBtn->setIconSet(MYpausePixmap);
1122 if (mySaveCheck->isChecked())
1123 myAnimator->dumpTo(myPathEdit->text());
1125 myAnimator->dumpTo("");
1126 mySetupBtn->setEnabled(false);
1127 myGenBtn->setEnabled(false);
1128 myAnimator->startAnimation();
1130 myPlayBtn->setIconSet(MYplayPixmap);
1131 myAnimator->stopAnimation();
1132 mySetupBtn->setEnabled(true);
1133 myGenBtn->setEnabled(true);
1137 //************************************************************************
1138 void VisuGUI_TimeAnimationDlg::onBackPressed()
1141 myAnimator->prevFrame();
1144 //************************************************************************
1145 void VisuGUI_TimeAnimationDlg::onForvardPressed()
1147 myAnimator->nextFrame();
1150 //************************************************************************
1151 void VisuGUI_TimeAnimationDlg::onLastPressed()
1153 myAnimator->lastFrame();
1156 //************************************************************************
1157 void VisuGUI_TimeAnimationDlg::onFirstPressed()
1159 myAnimator->firstFrame();
1162 //************************************************************************
1163 void VisuGUI_TimeAnimationDlg::clearView()
1165 myAnimator->clearView();
1168 //************************************************************************
1169 void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent)
1171 myAnimator->stopAnimation();
1172 myAnimator->wait(500);
1173 if (myAnimator->running() && (! myAnimator->finished())) {
1177 QDialog::closeEvent(theEvent);
1181 //************************************************************************
1182 void VisuGUI_TimeAnimationDlg::onWindowChanged (int index)
1184 if (myAnimator->isRunning()) return;
1185 myAnimator->gotoFrame(index);
1188 //************************************************************************
1189 void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed)
1191 myAnimator->setSpeed((int)theSpeed);
1194 //************************************************************************
1195 void VisuGUI_TimeAnimationDlg::stopAnimation()
1197 myAnimator->stopAnimation();
1198 myPlayBtn->setOn(false);
1199 myPlayBtn->setIconSet(MYplayPixmap);
1200 mySetupBtn->setEnabled(true);
1201 myGenBtn->setEnabled(true);
1204 //************************************************************************
1205 void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime)
1207 myTimeLbl->setText(QString("%1").arg(theTime));
1208 mySlider->setValue(theNewFrame);
1211 //************************************************************************
1212 void VisuGUI_TimeAnimationDlg::onSetupDlg()
1214 if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame();
1215 SetupDlg* aDlg = new SetupDlg (myModule, myAnimator);
1217 myPlayFrame->setEnabled(false);
1221 //************************************************************************
1222 void VisuGUI_TimeAnimationDlg::onBrowse()
1224 QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/","Select path");
1225 if (!aPath.isEmpty())
1226 myPathEdit->setText(aPath);
1229 //************************************************************************
1230 void VisuGUI_TimeAnimationDlg::onStop()
1233 QDialog::closeEvent(myEvent);
1235 myPlayBtn->setOn(false);
1236 myPlayBtn->setIconSet(MYplayPixmap);
1237 mySetupBtn->setEnabled(true);
1238 myGenBtn->setEnabled(true);
1242 //************************************************************************
1243 void VisuGUI_TimeAnimationDlg::saveToStudy()
1245 myAnimator->saveAnimation();
1246 VISU::UpdateObjBrowser(myModule, true);
1249 //************************************************************************
1250 void VisuGUI_TimeAnimationDlg::publishToStudy()
1252 myAnimator->publishInStudy();
1253 VISU::UpdateObjBrowser(myModule, true);
1254 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());
1257 //************************************************************************
1258 void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation)
1260 myAnimator->restoreFromStudy(theAnimation);
1261 mySaveBtn->setEnabled(myAnimator->isSavedInStudy());