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;
284 QString aFixRange = VISU::GetResourceMgr()->stringValue("Visu:SBImposeRange");
285 if (aFixRange.compare("true") != 0) {
286 for (i = 0; i < aData.myNbFrames; i++) {
287 aData.myPrs[i]->SetRange(aMin, aMax);
288 aData.myPrs[i]->SetOffset(aData.myOffset);
290 if (aData.myPrsType == VISU::TISOSURFACE)
291 for (i = 0; i < aData.myNbFrames; i++)
292 if (VISU::IsoSurfaces_i* aPrs = dynamic_cast<VISU::IsoSurfaces_i*>(aData.myPrs[i]))
293 aPrs->SetSubRange(aMin, aMax);
298 //************************************************************************
299 CORBA::Boolean VISU_TimeAnimation::generateFrames() {
301 MESSAGE("Viewer is nod defined for animation");
305 myLastError = QString("Frame(s) for ");
306 bool aNoError = true;
310 for (int i = 0; i < getNbFields(); i++) {
311 FieldData& aData = myFieldsLst[i];
312 aData.myActors.resize(aData.myNbFrames,NULL);
313 for (long j = 0; j < aData.myNbFrames; j++) {
314 VISU_Actor* aActor = NULL;
316 aData.myPrs[j]->SetOffset(aData.myOffset);
317 aActor = aData.myPrs[j]->CreateActor();
318 myView->AddActor(aActor);
320 aActor->VisibilityOn();
322 aActor->VisibilityOff();
323 }catch(...){ //catch(std::runtime_error& exc){
325 myLastError += QString("%1 ").arg(aData.myTiming[j]);
327 aData.myActors[j] = aActor;
331 myLastError += QString(" timestamp(s) cannot be created.");
332 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
337 //************************************************************************
338 void VISU_TimeAnimation::clearView() {
340 MESSAGE("Viewer is nod defined for animation");
343 vtkRenderer* aRen = myView->getRenderer();
344 for (int i = 0; i < getNbFields(); i++) {
345 FieldData& aData = myFieldsLst[i];
346 if (!aData.myActors.empty()) {
347 for (int i = 0, iEnd = aData.myActors.size(); i < iEnd; i++) {
348 if (aData.myActors[i] != 0) {
349 aData.myActors[i]->RemoveFromRender(aRen);
350 aData.myActors[i]->Delete();
353 aData.myActors.clear();
356 VISU::RepaintView(myView);
359 //************************************************************************
360 void VISU_TimeAnimation::stopAnimation() {
364 //************************************************************************
365 void VISU_TimeAnimation::startAnimation() {
372 //************************************************************************
373 void VISU_TimeAnimation::nextFrame() {
375 if (myFrame < (myFieldsLst[0].myNbFrames-1)) {
377 for (i = 0; i < getNbFields(); i++)
378 if (myFieldsLst[i].myActors[myFrame] != 0)
379 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
382 for (i = 0; i < getNbFields(); i++)
383 if (myFieldsLst[i].myActors[myFrame] != 0)
384 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
386 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
391 //************************************************************************
392 void VISU_TimeAnimation::prevFrame() {
396 for (i = 0; i < getNbFields(); i++)
397 if (myFieldsLst[i].myActors[myFrame] != 0)
398 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
401 for (i = 0; i < getNbFields(); i++)
402 if (myFieldsLst[i].myActors[myFrame] != 0)
403 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
405 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
410 //************************************************************************
411 void VISU_TimeAnimation::firstFrame() {
414 for (i = 0; i < getNbFields(); i++)
415 if(!myFieldsLst[i].myActors.empty())
416 if (myFieldsLst[i].myActors[myFrame] != 0)
417 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
419 for (i = 0; i < getNbFields(); i++)
420 if(!myFieldsLst[i].myActors.empty())
421 if (myFieldsLst[i].myActors[myFrame] != 0)
422 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
423 if(!myFieldsLst[0].myTiming.empty()){
424 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
429 //************************************************************************
430 void VISU_TimeAnimation::lastFrame() {
433 for (i = 0; i < getNbFields(); i++)
434 if (myFieldsLst[i].myActors[myFrame] != 0)
435 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
437 myFrame = myFieldsLst[0].myNbFrames-1;
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 // For Batchmode using
449 void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) {
450 if ((theFrame < 0) || (theFrame > (getNbFrames()-1)))
456 for (i = 0; i < getNbFields(); i++)
457 if (myFieldsLst[i].myActors[myFrame] != 0)
458 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
461 for (i = 0; i < getNbFields(); i++)
462 if (myFieldsLst[i].myActors[myFrame] != 0)
463 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
465 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
468 qApp->processEvents(3);
473 //************************************************************************
474 VISU::ScalarMap_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) {
475 if ((theField > getNbFields()) || (theField < 0))
476 return VISU::ScalarMap::_nil();
477 if ((theFrame < 0) || (theFrame > (myFieldsLst[theField].myNbFrames - 1)))
478 return VISU::ScalarMap::_nil();
479 return myFieldsLst[theField].myPrs[theFrame]->_this();
483 //************************************************************************
484 CORBA::Long VISU_TimeAnimation::getNbFrames() {
485 return (getNbFields() > 0)? myFieldsLst[0].myNbFrames : 0;
489 //************************************************************************
490 void VISU_TimeAnimation::run() {
492 MESSAGE("Viewer is nod defined for animation");
497 bool isDumping = !myDumpPath.isEmpty();
498 aOneVal = (myFieldsLst[0].myNbFrames > 2) ?
499 myFieldsLst[0].myTiming[1] - myFieldsLst[0].myTiming[0] : 1;
502 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
503 for (int i = 0; i < getNbFields(); i++) {
504 FieldData& aData = myFieldsLst[i];
506 if (aData.myActors[myFrame-1] != 0)
507 aData.myActors[myFrame-1]->VisibilityOff();
509 if (aData.myActors[aData.myNbFrames-1] != 0)
510 aData.myActors[aData.myNbFrames-1]->VisibilityOff();
512 if (aData.myActors[myFrame] != 0) {
513 aData.myActors[myFrame]->VisibilityOn();
516 myView->Repaint(false);
518 QPixmap px = QPixmap::grabWindow(myView->winId());
519 QString aFile(myDumpPath);
520 QString aName = QString("%1").arg(myFieldsLst[0].myTiming[myFrame]);
522 while ((aPos = aName.find(".")) > -1 )
523 aName.replace(aPos, 1, "_");
526 px.save(aFile, "JPEG");
529 if (myProportional) {
535 if (myFieldsLst[0].myNbFrames > 2)
536 k = (myFieldsLst[0].myTiming[myFrame+1] - myFieldsLst[0].myTiming[myFrame])/aOneVal;
541 k = (myFrame < (myFieldsLst[0].myNbFrames-1))?
542 (myFieldsLst[0].myTiming[myFrame+1] - myFieldsLst[0].myTiming[myFrame])/aOneVal : 1;
547 msleep((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 return aNameString.toDouble();
610 //************************************************************************
611 void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed)
613 mySpeed = (theSpeed<1)? 1 : theSpeed;
616 //************************************************************************
617 int VISU_TimeAnimation::myNBAnimations = 0;
618 QString VISU_TimeAnimation::GenerateName()
620 return VISU::GenerateName("Animation", myNBAnimations++);
623 //************************************************************************
624 std::string GetPresentationComment (VISU::VISUType thePrsType)
627 switch (thePrsType) {
628 case VISU::TSCALARMAP:
629 aPrsCmt = VISU::ScalarMap_i::myComment;
631 case VISU::TISOSURFACE:
632 aPrsCmt = VISU::IsoSurfaces_i::myComment;
634 case VISU::TCUTPLANES:
635 aPrsCmt = VISU::CutPlanes_i::myComment;
638 aPrsCmt = VISU::Plot3D_i::myComment;
640 case VISU::TDEFORMEDSHAPE:
641 aPrsCmt = VISU::DeformedShape_i::myComment;
644 aPrsCmt = VISU::Vectors_i::myComment;
646 case VISU::TSTREAMLINES:
647 aPrsCmt = VISU::StreamLines_i::myComment;
650 aPrsCmt = "Unknown presentation";
656 //************************************************************************
657 SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
659 if (myStudy->GetProperties()->IsLocked())
660 return SALOMEDS::SObject::_nil();
662 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
663 aStudyBuilder->NewCommand(); // There is a transaction
664 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
665 std::string aSComponentEntry = aSComponent->GetID();
668 aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
669 VISU::TANIMATION,myMinVal,myMaxVal);
671 string anEntry = VISU::CreateAttributes(myStudy,aSComponentEntry.c_str(),"","",
672 GenerateName(),"",aComment,true);
673 myAnimEntry = anEntry.c_str();
674 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
676 for (int i = 0; i < getNbFields(); i++) {
677 FieldData& aData = myFieldsLst[i];
678 _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
679 aStudyBuilder->Addreference(newObj, aData.myField);
680 if (aData.myPrs.empty()) {
681 VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
682 GetPresentationComment(aData.myPrsType).c_str(),"","",true);
684 ostringstream strOut;
685 aData.myPrs[0]->ToStream(strOut);
686 string aPrsComment = strOut.str();
687 VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
688 aData.myPrs[0]->GetComment(),"",aPrsComment.c_str(),true);
691 aStudyBuilder->CommitCommand();
693 return VISU::GetSObject(aAnimSObject);
696 //************************************************************************
697 void VISU_TimeAnimation::saveAnimation()
699 if (myStudy->GetProperties()->IsLocked()) return;
700 if (myAnimEntry.isEmpty()) return;
702 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry);
703 if (!aAnimSObject) return;
705 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
706 aStudyBuilder->NewCommand(); // There is a transaction
707 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
708 std::string aSComponentEntry = aSComponent->GetID();
711 aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
712 VISU::TANIMATION,myMinVal,myMaxVal);
714 _PTR(GenericAttribute) anAttr;
715 anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeComment");
716 _PTR(AttributeComment) aCmnt (anAttr);
717 aCmnt->SetValue(aComment);
719 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
721 for (i = 0, anIter->Init(); anIter->More(); anIter->Next(), i++) {
722 FieldData& aData = myFieldsLst[i];
724 _PTR(SObject) aRefObj = anIter->Value();
725 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
728 string aPrsComment, aPrsNameTxt;
729 if (aData.myPrs.empty()) {
731 aPrsNameTxt = GetPresentationComment(aData.myPrsType);
733 ostringstream strOut;
734 aData.myPrs[0]->ToStream(strOut);
735 aPrsComment = strOut.str();
737 aPrsNameTxt = aData.myPrs[0]->GetComment();
740 if (anPrsIter->More()) {
741 _PTR(SObject) aPrsObj = anPrsIter->Value();
742 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeComment");
743 aCmnt = _PTR(AttributeComment)(anAttr);
744 aCmnt->SetValue(aPrsComment.c_str());
746 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
747 _PTR(AttributeName) aPrsName (anAttr);
748 aPrsName->SetValue(aPrsNameTxt);
751 VISU::CreateAttributes(myStudy, aRefObj->GetID().c_str(),"","",
752 aPrsNameTxt.c_str(),"",aPrsComment.c_str(),true);
755 aStudyBuilder->CommitCommand();
758 //************************************************************************
759 void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
761 _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
762 restoreFromStudy(aAnimSObject);
765 void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
767 _PTR(SObject) aAnimSObject = theField;
769 VISU::Storable::TRestoringMap aMap;
770 _PTR(GenericAttribute) anAttr;
771 if (!aAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
773 _PTR(AttributeComment) aComment (anAttr);
774 string aComm = aComment->Value();
775 QString strIn (aComm.c_str());
776 VISU::Storable::StrToMap(strIn,aMap);
779 myMinVal = VISU::Storable::FindValue(aMap,"myMinVal",&isExist).toDouble();
780 myMaxVal = VISU::Storable::FindValue(aMap,"myMaxVal",&isExist).toDouble();
782 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
783 for (anIter->Init(); anIter->More(); anIter->Next()) {
784 _PTR(SObject) aRefObj = anIter->Value();
785 _PTR(SObject) aFieldObj;
786 if (!aRefObj->ReferencedObject(aFieldObj) ) continue;
788 FieldData& aData = getFieldData(getNbFields()-1);
790 // Get Presentation object
791 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
793 if (!anPrsIter->More()) continue;
794 _PTR(SObject) aPrsObj = anPrsIter->Value();
795 if (!aPrsObj->FindAttribute(anAttr, "AttributeName")) continue;
796 _PTR(AttributeName) aName (anAttr);
797 string aStr = aName->Value();
798 QString strName (aStr.c_str());
800 if (strName == VISU::ScalarMap_i::myComment.c_str())
801 aData.myPrsType = VISU::TSCALARMAP;
802 else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
803 aData.myPrsType = VISU::TISOSURFACE;
804 else if (strName == VISU::CutPlanes_i::myComment.c_str())
805 aData.myPrsType = VISU::TCUTPLANES;
806 else if (strName == VISU::Plot3D_i::myComment.c_str())
807 aData.myPrsType = VISU::TPLOT3D;
808 else if (strName == VISU::DeformedShape_i::myComment.c_str())
809 aData.myPrsType = VISU::TDEFORMEDSHAPE;
810 else if (strName == VISU::Vectors_i::myComment.c_str())
811 aData.myPrsType = VISU::TVECTORS;
812 else if (strName == VISU::StreamLines_i::myComment.c_str())
813 aData.myPrsType = VISU::TSTREAMLINES;
816 generatePresentations(getNbFields()-1);
818 if (!aPrsObj->FindAttribute(anAttr, "AttributeComment")) continue;
819 _PTR(AttributeComment) aPrsComment (anAttr);
820 string aPrsComm = aPrsComment->Value();
821 if (aPrsComm.length() > 0) {
822 QString strPrsIn (aPrsComm.c_str());
823 VISU::Storable::TRestoringMap aPrsMap;
824 VISU::Storable::StrToMap(strPrsIn,aPrsMap);
826 aData.myPrs[0]->Restore(aPrsMap);
828 aData.myPrs[0]->GetOffset(aData.myOffset);
829 for (int i = 1; i < aData.myNbFrames; i++) {
830 aData.myPrs[i]->SameAs(aData.myPrs[0]);
833 string aStr = aAnimSObject->GetID();
834 myAnimEntry = aStr.c_str();
838 //========================================================================
839 //========================================================================
840 //========================================================================
841 struct TNewAnimationEvent: public SALOME_Event
843 std::string myStudyName;
844 VISU::View3D_ptr myView3D;
846 typedef VISU_TimeAnimation* TResult;
849 TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
850 myStudyName(theStudyName),
851 myView3D(VISU::View3D::_duplicate(theView3D)),
859 SUIT_Session* aSession = SUIT_Session::session();
860 QPtrList<SUIT_Application> anApplications = aSession->applications();
861 QPtrListIterator<SUIT_Application> anIter (anApplications);
862 while (SUIT_Application* anApp = anIter.current()) {
864 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
865 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
866 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
867 if (myStudyName == aCStudy->Name()) {
868 myResult = new VISU_TimeAnimation (aCStudy, myView3D);
878 VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
879 VISU::View3D_ptr theView3D)
881 std::string aStudyName = theStudy->Name();
882 myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
885 VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
890 void VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
892 myAnim->addField(theField);
895 CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
897 return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
898 (myAnim,&VISU_TimeAnimation::generateFrames));
901 void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
903 myAnim->generatePresentations(theFieldNum);
906 void VISU_TimeAnimation_i::clearView()
908 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
909 (myAnim,&VISU_TimeAnimation::clearView));
912 void VISU_TimeAnimation_i::stopAnimation()
914 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
915 (myAnim,&VISU_TimeAnimation::stopAnimation));
918 void VISU_TimeAnimation_i::startAnimation()
920 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
921 (myAnim,&VISU_TimeAnimation::startAnimation));
924 void VISU_TimeAnimation_i::nextFrame()
926 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
927 (myAnim,&VISU_TimeAnimation::nextFrame));
930 void VISU_TimeAnimation_i::prevFrame()
932 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
933 (myAnim,&VISU_TimeAnimation::prevFrame));
936 void VISU_TimeAnimation_i::firstFrame()
938 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
939 (myAnim,&VISU_TimeAnimation::firstFrame));
942 void VISU_TimeAnimation_i::lastFrame()
944 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
945 (myAnim,&VISU_TimeAnimation::lastFrame));
948 void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
950 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
951 (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
954 CORBA::Long VISU_TimeAnimation_i::getNbFields()
956 return myAnim->getNbFields();
959 CORBA::Long VISU_TimeAnimation_i::getNbFrames()
961 return myAnim->getNbFrames();
964 CORBA::Boolean VISU_TimeAnimation_i::isRunning()
966 return myAnim->isRunning();
969 CORBA::Long VISU_TimeAnimation_i::getCurrentFrame()
971 return myAnim->getCurrentFrame();
974 VISU::ScalarMap_ptr VISU_TimeAnimation_i::getPresentation
975 (CORBA::Long theField, CORBA::Long theFrame)
977 return myAnim->getPresentation(theField,theFrame);
980 void VISU_TimeAnimation_i::setPresentationType (CORBA::Long theFieldNum,
981 VISU::VISUType theType)
983 myAnim->setPresentationType(theFieldNum,theType);
986 VISU::VISUType VISU_TimeAnimation_i::getPresentationType (CORBA::Long theFieldNum)
988 return myAnim->getPresentationType(theFieldNum);
991 void VISU_TimeAnimation_i::setSpeed(CORBA::Long theSpeed)
993 myAnim->setSpeed(theSpeed);
996 CORBA::Long VISU_TimeAnimation_i::getSpeed()
998 return myAnim->getSpeed();
1001 CORBA::Boolean VISU_TimeAnimation_i::isProportional()
1003 return myAnim->isProportional();
1006 void VISU_TimeAnimation_i::setAnimationRange (CORBA::Double theMin,
1007 CORBA::Double theMax)
1009 myAnim->setAnimationRange(theMin,theMax);
1012 CORBA::Double VISU_TimeAnimation_i::getMinRange()
1014 return myAnim->getMinRange();
1017 CORBA::Double VISU_TimeAnimation_i::getMaxRange()
1019 return myAnim->getMaxRange();
1022 CORBA::Boolean VISU_TimeAnimation_i::isRangeDefined()
1024 return myAnim->isRangeDefined();
1027 void VISU_TimeAnimation_i::dumpTo (const char* thePath)
1029 myAnim->dumpTo(thePath);
1032 CORBA::Boolean VISU_TimeAnimation_i::isCycling()
1034 return myAnim->isCycling();
1037 CORBA::Double VISU_TimeAnimation_i::getMinTime()
1039 return myAnim->getMinTime();
1042 CORBA::Double VISU_TimeAnimation_i::getMaxTime()
1044 return myAnim->getMaxTime();
1047 void VISU_TimeAnimation_i::setProportional (CORBA::Boolean theProp)
1049 myAnim->setProportional(theProp);
1052 void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
1054 myAnim->setCycling(theCycle);
1057 SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
1059 return myAnim->publishInStudy();
1062 void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
1064 myAnim->restoreFromStudy(theObj);
1067 CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
1069 return myAnim->isSavedInStudy();
1072 void VISU_TimeAnimation_i::saveAnimation()
1074 myAnim->saveAnimation();