From e282b2663312cebaaa39825cb6c42f2916f4d5a9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 18 Aug 2005 08:55:17 +0000 Subject: [PATCH] This commit was generated by cvs2git to create branch 'BR-D5-38-2003'. Cherrypick from master 2005-08-18 08:55:16 UTC jfa 'Fix pb with Animation': src/OBJECT/VISU_MeshAct.cxx src/VISUGUI/VisuGUI_TimeAnimation.cxx src/VISU_I/VISU_Gen_i.hh --- src/OBJECT/VISU_MeshAct.cxx | 389 ++++++++ src/VISUGUI/VisuGUI_TimeAnimation.cxx | 1268 +++++++++++++++++++++++++ src/VISU_I/VISU_Gen_i.hh | 172 ++++ 3 files changed, 1829 insertions(+) create mode 100644 src/OBJECT/VISU_MeshAct.cxx create mode 100644 src/VISUGUI/VisuGUI_TimeAnimation.cxx create mode 100644 src/VISU_I/VISU_Gen_i.hh diff --git a/src/OBJECT/VISU_MeshAct.cxx b/src/OBJECT/VISU_MeshAct.cxx new file mode 100644 index 00000000..68f7446a --- /dev/null +++ b/src/OBJECT/VISU_MeshAct.cxx @@ -0,0 +1,389 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VISU_MeshAct.cxx +// Author : Laurent CORNABE with the help of Nicolas REJNERI +// Module : VISU +// $Header$ + +#include "VISU_MeshAct.h" +#include "VTKViewer_PassThroughFilter.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +vtkStandardNewMacro(VISU_MeshAct); + +VISU_MeshAct::VISU_MeshAct(){ + + vtkMatrix4x4 *m; + m = vtkMatrix4x4::New(); + + mySurfaceActor = VISU_Actor::New(); + mySurfaceActor->SetParent(this); + mySurfaceActor->GetProperty()->FrontfaceCullingOff(); + mySurfaceActor->GetProperty()->BackfaceCullingOff(); + mySurfaceActor->SetUserMatrix(m); + mySurfaceActor->SetRepresentation(2); //SURFACE + + myEdgeActor = VISU_Actor::New(); + myEdgeActor->SetParent(this); + myEdgeActor->PickableOff(); + myEdgeActor->GetProperty()->FrontfaceCullingOff(); + myEdgeActor->GetProperty()->BackfaceCullingOff(); + myEdgeActor->SetUserMatrix(m); + myEdgeActor->SetRepresentation(1); //WIREFRAME + + myNodeActor = VISU_Actor::New(); + myNodeActor->SetParent(this); + myNodeActor->PickableOff(); + myNodeActor->GetProperty()->SetPointSize(SALOME_POINT_SIZE); + myNodeActor->GetProperty()->FrontfaceCullingOff(); + myNodeActor->GetProperty()->BackfaceCullingOff(); + myNodeActor->SetUserMatrix(m); + myNodeActor->SetRepresentation(0); //POINT + + m->Delete(); + SetRepresentation(2); //SURFACE +} + +VISU_MeshAct::~VISU_MeshAct(){ + mySurfaceActor->Delete(); + myEdgeActor->Delete(); + myNodeActor->Delete(); +} + +void VISU_MeshAct::setIO(const Handle(SALOME_InteractiveObject)& theIO){ + VISU_Actor::setIO(theIO); + mySurfaceActor->setIO(theIO); + myEdgeActor->setIO(theIO); + myNodeActor->setIO(theIO); +} + +void VISU_MeshAct::SetPrs3d(VISU::Prs3d_i* thePrs3d){ + if(thePrs3d){ + VISU_Actor::SetPrs3d(thePrs3d); + mySurfaceActor->SetPrs3d(thePrs3d); + myEdgeActor->SetPrs3d(thePrs3d); + myNodeActor->SetPrs3d(thePrs3d); + } +} + +void VISU_MeshAct::AddToRender(vtkRenderer* theRenderer){ + VISU_Actor::AddToRender(theRenderer); + theRenderer->AddActor(myEdgeActor); +} + +void VISU_MeshAct::RemoveFromRender(vtkRenderer* theRenderer){ + VISU_Actor::RemoveFromRender(theRenderer); + theRenderer->RemoveActor(myEdgeActor); +} + +void VISU_MeshAct::SetPipeLine(VISU_PipeLine* thePipeLine) { + VISU_Actor::SetPipeLine(thePipeLine); + mySurfaceActor->SetPipeLine(thePipeLine); + myEdgeActor->SetPipeLine(thePipeLine); + myNodeActor->SetPipeLine(thePipeLine); +} + +void VISU_MeshAct::SetTransform(VTKViewer_Transform* theTransform){ + VISU_Actor::SetTransform(theTransform); + mySurfaceActor->SetTransform(theTransform); + myEdgeActor->SetTransform(theTransform); + myNodeActor->SetTransform(theTransform); +} + +void VISU_MeshAct::SetShrinkable(bool theIsShrinkable){ + VISU_Actor::SetShrinkable(theIsShrinkable); + mySurfaceActor->SetShrinkable(theIsShrinkable); + myEdgeActor->SetShrinkable(theIsShrinkable); + myNodeActor->SetShrinkable(theIsShrinkable); +} + +void VISU_MeshAct::SetShrinkFactor(float theValue){ + VISU_Actor::SetShrinkFactor(theValue); + mySurfaceActor->SetShrinkFactor(theValue); + myEdgeActor->SetShrinkFactor(theValue); +} + +vtkProperty* VISU_MeshAct::GetSurfaceProperty(){ + return mySurfaceActor->GetProperty(); +} + +void VISU_MeshAct::SetSurfaceProperty(vtkProperty* theProperty){ + mySurfaceActor->SetProperty(theProperty); +} + +vtkProperty* VISU_MeshAct::GetEdgeProperty(){ + return myEdgeActor->GetProperty(); +} + +void VISU_MeshAct::SetEdgeProperty(vtkProperty* theProperty){ + myEdgeActor->SetProperty(theProperty); +} + +vtkProperty* VISU_MeshAct::GetNodeProperty(){ + return myNodeActor->GetProperty(); +} + +void VISU_MeshAct::SetNodeProperty(vtkProperty* theProperty){ + myNodeActor->SetProperty(theProperty); +} + +void VISU_MeshAct::SetOpacity(float theValue){ + GetSurfaceProperty()->SetOpacity(theValue); +} + +float VISU_MeshAct::GetOpacity(){ + return GetSurfaceProperty()->GetOpacity(); +} + +void VISU_MeshAct::SetLineWidth(float theLineWidth){ + GetEdgeProperty()->SetLineWidth(theLineWidth); +} + +float VISU_MeshAct::GetLineWidth(){ + return GetEdgeProperty()->GetLineWidth(); +} + +void VISU_MeshAct::SetShrink(){ + if(myRepresentation == VTK_POINTS) + return; + VISU_Actor::SetShrink(); + mySurfaceActor->SetShrink(); + myEdgeActor->SetShrink(); + //SetRepresentation(GetRepresentation()); +} + +void VISU_MeshAct::UnShrink(){ + VISU_Actor::UnShrink(); + mySurfaceActor->UnShrink(); + myEdgeActor->UnShrink(); + //SetRepresentation(GetRepresentation()); +} + +void VISU_MeshAct::SetRepresentation(int theMode) +{ + SALOME_Actor::SetRepresentation(theMode); + + if (!GetVisibility()) return; // Fix IPAL9555 + + mySurfaceActor->VisibilityOff(); + myEdgeActor->VisibilityOff(); + myNodeActor->VisibilityOff(); + myEdgeActor->PickableOff(); + myNodeActor->PickableOff(); + switch (theMode) { + case VTK_POINTS: + myNodeActor->VisibilityOn(); + myNodeActor->PickableOn(); + break; + case VTK_WIREFRAME: + myEdgeActor->VisibilityOn(); + myEdgeActor->SetRepresentation(1); + myEdgeActor->PickableOn(); + break; + case VTK_SURFACE: + mySurfaceActor->VisibilityOn(); + break; + case 3: //INSIDEFRAME + myEdgeActor->VisibilityOn(); + myEdgeActor->SetRepresentation(3); + myEdgeActor->PickableOn(); + break; + case 4: //SURFACEFRAME + myEdgeActor->VisibilityOn(); + myEdgeActor->SetRepresentation(1); + mySurfaceActor->VisibilityOn(); + break; + } + if (myRepresentation == VTK_POINTS) + UnShrink(); +} + +void VISU_MeshAct::SetVisibility(int theMode){ + VISU_Actor::SetVisibility(theMode); + if(GetVisibility()) + SetRepresentation(GetRepresentation()); + else{ + myNodeActor->VisibilityOff(); + myEdgeActor->VisibilityOff(); + mySurfaceActor->VisibilityOff(); + } +} + +// From vtkLODActor +void VISU_MeshAct::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m)) +{ + float myTime, bestTime, tempTime; + vtkMatrix4x4 *matrix; + vtkMapper *mapper, *bestMapper; + + if (this->Mapper == NULL) + { + vtkErrorMacro("No mapper for actor."); + return; + } + + // first time through create lods if non have been added + if (this->LODMappers->GetNumberOfItems() == 0) + { + this->CreateOwnLODs(); + } + + // If the actor has changed or the primary mapper has changed ... + // Is this the correct test? + if (this->MediumMapper) + { + if (this->GetMTime() > this->BuildTime || + this->Mapper->GetMTime() > this->BuildTime) + { + this->UpdateOwnLODs(); + } + } + + // figure out how much time we have to render + myTime = this->AllocatedRenderTime; + + // Figure out which resolution to use + // none is a valid resolution. Do we want to have a lowest: + // bbox, single point, ... + // There is no order to the list, so it is assumed that mappers that take + // longer to render are better quality. + // Timings might become out of date, but we rely on + + bestMapper = this->Mapper; + bestTime = bestMapper->GetTimeToDraw(); + if (bestTime > myTime) + { + this->LODMappers->InitTraversal(); + while ((mapper = this->LODMappers->GetNextItem()) != NULL && + bestTime != 0.0) + { + tempTime = mapper->GetTimeToDraw(); + + // If the LOD has never been rendered, select it! + if (tempTime == 0.0) + { + bestMapper = mapper; + bestTime = 0.0; + } + else + { + if (bestTime > myTime && tempTime < bestTime) + { + bestMapper = mapper; + bestTime = tempTime; + } + if (tempTime > bestTime && tempTime < myTime) + { + bestMapper = mapper; + bestTime = tempTime; + } + } + } + } + + switch(GetRepresentation()){ + case 0: //POINTS + myNodeActor->GetProperty()->Render(this, ren); + break; + case 1: //WIREFRAME + //PAL5268: myEdgeActor->GetProperty()->Render(this, ren); + break; + case 2: //SURFACE + mySurfaceActor->GetProperty()->Render(this, ren); + break; + case 3: //INSIDEFRAME + //PAL5268: myEdgeActor->GetProperty()->Render(this, ren); + break; + case 4: //SURFACEFRAME + //PAL5268: myEdgeActor->GetProperty()->Render(this, ren); + mySurfaceActor->GetProperty()->Render(this, ren); + break; + } + + // render the texture + if (this->Texture) + { + this->Texture->Render(ren); + } + + switch(GetRepresentation()){ + case 0: //POINTS + matrix = myNodeActor->GetUserMatrix(); + break; + case 1: //WIREFRAME + matrix = myEdgeActor->GetUserMatrix(); + break; + case 2: //SURFACE + matrix = mySurfaceActor->GetUserMatrix(); + break; + case 3: //INSIDEFRAME + matrix = myEdgeActor->GetUserMatrix(); + break; + case 4: //SURFACEFRAME + matrix = myEdgeActor->GetUserMatrix(); + this->GetMatrix(matrix); + matrix = mySurfaceActor->GetUserMatrix(); + break; + } + this->GetMatrix(matrix); + + switch(GetRepresentation()){ + case 0: //POINTS + myNodeActor->Render(ren,bestMapper); + break; + case 1: //WIREFRAME + //PAL5268: myEdgeActor->Render(ren,bestMapper); + break; + case 2: //SURFACE + mySurfaceActor->Render(ren,bestMapper); + break; + case 3: //INSIDEFRAME + //PAL5268: myEdgeActor->Render(ren,bestMapper); + break; + case 4: //SURFACEFRAME + //PAL5268: myEdgeActor->Render(ren,bestMapper); + mySurfaceActor->Render(ren,bestMapper); + break; + } + + this->EstimatedRenderTime = bestMapper->GetTimeToDraw(); +} + +// From vtkLODActor +void VISU_MeshAct::Modified() +{ + myNodeActor->Modified(); + //PAL5268: myEdgeActor->Modified(); + mySurfaceActor->Modified(); + this->vtkActor::Modified(); +} diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.cxx b/src/VISUGUI/VisuGUI_TimeAnimation.cxx new file mode 100644 index 00000000..0598764e --- /dev/null +++ b/src/VISUGUI/VisuGUI_TimeAnimation.cxx @@ -0,0 +1,1268 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VisuGUI_TimeAnimation.cxx +// Author : Vitaly SMETANNIKOV +// Module : VISU + +#include "VisuGUI_TimeAnimation.h" + +#include "VisuGUI.h" +#include "VisuGUI_Tools.h" +#include "VisuGUI_DeformedShapeDlg.h" +#include "VisuGUI_CutPlanesDlg.h" +#include "VisuGUI_Plot3DDlg.h" +#include "VisuGUI_VectorsDlg.h" +#include "VisuGUI_IsoSurfacesDlg.h" +#include "VisuGUI_StreamLinesDlg.h" + +#include "VISU_TimeAnimation.h" + +#include "VISU_ScalarMap_i.hh" +#include "VISU_IsoSurfaces_i.hh" +#include "VISU_DeformedShape_i.hh" +#include "VISU_CutPlanes_i.hh" +#include "VISU_Plot3D_i.hh" +#include "VISU_CutLines_i.hh" +#include "VISU_Vectors_i.hh" +#include "VISU_StreamLines_i.hh" + +#include "VISU_ViewManager_i.hh" + +#include "VISU_ScalarBarActor.hxx" +#include "VISU_Actor.h" + +#include "SalomeApp_Study.h" +#include "SalomeApp_Application.h" + +#include "SVTK_ViewWindow.h" + +#include "SUIT_OverrideCursor.h" +#include "SUIT_MessageBox.h" +#include "SUIT_Desktop.h" +#include "SUIT_FileDlg.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAXVAL 1e10 + +ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator) + : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myAnimator(theAnimator), myViewWindow(theAnimator->getViewer()) +{ + myCurrent = 0; + init(); + QStringList aFieldNames; + // Find names of fields + for (int i = 0; i < theAnimator->getNbFields(); i++) { + aFieldNames.append(VISU::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); +} + +ArrangeDlg::ArrangeDlg(QWidget* theParent, SVTK_ViewWindow* theViewWindow) + : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | + WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myAnimator(0), myViewWindow(theViewWindow) +{ + myCurrent = 0; + init(); + QStringList aPrsNames; + vtkActor* anActor; + vtkActorCollection *anActColl = myViewWindow->getRenderer()->GetActors(); + for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL;) { + VISU_Actor* anVISUActor = dynamic_cast(anActor); + if (anVISUActor) + if (anVISUActor->GetVisibility() != 0) { + VISU::Prs3d_i* aPrs = anVISUActor->GetParent()->GetPrs3d(); + if (aPrs) { + if (!myPrsMap.contains(aPrs)) { + SALOMEDS::SObject_var aSObject = aPrs->GetSObject(); + if(!aSObject->_is_nil()){ + SALOMEDS::GenericAttribute_var anAttr; + if (aSObject->FindAttribute(anAttr, "AttributeName")) { + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + string aNam = aName->Value(); + QString strIn(aNam.c_str()); + aPrsNames.append(strIn); + myPrsMap[aPrs] = myOffsets.count(); + Offset aOffs; + anVISUActor->GetPosition(aOffs.myOffset); + myOffsets.append(aOffs); + } + } + } + } + } + } + myFieldLst->insertStringList(aPrsNames); + 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("Relative Distance", aDistPane); + myDistVal = new QtxDblSpinBox (-10,10, 0.5, aDistPane); + myDistVal->setValue(1); + + 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 QtxDblSpinBox(aCoordPane); + myCoord[0]->setRange(-MAXVAL, MAXVAL); + + new QLabel("Y", aCoordPane); + myCoord[1] = new QtxDblSpinBox(aCoordPane); + myCoord[1]->setRange(-MAXVAL, MAXVAL); + + new QLabel("Z", aCoordPane); + myCoord[2] = new QtxDblSpinBox(aCoordPane); + myCoord[2]->setRange(-MAXVAL, MAXVAL); + + myStackWgt->addWidget(aManualPane, ManualMode); + + myStackWgt->raiseWidget(AutoMode); + + connect(aBtnGrp, SIGNAL(clicked(int)), myStackWgt, SLOT(raiseWidget(int)) ); + + SUIT_Study* aSUITStudy = myViewWindow->getViewManager()->study(); + SalomeApp_Study* anAppStudy = dynamic_cast(aSUITStudy); + _PTR(Study) aCStudy = VISU::GetCStudy(anAppStudy); + if (!myAnimator && !aCStudy->GetProperties()->IsLocked()) { + mySaveChk = new QCheckBox ("Save to presentation", this); + mySaveChk->setChecked(false); + aMainLayout->addWidget(mySaveChk); + } else { + mySaveChk = 0; + } + + // 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 (myAnimator) { + acceptAnimation(); + } else { + acceptViewWindow(); + } + 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]); +} + +void ArrangeDlg::acceptAnimation() +{ + 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 = 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[1] - aBounds[0]); + break; + case YAxis: + aDist = fabs(aBounds[3] - aBounds[2]); + break; + case ZAxis: + aDist = fabs(aBounds[5] - aBounds[4]); + } + + float dx = fabs(aBounds[1] - aBounds[0]); + float dy = fabs(aBounds[3] - aBounds[2]); + float dz = fabs(aBounds[5] - aBounds[4]); + float max = (dx > dy) ? dx : dy; + max = (dz > max) ? dz : max; + max /= 100.0; + + if (aDist < max) { + // set base distance between centers of bounding boxes + // to minimal (but big enough) size of current bounding box + if (dx < max) dx = FLT_MAX; + if (dy < max) dy = FLT_MAX; + if (dz < max) dz = FLT_MAX; + + aDist = (dx < dy) ? dx : dy; + aDist = (dz < aDist) ? dz : aDist; + } + 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(); + } +} + +void ArrangeDlg::acceptViewWindow() +{ + 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(); + + QMap::Iterator it; + for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it) { + VISU::Prs3d_i* aPrs = it.key(); + Offset& aOffs = myOffsets[it.data()]; + if (VISU_Actor* anActor = VISU::GetActor(aPrs, myViewWindow)) + anActor->SetPosition(aOffs.myOffset); + if (mySaveChk) + if (mySaveChk->isChecked()) + aPrs->SetOffset(aOffs.myOffset); + } + } else { + float aDist = 0; + float aShift = 0; + float aPrevDist = 0; + float aPrevShift = 0; + int i; + QMap::Iterator it; + for (it = myPrsMap.begin(), i = 0; it != myPrsMap.end(); ++it, i++) { + VISU::Prs3d_i* aPrs = it.key(); + if (VISU_Actor* aActor = VISU::GetActor(aPrs, myViewWindow)) { + int aAxis = getAxis(); + + float aZeroOffset[3]; + aZeroOffset[0] = aZeroOffset[1] = aZeroOffset[2] = 0; + aActor->SetPosition(aZeroOffset); + aActor->GetMapper()->Update(); + + float aBounds[6]; + aActor->GetBounds(aBounds); + switch (aAxis) { + case XAxis: + aDist = fabs(aBounds[1] - aBounds[0]); + break; + case YAxis: + aDist = fabs(aBounds[3] - aBounds[2]); + break; + case ZAxis: + aDist = fabs(aBounds[5] - aBounds[4]); + } + float aOffset[3]; + aOffset[0] = (aBounds[1] < aBounds[0]) ? -aBounds[1] : -aBounds[0]; + aOffset[1] = (aBounds[3] < aBounds[2]) ? -aBounds[3] : -aBounds[2]; + aOffset[2] = (aBounds[5] < aBounds[4]) ? -aBounds[5] : -aBounds[4]; + + if (i > 0) { + float aCCDist = (aDist + aPrevDist) / 2.0; + + float dx = fabs(aBounds[1] - aBounds[0]); + float dy = fabs(aBounds[3] - aBounds[2]); + float dz = fabs(aBounds[5] - aBounds[4]); + float max = (dx > dy) ? dx : dy; + max = (dz > max) ? dz : max; + max /= 100.0; + + if (aCCDist < max) { + // set base distance between centers of bounding boxes + // to minimal (but big enough) size of current bounding box + if (dx < max) dx = FLT_MAX; + if (dy < max) dy = FLT_MAX; + if (dz < max) dz = FLT_MAX; + + aCCDist = (dx < dy) ? dx : dy; + aCCDist = (dz < aCCDist) ? dz : aCCDist; + } + + //--------------------------------> + // aShift + // aDist / 2 + // <--> + // .--------------. .------. + //----------->| | | | + // aPrevShift '--------------' '------' + // <------> + // aPrevDist / 2 + // + // <---------------> + // (aDist + aPrevDist) * getDistance() / 2 + + aShift = aPrevShift + aPrevDist/2.0 + aCCDist*getDistance() - aDist/2.0; + } + + aOffset[aAxis] += aShift; + aActor->SetPosition(aOffset); + if (mySaveChk) + if (mySaveChk->isChecked()) + aPrs->SetOffset(aOffset); + + aPrevDist = aDist; + aPrevShift = aShift; + } + } + } + myViewWindow->getRenderer()->ResetCameraClippingRange(); + myViewWindow->Repaint(); +} + + +//***************************************************************************************************** +//***************************************************************************************************** +//***************************************************************************************************** +SetupDlg::SetupDlg (VisuGUI* theModule, VISU_TimeAnimation* theAnimator) + : QDialog(VISU::GetDesktop(theModule), "SetupDlg", true, WStyle_Customize | + WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myModule(theModule) +{ + setCaption("Setup Animation"); + setSizeGripEnabled( TRUE ); + myAnimator = theAnimator; + + QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6); + aMainLayout->setSpacing(5); + + + QFrame* aRangeGrp = new QFrame(this); + QGridLayout* aRangeLayout = new QGridLayout( aRangeGrp ); + aRangeLayout->setSpacing( 6 ); + aRangeLayout->setMargin( 11 ); + aRangeGrp->setFrameStyle(QFrame::Box | QFrame::Raised); + + myUseRangeChk = new QCheckBox("Use range of time stamps", aRangeGrp); + aRangeLayout->addMultiCellWidget(myUseRangeChk, 0, 0, 0, 3); + myUseRangeChk->setChecked(myAnimator->isRangeDefined()); + + QLabel* aMinLbl = new QLabel("From", aRangeGrp); + aMinLbl->setEnabled(myUseRangeChk->isChecked()); + aRangeLayout->addWidget(aMinLbl, 1, 0); + double aStep = (myAnimator->getMaxTime() - myAnimator->getMinTime())/(theAnimator->getFieldData(0).myNbTimes - 1); + myMinVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp ); + myMinVal->setEnabled(myUseRangeChk->isChecked()); + if (myUseRangeChk->isChecked()) + myMinVal->setValue( myAnimator->getMinRange() ); + else + myMinVal->setValue( myAnimator->getMinTime() ); + + connect(myMinVal, SIGNAL( valueChanged(double)), + this, SLOT( onMinValue(double) )); + aRangeLayout->addWidget(myMinVal, 1, 1); + + QLabel* aMaxLbl = new QLabel("To", aRangeGrp); + aMaxLbl->setEnabled(myUseRangeChk->isChecked()); + aRangeLayout->addWidget(aMaxLbl, 1, 2); + myMaxVal = new QtxDblSpinBox( myAnimator->getMinTime(), myAnimator->getMaxTime(), aStep, aRangeGrp ); + myMaxVal->setEnabled(myUseRangeChk->isChecked()); + if (myUseRangeChk->isChecked()) + myMaxVal->setValue( myAnimator->getMaxRange() ); + else + myMaxVal->setValue( myAnimator->getMaxTime() ); + + connect(myMaxVal, SIGNAL( valueChanged(double)), + this, SLOT( onMaxValue(double) )); + aRangeLayout->addWidget(myMaxVal, 1, 3); + + connect(myUseRangeChk, SIGNAL( toggled(bool)), + aMinLbl, SLOT( setEnabled(bool) )); + connect(myUseRangeChk, SIGNAL( toggled(bool)), + aMaxLbl, SLOT( setEnabled(bool) )); + connect(myUseRangeChk, SIGNAL( toggled(bool)), + this, SLOT( onRangeCheck(bool) )); + + aMainLayout->addWidget(aRangeGrp); + + + QHBox* aPropFrame = new QHBox(this); + aPropFrame->setSpacing(5); + + QVGroupBox* aNamesBox = new QVGroupBox("Fields",aPropFrame); + myFieldLst = new QListBox(aNamesBox); + QStringList aFieldNames; + // Find names of fields + for (int i = 0; i < theAnimator->getNbFields(); i++) { + _PTR(SObject) aSO = theAnimator->getFieldData(i).myField; + aFieldNames.append(VISU::getValue(aSO, "myName")); + } + myFieldLst->insertStringList(aFieldNames); + myFieldLst->setSelected(0, true); + connect( myFieldLst, SIGNAL( highlighted(int) ), + this, SLOT( onFieldChange(int) ) ); + + + QVBox* aSetupBox = new QVBox(aPropFrame); + aSetupBox->setSpacing(5); + + QVGroupBox* aPropBox = new QVGroupBox("Properties", aSetupBox); + //QVGroupBox* aPropBox = new QVGroupBox("Properties", aPropFrame); + myTypeCombo = new QComboBox(aPropBox); + connect( myTypeCombo, SIGNAL( activated(int) ), + this, SLOT( onTypeChanged(int) ) ); + + // QPushButton* aBarBtn = new QPushButton("Scalar Bar...", aPropBox); + //connect( aBarBtn, SIGNAL( clicked() ), + // this, SLOT( onScalarBarDlg() ) ); + + myPropBtn = new QPushButton("Properties...", aPropBox); + // 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); + + QHBox* aBtnBox = new QHBox(this); + QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout()); + aBtnLayout->addStretch(); + + QPushButton* aCloseBtn = new QPushButton(tr("BUT_OK"), aBtnBox); + connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close())); + + aMainLayout->addWidget(aBtnBox); +} + +//************************************************************************ +enum PrsComboItem { + TSCALARMAP_ITEM = 0, // VISU::TSCALARMAP + TISOSURFACE_ITEM = 1, // VISU::TISOSURFACE + TCUTPLANES_ITEM = 2, // VISU::TCUTPLANES + TPLOT3D_ITEM = 3, // VISU::TPLOT3D + TDEFORMEDSHAPE_ITEM = 4, // VISU::TDEFORMEDSHAPE + TVECTORS_ITEM = 5, // VISU::TVECTORS + TSTREAMLINES_ITEM = 6 // VISU::TSTREAMLINES +}; + +//************************************************************************ +void SetupDlg::onFieldChange (int theIndex) +{ + FieldData& aData = myAnimator->getFieldData(theIndex); + myTypeCombo->clear(); + // ATTENTION: append items in the same order like it is done in the PrsComboItem enumeration + myTypeCombo->insertItem("Scalar Map"); // item 0 + myTypeCombo->insertItem("Iso Surfaces"); // item 1 + myTypeCombo->insertItem("Cut Planes"); // item 2 + myTypeCombo->insertItem("Plot 3D"); // item 3 + + _PTR(SObject) aSObject = aData.myField; + long aNumComp = VISU::getValue(aSObject, "myNumComponent").toLong(); + if (aNumComp > 1) { + myTypeCombo->insertItem("Deformed Shape"); // item 4 + myTypeCombo->insertItem("Vectors"); // item 5 + myTypeCombo->insertItem("Stream Lines"); // item 6 + } + switch (aData.myPrsType) { + case VISU::TSCALARMAP: //Scalar Map + myTypeCombo->setCurrentItem(TSCALARMAP_ITEM); + break; + case VISU::TISOSURFACE: //Iso Surfaces + myTypeCombo->setCurrentItem(TISOSURFACE_ITEM); + break; + case VISU::TCUTPLANES: //Cut Planes + myTypeCombo->setCurrentItem(TCUTPLANES_ITEM); + break; + case VISU::TPLOT3D: //Plot 3D + myTypeCombo->setCurrentItem(TPLOT3D_ITEM); + break; + case VISU::TDEFORMEDSHAPE: //Deformed Shape + myTypeCombo->setCurrentItem(TDEFORMEDSHAPE_ITEM); + break; + case VISU::TVECTORS: //Vectors + myTypeCombo->setCurrentItem(TVECTORS_ITEM); + break; + case VISU::TSTREAMLINES: //Stream Lines + myTypeCombo->setCurrentItem(TSTREAMLINES_ITEM); + aData.myPrsType = VISU::TSTREAMLINES; + break; + } + //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP); +} + +//************************************************************************ +void SetupDlg::onTypeChanged (int theIndex) +{ + FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem()); + switch (theIndex) { + case TSCALARMAP_ITEM: //Scalar Map + aData.myPrsType = VISU::TSCALARMAP; + break; + case TISOSURFACE_ITEM: //Iso Surfaces + aData.myPrsType = VISU::TISOSURFACE; + break; + case TCUTPLANES_ITEM: //Cut Planes + aData.myPrsType = VISU::TCUTPLANES; + break; + case TPLOT3D_ITEM: //Plot 3D + aData.myPrsType = VISU::TPLOT3D; + break; + case TDEFORMEDSHAPE_ITEM: //Deformed Shape + aData.myPrsType = VISU::TDEFORMEDSHAPE; + break; + case TVECTORS_ITEM: //Vectors + aData.myPrsType = VISU::TVECTORS; + break; + case TSTREAMLINES_ITEM: //Stream Lines + aData.myPrsType = VISU::TSTREAMLINES; + break; + } + myAnimator->clearData(aData); + //myPropBtn->setEnabled(aData.myPrsType != VISU::TSCALARMAP); + //myAnimator->generatePresentations(myFieldLst->currentItem()); +} + +//************************************************************************ +/*void SetupDlg::onScalarBarDlg() { + QApplication::setOverrideCursor( Qt::waitCursor ); + FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem()); + if (aData.myPrs == 0) + myAnimator->generatePresentations(myFieldLst->currentItem()); + QApplication::restoreOverrideCursor(); + + VisuGUI_ScalarBarDlg* aScalarBarDlg = new VisuGUI_ScalarBarDlg(); + aScalarBarDlg->initFromPrsObject(aData.myPrs[0]); + if (aScalarBarDlg->exec()) { + for (int i = 0; i < aData.myNbFrames; i++) + aScalarBarDlg->storeToPrsObject(aData.myPrs[i]); + } +} +*/ + +//************************************************************************ +void SetupDlg::onPreferencesDlg() +{ + SUIT_OverrideCursor c; + FieldData& aData = myAnimator->getFieldData(myFieldLst->currentItem()); + if (aData.myPrs.empty()) + myAnimator->generatePresentations(myFieldLst->currentItem()); + +// BUG VISU5725 : Compatibility gcc 2.95 +// #define EDITPRS(TYPE, DLG) \ +// { \ +// DLG* aDlg = new DLG(); \ +// aDlg->initFromPrsObject(dynamic_cast(aData.myPrs.at(0))); \ +// if (aDlg->exec()) { \ +// for (int i = 0; i < aData.myNbFrames; i++) \ +// aDlg->storeToPrsObject(dynamic_cast(aData.myPrs.at(i))); \ +// } \ +// delete aDlg; \ +// } + + +#define EDITPRS(TYPE, DLG) {\ + DLG* aDlg = new DLG (myModule);\ + aDlg->initFromPrsObject(dynamic_cast(aData.myPrs[0]));\ + if (aDlg->exec())\ + { \ + for (int i = 0; i < aData.myNbFrames; i++)\ + aDlg->storeToPrsObject(dynamic_cast(aData.myPrs[i]));\ + } \ + delete aDlg;} + + switch (myTypeCombo->currentItem()) { + case TSCALARMAP_ITEM: //Scalar Map + c.suspend(); + EDITPRS(VISU::ScalarMap_i, VisuGUI_ScalarBarDlg); + break; + case TISOSURFACE_ITEM: //Iso Surfaces + c.suspend(); + EDITPRS(VISU::IsoSurfaces_i, VisuGUI_IsoSurfacesDlg); + break; + case TCUTPLANES_ITEM: //Cut Planes + c.suspend(); + EDITPRS(VISU::CutPlanes_i, VisuGUI_CutPlanesDlg); + /*{ + VisuGUI_CutPlanesDlg* aDlg = new VisuGUI_CutPlanesDlg (myModule); + //_CS_PhB :operator [] .at aDlg->initFromPrsObject(dynamic_cast(aData.myPrs.at(0))); + aDlg->initFromPrsObject(dynamic_cast(aData.myPrs[0])); + + if (aDlg->exec()) { + for (int i = 0; i < aData.myNbFrames; i++) + //_CS_PhB:operator [] .at aDlg->storeToPrsObject(dynamic_cast(aData.myPrs.at(i))); + aDlg->storeToPrsObject(dynamic_cast(aData.myPrs[i])); + } + delete aDlg; + }*/ + break; + case TPLOT3D_ITEM: //Plot 3D + c.suspend(); + EDITPRS(VISU::Plot3D_i, VisuGUI_Plot3DDlg); + break; + case TDEFORMEDSHAPE_ITEM: //Deformed Shape + c.suspend(); + EDITPRS(VISU::DeformedShape_i, VisuGUI_DeformedShapeDlg); + break; + case TVECTORS_ITEM: //Vectors + c.suspend(); + EDITPRS(VISU::Vectors_i, VisuGUI_VectorsDlg); + break; + case TSTREAMLINES_ITEM: //Stream Lines + c.suspend(); + EDITPRS(VISU::StreamLines_i, VisuGUI_StreamLinesDlg); + break; + } +#undef EDITPRS +} + + +//************************************************************************ +void SetupDlg::onArrangeDlg() +{ + ArrangeDlg aDlg(this, myAnimator); + aDlg.exec(); +} + +//************************************************************************ +void SetupDlg::onRangeCheck (bool theCheck) +{ + for (int i = 0; i < myAnimator->getNbFields(); i++) + myAnimator->clearData(myAnimator->getFieldData(i)); + + myMinVal->setEnabled(theCheck); + myMaxVal->setEnabled(theCheck); + + if (!theCheck) + myAnimator->setAnimationRange(0, 0); + else { + // if (myMinVal->value() < myMaxVal->value()) + myAnimator->setAnimationRange(myMinVal->value(), myMaxVal->value()); +// else if (myMinVal->value() > myMaxVal->value()) +// myAnimator->setAnimationRange(myMaxVal->value(), myMinVal->value()); +// else // equal case +// myAnimator->setAnimationRange(0, 0); + } +} + +//************************************************************************ +void SetupDlg::onMinValue (double theVal) +{ + if (theVal > myAnimator->getMaxRange()) { + myMinVal->setValue( myAnimator->getMinTime() ); + myMinVal->setFocus(); + return; + } + for (int i = 0; i < myAnimator->getNbFields(); i++) + myAnimator->clearData(myAnimator->getFieldData(i)); + myAnimator->setAnimationRange(theVal, myAnimator->getMaxRange()); +} + +//************************************************************************ +void SetupDlg::onMaxValue (double theVal) +{ + if (theVal < myAnimator->getMinRange()) { + myMaxVal->setValue( myAnimator->getMaxTime() ); + myMaxVal->setFocus(); + return; + } + for (int i = 0; i < myAnimator->getNbFields(); i++) + myAnimator->clearData(myAnimator->getFieldData(i)); + myAnimator->setAnimationRange(myAnimator->getMinRange(), theVal); +} + +static const char * firstIco[] = { +"18 10 2 1", +" g None", +". g #000000", +" . . ", +" .. .. .. ", +" .. ... ... ", +" .. .... .... ", +" .. ..... ..... ", +" .. ..... ..... ", +" .. .... .... ", +" .. ... ... ", +" .. .. .. ", +" . . "}; + + +static const char * lastIco[] = { +"18 10 2 1", +" g None", +". g #000000", +" . . ", +" .. .. .. ", +" ... ... .. ", +" .... .... .. ", +" ..... ..... .. ", +" ..... ..... .. ", +" .... .... .. ", +" ... ... .. ", +" .. .. .. ", +" . . "}; + + +static const char * leftIco[] = { +"11 10 2 1", +" g None", +". g #000000", +" . .", +" .. ..", +" ... ...", +" .... ....", +"..... .....", +"..... .....", +" .... ....", +" ... ...", +" .. ..", +" . ."}; + +static const char * playIco[] = { +"14 14 2 1", +" g None", +". g #000000", +" ", +" ", +" .. ", +" .... ", +" ...... ", +" ........ ", +" .......... ", +" .......... ", +" ........ ", +" ...... ", +" .... ", +" .. ", +" ", +" "}; + +static QPixmap MYplayPixmap(playIco); + + +static const char * rightIco[] = { +"11 10 2 1", +" g None", +". g #000000", +". . ", +".. .. ", +"... ... ", +".... .... ", +"..... .....", +"..... .....", +".... .... ", +"... ... ", +".. .. ", +". . "}; + + +static const char * pauseIco[] = { +"14 14 2 1", +" g None", +". g #000000", +" ", +" ", +" .. .. ", +" .. .. ", +" .. .. ", +" .. .. ", +" .. .. ", +" .. .. ", +" .. .. ", +" .. .. ", +" .. .. ", +" .. .. ", +" ", +" "}; + +static QPixmap MYpausePixmap(pauseIco); + + +VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Study) theStudy) + : QDialog(VISU::GetDesktop(theModule), "VisuGUI_TimeAnimationDlg", false, WStyle_Customize | + WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), + myModule(theModule), + myStudy(theStudy) +{ + setCaption("Animation"); + setSizeGripEnabled( TRUE ); + isClosing = false; + + myAnimator = new VISU_TimeAnimation (theStudy); + myAnimator->setSpeed(1); + myAnimator->setViewer(VISU::GetViewWindow()); + connect(myAnimator, SIGNAL(frameChanged(long, double)), this, SLOT(onExecution(long, double))); + connect(myAnimator, SIGNAL(stopped()), this, SLOT(onStop())); + + QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 6); + aMainLayout->setSpacing(5); + + mySetupBtn = new QPushButton("Setup Animation...", this); + connect( mySetupBtn, SIGNAL( clicked() ), + this, SLOT( onSetupDlg() ) ); + aMainLayout->addWidget(mySetupBtn); + + myGenBtn = new QPushButton("Generate frames", this); + connect( myGenBtn, SIGNAL( clicked() ), + this, SLOT( createFrames() ) ); + aMainLayout->addWidget(myGenBtn); + + myPlayFrame = new QFrame(this); + myPlayFrame->setFrameStyle(QFrame::WinPanel | QFrame::Sunken); + myPlayFrame->setLineWidth( 1 ); + + + // --- Play controls --- + QGridLayout* TopLayout = new QGridLayout( myPlayFrame ); + TopLayout->setSpacing( 6 ); + TopLayout->setMargin( 11 ); + + myTimeLbl = new QLabel("0", myPlayFrame); + TopLayout->addMultiCellWidget(myTimeLbl, 0, 0, 0, 2, Qt::AlignHCenter); + + mySlider = new QSlider(Qt::Horizontal, myPlayFrame); + mySlider->setMinValue(0); + mySlider->setMaxValue(3); + mySlider->setTickInterval(1); + //mySlider->setTickmarks(QSlider::Below); + mySlider->setTracking(false); + connect( mySlider, SIGNAL( valueChanged(int) ), + this, SLOT( onWindowChanged(int) ) ); + TopLayout->addMultiCellWidget(mySlider, 1, 1, 0, 2); + + myPlayBtn = new QToolButton(myPlayFrame); + myPlayBtn->setIconSet(MYplayPixmap); + myPlayBtn->setToggleButton(true); + connect( myPlayBtn, SIGNAL( clicked() ), + this, SLOT( onPlayPressed() ) ); + TopLayout->addMultiCellWidget(myPlayBtn, 2, 2, 0, 1); + + QToolButton* aBackBtn = new QToolButton(myPlayFrame); + aBackBtn->setIconSet(QPixmap(leftIco)); + connect( aBackBtn, SIGNAL( clicked() ), + this, SLOT( onBackPressed() ) ); + TopLayout->addWidget(aBackBtn, 3, 0); + + QToolButton* aForvardBtn = new QToolButton(myPlayFrame); + aForvardBtn->setIconSet(QPixmap(rightIco)); + connect( aForvardBtn, SIGNAL( clicked() ), + this, SLOT( onForvardPressed() ) ); + TopLayout->addWidget(aForvardBtn, 3, 1); + + QToolButton* aFirstBtn = new QToolButton(myPlayFrame); + aFirstBtn->setIconSet(QPixmap(firstIco)); + connect( aFirstBtn, SIGNAL( clicked() ), + this, SLOT( onFirstPressed() ) ); + TopLayout->addWidget(aFirstBtn, 4, 0); + + QToolButton* aLastBtn = new QToolButton(myPlayFrame); + aLastBtn->setIconSet(QPixmap(lastIco)); + connect( aLastBtn, SIGNAL( clicked() ), + this, SLOT( onLastPressed() ) ); + TopLayout->addWidget(aLastBtn, 4, 1); + + QLabel* aSpeedLbl = new QLabel("Speed", myPlayFrame); + TopLayout->addWidget(aSpeedLbl, 4, 2, Qt::AlignRight); + + QLCDNumber* aSpeedNum = new QLCDNumber( 2, myPlayFrame ); + aSpeedNum->setSegmentStyle(QLCDNumber::Flat); + aSpeedNum->display(1); + TopLayout->addWidget(aSpeedNum, 4, 3); + + QwtWheel* aWheel = new QwtWheel(myPlayFrame); + aWheel->setOrientation(Qt::Vertical); + aWheel->setRange(1, 99, 1); + connect( aWheel, SIGNAL(valueChanged(double)), + aSpeedNum, SLOT(display(double)) ); + connect( aWheel, SIGNAL(valueChanged(double)), + this, SLOT(onSpeedChange(double)) ); + TopLayout->addMultiCellWidget(aWheel, 1, 3, 3, 3, Qt::AlignRight); + + QCheckBox* aCycleCheck = new QCheckBox("Cycled animation",myPlayFrame); + aCycleCheck->setChecked(myAnimator->isCycling()); + connect(aCycleCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCyclingSlot(bool))); + TopLayout->addMultiCellWidget(aCycleCheck, 5, 5, 0, 3); + + QCheckBox* aPropCheck = new QCheckBox("Use proportional timing",myPlayFrame); + aPropCheck->setChecked(myAnimator->isProportional()); + connect(aPropCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setProportionalSlot(bool))); + TopLayout->addMultiCellWidget(aPropCheck, 6, 6, 0, 3); + + QGroupBox* aSaveBox = new QGroupBox( "Saving", myPlayFrame ); + aSaveBox->setColumnLayout(0, Qt::Horizontal ); + QGridLayout* aSaveLay = new QGridLayout(aSaveBox->layout()); + aSaveLay->setSpacing( 5 ); + aSaveLay->setMargin( 5 ); + + mySaveCheck = new QCheckBox("Save pictures to directory", aSaveBox); + aSaveLay->addMultiCellWidget(mySaveCheck, 0, 0, 0, 2); + connect(mySaveCheck, SIGNAL( toggled(bool)), + aWheel, SLOT( setDisabled(bool) )); + + QLabel* aPathLbl = new QLabel("Path:", aSaveBox); + aPathLbl->setEnabled(false); + connect(mySaveCheck, SIGNAL( toggled(bool)), + aPathLbl, SLOT( setEnabled(bool) )); + aSaveLay->addWidget(aPathLbl, 1, 0); + + myPathEdit = new QLineEdit(aSaveBox); + myPathEdit->setEnabled(false); + connect(mySaveCheck, SIGNAL( toggled(bool)), + myPathEdit, SLOT( setEnabled(bool) )); + aSaveLay->addWidget(myPathEdit, 1, 1); + + QPushButton* aBrowseBtn = new QPushButton("Browse...", aSaveBox); + aBrowseBtn->setEnabled(false); + connect(mySaveCheck, SIGNAL( toggled(bool)), + aBrowseBtn, SLOT( setEnabled(bool) )); + connect(aBrowseBtn, SIGNAL( clicked()), + this, SLOT( onBrowse() )); + mySaveCheck->setChecked(false); + aSaveLay->addWidget(aBrowseBtn, 1, 2); + + TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3); + + aMainLayout->addWidget(myPlayFrame); + + QHBox* aPublishBox = new QHBox(this); + aPublishBox->setSpacing(5); + + myPublishBtn = new QPushButton("Publish to study", aPublishBox); + connect(myPublishBtn, SIGNAL(clicked()), this, SLOT(publishToStudy())); + + mySaveBtn = new QPushButton("Save Animation", aPublishBox); + mySaveBtn->setEnabled(myAnimator->isSavedInStudy()); + connect(mySaveBtn, SIGNAL(clicked()), this, SLOT(saveToStudy())); + + aMainLayout->addWidget(aPublishBox); + + + QHBox* aBtnBox = new QHBox(this); + QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout()); + aBtnLayout->addStretch(); + + QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox); + connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close())); + + SUIT_Study* aStudy = VISU::GetAppStudy(myModule); + connect(aStudy, SIGNAL(destroyed()), this, SLOT(close())); + + aMainLayout->addWidget(aBtnBox); + + myPlayFrame->setEnabled(false); +} + +//************************************************************************ +VisuGUI_TimeAnimationDlg::~VisuGUI_TimeAnimationDlg() +{ + delete myAnimator; +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onTypeChange (int index) +{ + stopAnimation(); + myPropBtn->setEnabled(index != 0); + + clearView(); + myPlayFrame->setEnabled(false); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::addField (_PTR(SObject) theSObject) +{ + myPlayFrame->setEnabled(false); + myAnimator->addField(theSObject); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::createFrames() +{ + stopAnimation(); + SUIT_OverrideCursor c; + + for (int i = 0; i < myAnimator->getNbFields(); i++) { + if (myAnimator->getFieldData(i).myPrs.empty()) + myAnimator->generatePresentations(i); + } + if (myAnimator->getNbFrames() == 0) { + myPlayFrame->setEnabled(false); + c.suspend(); + SUIT_MessageBox::warn1(this, + tr("ERROR"), + tr("MSG_NO_ANIMATIONDATA"), + tr("&OK")); + return; + } + mySlider->setMaxValue(myAnimator->getNbFrames()-1); + myPlayFrame->setEnabled(true); + if (!myAnimator->generateFrames()) { + c.suspend(); + //myPlayFrame->setEnabled(false); + SUIT_MessageBox::warn1(this, + tr("ERROR"), + myAnimator->getLastErrorMsg(), + tr("&OK")); + return; + } + //myPlayFrame->setEnabled(true); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onPlayPressed() +{ + if (myPlayBtn->isOn() && (!myAnimator->running())) { + myPlayBtn->setIconSet(MYpausePixmap); + if (mySaveCheck->isChecked()) + myAnimator->dumpTo(myPathEdit->text()); + else + myAnimator->dumpTo(""); + mySetupBtn->setEnabled(false); + myGenBtn->setEnabled(false); + myAnimator->startAnimation(); + } else { + myPlayBtn->setIconSet(MYplayPixmap); + myAnimator->stopAnimation(); + mySetupBtn->setEnabled(true); + myGenBtn->setEnabled(true); + } +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onBackPressed() +{ + //stopAnimation(); + myAnimator->prevFrame(); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onForvardPressed() +{ + myAnimator->nextFrame(); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onLastPressed() +{ + myAnimator->lastFrame(); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onFirstPressed() +{ + myAnimator->firstFrame(); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::clearView() +{ + myAnimator->clearView(); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::closeEvent (QCloseEvent* theEvent) +{ + myAnimator->stopAnimation(); + myAnimator->wait(500); + if (myAnimator->running() && (! myAnimator->finished())) { + isClosing = true; + myEvent = theEvent; + } else { + QDialog::closeEvent(theEvent); + } +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onWindowChanged (int index) +{ + if (myAnimator->isRunning()) return; + myAnimator->gotoFrame(index); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onSpeedChange (double theSpeed) +{ + myAnimator->setSpeed((int)theSpeed); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::stopAnimation() +{ + myAnimator->stopAnimation(); + myPlayBtn->setOn(false); + myPlayBtn->setIconSet(MYplayPixmap); + mySetupBtn->setEnabled(true); + myGenBtn->setEnabled(true); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onExecution (long theNewFrame, double theTime) +{ + myTimeLbl->setText(QString("%1").arg(theTime)); + mySlider->setValue(theNewFrame); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onSetupDlg() +{ + if (myAnimator->getNbFrames() > 0) myAnimator->firstFrame(); + SetupDlg* aDlg = new SetupDlg (myModule, myAnimator); + aDlg->exec(); + myPlayFrame->setEnabled(false); + delete aDlg; +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onBrowse() +{ + QString aPath = SUIT_FileDlg::getExistingDirectory(this, "/","Select path"); + if (!aPath.isEmpty()) + myPathEdit->setText(aPath); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::onStop() +{ + if (isClosing) { + QDialog::closeEvent(myEvent); + } else { + myPlayBtn->setOn(false); + myPlayBtn->setIconSet(MYplayPixmap); + mySetupBtn->setEnabled(true); + myGenBtn->setEnabled(true); + } +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::saveToStudy() +{ + myAnimator->saveAnimation(); + VISU::UpdateObjBrowser(myModule, true); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::publishToStudy() +{ + myAnimator->publishInStudy(); + VISU::UpdateObjBrowser(myModule, true); + mySaveBtn->setEnabled(myAnimator->isSavedInStudy()); +} + +//************************************************************************ +void VisuGUI_TimeAnimationDlg::restoreFromStudy(_PTR(SObject) theAnimation) +{ + myAnimator->restoreFromStudy(theAnimation); + mySaveBtn->setEnabled(myAnimator->isSavedInStudy()); +} diff --git a/src/VISU_I/VISU_Gen_i.hh b/src/VISU_I/VISU_Gen_i.hh new file mode 100644 index 00000000..abaac0a6 --- /dev/null +++ b/src/VISU_I/VISU_Gen_i.hh @@ -0,0 +1,172 @@ +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : VISU_GEN_i.h file +// Author : Alexey Petrov +// Module : VISU +// $Header: + +#ifndef __VISU_GEN_I_H__ +#define __VISU_GEN_I_H__ + +#include "VISUConfig.hh" + +#include "SALOME_Component_i.hxx" +#include "SALOME_NamingService.hxx" + +namespace VISU{ + class Result_i; + class VISU_Gen_i : public virtual POA_VISU::VISU_Gen, + public virtual ::Engines_Component_i, + public virtual Base_i + { + SALOMEDS::Study_var myStudyDocument; + VISU_Gen_i(); + VISU_Gen_i(const VISU::VISU_Gen_i &); + public: + VISU_Gen_i(CORBA::ORB_ptr theORB, + PortableServer::POA_ptr thePOA, + SALOME_NamingService* theNamingService, + QMutex* theMutex); + virtual ~VISU_Gen_i(); + + virtual char* GetID(); + virtual VISU::VISUType GetType() { return VISU::TVISUGEN;}; + + virtual void SetCurrentStudy(SALOMEDS::Study_ptr theStudy); + virtual SALOMEDS::Study_ptr GetCurrentStudy(); + + virtual ViewManager_ptr GetViewManager(); + + virtual SALOMEDS::SObject_ptr ImportTables(const char* theFileName); + virtual CORBA::Boolean ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName ); + + //Create Result + virtual Result_ptr ImportFile(const char* theFileName); + virtual Result_ptr CopyAndImportFile(const char* theFileName); + virtual Result_ptr ImportMed(SALOMEDS::SObject_ptr theMedSObject); + virtual Result_ptr ImportMedField(SALOME_MED::FIELD_ptr theField); + + //Create Presentation Of Submeshes + virtual Mesh_ptr MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity); + virtual Mesh_ptr FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName, + VISU::Entity theEntity, const char* theFamilyName); + virtual Mesh_ptr GroupMesh(Result_ptr theResult, const char* theMeshName, const char* theGroupName); + + //Create 3D collored Presentation Of Different Types + template TPrs3d_i* + CreatePrs3d(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration, bool theAddToStudy = true) + { + TPrs3d_i* aPresent = NULL; + if(myStudyDocument->GetProperties()->IsLocked()) + return aPresent; + + typedef typename TPrs3d_i::TInterface TPrs3d; + typename TPrs3d::_var_type aPrs3d; + Mutex mt(myMutex); + if(Result_i* pResult = dynamic_cast(GetServant(theResult).in())){ + if(TPrs3d_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,int(theIteration))){ + aPresent = new TPrs3d_i(pResult,theAddToStudy); + if(aPresent->Create(theMeshName,theEntity,theFieldName,int(theIteration)) == NULL) + aPresent->_remove_ref(); + } + } + return aPresent; + } + + template typename TPrs3d_i::TInterface::_var_type + Prs3dOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration, bool theAddToStudy = true) + { + typedef typename TPrs3d_i::TInterface TPrs3d; + typename TPrs3d::_var_type aPrs3d; + if(TPrs3d_i* aPrs3d = CreatePrs3d(theResult,theMeshName,theEntity,theFieldName,theIteration,theAddToStudy)) + return aPrs3d->_this(); + return TPrs3d::_nil(); + } + + virtual ScalarMap_ptr ScalarMapOnField(Result_ptr theResult, + const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); + virtual DeformedShape_ptr DeformedShapeOnField(Result_ptr theResult, + const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); + virtual Vectors_ptr VectorsOnField(Result_ptr theResult, + const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); + virtual IsoSurfaces_ptr IsoSurfacesOnField(Result_ptr theResult, + const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); + virtual CutPlanes_ptr CutPlanesOnField(Result_ptr theResult, + const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); + virtual CutLines_ptr CutLinesOnField(Result_ptr theResult, + const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); + virtual StreamLines_ptr StreamLinesOnField(Result_ptr theResult, + const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); + virtual Plot3D_ptr Plot3DOnField(Result_ptr theResult, + const char* theMeshName, VISU::Entity theEntity, + const char* theFieldName, CORBA::Double theIteration); + //Create Digital Presentation + virtual Table_ptr CreateTable(const char* theTableEntry); + virtual Curve_ptr CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow); + virtual Container_ptr CreateContainer(); + virtual Animation_ptr CreateAnimation(View3D_ptr theView3d); + + virtual void DeleteResult(Result_ptr theResult); + virtual void DeletePrs3d(Prs3d_ptr thePrs3d); + + // inherited methods from Engines::Component + virtual + Engines::TMPFile* + DumpPython(CORBA::Object_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript); + // inherited methods from SALOMEDS::Driver + virtual SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); + virtual SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); + virtual bool Load(SALOMEDS::SComponent_ptr, + const SALOMEDS::TMPFile &, + const char* theURL, + bool isMultiFile); + virtual bool LoadASCII(SALOMEDS::SComponent_ptr, + const SALOMEDS::TMPFile &, + const char* theURL, + bool isMultiFile); + + virtual void Close(SALOMEDS::SComponent_ptr IORSComponent); + + virtual char* ComponentDataType(); + + virtual char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, + const char* IORString, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII); + virtual char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, + const char* aLocalPersistentID, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII); + + virtual bool CanPublishInStudy(CORBA::Object_ptr theIOR); + virtual SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject, + const char* theName) throw (SALOME::SALOME_Exception); + + CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject); + SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID); + CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID); + SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream, + CORBA::Long theObjectID, + SALOMEDS::SObject_ptr theObject); + }; +} +#endif -- 2.39.2