]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix for bug PAL8166 : [IMP] A flag "clean memory after each frame" in visu animation.
authormkr <mkr@opencascade.com>
Mon, 23 Oct 2006 14:18:57 +0000 (14:18 +0000)
committermkr <mkr@opencascade.com>
Mon, 23 Oct 2006 14:18:57 +0000 (14:18 +0000)
idl/VISU_Gen.idl
src/VISUGUI/VisuGUI_TimeAnimation.cxx
src/VISU_I/VISU_TimeAnimation.cxx
src/VISU_I/VISU_TimeAnimation.h

index 6939b00842afb50cfc7ca204dc392a6a6795e409..a0396431e3a0837fd1c16eceeb13cfcf315184d9 100644 (file)
@@ -1321,6 +1321,9 @@ module VISU {
      */
     void setCycling(in boolean theCycle);
 
+    boolean isCleaningMemoryAtEachFrame();
+    void setCleaningMemoryAtEachFrame(in boolean theCycle);
+
     SALOMEDS::SObject publishInStudy();
 
     void saveAnimation();
index 91d6fd39fc44b869568fcf682dc213654a118dc1..85ac8918c337e4daa27d7b22d902659bda2dae51 100644 (file)
@@ -1185,6 +1185,11 @@ VisuGUI_TimeAnimationDlg::VisuGUI_TimeAnimationDlg (VisuGUI* theModule, _PTR(Stu
 
   TopLayout->addMultiCellWidget(aSaveBox, 7, 7, 0, 3);
 
+  QCheckBox* aCleanMemCheck = new QCheckBox("Clean memory at each frame",myPlayFrame);
+  aCleanMemCheck->setChecked(myAnimator->isCleaningMemoryAtEachFrame());
+  connect(aCleanMemCheck, SIGNAL(toggled(bool)), myAnimator, SLOT(setCleaningMemoryAtEachFrameSlot(bool)));
+  TopLayout->addMultiCellWidget(aCleanMemCheck, 8, 8, 0, 3);
+
   aMainLayout->addWidget(myPlayFrame);
 
   // Animation publishing in study
index 92f1ea7d34368bb5f5e81b0c157f85bc62162fbb..c2974eecdde87d84b377393b91a20ab6afa2ff8b 100644 (file)
@@ -102,6 +102,7 @@ VISU_TimeAnimation::VISU_TimeAnimation (_PTR(Study) theStudy,
   myTimeMax = 0;
   myLastError = "";
   myCycling = false;
+  myCleaningMemoryAtEachFrame = false;
 
   myAnimEntry = "";
 
@@ -202,7 +203,6 @@ void VISU_TimeAnimation::clearData(FieldData& theData) {
   myView->update();
 }
 
-
 namespace
 {
   //------------------------------------------------------------------------
@@ -406,7 +406,7 @@ void VISU_TimeAnimation::generatePresentations(CORBA::Long theFieldNum) {
 
 
 //------------------------------------------------------------------------
-CORBA::Boolean VISU_TimeAnimation::generateFrames() {
+CORBA::Boolean VISU_TimeAnimation::_generateFrames() {
   if (!myView) {
     MESSAGE("Viewer is not defined for animation");
     return false;
@@ -445,7 +445,14 @@ CORBA::Boolean VISU_TimeAnimation::generateFrames() {
 }
 
 //------------------------------------------------------------------------
-void VISU_TimeAnimation::clearView() {
+CORBA::Boolean VISU_TimeAnimation::generateFrames()
+{
+  return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
+                      (this,&VISU_TimeAnimation::_generateFrames));
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::_clearView() {
   if (!myView) {
     MESSAGE("Viewer is not defined for animation");
     return;
@@ -466,12 +473,54 @@ void VISU_TimeAnimation::clearView() {
 }
 
 //------------------------------------------------------------------------
-void VISU_TimeAnimation::stopAnimation() {
+void VISU_TimeAnimation::clearView()
+{
+  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+                   (this,&VISU_TimeAnimation::_clearView));
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::visibilityOff(int num_field, int num_frame) {
+  FieldData& aData = myFieldsLst[num_field];
+  VISU_Actor* aActor = aData.myActors[num_frame];
+  if (! myCleaningMemoryAtEachFrame) {
+    //
+    // Usual behaviour : VisibilityOff()
+    // Problem : It don't clean the memory so if there is
+    //           a lot of frames, the memory grows dramatically
+    //
+    aActor->VisibilityOff();
+  } else {
+    //
+    // myCleaningMemoryAtEachFrame behaviour:
+    // Delete the actor and re-creation it with VisibilityOff()
+    // since it takes memory only at VisibilityOn()
+    //
+    // Delete the actor
+    aActor->RemoveFromRender(myView->getRenderer());
+    //aActor->Delete();
+    // Re-create the actor
+    aActor = aData.myPrs[num_frame]->CreateActor();
+    myView->AddActor(aActor);
+    aActor->VisibilityOff();
+    aData.myActors[num_frame] = aActor;
+  }
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::_stopAnimation() {
   myIsActive = false;
 }
 
 //------------------------------------------------------------------------
-void VISU_TimeAnimation::startAnimation() {
+void VISU_TimeAnimation::stopAnimation()
+{
+  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+                   (this,&VISU_TimeAnimation::_stopAnimation));
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::_startAnimation() {
   if (!myIsActive) {
     myIsActive = true;
     QThread::start();
@@ -479,7 +528,15 @@ void VISU_TimeAnimation::startAnimation() {
 }
 
 //------------------------------------------------------------------------
-void VISU_TimeAnimation::nextFrame() {
+void VISU_TimeAnimation::startAnimation()
+{
+  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+                   (this,&VISU_TimeAnimation::_startAnimation));
+}
+
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::_nextFrame() {
   if (!myView) {
     MESSAGE("Viewer is not defined for animation");
     return;
@@ -489,7 +546,8 @@ void VISU_TimeAnimation::nextFrame() {
     int i;
     for (i = 0; i < getNbFields(); i++)
       if (myFieldsLst[i].myActors[myFrame] != 0)
-       myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+       //myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+       visibilityOff(i, myFrame);
 
     myFrame++;
     for (i = 0; i < getNbFields(); i++)
@@ -502,7 +560,14 @@ void VISU_TimeAnimation::nextFrame() {
 }
 
 //------------------------------------------------------------------------
-void VISU_TimeAnimation::prevFrame() {
+void VISU_TimeAnimation::nextFrame()
+{
+  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+                   (this,&VISU_TimeAnimation::_nextFrame));
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::_prevFrame() {
   if (!myView) {
     MESSAGE("Viewer is not defined for animation");
     return;
@@ -512,7 +577,8 @@ void VISU_TimeAnimation::prevFrame() {
     int i;
     for (i = 0; i < getNbFields(); i++)
       if (myFieldsLst[i].myActors[myFrame] != 0)
-       myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+       //myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+       visibilityOff(i, myFrame);
 
     myFrame--;
     for (i = 0; i < getNbFields(); i++)
@@ -525,7 +591,14 @@ void VISU_TimeAnimation::prevFrame() {
 }
 
 //------------------------------------------------------------------------
-void VISU_TimeAnimation::firstFrame() {
+void VISU_TimeAnimation::prevFrame()
+{
+  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+                   (this,&VISU_TimeAnimation::_prevFrame));
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::_firstFrame() {
   if (!myView) {
     MESSAGE("Viewer is not defined for animation");
     return;
@@ -535,7 +608,8 @@ void VISU_TimeAnimation::firstFrame() {
   for (i = 0; i < getNbFields(); i++)
     if(!myFieldsLst[i].myActors.empty())
       if (myFieldsLst[i].myActors[myFrame] != 0)
-       myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+       //myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+       visibilityOff(i, myFrame);
   myFrame = 0;
   for (i = 0; i < getNbFields(); i++)
     if(!myFieldsLst[i].myActors.empty())
@@ -548,7 +622,14 @@ void VISU_TimeAnimation::firstFrame() {
 }
 
 //------------------------------------------------------------------------
-void VISU_TimeAnimation::lastFrame() {
+void VISU_TimeAnimation::firstFrame()
+{
+  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+                   (this,&VISU_TimeAnimation::_firstFrame));
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::_lastFrame() {
   if (!myView) {
     MESSAGE("Viewer is not defined for animation");
     return;
@@ -557,7 +638,8 @@ void VISU_TimeAnimation::lastFrame() {
   int i;
   for (i = 0; i < getNbFields(); i++)
    if (myFieldsLst[i].myActors[myFrame] != 0)
-      myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+     //myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+     visibilityOff(i, myFrame);
 
   myFrame = myFieldsLst[0].myNbFrames-1;
   for (i = 0; i < getNbFields(); i++)
@@ -568,10 +650,17 @@ void VISU_TimeAnimation::lastFrame() {
   myView->Repaint();
 }
 
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::lastFrame()
+{
+  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+                   (this,&VISU_TimeAnimation::_lastFrame));
+}
+
 
 //------------------------------------------------------------------------
 // For Batchmode using
-void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) {
+void VISU_TimeAnimation::_gotoFrame(CORBA::Long theFrame) {
   if (!myView) {
     MESSAGE("Viewer is not defined for animation");
     return;
@@ -579,12 +668,13 @@ void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) {
   if ((theFrame < 0) || (theFrame > (getNbFrames()-1)))
     return;
   stopAnimation();
-  qApp->lock();
-  qApp->syncX();
+  //qApp->lock();
+  //qApp->syncX();
   int i;
   for (i = 0; i < getNbFields(); i++)
     if (myFieldsLst[i].myActors[myFrame] != 0)
-      myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+      //myFieldsLst[i].myActors[myFrame]->VisibilityOff();
+      visibilityOff(i, myFrame);
 
   myFrame = theFrame;
   for (i = 0; i < getNbFields(); i++)
@@ -593,9 +683,16 @@ void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame) {
 
   emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
   myView->Repaint();
-  qApp->flushX();
-  qApp->processEvents(3);
-  qApp->unlock();
+  //qApp->flushX();
+  //qApp->processEvents(3);
+  //qApp->unlock();
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::gotoFrame(CORBA::Long theFrame)
+{
+  ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
+                   (this,&VISU_TimeAnimation::_gotoFrame,theFrame));
 }
 
 
@@ -640,10 +737,12 @@ void VISU_TimeAnimation::run()
       FieldData& aData = myFieldsLst[i];
       if (myFrame > 0) {
        if (aData.myActors[myFrame-1] != 0)
-         aData.myActors[myFrame-1]->VisibilityOff();
+         //aData.myActors[myFrame-1]->VisibilityOff();
+         visibilityOff(i, myFrame-1);
       } else {
        if (aData.myActors[aData.myNbFrames-1] != 0)
-         aData.myActors[aData.myNbFrames-1]->VisibilityOff();
+         //aData.myActors[aData.myNbFrames-1]->VisibilityOff();
+         visibilityOff(i, aData.myNbFrames-1);
       }
       if (aData.myActors[myFrame] != 0) {
        aData.myActors[myFrame]->VisibilityOn();
@@ -675,12 +774,20 @@ void VISU_TimeAnimation::run()
     }
     qApp->unlock();
     msleep(delay);
+    if (!myIsActive) {
+      emit stopped();
+      return;
+    }
     qApp->lock();
 
     if (isDumping) {
       // We must unlock mutex for some time before grabbing to allow view updating
       qApp->unlock();
       msleep(delay);
+      if (!myIsActive) { // this check was taken from WP_DEB branch
+       emit stopped();
+       return;
+      }
       qApp->lock();
       if(!(myFieldsLst[0].myField)) // break, if field was deleted.
        break;
@@ -1183,8 +1290,9 @@ void VISU_TimeAnimation_i::addField (SALOMEDS::SObject_ptr theField)
 
 CORBA::Boolean VISU_TimeAnimation_i::generateFrames()
 {
-  return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
-                      (myAnim,&VISU_TimeAnimation::generateFrames));
+  //return ProcessEvent(new TMemFunEvent<VISU_TimeAnimation,bool>
+  //                    (myAnim,&VISU_TimeAnimation::generateFrames));
+  return myAnim->generateFrames();
 }
 
 void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
@@ -1194,50 +1302,58 @@ void VISU_TimeAnimation_i::generatePresentations (CORBA::Long theFieldNum)
 
 void VISU_TimeAnimation_i::clearView()
 {
-  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
-                   (myAnim,&VISU_TimeAnimation::clearView));
+  //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+  //                 (myAnim,&VISU_TimeAnimation::clearView));
+  myAnim->clearView();
 }
 
 void VISU_TimeAnimation_i::stopAnimation()
 {
-  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
-                   (myAnim,&VISU_TimeAnimation::stopAnimation));
+  //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+  //                 (myAnim,&VISU_TimeAnimation::stopAnimation));
+  myAnim->stopAnimation();
 }
 
 void VISU_TimeAnimation_i::startAnimation()
 {
-  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
-                   (myAnim,&VISU_TimeAnimation::startAnimation));
+  //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+  //                 (myAnim,&VISU_TimeAnimation::startAnimation));
+  myAnim->startAnimation();
 }
 
 void VISU_TimeAnimation_i::nextFrame()
 {
-  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
-                   (myAnim,&VISU_TimeAnimation::nextFrame));
+  //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+  //                 (myAnim,&VISU_TimeAnimation::nextFrame));
+  myAnim->nextFrame();
 }
 
 void VISU_TimeAnimation_i::prevFrame()
 {
-  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
-                   (myAnim,&VISU_TimeAnimation::prevFrame));
+  //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+  //                 (myAnim,&VISU_TimeAnimation::prevFrame));
+  myAnim->prevFrame();
 }
 
 void VISU_TimeAnimation_i::firstFrame()
 {
-  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
-                   (myAnim,&VISU_TimeAnimation::firstFrame));
+  //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+  //                 (myAnim,&VISU_TimeAnimation::firstFrame));
+  myAnim->firstFrame();
 }
 
 void VISU_TimeAnimation_i::lastFrame()
 {
-  ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
-                   (myAnim,&VISU_TimeAnimation::lastFrame));
+  //ProcessVoidEvent(new TVoidMemFunEvent<VISU_TimeAnimation>
+  //                 (myAnim,&VISU_TimeAnimation::lastFrame));
+  myAnim->lastFrame();
 }
 
 void VISU_TimeAnimation_i::gotoFrame(CORBA::Long theFrame)
 {
-  ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
-                   (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
+  //ProcessVoidEvent(new TVoidMemFun1ArgEvent<VISU_TimeAnimation,CORBA::Long>
+  //                 (myAnim,&VISU_TimeAnimation::gotoFrame,theFrame));
+  myAnim->gotoFrame(theFrame);
 }
 
 CORBA::Long VISU_TimeAnimation_i::getNbFields()
@@ -1329,6 +1445,10 @@ CORBA::Boolean VISU_TimeAnimation_i::isCycling()
   return myAnim->isCycling();
 }
 
+CORBA::Boolean VISU_TimeAnimation_i::isCleaningMemoryAtEachFrame(){
+  return myAnim->isCleaningMemoryAtEachFrame();
+}
+
 CORBA::Double VISU_TimeAnimation_i::getMinTime()
 {
   return myAnim->getMinTime();
@@ -1349,6 +1469,10 @@ void VISU_TimeAnimation_i::setCycling (CORBA::Boolean theCycle)
   myAnim->setCycling(theCycle);
 }
 
+void VISU_TimeAnimation_i::setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle){
+  myAnim->setCleaningMemoryAtEachFrame(theCycle);
+}
+
 SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
 {
   return myAnim->publishInStudy();
index d2da49a4c4bcae61918a3aada2dd7ac6534c6c60..22d523698ccb43b8d1954cff15ac67bfed33142c 100644 (file)
@@ -57,6 +57,19 @@ struct FieldData
 class VISU_TimeAnimation: public QObject, public QThread
 {
   Q_OBJECT;
+
+ private:
+  // PAL8166
+  CORBA::Boolean _generateFrames();
+  void _clearView();
+  void _stopAnimation();
+  void _startAnimation();
+  void _nextFrame();
+  void _prevFrame();
+  void _firstFrame();
+  void _lastFrame();
+  void _gotoFrame(CORBA::Long theFrame);
+
  public:
   //static VISU::Result_i* createPresent (SALOMEDS::SObject_var theField);
   //static VISU::Storable::TRestoringMap getMapOfValue (SALOMEDS::SObject_var theSObject);
@@ -84,6 +97,7 @@ class VISU_TimeAnimation: public QObject, public QThread
   void clearData(FieldData& theData);
   void clearFieldData() { myFieldsLst.clear();};
 
+  void visibilityOff(int num_field, int num_frame);
   void stopAnimation();
   void startAnimation();
   void nextFrame();
@@ -123,12 +137,14 @@ class VISU_TimeAnimation: public QObject, public QThread
   QString getLastErrorMsg() { return myLastError; }
 
   CORBA::Boolean isCycling() { return myCycling; }
+  CORBA::Boolean isCleaningMemoryAtEachFrame() { return myCleaningMemoryAtEachFrame; }
 
   CORBA::Double getMinTime() { return myTimeMin;}
   CORBA::Double getMaxTime() { return myTimeMax;}
 
   void setProportional(CORBA::Boolean theProp) { myProportional = theProp; }
   void setCycling(CORBA::Boolean theCycle) { myCycling = theCycle; }
+  void setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle) { myCleaningMemoryAtEachFrame = theCycle; }
 
   SALOMEDS::SObject_ptr publishInStudy();
   void restoreFromStudy(SALOMEDS::SObject_ptr theField);
@@ -139,6 +155,7 @@ class VISU_TimeAnimation: public QObject, public QThread
  public slots:
   void setProportionalSlot(bool theProp) { myProportional = theProp; }
   void setCyclingSlot(bool theCycle) { myCycling = theCycle; }
+  void setCleaningMemoryAtEachFrameSlot(bool theCycle) { myCleaningMemoryAtEachFrame = theCycle; }
 
  signals:
   void frameChanged(long theNewFrame, double theTime);
@@ -160,6 +177,7 @@ class VISU_TimeAnimation: public QObject, public QThread
   int mySpeed;
   bool myProportional;
   bool myCycling;
+  bool myCleaningMemoryAtEachFrame;
   _PTR(Study) myStudy;
 
   double myTimeMinVal, myTimeMaxVal; //!< Range of time stams, set by user
@@ -228,12 +246,14 @@ public:
   virtual char* setDumpFormat(const char* theFormat);
 
   virtual CORBA::Boolean isCycling();
+  virtual CORBA::Boolean isCleaningMemoryAtEachFrame();
 
   virtual CORBA::Double getMinTime();
   virtual CORBA::Double getMaxTime();
 
   virtual void setProportional(CORBA::Boolean theProp);
   virtual void setCycling(CORBA::Boolean theCycle);
+  virtual void setCleaningMemoryAtEachFrame(CORBA::Boolean theCycle);
 
   virtual SALOMEDS::SObject_ptr publishInStudy();
   virtual void restoreFromStudy(SALOMEDS::SObject_ptr theField);