From 72574e108f1d0dc28285712ac444da2c9e80ca8d Mon Sep 17 00:00:00 2001 From: mkr Date: Tue, 21 Nov 2006 14:10:42 +0000 Subject: [PATCH] Fix for IPAL13727 : anim properties accessible via TUI. --- src/VISU_I/VISU_ColoredPrs3d_i.cc | 33 +++-- src/VISU_I/VISU_ColoredPrs3d_i.hh | 5 +- src/VISU_I/VISU_ScalarMap_i.cc | 2 +- src/VISU_I/VISU_TimeAnimation.cxx | 68 ++++++--- src/VISU_SWIG/Makefile.in | 3 +- src/VISU_SWIG/visu_apply_properties.py | 119 +++++++++++++++ .../visu_apply_properties_successive.py | 135 ++++++++++++++++++ 7 files changed, 330 insertions(+), 35 deletions(-) create mode 100644 src/VISU_SWIG/visu_apply_properties.py create mode 100644 src/VISU_SWIG/visu_apply_properties_successive.py diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.cc b/src/VISU_I/VISU_ColoredPrs3d_i.cc index 275d3e2e..ef82e36b 100644 --- a/src/VISU_I/VISU_ColoredPrs3d_i.cc +++ b/src/VISU_I/VISU_ColoredPrs3d_i.cc @@ -104,13 +104,13 @@ VISU::ColoredPrs3d_i DoHook(); ColoredPrs3d_i* anOrigin = const_cast(aPrs3d); - - myField = anOrigin->GetField(); - myMeshName = myField->myMeshName; - myEntity = VISU::TEntity(anOrigin->GetEntity());//myField->myEntity; - myIteration = anOrigin->GetIteration(); - myFieldName = anOrigin->GetFieldName(); - + if(myMeshName == ""){ + myField = anOrigin->GetField(); + myMeshName = myField->myMeshName; + myEntity = VISU::TEntity(anOrigin->GetEntity());//myField->myEntity; + myIteration = anOrigin->GetIteration(); + myFieldName = anOrigin->GetFieldName(); + } Build(-1); TSuperClass::SameAs(theOrigin); @@ -143,12 +143,23 @@ VISU::ColoredPrs3d_i void VISU::ColoredPrs3d_i -::SameAsParams(const ColoredPrs3d_i* theOrigin) +::SameAsParams(const ColoredPrs3d_i* theOrigin, + const std::string& theMeshName, const std::string& theFieldName, + VISU::Entity theEntity, int theIteration, + char* theTitle, bool theIsFixedRange) { - int anIteration = GetIteration(); - SameAs(theOrigin); - myIteration = anIteration; + myMeshName = theMeshName; + myFieldName = theFieldName; + myEntity = (VISU::TEntity)theEntity; + myIteration = theIteration; + myIsFixedRange = theIsFixedRange; + //int anIteration = GetIteration(); + SameAs(theOrigin); + //myIteration = anIteration; + + myTitle = theTitle; + Build(-1); Update(); } diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.hh b/src/VISU_I/VISU_ColoredPrs3d_i.hh index b5417b22..4f59e59f 100644 --- a/src/VISU_I/VISU_ColoredPrs3d_i.hh +++ b/src/VISU_I/VISU_ColoredPrs3d_i.hh @@ -164,7 +164,10 @@ namespace VISU * Is used in VISU_TimeAnimation class implementation. */ void - SameAsParams(const ColoredPrs3d_i* theOrigin); + SameAsParams(const ColoredPrs3d_i* theOrigin, + const std::string& theMeshName, const std::string& theFieldName, + VISU::Entity theEntity, int theIteration, + char* theTitle, bool theIsFixedRange); virtual const VISU::PField& GetField() const; diff --git a/src/VISU_I/VISU_ScalarMap_i.cc b/src/VISU_I/VISU_ScalarMap_i.cc index e56862cf..1b20e9df 100644 --- a/src/VISU_I/VISU_ScalarMap_i.cc +++ b/src/VISU_I/VISU_ScalarMap_i.cc @@ -131,7 +131,7 @@ VISU::ScalarMap_i ScalarMap_i* anOrigin = const_cast(aPrs3d); SetRange(anOrigin->GetMin(), anOrigin->GetMax()); - myIsFixedRange = anOrigin->IsRangeFixed(); + //myIsFixedRange = anOrigin->IsRangeFixed(); SetScaling(anOrigin->GetScaling()); diff --git a/src/VISU_I/VISU_TimeAnimation.cxx b/src/VISU_I/VISU_TimeAnimation.cxx index f751e5f6..697e32b0 100644 --- a/src/VISU_I/VISU_TimeAnimation.cxx +++ b/src/VISU_I/VISU_TimeAnimation.cxx @@ -1621,8 +1621,16 @@ void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField) } aData.myPrs[0]->GetOffset(aData.myOffset); for (int i = 1; i < aData.myNbFrames; i++) { + bool anIsFixedRange = false; + if (aData.myPrsType != VISU::TGAUSSPOINTS) { + if (VISU::ScalarMap_i* aPrs = dynamic_cast(aData.myPrs[i])) + anIsFixedRange = aPrs->IsRangeFixed(); + } //jfa 03.08.2005:aData.myPrs[i]->SameAs(aData.myPrs[0]); - aData.myPrs[i]->SameAsParams(aData.myPrs[0]);//jfa 03.08.2005 + aData.myPrs[i]->SameAsParams(aData.myPrs[0], + aData.myPrs[i]->GetMeshName(),aData.myPrs[i]->GetFieldName(), + aData.myPrs[i]->GetEntity(), aData.myPrs[i]->GetIteration(), + aData.myPrs[i]->GetTitle(), anIsFixedRange);//jfa 03.08.2005 } } string aStr = aAnimSObject->GetID(); @@ -1637,32 +1645,50 @@ void VISU_TimeAnimation::onViewDeleted() void VISU_TimeAnimation::ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs) throw (SALOME::SALOME_Exception) { - FieldData& aData = myFieldsLst[theFieldNum]; - - if ( aData.myPrs.empty() ) - throw SALOME_Exception(LOCALIZED("Error : presentations for the given field is not yet created!")); - VISU::ColoredPrs3d_i* aPrs_i = dynamic_cast(GetServant(thePrs).in()); if ( !aPrs_i ) throw SALOME_Exception(LOCALIZED("Error : invalid dynamic cast of the given presentation to VISU::ColoredPrs3d_i")); - - if ( aPrs_i->GetResult() != aData.myPrs[0]->GetResult() ) - throw SALOME_Exception(LOCALIZED("Error : the MED file is not the same!")); - - if ( aPrs_i->GetMeshName() != aData.myPrs[0]->GetMeshName() ) - throw SALOME_Exception(LOCALIZED("Error : the mesh name is not the same!")); - - if ( aPrs_i->GetFieldName() != aData.myPrs[0]->GetFieldName() ) - throw SALOME_Exception(LOCALIZED("Error : the field name is not the same!")); - - if ( aPrs_i->GetEntity() != aData.myPrs[0]->GetEntity() ) - throw SALOME_Exception(LOCALIZED("Error : the entity is not the same!")); + printf("aPrs_i->GetMeshName() = %s; aPrs_i->GetFieldName() = %s\n",aPrs_i->GetMeshName().c_str(),aPrs_i->GetFieldName().c_str()); - for (int i = 0; i < aData.myNbFrames; i++) { - aData.myPrs[i]->SameAsParams(aPrs_i); + if ( myAnimationMode == 0 ) { // parallel animation mode + FieldData& aData = myFieldsLst[theFieldNum]; + + if ( aData.myPrs.empty() ) + throw SALOME_Exception(LOCALIZED("Error : presentations for the given field is not yet created!")); + + if ( aPrs_i->GetResult() != aData.myPrs[0]->GetResult() ) + throw SALOME_Exception(LOCALIZED("Error : the MED file is not the same!")); + + for (int i = 0; i < aData.myNbFrames; i++) { + bool anIsFixedRange = false; + if (aData.myPrsType != VISU::TGAUSSPOINTS) { + if (VISU::ScalarMap_i* aPrs = dynamic_cast(aData.myPrs[i])) + anIsFixedRange = aPrs->IsRangeFixed(); + } + aData.myPrs[i]->SameAsParams(aPrs_i, + aData.myPrs[i]->GetMeshName(),aData.myPrs[i]->GetFieldName(), + aData.myPrs[i]->GetEntity(), aData.myPrs[i]->GetIteration(), + aData.myPrs[i]->GetTitle(), anIsFixedRange); + } + } + else if ( myAnimationMode == 1 ) { // successive animation mode + for (int f = 0; f < getNbFields(); f++) { + FieldData& aData = myFieldsLst[f]; + + if ( aData.myPrs.empty() ) + throw SALOME_Exception(LOCALIZED("Error : presentations for the given field is not yet created!")); + + for (int i = 0; i < aData.myNbFrames; i++) { + printf("aData.myPrs[%d]->GetMeshName() = %s; aData.myPrs[%d]->GetFieldName() = %s\n", + i,aData.myPrs[i]->GetMeshName().c_str(),i,aData.myPrs[i]->GetFieldName().c_str()); + aData.myPrs[i]->SameAsParams(aPrs_i, + aData.myPrs[i]->GetMeshName(),aData.myPrs[i]->GetFieldName(), + aData.myPrs[i]->GetEntity(), aData.myPrs[i]->GetIteration(), + aData.myPrs[i]->GetTitle(), true); + } + } } - } //======================================================================== diff --git a/src/VISU_SWIG/Makefile.in b/src/VISU_SWIG/Makefile.in index b654db9e..0d032d14 100644 --- a/src/VISU_SWIG/Makefile.in +++ b/src/VISU_SWIG/Makefile.in @@ -42,7 +42,8 @@ SWIG_DEF = libVISU_Swig.i EXPORT_PYSCRIPTS = libVISU_Swig.py batchmode_visu.py batchmode_visu_table.py batchmode_visu_view3d.py \ visu_med.py visu_view3d.py visu.py visu_gui.py visu_prs_example.py \ visu_table.py visu_big_table.py visu_view.py visu_delete.py \ - visu_swig_test.py visu_split_views.py visu_succcessive_animation.py \ + visu_swig_test.py visu_split_views.py \ + visu_succcessive_animation.py visu_apply_properties.py visu_apply_properties_successive.py \ VISU_Example_01.py VISU_Example_02.py VISU_Example_03.py VISU_Example_04.py \ VISU_Example_05.py VISU_Example_06.py VISU_Example_07.py EXPORT_SHAREDPYSCRIPTS = VISU_shared_modules.py diff --git a/src/VISU_SWIG/visu_apply_properties.py b/src/VISU_SWIG/visu_apply_properties.py new file mode 100644 index 00000000..cdf8b6f6 --- /dev/null +++ b/src/VISU_SWIG/visu_apply_properties.py @@ -0,0 +1,119 @@ +# VISU VISU_SWIG : binding of C++ implementation and Python +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# File : visu_apply_properties.py +# Module : VISU + +import os +import time +import math +import VISU +import SALOMEDS +from visu_gui import * + +aDelay = 0 + +myViewManager = myVisu.GetViewManager(); + +myView = myViewManager.Create3DView(); +myView.SetTitle("The viewer for Animation") +print "myViewManager.Create3DView()" +time.sleep(aDelay) + +medFile = "TimeStamps.med" +myFieldName = "temperature" + +medFile = os.getenv('DATA_DIR') + '/MedFiles/' + medFile +myResult = myVisu.ImportFile(medFile) + +anAnim = myVisu.CreateAnimation(myView); + +aSObj = myStudy.FindObjectIOR(myResult.GetID()) +aSObj = aSObj.FindSubObject(1)[1] +aSObj = aSObj.FindSubObject(3)[1] +aSObj = aSObj.FindSubObject(1)[1] +print "addField 1 : ", anAnim.addField(aSObj) + +print "Generate presentations for ", anAnim.getNbFields(), " fields" +for i in range(0,anAnim.getNbFields()): + anAnim.setPresentationType(i,VISU.TPLOT3D) + anAnim.generatePresentations(i) + +print "Generate frames" +anAnim.generateFrames() + +print "Start Animation" +anAnim.setSpeed(22) +anAnim.startAnimation() +myView.FitAll() + +while 1: + time.sleep(1+aDelay) + if not anAnim.isRunning(): + anAnim.stopAnimation() + break + +anAnim.publishInStudy() +anAnim.saveAnimation() + +for i in range(0,anAnim.getNbFields()): + aPrs = anAnim.getPresentation(i,0) + aPlot3D = aPrs._narrow(VISU.Plot3D) + + if aPlot3D: + aNbLabels = aPlot3D.GetLabels() + aPlot3D.SetLabels(aNbLabels+3) + + aWidth = aPlot3D.GetWidth() + aHeight = aPlot3D.GetHeight() + aPlot3D.SetSize(aWidth+0.07,aHeight+0.07) + + print "Apply properties for all time stamps of ", i, " field." + try: + anAnim.ApplyProperties(i,aPlot3D) + except SALOME.SALOME_Exception, inst: + msg = "SALOME.SALOME_Exception caught, see details:" + msg+="\n******* text:\t" + inst.details.text + msg+="\n******* type:\t" + str(inst.details.type) + msg+="\n******* where:\t" + inst.details.sourceFile + ":" + \ + str(inst.details.lineNumber) + print msg + raise RuntimeError, "There are some errors were occured... For more info see ERRORs above..." + +print "Generate frames" +anAnim.generateFrames() + +print "Start Animation" +anAnim.startAnimation() +myView.FitAll() + +while 1: + time.sleep(1+aDelay) + if not anAnim.isRunning(): + anAnim.stopAnimation() + break + +anAnim.publishInStudy() +anAnim.saveAnimation() + +anAnim.clearFields() +print "The number of fields in animation after clearFields method is", anAnim.getNbFields() + diff --git a/src/VISU_SWIG/visu_apply_properties_successive.py b/src/VISU_SWIG/visu_apply_properties_successive.py new file mode 100644 index 00000000..b1f931a0 --- /dev/null +++ b/src/VISU_SWIG/visu_apply_properties_successive.py @@ -0,0 +1,135 @@ +# VISU VISU_SWIG : binding of C++ implementation and Python +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# File : visu_apply_properties_consecutive.py +# Module : VISU + +import os +import time +import math +import VISU +import SALOMEDS +from visu_gui import * + +aDelay = 0 + +myViewManager = myVisu.GetViewManager(); + +myView = myViewManager.Create3DView(); +myView.SetTitle("The viewer for Animation") +print "myViewManager.Create3DView()" +time.sleep(aDelay) + +medFile = "TimeStamps.med" +myFieldName = "temperature" + +medFile = os.getenv('DATA_DIR') + '/MedFiles/' + medFile +myResult = myVisu.ImportFile(medFile) + +anAnim = myVisu.CreateAnimation(myView); +anAnim.setAnimationMode(VISU.Animation.SUCCCESSIVE) + +aSObj = myStudy.FindObjectIOR(myResult.GetID()) +aSObj = aSObj.FindSubObject(1)[1] +aSObj = aSObj.FindSubObject(3)[1] +aSObj = aSObj.FindSubObject(1)[1] +print "addField 1 : ", anAnim.addField(aSObj) + +medFile1 = "TimeStamps_import22.med" +myFieldName1 = "pression" + +medFile1 = os.getenv('DATA_DIR') + '/MedFiles/' + medFile1 +myResult1 = myVisu.ImportFile(medFile1) + +aSObj1 = myStudy.FindObjectIOR(myResult1.GetID()) +aSObj1 = aSObj1.FindSubObject(1)[1] +aSObj1 = aSObj1.FindSubObject(3)[1] +aSObj1 = aSObj1.FindSubObject(3)[1] +print "addField 2 : ", anAnim.addField(aSObj1) + +print "Generate presentations for ", anAnim.getNbFields(), " fields" +for i in range(0,anAnim.getNbFields()): + anAnim.setPresentationType(i,VISU.TPLOT3D) + anAnim.generatePresentations(i) + +print "Generate frames" +anAnim.generateFrames() + +print "Start Animation" +anAnim.setSpeed(22) +anAnim.startAnimation() +myView.FitAll() + +while 1: + time.sleep(1+aDelay) + if not anAnim.isRunning(): + anAnim.stopAnimation() + break + +anAnim.publishInStudy() +anAnim.saveAnimation() + +if anAnim.getAnimationMode() == VISU.Animation.SUCCCESSIVE: + print "End of succcessive animation for 2 fields with presentation type VISU.Animation.SUCCCESSIVE" + +#for i in range(0,anAnim.getNbFields()): +aPrs = anAnim.getPresentation(0,0) +aPlot3D = aPrs._narrow(VISU.Plot3D) + +if aPlot3D: + aNbLabels = aPlot3D.GetLabels() + aPlot3D.SetLabels(aNbLabels+3) + + aWidth = aPlot3D.GetWidth() + aHeight = aPlot3D.GetHeight() + aPlot3D.SetSize(aWidth+0.07,aHeight+0.07) + + print "Apply properties for all time stamps of all fields." + try: + anAnim.ApplyProperties(0,aPlot3D) + except SALOME.SALOME_Exception, inst: + msg = "SALOME.SALOME_Exception caught, see details:" + msg+="\n******* text:\t" + inst.details.text + msg+="\n******* type:\t" + str(inst.details.type) + msg+="\n******* where:\t" + inst.details.sourceFile + ":" + \ + str(inst.details.lineNumber) + print msg + raise RuntimeError, "There are some errors were occured... For more info see ERRORs above..." + +print "Generate frames" +anAnim.generateFrames() + +print "Start Animation" +anAnim.startAnimation() +myView.FitAll() + +while 1: + time.sleep(1+aDelay) + if not anAnim.isRunning(): + anAnim.stopAnimation() + break + +anAnim.publishInStudy() +anAnim.saveAnimation() + +anAnim.clearFields() +print "The number of fields in animation after clearFields method is", anAnim.getNbFields() + -- 2.39.2