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_CutPlanes_i.hh"
20 #include "VISU_Plot3D_i.hh"
21 #include "VISU_CutLines_i.hh"
22 #include "VISU_Vectors_i.hh"
23 #include "VISU_StreamLines_i.hh"
24 #include "VISU_ViewManager_i.hh"
25 #include "VISU_View_i.hh"
27 #include "VISU_ScalarBarActor.hxx"
28 #include "VISU_Actor.h"
30 #include "SalomeApp_Study.h"
32 #include "SVTK_ViewWindow.h"
34 #include "SALOME_Event.hxx"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Application.h"
38 #include "SUIT_Session.h"
39 #include "SUIT_Study.h"
41 #include "SALOMEDSClient_AttributeComment.hxx"
42 #include "SALOMEDSClient_AttributeName.hxx"
49 //************************************************************************
50 VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy,
51 VISU::View3D_ptr theView3D)
57 myProportional = false;
60 if (!CORBA::is_nil(theView3D)) {
61 VISU::View3D_i* pView = dynamic_cast<VISU::View3D_i*>(GetServant(theView3D).in());
62 //QAD_StudyFrame* aStudyFrame = pView->GetStudyFrame();
63 //myView = VISU::GetViewFrame(aStudyFrame);
64 SUIT_ViewWindow* aVW = pView->myViewWindow;
65 myView = VISU::GetViewWindow(aVW);
79 //************************************************************************
80 VISU_TimeAnimation::~VISU_TimeAnimation()
82 for (int i = 0; i < getNbFields(); i++) {
83 clearData(myFieldsLst[i]);
88 //************************************************************************
89 void VISU_TimeAnimation::addField (_PTR(SObject) theField)
92 aNewData.myField = theField;
93 aNewData.myNbFrames = 0;
94 aNewData.myPrsType = VISU::TSCALARMAP;
95 aNewData.myOffset[0] = aNewData.myOffset[1] = aNewData.myOffset[2] = 0;
96 VISU::Storable::TRestoringMap aMap = getMapOfValue(aNewData.myField);
97 aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
98 myFieldsLst.append(aNewData);
100 //find Min/Max timestamps
101 if ((myTimeMin == 0) && (myTimeMax == 0)) {
102 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(theField);
103 anIter->Next(); // First is reference on support
104 myTimeMin = getTimeValue(anIter->Value());
105 for(; anIter->More(); anIter->Next()) {
106 myTimeMax = getTimeValue(anIter->Value());
111 //************************************************************************
112 void VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField)
115 _PTR(SObject) aField = VISU::GetClientSObject(theField, myStudy);
116 aNewData.myField = aField;
117 aNewData.myNbFrames = 0;
118 aNewData.myPrsType = VISU::TSCALARMAP;
119 VISU::Storable::TRestoringMap aMap = getMapOfValue(aNewData.myField);
120 aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
121 myFieldsLst.append(aNewData);
123 //find Min/Max timestamps
124 if ((myTimeMin == 0) && (myTimeMax == 0)) {
125 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aField);
126 anIter->Next(); // First is reference on support
127 myTimeMin = getTimeValue(anIter->Value());
128 for(; anIter->More(); anIter->Next()) {
129 myTimeMax = getTimeValue(anIter->Value());
135 //************************************************************************
136 void VISU_TimeAnimation::clearData(FieldData& theData) {
137 theData.myTiming.clear();
138 vtkRenderer* aRen = myView->getRenderer();
139 if (!theData.myActors.empty()) {
140 for (int i = 0, iEnd = theData.myActors.size(); i < iEnd; i++) {
141 if (theData.myActors[i] != 0) {
142 theData.myActors[i]->RemoveFromRender(aRen);
143 theData.myActors[i]->Delete();
146 theData.myActors.clear();
148 if (!theData.myPrs.empty()) {
149 for (int i = 0, iEnd = theData.myPrs.size(); i < iEnd; i++)
150 if (theData.myPrs[i] != 0) {
151 theData.myPrs[i]->_remove_ref();
153 theData.myPrs.clear();
155 theData.myNbFrames = 0;
160 //************************************************************************
161 void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum) {
162 FieldData& aData = myFieldsLst[theFieldNum];
164 // Delete previous presentations
167 VISU::Result_i* pResult = createPresent(aData.myField);
168 VISU::Storable::TRestoringMap aMap = getMapOfValue(aData.myField);
169 aData.myNbFrames = aData.myNbTimes;
170 //VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
172 aData.myPrs.resize(aData.myNbTimes,NULL);
173 aData.myTiming.resize(aData.myNbTimes);
175 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aData.myField);
176 _PTR(SObject) aTimeStamp;
177 anIter->Next(); // First is reference on support
179 double aMin = VTK_LARGE_FLOAT, aMax = -VTK_LARGE_FLOAT;
180 for (; anIter->More(); anIter->Next()) {
181 if (i == aData.myNbTimes) {
182 MESSAGE("There are extra timestamps in field");
185 aTimeStamp = anIter->Value();
186 if (!aTimeStamp) continue;
188 aData.myTiming[i] = getTimeValue(aTimeStamp);
189 if (isRangeDefined()) {
190 if (aData.myTiming[i] < myMinVal) continue;
191 if (aData.myTiming[i] > myMaxVal) break;
194 VISU::Storable::TRestoringMap aTimeMap = getMapOfValue(aTimeStamp);
195 QString aMeshName = VISU::Storable::FindValue(aTimeMap,"myMeshName");
196 VISU::Entity anEntity = (VISU::Entity) VISU::Storable::FindValue(aTimeMap,"myEntityId").toInt();
197 QString aFieldName = VISU::Storable::FindValue(aTimeMap,"myFieldName");
198 int aTimeStampId = VISU::Storable::FindValue(aTimeMap,"myTimeStampId").toInt();
200 switch (aData.myPrsType) {
201 case VISU::TSCALARMAP: // ScalarMap
203 VISU::ScalarMap_i* aPresent = new VISU::ScalarMap_i(pResult, false);
204 aPresent->Create(aMeshName.latin1(), anEntity,
205 aFieldName.latin1(), aTimeStampId);
206 //VISU::ScalarMap_var aTmp = aPresent->_this();
207 //aPresent->_remove_ref();
208 aData.myPrs[i] = aPresent;
212 case VISU::TISOSURFACE: // Iso Surfaces
214 VISU::IsoSurfaces_i* aPresent = new VISU::IsoSurfaces_i(pResult, false);
215 aPresent->Create(aMeshName.latin1(), anEntity,
216 aFieldName.latin1(), aTimeStampId);
217 //VISU::IsoSurfaces_var aTmp = aPresent->_this();
218 //aPresent->_remove_ref();
219 aData.myPrs[i] = aPresent;
223 case VISU::TCUTPLANES: // Cut Planes
225 VISU::CutPlanes_i* aPresent = new VISU::CutPlanes_i(pResult, false);
226 aPresent->Create(aMeshName.latin1(), anEntity,
227 aFieldName.latin1(), aTimeStampId);
228 //VISU::CutPlanes_var aTmp = aPresent->_this();
229 //aPresent->_remove_ref();
230 aData.myPrs[i] = aPresent;
234 case VISU::TPLOT3D: // Cut Planes
236 VISU::Plot3D_i* aPresent = new VISU::Plot3D_i (pResult, false);
237 aPresent->Create(aMeshName.latin1(), anEntity,
238 aFieldName.latin1(), aTimeStampId);
239 aData.myPrs[i] = aPresent;
243 case VISU::TDEFORMEDSHAPE: // Deformed Shape
245 VISU::DeformedShape_i* aPresent = new VISU::DeformedShape_i(pResult, false);
246 aPresent->Create(aMeshName.latin1(), anEntity,
247 aFieldName.latin1(), aTimeStampId);
248 //VISU::DeformedShape_var aTmp = aPresent->_this();
249 //aPresent->_remove_ref();
250 aData.myPrs[i] = aPresent;
254 case VISU::TVECTORS: // Vectors
256 VISU::Vectors_i* aPresent = new VISU::Vectors_i(pResult, false);
257 aPresent->Create(aMeshName.latin1(), anEntity,
258 aFieldName.latin1(), aTimeStampId);
259 //VISU::Vectors_var aTmp = aPresent->_this();
260 //aPresent->_remove_ref();
261 aData.myPrs[i] = aPresent;
265 case VISU::TSTREAMLINES: // Stream Lines
267 VISU::StreamLines_i* aPresent = new VISU::StreamLines_i(pResult, false);
268 aPresent->Create(aMeshName.latin1(), anEntity,
269 aFieldName.latin1(), aTimeStampId);
270 //VISU::StreamLines_var aTmp = aPresent->_this();
271 //aPresent->_remove_ref();
272 aData.myPrs[i] = aPresent;
276 MESSAGE("Not implemented for this presentation type: " << aData.myPrsType);
279 if (aData.myPrs[i]->GetMin() < aMin) aMin = aData.myPrs[i]->GetMin();
280 if (aData.myPrs[i]->GetMax() > aMax) aMax = aData.myPrs[i]->GetMax();
283 aData.myNbFrames = i;
285 int rangeType = VISU::GetResourceMgr()->integerValue("VISU" , "scalar_range_type", 0);
286 if ( rangeType != 1 ) {
287 for (i = 0; i < aData.myNbFrames; i++) {
288 aData.myPrs[i]->SetRange(aMin, aMax);
289 aData.myPrs[i]->SetOffset(aData.myOffset);
291 if (aData.myPrsType == VISU::TISOSURFACE)
292 for (i = 0; i < aData.myNbFrames; i++)
293 if (VISU::IsoSurfaces_i* aPrs = dynamic_cast<VISU::IsoSurfaces_i*>(aData.myPrs[i]))
294 aPrs->SetSubRange(aMin, aMax);
299 //************************************************************************
300 CORBA::Boolean VISU_TimeAnimation::generateFrames() {
302 MESSAGE("Viewer is not defined for animation");
306 myLastError = QString("Frame(s) for ");
307 bool aNoError = true;
311 for (int i = 0; i < getNbFields(); i++) {
312 FieldData& aData = myFieldsLst[i];
313 aData.myActors.resize(aData.myNbFrames,NULL);
314 for (long j = 0; j < aData.myNbFrames; j++) {
315 VISU_Actor* aActor = NULL;
317 aData.myPrs[j]->SetOffset(aData.myOffset);
318 aActor = aData.myPrs[j]->CreateActor();
319 myView->AddActor(aActor);
321 aActor->VisibilityOn();
323 aActor->VisibilityOff();
324 }catch(...){ //catch(std::runtime_error& exc){
326 myLastError += QString("%1 ").arg(aData.myTiming[j]);
328 aData.myActors[j] = aActor;
332 myLastError += QString(" timestamp(s) cannot be created.");
333 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
338 //************************************************************************
339 void VISU_TimeAnimation::clearView() {
341 MESSAGE("Viewer is not defined for animation");
344 vtkRenderer* aRen = myView->getRenderer();
345 for (int i = 0; i < getNbFields(); i++) {
346 FieldData& aData = myFieldsLst[i];
347 if (!aData.myActors.empty()) {
348 for (int i = 0, iEnd = aData.myActors.size(); i < iEnd; i++) {
349 if (aData.myActors[i] != 0) {
350 aData.myActors[i]->RemoveFromRender(aRen);
351 aData.myActors[i]->Delete();
354 aData.myActors.clear();
357 VISU::RepaintView(myView);
360 //************************************************************************
361 void VISU_TimeAnimation::stopAnimation() {
365 //************************************************************************
366 void VISU_TimeAnimation::startAnimation() {
373 //************************************************************************
374 void VISU_TimeAnimation::nextFrame() {
376 if (myFrame < (myFieldsLst[0].myNbFrames-1)) {
378 for (i = 0; i < getNbFields(); i++)
379 if (myFieldsLst[i].myActors[myFrame] != 0)
380 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
383 for (i = 0; i < getNbFields(); i++)
384 if (myFieldsLst[i].myActors[myFrame] != 0)
385 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
387 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
392 //************************************************************************
393 void VISU_TimeAnimation::prevFrame() {
397 for (i = 0; i < getNbFields(); i++)
398 if (myFieldsLst[i].myActors[myFrame] != 0)
399 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
402 for (i = 0; i < getNbFields(); i++)
403 if (myFieldsLst[i].myActors[myFrame] != 0)
404 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
406 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
411 //************************************************************************
412 void VISU_TimeAnimation::firstFrame() {
415 for (i = 0; i < getNbFields(); i++)
416 if(!myFieldsLst[i].myActors.empty())
417 if (myFieldsLst[i].myActors[myFrame] != 0)
418 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
420 for (i = 0; i < getNbFields(); i++)
421 if(!myFieldsLst[i].myActors.empty())
422 if (myFieldsLst[i].myActors[myFrame] != 0)
423 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
424 if(!myFieldsLst[0].myTiming.empty()){
425 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
430 //************************************************************************
431 void VISU_TimeAnimation::lastFrame() {
434 for (i = 0; i < getNbFields(); i++)
435 if (myFieldsLst[i].myActors[myFrame] != 0)
436 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
438 myFrame = myFieldsLst[0].myNbFrames-1;
439 for (i = 0; i < getNbFields(); i++)
440 if (myFieldsLst[i].myActors[myFrame] != 0)
441 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
443 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
448 //************************************************************************
449 // For Batchmode using
450 void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) {
451 if ((theFrame < 0) || (theFrame > (getNbFrames()-1)))
457 for (i = 0; i < getNbFields(); i++)
458 if (myFieldsLst[i].myActors[myFrame] != 0)
459 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
462 for (i = 0; i < getNbFields(); i++)
463 if (myFieldsLst[i].myActors[myFrame] != 0)
464 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
466 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
469 qApp->processEvents(3);
474 //************************************************************************
475 VISU::ScalarMap_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) {
476 if ((theField > getNbFields()) || (theField < 0))
477 return VISU::ScalarMap::_nil();
478 if ((theFrame < 0) || (theFrame > (myFieldsLst[theField].myNbFrames - 1)))
479 return VISU::ScalarMap::_nil();
480 return myFieldsLst[theField].myPrs[theFrame]->_this();
484 //************************************************************************
485 CORBA::Long VISU_TimeAnimation::getNbFrames() {
486 return (getNbFields() > 0)? myFieldsLst[0].myNbFrames : 0;
490 //************************************************************************
491 void VISU_TimeAnimation::run()
494 MESSAGE("Viewer is not defined for animation");
498 bool isDumping = !myDumpPath.isEmpty();
500 if (myFieldsLst[0].myNbFrames > 2)
501 aOneVal = myFieldsLst[0].myTiming[1] - myFieldsLst[0].myTiming[0];
504 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
505 for (int i = 0; i < getNbFields(); i++) {
506 FieldData& aData = myFieldsLst[i];
508 if (aData.myActors[myFrame-1] != 0)
509 aData.myActors[myFrame-1]->VisibilityOff();
511 if (aData.myActors[aData.myNbFrames-1] != 0)
512 aData.myActors[aData.myNbFrames-1]->VisibilityOff();
514 if (aData.myActors[myFrame] != 0) {
515 aData.myActors[myFrame]->VisibilityOn();
518 myView->Repaint(false);
522 QPixmap px = QPixmap::grabWindow(myView->winId());
523 QString aFile(myDumpPath);
524 QString aName = QString("%1").arg(myFieldsLst[0].myTiming[myFrame]);
526 while ((aPos = aName.find(".")) > -1 )
527 aName.replace(aPos, 1, "_");
530 px.save(aFile, "JPEG");
533 if (myProportional) {
538 if (myFieldsLst[0].myNbFrames > 2)
539 k = (myFieldsLst[0].myTiming[myFrame+1] -
540 myFieldsLst[0].myTiming[myFrame]) / aOneVal;
543 if (myFrame < (myFieldsLst[0].myNbFrames - 1))
544 k = (myFieldsLst[0].myTiming[myFrame+1] -
545 myFieldsLst[0].myTiming[myFrame]) / aOneVal;
548 delay = (int)(1000. * k / mySpeed);
554 if (!myIsActive) break;
557 if (myFrame == myFieldsLst[0].myNbFrames) {
571 //************************************************************************
572 VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField)
574 _PTR(SObject) aSObj = theField->GetFather();
575 aSObj = aSObj->GetFather();
576 aSObj = aSObj->GetFather();
577 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
578 if (CORBA::is_nil(anObject)) return NULL;
579 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
582 //************************************************************************
583 VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (_PTR(SObject) theSObject)
585 VISU::Storable::TRestoringMap aMap;
587 _PTR(GenericAttribute) anAttr;
588 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
589 _PTR(AttributeComment) aComment (anAttr);
590 std::string aString = aComment->Value();
591 QString strIn (aString.c_str());
592 VISU::Storable::StrToMap(strIn, aMap);
598 //************************************************************************
599 double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp)
601 _PTR(GenericAttribute) anAttr;
602 if (theTimeStamp->FindAttribute(anAttr, "AttributeName")) {
603 _PTR(AttributeName) aName (anAttr);
604 QString aNameString (aName->Value().c_str());
605 int time_len = aNameString.find(',');
607 return aNameString.left(time_len).toDouble();
609 return aNameString.toDouble();
614 //************************************************************************
615 void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed)
617 mySpeed = (theSpeed<1)? 1 : theSpeed;
620 //************************************************************************
621 int VISU_TimeAnimation::myNBAnimations = 0;
622 QString VISU_TimeAnimation::GenerateName()
624 return VISU::GenerateName("Animation", myNBAnimations++);
627 //************************************************************************
628 std::string GetPresentationComment (VISU::VISUType thePrsType)
631 switch (thePrsType) {
632 case VISU::TSCALARMAP:
633 aPrsCmt = VISU::ScalarMap_i::myComment;
635 case VISU::TISOSURFACE:
636 aPrsCmt = VISU::IsoSurfaces_i::myComment;
638 case VISU::TCUTPLANES:
639 aPrsCmt = VISU::CutPlanes_i::myComment;
642 aPrsCmt = VISU::Plot3D_i::myComment;
644 case VISU::TDEFORMEDSHAPE:
645 aPrsCmt = VISU::DeformedShape_i::myComment;
648 aPrsCmt = VISU::Vectors_i::myComment;
650 case VISU::TSTREAMLINES:
651 aPrsCmt = VISU::StreamLines_i::myComment;
654 aPrsCmt = "Unknown presentation";
660 //************************************************************************
661 SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
663 if (myStudy->GetProperties()->IsLocked())
664 return SALOMEDS::SObject::_nil();
666 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
667 aStudyBuilder->NewCommand(); // There is a transaction
668 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
669 std::string aSComponentEntry = aSComponent->GetID();
672 aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
673 VISU::TANIMATION,myMinVal,myMaxVal);
675 string anEntry = VISU::CreateAttributes(myStudy,aSComponentEntry.c_str(),"","",
676 GenerateName(),"",aComment,true);
677 myAnimEntry = anEntry.c_str();
678 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
680 for (int i = 0; i < getNbFields(); i++) {
681 FieldData& aData = myFieldsLst[i];
682 _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
683 aStudyBuilder->Addreference(newObj, aData.myField);
684 if (aData.myPrs.empty()) {
685 VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
686 GetPresentationComment(aData.myPrsType).c_str(),"","",true);
688 ostringstream strOut;
689 aData.myPrs[0]->ToStream(strOut);
690 string aPrsComment = strOut.str();
691 VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
692 aData.myPrs[0]->GetComment(),"",aPrsComment.c_str(),true);
695 aStudyBuilder->CommitCommand();
697 return VISU::GetSObject(aAnimSObject);
700 //************************************************************************
701 void VISU_TimeAnimation::saveAnimation()
703 if (myStudy->GetProperties()->IsLocked()) return;
704 if (myAnimEntry.isEmpty()) return;
706 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.latin1());
707 if (!aAnimSObject) return;
709 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
710 aStudyBuilder->NewCommand(); // There is a transaction
711 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
712 std::string aSComponentEntry = aSComponent->GetID();
715 aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
716 VISU::TANIMATION,myMinVal,myMaxVal);
718 _PTR(GenericAttribute) anAttr;
719 anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeComment");
720 _PTR(AttributeComment) aCmnt (anAttr);
721 aCmnt->SetValue(aComment.latin1());
723 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
725 for (i = 0, anIter->Init(); anIter->More(); anIter->Next(), i++) {
726 FieldData& aData = myFieldsLst[i];
728 _PTR(SObject) aRefObj = anIter->Value();
729 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
732 string aPrsComment, aPrsNameTxt;
733 if (aData.myPrs.empty()) {
735 aPrsNameTxt = GetPresentationComment(aData.myPrsType);
737 ostringstream strOut;
738 aData.myPrs[0]->ToStream(strOut);
739 aPrsComment = strOut.str();
741 aPrsNameTxt = aData.myPrs[0]->GetComment();
744 if (anPrsIter->More()) {
745 _PTR(SObject) aPrsObj = anPrsIter->Value();
746 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeComment");
747 aCmnt = _PTR(AttributeComment)(anAttr);
748 aCmnt->SetValue(aPrsComment.c_str());
750 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
751 _PTR(AttributeName) aPrsName (anAttr);
752 aPrsName->SetValue(aPrsNameTxt);
755 VISU::CreateAttributes(myStudy, aRefObj->GetID().c_str(),"","",
756 aPrsNameTxt.c_str(),"",aPrsComment.c_str(),true);
759 aStudyBuilder->CommitCommand();
762 //************************************************************************
763 void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
765 _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
766 restoreFromStudy(aAnimSObject);
769 void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
771 _PTR(SObject) aAnimSObject = theField;
773 VISU::Storable::TRestoringMap aMap;
774 _PTR(GenericAttribute) anAttr;
775 if (!aAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
777 _PTR(AttributeComment) aComment (anAttr);
778 string aComm = aComment->Value();
779 QString strIn (aComm.c_str());
780 VISU::Storable::StrToMap(strIn,aMap);
783 myMinVal = VISU::Storable::FindValue(aMap,"myMinVal",&isExist).toDouble();
784 myMaxVal = VISU::Storable::FindValue(aMap,"myMaxVal",&isExist).toDouble();
786 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
787 for (anIter->Init(); anIter->More(); anIter->Next()) {
788 _PTR(SObject) aRefObj = anIter->Value();
789 _PTR(SObject) aFieldObj;
790 if (!aRefObj->ReferencedObject(aFieldObj) ) continue;
792 FieldData& aData = getFieldData(getNbFields()-1);
794 // Get Presentation object
795 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
797 if (!anPrsIter->More()) continue;
798 _PTR(SObject) aPrsObj = anPrsIter->Value();
799 if (!aPrsObj->FindAttribute(anAttr, "AttributeName")) continue;
800 _PTR(AttributeName) aName (anAttr);
801 string aStr = aName->Value();
802 QString strName (aStr.c_str());
804 if (strName == VISU::ScalarMap_i::myComment.c_str())
805 aData.myPrsType = VISU::TSCALARMAP;
806 else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
807 aData.myPrsType = VISU::TISOSURFACE;
808 else if (strName == VISU::CutPlanes_i::myComment.c_str())
809 aData.myPrsType = VISU::TCUTPLANES;
810 else if (strName == VISU::Plot3D_i::myComment.c_str())
811 aData.myPrsType = VISU::TPLOT3D;
812 else if (strName == VISU::DeformedShape_i::myComment.c_str())
813 aData.myPrsType = VISU::TDEFORMEDSHAPE;
814 else if (strName == VISU::Vectors_i::myComment.c_str())
815 aData.myPrsType = VISU::TVECTORS;
816 else if (strName == VISU::StreamLines_i::myComment.c_str())
817 aData.myPrsType = VISU::TSTREAMLINES;
820 generatePresentations(getNbFields()-1);
822 if (!aPrsObj->FindAttribute(anAttr, "AttributeComment")) continue;
823 _PTR(AttributeComment) aPrsComment (anAttr);
824 string aPrsComm = aPrsComment->Value();
825 if (aPrsComm.length() > 0) {
826 QString strPrsIn (aPrsComm.c_str());
827 VISU::Storable::TRestoringMap aPrsMap;
828 VISU::Storable::StrToMap(strPrsIn,aPrsMap);
830 aData.myPrs[0]->Restore(aPrsMap);
832 aData.myPrs[0]->GetOffset(aData.myOffset);
833 for (int i = 1; i < aData.myNbFrames; i++) {
834 aData.myPrs[i]->SameAs(aData.myPrs[0]);
837 string aStr = aAnimSObject->GetID();
838 myAnimEntry = aStr.c_str();
842 //========================================================================
843 //========================================================================
844 //========================================================================
845 struct TNewAnimationEvent: public SALOME_Event
847 std::string myStudyName;
848 VISU::View3D_ptr myView3D;
850 typedef VISU_TimeAnimation* TResult;
853 TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
854 myStudyName(theStudyName),
855 myView3D(VISU::View3D::_duplicate(theView3D)),
863 SUIT_Session* aSession = SUIT_Session::session();
864 QPtrList<SUIT_Application> anApplications = aSession->applications();
865 QPtrListIterator<SUIT_Application> anIter (anApplications);
866 while (SUIT_Application* anApp = anIter.current()) {
868 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
869 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
870 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
871 if (myStudyName == aCStudy->Name()) {
872 myResult = new VISU_TimeAnimation (aCStudy, myView3D);
882 VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
883 VISU::View3D_ptr theView3D)
885 std::string aStudyName = theStudy->Name();
886 myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
889 VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
894 void VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
896 myAnim->addField(theField);
899 CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
901 return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
902 (myAnim,&VISU_TimeAnimation::generateFrames));
905 void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
907 myAnim->generatePresentations(theFieldNum);
910 void VISU_TimeAnimation_i::clearView()
912 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
913 (myAnim,&VISU_TimeAnimation::clearView));
916 void VISU_TimeAnimation_i::stopAnimation()
918 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
919 (myAnim,&VISU_TimeAnimation::stopAnimation));
922 void VISU_TimeAnimation_i::startAnimation()
924 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
925 (myAnim,&VISU_TimeAnimation::startAnimation));
928 void VISU_TimeAnimation_i::nextFrame()
930 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
931 (myAnim,&VISU_TimeAnimation::nextFrame));
934 void VISU_TimeAnimation_i::prevFrame()
936 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
937 (myAnim,&VISU_TimeAnimation::prevFrame));
940 void VISU_TimeAnimation_i::firstFrame()
942 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
943 (myAnim,&VISU_TimeAnimation::firstFrame));
946 void VISU_TimeAnimation_i::lastFrame()
948 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
949 (myAnim,&VISU_TimeAnimation::lastFrame));
952 void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
954 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
955 (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
958 CORBA::Long VISU_TimeAnimation_i::getNbFields()
960 return myAnim->getNbFields();
963 CORBA::Long VISU_TimeAnimation_i::getNbFrames()
965 return myAnim->getNbFrames();
968 CORBA::Boolean VISU_TimeAnimation_i::isRunning()
970 return myAnim->isRunning();
973 CORBA::Long VISU_TimeAnimation_i::getCurrentFrame()
975 return myAnim->getCurrentFrame();
978 VISU::ScalarMap_ptr VISU_TimeAnimation_i::getPresentation
979 (CORBA::Long theField, CORBA::Long theFrame)
981 return myAnim->getPresentation(theField,theFrame);
984 void VISU_TimeAnimation_i::setPresentationType (CORBA::Long theFieldNum,
985 VISU::VISUType theType)
987 myAnim->setPresentationType(theFieldNum,theType);
990 VISU::VISUType VISU_TimeAnimation_i::getPresentationType (CORBA::Long theFieldNum)
992 return myAnim->getPresentationType(theFieldNum);
995 void VISU_TimeAnimation_i::setSpeed(CORBA::Long theSpeed)
997 myAnim->setSpeed(theSpeed);
1000 CORBA::Long VISU_TimeAnimation_i::getSpeed()
1002 return myAnim->getSpeed();
1005 CORBA::Boolean VISU_TimeAnimation_i::isProportional()
1007 return myAnim->isProportional();
1010 void VISU_TimeAnimation_i::setAnimationRange (CORBA::Double theMin,
1011 CORBA::Double theMax)
1013 myAnim->setAnimationRange(theMin,theMax);
1016 CORBA::Double VISU_TimeAnimation_i::getMinRange()
1018 return myAnim->getMinRange();
1021 CORBA::Double VISU_TimeAnimation_i::getMaxRange()
1023 return myAnim->getMaxRange();
1026 CORBA::Boolean VISU_TimeAnimation_i::isRangeDefined()
1028 return myAnim->isRangeDefined();
1031 void VISU_TimeAnimation_i::dumpTo (const char* thePath)
1033 myAnim->dumpTo(thePath);
1036 CORBA::Boolean VISU_TimeAnimation_i::isCycling()
1038 return myAnim->isCycling();
1041 CORBA::Double VISU_TimeAnimation_i::getMinTime()
1043 return myAnim->getMinTime();
1046 CORBA::Double VISU_TimeAnimation_i::getMaxTime()
1048 return myAnim->getMaxTime();
1051 void VISU_TimeAnimation_i::setProportional (CORBA::Boolean theProp)
1053 myAnim->setProportional(theProp);
1056 void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
1058 myAnim->setCycling(theCycle);
1061 SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
1063 return myAnim->publishInStudy();
1066 void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
1068 myAnim->restoreFromStudy(theObj);
1071 CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
1073 return myAnim->isSavedInStudy();
1076 void VISU_TimeAnimation_i::saveAnimation()
1078 myAnim->saveAnimation();