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 not 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 not 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()
493 MESSAGE("Viewer is not defined for animation");
497 bool isDumping = !myDumpPath.isEmpty();
499 if (myFieldsLst[0].myNbFrames > 2)
500 aOneVal = myFieldsLst[0].myTiming[1] - myFieldsLst[0].myTiming[0];
503 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
504 for (int i = 0; i < getNbFields(); i++) {
505 FieldData& aData = myFieldsLst[i];
507 if (aData.myActors[myFrame-1] != 0)
508 aData.myActors[myFrame-1]->VisibilityOff();
510 if (aData.myActors[aData.myNbFrames-1] != 0)
511 aData.myActors[aData.myNbFrames-1]->VisibilityOff();
513 if (aData.myActors[myFrame] != 0) {
514 aData.myActors[myFrame]->VisibilityOn();
517 myView->Repaint(false);
521 QPixmap px = QPixmap::grabWindow(myView->winId());
522 QString aFile(myDumpPath);
523 QString aName = QString("%1").arg(myFieldsLst[0].myTiming[myFrame]);
525 while ((aPos = aName.find(".")) > -1 )
526 aName.replace(aPos, 1, "_");
529 px.save(aFile, "JPEG");
532 if (myProportional) {
537 if (myFieldsLst[0].myNbFrames > 2)
538 k = (myFieldsLst[0].myTiming[myFrame+1] -
539 myFieldsLst[0].myTiming[myFrame]) / aOneVal;
542 if (myFrame < (myFieldsLst[0].myNbFrames - 1))
543 k = (myFieldsLst[0].myTiming[myFrame+1] -
544 myFieldsLst[0].myTiming[myFrame]) / aOneVal;
547 delay = (int)(1000. * k / mySpeed);
553 if (!myIsActive) break;
556 if (myFrame == myFieldsLst[0].myNbFrames) {
570 //************************************************************************
571 VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField)
573 _PTR(SObject) aSObj = theField->GetFather();
574 aSObj = aSObj->GetFather();
575 aSObj = aSObj->GetFather();
576 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
577 if (CORBA::is_nil(anObject)) return NULL;
578 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
581 //************************************************************************
582 VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (_PTR(SObject) theSObject)
584 VISU::Storable::TRestoringMap aMap;
586 _PTR(GenericAttribute) anAttr;
587 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
588 _PTR(AttributeComment) aComment (anAttr);
589 std::string aString = aComment->Value();
590 QString strIn (aString.c_str());
591 VISU::Storable::StrToMap(strIn, aMap);
597 //************************************************************************
598 double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp)
600 _PTR(GenericAttribute) anAttr;
601 if (theTimeStamp->FindAttribute(anAttr, "AttributeName")) {
602 _PTR(AttributeName) aName (anAttr);
603 QString aNameString (aName->Value().c_str());
604 int time_len = aNameString.find(',');
606 return aNameString.left(time_len).toDouble();
608 return aNameString.toDouble();
613 //************************************************************************
614 void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed)
616 mySpeed = (theSpeed<1)? 1 : theSpeed;
619 //************************************************************************
620 int VISU_TimeAnimation::myNBAnimations = 0;
621 QString VISU_TimeAnimation::GenerateName()
623 return VISU::GenerateName("Animation", myNBAnimations++);
626 //************************************************************************
627 std::string GetPresentationComment (VISU::VISUType thePrsType)
630 switch (thePrsType) {
631 case VISU::TSCALARMAP:
632 aPrsCmt = VISU::ScalarMap_i::myComment;
634 case VISU::TISOSURFACE:
635 aPrsCmt = VISU::IsoSurfaces_i::myComment;
637 case VISU::TCUTPLANES:
638 aPrsCmt = VISU::CutPlanes_i::myComment;
641 aPrsCmt = VISU::Plot3D_i::myComment;
643 case VISU::TDEFORMEDSHAPE:
644 aPrsCmt = VISU::DeformedShape_i::myComment;
647 aPrsCmt = VISU::Vectors_i::myComment;
649 case VISU::TSTREAMLINES:
650 aPrsCmt = VISU::StreamLines_i::myComment;
653 aPrsCmt = "Unknown presentation";
659 //************************************************************************
660 SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
662 if (myStudy->GetProperties()->IsLocked())
663 return SALOMEDS::SObject::_nil();
665 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
666 aStudyBuilder->NewCommand(); // There is a transaction
667 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
668 std::string aSComponentEntry = aSComponent->GetID();
671 aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
672 VISU::TANIMATION,myMinVal,myMaxVal);
674 string anEntry = VISU::CreateAttributes(myStudy,aSComponentEntry.c_str(),"","",
675 GenerateName(),"",aComment,true);
676 myAnimEntry = anEntry.c_str();
677 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
679 for (int i = 0; i < getNbFields(); i++) {
680 FieldData& aData = myFieldsLst[i];
681 _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
682 aStudyBuilder->Addreference(newObj, aData.myField);
683 if (aData.myPrs.empty()) {
684 VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
685 GetPresentationComment(aData.myPrsType).c_str(),"","",true);
687 ostringstream strOut;
688 aData.myPrs[0]->ToStream(strOut);
689 string aPrsComment = strOut.str();
690 VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
691 aData.myPrs[0]->GetComment(),"",aPrsComment.c_str(),true);
694 aStudyBuilder->CommitCommand();
696 return VISU::GetSObject(aAnimSObject);
699 //************************************************************************
700 void VISU_TimeAnimation::saveAnimation()
702 if (myStudy->GetProperties()->IsLocked()) return;
703 if (myAnimEntry.isEmpty()) return;
705 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.latin1());
706 if (!aAnimSObject) return;
708 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
709 aStudyBuilder->NewCommand(); // There is a transaction
710 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
711 std::string aSComponentEntry = aSComponent->GetID();
714 aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
715 VISU::TANIMATION,myMinVal,myMaxVal);
717 _PTR(GenericAttribute) anAttr;
718 anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeComment");
719 _PTR(AttributeComment) aCmnt (anAttr);
720 aCmnt->SetValue(aComment.latin1());
722 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
724 for (i = 0, anIter->Init(); anIter->More(); anIter->Next(), i++) {
725 FieldData& aData = myFieldsLst[i];
727 _PTR(SObject) aRefObj = anIter->Value();
728 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
731 string aPrsComment, aPrsNameTxt;
732 if (aData.myPrs.empty()) {
734 aPrsNameTxt = GetPresentationComment(aData.myPrsType);
736 ostringstream strOut;
737 aData.myPrs[0]->ToStream(strOut);
738 aPrsComment = strOut.str();
740 aPrsNameTxt = aData.myPrs[0]->GetComment();
743 if (anPrsIter->More()) {
744 _PTR(SObject) aPrsObj = anPrsIter->Value();
745 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeComment");
746 aCmnt = _PTR(AttributeComment)(anAttr);
747 aCmnt->SetValue(aPrsComment.c_str());
749 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
750 _PTR(AttributeName) aPrsName (anAttr);
751 aPrsName->SetValue(aPrsNameTxt);
754 VISU::CreateAttributes(myStudy, aRefObj->GetID().c_str(),"","",
755 aPrsNameTxt.c_str(),"",aPrsComment.c_str(),true);
758 aStudyBuilder->CommitCommand();
761 //************************************************************************
762 void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
764 _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
765 restoreFromStudy(aAnimSObject);
768 void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
770 _PTR(SObject) aAnimSObject = theField;
772 VISU::Storable::TRestoringMap aMap;
773 _PTR(GenericAttribute) anAttr;
774 if (!aAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
776 _PTR(AttributeComment) aComment (anAttr);
777 string aComm = aComment->Value();
778 QString strIn (aComm.c_str());
779 VISU::Storable::StrToMap(strIn,aMap);
782 myMinVal = VISU::Storable::FindValue(aMap,"myMinVal",&isExist).toDouble();
783 myMaxVal = VISU::Storable::FindValue(aMap,"myMaxVal",&isExist).toDouble();
785 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
786 for (anIter->Init(); anIter->More(); anIter->Next()) {
787 _PTR(SObject) aRefObj = anIter->Value();
788 _PTR(SObject) aFieldObj;
789 if (!aRefObj->ReferencedObject(aFieldObj) ) continue;
791 FieldData& aData = getFieldData(getNbFields()-1);
793 // Get Presentation object
794 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
796 if (!anPrsIter->More()) continue;
797 _PTR(SObject) aPrsObj = anPrsIter->Value();
798 if (!aPrsObj->FindAttribute(anAttr, "AttributeName")) continue;
799 _PTR(AttributeName) aName (anAttr);
800 string aStr = aName->Value();
801 QString strName (aStr.c_str());
803 if (strName == VISU::ScalarMap_i::myComment.c_str())
804 aData.myPrsType = VISU::TSCALARMAP;
805 else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
806 aData.myPrsType = VISU::TISOSURFACE;
807 else if (strName == VISU::CutPlanes_i::myComment.c_str())
808 aData.myPrsType = VISU::TCUTPLANES;
809 else if (strName == VISU::Plot3D_i::myComment.c_str())
810 aData.myPrsType = VISU::TPLOT3D;
811 else if (strName == VISU::DeformedShape_i::myComment.c_str())
812 aData.myPrsType = VISU::TDEFORMEDSHAPE;
813 else if (strName == VISU::Vectors_i::myComment.c_str())
814 aData.myPrsType = VISU::TVECTORS;
815 else if (strName == VISU::StreamLines_i::myComment.c_str())
816 aData.myPrsType = VISU::TSTREAMLINES;
819 generatePresentations(getNbFields()-1);
821 if (!aPrsObj->FindAttribute(anAttr, "AttributeComment")) continue;
822 _PTR(AttributeComment) aPrsComment (anAttr);
823 string aPrsComm = aPrsComment->Value();
824 if (aPrsComm.length() > 0) {
825 QString strPrsIn (aPrsComm.c_str());
826 VISU::Storable::TRestoringMap aPrsMap;
827 VISU::Storable::StrToMap(strPrsIn,aPrsMap);
829 aData.myPrs[0]->Restore(aPrsMap);
831 aData.myPrs[0]->GetOffset(aData.myOffset);
832 for (int i = 1; i < aData.myNbFrames; i++) {
833 aData.myPrs[i]->SameAs(aData.myPrs[0]);
836 string aStr = aAnimSObject->GetID();
837 myAnimEntry = aStr.c_str();
841 //========================================================================
842 //========================================================================
843 //========================================================================
844 struct TNewAnimationEvent: public SALOME_Event
846 std::string myStudyName;
847 VISU::View3D_ptr myView3D;
849 typedef VISU_TimeAnimation* TResult;
852 TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
853 myStudyName(theStudyName),
854 myView3D(VISU::View3D::_duplicate(theView3D)),
862 SUIT_Session* aSession = SUIT_Session::session();
863 QPtrList<SUIT_Application> anApplications = aSession->applications();
864 QPtrListIterator<SUIT_Application> anIter (anApplications);
865 while (SUIT_Application* anApp = anIter.current()) {
867 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
868 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
869 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
870 if (myStudyName == aCStudy->Name()) {
871 myResult = new VISU_TimeAnimation (aCStudy, myView3D);
881 VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
882 VISU::View3D_ptr theView3D)
884 std::string aStudyName = theStudy->Name();
885 myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
888 VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
893 void VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
895 myAnim->addField(theField);
898 CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
900 return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
901 (myAnim,&VISU_TimeAnimation::generateFrames));
904 void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
906 myAnim->generatePresentations(theFieldNum);
909 void VISU_TimeAnimation_i::clearView()
911 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
912 (myAnim,&VISU_TimeAnimation::clearView));
915 void VISU_TimeAnimation_i::stopAnimation()
917 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
918 (myAnim,&VISU_TimeAnimation::stopAnimation));
921 void VISU_TimeAnimation_i::startAnimation()
923 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
924 (myAnim,&VISU_TimeAnimation::startAnimation));
927 void VISU_TimeAnimation_i::nextFrame()
929 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
930 (myAnim,&VISU_TimeAnimation::nextFrame));
933 void VISU_TimeAnimation_i::prevFrame()
935 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
936 (myAnim,&VISU_TimeAnimation::prevFrame));
939 void VISU_TimeAnimation_i::firstFrame()
941 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
942 (myAnim,&VISU_TimeAnimation::firstFrame));
945 void VISU_TimeAnimation_i::lastFrame()
947 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
948 (myAnim,&VISU_TimeAnimation::lastFrame));
951 void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
953 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
954 (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
957 CORBA::Long VISU_TimeAnimation_i::getNbFields()
959 return myAnim->getNbFields();
962 CORBA::Long VISU_TimeAnimation_i::getNbFrames()
964 return myAnim->getNbFrames();
967 CORBA::Boolean VISU_TimeAnimation_i::isRunning()
969 return myAnim->isRunning();
972 CORBA::Long VISU_TimeAnimation_i::getCurrentFrame()
974 return myAnim->getCurrentFrame();
977 VISU::ScalarMap_ptr VISU_TimeAnimation_i::getPresentation
978 (CORBA::Long theField, CORBA::Long theFrame)
980 return myAnim->getPresentation(theField,theFrame);
983 void VISU_TimeAnimation_i::setPresentationType (CORBA::Long theFieldNum,
984 VISU::VISUType theType)
986 myAnim->setPresentationType(theFieldNum,theType);
989 VISU::VISUType VISU_TimeAnimation_i::getPresentationType (CORBA::Long theFieldNum)
991 return myAnim->getPresentationType(theFieldNum);
994 void VISU_TimeAnimation_i::setSpeed(CORBA::Long theSpeed)
996 myAnim->setSpeed(theSpeed);
999 CORBA::Long VISU_TimeAnimation_i::getSpeed()
1001 return myAnim->getSpeed();
1004 CORBA::Boolean VISU_TimeAnimation_i::isProportional()
1006 return myAnim->isProportional();
1009 void VISU_TimeAnimation_i::setAnimationRange (CORBA::Double theMin,
1010 CORBA::Double theMax)
1012 myAnim->setAnimationRange(theMin,theMax);
1015 CORBA::Double VISU_TimeAnimation_i::getMinRange()
1017 return myAnim->getMinRange();
1020 CORBA::Double VISU_TimeAnimation_i::getMaxRange()
1022 return myAnim->getMaxRange();
1025 CORBA::Boolean VISU_TimeAnimation_i::isRangeDefined()
1027 return myAnim->isRangeDefined();
1030 void VISU_TimeAnimation_i::dumpTo (const char* thePath)
1032 myAnim->dumpTo(thePath);
1035 CORBA::Boolean VISU_TimeAnimation_i::isCycling()
1037 return myAnim->isCycling();
1040 CORBA::Double VISU_TimeAnimation_i::getMinTime()
1042 return myAnim->getMinTime();
1045 CORBA::Double VISU_TimeAnimation_i::getMaxTime()
1047 return myAnim->getMaxTime();
1050 void VISU_TimeAnimation_i::setProportional (CORBA::Boolean theProp)
1052 myAnim->setProportional(theProp);
1055 void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
1057 myAnim->setCycling(theCycle);
1060 SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
1062 return myAnim->publishInStudy();
1065 void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
1067 myAnim->restoreFromStudy(theObj);
1070 CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
1072 return myAnim->isSavedInStudy();
1075 void VISU_TimeAnimation_i::saveAnimation()
1077 myAnim->saveAnimation();