From 1812aeca5e4d0c12d2ed079aa07b61bdb64dcc3c Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 12 May 2005 10:10:28 +0000 Subject: [PATCH] Animation with offsetted presentations --- src/VISUGUI/VisuGUI_TimeAnimation.cxx | 220 +++++++++++++++++++++++++- src/VISUGUI/VisuGUI_TimeAnimation.h | 43 +++++ src/VISU_I/VISU_TimeAnimation.cxx | 6 +- src/VISU_I/VISU_TimeAnimation.h | 1 + 4 files changed, 267 insertions(+), 3 deletions(-) diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.cxx b/src/VISUGUI/VisuGUI_TimeAnimation.cxx index d4465510..62273ad2 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.cxx +++ b/src/VISUGUI/VisuGUI_TimeAnimation.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include "QAD_Application.h" #include "QAD_Desktop.h" @@ -42,10 +43,210 @@ #include "VISU_CutLines_i.hh" #include "VISU_Vectors_i.hh" #include "VISU_StreamLines_i.hh" +#include "VISU_Actor.h" static double MAXVALUE = 1.0E+300; +#define MAXVAL 1e10 + + + +ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator) + : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myAnimator(theAnimator) +{ + myCurrent = 0; + init(); + QStringList aFieldNames; + // Find names of fields + for (int i = 0; i < theAnimator->getNbFields(); i++) { + aFieldNames.append(VisuGUI::getValue(theAnimator->getFieldData(i).myField, "myName")); + Offset aOffs; + aOffs.myOffset[0] = myAnimator->getFieldData(i).myOffset[0]; + aOffs.myOffset[1] = myAnimator->getFieldData(i).myOffset[1]; + aOffs.myOffset[2] = myAnimator->getFieldData(i).myOffset[2]; + myOffsets.append(aOffs); + } + myFieldLst->insertStringList(aFieldNames); + myFieldLst->setSelected(0, true); +} + + +void ArrangeDlg::init() +{ + setCaption("Arrange Presentations"); + setSizeGripEnabled( TRUE ); + + QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6); + aMainLayout->setSpacing(5); + + QButtonGroup* aBtnGrp = new QButtonGroup(2, Qt::Horizontal, this); + aBtnGrp->setExclusive(true); + aMainLayout->addWidget(aBtnGrp); + + QRadioButton* aAutoBtn = new QRadioButton("Auto", aBtnGrp); + aBtnGrp->insert(aAutoBtn, AutoMode); + + QRadioButton* aManualBtn = new QRadioButton("Manual", aBtnGrp); + aBtnGrp->insert(aManualBtn, ManualMode); + aBtnGrp->setButton(AutoMode); + + myStackWgt = new QWidgetStack(this); + aMainLayout->addWidget(myStackWgt); + + // AUTO Pane + QVBox* aAutoPane = new QVBox(myStackWgt); + aAutoPane->setSpacing(5); + // Axis Group + myAxisGrp = new QButtonGroup(3, Qt::Horizontal,"Axis", aAutoPane); + + QRadioButton* aXBtn = new QRadioButton("X",myAxisGrp ); + myAxisGrp->insert(aXBtn, XAxis); + + QRadioButton* aYBtn = new QRadioButton("Y",myAxisGrp ); + myAxisGrp->insert(aYBtn, YAxis); + + QRadioButton* aZBtn = new QRadioButton("Z",myAxisGrp ); + myAxisGrp->insert(aZBtn, ZAxis); + + myAxisGrp->setButton(XAxis); + + //Distance Input + QHBox* aDistPane = new QHBox(aAutoPane); + aDistPane->setSpacing(5); + new QLabel("Distance", aDistPane); + myDistVal = new QAD_SpinBoxDbl(aDistPane, -5, 5, 0.5 ); + myDistVal->setValue(0.5); + + myStackWgt->addWidget(aAutoPane, AutoMode); + + // Manual Pane + QHBox* aManualPane = new QHBox(myStackWgt); + aManualPane->setSpacing(10); + + myFieldLst = new QListBox(aManualPane); + connect( myFieldLst, SIGNAL( highlighted(int) ), + this, SLOT( onFieldChange(int) ) ); + + QGrid* aCoordPane = new QGrid(2, aManualPane); + aCoordPane->setSpacing(5); + + new QLabel("X", aCoordPane); + myCoord[0] = new QAD_SpinBoxDbl(aCoordPane); + myCoord[0]->setRange(-MAXVAL, MAXVAL); + + new QLabel("Y", aCoordPane); + myCoord[1] = new QAD_SpinBoxDbl(aCoordPane); + myCoord[1]->setRange(-MAXVAL, MAXVAL); + + new QLabel("Z", aCoordPane); + myCoord[2] = new QAD_SpinBoxDbl(aCoordPane); + myCoord[2]->setRange(-MAXVAL, MAXVAL); + + myStackWgt->addWidget(aManualPane, ManualMode); + + myStackWgt->raiseWidget(AutoMode); + + connect(aBtnGrp, SIGNAL(clicked(int)), myStackWgt, SLOT(raiseWidget(int)) ); + + // Common buttons =========================================================== + QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); + GroupButtons->setColumnLayout(0, Qt::Vertical ); + GroupButtons->layout()->setSpacing( 0 ); + GroupButtons->layout()->setMargin( 0 ); + QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setSpacing( 6 ); + GroupButtonsLayout->setMargin( 11 ); + + QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" ); + buttonOk->setAutoDefault( TRUE ); + buttonOk->setDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonOk, 0, 0 ); + GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + + QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" ); + buttonCancel->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonCancel, 0, 2 ); + + aMainLayout->addWidget( GroupButtons ); + + connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} + + +void ArrangeDlg::accept() +{ + if (getMode() == ManualMode) { + // Save from GUI + Offset& aOffs = myOffsets[myCurrent]; + aOffs.myOffset[0] = myCoord[0]->value(); + aOffs.myOffset[1] = myCoord[1]->value(); + aOffs.myOffset[2] = myCoord[2]->value(); + + for (int i = 0; i < myAnimator->getNbFields(); i++) { + Offset aOffs = myOffsets[i]; + myAnimator->getFieldData(i).myOffset[0] = aOffs.myOffset[0]; + myAnimator->getFieldData(i).myOffset[1] = aOffs.myOffset[1]; + myAnimator->getFieldData(i).myOffset[2] = aOffs.myOffset[2]; + } + } else { + QApplication::setOverrideCursor( Qt::waitCursor ); + FieldData& aData = myAnimator->getFieldData(0); + if (aData.myPrs.empty()) + myAnimator->generatePresentations(0); + VISU_Actor* aActor = aActor = aData.myPrs[0]->CreateActor(); + float aBounds[6]; + aActor->GetBounds(aBounds); + aActor->Delete(); + float aDist = 0; + int aAxis = getAxis(); + switch (aAxis) { + case XAxis: + aDist = fabs(aBounds[3] - aBounds[0]); + break; + case YAxis: + aDist = fabs(aBounds[4] - aBounds[1]); + break; + case ZAxis: + aDist = fabs(aBounds[5] - aBounds[2]); + } + aDist += aDist*getDistance(); + for (int i = 0; i < myAnimator->getNbFields(); i++) { + myAnimator->getFieldData(i).myOffset[0] = 0; + myAnimator->getFieldData(i).myOffset[1] = 0; + myAnimator->getFieldData(i).myOffset[2] = 0; + myAnimator->getFieldData(i).myOffset[aAxis] = aDist * i; + } + + QApplication::restoreOverrideCursor(); + } + QDialog::accept(); +} + +void ArrangeDlg::onFieldChange(int theCurrent) +{ + if (myCurrent != theCurrent) { + Offset& aOffs = myOffsets[myCurrent]; + aOffs.myOffset[0] = myCoord[0]->value(); + aOffs.myOffset[1] = myCoord[1]->value(); + aOffs.myOffset[2] = myCoord[2]->value(); + } + myCurrent = theCurrent; + const Offset& aNewOffs = myOffsets[myCurrent]; + myCoord[0]->setValue(aNewOffs.myOffset[0]); + myCoord[1]->setValue(aNewOffs.myOffset[1]); + myCoord[2]->setValue(aNewOffs.myOffset[2]); +} + + + + +//***************************************************************************************************** +//***************************************************************************************************** +//***************************************************************************************************** SetupDlg::SetupDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator) : QDialog( theParent, "SetupDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) { @@ -122,7 +323,10 @@ SetupDlg::SetupDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator) this, SLOT( onFieldChange(int) ) ); - QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame); + QVBox* aSetupBox = new QVBox(aPropFrame); + aSetupBox->setSpacing(5); + + QVGroupBox* aPropBox = new QVGroupBox("Properties", aSetupBox); myTypeCombo = new QComboBox(aPropBox); connect( myTypeCombo, SIGNAL( activated(int) ), this, SLOT( onTypeChanged(int) ) ); @@ -135,7 +339,11 @@ SetupDlg::SetupDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator) // myPropBtn->setEnabled(theAnimator->getFieldData(0).myPrsType != VISU::TSCALARMAP); connect( myPropBtn, SIGNAL( clicked() ), this, SLOT( onPreferencesDlg() ) ); - + + if (myAnimator->getNbFields() > 1) { + myArrangeBtn = new QPushButton("Arrange...", aSetupBox); + connect( myArrangeBtn, SIGNAL( clicked() ), this, SLOT( onArrangeDlg() ) ); + } onFieldChange(0); aMainLayout->addWidget(aPropFrame); @@ -292,6 +500,14 @@ void SetupDlg::onPreferencesDlg() { #undef EDITPRS } + +//************************************************************************ +void SetupDlg::onArrangeDlg() +{ + ArrangeDlg aDlg(this, myAnimator); + aDlg.exec(); +} + //************************************************************************ void SetupDlg::onRangeCheck(bool theCheck) { for (int i = 0; i < myAnimator->getNbFields(); i++) diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.h b/src/VISUGUI/VisuGUI_TimeAnimation.h index 1480326c..dbba957f 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.h +++ b/src/VISUGUI/VisuGUI_TimeAnimation.h @@ -16,6 +16,7 @@ #include #include #include +#include #include "VisuGUI_ScalarBarDlg.h" @@ -26,9 +27,49 @@ class VISU_TimeAnimation; + /** * Auxilliary class for presentations definition */ +class ArrangeDlg: public QDialog +{ + Q_OBJECT + public: + enum { AutoMode, ManualMode }; + enum { XAxis, YAxis, ZAxis }; + + ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator); + ~ArrangeDlg() {}; + + int getMode() const { return myStackWgt->id(myStackWgt->visibleWidget()); } + double getDistance() const { return myDistVal->value(); } + int getAxis() const { return myAxisGrp->id(myAxisGrp->selected()); } + +protected slots: + virtual void accept(); + void onFieldChange(int); + + private: + struct Offset { + float myOffset[3]; + }; + + + void init(); + + VISU_TimeAnimation* myAnimator; + QWidgetStack* myStackWgt; + QButtonGroup* myAxisGrp; + QAD_SpinBoxDbl* myDistVal; + QListBox* myFieldLst; + QAD_SpinBoxDbl* myCoord[3]; + QValueList myOffsets; + + int myCurrent; +}; + + + class SetupDlg: public QDialog { Q_OBJECT @@ -44,12 +85,14 @@ private slots: void onRangeCheck(bool theCheck); void onMinValue(double theVal); void onMaxValue(double theVal); + void onArrangeDlg(); private: VISU_TimeAnimation* myAnimator; QListBox* myFieldLst; QComboBox* myTypeCombo; QPushButton* myPropBtn; + QPushButton* myArrangeBtn; QCheckBox* myUseRangeChk; QAD_SpinBoxDbl* myMinVal; QAD_SpinBoxDbl* myMaxVal; diff --git a/src/VISU_I/VISU_TimeAnimation.cxx b/src/VISU_I/VISU_TimeAnimation.cxx index 2f16e023..c827743e 100644 --- a/src/VISU_I/VISU_TimeAnimation.cxx +++ b/src/VISU_I/VISU_TimeAnimation.cxx @@ -68,6 +68,7 @@ void VISU_TimeAnimation::addField(SALOMEDS::SObject_ptr theField) { aNewData.myField = SALOMEDS::SObject::_duplicate(theField); aNewData.myNbFrames = 0; aNewData.myPrsType = VISU::TSCALARMAP; + aNewData.myOffset[0] = aNewData.myOffset[1] = aNewData.myOffset[2] = 0; VISU::Storable::TRestoringMap aMap = getMapOfValue(aNewData.myField); aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong(); myFieldsLst.append(aNewData); @@ -224,8 +225,10 @@ void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum) { aData.myNbFrames = i; QString aFixRange = QAD_CONFIG->getSetting("Visu:SBImposeRange"); if (aFixRange.compare("true") != 0) { - for (i = 0; i < aData.myNbFrames; i++) + for (i = 0; i < aData.myNbFrames; i++) { aData.myPrs[i]->SetRange(aMin, aMax); + aData.myPrs[i]->SetOffset(aData.myOffset); + } if(aData.myPrsType == VISU::TISOSURFACE) for (i = 0; i < aData.myNbFrames; i++) if(VISU::IsoSurfaces_i* aPrs = dynamic_cast(aData.myPrs[i])) @@ -252,6 +255,7 @@ CORBA::Boolean VISU_TimeAnimation::generateFrames() { for (long j = 0; j < aData.myNbFrames; j++) { VISU_Actor* aActor = NULL; try{ + aData.myPrs[j]->SetOffset(aData.myOffset); aActor = aData.myPrs[j]->CreateActor(); myView->AddActor(aActor); if(j == 0) diff --git a/src/VISU_I/VISU_TimeAnimation.h b/src/VISU_I/VISU_TimeAnimation.h index 01de4065..9cdb13b4 100644 --- a/src/VISU_I/VISU_TimeAnimation.h +++ b/src/VISU_I/VISU_TimeAnimation.h @@ -34,6 +34,7 @@ struct FieldData std::vector myPrs; // Presentations std::vector myActors; // Actors std::vector myTiming; // time values + float myOffset[3]; }; -- 2.39.2