1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VISU_TimeAnimation.cxx
24 // Author : Vitaly SMETANNIKOV
27 #include "VISU_TimeAnimation.h"
31 #include <QMessageBox>
34 #include "VISUConfig.hh"
36 #include "VISU_Result_i.hh"
37 #include "VISU_Prs3d_i.hh"
38 #include "VISU_Mesh_i.hh"
39 #include "VISU_IsoSurfaces_i.hh"
40 #include "VISU_DeformedShape_i.hh"
41 #include "VISU_DeformedShapeAndScalarMap_i.hh"
42 #include "VISU_CutPlanes_i.hh"
43 #include "VISU_Plot3D_i.hh"
44 #include "VISU_CutLines_i.hh"
45 #include "VISU_CutSegment_i.hh"
46 #include "VISU_Vectors_i.hh"
47 #include "VISU_StreamLines_i.hh"
48 #include "VISU_GaussPoints_i.hh"
49 #include "VISU_ViewManager_i.hh"
50 #include "VISU_View_i.hh"
52 #include "VISU_ScalarBarActor.hxx"
53 #include "VISU_Actor.h"
55 #include "SalomeApp_Study.h"
57 #include "SVTK_ViewWindow.h"
59 #include "SALOME_Event.h"
61 #include "SUIT_ResourceMgr.h"
62 #include "SUIT_Application.h"
63 #include "SUIT_Session.h"
64 #include "SUIT_Study.h"
65 #include "SUIT_MessageBox.h"
67 #include "SALOMEDSClient_AttributeString.hxx"
68 #include "SALOMEDSClient_AttributeName.hxx"
70 #include "Utils_ExceptHandlers.hxx"
74 #include <QImageWriter>
75 #include <QStringList>
78 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
82 #include <Standard_Failure.hxx>
85 #include <Standard_ErrorHandler.hxx>
90 //------------------------------------------------------------------------
93 //------------------------------------------------------------------------
97 QMutex myIsActiveMutex;
99 ExecutionState(bool isActive = false)
100 : myIsActive(isActive) {}
104 myIsActiveMutex.lock();
106 myIsActiveMutex.unlock();
109 bool SetActive(bool isActive) {
111 myIsActiveMutex.lock();
113 myIsActive = isActive;
114 myIsActiveMutex.unlock();
120 //------------------------------------------------------------------------
126 DumpPath(QString thePath = QString())
133 myPathMutex.unlock();
136 void SetPath(QString thePath) {
139 myPathMutex.unlock();
144 //------------------------------------------------------------------------
145 struct TCompositeMinMaxController : virtual TVTKMinMaxController
147 typedef ColoredPrs3d_i* TKey;
148 typedef std::map< TKey, VISU::PMinMaxController > TMinMaxContainer;
149 TMinMaxContainer myMinMaxContainer;
152 AddController(ColoredPrs3d_i* theReference,
153 VISU::PMinMaxController theMinMaxController)
155 myMinMaxContainer[ TKey( theReference ) ] = theMinMaxController;
160 UpdateReference(ColoredPrs3d_i* theFromPrs3, ColoredPrs3d_i* theToPrs3d)
162 TMinMaxContainer::iterator anIter = myMinMaxContainer.find( TKey( theFromPrs3 ) );
163 if ( anIter != myMinMaxContainer.end() ) {
164 myMinMaxContainer.erase( anIter );
165 myMinMaxContainer[ TKey( theToPrs3d ) ] = VISU::CreateDefaultMinMaxController( theToPrs3d );
171 GetComponentMin(vtkIdType theCompID)
173 vtkFloatingPointType aMin = TMinMaxController::GetComponentMin(theCompID);
174 if ( !myMinMaxContainer.empty() ) {
175 TMinMaxContainer::const_iterator anIter = myMinMaxContainer.begin();
176 for(; anIter != myMinMaxContainer.end(); anIter++){
177 VISU::PMinMaxController aMinMaxController = anIter->second;
178 aMin = std::min(aMin, aMinMaxController->GetComponentMin(theCompID));
186 GetComponentMax(vtkIdType theCompID)
188 vtkFloatingPointType aMax = TMinMaxController::GetComponentMax(theCompID);
189 if ( !myMinMaxContainer.empty() ) {
190 TMinMaxContainer::const_iterator anIter = myMinMaxContainer.begin();
191 for(; anIter != myMinMaxContainer.end(); anIter++){
192 VISU::PMinMaxController aMinMaxController = anIter->second;
193 aMax = std::max(aMax, aMinMaxController->GetComponentMax(theCompID));
200 typedef SALOME::GenericObjPtr<TCompositeMinMaxController> PCompositeMinMaxController;
203 //------------------------------------------------------------------------
204 VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy,
205 VISU::View3D_ptr theView3D)
208 myExecutionState = new VISU::ExecutionState(false);
210 mySpeed = VISU::GetResourceMgr()->integerValue("VISU", "speed", 1);
211 myProportional = VISU::GetResourceMgr()->booleanValue("VISU", "use_proportional_timing", false);
214 if (!CORBA::is_nil(theView3D)) {
215 VISU::View3D_i* pView = dynamic_cast<VISU::View3D_i*>(GetServant(theView3D).in());
216 SUIT_ViewWindow* aVW = pView->GetViewWindow();
217 setViewer( dynamic_cast<SVTK_ViewWindow*>(aVW) );
220 myAnimationMode = VISU::Animation::PARALLEL;
226 myCycling = VISU::GetResourceMgr()->booleanValue("VISU", "cycled_animation", false);
227 myCleaningMemoryAtEachFrame = VISU::GetResourceMgr()->booleanValue("VISU", "clean_memory_at_each_frame", false);
231 myDumpPath = new VISU::DumpPath( "" );
233 myAVIMaker = "jpeg2yuv";
235 myDumpMode = VISU::GetResourceMgr()->integerValue("VISU", "dump_mode", 0);
236 myTimeStampFrequency = VISU::GetResourceMgr()->integerValue("VISU", "time_stamp_frequency", 1);
240 //------------------------------------------------------------------------
241 VISU_TimeAnimation::~VISU_TimeAnimation()
243 if (QThread::isRunning() && !QThread::isFinished()) {
246 if (QThread::isRunning() && !QThread::isFinished()) {
247 QThread::terminate();
251 for (int i = 0; i < getNbFields() && myView; i++) {
252 clearData(myFieldsLst[i]);
256 delete myExecutionState;
260 /* Terminates the execution of the thread.
261 * The thread may or may not be terminated immediately,
262 * depending on the operating system's scheduling policies.
264 * Use QThread::wait() after terminate() for synchronous termination.
266 * When the thread is terminated, all threads waiting for the the thread to finish will be woken up.
268 * Warning: This function is dangerous, and its use is discouraged.
269 * The thread can be terminated at any point in its code path.
270 * Threads can be terminated while modifying data.
271 * There is no chance for the thread to cleanup after itself,
272 * unlock any held mutexes, etc. In short, use this function only if absolutely necessary.
274 //QThread::wait(100);
275 //QThread::terminate();
276 //QThread::wait(400);
280 //------------------------------------------------------------------------
281 void VISU_TimeAnimation::_connectView()
283 connect( myView, SIGNAL( destroyed() ), this, SLOT( onViewDeleted() ) );
286 //------------------------------------------------------------------------
287 bool VISU_TimeAnimation::addField (_PTR(SObject) theField)
289 if (!theField) return false;
292 aNewData.myField = theField;
293 aNewData.myNbFrames = 0;
294 aNewData.myPrsType = VISU::TSCALARMAP;
295 aNewData.myOffset[0] = aNewData.myOffset[1] = aNewData.myOffset[2] = 0;
297 // initialize myResult in aNewData
298 _PTR(SObject) aSObj = theField->GetFather();
299 aSObj = aSObj->GetFather();
300 aSObj = aSObj->GetFather();
301 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
302 if (CORBA::is_nil(anObject)) return false;
303 aNewData.myResult = dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
305 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(aNewData.myField);
306 if(VISU::Storable::FindValue(aMap,"myComment") != "FIELD")
309 aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
311 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
312 if ( aNewData.myNbTimes < 2 )
314 if ( !myFieldsLst.isEmpty() && myFieldsLst.first().myNbTimes != aNewData.myNbTimes )
316 if ( myFieldsLst.isEmpty() )
317 myFieldsAbsFrames.push_back(aNewData.myNbTimes);
319 else { // successive animation mode
320 if ( aNewData.myNbTimes < 1 )
323 long aNumCompCurr = VISU::Storable::FindValue(aMap, "myNumComponent").toLong();
324 if ( !myFieldsLst.isEmpty() ) {
325 VISU::Storable::TRestoringMap aFMap = VISU::Storable::GetStorableMap(myFieldsLst.first().myField);
326 long aNumComp = VISU::Storable::FindValue(aFMap, "myNumComponent").toLong();
327 if ( aNumCompCurr != aNumComp )
331 if ( !myFieldsLst.isEmpty() )
332 myFieldsAbsFrames.push_back(myFieldsAbsFrames.back() + aNewData.myNbTimes);
334 myFieldsAbsFrames.push_back(aNewData.myNbTimes);
337 myFieldsLst.append(aNewData);
339 //find Min/Max timestamps
340 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(theField);
341 anIter->Next(); // First is reference on support
342 if ( myFieldsLst.size() == 1 ) { // the first field
343 myTimeMin = getTimeValue(anIter->Value());
344 myTimeMax = getTimeValue(anIter->Value());
346 for(; anIter->More(); anIter->Next()) {
347 if ( myTimeMin > getTimeValue(anIter->Value()) )
348 myTimeMin = getTimeValue(anIter->Value());
349 if ( myTimeMax < getTimeValue(anIter->Value()) )
350 myTimeMax = getTimeValue(anIter->Value());
356 //------------------------------------------------------------------------
357 bool VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField)
359 SALOMEDS::SObject_var theFieldDup = SALOMEDS::SObject::_duplicate(theField);
360 _PTR(SObject) aField = VISU::GetClientSObject(theFieldDup, myStudy);
361 return addField(aField);
365 //------------------------------------------------------------------------
366 void VISU_TimeAnimation::_clearData(FieldData& theData) {
368 MESSAGE("Viewer is not defined for animation");
371 theData.myTiming.clear();
372 vtkRenderer* aRen = myView->getRenderer();
373 if (!theData.myActors.empty()) {
374 for (int i = 0, iEnd = theData.myActors.size(); i < iEnd; i++) {
375 if (theData.myActors[i] != 0) {
376 theData.myActors[i]->RemoveFromRender(aRen);
379 theData.myActors.clear();
381 if (!theData.myPrs.empty()) {
382 for (int i = 0, iEnd = theData.myPrs.size(); i < iEnd; i++)
383 if (theData.myPrs[i] != 0) {
384 theData.myPrs[i]->_remove_ref();
386 theData.myPrs.clear();
388 theData.myNbFrames = 0;
392 //------------------------------------------------------------------------
393 void VISU_TimeAnimation::clearData(FieldData& theData) {
394 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,FieldData&>
395 (this,&VISU_TimeAnimation::_clearData,theData));
400 //------------------------------------------------------------------------
401 template<class TPrs3d>
403 GeneratePresentations(_PTR(Study) theStudy,
405 VISU::Result_i* theResult,
406 bool theIsRangeDefined,
407 CORBA::Double theTimeMin,
408 CORBA::Double theTimeMax,
409 QList<long> theSequence)
411 _PTR(ChildIterator) anIter = theStudy->NewChildIterator(theData.myField);
412 anIter->Next(); // First is reference on support
414 long aSequenceLength = theSequence.count();
415 bool isSequenceDefined = aSequenceLength > 0;
416 if (isSequenceDefined)
417 theData.myPrs.resize(aSequenceLength,NULL);
420 long aSequenceIndex = 1;
421 for(; anIter->More(); anIter->Next(), aSequenceIndex++){
422 if (aFrameId == theData.myNbTimes) {
423 MESSAGE("There are extra timestamps in field");
426 _PTR(SObject) aTimeStamp = anIter->Value();
430 long aSequenceId = -1;
432 theData.myTiming[aFrameId] = VISU_TimeAnimation::getTimeValue(aTimeStamp);
433 if (theIsRangeDefined) {
434 if (theData.myTiming[aFrameId] < theTimeMin)
436 if (theData.myTiming[aFrameId] > theTimeMax)
439 else if (isSequenceDefined) {
440 aSequenceId = theSequence.indexOf( aSequenceIndex );
441 if( aSequenceId == -1 )
445 VISU::Storable::TRestoringMap aTimeMap = VISU::Storable::GetStorableMap(aTimeStamp);
446 QString aMeshName = VISU::Storable::FindValue(aTimeMap,"myMeshName");
447 VISU::Entity anEntity = (VISU::Entity) VISU::Storable::FindValue(aTimeMap,"myEntityId").toInt();
448 QString aFieldName = VISU::Storable::FindValue(aTimeMap,"myFieldName");
449 int aTimeStampId = VISU::Storable::FindValue(aTimeMap,"myTimeStampId").toInt();
451 bool anIsCreated = false;
452 TPrs3d* aPresent = new TPrs3d(VISU::ColoredPrs3d_i::EDoNotPublish);
453 aPresent->SetCResult(theResult);
454 aPresent->SetMeshName(aMeshName.toLatin1().data());
455 aPresent->SetEntity(anEntity);
456 aPresent->SetFieldName(aFieldName.toLatin1().data());
457 aPresent->SetTimeStampNumber(aTimeStampId);
462 if(aPresent->Apply(false)){
464 if(isSequenceDefined)
466 theData.myPrs[aSequenceId] = aPresent;
471 theData.myPrs[aFrameId++] = aPresent;
474 }catch(Standard_Failure) {
475 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
476 INFOS("Follow signal was occured :\n"<<aFail->GetMessageString());
477 }catch(std::exception& exc){
478 INFOS("Follow exception was occured :\n"<<exc.what());
480 INFOS("Unknown exception was occured!");
483 aPresent->_remove_ref();
486 theData.myNbFrames = aFrameId;
488 if (theData.myPrsType != VISU::TGAUSSPOINTS) {
489 for(long aFrameId = 0; aFrameId < theData.myNbFrames; aFrameId++) {
490 if (VISU::ScalarMap_i* aPrs = dynamic_cast<VISU::ScalarMap_i*>(theData.myPrs[aFrameId])){
491 aPrs->SetOffset(theData.myOffset);
498 double getMinFieldsValue( QList<FieldData>& theFieldsLst )
500 // for successive animation mode only
502 for (int i = 0; i < theFieldsLst.count(); i++) {
503 if ( theFieldsLst[i].myPrs[0] ) {
504 aRes = theFieldsLst[i].myPrs[0]->GetMin();
509 for (int i = 1; i < theFieldsLst.count() && theFieldsLst[i].myPrs[0]; i++) {
510 if ( aRes > theFieldsLst[i].myPrs[0]->GetMin() )
511 aRes = theFieldsLst[i].myPrs[0]->GetMin();
516 double getMaxFieldsValue( QList<FieldData>& theFieldsLst )
518 // for successive animation mode only
520 for (int i = 0; i < theFieldsLst.count(); i++) {
521 if ( theFieldsLst[i].myPrs[0] ) {
522 aRes = theFieldsLst[i].myPrs[0]->GetMax();
527 for (int i = 1; i < theFieldsLst.count() && theFieldsLst[i].myPrs[0]; i++) {
528 if ( aRes < theFieldsLst[i].myPrs[0]->GetMax() )
529 aRes = theFieldsLst[i].myPrs[0]->GetMax();
534 void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum)
536 int nbf = myFieldsLst.size();
537 if( theFieldNum<0 || theFieldNum>nbf-1 )
540 FieldData& aData = myFieldsLst[theFieldNum];
542 // Delete previous presentations
545 VISU::Result_i* aResult = createPresent(aData.myField);
546 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(aData.myField);
547 aData.myNbFrames = aData.myNbTimes;
548 //VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
550 aData.myPrs.resize(aData.myNbTimes,NULL);
551 aData.myTiming.resize(aData.myNbTimes);
553 QList<long> aSequence;
554 if( isSequenceDefined() )
556 bool ok = getIndicesFromSequence( mySequence, aSequence );
561 using namespace VISU;
562 switch (aData.myPrsType) {
563 case VISU::TSCALARMAP:
564 GeneratePresentations<ScalarMap_i>(myStudy,
572 case VISU::TISOSURFACES: // Iso Surfaces
573 GeneratePresentations<IsoSurfaces_i>(myStudy,
581 case VISU::TCUTPLANES: // Cut Planes
582 GeneratePresentations<CutPlanes_i>(myStudy,
590 case VISU::TCUTLINES: // Cut Lines
591 GeneratePresentations<CutLines_i>(myStudy,
599 case VISU::TCUTSEGMENT: // Cut Segment
600 GeneratePresentations<CutSegment_i>(myStudy,
608 case VISU::TPLOT3D: // Plot3d
609 GeneratePresentations<Plot3D_i>(myStudy,
617 case VISU::TDEFORMEDSHAPE: // Deformed Shape
618 GeneratePresentations<DeformedShape_i>(myStudy,
626 case VISU::TVECTORS: // Vectors
627 GeneratePresentations<Vectors_i>(myStudy,
635 case VISU::TSTREAMLINES: // Stream Lines
636 GeneratePresentations<StreamLines_i>(myStudy,
644 case VISU::TGAUSSPOINTS: // Gauss Points
645 GeneratePresentations<GaussPoints_i>(myStudy,
653 case VISU::TSCALARMAPONDEFORMEDSHAPE: // Scalar map on deformed shape
654 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
655 GeneratePresentations<DeformedShapeAndScalarMap_i>(myStudy,
664 MESSAGE("Not implemented for this presentation type: " << aData.myPrsType);
668 if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) { // successive animation mode
669 if ( myFieldsAbsFrames.size() == getNbFields() )
670 myFieldsAbsFrames.clear();
671 if ( theFieldNum > 0 )
672 myFieldsAbsFrames.push_back(myFieldsAbsFrames.back() + aData.myNbFrames);
674 myFieldsAbsFrames.push_back(aData.myNbFrames);
676 if (theFieldNum == getNbFields() - 1) {
677 if ( aData.myPrsType != VISU::TGAUSSPOINTS && aData.myPrsType != TDEFORMEDSHAPEANDSCALARMAP && aData.myPrsType != TSCALARMAPONDEFORMEDSHAPE) {
679 // Initialize the MinMax controller
680 VISU::PCompositeMinMaxController aMinMaxController(new VISU::TCompositeMinMaxController());
681 if ( myAnimationMode == VISU::Animation::PARALLEL ) {
682 FieldData& aFieldData = getFieldData(theFieldNum);
683 VISU::ColoredPrs3d_i* aPrs3d = aFieldData.myPrs[0];
684 aMinMaxController->AddController( aPrs3d, VISU::CreateDefaultMinMaxController( aPrs3d ) );
686 for (int aFieldId = 0; aFieldId < getNbFields(); aFieldId++) {
687 FieldData& aFieldData = getFieldData(aFieldId);
688 VISU::ColoredPrs3d_i* aPrs3d = aFieldData.myPrs[0];
689 aMinMaxController->AddController( aPrs3d, VISU::CreateDefaultMinMaxController( aPrs3d ) );
693 double aMin = getMinFieldsValue(myFieldsLst);
694 double aMax = getMaxFieldsValue(myFieldsLst);
696 for (int aFieldId = 0; aFieldId < getNbFields(); aFieldId++) {
697 FieldData& aFieldData = getFieldData(aFieldId);
698 for (long aFrameId = 0; aFrameId < aFieldData.myNbFrames; aFrameId++) {
699 VISU::ColoredPrs3d_i* aPrs3d = aFieldData.myPrs[aFrameId];
700 aPrs3d->SetMinMaxController(aMinMaxController);
701 if (VISU::IsoSurfaces_i* anIsoSurfaces = dynamic_cast<VISU::IsoSurfaces_i*>(aPrs3d))
702 anIsoSurfaces->SetSubRange(aMin, aMax);
711 //------------------------------------------------------------------------
712 CORBA::Boolean VISU_TimeAnimation::_generateFrames() {
714 MESSAGE("Viewer is not defined for animation");
718 myLastError = QString("Frame(s) for ");
719 bool aNoError = true;
723 for (int i = 0; i < getNbFields(); i++) {
724 FieldData& aData = myFieldsLst[i];
725 aData.myActors.resize(aData.myNbFrames,NULL);
726 for (long j = 0; j < aData.myNbFrames; j++) {
727 VISU_Actor* aActor = NULL;
729 aData.myPrs[j]->SetOffset(aData.myOffset);
730 aActor = aData.myPrs[j]->CreateActor();
731 myView->AddActor(aActor);
732 bool condition = ( myAnimationMode == VISU::Animation::PARALLEL ) ? (j == 0) : (j == 0 && i == 0);
734 aActor->VisibilityOn();
736 aActor->VisibilityOff();
737 }catch(...){ //catch(std::runtime_error& exc){
739 myLastError += QString("%1 ").arg(aData.myTiming[j]);
741 aData.myActors[j] = aActor;
745 myLastError += QString(" timestamp(s) cannot be created.");
746 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
747 myFrame, myFieldsLst[0].myTiming[myFrame]));
752 //------------------------------------------------------------------------
753 CORBA::Boolean VISU_TimeAnimation::generateFrames()
755 return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
756 (this,&VISU_TimeAnimation::_generateFrames));
759 //------------------------------------------------------------------------
760 void VISU_TimeAnimation::_clearView() {
762 MESSAGE("Viewer is not defined for animation");
765 vtkRenderer* aRen = myView->getRenderer();
766 for (int i = 0; i < getNbFields(); i++) {
767 FieldData& aData = myFieldsLst[i];
768 if (!aData.myActors.empty()) {
769 for (int i = 0, iEnd = aData.myActors.size(); i < iEnd; i++) {
770 if (aData.myActors[i] != 0) {
771 aData.myActors[i]->RemoveFromRender(aRen);
774 aData.myActors.clear();
777 VISU::RepaintView(myView);
780 //------------------------------------------------------------------------
781 void VISU_TimeAnimation::clearView()
783 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
784 (this,&VISU_TimeAnimation::_clearView));
787 //------------------------------------------------------------------------
788 void VISU_TimeAnimation::_visibilityOff(int num_field, int num_frame) {
790 MESSAGE("Viewer is not defined for animation");
793 if ( num_field < 0 || num_frame < 0 ) return;
794 FieldData& aData = myFieldsLst[num_field];
795 if ( aData.myActors.empty() ) return;
796 VISU_Actor* aActor = aData.myActors[num_frame];
797 if (! myCleaningMemoryAtEachFrame) {
799 // Usual behaviour : VisibilityOff()
800 // Problem : It don't clean the memory so if there is
801 // a lot of frames, the memory grows dramatically
803 aActor->VisibilityOff();
806 // myCleaningMemoryAtEachFrame behaviour:
807 // Delete the actor and re-creation it with VisibilityOff()
808 // since it takes memory only at VisibilityOn()
811 aActor->RemoveFromRender(myView->getRenderer());
812 // Re-create the actor
813 aActor = aData.myPrs[num_frame]->CreateActor();
814 myView->AddActor(aActor);
815 aActor->VisibilityOff();
816 aData.myActors[num_frame] = aActor;
820 //------------------------------------------------------------------------
821 void VISU_TimeAnimation::visibilityOff(int num_field, int num_frame)
823 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,int,int>
824 (this,&VISU_TimeAnimation::_visibilityOff,num_field,num_frame));
827 //------------------------------------------------------------------------
828 void VISU_TimeAnimation::stopAnimation()
830 myExecutionState->SetActive(false);
833 //------------------------------------------------------------------------
834 void VISU_TimeAnimation::_startAnimation() {
835 if (!myExecutionState->IsActive()) {
836 myExecutionState->SetActive(true);
841 //------------------------------------------------------------------------
842 void VISU_TimeAnimation::startAnimation()
844 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
845 (this,&VISU_TimeAnimation::_startAnimation));
848 //------------------------------------------------------------------------
849 void VISU_TimeAnimation::_nextFrame() {
851 MESSAGE("Viewer is not defined for animation");
855 if (myFrame < getNbFrames() - 1 ) { //(myFieldsLst[0].myNbFrames-1)) {
857 std::pair<int,long> aPair;
861 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
862 for (i = 0; i < getNbFields(); i++)
863 if (myFieldsLst[i].myActors[myFrame] != 0)
864 visibilityOff(i, myFrame);
866 else { //successive animation mode
867 aPair = getRelativeFrameNumber(myFrame);
868 aFieldId = aPair.first;
869 aFrameId = aPair.second;
870 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
871 visibilityOff(aFieldId, aFrameId);
876 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
877 for (i = 0; i < getNbFields(); i++)
878 if (myFieldsLst[i].myActors[myFrame] != 0)
879 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
881 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
882 myFrame, myFieldsLst[0].myTiming[myFrame]));
884 else { //successive animation mode
885 aPair = getRelativeFrameNumber(myFrame);
886 aFieldId = aPair.first;
887 aFrameId = aPair.second;
888 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
889 myFieldsLst[aFieldId].myActors[aFrameId]->VisibilityOn();
891 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
892 myFrame, myFieldsLst[aFieldId].myTiming[aFrameId]));
898 //------------------------------------------------------------------------
899 void VISU_TimeAnimation::nextFrame()
901 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
902 (this,&VISU_TimeAnimation::_nextFrame));
905 //------------------------------------------------------------------------
906 void VISU_TimeAnimation::_prevFrame() {
908 MESSAGE("Viewer is not defined for animation");
914 std::pair<int,long> aPair;
918 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
919 for (i = 0; i < getNbFields(); i++)
920 if (myFieldsLst[i].myActors[myFrame] != 0)
921 visibilityOff(i, myFrame);
923 else { //successive animation mode
924 aPair = getRelativeFrameNumber(myFrame);
925 aFieldId = aPair.first;
926 aFrameId = aPair.second;
927 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
928 visibilityOff(aFieldId, aFrameId);
933 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
934 for (i = 0; i < getNbFields(); i++)
935 if (myFieldsLst[i].myActors[myFrame] != 0)
936 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
938 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
939 myFrame, myFieldsLst[0].myTiming[myFrame]));
941 else { //successive animation mode
942 aPair = getRelativeFrameNumber(myFrame);
943 aFieldId = aPair.first;
944 aFrameId = aPair.second;
945 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
946 myFieldsLst[aFieldId].myActors[aFrameId]->VisibilityOn();
948 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
949 myFrame, myFieldsLst[aFieldId].myTiming[aFrameId]));
955 //------------------------------------------------------------------------
956 void VISU_TimeAnimation::prevFrame()
958 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
959 (this,&VISU_TimeAnimation::_prevFrame));
962 //------------------------------------------------------------------------
963 void VISU_TimeAnimation::_firstFrame() {
965 MESSAGE("Viewer is not defined for animation");
970 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
971 for (i = 0; i < getNbFields(); i++)
972 if(!myFieldsLst[i].myActors.empty())
973 if (myFieldsLst[i].myActors[myFrame] != 0)
974 visibilityOff(i, myFrame);
976 else { //successive animation mode
977 std::pair<int,long> aPair = getRelativeFrameNumber(myFrame);
978 int aFieldId = aPair.first;
979 long aFrameId = aPair.second;
980 if(!myFieldsLst[aFieldId].myActors.empty())
981 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
982 visibilityOff(aFieldId, aFrameId);
987 if ( myAnimationMode == VISU::Animation::PARALLEL ) // parallel animation mode
988 imax = getNbFields();
989 else //successive animation mode
992 for (i = 0; i < imax; i++)
993 if(!myFieldsLst[i].myActors.empty())
994 if (myFieldsLst[i].myActors[myFrame] != 0)
995 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
997 if(!myFieldsLst[0].myTiming.empty()){
998 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
999 myFrame, myFieldsLst[0].myTiming[myFrame]));
1004 //------------------------------------------------------------------------
1005 void VISU_TimeAnimation::firstFrame()
1007 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1008 (this,&VISU_TimeAnimation::_firstFrame));
1011 //------------------------------------------------------------------------
1012 void VISU_TimeAnimation::_lastFrame() {
1014 MESSAGE("Viewer is not defined for animation");
1019 std::pair<int,long> aPair;
1023 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1024 for (i = 0; i < getNbFields(); i++)
1025 if (myFieldsLst[i].myActors[myFrame] != 0)
1026 visibilityOff(i, myFrame);
1028 else { //successive animation mode
1029 aPair = getRelativeFrameNumber(myFrame);
1030 aFieldId = aPair.first;
1031 aFrameId = aPair.second;
1032 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
1033 visibilityOff(aFieldId, aFrameId);
1036 myFrame = getNbFrames() - 1; //myFieldsLst[0].myNbFrames-1;
1038 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1039 for (i = 0; i < getNbFields(); i++)
1040 if (myFieldsLst[i].myActors[myFrame] != 0)
1041 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
1043 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
1044 myFrame, myFieldsLst[0].myTiming[myFrame]));
1046 else { //successive animation mode
1047 aPair = getRelativeFrameNumber(myFrame);
1048 aFieldId = aPair.first;
1049 aFrameId = aPair.second;
1050 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
1051 myFieldsLst[aFieldId].myActors[aFrameId]->VisibilityOn();
1053 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
1054 myFrame, myFieldsLst[aFieldId].myTiming[aFrameId]));
1060 //------------------------------------------------------------------------
1061 void VISU_TimeAnimation::lastFrame()
1063 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1064 (this,&VISU_TimeAnimation::_lastFrame));
1068 //------------------------------------------------------------------------
1069 // For Batchmode using
1070 void VISU_TimeAnimation::_gotoFrame(CORBA::Long theFrame) {
1072 MESSAGE("Viewer is not defined for animation");
1075 if ((theFrame < 0) || (theFrame > (getNbFrames()-1)))
1079 std::pair<int,long> aPair;
1083 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1084 for (i = 0; i < getNbFields(); i++)
1085 if (myFieldsLst[i].myActors[myFrame] != 0)
1086 visibilityOff(i, myFrame);
1088 else { //successive animation mode
1089 aPair = getRelativeFrameNumber(myFrame);
1090 aFieldId = aPair.first;
1091 aFrameId = aPair.second;
1092 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
1093 visibilityOff(aFieldId, aFrameId);
1098 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1099 for (i = 0; i < getNbFields(); i++)
1100 if (myFieldsLst[i].myActors[myFrame] != 0)
1101 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
1103 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
1104 myFrame, myFieldsLst[0].myTiming[myFrame]));
1106 else { //successive animation mode
1107 aPair = getRelativeFrameNumber(myFrame);
1108 aFieldId = aPair.first;
1109 aFrameId = aPair.second;
1110 if (myFieldsLst[aFieldId].myActors[aFrameId] != 0)
1111 myFieldsLst[aFieldId].myActors[aFrameId]->VisibilityOn();
1113 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>(this, &VISU_TimeAnimation::_emitFrameChanged,
1114 myFrame, myFieldsLst[aFieldId].myTiming[aFrameId]));
1120 //------------------------------------------------------------------------
1121 void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame)
1123 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
1124 (this,&VISU_TimeAnimation::_gotoFrame,theFrame));
1127 //------------------------------------------------------------------------
1128 void VISU_TimeAnimation::_emitFrameChanged(long theNewFrame, double theTime)
1130 emit frameChanged(theNewFrame, theTime);
1133 //------------------------------------------------------------------------
1134 void VISU_TimeAnimation::_emitStopped()
1139 //------------------------------------------------------------------------
1140 VISU::ColoredPrs3d_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) {
1141 if ((theField > getNbFields()) || (theField < 0))
1142 return VISU::ColoredPrs3d::_nil();
1143 if ((theFrame < 0) || (theFrame > (myFieldsLst[theField].myNbFrames - 1)))
1144 return VISU::ColoredPrs3d::_nil();
1145 return myFieldsLst[theField].myPrs[theFrame]->_this();
1148 //------------------------------------------------------------------------
1149 void VISU_TimeAnimation::setPresentationType(CORBA::Long theFieldNum, VISU::VISUType theType) {
1150 if ( theFieldNum < 0 || theFieldNum >= myFieldsLst.size() )
1153 myFieldsLst[theFieldNum].myPrsType = theType;
1156 //------------------------------------------------------------------------
1157 VISU::VISUType VISU_TimeAnimation::getPresentationType(CORBA::Long theFieldNum) {
1158 if ( theFieldNum < 0 || theFieldNum >= myFieldsLst.size() )
1161 return myFieldsLst[theFieldNum].myPrsType;
1164 //------------------------------------------------------------------------
1165 CORBA::Long VISU_TimeAnimation::getNbFrames() {
1166 if ( myAnimationMode == VISU::Animation::PARALLEL ) // parallel animation mode
1167 return (getNbFields() > 0)? myFieldsLst[0].myNbFrames : 0;
1168 else //successive animation mode
1169 return (getNbFields() > 0 && !myFieldsAbsFrames.empty()) ? myFieldsAbsFrames[myFieldsAbsFrames.size()-1] : 0;
1172 //------------------------------------------------------------------------
1173 long VISU_TimeAnimation::getAbsoluteFrameNumber(std::pair<int,long> theFieldTimeStamp)
1176 if ( getNbFields() > 0 ) {
1177 int aFieldId = theFieldTimeStamp.first;
1178 long aFrameNum = theFieldTimeStamp.second + 1;
1179 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1180 if ( aFrameNum <= myFieldsAbsFrames[0] )
1183 else { //successive animation mode
1184 if ( aFieldId == 0 && aFrameNum <= myFieldsAbsFrames[aFieldId] )
1186 else if ( aFieldId && aFrameNum <= myFieldsAbsFrames[aFieldId] - myFieldsAbsFrames[aFieldId-1] )
1187 aRes = myFieldsAbsFrames[aFieldId-1] + aFrameNum;
1193 //------------------------------------------------------------------------
1194 std::pair<int,long> VISU_TimeAnimation::getRelativeFrameNumber(long theFrame)
1196 std::pair<int,long> aRes;
1197 if ( getNbFields() > 0 && theFrame < getNbFrames() ) {
1198 theFrame = theFrame + 1;
1199 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
1201 aRes.second = theFrame - 1;
1203 else { //successive animation mode
1204 for (int i = 0, iEnd = myFieldsAbsFrames.size(); i < iEnd; i++)
1205 if ( myFieldsAbsFrames[i] >= theFrame ) {
1208 aRes.second = theFrame - 1;
1210 aRes.second = theFrame-myFieldsAbsFrames[i-1] - 1;
1218 //------------------------------------------------------------------------
1219 void VISU_TimeAnimation::parallelAnimation( bool& theIsDumping, QList<int>& theIndexList )
1223 FieldData& aFirstFieldData = myFieldsLst[0];
1224 if (aFirstFieldData.myNbFrames > 2)
1225 aOneVal = ( myTimeMax - myTimeMin ) / getNbFrames();
1228 bool aHasNextFrame = aFirstFieldData.myField && aFirstFieldData.myNbFrames > 0;
1229 while (aHasNextFrame && myExecutionState->IsActive()) {
1230 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>
1231 (this, &VISU_TimeAnimation::_emitFrameChanged,
1232 myFrame, aFirstFieldData.myTiming[myFrame]));
1233 if (myExecutionState->IsActive()) {
1234 for (int i = 0; i < getNbFields(); i++) {
1235 FieldData& aData = myFieldsLst[i];
1236 if (aData.myNbFrames == 0)
1239 if (aData.myActors[myFrame-1] != 0)
1240 visibilityOff(i, myFrame-1);
1242 if (aData.myActors[aData.myNbFrames-1] != 0)
1243 visibilityOff(i, aData.myNbFrames-1);
1245 if (aData.myActors[myFrame] != 0 && myView) {
1246 ProcessVoidEvent(new TVoidMemFunEvent<VISU_Actor>(aData.myActors[myFrame],
1247 &VISU_Actor::VisibilityOn));
1252 bool repainArg = false;
1253 ProcessVoidEvent(new TVoidMemFun1ArgEvent<SVTK_ViewWindow,bool>(myView,
1254 &SVTK_ViewWindow::Repaint,
1259 if (myProportional) {
1264 if (aFirstFieldData.myNbFrames > 2)
1265 k = (aFirstFieldData.myTiming[myFrame+1] -
1266 aFirstFieldData.myTiming[myFrame]) / aOneVal;
1269 if (myFrame < (aFirstFieldData.myNbFrames - 1))
1270 k = (aFirstFieldData.myTiming[myFrame+1] -
1271 aFirstFieldData.myTiming[myFrame]) / aOneVal;
1274 int delay = (int)(1000. * k / mySpeed);
1275 theIsDumping = !myDumpPath->GetPath().isEmpty();
1276 if (delay < 1 && theIsDumping) {
1277 // We must unlock mutex for some time before grabbing to allow view updating
1281 if (!myExecutionState->IsActive())
1285 // We must unlock mutex for some time before grabbing to allow view updating
1287 if (!myExecutionState->IsActive())
1290 if (!(aFirstFieldData.myField)) // break, if field was deleted.
1293 saveImages( 0, aOneVal, aNbFiles, theIndexList );
1296 if (!myExecutionState->IsActive())
1300 if (myFrame == aFirstFieldData.myNbFrames) {
1302 aHasNextFrame = false;
1308 } // while (aHasNextFrame && myExecutionState->IsActive())
1311 //------------------------------------------------------------------------
1312 void VISU_TimeAnimation::successiveAnimation( bool& theIsDumping, QList<int>& theIndexList )
1314 if (myFrame >= getNbFrames() - 1)
1316 myExecutionState->SetActive(false);
1322 FieldData& aFirstFieldData = myFieldsLst[0];
1323 if (aFirstFieldData.myNbFrames > 2)
1324 aOneVal = ( myTimeMax - myTimeMin ) / getNbFrames();
1326 long aFrame = myFrame;
1328 bool aHasNextFrame = true;
1329 while (aHasNextFrame && myExecutionState->IsActive())
1331 for (int aFieldId = 0;
1332 (aFieldId < getNbFields()) && (myFieldsLst[aFieldId].myField);
1333 aFieldId++, aFrame = 0)
1335 if (!myExecutionState->IsActive()) break;
1337 FieldData& aData = myFieldsLst[aFieldId];
1338 if ( !aData.myPrs[0] ) continue;
1339 for (; aFrame < aData.myNbFrames && myExecutionState->IsActive(); aFrame++, myFrame++)
1341 ProcessVoidEvent(new TVoidMemFun2ArgEvent<VISU_TimeAnimation,long,double>
1342 (this, &VISU_TimeAnimation::_emitFrameChanged,
1343 myFrame, myFieldsLst[aFieldId].myTiming[aFrame]));
1345 if (myExecutionState->IsActive()) {
1347 if (aData.myActors[aFrame-1] != 0)
1348 visibilityOff(aFieldId, aFrame-1);
1349 } else if ( myFrame > 0) {
1350 if (myFieldsLst[aFieldId-1].myActors[myFieldsLst[aFieldId-1].myNbFrames-1] != 0)
1351 visibilityOff(aFieldId-1, myFieldsLst[aFieldId-1].myNbFrames-1);
1352 } else if ( myCycling ) {
1353 if (myFieldsLst[getNbFields()-1].myActors[myFieldsLst[getNbFields()-1].myNbFrames-1] != 0)
1354 visibilityOff(getNbFields()-1, myFieldsLst[getNbFields()-1].myNbFrames-1);
1356 if (aData.myActors[aData.myNbFrames-1] != 0)
1357 visibilityOff(aFieldId, aData.myNbFrames-1);
1359 if (aData.myActors[aFrame] != 0 && myView) {
1360 ProcessVoidEvent(new TVoidMemFunEvent<VISU_Actor>(aData.myActors[aFrame],
1361 &VISU_Actor::VisibilityOn));
1366 bool repainArg = false;
1367 ProcessVoidEvent(new TVoidMemFun1ArgEvent<SVTK_ViewWindow,bool>(myView,
1368 &SVTK_ViewWindow::Repaint,
1373 if (myProportional) {
1378 if (aFirstFieldData.myNbFrames > 2)
1379 k = (aFirstFieldData.myTiming[aFrame+1] -
1380 aFirstFieldData.myTiming[aFrame]) / aOneVal;
1383 if (aFrame < (aFirstFieldData.myNbFrames - 1))
1384 k = (aFirstFieldData.myTiming[aFrame+1] -
1385 aFirstFieldData.myTiming[aFrame]) / aOneVal;
1388 int delay = (int)(1000. * k / mySpeed);
1389 theIsDumping = !myDumpPath->GetPath().isEmpty();
1390 if (delay < 1 && theIsDumping) {
1391 // We must unlock mutex for some time before grabbing to allow view updating
1396 if (!myExecutionState->IsActive()) return;
1399 // We must unlock mutex for some time before grabbing to allow view updating
1401 if (!myExecutionState->IsActive()) return;
1403 if (!(myFieldsLst[aFieldId].myField)) // break, if field was deleted.
1406 saveImages( aFieldId, aOneVal, aNbFiles, theIndexList );
1408 } // for (; aFrame < aData.myNbFrames && myExecutionState->IsActive(); aFrame++, myFrame++)
1409 } // for (int aFieldId = 0;
1412 aHasNextFrame = false;
1419 } // while (aHasNextFrame && myExecutionState->IsActive())
1422 //------------------------------------------------------------------------
1423 void VISU_TimeAnimation::saveImages( int theFieldId,
1424 double& theOneVal, int& theNbFiles,
1425 QList<int>& theIndexList )
1427 if (myDumpFormat.compare("AVI") != 0) {
1428 QString aFile(myDumpPath->GetPath());
1430 int aFrameNb = myFrame; // parallel animation mode
1431 if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) // successive animation mode
1432 aFrameNb = getRelativeFrameNumber(myFrame).second;
1434 int aMaxNb = myFieldsLst[theFieldId].myTiming.size();
1435 int nbDigits = QString("%1").arg(aMaxNb).length();
1436 QString aFormat = QString("%.%1d_").arg(nbDigits);
1439 aName.sprintf(aFormat.toLatin1().data(), aFrameNb);
1440 aName += QString("%1").arg(myFieldsLst[theFieldId].myTiming[aFrameNb]);
1443 while ((aPos = aName.indexOf(".")) > -1 )
1444 aName.replace(aPos, 1, "_");
1447 aFile += myDumpFormat.toLower();
1448 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1449 (myView,&SVTK_ViewWindow::RefreshDumpImage)); // IPAL13602
1450 ProcessEvent(new TMemFun2ArgEvent<SUIT_ViewWindow,bool,const QString&,const QString&>
1451 (myView,&SUIT_ViewWindow::dumpViewToFormat,aFile,myDumpFormat));
1453 QFileInfo aFileInfo(myDumpPath->GetPath());
1454 QString aDirPath = aFileInfo.absolutePath();
1455 QString aBaseName = aFileInfo.fileName();
1457 if( myTimeStampFrequency > 1 && myFrame % myTimeStampFrequency != 0 )
1467 if (myProportional) {
1468 FieldData& aFirstFieldData = myFieldsLst[0];
1469 double p = (aFirstFieldData.myTiming[myFrame] -
1470 aFirstFieldData.myTiming[myFrame-1]) / theOneVal;
1471 myFileIndex += (long) (5*p);
1477 QString aFile = aDirPath + QDir::separator() + aBaseName;
1479 aFile += QString("%1").arg(myFileIndex).rightJustified(8, '0');
1482 /* check image size is divisable 16
1483 myView->dumpViewToFormat(aFile,"JPEG");
1485 SUIT_ViewWindow* aView = myView;
1486 ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>(myView,&SVTK_ViewWindow::RefreshDumpImage)); // IPAL13602
1487 QImage img = ProcessEvent(new TMemFunEvent<SUIT_ViewWindow,QImage>(aView,&SUIT_ViewWindow::dumpView));
1488 if (!img.isNull()) {
1489 int width = img.width(); width = (width/16)*16;
1490 int height = img.height(); height = (height/16)*16;
1491 QImage copy = img.copy(0, 0, width, height);
1492 if (copy.save(aFile, "JPEG")) {
1493 theIndexList.append(myFileIndex);
1500 //------------------------------------------------------------------------
1501 void VISU_TimeAnimation::run()
1504 MESSAGE("Viewer is not defined for animation");
1508 bool isDumping = !myDumpPath->GetPath().isEmpty();
1510 QList<int> anIndexList;
1512 if ( myAnimationMode == VISU::Animation::PARALLEL ) // parallel animation mode
1513 parallelAnimation( isDumping, anIndexList );
1514 else //successive animation mode
1515 successiveAnimation( isDumping, anIndexList );
1517 // make AVI file if need
1518 if (isDumping && myDumpFormat.compare("AVI") == 0 && myExecutionState->IsActive()) {
1519 double aFPS = 17.3 * mySpeed / myTimeStampFrequency;
1521 QFileInfo aFileInfo(myDumpPath->GetPath());
1522 QString aDirPath = aFileInfo.absolutePath();
1523 QString aBaseName = aFileInfo.fileName();
1525 // add missing files
1526 if (anIndexList.count() > 1) {
1527 QString aFFile = aDirPath + "/" + aBaseName;
1528 aFFile += QString("_%1.jpeg");
1529 int aStartIndex = anIndexList[0], anEndIndex;
1530 for (int i = 1; i < anIndexList.count(); i++) {
1531 anEndIndex = anIndexList[i];
1532 QString aCurFile = aFFile.arg(QString::number(aStartIndex).rightJustified(8, '0'));
1533 QStringList aCommands;
1535 for (int j = aStartIndex+1; j < anEndIndex; j++) {
1536 QString aFile = aFFile.arg(QString::number(j).rightJustified(8, '0'));
1538 aCommands.append(QString("ln -s %1 %2").arg(aCurFile).arg(aFile));
1539 aSeparator = QString(" ; \\\n");
1541 aCommands.append(QString("COPY /Y %1 %2 > NUL").arg(QString(aCurFile).replace("/","\\\\")).arg(QString(aFile).replace("/","\\\\")));
1542 aSeparator = QString(" & ");
1545 system(aCommands.join(aSeparator).toLatin1().data());
1546 aStartIndex = anEndIndex;
1551 QString aPattern = aDirPath + "/" + aBaseName;
1552 aPattern += "_\%08d.jpeg";
1554 QString aCmd = myAVIMaker;
1557 aCmd += QString(" -f %1").arg(aFPS);
1558 // aCmd += QString(" -n %1").arg(aNbFiles);
1559 aCmd += QString(" -n %1").arg(myFileIndex+1);
1560 aCmd += QString(" -j \"%1\"").arg(aPattern);
1561 aCmd += " | yuv2lav";
1562 aCmd += QString(" -o \"%1\"").arg(myDumpPath->GetPath());
1566 system(aCmd.toLatin1().data());
1568 // remove temporary jpeg files
1571 aCmd += QString("cd %1").arg(aDirPath);
1573 aCmd += QString(" | egrep '%1_[0-9]*.jpeg'").arg(aBaseName);
1574 aCmd += " | xargs rm";
1577 QString tmpFile = QString("_") + aBaseName + "_tempfile";
1578 QString diskName = aDirPath.split("/")[0];
1579 aCmd = diskName + " && (cd " + aDirPath.replace("/","\\\\") +
1580 " && ((dir /b | findstr " + aBaseName + "_[0-9]*.jpeg > " + tmpFile +
1581 ") & (for /f %i in (" + tmpFile + ") do (del \"%i\")) & (del " + tmpFile + "))) > NUL";
1583 system(aCmd.toLatin1().data());
1586 if (myExecutionState->IsActive())
1587 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>(this,&VISU_TimeAnimation::_emitStopped));
1588 myExecutionState->SetActive(false);
1591 //------------------------------------------------------------------------
1592 VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField)
1594 _PTR(SObject) aSObj = theField->GetFather();
1595 aSObj = aSObj->GetFather();
1596 aSObj = aSObj->GetFather();
1597 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
1598 if (CORBA::is_nil(anObject)) return NULL;
1599 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
1602 //------------------------------------------------------------------------
1603 double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp)
1605 _PTR(GenericAttribute) anAttr;
1606 if (theTimeStamp->FindAttribute(anAttr, "AttributeName")) {
1607 _PTR(AttributeName) aName (anAttr);
1608 QString aNameString (aName->Value().c_str());
1609 int time_len = aNameString.indexOf(',');
1611 return aNameString.left(time_len).toDouble();
1613 return aNameString.toDouble();
1618 //------------------------------------------------------------------------
1619 void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed)
1621 mySpeed = (theSpeed<1)? 1 : theSpeed;
1624 //------------------------------------------------------------------------
1625 void VISU_TimeAnimation::setAnimationSequence(const char* theSequence)
1627 mySequence = QString( theSequence );
1630 //------------------------------------------------------------------------
1631 char* VISU_TimeAnimation::getAnimationSequence()
1633 return strdup( mySequence.toLatin1().data() );
1636 //------------------------------------------------------------------------
1637 CORBA::Boolean VISU_TimeAnimation::isSequenceDefined()
1639 return !mySequence.isEmpty();
1642 //------------------------------------------------------------------------
1643 bool VISU_TimeAnimation::getIndicesFromSequence( QString theSequence, QList<long>& theIndices )
1645 bool isCorrect = true;
1649 QStringList aList = theSequence.split( ",", QString::SkipEmptyParts );
1650 QStringList::iterator it = aList.begin();
1651 QStringList::iterator itEnd = aList.end();
1652 for( ; it != itEnd; ++it )
1659 QString aString = *it;
1660 if( aString.isEmpty() )
1664 int aSingleIndex = aString.toLong( &ok );
1667 theIndices.append( aSingleIndex );
1670 else if( aString.contains( '-' ) == 1 )
1672 QString aLeftIndexStr = aString.section( '-', 0, 0 );
1673 QString aRightIndexStr = aString.section( '-', -1 );
1676 int aLeftIndex = aLeftIndexStr.toLong( &ok );
1681 int aRightIndex = aRightIndexStr.toLong( &ok );
1685 if( aLeftIndex >= aRightIndex )
1688 for( int i = aLeftIndex; i <= aRightIndex; i++ )
1689 theIndices.append( i );
1698 //------------------------------------------------------------------------
1699 void VISU_TimeAnimation::dumpTo(const char* thePath)
1701 myDumpPath->SetPath( QString( thePath ) );
1704 //------------------------------------------------------------------------
1705 std::string VISU_TimeAnimation::setDumpFormat(const char* theFormat)
1707 myDumpFormat = theFormat;
1708 QList<QByteArray> aDumpFormats = QImageWriter::supportedImageFormats();
1709 if (myDumpFormat.isEmpty() ||
1710 (aDumpFormats.indexOf(theFormat) < 0 && myDumpFormat.compare("AVI") != 0)) {
1711 if (aDumpFormats.indexOf("JPEG") >= 0 ||
1712 aDumpFormats.indexOf("jpeg") >= 0)
1713 myDumpFormat = "JPEG";
1715 myDumpFormat = aDumpFormats.at(0);
1717 return myDumpFormat.toLatin1().data();
1720 //------------------------------------------------------------------------
1721 void VISU_TimeAnimation::setTimeStampFrequency(CORBA::Long theFrequency)
1723 myTimeStampFrequency = theFrequency;
1726 //------------------------------------------------------------------------
1727 bool VISU_TimeAnimation::checkAVIMaker() const
1729 QList<QByteArray> aDumpFormats = QImageWriter::supportedImageFormats();
1730 if (aDumpFormats.indexOf("JPEG") < 0 &&
1731 aDumpFormats.indexOf("jpeg") < 0)
1736 aCmd = "which " + myAVIMaker + " 2> /dev/null";
1738 aCmd = "setlocal & set P2=.;%PATH% & (for %e in (%PATHEXT%) do @for %i in (" + myAVIMaker + "%e) do @if NOT \"%~$P2:i\"==\"\" exit /b 0) & exit /b 1";
1740 int iErr = system(aCmd.toLatin1().data());
1744 //************************************************************************
1745 int VISU_TimeAnimation::myNBAnimations = 0;
1746 QString VISU_TimeAnimation::GenerateName()
1748 return VISU::GenerateName("Animation", myNBAnimations++);
1751 //------------------------------------------------------------------------
1752 std::string GetPresentationComment (VISU::VISUType thePrsType)
1754 std::string aPrsCmt;
1755 switch (thePrsType) {
1756 case VISU::TSCALARMAP:
1757 aPrsCmt = VISU::ScalarMap_i::myComment;
1759 case VISU::TISOSURFACES:
1760 aPrsCmt = VISU::IsoSurfaces_i::myComment;
1762 case VISU::TCUTPLANES:
1763 aPrsCmt = VISU::CutPlanes_i::myComment;
1765 case VISU::TCUTLINES:
1766 aPrsCmt = VISU::CutLines_i::myComment;
1768 case VISU::TCUTSEGMENT:
1769 aPrsCmt = VISU::CutSegment_i::myComment;
1772 aPrsCmt = VISU::Plot3D_i::myComment;
1774 case VISU::TDEFORMEDSHAPE:
1775 aPrsCmt = VISU::DeformedShape_i::myComment;
1777 case VISU::TVECTORS:
1778 aPrsCmt = VISU::Vectors_i::myComment;
1780 case VISU::TSTREAMLINES:
1781 aPrsCmt = VISU::StreamLines_i::myComment;
1783 case VISU::TGAUSSPOINTS:
1784 aPrsCmt = VISU::GaussPoints_i::myComment;
1786 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1787 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1788 aPrsCmt = VISU::DeformedShapeAndScalarMap_i::myComment;
1791 aPrsCmt = "Unknown presentation";
1797 //------------------------------------------------------------------------
1798 SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
1800 if (myStudy->GetProperties()->IsLocked()) {
1801 SUIT_MessageBox::warning(0,
1802 QObject::tr("WRN_VISU_WARNING"),
1803 QObject::tr("WRN_STUDY_LOCKED"),
1804 QObject::tr("BUT_OK"));
1805 return SALOMEDS::SObject::_nil();
1808 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
1809 aStudyBuilder->NewCommand(); // There is a transaction
1810 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
1811 std::string aSComponentEntry = aSComponent->GetID();
1814 aComment.sprintf("myComment=ANIMATION;myTimeMinVal=%g;myTimeMaxVal=%g;mySequence=%s;myMode=%d",
1817 mySequence.toLatin1().data(),
1820 string anEntry = VISU::CreateAttributes(myStudy,
1821 aSComponentEntry.c_str(),
1824 GenerateName().toLatin1().data(),
1825 VISU::NO_PERFSITENT_REF,
1826 aComment.toLatin1().data(),
1828 myAnimEntry = anEntry.c_str();
1829 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
1831 for (int i = 0; i < getNbFields(); i++) {
1832 FieldData& aData = myFieldsLst[i];
1833 if (aData.myPrs.empty()) {
1834 generatePresentations(i);
1836 if ( !aData.myPrs.empty() ) {
1837 _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
1838 aStudyBuilder->Addreference(newObj, aData.myField);
1840 ostringstream strOut;
1841 aData.myPrs[0]->ToStream(strOut);
1842 string aPrsComment = strOut.str();
1843 string aPrsMyComment = aData.myPrs[0]->GetComment();
1844 if(aPrsMyComment == "PRSMERGER")
1845 aPrsMyComment = "SCALARMAP";
1846 VISU::CreateAttributes(myStudy,
1847 newObj->GetID().c_str(),
1850 aPrsMyComment.c_str(),
1851 VISU::NO_PERFSITENT_REF,
1852 aPrsComment.c_str(),
1856 aStudyBuilder->CommitCommand();
1858 return VISU::GetSObject(aAnimSObject)._retn();
1861 //------------------------------------------------------------------------
1862 void VISU_TimeAnimation::saveAnimation()
1864 if (myStudy->GetProperties()->IsLocked()) return;
1865 if (myAnimEntry.isEmpty()) return;
1867 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.toLatin1().data());
1868 if (!aAnimSObject) return;
1870 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
1871 aStudyBuilder->NewCommand(); // There is a transaction
1872 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
1873 std::string aSComponentEntry = aSComponent->GetID();
1876 aComment.sprintf("myComment=ANIMATION;myTimeMinVal=%g;myTimeMaxVal=%g;mySequence=%s;myMode=%d",
1879 mySequence.toLatin1().data(),
1882 _PTR(GenericAttribute) anAttr;
1883 anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeString");
1884 _PTR(AttributeString) aCmnt (anAttr);
1885 aCmnt->SetValue(aComment.toLatin1().data());
1887 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
1888 int i = 0, nbf = getNbFields();
1889 for (anIter->Init(); anIter->More(); anIter->Next(), i++) {
1890 if (i >= nbf) break; // it must not be
1891 FieldData& aData = myFieldsLst[i];
1893 // Get presentation name and comment
1894 if (aData.myPrs.empty()) {
1895 generatePresentations(i);
1897 ostringstream strOut;
1898 aData.myPrs[0]->ToStream(strOut);
1899 string aPrsComment = strOut.str();
1900 string aPrsNameTxt = aData.myPrs[0]->GetComment();
1901 if(aPrsNameTxt == "PRSMERGER")
1902 aPrsNameTxt = "SCALARMAP";
1904 _PTR(SObject) aRefObj = anIter->Value();
1905 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
1908 if (anPrsIter->More()) {
1909 _PTR(SObject) aPrsObj = anPrsIter->Value();
1910 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeString");
1911 aCmnt = _PTR(AttributeString)(anAttr);
1912 aCmnt->SetValue(aPrsComment.c_str());
1914 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
1915 _PTR(AttributeName) aPrsName (anAttr);
1916 aPrsName->SetValue(aPrsNameTxt);
1919 VISU::CreateAttributes(myStudy,
1920 aRefObj->GetID().c_str(),
1923 aPrsNameTxt.c_str(),
1924 VISU::NO_PERFSITENT_REF,
1925 aPrsComment.c_str(),
1929 aStudyBuilder->CommitCommand();
1932 //------------------------------------------------------------------------
1933 void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
1935 _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
1936 restoreFromStudy(aAnimSObject);
1939 void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
1941 _PTR(SObject) aAnimSObject = theField;
1943 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(aAnimSObject);
1948 myTimeMinVal = VISU::Storable::FindValue(aMap,"myTimeMinVal",&isExist).toDouble();
1949 myTimeMaxVal = VISU::Storable::FindValue(aMap,"myTimeMaxVal",&isExist).toDouble();
1950 mySequence = VISU::Storable::FindValue(aMap,"mySequence",&isExist);
1951 myAnimationMode = VISU::Animation::AnimationMode(VISU::Storable::FindValue(aMap,"myMode",&isExist).toInt());
1953 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
1954 for (anIter->Init(); anIter->More(); anIter->Next()) {
1955 _PTR(SObject) aRefObj = anIter->Value();
1956 _PTR(SObject) aFieldObj;
1958 if (!aRefObj->ReferencedObject(aFieldObj) )
1961 int nbAttr = aFieldObj->GetAllAttributes().size();
1962 //std::string name1 = aFieldObj->GetName();
1966 addField(aFieldObj);
1967 if ( isRangeDefined() || isSequenceDefined() )
1968 myFieldsAbsFrames.pop_back();
1970 FieldData& aData = getFieldData(getNbFields()-1);
1972 // Get Presentation object
1973 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
1975 if (!anPrsIter->More())
1977 _PTR(SObject) aPrsObj = anPrsIter->Value();
1978 _PTR(GenericAttribute) anAttr;
1979 if (!aPrsObj->FindAttribute(anAttr, "AttributeName"))
1981 _PTR(AttributeName) aName (anAttr);
1982 string aStr = aName->Value();
1983 QString strName (aStr.c_str());
1985 if (strName == VISU::ScalarMap_i::myComment.c_str())
1986 aData.myPrsType = VISU::TSCALARMAP;
1987 else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
1988 aData.myPrsType = VISU::TISOSURFACES;
1989 else if (strName == VISU::CutPlanes_i::myComment.c_str())
1990 aData.myPrsType = VISU::TCUTPLANES;
1991 else if (strName == VISU::CutLines_i::myComment.c_str())
1992 aData.myPrsType = VISU::TCUTLINES;
1993 else if (strName == VISU::CutSegment_i::myComment.c_str())
1994 aData.myPrsType = VISU::TCUTSEGMENT;
1995 else if (strName == VISU::Plot3D_i::myComment.c_str())
1996 aData.myPrsType = VISU::TPLOT3D;
1997 else if (strName == VISU::DeformedShape_i::myComment.c_str())
1998 aData.myPrsType = VISU::TDEFORMEDSHAPE;
1999 else if (strName == VISU::Vectors_i::myComment.c_str())
2000 aData.myPrsType = VISU::TVECTORS;
2001 else if (strName == VISU::StreamLines_i::myComment.c_str())
2002 aData.myPrsType = VISU::TSTREAMLINES;
2003 else if (strName == VISU::GaussPoints_i::myComment.c_str())
2004 aData.myPrsType = VISU::TGAUSSPOINTS;
2005 else if (strName == VISU::DeformedShapeAndScalarMap_i::myComment.c_str())
2006 aData.myPrsType = VISU::TDEFORMEDSHAPEANDSCALARMAP;
2009 generatePresentations(getNbFields()-1);
2011 VISU::Storable::TRestoringMap aPrsMap = VISU::Storable::GetStorableMap(aPrsObj);
2012 if (aPrsMap.empty())
2014 if (aData.myPrs[0]) {
2015 aData.myPrs[0]->Restore(VISU::GetSObject(aData.myField), aPrsMap);
2016 aData.myPrs[0]->GetOffset(aData.myOffset);
2018 for (int i = 1; i < aData.myNbFrames; i++) {
2019 if (!aData.myPrs[0])
2021 bool anIsFixedRange = false;
2022 if (aData.myPrsType != VISU::TGAUSSPOINTS) {
2023 if (VISU::ScalarMap_i* aPrs = dynamic_cast<VISU::ScalarMap_i*>(aData.myPrs[i]))
2024 anIsFixedRange = aPrs->IsRangeFixed();
2026 if (aData.myPrsType == VISU::TDEFORMEDSHAPEANDSCALARMAP) {
2027 if (VISU::DeformedShapeAndScalarMap_i* aDeformedPrs =
2028 dynamic_cast<VISU::DeformedShapeAndScalarMap_i*>(aData.myPrs[i])) {
2029 //Set correct time stamp number
2030 int aTimeStampNum = aDeformedPrs->GetScalarTimeStampNumber();
2031 aDeformedPrs->SameAs(aData.myPrs[0]);
2032 aDeformedPrs->SetScalarField(aDeformedPrs->GetScalarEntity(),
2033 aDeformedPrs->GetScalarFieldName(),
2038 aData.myPrs[i]->SameAs(aData.myPrs[0]);
2041 string aStr = aAnimSObject->GetID();
2042 myAnimEntry = aStr.c_str();
2045 void VISU_TimeAnimation::onViewDeleted()
2051 void VISU_TimeAnimation::ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs)
2052 throw (SALOME::SALOME_Exception)
2054 Unexpect aCatch(SALOME_SalomeException);
2056 VISU::ColoredPrs3d_i* aPrs_i = dynamic_cast<VISU::ColoredPrs3d_i*>(GetServant(thePrs).in());
2059 THROW_SALOME_CORBA_EXCEPTION("Error : invalid dynamic cast of the given presentation to VISU::ColoredPrs3d_i",
2060 SALOME::INTERNAL_ERROR);
2062 if ( myAnimationMode == VISU::Animation::PARALLEL ) { // parallel animation mode
2063 FieldData& aData = myFieldsLst[theFieldNum];
2065 if ( aData.myPrs.empty() )
2066 THROW_SALOME_CORBA_EXCEPTION("Error : presentations for the given field is not yet created!",
2067 SALOME::INTERNAL_ERROR);
2069 if ( aPrs_i->GetCResult() != aData.myPrs[0]->GetCResult() )
2070 THROW_SALOME_CORBA_EXCEPTION("Error : the MED file is not the same!",
2071 SALOME::INTERNAL_ERROR);
2073 for (int i = 0; i < aData.myNbFrames; i++) {
2074 bool anIsFixedRange = false;
2075 if (aData.myPrsType != VISU::TGAUSSPOINTS) {
2076 if (VISU::ScalarMap_i* aPrs = dynamic_cast<VISU::ScalarMap_i*>(aData.myPrs[i]))
2077 anIsFixedRange = aPrs->IsRangeFixed();
2079 aData.myPrs[i]->SameAs(aPrs_i);
2082 else if ( myAnimationMode == VISU::Animation::SUCCESSIVE ) { // successive animation mode
2083 for (int f = 0; f < getNbFields(); f++) {
2084 FieldData& aData = myFieldsLst[f];
2086 if ( aData.myPrs.empty() )
2087 THROW_SALOME_CORBA_EXCEPTION("Error : presentations for the given field is not yet created!",
2088 SALOME::INTERNAL_ERROR);
2090 for (int i = 0; i < aData.myNbFrames; i++) {
2091 aData.myPrs[i]->SameAs(aPrs_i);
2097 //========================================================================
2098 //========================================================================
2099 //========================================================================
2100 struct TNewAnimationEvent: public SALOME_Event
2102 std::string myStudyName;
2103 VISU::View3D_ptr myView3D;
2105 typedef VISU_TimeAnimation* TResult;
2108 TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
2109 myStudyName(theStudyName),
2110 myView3D(VISU::View3D::_duplicate(theView3D)),
2118 SUIT_Session* aSession = SUIT_Session::session();
2119 QList<SUIT_Application*> anApplications = aSession->applications();
2120 QList<SUIT_Application*>::Iterator anIter = anApplications.begin();
2121 while ( anIter != anApplications.end() ) {
2122 SUIT_Application* anApp = *anIter;
2123 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
2124 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
2125 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
2126 if (myStudyName == aCStudy->Name()) {
2127 myResult = new VISU_TimeAnimation (aCStudy, myView3D);
2138 VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
2139 VISU::View3D_ptr theView3D)
2141 std::string aStudyName = theStudy->Name();
2142 myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
2145 VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
2150 bool VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
2152 return myAnim->addField(theField);
2155 void VISU_TimeAnimation_i::clearFields ()
2157 for (int i = 0; i < myAnim->getNbFields(); i++) {
2158 myAnim->clearData(myAnim->getFieldData(i));
2160 myAnim->clearFieldData();
2163 CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
2165 //return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
2166 // (myAnim,&VISU_TimeAnimation::generateFrames));
2167 return myAnim->generateFrames();
2170 void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
2172 myAnim->generatePresentations(theFieldNum);
2175 void VISU_TimeAnimation_i::clearView()
2177 //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2178 // (myAnim,&VISU_TimeAnimation::clearView));
2179 myAnim->clearView();
2182 void VISU_TimeAnimation_i::stopAnimation()
2184 //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2185 // (myAnim,&VISU_TimeAnimation::stopAnimation));
2186 myAnim->stopAnimation();
2189 void VISU_TimeAnimation_i::startAnimation()
2191 //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2192 // (myAnim,&VISU_TimeAnimation::startAnimation));
2193 myAnim->startAnimation();
2196 void VISU_TimeAnimation_i::nextFrame()
2198 //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2199 // (myAnim,&VISU_TimeAnimation::nextFrame));
2200 myAnim->nextFrame();
2203 void VISU_TimeAnimation_i::prevFrame()
2205 //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2206 // (myAnim,&VISU_TimeAnimation::prevFrame));
2207 myAnim->prevFrame();
2210 void VISU_TimeAnimation_i::firstFrame()
2212 //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2213 // (myAnim,&VISU_TimeAnimation::firstFrame));
2214 myAnim->firstFrame();
2217 void VISU_TimeAnimation_i::lastFrame()
2219 //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
2220 // (myAnim,&VISU_TimeAnimation::lastFrame));
2221 myAnim->lastFrame();
2224 void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
2226 //ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
2227 // (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
2228 myAnim->gotoFrame(theFrame);
2231 CORBA::Long VISU_TimeAnimation_i::getNbFields()
2233 return myAnim->getNbFields();
2236 CORBA::Long VISU_TimeAnimation_i::getNbFrames()
2238 return myAnim->getNbFrames();
2241 CORBA::Boolean VISU_TimeAnimation_i::isRunning()
2243 return myAnim->isRunning();
2246 CORBA::Long VISU_TimeAnimation_i::getCurrentFrame()
2248 return myAnim->getCurrentFrame();
2251 VISU::ColoredPrs3d_ptr VISU_TimeAnimation_i::getPresentation
2252 (CORBA::Long theField, CORBA::Long theFrame)
2254 return myAnim->getPresentation(theField,theFrame);
2257 void VISU_TimeAnimation_i::setPresentationType (CORBA::Long theFieldNum,
2258 VISU::VISUType theType)
2260 myAnim->setPresentationType(theFieldNum,theType);
2263 VISU::VISUType VISU_TimeAnimation_i::getPresentationType (CORBA::Long theFieldNum)
2265 return myAnim->getPresentationType(theFieldNum);
2268 void VISU_TimeAnimation_i::setSpeed(CORBA::Long theSpeed)
2270 myAnim->setSpeed(theSpeed);
2273 CORBA::Long VISU_TimeAnimation_i::getSpeed()
2275 return myAnim->getSpeed();
2278 CORBA::Boolean VISU_TimeAnimation_i::isProportional()
2280 return myAnim->isProportional();
2283 void VISU_TimeAnimation_i::setAnimationRange (CORBA::Double theMin,
2284 CORBA::Double theMax)
2286 myAnim->setAnimationRange(theMin,theMax);
2289 CORBA::Double VISU_TimeAnimation_i::getMinRange()
2291 return myAnim->getMinRange();
2294 CORBA::Double VISU_TimeAnimation_i::getMaxRange()
2296 return myAnim->getMaxRange();
2299 CORBA::Boolean VISU_TimeAnimation_i::isRangeDefined()
2301 return myAnim->isRangeDefined();
2304 void VISU_TimeAnimation_i::setAnimationSequence (const char* theSequence)
2306 myAnim->setAnimationSequence(theSequence);
2309 char* VISU_TimeAnimation_i::getAnimationSequence()
2311 return myAnim->getAnimationSequence();
2314 CORBA::Boolean VISU_TimeAnimation_i::isSequenceDefined()
2316 return myAnim->isSequenceDefined();
2319 void VISU_TimeAnimation_i::dumpTo (const char* thePath)
2321 myAnim->dumpTo(thePath);
2324 char* VISU_TimeAnimation_i::setDumpFormat (const char* theFormat)
2326 string aDumpFormat = myAnim->setDumpFormat(theFormat);
2327 return CORBA::string_dup(aDumpFormat.c_str());
2330 void VISU_TimeAnimation_i::setTimeStampFrequency(CORBA::Long theFrequency)
2332 myAnim->setTimeStampFrequency(theFrequency);
2335 CORBA::Long VISU_TimeAnimation_i::getTimeStampFrequency()
2337 return myAnim->getTimeStampFrequency();
2340 CORBA::Boolean VISU_TimeAnimation_i::isCycling()
2342 return myAnim->isCycling();
2345 CORBA::Boolean VISU_TimeAnimation_i::isCleaningMemoryAtEachFrame(){
2346 return myAnim->isCleaningMemoryAtEachFrame();
2349 CORBA::Double VISU_TimeAnimation_i::getMinTime()
2351 return myAnim->getMinTime();
2354 CORBA::Double VISU_TimeAnimation_i::getMaxTime()
2356 return myAnim->getMaxTime();
2359 void VISU_TimeAnimation_i::setProportional (CORBA::Boolean theProp)
2361 myAnim->setProportional(theProp);
2364 void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
2366 myAnim->setCycling(theCycle);
2369 void VISU_TimeAnimation_i::setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle){
2370 myAnim->setCleaningMemoryAtEachFrame(theCycle);
2373 SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
2375 return myAnim->publishInStudy();
2378 void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
2380 myAnim->restoreFromStudy(theObj);
2383 CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
2385 return myAnim->isSavedInStudy();
2388 void VISU_TimeAnimation_i::saveAnimation()
2390 myAnim->saveAnimation();
2393 void VISU_TimeAnimation_i::setAnimationMode(VISU::Animation::AnimationMode theMode)
2395 myAnim->setAnimationMode(theMode);
2398 VISU::Animation::AnimationMode VISU_TimeAnimation_i::getAnimationMode()
2400 return VISU::Animation::AnimationMode(myAnim->getAnimationMode());
2403 void VISU_TimeAnimation_i::ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs)
2404 throw (SALOME::SALOME_Exception)
2406 myAnim->ApplyProperties(theFieldNum, thePrs);