1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : VISU_TimeAnimation.cxx
6 // Author : Vitaly SMETANNIKOV
9 #include "VISU_TimeAnimation.h"
11 #include "VISUConfig.hh"
13 #include "VISU_Result_i.hh"
14 #include "VISU_Prs3d_i.hh"
15 #include "VISU_Mesh_i.hh"
16 #include "VISU_ScalarMap_i.hh"
17 #include "VISU_IsoSurfaces_i.hh"
18 #include "VISU_DeformedShape_i.hh"
19 #include "VISU_ScalarMapOnDeformedShape_i.hh"
20 #include "VISU_CutPlanes_i.hh"
21 #include "VISU_Plot3D_i.hh"
22 #include "VISU_CutLines_i.hh"
23 #include "VISU_Vectors_i.hh"
24 #include "VISU_StreamLines_i.hh"
25 #include "VISU_GaussPoints_i.hh"
26 #include "VISU_ViewManager_i.hh"
27 #include "VISU_View_i.hh"
29 #include "VISU_ScalarBarActor.hxx"
30 #include "VISU_Actor.h"
32 #include "SalomeApp_Study.h"
34 #include "SVTK_ViewWindow.h"
36 #include "SALOME_Event.hxx"
38 #include "SUIT_ResourceMgr.h"
39 #include "SUIT_Application.h"
40 #include "SUIT_Session.h"
41 #include "SUIT_Study.h"
43 #include "SALOMEDSClient_AttributeComment.hxx"
44 #include "SALOMEDSClient_AttributeName.hxx"
53 //------------------------------------------------------------------------
54 VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy,
55 VISU::View3D_ptr theView3D)
61 myProportional = false;
64 if (!CORBA::is_nil(theView3D)) {
65 VISU::View3D_i* pView = dynamic_cast<VISU::View3D_i*>(GetServant(theView3D).in());
66 SUIT_ViewWindow* aVW = pView->GetViewWindow();
67 myView = dynamic_cast<SVTK_ViewWindow*>(aVW);
68 connect( myView, SIGNAL( destroyed() ), this, SLOT( onViewDeleted() ) );
82 //------------------------------------------------------------------------
83 VISU_TimeAnimation::~VISU_TimeAnimation()
86 MESSAGE("Viewer is not defined for animation");
90 for (int i = 0; i < getNbFields(); i++) {
91 clearData(myFieldsLst[i]);
96 //------------------------------------------------------------------------
97 void VISU_TimeAnimation::addField (_PTR(SObject) theField)
100 aNewData.myField = theField;
101 aNewData.myNbFrames = 0;
102 aNewData.myPrsType = VISU::TSCALARMAP;
103 aNewData.myOffset[0] = aNewData.myOffset[1] = aNewData.myOffset[2] = 0;
104 VISU::Storable::TRestoringMap aMap = getMapOfValue(aNewData.myField);
105 aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
106 myFieldsLst.append(aNewData);
108 //find Min/Max timestamps
109 if ((myTimeMin == 0) && (myTimeMax == 0)) {
110 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(theField);
111 anIter->Next(); // First is reference on support
112 myTimeMin = getTimeValue(anIter->Value());
113 for(; anIter->More(); anIter->Next()) {
114 myTimeMax = getTimeValue(anIter->Value());
119 //------------------------------------------------------------------------
120 void VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField)
122 SALOMEDS::SObject_var theFieldDup = SALOMEDS::SObject::_duplicate(theField);
123 _PTR(SObject) aField = VISU::GetClientSObject(theFieldDup, myStudy);
128 //------------------------------------------------------------------------
129 void VISU_TimeAnimation::clearData(FieldData& theData) {
131 MESSAGE("Viewer is not defined for animation");
134 theData.myTiming.clear();
135 vtkRenderer* aRen = myView->getRenderer();
136 if (!theData.myActors.empty()) {
137 for (int i = 0, iEnd = theData.myActors.size(); i < iEnd; i++) {
138 if (theData.myActors[i] != 0) {
139 theData.myActors[i]->RemoveFromRender(aRen);
142 theData.myActors.clear();
144 if (!theData.myPrs.empty()) {
145 for (int i = 0, iEnd = theData.myPrs.size(); i < iEnd; i++)
146 if (theData.myPrs[i] != 0) {
147 theData.myPrs[i]->_remove_ref();
149 theData.myPrs.clear();
151 theData.myNbFrames = 0;
158 //------------------------------------------------------------------------
159 template<class TPrs3d>
161 GeneratePresentations(_PTR(Study) theStudy,
163 VISU::Result_i* theResult,
164 bool theIsRangeDefined,
165 CORBA::Double theTimeMin,
166 CORBA::Double theTimeMax)
168 double aMin = VTK_LARGE_FLOAT, aMax = -VTK_LARGE_FLOAT;
170 _PTR(ChildIterator) anIter = theStudy->NewChildIterator(theData.myField);
171 anIter->Next(); // First is reference on support
174 for(; anIter->More(); anIter->Next()){
175 if (aFrameId == theData.myNbTimes) {
176 MESSAGE("There are extra timestamps in field");
179 _PTR(SObject) aTimeStamp = anIter->Value();
183 theData.myTiming[aFrameId] = VISU_TimeAnimation::getTimeValue(aTimeStamp);
184 if (theIsRangeDefined) {
185 if (theData.myTiming[aFrameId] < theTimeMin)
187 if (theData.myTiming[aFrameId] > theTimeMax)
191 VISU::Storable::TRestoringMap aTimeMap = VISU_TimeAnimation::getMapOfValue(aTimeStamp);
192 QString aMeshName = VISU::Storable::FindValue(aTimeMap,"myMeshName");
193 VISU::Entity anEntity = (VISU::Entity) VISU::Storable::FindValue(aTimeMap,"myEntityId").toInt();
194 QString aFieldName = VISU::Storable::FindValue(aTimeMap,"myFieldName");
195 int aTimeStampId = VISU::Storable::FindValue(aTimeMap,"myTimeStampId").toInt();
197 TPrs3d* aPresent = new TPrs3d(theResult, false);
198 aPresent->Create(aMeshName.latin1(), anEntity,
199 aFieldName.latin1(), aTimeStampId);
200 theData.myPrs[aFrameId++] = aPresent;
202 aMin = std::min(aPresent->GetMin(), aMin);
203 aMax = std::max(aPresent->GetMax(), aMax);
205 theData.myNbFrames = aFrameId;
207 if (theData.myPrsType != VISU::TGAUSSPOINTS){
208 int aRangeType = VISU::GetResourceMgr()->integerValue("VISU" , "scalar_range_type", 0);
209 if( aRangeType != 1 ){
210 for(long aFrameId = 0; aFrameId < theData.myNbFrames; aFrameId++) {
211 if (VISU::ScalarMap_i* aPrs = dynamic_cast<VISU::ScalarMap_i*>(theData.myPrs[aFrameId])){
212 aPrs->SetRange(aMin, aMax);
213 aPrs->SetOffset(theData.myOffset);
217 if (theData.myPrsType == VISU::TISOSURFACE)
218 for (long aFrameId = 0; aFrameId < theData.myNbFrames; aFrameId++)
219 if (VISU::IsoSurfaces_i* aPrs = dynamic_cast<VISU::IsoSurfaces_i*>(theData.myPrs[aFrameId]))
220 aPrs->SetSubRange(aMin, aMax);
225 void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum) {
226 FieldData& aData = myFieldsLst[theFieldNum];
228 // Delete previous presentations
231 VISU::Result_i* aResult = createPresent(aData.myField);
232 VISU::Storable::TRestoringMap aMap = getMapOfValue(aData.myField);
233 aData.myNbFrames = aData.myNbTimes;
234 //VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
236 aData.myPrs.resize(aData.myNbTimes,NULL);
237 aData.myTiming.resize(aData.myNbTimes);
239 using namespace VISU;
240 switch (aData.myPrsType) {
241 case VISU::TSCALARMAP: // ScalarMap
242 GeneratePresentations<ScalarMap_i>(myStudy,
249 case VISU::TISOSURFACE: // Iso Surfaces
250 GeneratePresentations<IsoSurfaces_i>(myStudy,
257 case VISU::TCUTPLANES: // Cut Planes
258 GeneratePresentations<CutPlanes_i>(myStudy,
265 case VISU::TCUTLINES: // Cut Lines
266 GeneratePresentations<CutLines_i>(myStudy,
273 case VISU::TPLOT3D: // Plot3d
274 GeneratePresentations<Plot3D_i>(myStudy,
281 case VISU::TDEFORMEDSHAPE: // Deformed Shape
282 GeneratePresentations<DeformedShape_i>(myStudy,
289 case VISU::TVECTORS: // Vectors
290 GeneratePresentations<Vectors_i>(myStudy,
297 case VISU::TSTREAMLINES: // Stream Lines
298 GeneratePresentations<StreamLines_i>(myStudy,
305 case VISU::TGAUSSPOINTS: // Gauss Points
306 GeneratePresentations<GaussPoints_i>(myStudy,
313 case VISU::TSCALARMAPONDEFORMEDSHAPE: // Scalar map on deformed shape
314 GeneratePresentations<ScalarMapOnDeformedShape_i>(myStudy,
322 MESSAGE("Not implemented for this presentation type: " << aData.myPrsType);
328 //------------------------------------------------------------------------
329 CORBA::Boolean VISU_TimeAnimation::generateFrames() {
331 MESSAGE("Viewer is not defined for animation");
335 myLastError = QString("Frame(s) for ");
336 bool aNoError = true;
340 for (int i = 0; i < getNbFields(); i++) {
341 FieldData& aData = myFieldsLst[i];
342 aData.myActors.resize(aData.myNbFrames,NULL);
343 for (long j = 0; j < aData.myNbFrames; j++) {
344 VISU_Actor* aActor = NULL;
346 aData.myPrs[j]->SetOffset(aData.myOffset);
347 aActor = aData.myPrs[j]->CreateActor();
348 myView->AddActor(aActor);
350 aActor->VisibilityOn();
352 aActor->VisibilityOff();
353 }catch(...){ //catch(std::runtime_error& exc){
355 myLastError += QString("%1 ").arg(aData.myTiming[j]);
357 aData.myActors[j] = aActor;
361 myLastError += QString(" timestamp(s) cannot be created.");
362 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
367 //------------------------------------------------------------------------
368 void VISU_TimeAnimation::clearView() {
370 MESSAGE("Viewer is not defined for animation");
373 vtkRenderer* aRen = myView->getRenderer();
374 for (int i = 0; i < getNbFields(); i++) {
375 FieldData& aData = myFieldsLst[i];
376 if (!aData.myActors.empty()) {
377 for (int i = 0, iEnd = aData.myActors.size(); i < iEnd; i++) {
378 if (aData.myActors[i] != 0) {
379 aData.myActors[i]->RemoveFromRender(aRen);
382 aData.myActors.clear();
385 VISU::RepaintView(myView);
388 //------------------------------------------------------------------------
389 void VISU_TimeAnimation::stopAnimation() {
393 //------------------------------------------------------------------------
394 void VISU_TimeAnimation::startAnimation() {
401 //------------------------------------------------------------------------
402 void VISU_TimeAnimation::nextFrame() {
404 MESSAGE("Viewer is not defined for animation");
408 if (myFrame < (myFieldsLst[0].myNbFrames-1)) {
410 for (i = 0; i < getNbFields(); i++)
411 if (myFieldsLst[i].myActors[myFrame] != 0)
412 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
415 for (i = 0; i < getNbFields(); i++)
416 if (myFieldsLst[i].myActors[myFrame] != 0)
417 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
419 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
424 //------------------------------------------------------------------------
425 void VISU_TimeAnimation::prevFrame() {
427 MESSAGE("Viewer is not defined for animation");
433 for (i = 0; i < getNbFields(); i++)
434 if (myFieldsLst[i].myActors[myFrame] != 0)
435 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
438 for (i = 0; i < getNbFields(); i++)
439 if (myFieldsLst[i].myActors[myFrame] != 0)
440 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
442 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
447 //------------------------------------------------------------------------
448 void VISU_TimeAnimation::firstFrame() {
450 MESSAGE("Viewer is not defined for animation");
455 for (i = 0; i < getNbFields(); i++)
456 if(!myFieldsLst[i].myActors.empty())
457 if (myFieldsLst[i].myActors[myFrame] != 0)
458 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
460 for (i = 0; i < getNbFields(); i++)
461 if(!myFieldsLst[i].myActors.empty())
462 if (myFieldsLst[i].myActors[myFrame] != 0)
463 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
464 if(!myFieldsLst[0].myTiming.empty()){
465 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
470 //------------------------------------------------------------------------
471 void VISU_TimeAnimation::lastFrame() {
473 MESSAGE("Viewer is not defined for animation");
478 for (i = 0; i < getNbFields(); i++)
479 if (myFieldsLst[i].myActors[myFrame] != 0)
480 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
482 myFrame = myFieldsLst[0].myNbFrames-1;
483 for (i = 0; i < getNbFields(); i++)
484 if (myFieldsLst[i].myActors[myFrame] != 0)
485 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
487 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
492 //------------------------------------------------------------------------
493 // For Batchmode using
494 void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) {
496 MESSAGE("Viewer is not defined for animation");
499 if ((theFrame < 0) || (theFrame > (getNbFrames()-1)))
505 for (i = 0; i < getNbFields(); i++)
506 if (myFieldsLst[i].myActors[myFrame] != 0)
507 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
510 for (i = 0; i < getNbFields(); i++)
511 if (myFieldsLst[i].myActors[myFrame] != 0)
512 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
514 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
517 qApp->processEvents(3);
522 //------------------------------------------------------------------------
523 VISU::ColoredPrs3d_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) {
524 if ((theField > getNbFields()) || (theField < 0))
525 return VISU::ColoredPrs3d::_nil();
526 if ((theFrame < 0) || (theFrame > (myFieldsLst[theField].myNbFrames - 1)))
527 return VISU::ColoredPrs3d::_nil();
528 return myFieldsLst[theField].myPrs[theFrame]->_this();
532 //------------------------------------------------------------------------
533 CORBA::Long VISU_TimeAnimation::getNbFrames() {
534 return (getNbFields() > 0)? myFieldsLst[0].myNbFrames : 0;
538 //------------------------------------------------------------------------
539 void VISU_TimeAnimation::run()
542 MESSAGE("Viewer is not defined for animation");
546 bool isDumping = !myDumpPath.isEmpty();
548 if (myFieldsLst[0].myNbFrames > 2)
549 aOneVal = myFieldsLst[0].myTiming[1] - myFieldsLst[0].myTiming[0];
552 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
553 for (int i = 0; i < getNbFields(); i++) {
554 FieldData& aData = myFieldsLst[i];
556 if (aData.myActors[myFrame-1] != 0)
557 aData.myActors[myFrame-1]->VisibilityOff();
559 if (aData.myActors[aData.myNbFrames-1] != 0)
560 aData.myActors[aData.myNbFrames-1]->VisibilityOff();
562 if (aData.myActors[myFrame] != 0) {
563 aData.myActors[myFrame]->VisibilityOn();
566 myView->Repaint(false);
569 if (myProportional) {
574 if (myFieldsLst[0].myNbFrames > 2)
575 k = (myFieldsLst[0].myTiming[myFrame+1] -
576 myFieldsLst[0].myTiming[myFrame]) / aOneVal;
579 if (myFrame < (myFieldsLst[0].myNbFrames - 1))
580 k = (myFieldsLst[0].myTiming[myFrame+1] -
581 myFieldsLst[0].myTiming[myFrame]) / aOneVal;
584 int delay = (int)(1000. * k / mySpeed);
585 if (delay < 1 && isDumping) {
586 // We must unlock mutex for some time before grabbing to allow view updating
594 // We must unlock mutex for some time before grabbing to allow view updating
598 QString aFile(myDumpPath);
599 QString aName = QString("%1").arg(myFieldsLst[0].myTiming[myFrame]);
601 while ((aPos = aName.find(".")) > -1 )
602 aName.replace(aPos, 1, "_");
605 aFile += myDumpFormat.lower();
606 myView->dumpViewToFormat(aFile,myDumpFormat);
609 if (!myIsActive) break;
612 if (myFrame == myFieldsLst[0].myNbFrames) {
626 //------------------------------------------------------------------------
627 VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField)
629 _PTR(SObject) aSObj = theField->GetFather();
630 aSObj = aSObj->GetFather();
631 aSObj = aSObj->GetFather();
632 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
633 if (CORBA::is_nil(anObject)) return NULL;
634 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
637 //------------------------------------------------------------------------
638 VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (_PTR(SObject) theSObject)
640 VISU::Storable::TRestoringMap aMap;
642 _PTR(GenericAttribute) anAttr;
643 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
644 _PTR(AttributeComment) aComment (anAttr);
645 std::string aString = aComment->Value();
646 QString strIn (aString.c_str());
647 VISU::Storable::StrToMap(strIn, aMap);
653 //------------------------------------------------------------------------
654 double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp)
656 _PTR(GenericAttribute) anAttr;
657 if (theTimeStamp->FindAttribute(anAttr, "AttributeName")) {
658 _PTR(AttributeName) aName (anAttr);
659 QString aNameString (aName->Value().c_str());
660 int time_len = aNameString.find(',');
662 return aNameString.left(time_len).toDouble();
664 return aNameString.toDouble();
669 //------------------------------------------------------------------------
670 void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed)
672 mySpeed = (theSpeed<1)? 1 : theSpeed;
675 std::string VISU_TimeAnimation::setDumpFormat(const char* theFormat)
677 myDumpFormat = theFormat;
678 QStrList aDumpFormats = QImageIO::outputFormats();
679 if (myDumpFormat.isEmpty() || aDumpFormats.find(theFormat) < 0) {
680 if (aDumpFormats.find("JPEG"))
681 myDumpFormat = "JPEG";
683 myDumpFormat = aDumpFormats.at(0);
685 return myDumpFormat.latin1();
688 //************************************************************************
689 int VISU_TimeAnimation::myNBAnimations = 0;
690 QString VISU_TimeAnimation::GenerateName()
692 return VISU::GenerateName("Animation", myNBAnimations++);
695 //------------------------------------------------------------------------
696 std::string GetPresentationComment (VISU::VISUType thePrsType)
699 switch (thePrsType) {
700 case VISU::TSCALARMAP:
701 aPrsCmt = VISU::ScalarMap_i::myComment;
703 case VISU::TISOSURFACE:
704 aPrsCmt = VISU::IsoSurfaces_i::myComment;
706 case VISU::TCUTPLANES:
707 aPrsCmt = VISU::CutPlanes_i::myComment;
709 case VISU::TCUTLINES:
710 aPrsCmt = VISU::CutLines_i::myComment;
713 aPrsCmt = VISU::Plot3D_i::myComment;
715 case VISU::TDEFORMEDSHAPE:
716 aPrsCmt = VISU::DeformedShape_i::myComment;
719 aPrsCmt = VISU::Vectors_i::myComment;
721 case VISU::TSTREAMLINES:
722 aPrsCmt = VISU::StreamLines_i::myComment;
724 case VISU::TGAUSSPOINTS:
725 aPrsCmt = VISU::GaussPoints_i::myComment;
727 case VISU::TSCALARMAPONDEFORMEDSHAPE:
728 aPrsCmt = VISU::ScalarMapOnDeformedShape_i::myComment;
731 aPrsCmt = "Unknown presentation";
737 //------------------------------------------------------------------------
738 SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
740 if (myStudy->GetProperties()->IsLocked())
741 return SALOMEDS::SObject::_nil();
743 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
744 aStudyBuilder->NewCommand(); // There is a transaction
745 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
746 std::string aSComponentEntry = aSComponent->GetID();
749 aComment.sprintf("myComment=ANIMATION;myType=%d;myTimeMinVal=%g;myTimeMaxVal=%g",
750 VISU::TANIMATION,myTimeMinVal,myTimeMaxVal);
752 string anEntry = VISU::CreateAttributes(myStudy,aSComponentEntry.c_str(),"","",
753 GenerateName(),"",aComment,true);
754 myAnimEntry = anEntry.c_str();
755 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
757 for (int i = 0; i < getNbFields(); i++) {
758 FieldData& aData = myFieldsLst[i];
760 _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
761 aStudyBuilder->Addreference(newObj, aData.myField);
763 if (aData.myPrs.empty()) {
764 generatePresentations(i);
766 ostringstream strOut;
767 aData.myPrs[0]->ToStream(strOut);
768 string aPrsComment = strOut.str();
769 VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
770 aData.myPrs[0]->GetComment(),"",aPrsComment.c_str(),true);
772 aStudyBuilder->CommitCommand();
774 return VISU::GetSObject(aAnimSObject);
777 //------------------------------------------------------------------------
778 void VISU_TimeAnimation::saveAnimation()
780 if (myStudy->GetProperties()->IsLocked()) return;
781 if (myAnimEntry.isEmpty()) return;
783 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.latin1());
784 if (!aAnimSObject) return;
786 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
787 aStudyBuilder->NewCommand(); // There is a transaction
788 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
789 std::string aSComponentEntry = aSComponent->GetID();
792 aComment.sprintf("myComment=ANIMATION;myType=%d;myTimeMinVal=%g;myTimeMaxVal=%g",
793 VISU::TANIMATION,myTimeMinVal,myTimeMaxVal);
795 _PTR(GenericAttribute) anAttr;
796 anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeComment");
797 _PTR(AttributeComment) aCmnt (anAttr);
798 aCmnt->SetValue(aComment.latin1());
800 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
801 int i = 0, nbf = getNbFields();
802 for (anIter->Init(); anIter->More(); anIter->Next(), i++) {
803 if (i >= nbf) break; // it must not be
804 FieldData& aData = myFieldsLst[i];
806 // Get presentation name and comment
807 if (aData.myPrs.empty()) {
808 generatePresentations(i);
810 ostringstream strOut;
811 aData.myPrs[0]->ToStream(strOut);
812 string aPrsComment = strOut.str();
813 string aPrsNameTxt = aData.myPrs[0]->GetComment();
816 _PTR(SObject) aRefObj = anIter->Value();
817 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
820 if (anPrsIter->More()) {
821 _PTR(SObject) aPrsObj = anPrsIter->Value();
822 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeComment");
823 aCmnt = _PTR(AttributeComment)(anAttr);
824 aCmnt->SetValue(aPrsComment.c_str());
826 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
827 _PTR(AttributeName) aPrsName (anAttr);
828 aPrsName->SetValue(aPrsNameTxt);
831 VISU::CreateAttributes(myStudy, aRefObj->GetID().c_str(),"","",
832 aPrsNameTxt.c_str(),"",aPrsComment.c_str(),true);
835 aStudyBuilder->CommitCommand();
838 //------------------------------------------------------------------------
839 void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
841 _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
842 restoreFromStudy(aAnimSObject);
845 void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
847 _PTR(SObject) aAnimSObject = theField;
849 VISU::Storable::TRestoringMap aMap;
850 _PTR(GenericAttribute) anAttr;
851 if (!aAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
853 _PTR(AttributeComment) aComment (anAttr);
854 string aComm = aComment->Value();
855 QString strIn (aComm.c_str());
856 VISU::Storable::StrToMap(strIn,aMap);
859 myTimeMinVal = VISU::Storable::FindValue(aMap,"myTimeMinVal",&isExist).toDouble();
860 myTimeMaxVal = VISU::Storable::FindValue(aMap,"myTimeMaxVal",&isExist).toDouble();
862 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
863 for (anIter->Init(); anIter->More(); anIter->Next()) {
864 _PTR(SObject) aRefObj = anIter->Value();
865 _PTR(SObject) aFieldObj;
866 if (!aRefObj->ReferencedObject(aFieldObj) ) continue;
868 FieldData& aData = getFieldData(getNbFields()-1);
870 // Get Presentation object
871 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
873 if (!anPrsIter->More()) continue;
874 _PTR(SObject) aPrsObj = anPrsIter->Value();
875 if (!aPrsObj->FindAttribute(anAttr, "AttributeName")) continue;
876 _PTR(AttributeName) aName (anAttr);
877 string aStr = aName->Value();
878 QString strName (aStr.c_str());
880 if (strName == VISU::ScalarMap_i::myComment.c_str())
881 aData.myPrsType = VISU::TSCALARMAP;
882 else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
883 aData.myPrsType = VISU::TISOSURFACE;
884 else if (strName == VISU::CutPlanes_i::myComment.c_str())
885 aData.myPrsType = VISU::TCUTPLANES;
886 else if (strName == VISU::CutLines_i::myComment.c_str())
887 aData.myPrsType = VISU::TCUTLINES;
888 else if (strName == VISU::Plot3D_i::myComment.c_str())
889 aData.myPrsType = VISU::TPLOT3D;
890 else if (strName == VISU::DeformedShape_i::myComment.c_str())
891 aData.myPrsType = VISU::TDEFORMEDSHAPE;
892 else if (strName == VISU::Vectors_i::myComment.c_str())
893 aData.myPrsType = VISU::TVECTORS;
894 else if (strName == VISU::StreamLines_i::myComment.c_str())
895 aData.myPrsType = VISU::TSTREAMLINES;
896 else if (strName == VISU::GaussPoints_i::myComment.c_str())
897 aData.myPrsType = VISU::TGAUSSPOINTS;
898 else if (strName == VISU::ScalarMapOnDeformedShape_i::myComment.c_str())
899 aData.myPrsType = VISU::TSCALARMAPONDEFORMEDSHAPE;
902 generatePresentations(getNbFields()-1);
904 if (!aPrsObj->FindAttribute(anAttr, "AttributeComment")) continue;
905 _PTR(AttributeComment) aPrsComment (anAttr);
906 string aPrsComm = aPrsComment->Value();
907 if (aPrsComm.length() > 0) {
908 QString strPrsIn (aPrsComm.c_str());
909 VISU::Storable::TRestoringMap aPrsMap;
910 VISU::Storable::StrToMap(strPrsIn,aPrsMap);
912 aData.myPrs[0]->Restore(aPrsMap);
914 aData.myPrs[0]->GetOffset(aData.myOffset);
915 for (int i = 1; i < aData.myNbFrames; i++) {
916 //jfa 03.08.2005:aData.myPrs[i]->SameAs(aData.myPrs[0]);
917 aData.myPrs[i]->SameAsParams(aData.myPrs[0]);//jfa 03.08.2005
920 string aStr = aAnimSObject->GetID();
921 myAnimEntry = aStr.c_str();
924 void VISU_TimeAnimation::onViewDeleted()
930 //========================================================================
931 //========================================================================
932 //========================================================================
933 struct TNewAnimationEvent: public SALOME_Event
935 std::string myStudyName;
936 VISU::View3D_ptr myView3D;
938 typedef VISU_TimeAnimation* TResult;
941 TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
942 myStudyName(theStudyName),
943 myView3D(VISU::View3D::_duplicate(theView3D)),
951 SUIT_Session* aSession = SUIT_Session::session();
952 QPtrList<SUIT_Application> anApplications = aSession->applications();
953 QPtrListIterator<SUIT_Application> anIter (anApplications);
954 while (SUIT_Application* anApp = anIter.current()) {
956 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
957 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
958 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
959 if (myStudyName == aCStudy->Name()) {
960 myResult = new VISU_TimeAnimation (aCStudy, myView3D);
970 VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
971 VISU::View3D_ptr theView3D)
973 std::string aStudyName = theStudy->Name();
974 myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
977 VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
982 void VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
984 myAnim->addField(theField);
987 CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
989 return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
990 (myAnim,&VISU_TimeAnimation::generateFrames));
993 void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
995 myAnim->generatePresentations(theFieldNum);
998 void VISU_TimeAnimation_i::clearView()
1000 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1001 (myAnim,&VISU_TimeAnimation::clearView));
1004 void VISU_TimeAnimation_i::stopAnimation()
1006 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1007 (myAnim,&VISU_TimeAnimation::stopAnimation));
1010 void VISU_TimeAnimation_i::startAnimation()
1012 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1013 (myAnim,&VISU_TimeAnimation::startAnimation));
1016 void VISU_TimeAnimation_i::nextFrame()
1018 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1019 (myAnim,&VISU_TimeAnimation::nextFrame));
1022 void VISU_TimeAnimation_i::prevFrame()
1024 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1025 (myAnim,&VISU_TimeAnimation::prevFrame));
1028 void VISU_TimeAnimation_i::firstFrame()
1030 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1031 (myAnim,&VISU_TimeAnimation::firstFrame));
1034 void VISU_TimeAnimation_i::lastFrame()
1036 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
1037 (myAnim,&VISU_TimeAnimation::lastFrame));
1040 void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
1042 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
1043 (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
1046 CORBA::Long VISU_TimeAnimation_i::getNbFields()
1048 return myAnim->getNbFields();
1051 CORBA::Long VISU_TimeAnimation_i::getNbFrames()
1053 return myAnim->getNbFrames();
1056 CORBA::Boolean VISU_TimeAnimation_i::isRunning()
1058 return myAnim->isRunning();
1061 CORBA::Long VISU_TimeAnimation_i::getCurrentFrame()
1063 return myAnim->getCurrentFrame();
1066 VISU::ColoredPrs3d_ptr VISU_TimeAnimation_i::getPresentation
1067 (CORBA::Long theField, CORBA::Long theFrame)
1069 return myAnim->getPresentation(theField,theFrame);
1072 void VISU_TimeAnimation_i::setPresentationType (CORBA::Long theFieldNum,
1073 VISU::VISUType theType)
1075 myAnim->setPresentationType(theFieldNum,theType);
1078 VISU::VISUType VISU_TimeAnimation_i::getPresentationType (CORBA::Long theFieldNum)
1080 return myAnim->getPresentationType(theFieldNum);
1083 void VISU_TimeAnimation_i::setSpeed(CORBA::Long theSpeed)
1085 myAnim->setSpeed(theSpeed);
1088 CORBA::Long VISU_TimeAnimation_i::getSpeed()
1090 return myAnim->getSpeed();
1093 CORBA::Boolean VISU_TimeAnimation_i::isProportional()
1095 return myAnim->isProportional();
1098 void VISU_TimeAnimation_i::setAnimationRange (CORBA::Double theMin,
1099 CORBA::Double theMax)
1101 myAnim->setAnimationRange(theMin,theMax);
1104 CORBA::Double VISU_TimeAnimation_i::getMinRange()
1106 return myAnim->getMinRange();
1109 CORBA::Double VISU_TimeAnimation_i::getMaxRange()
1111 return myAnim->getMaxRange();
1114 CORBA::Boolean VISU_TimeAnimation_i::isRangeDefined()
1116 return myAnim->isRangeDefined();
1119 void VISU_TimeAnimation_i::dumpTo (const char* thePath)
1121 myAnim->dumpTo(thePath);
1124 char* VISU_TimeAnimation_i::setDumpFormat (const char* theFormat)
1126 string aDumpFormat = myAnim->setDumpFormat(theFormat);
1127 return CORBA::string_dup(aDumpFormat.c_str());
1130 CORBA::Boolean VISU_TimeAnimation_i::isCycling()
1132 return myAnim->isCycling();
1135 CORBA::Double VISU_TimeAnimation_i::getMinTime()
1137 return myAnim->getMinTime();
1140 CORBA::Double VISU_TimeAnimation_i::getMaxTime()
1142 return myAnim->getMaxTime();
1145 void VISU_TimeAnimation_i::setProportional (CORBA::Boolean theProp)
1147 myAnim->setProportional(theProp);
1150 void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
1152 myAnim->setCycling(theCycle);
1155 SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
1157 return myAnim->publishInStudy();
1160 void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
1162 myAnim->restoreFromStudy(theObj);
1165 CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
1167 return myAnim->isSavedInStudy();
1170 void VISU_TimeAnimation_i::saveAnimation()
1172 myAnim->saveAnimation();