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 SUIT_ViewWindow* aVW = pView->GetViewWindow();
63 myView = VISU::GetViewWindow(aVW);
77 //************************************************************************
78 VISU_TimeAnimation::~VISU_TimeAnimation()
80 for (int i = 0; i < getNbFields(); i++) {
81 clearData(myFieldsLst[i]);
86 //************************************************************************
87 void VISU_TimeAnimation::addField (_PTR(SObject) theField)
90 aNewData.myField = theField;
91 aNewData.myNbFrames = 0;
92 aNewData.myPrsType = VISU::TSCALARMAP;
93 aNewData.myOffset[0] = aNewData.myOffset[1] = aNewData.myOffset[2] = 0;
94 VISU::Storable::TRestoringMap aMap = getMapOfValue(aNewData.myField);
95 aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
96 myFieldsLst.append(aNewData);
98 //find Min/Max timestamps
99 if ((myTimeMin == 0) && (myTimeMax == 0)) {
100 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(theField);
101 anIter->Next(); // First is reference on support
102 myTimeMin = getTimeValue(anIter->Value());
103 for(; anIter->More(); anIter->Next()) {
104 myTimeMax = getTimeValue(anIter->Value());
109 //************************************************************************
110 void VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField)
112 SALOMEDS::SObject_var theFieldDup = SALOMEDS::SObject::_duplicate(theField);
113 _PTR(SObject) aField = VISU::GetClientSObject(theFieldDup, myStudy);
118 //************************************************************************
119 void VISU_TimeAnimation::clearData(FieldData& theData) {
120 theData.myTiming.clear();
121 vtkRenderer* aRen = myView->getRenderer();
122 if (!theData.myActors.empty()) {
123 for (int i = 0, iEnd = theData.myActors.size(); i < iEnd; i++) {
124 if (theData.myActors[i] != 0) {
125 theData.myActors[i]->RemoveFromRender(aRen);
126 theData.myActors[i]->Delete();
129 theData.myActors.clear();
131 if (!theData.myPrs.empty()) {
132 for (int i = 0, iEnd = theData.myPrs.size(); i < iEnd; i++)
133 if (theData.myPrs[i] != 0) {
134 theData.myPrs[i]->_remove_ref();
136 theData.myPrs.clear();
138 theData.myNbFrames = 0;
143 //************************************************************************
144 void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum) {
145 FieldData& aData = myFieldsLst[theFieldNum];
147 // Delete previous presentations
150 VISU::Result_i* pResult = createPresent(aData.myField);
151 VISU::Storable::TRestoringMap aMap = getMapOfValue(aData.myField);
152 aData.myNbFrames = aData.myNbTimes;
153 //VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
155 aData.myPrs.resize(aData.myNbTimes,NULL);
156 aData.myTiming.resize(aData.myNbTimes);
158 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aData.myField);
159 _PTR(SObject) aTimeStamp;
160 anIter->Next(); // First is reference on support
162 double aMin = VTK_LARGE_FLOAT, aMax = -VTK_LARGE_FLOAT;
163 for (; anIter->More(); anIter->Next()) {
164 if (i == aData.myNbTimes) {
165 MESSAGE("There are extra timestamps in field");
168 aTimeStamp = anIter->Value();
169 if (!aTimeStamp) continue;
171 aData.myTiming[i] = getTimeValue(aTimeStamp);
172 if (isRangeDefined()) {
173 if (aData.myTiming[i] < myMinVal) continue;
174 if (aData.myTiming[i] > myMaxVal) break;
177 VISU::Storable::TRestoringMap aTimeMap = getMapOfValue(aTimeStamp);
178 QString aMeshName = VISU::Storable::FindValue(aTimeMap,"myMeshName");
179 VISU::Entity anEntity = (VISU::Entity) VISU::Storable::FindValue(aTimeMap,"myEntityId").toInt();
180 QString aFieldName = VISU::Storable::FindValue(aTimeMap,"myFieldName");
181 int aTimeStampId = VISU::Storable::FindValue(aTimeMap,"myTimeStampId").toInt();
183 switch (aData.myPrsType) {
184 case VISU::TSCALARMAP: // ScalarMap
186 VISU::ScalarMap_i* aPresent = new VISU::ScalarMap_i(pResult, false);
187 aPresent->Create(aMeshName.latin1(), anEntity,
188 aFieldName.latin1(), aTimeStampId);
189 //VISU::ScalarMap_var aTmp = aPresent->_this();
190 //aPresent->_remove_ref();
191 aData.myPrs[i] = aPresent;
195 case VISU::TISOSURFACE: // Iso Surfaces
197 VISU::IsoSurfaces_i* aPresent = new VISU::IsoSurfaces_i(pResult, false);
198 aPresent->Create(aMeshName.latin1(), anEntity,
199 aFieldName.latin1(), aTimeStampId);
200 //VISU::IsoSurfaces_var aTmp = aPresent->_this();
201 //aPresent->_remove_ref();
202 aData.myPrs[i] = aPresent;
206 case VISU::TCUTPLANES: // Cut Planes
208 VISU::CutPlanes_i* aPresent = new VISU::CutPlanes_i(pResult, false);
209 aPresent->Create(aMeshName.latin1(), anEntity,
210 aFieldName.latin1(), aTimeStampId);
211 //VISU::CutPlanes_var aTmp = aPresent->_this();
212 //aPresent->_remove_ref();
213 aData.myPrs[i] = aPresent;
217 case VISU::TPLOT3D: // Plot3d
219 VISU::Plot3D_i* aPresent = new VISU::Plot3D_i (pResult, false);
220 aPresent->Create(aMeshName.latin1(), anEntity,
221 aFieldName.latin1(), aTimeStampId);
222 aData.myPrs[i] = aPresent;
226 case VISU::TDEFORMEDSHAPE: // Deformed Shape
228 VISU::DeformedShape_i* aPresent = new VISU::DeformedShape_i(pResult, false);
229 aPresent->Create(aMeshName.latin1(), anEntity,
230 aFieldName.latin1(), aTimeStampId);
231 //VISU::DeformedShape_var aTmp = aPresent->_this();
232 //aPresent->_remove_ref();
233 aData.myPrs[i] = aPresent;
237 case VISU::TVECTORS: // Vectors
239 VISU::Vectors_i* aPresent = new VISU::Vectors_i(pResult, false);
240 aPresent->Create(aMeshName.latin1(), anEntity,
241 aFieldName.latin1(), aTimeStampId);
242 //VISU::Vectors_var aTmp = aPresent->_this();
243 //aPresent->_remove_ref();
244 aData.myPrs[i] = aPresent;
248 case VISU::TSTREAMLINES: // Stream Lines
250 VISU::StreamLines_i* aPresent = new VISU::StreamLines_i(pResult, false);
251 aPresent->Create(aMeshName.latin1(), anEntity,
252 aFieldName.latin1(), aTimeStampId);
253 //VISU::StreamLines_var aTmp = aPresent->_this();
254 //aPresent->_remove_ref();
255 aData.myPrs[i] = aPresent;
259 MESSAGE("Not implemented for this presentation type: " << aData.myPrsType);
262 if (aData.myPrs[i]->GetMin() < aMin) aMin = aData.myPrs[i]->GetMin();
263 if (aData.myPrs[i]->GetMax() > aMax) aMax = aData.myPrs[i]->GetMax();
266 aData.myNbFrames = i;
268 int rangeType = VISU::GetResourceMgr()->integerValue("VISU" , "scalar_range_type", 0);
269 if ( rangeType != 1 ) {
270 for (i = 0; i < aData.myNbFrames; i++) {
271 aData.myPrs[i]->SetRange(aMin, aMax);
272 aData.myPrs[i]->SetOffset(aData.myOffset);
274 if (aData.myPrsType == VISU::TISOSURFACE)
275 for (i = 0; i < aData.myNbFrames; i++)
276 if (VISU::IsoSurfaces_i* aPrs = dynamic_cast<VISU::IsoSurfaces_i*>(aData.myPrs[i]))
277 aPrs->SetSubRange(aMin, aMax);
282 //************************************************************************
283 CORBA::Boolean VISU_TimeAnimation::generateFrames() {
285 MESSAGE("Viewer is not defined for animation");
289 myLastError = QString("Frame(s) for ");
290 bool aNoError = true;
294 for (int i = 0; i < getNbFields(); i++) {
295 FieldData& aData = myFieldsLst[i];
296 aData.myActors.resize(aData.myNbFrames,NULL);
297 for (long j = 0; j < aData.myNbFrames; j++) {
298 VISU_Actor* aActor = NULL;
300 aData.myPrs[j]->SetOffset(aData.myOffset);
301 aActor = aData.myPrs[j]->CreateActor();
302 myView->AddActor(aActor);
304 aActor->VisibilityOn();
306 aActor->VisibilityOff();
307 }catch(...){ //catch(std::runtime_error& exc){
309 myLastError += QString("%1 ").arg(aData.myTiming[j]);
311 aData.myActors[j] = aActor;
315 myLastError += QString(" timestamp(s) cannot be created.");
316 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
321 //************************************************************************
322 void VISU_TimeAnimation::clearView() {
324 MESSAGE("Viewer is not defined for animation");
327 vtkRenderer* aRen = myView->getRenderer();
328 for (int i = 0; i < getNbFields(); i++) {
329 FieldData& aData = myFieldsLst[i];
330 if (!aData.myActors.empty()) {
331 for (int i = 0, iEnd = aData.myActors.size(); i < iEnd; i++) {
332 if (aData.myActors[i] != 0) {
333 aData.myActors[i]->RemoveFromRender(aRen);
334 aData.myActors[i]->Delete();
337 aData.myActors.clear();
340 VISU::RepaintView(myView);
343 //************************************************************************
344 void VISU_TimeAnimation::stopAnimation() {
348 //************************************************************************
349 void VISU_TimeAnimation::startAnimation() {
356 //************************************************************************
357 void VISU_TimeAnimation::nextFrame() {
359 if (myFrame < (myFieldsLst[0].myNbFrames-1)) {
361 for (i = 0; i < getNbFields(); i++)
362 if (myFieldsLst[i].myActors[myFrame] != 0)
363 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
366 for (i = 0; i < getNbFields(); i++)
367 if (myFieldsLst[i].myActors[myFrame] != 0)
368 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
370 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
375 //************************************************************************
376 void VISU_TimeAnimation::prevFrame() {
380 for (i = 0; i < getNbFields(); i++)
381 if (myFieldsLst[i].myActors[myFrame] != 0)
382 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
385 for (i = 0; i < getNbFields(); i++)
386 if (myFieldsLst[i].myActors[myFrame] != 0)
387 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
389 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
394 //************************************************************************
395 void VISU_TimeAnimation::firstFrame() {
398 for (i = 0; i < getNbFields(); i++)
399 if(!myFieldsLst[i].myActors.empty())
400 if (myFieldsLst[i].myActors[myFrame] != 0)
401 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
403 for (i = 0; i < getNbFields(); i++)
404 if(!myFieldsLst[i].myActors.empty())
405 if (myFieldsLst[i].myActors[myFrame] != 0)
406 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
407 if(!myFieldsLst[0].myTiming.empty()){
408 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
413 //************************************************************************
414 void VISU_TimeAnimation::lastFrame() {
417 for (i = 0; i < getNbFields(); i++)
418 if (myFieldsLst[i].myActors[myFrame] != 0)
419 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
421 myFrame = myFieldsLst[0].myNbFrames-1;
422 for (i = 0; i < getNbFields(); i++)
423 if (myFieldsLst[i].myActors[myFrame] != 0)
424 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
426 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
431 //************************************************************************
432 // For Batchmode using
433 void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) {
434 if ((theFrame < 0) || (theFrame > (getNbFrames()-1)))
440 for (i = 0; i < getNbFields(); i++)
441 if (myFieldsLst[i].myActors[myFrame] != 0)
442 myFieldsLst[i].myActors[myFrame]->VisibilityOff();
445 for (i = 0; i < getNbFields(); i++)
446 if (myFieldsLst[i].myActors[myFrame] != 0)
447 myFieldsLst[i].myActors[myFrame]->VisibilityOn();
449 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
452 qApp->processEvents(3);
457 //************************************************************************
458 VISU::ScalarMap_ptr VISU_TimeAnimation::getPresentation(CORBA::Long theField, CORBA::Long theFrame) {
459 if ((theField > getNbFields()) || (theField < 0))
460 return VISU::ScalarMap::_nil();
461 if ((theFrame < 0) || (theFrame > (myFieldsLst[theField].myNbFrames - 1)))
462 return VISU::ScalarMap::_nil();
463 return myFieldsLst[theField].myPrs[theFrame]->_this();
467 //************************************************************************
468 CORBA::Long VISU_TimeAnimation::getNbFrames() {
469 return (getNbFields() > 0)? myFieldsLst[0].myNbFrames : 0;
473 //************************************************************************
474 void VISU_TimeAnimation::run()
477 MESSAGE("Viewer is not defined for animation");
481 bool isDumping = !myDumpPath.isEmpty();
483 if (myFieldsLst[0].myNbFrames > 2)
484 aOneVal = myFieldsLst[0].myTiming[1] - myFieldsLst[0].myTiming[0];
487 emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
488 for (int i = 0; i < getNbFields(); i++) {
489 FieldData& aData = myFieldsLst[i];
491 if (aData.myActors[myFrame-1] != 0)
492 aData.myActors[myFrame-1]->VisibilityOff();
494 if (aData.myActors[aData.myNbFrames-1] != 0)
495 aData.myActors[aData.myNbFrames-1]->VisibilityOff();
497 if (aData.myActors[myFrame] != 0) {
498 aData.myActors[myFrame]->VisibilityOn();
501 myView->Repaint(false);
504 // We must unlock mutex for some time before grabbing to allow view updating
509 QPixmap px = QPixmap::grabWindow(myView->winId());
510 QString aFile(myDumpPath);
511 QString aName = QString("%1").arg(myFieldsLst[0].myTiming[myFrame]);
513 while ((aPos = aName.find(".")) > -1 )
514 aName.replace(aPos, 1, "_");
517 px.save(aFile, "JPEG");
520 if (myProportional) {
525 if (myFieldsLst[0].myNbFrames > 2)
526 k = (myFieldsLst[0].myTiming[myFrame+1] -
527 myFieldsLst[0].myTiming[myFrame]) / aOneVal;
530 if (myFrame < (myFieldsLst[0].myNbFrames - 1))
531 k = (myFieldsLst[0].myTiming[myFrame+1] -
532 myFieldsLst[0].myTiming[myFrame]) / aOneVal;
535 int delay = (int)(1000. * k / mySpeed);
541 if (!myIsActive) break;
544 if (myFrame == myFieldsLst[0].myNbFrames) {
558 //************************************************************************
559 VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField)
561 _PTR(SObject) aSObj = theField->GetFather();
562 aSObj = aSObj->GetFather();
563 aSObj = aSObj->GetFather();
564 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObj);
565 if (CORBA::is_nil(anObject)) return NULL;
566 return dynamic_cast<VISU::Result_i*>(VISU::GetServant(anObject).in());
569 //************************************************************************
570 VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (_PTR(SObject) theSObject)
572 VISU::Storable::TRestoringMap aMap;
574 _PTR(GenericAttribute) anAttr;
575 if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
576 _PTR(AttributeComment) aComment (anAttr);
577 std::string aString = aComment->Value();
578 QString strIn (aString.c_str());
579 VISU::Storable::StrToMap(strIn, aMap);
585 //************************************************************************
586 double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp)
588 _PTR(GenericAttribute) anAttr;
589 if (theTimeStamp->FindAttribute(anAttr, "AttributeName")) {
590 _PTR(AttributeName) aName (anAttr);
591 QString aNameString (aName->Value().c_str());
592 int time_len = aNameString.find(',');
594 return aNameString.left(time_len).toDouble();
596 return aNameString.toDouble();
601 //************************************************************************
602 void VISU_TimeAnimation::setSpeed(CORBA::Long theSpeed)
604 mySpeed = (theSpeed<1)? 1 : theSpeed;
607 //************************************************************************
608 int VISU_TimeAnimation::myNBAnimations = 0;
609 QString VISU_TimeAnimation::GenerateName()
611 return VISU::GenerateName("Animation", myNBAnimations++);
614 //************************************************************************
615 std::string GetPresentationComment (VISU::VISUType thePrsType)
618 switch (thePrsType) {
619 case VISU::TSCALARMAP:
620 aPrsCmt = VISU::ScalarMap_i::myComment;
622 case VISU::TISOSURFACE:
623 aPrsCmt = VISU::IsoSurfaces_i::myComment;
625 case VISU::TCUTPLANES:
626 aPrsCmt = VISU::CutPlanes_i::myComment;
629 aPrsCmt = VISU::Plot3D_i::myComment;
631 case VISU::TDEFORMEDSHAPE:
632 aPrsCmt = VISU::DeformedShape_i::myComment;
635 aPrsCmt = VISU::Vectors_i::myComment;
637 case VISU::TSTREAMLINES:
638 aPrsCmt = VISU::StreamLines_i::myComment;
641 aPrsCmt = "Unknown presentation";
647 //************************************************************************
648 SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
650 if (myStudy->GetProperties()->IsLocked())
651 return SALOMEDS::SObject::_nil();
653 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
654 aStudyBuilder->NewCommand(); // There is a transaction
655 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
656 std::string aSComponentEntry = aSComponent->GetID();
659 aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
660 VISU::TANIMATION,myMinVal,myMaxVal);
662 string anEntry = VISU::CreateAttributes(myStudy,aSComponentEntry.c_str(),"","",
663 GenerateName(),"",aComment,true);
664 myAnimEntry = anEntry.c_str();
665 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
667 for (int i = 0; i < getNbFields(); i++) {
668 FieldData& aData = myFieldsLst[i];
670 _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
671 aStudyBuilder->Addreference(newObj, aData.myField);
673 if (aData.myPrs.empty()) {
674 generatePresentations(i);
676 ostringstream strOut;
677 aData.myPrs[0]->ToStream(strOut);
678 string aPrsComment = strOut.str();
679 VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
680 aData.myPrs[0]->GetComment(),"",aPrsComment.c_str(),true);
682 aStudyBuilder->CommitCommand();
684 return VISU::GetSObject(aAnimSObject);
687 //************************************************************************
688 void VISU_TimeAnimation::saveAnimation()
690 if (myStudy->GetProperties()->IsLocked()) return;
691 if (myAnimEntry.isEmpty()) return;
693 _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.latin1());
694 if (!aAnimSObject) return;
696 _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
697 aStudyBuilder->NewCommand(); // There is a transaction
698 _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
699 std::string aSComponentEntry = aSComponent->GetID();
702 aComment.sprintf("myComment=ANIMATION;myType=%d;myMinVal=%g;myMaxVal=%g",
703 VISU::TANIMATION,myMinVal,myMaxVal);
705 _PTR(GenericAttribute) anAttr;
706 anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeComment");
707 _PTR(AttributeComment) aCmnt (anAttr);
708 aCmnt->SetValue(aComment.latin1());
710 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
711 int i = 0, nbf = getNbFields();
712 for (anIter->Init(); anIter->More(); anIter->Next(), i++) {
713 if (i >= nbf) break; // it must not be
714 FieldData& aData = myFieldsLst[i];
716 // Get presentation name and comment
717 if (aData.myPrs.empty()) {
718 generatePresentations(i);
720 ostringstream strOut;
721 aData.myPrs[0]->ToStream(strOut);
722 string aPrsComment = strOut.str();
723 string aPrsNameTxt = aData.myPrs[0]->GetComment();
726 _PTR(SObject) aRefObj = anIter->Value();
727 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
730 if (anPrsIter->More()) {
731 _PTR(SObject) aPrsObj = anPrsIter->Value();
732 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeComment");
733 aCmnt = _PTR(AttributeComment)(anAttr);
734 aCmnt->SetValue(aPrsComment.c_str());
736 anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
737 _PTR(AttributeName) aPrsName (anAttr);
738 aPrsName->SetValue(aPrsNameTxt);
741 VISU::CreateAttributes(myStudy, aRefObj->GetID().c_str(),"","",
742 aPrsNameTxt.c_str(),"",aPrsComment.c_str(),true);
745 aStudyBuilder->CommitCommand();
748 //************************************************************************
749 void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
751 _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
752 restoreFromStudy(aAnimSObject);
755 void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
757 _PTR(SObject) aAnimSObject = theField;
759 VISU::Storable::TRestoringMap aMap;
760 _PTR(GenericAttribute) anAttr;
761 if (!aAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
763 _PTR(AttributeComment) aComment (anAttr);
764 string aComm = aComment->Value();
765 QString strIn (aComm.c_str());
766 VISU::Storable::StrToMap(strIn,aMap);
769 myMinVal = VISU::Storable::FindValue(aMap,"myMinVal",&isExist).toDouble();
770 myMaxVal = VISU::Storable::FindValue(aMap,"myMaxVal",&isExist).toDouble();
772 _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
773 for (anIter->Init(); anIter->More(); anIter->Next()) {
774 _PTR(SObject) aRefObj = anIter->Value();
775 _PTR(SObject) aFieldObj;
776 if (!aRefObj->ReferencedObject(aFieldObj) ) continue;
778 FieldData& aData = getFieldData(getNbFields()-1);
780 // Get Presentation object
781 _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
783 if (!anPrsIter->More()) continue;
784 _PTR(SObject) aPrsObj = anPrsIter->Value();
785 if (!aPrsObj->FindAttribute(anAttr, "AttributeName")) continue;
786 _PTR(AttributeName) aName (anAttr);
787 string aStr = aName->Value();
788 QString strName (aStr.c_str());
790 if (strName == VISU::ScalarMap_i::myComment.c_str())
791 aData.myPrsType = VISU::TSCALARMAP;
792 else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
793 aData.myPrsType = VISU::TISOSURFACE;
794 else if (strName == VISU::CutPlanes_i::myComment.c_str())
795 aData.myPrsType = VISU::TCUTPLANES;
796 else if (strName == VISU::Plot3D_i::myComment.c_str())
797 aData.myPrsType = VISU::TPLOT3D;
798 else if (strName == VISU::DeformedShape_i::myComment.c_str())
799 aData.myPrsType = VISU::TDEFORMEDSHAPE;
800 else if (strName == VISU::Vectors_i::myComment.c_str())
801 aData.myPrsType = VISU::TVECTORS;
802 else if (strName == VISU::StreamLines_i::myComment.c_str())
803 aData.myPrsType = VISU::TSTREAMLINES;
806 generatePresentations(getNbFields()-1);
808 if (!aPrsObj->FindAttribute(anAttr, "AttributeComment")) continue;
809 _PTR(AttributeComment) aPrsComment (anAttr);
810 string aPrsComm = aPrsComment->Value();
811 if (aPrsComm.length() > 0) {
812 QString strPrsIn (aPrsComm.c_str());
813 VISU::Storable::TRestoringMap aPrsMap;
814 VISU::Storable::StrToMap(strPrsIn,aPrsMap);
816 aData.myPrs[0]->Restore(aPrsMap);
818 aData.myPrs[0]->GetOffset(aData.myOffset);
819 for (int i = 1; i < aData.myNbFrames; i++) {
820 //jfa 03.08.2005:aData.myPrs[i]->SameAs(aData.myPrs[0]);
821 aData.myPrs[i]->SameAsParams(aData.myPrs[0]);//jfa 03.08.2005
824 string aStr = aAnimSObject->GetID();
825 myAnimEntry = aStr.c_str();
829 //========================================================================
830 //========================================================================
831 //========================================================================
832 struct TNewAnimationEvent: public SALOME_Event
834 std::string myStudyName;
835 VISU::View3D_ptr myView3D;
837 typedef VISU_TimeAnimation* TResult;
840 TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
841 myStudyName(theStudyName),
842 myView3D(VISU::View3D::_duplicate(theView3D)),
850 SUIT_Session* aSession = SUIT_Session::session();
851 QPtrList<SUIT_Application> anApplications = aSession->applications();
852 QPtrListIterator<SUIT_Application> anIter (anApplications);
853 while (SUIT_Application* anApp = anIter.current()) {
855 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
856 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
857 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
858 if (myStudyName == aCStudy->Name()) {
859 myResult = new VISU_TimeAnimation (aCStudy, myView3D);
869 VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
870 VISU::View3D_ptr theView3D)
872 std::string aStudyName = theStudy->Name();
873 myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
876 VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
881 void VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
883 myAnim->addField(theField);
886 CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
888 return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
889 (myAnim,&VISU_TimeAnimation::generateFrames));
892 void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
894 myAnim->generatePresentations(theFieldNum);
897 void VISU_TimeAnimation_i::clearView()
899 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
900 (myAnim,&VISU_TimeAnimation::clearView));
903 void VISU_TimeAnimation_i::stopAnimation()
905 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
906 (myAnim,&VISU_TimeAnimation::stopAnimation));
909 void VISU_TimeAnimation_i::startAnimation()
911 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
912 (myAnim,&VISU_TimeAnimation::startAnimation));
915 void VISU_TimeAnimation_i::nextFrame()
917 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
918 (myAnim,&VISU_TimeAnimation::nextFrame));
921 void VISU_TimeAnimation_i::prevFrame()
923 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
924 (myAnim,&VISU_TimeAnimation::prevFrame));
927 void VISU_TimeAnimation_i::firstFrame()
929 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
930 (myAnim,&VISU_TimeAnimation::firstFrame));
933 void VISU_TimeAnimation_i::lastFrame()
935 ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
936 (myAnim,&VISU_TimeAnimation::lastFrame));
939 void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
941 ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
942 (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
945 CORBA::Long VISU_TimeAnimation_i::getNbFields()
947 return myAnim->getNbFields();
950 CORBA::Long VISU_TimeAnimation_i::getNbFrames()
952 return myAnim->getNbFrames();
955 CORBA::Boolean VISU_TimeAnimation_i::isRunning()
957 return myAnim->isRunning();
960 CORBA::Long VISU_TimeAnimation_i::getCurrentFrame()
962 return myAnim->getCurrentFrame();
965 VISU::ScalarMap_ptr VISU_TimeAnimation_i::getPresentation
966 (CORBA::Long theField, CORBA::Long theFrame)
968 return myAnim->getPresentation(theField,theFrame);
971 void VISU_TimeAnimation_i::setPresentationType (CORBA::Long theFieldNum,
972 VISU::VISUType theType)
974 myAnim->setPresentationType(theFieldNum,theType);
977 VISU::VISUType VISU_TimeAnimation_i::getPresentationType (CORBA::Long theFieldNum)
979 return myAnim->getPresentationType(theFieldNum);
982 void VISU_TimeAnimation_i::setSpeed(CORBA::Long theSpeed)
984 myAnim->setSpeed(theSpeed);
987 CORBA::Long VISU_TimeAnimation_i::getSpeed()
989 return myAnim->getSpeed();
992 CORBA::Boolean VISU_TimeAnimation_i::isProportional()
994 return myAnim->isProportional();
997 void VISU_TimeAnimation_i::setAnimationRange (CORBA::Double theMin,
998 CORBA::Double theMax)
1000 myAnim->setAnimationRange(theMin,theMax);
1003 CORBA::Double VISU_TimeAnimation_i::getMinRange()
1005 return myAnim->getMinRange();
1008 CORBA::Double VISU_TimeAnimation_i::getMaxRange()
1010 return myAnim->getMaxRange();
1013 CORBA::Boolean VISU_TimeAnimation_i::isRangeDefined()
1015 return myAnim->isRangeDefined();
1018 void VISU_TimeAnimation_i::dumpTo (const char* thePath)
1020 myAnim->dumpTo(thePath);
1023 CORBA::Boolean VISU_TimeAnimation_i::isCycling()
1025 return myAnim->isCycling();
1028 CORBA::Double VISU_TimeAnimation_i::getMinTime()
1030 return myAnim->getMinTime();
1033 CORBA::Double VISU_TimeAnimation_i::getMaxTime()
1035 return myAnim->getMaxTime();
1038 void VISU_TimeAnimation_i::setProportional (CORBA::Boolean theProp)
1040 myAnim->setProportional(theProp);
1043 void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
1045 myAnim->setCycling(theCycle);
1048 SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
1050 return myAnim->publishInStudy();
1053 void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
1055 myAnim->restoreFromStudy(theObj);
1058 CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
1060 return myAnim->isSavedInStudy();
1063 void VISU_TimeAnimation_i::saveAnimation()
1065 myAnim->saveAnimation();