--- /dev/null
+// Copyright (C) 2003 CEA/DEN, EDF R&D
+//
+//
+//
+// File : VISU_TimeAnimation.cxx
+// Author : Vitaly SMETANNIKOV
+// Module : VISU
+
+#include "VISU_TimeAnimation.h"
+
+#include "VISUConfig.hh"
+
+#include "VISU_Result_i.hh"
+#include "VISU_Prs3d_i.hh"
+#include "VISU_Mesh_i.hh"
+#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_View_i.hh"
+
+#include "VISU_ScalarBarActor.hxx"
+#include "VISU_Actor.h"
+
+#include "SalomeApp_Study.h"
+
+#include "SVTK_ViewWindow.h"
+
+#include "SALOME_Event.hxx"
+
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_Application.h"
+#include "SUIT_Session.h"
+#include "SUIT_Study.h"
+
+#include "SALOMEDSClient_AttributeComment.hxx"
+#include "SALOMEDSClient_AttributeName.hxx"
+
+#include <qpixmap.h>
+
+using namespace std;
+
+
+//************************************************************************
+VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy,
+ VISU::View3D_ptr theView3D)
+{
+ myStudy = theStudy;
+ myIsActive = false;
+ myFrame = 0;
+ mySpeed = 1;
+ myProportional = false;
+ myView = 0;
+
+ if (!CORBA::is_nil(theView3D)) {
+ VISU::View3D_i* pView = dynamic_cast<VISU::View3D_i*>(GetServant(theView3D).in());
+ //QAD_StudyFrame* aStudyFrame = pView->GetStudyFrame();
+ //myView = VISU::GetViewFrame(aStudyFrame);
+ SUIT_ViewWindow* aVW = pView->myViewWindow;
+ myView = VISU::GetViewWindow(aVW);
+ }
+
+ myMaxVal = 0;
+ myMinVal = 0;
+ myTimeMin = 0;
+ myTimeMax = 0;
+ myLastError = "";
+ myCycling = false;
+
+ myAnimEntry = "";
+}
+
+
+//************************************************************************
+VISU_TimeAnimation::~VISU_TimeAnimation()
+{
+ for (int i = 0; i < getNbFields(); i++) {
+ clearData(myFieldsLst[i]);
+ }
+}
+
+
+//************************************************************************
+void VISU_TimeAnimation::addField (_PTR(SObject) theField)
+{
+ FieldData aNewData;
+ aNewData.myField = 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);
+
+ //find Min/Max timestamps
+ if ((myTimeMin == 0) && (myTimeMax == 0)) {
+ _PTR(ChildIterator) anIter = myStudy->NewChildIterator(theField);
+ anIter->Next(); // First is reference on support
+ myTimeMin = getTimeValue(anIter->Value());
+ for(; anIter->More(); anIter->Next()) {
+ myTimeMax = getTimeValue(anIter->Value());
+ }
+ }
+}
+
+//************************************************************************
+void VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField)
+{
+ SALOMEDS::SObject_var theFieldDup = SALOMEDS::SObject::_duplicate(theField);
+ _PTR(SObject) aField = VISU::GetClientSObject(theFieldDup, myStudy);
+ addField(aField);
+}
+
+
+//************************************************************************
+void VISU_TimeAnimation::clearData(FieldData& theData) {
+ theData.myTiming.clear();
+ vtkRenderer* aRen = myView->getRenderer();
+ if (!theData.myActors.empty()) {
+ for (int i = 0, iEnd = theData.myActors.size(); i < iEnd; i++) {
+ if (theData.myActors[i] != 0) {
+ theData.myActors[i]->RemoveFromRender(aRen);
+ theData.myActors[i]->Delete();
+ }
+ }
+ theData.myActors.clear();
+ }
+ if (!theData.myPrs.empty()) {
+ for (int i = 0, iEnd = theData.myPrs.size(); i < iEnd; i++)
+ if (theData.myPrs[i] != 0) {
+ theData.myPrs[i]->_remove_ref();
+ }
+ theData.myPrs.clear();
+ }
+ theData.myNbFrames = 0;
+ myView->update();
+}
+
+
+//************************************************************************
+void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum) {
+ FieldData& aData = myFieldsLst[theFieldNum];
+
+ // Delete previous presentations
+ clearData(aData);
+
+ VISU::Result_i* pResult = createPresent(aData.myField);
+ VISU::Storable::TRestoringMap aMap = getMapOfValue(aData.myField);
+ aData.myNbFrames = aData.myNbTimes;
+ //VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
+
+ aData.myPrs.resize(aData.myNbTimes,NULL);
+ aData.myTiming.resize(aData.myNbTimes);
+
+ _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aData.myField);
+ _PTR(SObject) aTimeStamp;
+ anIter->Next(); // First is reference on support
+ long i = 0;
+ double aMin = VTK_LARGE_FLOAT, aMax = -VTK_LARGE_FLOAT;
+ for (; anIter->More(); anIter->Next()) {
+ if (i == aData.myNbTimes) {
+ MESSAGE("There are extra timestamps in field");
+ return;
+ }
+ aTimeStamp = anIter->Value();
+ if (!aTimeStamp) continue;
+
+ aData.myTiming[i] = getTimeValue(aTimeStamp);
+ if (isRangeDefined()) {
+ if (aData.myTiming[i] < myMinVal) continue;
+ if (aData.myTiming[i] > myMaxVal) break;
+ }
+
+ VISU::Storable::TRestoringMap aTimeMap = getMapOfValue(aTimeStamp);
+ QString aMeshName = VISU::Storable::FindValue(aTimeMap,"myMeshName");
+ VISU::Entity anEntity = (VISU::Entity) VISU::Storable::FindValue(aTimeMap,"myEntityId").toInt();
+ QString aFieldName = VISU::Storable::FindValue(aTimeMap,"myFieldName");
+ int aTimeStampId = VISU::Storable::FindValue(aTimeMap,"myTimeStampId").toInt();
+
+ switch (aData.myPrsType) {
+ case VISU::TSCALARMAP: // ScalarMap
+ {
+ VISU::ScalarMap_i* aPresent = new VISU::ScalarMap_i(pResult, false);
+ aPresent->Create(aMeshName.latin1(), anEntity,
+ aFieldName.latin1(), aTimeStampId);
+ //VISU::ScalarMap_var aTmp = aPresent->_this();
+ //aPresent->_remove_ref();
+ aData.myPrs[i] = aPresent;
+ }
+ break;
+
+ case VISU::TISOSURFACE: // Iso Surfaces
+ {
+ VISU::IsoSurfaces_i* aPresent = new VISU::IsoSurfaces_i(pResult, false);
+ aPresent->Create(aMeshName.latin1(), anEntity,
+ aFieldName.latin1(), aTimeStampId);
+ //VISU::IsoSurfaces_var aTmp = aPresent->_this();
+ //aPresent->_remove_ref();
+ aData.myPrs[i] = aPresent;
+ }
+ break;
+
+ case VISU::TCUTPLANES: // Cut Planes
+ {
+ VISU::CutPlanes_i* aPresent = new VISU::CutPlanes_i(pResult, false);
+ aPresent->Create(aMeshName.latin1(), anEntity,
+ aFieldName.latin1(), aTimeStampId);
+ //VISU::CutPlanes_var aTmp = aPresent->_this();
+ //aPresent->_remove_ref();
+ aData.myPrs[i] = aPresent;
+ }
+ break;
+
+ case VISU::TPLOT3D: // Plot3d
+ {
+ VISU::Plot3D_i* aPresent = new VISU::Plot3D_i (pResult, false);
+ aPresent->Create(aMeshName.latin1(), anEntity,
+ aFieldName.latin1(), aTimeStampId);
+ aData.myPrs[i] = aPresent;
+ }
+ break;
+
+ case VISU::TDEFORMEDSHAPE: // Deformed Shape
+ {
+ VISU::DeformedShape_i* aPresent = new VISU::DeformedShape_i(pResult, false);
+ aPresent->Create(aMeshName.latin1(), anEntity,
+ aFieldName.latin1(), aTimeStampId);
+ //VISU::DeformedShape_var aTmp = aPresent->_this();
+ //aPresent->_remove_ref();
+ aData.myPrs[i] = aPresent;
+ }
+ break;
+
+ case VISU::TVECTORS: // Vectors
+ {
+ VISU::Vectors_i* aPresent = new VISU::Vectors_i(pResult, false);
+ aPresent->Create(aMeshName.latin1(), anEntity,
+ aFieldName.latin1(), aTimeStampId);
+ //VISU::Vectors_var aTmp = aPresent->_this();
+ //aPresent->_remove_ref();
+ aData.myPrs[i] = aPresent;
+ }
+ break;
+
+ case VISU::TSTREAMLINES: // Stream Lines
+ {
+ VISU::StreamLines_i* aPresent = new VISU::StreamLines_i(pResult, false);
+ aPresent->Create(aMeshName.latin1(), anEntity,
+ aFieldName.latin1(), aTimeStampId);
+ //VISU::StreamLines_var aTmp = aPresent->_this();
+ //aPresent->_remove_ref();
+ aData.myPrs[i] = aPresent;
+ }
+ break;
+ default:
+ MESSAGE("Not implemented for this presentation type: " << aData.myPrsType);
+ return;
+ }
+ if (aData.myPrs[i]->GetMin() < aMin) aMin = aData.myPrs[i]->GetMin();
+ if (aData.myPrs[i]->GetMax() > aMax) aMax = aData.myPrs[i]->GetMax();
+ i++;
+ }
+ aData.myNbFrames = i;
+
+ int rangeType = VISU::GetResourceMgr()->integerValue("VISU" , "scalar_range_type", 0);
+ if ( rangeType != 1 ) {
+ 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<VISU::IsoSurfaces_i*>(aData.myPrs[i]))
+ aPrs->SetSubRange(aMin, aMax);
+ }
+}
+
+
+//************************************************************************
+CORBA::Boolean VISU_TimeAnimation::generateFrames() {
+ if (!myView) {
+ MESSAGE("Viewer is not defined for animation");
+ return false;
+ }
+
+ myLastError = QString("Frame(s) for ");
+ bool aNoError = true;
+
+ clearView();
+
+ for (int i = 0; i < getNbFields(); i++) {
+ FieldData& aData = myFieldsLst[i];
+ aData.myActors.resize(aData.myNbFrames,NULL);
+ 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)
+ aActor->VisibilityOn();
+ else
+ aActor->VisibilityOff();
+ }catch(...){ //catch(std::runtime_error& exc){
+ aNoError = false;
+ myLastError += QString("%1 ").arg(aData.myTiming[j]);
+ }
+ aData.myActors[j] = aActor;
+ }
+ }
+ myFrame = 0;
+ myLastError += QString(" timestamp(s) cannot be created.");
+ emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
+ myView->Repaint();
+ return aNoError;
+}
+
+//************************************************************************
+void VISU_TimeAnimation::clearView() {
+ if (!myView) {
+ MESSAGE("Viewer is not defined for animation");
+ return;
+ }
+ vtkRenderer* aRen = myView->getRenderer();
+ for (int i = 0; i < getNbFields(); i++) {
+ FieldData& aData = myFieldsLst[i];
+ if (!aData.myActors.empty()) {
+ for (int i = 0, iEnd = aData.myActors.size(); i < iEnd; i++) {
+ if (aData.myActors[i] != 0) {
+ aData.myActors[i]->RemoveFromRender(aRen);
+ aData.myActors[i]->Delete();
+ }
+ }
+ aData.myActors.clear();
+ }
+ }
+ VISU::RepaintView(myView);
+}
+
+//************************************************************************
+void VISU_TimeAnimation::stopAnimation() {
+ myIsActive = false;
+}
+
+//************************************************************************
+void VISU_TimeAnimation::startAnimation() {
+ if (!myIsActive) {
+ myIsActive = true;
+ QThread::start();
+ }
+}
+
+//************************************************************************
+void VISU_TimeAnimation::nextFrame() {
+ stopAnimation();
+ if (myFrame < (myFieldsLst[0].myNbFrames-1)) {
+ int i;
+ for (i = 0; i < getNbFields(); i++)
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+
+ myFrame++;
+ for (i = 0; i < getNbFields(); i++)
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOn();
+
+ emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
+ myView->Repaint();
+ }
+}
+
+//************************************************************************
+void VISU_TimeAnimation::prevFrame() {
+ stopAnimation();
+ if (myFrame > 0) {
+ int i;
+ for (i = 0; i < getNbFields(); i++)
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+
+ myFrame--;
+ for (i = 0; i < getNbFields(); i++)
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOn();
+
+ emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
+ myView->Repaint();
+ }
+}
+
+//************************************************************************
+void VISU_TimeAnimation::firstFrame() {
+ stopAnimation();
+ int i;
+ for (i = 0; i < getNbFields(); i++)
+ if(!myFieldsLst[i].myActors.empty())
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+ myFrame = 0;
+ for (i = 0; i < getNbFields(); i++)
+ if(!myFieldsLst[i].myActors.empty())
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOn();
+ if(!myFieldsLst[0].myTiming.empty()){
+ emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
+ myView->Repaint();
+ }
+}
+
+//************************************************************************
+void VISU_TimeAnimation::lastFrame() {
+ stopAnimation();
+ int i;
+ for (i = 0; i < getNbFields(); i++)
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+
+ myFrame = myFieldsLst[0].myNbFrames-1;
+ for (i = 0; i < getNbFields(); i++)
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOn();
+
+ emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
+ myView->Repaint();
+}
+
+
+//************************************************************************
+// For Batchmode using
+void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) {
+ if ((theFrame < 0) || (theFrame > (getNbFrames()-1)))
+ return;
+ stopAnimation();
+ qApp->lock();
+ qApp->syncX();
+ int i;
+ for (i = 0; i < getNbFields(); i++)
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+
+ myFrame = theFrame;
+ for (i = 0; i < getNbFields(); i++)
+ if (myFieldsLst[i].myActors[myFrame] != 0)
+ myFieldsLst[i].myActors[myFrame]->VisibilityOn();
+
+ emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
+ myView->Repaint();
+ qApp->flushX();
+ qApp->processEvents(3);
+ qApp->unlock();
+}
+
+
+//************************************************************************
+VISU::ScalarMap_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) {
+ if ((theField > getNbFields()) || (theField < 0))
+ return VISU::ScalarMap::_nil();
+ if ((theFrame < 0) || (theFrame > (myFieldsLst[theField].myNbFrames - 1)))
+ return VISU::ScalarMap::_nil();
+ return myFieldsLst[theField].myPrs[theFrame]->_this();
+}
+
+
+//************************************************************************
+CORBA::Long VISU_TimeAnimation::getNbFrames() {
+ return (getNbFields() > 0)? myFieldsLst[0].myNbFrames : 0;
+}
+
+
+//************************************************************************
+void VISU_TimeAnimation::run()
+{
+ if (!myView) {
+ MESSAGE("Viewer is not defined for animation");
+ return;
+ }
+ double k = 1;
+ bool isDumping = !myDumpPath.isEmpty();
+ double aOneVal = 1;
+ if (myFieldsLst[0].myNbFrames > 2)
+ aOneVal = myFieldsLst[0].myTiming[1] - myFieldsLst[0].myTiming[0];
+ qApp->lock();
+ while (myIsActive) {
+ emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
+ for (int i = 0; i < getNbFields(); i++) {
+ FieldData& aData = myFieldsLst[i];
+ if (myFrame > 0) {
+ if (aData.myActors[myFrame-1] != 0)
+ aData.myActors[myFrame-1]->VisibilityOff();
+ } else {
+ if (aData.myActors[aData.myNbFrames-1] != 0)
+ aData.myActors[aData.myNbFrames-1]->VisibilityOff();
+ }
+ if (aData.myActors[myFrame] != 0) {
+ aData.myActors[myFrame]->VisibilityOn();
+ }
+ }
+ myView->Repaint(false);
+
+ int delay = 100;
+ if (isDumping) {
+ QPixmap px = QPixmap::grabWindow(myView->winId());
+ QString aFile(myDumpPath);
+ QString aName = QString("%1").arg(myFieldsLst[0].myTiming[myFrame]);
+ int aPos = -1;
+ while ((aPos = aName.find(".")) > -1 )
+ aName.replace(aPos, 1, "_");
+ aFile += aName;
+ aFile += ".jpeg";
+ px.save(aFile, "JPEG");
+ } else {
+ k = 1;
+ if (myProportional) {
+ switch (myFrame) {
+ case 0:
+ break;
+ case 1:
+ if (myFieldsLst[0].myNbFrames > 2)
+ k = (myFieldsLst[0].myTiming[myFrame+1] -
+ myFieldsLst[0].myTiming[myFrame]) / aOneVal;
+ break;
+ default:
+ if (myFrame < (myFieldsLst[0].myNbFrames - 1))
+ k = (myFieldsLst[0].myTiming[myFrame+1] -
+ myFieldsLst[0].myTiming[myFrame]) / aOneVal;
+ }
+ }
+ delay = (int)(1000. * k / mySpeed);
+ }
+ qApp->unlock();
+ msleep(delay);
+ qApp->lock();
+
+ if (!myIsActive) break;
+
+ myFrame++;
+ if (myFrame == myFieldsLst[0].myNbFrames) {
+ if (!myCycling) {
+ myIsActive = false;
+ myFrame--;
+ break;
+ } else
+ myFrame = 0;
+ }
+ }
+ emit stopped();
+ qApp->unlock();
+ QThread::exit();
+}
+
+//************************************************************************
+VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField)
+{
+ _PTR(SObject) aSObj = theField->GetFather();
+ aSObj = aSObj->GetFather();
+ aSObj = aSObj->GetFather();
+ CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
+ if (CORBA::is_nil(anObject)) return NULL;
+ return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
+}
+
+//************************************************************************
+VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (_PTR(SObject) theSObject)
+{
+ VISU::Storable::TRestoringMap aMap;
+ if (theSObject) {
+ _PTR(GenericAttribute) anAttr;
+ if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
+ _PTR(AttributeComment) aComment (anAttr);
+ std::string aString = aComment->Value();
+ QString strIn (aString.c_str());
+ VISU::Storable::StrToMap(strIn, aMap);
+ }
+ }
+ return aMap;
+}
+
+//************************************************************************
+double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp)
+{
+ _PTR(GenericAttribute) anAttr;
+ if (theTimeStamp->FindAttribute(anAttr, "AttributeName")) {
+ _PTR(AttributeName) aName (anAttr);
+ QString aNameString (aName->Value().c_str());
+ int time_len = aNameString.find(',');
+ if (time_len > -1)
+ return aNameString.left(time_len).toDouble();
+ else
+ return aNameString.toDouble();
+ }
+ return -1.0;
+}
+
+//************************************************************************
+void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed)
+{
+ mySpeed = (theSpeed<1)? 1 : theSpeed;
+}
+
+//************************************************************************
+int VISU_TimeAnimation::myNBAnimations = 0;
+QString VISU_TimeAnimation::GenerateName()
+{
+ return VISU::GenerateName("Animation", myNBAnimations++);
+}
+
+//************************************************************************
+std::string GetPresentationComment (VISU::VISUType thePrsType)
+{
+ std::string aPrsCmt;
+ switch (thePrsType) {
+ case VISU::TSCALARMAP:
+ aPrsCmt = VISU::ScalarMap_i::myComment;
+ break;
+ case VISU::TISOSURFACE:
+ aPrsCmt = VISU::IsoSurfaces_i::myComment;
+ break;
+ case VISU::TCUTPLANES:
+ aPrsCmt = VISU::CutPlanes_i::myComment;
+ break;
+ case VISU::TPLOT3D:
+ aPrsCmt = VISU::Plot3D_i::myComment;
+ break;
+ case VISU::TDEFORMEDSHAPE:
+ aPrsCmt = VISU::DeformedShape_i::myComment;
+ break;
+ case VISU::TVECTORS:
+ aPrsCmt = VISU::Vectors_i::myComment;
+ break;
+ case VISU::TSTREAMLINES:
+ aPrsCmt = VISU::StreamLines_i::myComment;
+ break;
+ default:
+ aPrsCmt = "Unknown presentation";
+ break;
+ }
+ return aPrsCmt;
+}
+
+//************************************************************************
+SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
+{
+ if (myStudy->GetProperties()->IsLocked())
+ return SALOMEDS::SObject::_nil();
+
+ _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+ _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
+ std::string aSComponentEntry = aSComponent->GetID();
+
+ QString aComment;
+ aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
+ VISU::TANIMATION,myMinVal,myMaxVal);
+
+ string anEntry = VISU::CreateAttributes(myStudy,aSComponentEntry.c_str(),"","",
+ GenerateName(),"",aComment,true);
+ myAnimEntry = anEntry.c_str();
+ _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
+
+ for (int i = 0; i < getNbFields(); i++) {
+ FieldData& aData = myFieldsLst[i];
+
+ _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
+ aStudyBuilder->Addreference(newObj, aData.myField);
+
+ if (aData.myPrs.empty()) {
+ generatePresentations(i);
+ }
+ ostringstream strOut;
+ aData.myPrs[0]->ToStream(strOut);
+ string aPrsComment = strOut.str();
+ VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
+ aData.myPrs[0]->GetComment(),"",aPrsComment.c_str(),true);
+ }
+ aStudyBuilder->CommitCommand();
+
+ return VISU::GetSObject(aAnimSObject);
+}
+
+//************************************************************************
+void VISU_TimeAnimation::saveAnimation()
+{
+ if (myStudy->GetProperties()->IsLocked()) return;
+ if (myAnimEntry.isEmpty()) return;
+
+ _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.latin1());
+ if (!aAnimSObject) return;
+
+ _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+ _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
+ std::string aSComponentEntry = aSComponent->GetID();
+
+ QString aComment;
+ aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
+ VISU::TANIMATION,myMinVal,myMaxVal);
+
+ _PTR(GenericAttribute) anAttr;
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeComment");
+ _PTR(AttributeComment) aCmnt (anAttr);
+ aCmnt->SetValue(aComment.latin1());
+
+ _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
+ int i = 0, nbf = getNbFields();
+ for (anIter->Init(); anIter->More(); anIter->Next(), i++) {
+ if (i >= nbf) break; // it must not be
+ FieldData& aData = myFieldsLst[i];
+
+ // Get presentation name and comment
+ if (aData.myPrs.empty()) {
+ generatePresentations(i);
+ }
+ ostringstream strOut;
+ aData.myPrs[0]->ToStream(strOut);
+ string aPrsComment = strOut.str();
+ string aPrsNameTxt = aData.myPrs[0]->GetComment();
+
+ // Save in study
+ _PTR(SObject) aRefObj = anIter->Value();
+ _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
+ anPrsIter->Init();
+
+ if (anPrsIter->More()) {
+ _PTR(SObject) aPrsObj = anPrsIter->Value();
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeComment");
+ aCmnt = _PTR(AttributeComment)(anAttr);
+ aCmnt->SetValue(aPrsComment.c_str());
+
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
+ _PTR(AttributeName) aPrsName (anAttr);
+ aPrsName->SetValue(aPrsNameTxt);
+
+ } else {
+ VISU::CreateAttributes(myStudy, aRefObj->GetID().c_str(),"","",
+ aPrsNameTxt.c_str(),"",aPrsComment.c_str(),true);
+ }
+ }
+ aStudyBuilder->CommitCommand();
+}
+
+//************************************************************************
+void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
+{
+ _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
+ restoreFromStudy(aAnimSObject);
+}
+
+void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
+{
+ _PTR(SObject) aAnimSObject = theField;
+
+ VISU::Storable::TRestoringMap aMap;
+ _PTR(GenericAttribute) anAttr;
+ if (!aAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
+
+ _PTR(AttributeComment) aComment (anAttr);
+ string aComm = aComment->Value();
+ QString strIn (aComm.c_str());
+ VISU::Storable::StrToMap(strIn,aMap);
+ bool isExist;
+
+ myMinVal = VISU::Storable::FindValue(aMap,"myMinVal",&isExist).toDouble();
+ myMaxVal = VISU::Storable::FindValue(aMap,"myMaxVal",&isExist).toDouble();
+
+ _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
+ for (anIter->Init(); anIter->More(); anIter->Next()) {
+ _PTR(SObject) aRefObj = anIter->Value();
+ _PTR(SObject) aFieldObj;
+ if (!aRefObj->ReferencedObject(aFieldObj) ) continue;
+ addField(aFieldObj);
+ FieldData& aData = getFieldData(getNbFields()-1);
+
+ // Get Presentation object
+ _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
+ anPrsIter->Init();
+ if (!anPrsIter->More()) continue;
+ _PTR(SObject) aPrsObj = anPrsIter->Value();
+ if (!aPrsObj->FindAttribute(anAttr, "AttributeName")) continue;
+ _PTR(AttributeName) aName (anAttr);
+ string aStr = aName->Value();
+ QString strName (aStr.c_str());
+
+ if (strName == VISU::ScalarMap_i::myComment.c_str())
+ aData.myPrsType = VISU::TSCALARMAP;
+ else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
+ aData.myPrsType = VISU::TISOSURFACE;
+ else if (strName == VISU::CutPlanes_i::myComment.c_str())
+ aData.myPrsType = VISU::TCUTPLANES;
+ else if (strName == VISU::Plot3D_i::myComment.c_str())
+ aData.myPrsType = VISU::TPLOT3D;
+ else if (strName == VISU::DeformedShape_i::myComment.c_str())
+ aData.myPrsType = VISU::TDEFORMEDSHAPE;
+ else if (strName == VISU::Vectors_i::myComment.c_str())
+ aData.myPrsType = VISU::TVECTORS;
+ else if (strName == VISU::StreamLines_i::myComment.c_str())
+ aData.myPrsType = VISU::TSTREAMLINES;
+ else
+ continue;
+ generatePresentations(getNbFields()-1);
+
+ if (!aPrsObj->FindAttribute(anAttr, "AttributeComment")) continue;
+ _PTR(AttributeComment) aPrsComment (anAttr);
+ string aPrsComm = aPrsComment->Value();
+ if (aPrsComm.length() > 0) {
+ QString strPrsIn (aPrsComm.c_str());
+ VISU::Storable::TRestoringMap aPrsMap;
+ VISU::Storable::StrToMap(strPrsIn,aPrsMap);
+
+ aData.myPrs[0]->Restore(aPrsMap);
+ }
+ aData.myPrs[0]->GetOffset(aData.myOffset);
+ for (int i = 1; i < aData.myNbFrames; i++) {
+ //jfa 03.08.2005:aData.myPrs[i]->SameAs(aData.myPrs[0]);
+ aData.myPrs[i]->SameAsParams(aData.myPrs[0]);//jfa 03.08.2005
+ }
+ }
+ string aStr = aAnimSObject->GetID();
+ myAnimEntry = aStr.c_str();
+}
+
+
+//========================================================================
+//========================================================================
+//========================================================================
+struct TNewAnimationEvent: public SALOME_Event
+{
+ std::string myStudyName;
+ VISU::View3D_ptr myView3D;
+
+ typedef VISU_TimeAnimation* TResult;
+ TResult myResult;
+
+ TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
+ myStudyName(theStudyName),
+ myView3D(VISU::View3D::_duplicate(theView3D)),
+ myResult(NULL)
+ {}
+
+ virtual
+ void
+ Execute()
+ {
+ SUIT_Session* aSession = SUIT_Session::session();
+ QPtrList<SUIT_Application> anApplications = aSession->applications();
+ QPtrListIterator<SUIT_Application> anIter (anApplications);
+ while (SUIT_Application* anApp = anIter.current()) {
+ ++anIter;
+ if (SUIT_Study* aSStudy = anApp->activeStudy()) {
+ if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
+ if (_PTR(Study) aCStudy = aStudy->studyDS()) {
+ if (myStudyName == aCStudy->Name()) {
+ myResult = new VISU_TimeAnimation (aCStudy, myView3D);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+};
+
+VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
+ VISU::View3D_ptr theView3D)
+{
+ std::string aStudyName = theStudy->Name();
+ myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
+}
+
+VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
+{
+ delete myAnim;
+}
+
+void VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
+{
+ myAnim->addField(theField);
+}
+
+CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
+{
+ return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
+ (myAnim,&VISU_TimeAnimation::generateFrames));
+}
+
+void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
+{
+ myAnim->generatePresentations(theFieldNum);
+}
+
+void VISU_TimeAnimation_i::clearView()
+{
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+ (myAnim,&VISU_TimeAnimation::clearView));
+}
+
+void VISU_TimeAnimation_i::stopAnimation()
+{
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+ (myAnim,&VISU_TimeAnimation::stopAnimation));
+}
+
+void VISU_TimeAnimation_i::startAnimation()
+{
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+ (myAnim,&VISU_TimeAnimation::startAnimation));
+}
+
+void VISU_TimeAnimation_i::nextFrame()
+{
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+ (myAnim,&VISU_TimeAnimation::nextFrame));
+}
+
+void VISU_TimeAnimation_i::prevFrame()
+{
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+ (myAnim,&VISU_TimeAnimation::prevFrame));
+}
+
+void VISU_TimeAnimation_i::firstFrame()
+{
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+ (myAnim,&VISU_TimeAnimation::firstFrame));
+}
+
+void VISU_TimeAnimation_i::lastFrame()
+{
+ ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+ (myAnim,&VISU_TimeAnimation::lastFrame));
+}
+
+void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
+{
+ ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
+ (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
+}
+
+CORBA::Long VISU_TimeAnimation_i::getNbFields()
+{
+ return myAnim->getNbFields();
+}
+
+CORBA::Long VISU_TimeAnimation_i::getNbFrames()
+{
+ return myAnim->getNbFrames();
+}
+
+CORBA::Boolean VISU_TimeAnimation_i::isRunning()
+{
+ return myAnim->isRunning();
+}
+
+CORBA::Long VISU_TimeAnimation_i::getCurrentFrame()
+{
+ return myAnim->getCurrentFrame();
+}
+
+VISU::ScalarMap_ptr VISU_TimeAnimation_i::getPresentation
+ (CORBA::Long theField, CORBA::Long theFrame)
+{
+ return myAnim->getPresentation(theField,theFrame);
+}
+
+void VISU_TimeAnimation_i::setPresentationType (CORBA::Long theFieldNum,
+ VISU::VISUType theType)
+{
+ myAnim->setPresentationType(theFieldNum,theType);
+}
+
+VISU::VISUType VISU_TimeAnimation_i::getPresentationType (CORBA::Long theFieldNum)
+{
+ return myAnim->getPresentationType(theFieldNum);
+}
+
+void VISU_TimeAnimation_i::setSpeed(CORBA::Long theSpeed)
+{
+ myAnim->setSpeed(theSpeed);
+}
+
+CORBA::Long VISU_TimeAnimation_i::getSpeed()
+{
+ return myAnim->getSpeed();
+}
+
+CORBA::Boolean VISU_TimeAnimation_i::isProportional()
+{
+ return myAnim->isProportional();
+}
+
+void VISU_TimeAnimation_i::setAnimationRange (CORBA::Double theMin,
+ CORBA::Double theMax)
+{
+ myAnim->setAnimationRange(theMin,theMax);
+}
+
+CORBA::Double VISU_TimeAnimation_i::getMinRange()
+{
+ return myAnim->getMinRange();
+}
+
+CORBA::Double VISU_TimeAnimation_i::getMaxRange()
+{
+ return myAnim->getMaxRange();
+}
+
+CORBA::Boolean VISU_TimeAnimation_i::isRangeDefined()
+{
+ return myAnim->isRangeDefined();
+}
+
+void VISU_TimeAnimation_i::dumpTo (const char* thePath)
+{
+ myAnim->dumpTo(thePath);
+}
+
+CORBA::Boolean VISU_TimeAnimation_i::isCycling()
+{
+ return myAnim->isCycling();
+}
+
+CORBA::Double VISU_TimeAnimation_i::getMinTime()
+{
+ return myAnim->getMinTime();
+}
+
+CORBA::Double VISU_TimeAnimation_i::getMaxTime()
+{
+ return myAnim->getMaxTime();
+}
+
+void VISU_TimeAnimation_i::setProportional (CORBA::Boolean theProp)
+{
+ myAnim->setProportional(theProp);
+}
+
+void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
+{
+ myAnim->setCycling(theCycle);
+}
+
+SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
+{
+ return myAnim->publishInStudy();
+}
+
+void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
+{
+ myAnim->restoreFromStudy(theObj);
+}
+
+CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
+{
+ return myAnim->isSavedInStudy();
+}
+
+void VISU_TimeAnimation_i::saveAnimation()
+{
+ myAnim->saveAnimation();
+}