From 17c15f9bda88125085e2ebaa737fc66069beac3a Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Tue, 7 Apr 2015 22:12:07 +0200 Subject: [PATCH] Completing documentation for TUI script entries --- doc/fr/tui.rst | 13 +++++++++---- src/daSalome/adaoBuilder.py | 35 +++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/doc/fr/tui.rst b/doc/fr/tui.rst index 688069b..55fa8a5 100644 --- a/doc/fr/tui.rst +++ b/doc/fr/tui.rst @@ -438,12 +438,15 @@ Param .. index:: single: setAlgorithmParameters -**setAlgorithmParameters** (*Algorithm, Parameters*) +**setAlgorithmParameters** (*Algorithm, Parameters, Script*) Cette commande permet de choisir l'algorithme de calcul ou de vérification par l'argument "*Algorithm*" sous la forme d'un nom d'algorithme (on se reportera utilement aux listes des :ref:`section_reference_assimilation` et des :ref:`section_reference_checking`), et de définir les paramètres de - calcul par l'argument "*Parameters*". + calcul par l'argument "*Parameters*". Dans le cas d'une définition par + "*Script*", le fichier indiqué doit contenir les deux variables + "*Algorithm*" et "*Parameters*" (ou "*AlgorithmParameters*" de manière + équivalente). .. index:: single: setDebug @@ -459,7 +462,7 @@ Param .. index:: single: setObserver -**setObserver** (*Variable, Template, String, Info*) +**setObserver** (*Variable, Template, String, Script, Info*) Cette commande permet de définir un observer sur une variable courante ou finale du calcul. On se reportera à la description de la manière d':ref:`section_advanced_observer`, et à la :ref:`section_reference` pour @@ -470,7 +473,9 @@ Param "*ValuePrinter*", "*ValueSeriePrinter*", "*ValueSaver*", "*ValueSerieSaver*", "*ValuePrinterAndSaver*", "*ValueSeriePrinterAndSaver*", "*ValueGnuPlotter*", - "*ValueSerieGnuPlotter*". + "*ValueSerieGnuPlotter*". Dans le cas d'une définition par "*Script*", le + fichier indiqué doit contenir uniquement le corps de la fonction, comme + décrit dans la manière d':ref:`section_advanced_observer`. Effectuer le calcul +++++++++++++++++++ diff --git a/src/daSalome/adaoBuilder.py b/src/daSalome/adaoBuilder.py index 8ac7727..abbb130 100644 --- a/src/daSalome/adaoBuilder.py +++ b/src/daSalome/adaoBuilder.py @@ -88,13 +88,13 @@ class New(object): self.setObservationOperator(Matrix,OneFunction,ThreeFunctions, Parameters,Script,Stored) elif Concept == "AlgorithmParameters": - self.setAlgorithmParameters(Algorithm,Parameters) + self.setAlgorithmParameters(Algorithm,Parameters,Script) elif Concept == "Debug": self.setDebug() elif Concept == "NoDebug": self.setNoDebug() elif Concept == "Observer": - self.setObserver(Variable,Template,String,Info) + self.setObserver(Variable,Template,String,Script,Info) else: raise ValueError("the variable named '%s' is not allowed."%str(Concept)) except Exception as e: @@ -208,7 +208,6 @@ class New(object): "Adjoint":_ImportFromScript(Script).getvalue( "AdjointOperator" ), } __Function.update(__Parameters) - else: __Matrix = Matrix if OneFunction is not None: @@ -317,7 +316,6 @@ class New(object): "Adjoint":_ImportFromScript(Script).getvalue( "AdjointOperator" ), } __Function.update(__Parameters) - else: __Matrix = Matrix if OneFunction is not None: @@ -426,7 +424,6 @@ class New(object): "Adjoint":_ImportFromScript(Script).getvalue( "AdjointOperator" ), } __Function.update(__Parameters) - else: __Matrix = Matrix if OneFunction is not None: @@ -455,11 +452,18 @@ class New(object): def setAlgorithmParameters( self, Algorithm = None, - Parameters = None): + Parameters = None, + Script = None): "Définition d'un paramétrage du calcul" self.__dumper.register("setAlgorithmParameters", dir(), locals()) - self.__adaoStudy.setAlgorithm( choice = Algorithm ) - self.__adaoStudy.setAlgorithmParameters( asDico = Parameters ) + if Script is not None: + __Algorithm = _ImportFromScript(Script).getvalue( "Algorithm" ) + __Parameters = _ImportFromScript(Script).getvalue( "AlgorithmParameters", "Parameters" ) + else: + __Algorithm = Algorithm + __Parameters = Parameters + self.__adaoStudy.setAlgorithm( choice = __Algorithm ) + self.__adaoStudy.setAlgorithmParameters( asDico = __Parameters ) def setDebug(self): "Définition d'un paramétrage du calcul" @@ -476,6 +480,7 @@ class New(object): Variable = None, Template = None, String = None, + Script = None, Info = None): "Définition d'un paramétrage du calcul" self.__dumper.register("setObserver", dir(), locals()) @@ -507,6 +512,8 @@ class New(object): __FunctionText = r"import Gnuplot\nglobal ifig,gp\ntry:\n ifig += 1\n gp('set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( var[-1], with_='lines lw 2' ) )" if Template == "ValueSerieGnuPlotter": __FunctionText = r"import Gnuplot\nglobal ifig,gp\ntry:\n ifig += 1\n gp('set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( var[:], with_='lines lw 2' ) )" + elif Script is not None: + __FunctionText = _ImportFromScript(Script).getstring() else: __FunctionText = "" __Function = _ObserverF(__FunctionText) @@ -618,14 +625,22 @@ class _ImportFromScript(object): if not os.path.isfile(str(__filename)+".py"): raise ValueError("The file containing the variable to be imported doesn't seem to exist. The given file name is:\n \"%s\""%__filename) self.__scriptfile = __import__(__filename, globals(), locals(), []) - def getvalue(self, __varname=None ): + self.__scriptstring = open(__filename+".py",'r').read() + def getvalue(self, __varname=None, __synonym=None ): "Renvoie la variable demandee" if __varname is None: raise ValueError("The name of the variable to be imported has to be specified.") if not hasattr(self.__scriptfile, __varname): - raise ValueError("The imported script file doesn't contain the specified variable \"%s\"."%__varname) + if __synonym is None: + raise ValueError("The imported script file doesn't contain the specified variable \"%s\"."%__varname) + elif not hasattr(self.__scriptfile, __synonym): + raise ValueError("The imported script file doesn't contain the specified variable \"%s\"."%__synonym) + else: + return getattr(self.__scriptfile, __synonym) else: return getattr(self.__scriptfile, __varname) + def getstring(self): + return self.__scriptstring # ============================================================================== if __name__ == "__main__": -- 2.39.2