This file is indexed.

/usr/lib/aster/Stanley/salomeVisuPylo.py is in code-aster 11.5.0+dfsg2-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# coding=utf-8
#            CONFIGURATION MANAGEMENT OF EDF VERSION
# ======================================================================
# COPYRIGHT (C) 1991 - 2012  EDF R&D                  WWW.CODE-ASTER.ORG
# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
# (AT YOUR OPTION) ANY LATER VERSION.
#
# THIS PROGRAM 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
# GENERAL PUBLIC LICENSE FOR MORE DETAILS.
#
# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
#    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
# ======================================================================

debug = False

import os, commands, string, sys, socket, getpass
from Utilitai.Utmess import UTMESS
from pylotage.TOOLS import *
from graphiqueTk import *
import cata_champs
cata = cata_champs.CATA_CHAMPS()


# Type de visualisation
ScalarMap           = 'ScalarMap'
DeformedShape       = 'DeformedShape'
IsoSurfaces         = 'IsoSurfaces'
CutPlanes           = 'CutPlanes'
Plot2D              = 'Plot2D'
GaussPointsOnField  = 'GaussPointsOnField'


# =========================================================================

class VISU:
    def __init__( self,  param ) :
        """
        param : dictionnaire pouvant contenir( optionnel ):
        machine_salome      : nom de la machine Salome dans laquelle on souhaite faire la VISU
        machine_salome_port : port du NS Salome

        remarque :
        le service NS Salome est deduit des 2 paramètres ci-dessus.
        le service NS Salome peut egalement etre specifie dans les arguments de la ligne de commande ( ORBInitRef )

        """
        self.param         = param              # parametres Stanley
        self.salomeParam   = ''                 # parametre SALOME pour composant de pylotage
        self.studyName     = None               # nom de l'etude SALOME dans laquelle on fait la visualisation

        # Construction paramètre pour SALOME
        self.salomeParam = self.__salomeParam( param )

        if not self.salomeParam:
            raise _("Erreur VISU Salome")

        # selection de l'étude SALOME ( parmi celles ouvertes )
        try:
           studyList = self.__studyList( self.salomeParam )
        except:
           UTMESS('A','STANLEY_14')
           return

        if studyList:
            if len( studyList ) == 1:   # une seule etude -> on publie ds celle-ci
                self.studyName = studyList[0]
            else:                               # plusieurs études -> l'utilisateur doit en sélectionner une
                self.studyName = SAISIE_MODE( studyList, _("Choix de l'etude SALOME pour visualisation"), vbar=1 )

        if self.studyName:
            self.salomeParam['studyName']  = self.studyName


    def __salomeParam( self, param ):
        """
        Construit les paramètres salome à partir des paramètres Stanley
        retourne {} si incorrect
        """
        result = {}
        try:
            if param['mode']   == 'LOCAL':
               lst = ['tmp']
               try:
                  amachineName = param[ 'machine_salome' ]
               except:
                  UTMESS('A','STANLEY_15')
                  return {}

               result[ 'machineName']  = amachineName
            elif param['mode'] == 'DISTANT':
               lst = ['machine_salome', 'tmp']
               key = 'machine_salome'
               amachineName = param[ key ]
               result[ 'machineName']  = amachineName
            else:
                raise _("Erreur MODE non implémenté, choix possible : LOCAL, DISTANT")

            # Verifications
            for var in lst:
                if not param[var].strip():
                    UTMESS('A','STANLEY_16', valk=[var])
                    return {}

            # Construction du paramètre 'ORBInitRef'
            key = 'machine_salome_port'
            nsPort = param[ key ]
            if not nsPort:
                UTMESS('A','STANLEY_17')
                return {}
            aORBInitRef     = 'NameService=corbaname::%s:%s' %(  amachineName, nsPort  )
            result[ 'ORBInitRef' ]  = aORBInitRef

        except KeyError:
            UTMESS('A','STANLEY_16',valk=[key])
            return {}
        except:
            return {}

        return result

    def __studyList( self, salomeParam ):
        """
        Retourne la liste des études
        """
        result = []
        stdyMnger = Study.StudyManager( **salomeParam)
        result = stdyMnger.getOpenStudies()

        if not result:
            study = stdyMnger.getOrCreateStudy('Stanley')
            if study:
                result = ['Stanley']
        return result

    def Terminal_ouvert(self) :
        """
            Retourne 1 si le terminal est ouvert, 0 sinon
        """
        return 0

    def Fermer(self) :
        """
            Ferme le terminal (si necessaire)
            Fais le menage dans l'objet
        """
        pass

    def Show( self ) :
        """
        Lance la visualisation dans SALOME
        """
        raise NotImplementedError("Non implémentée")


# =========================================================================

class ISOVALEURS( VISU ):
    def __init__( self, fichier, param,  selection ) :
        if not os.path.exists( fichier ):
            raise _("Fichier MED résultat de Stanley non accessible par SALOME : ") + fichier

        VISU .__init__( self,  param )

        # Si on n'a pas trouvé de session Salome ouverte on sort
        if not self.studyName: return

##        print 'CS_pbruno ISOVALEURS salomeParam ->',self.salomeParam
        self.fichier       = os.path.abspath( fichier )         #chemin absolu du fichier MED fourni par Stanley
        self.visuType      = None                               #type de visualisation
        self.entityType    = None                               #type d'entité
        self.selection     = selection

        # selon mode recopie sur le poste utilisateur de fichiers si nécessaire
        if   self.param['mode'] == 'LOCAL' :
                self.__init_local( )
        elif self.param['mode'] == 'DISTANT' :
                self.__init_distant( )
        elif self.param['mode'] == 'WINDOWS' :
                self.__init_windows( )
        else:
                raise _("Erreur MODE non implémenté, choix possible : LOCAL, DISTANT, WINDOWS")

        # parsing fichier MED( nom maillage + nom champ + nb iteration )
        self.medInfo = MEDInfo( selection )
        self.medInfo.iteration = 1 # CS_pbruno à finir implémenter ( on affiche que le 1er instant )

        if not self.medInfo.name or not self.medInfo.fieldName or not self.medInfo.iteration:
            raise 'Erreur lecture fichier MED : %s \n Nom maillage : %s, Nom champs %s '%( self.fichier,  self.medInfo.name, self.medInfo.fieldName )

        # selection d'un type de visualisation ( parmi celles possibles )
        self.visuType = self.__visuType( self.selection )

        # sur quel entité ( VISU.NODE, VISU.EDGE, VISU.FACE,  VISU.CELL )
        self.entityType = self.__entityType( self.selection )

        # et enfin la visualisation..
        self.Show()


    def __init_local( self ):
        """
        Stanley fonctionne sur le poste local de l'utilisateur
        """
        try:    os.rename( self.fichier, self.fichier  + '.pos' )
        except: pass
        self.fichier += '.pos'



    def __init_distant( self ):
        """
        Stanley fonctionne sur une machine distante de l'utilisateur.
        Il faut rapatrier le fichier sur la machine contenant salome.
        """
        result = False
        fichier = os.path.basename( self.fichier )

        mdis        = self.param['machine_salome']                                   # machine
        fdis        = self.param['tmp'] + '/' + fichier + '.pos'                     # /tmp/fort.33.pos
        fmdis       = self.param['machine_salome_login'] + '@' + mdis + ":" + fdis   # user@machine:/tmp/fort.33.pos

        # Protocole de recopie et d'execution distante
        copie     = self.param['protocole'].split('/')[0]                            # rcp ou scp

        # Copie du fichier
        cmd = copie + " " + fichier + " " + fmdis
        UTMESS('I','STANLEY_9',valk=[cmd])
        code, output = commands.getstatusoutput( cmd )
        if code!=0:
            raise _("Erreur exécution commande : ") + cmd

        self.fichier = fdis


    def __init_windows( self ):
        """
        mode WINDOWS
        """
        UTMESS('A','STANLEY_18')
        raise _("Arret sur erreur")


    def __entityType( self, selection ):
        """
        Visu.NODE, Visu.EDGE, Visu.FACE,  Visu.CELL
        """
        result = None
        type_champ = cata[selection.nom_cham].type

        if type_champ == 'ELGA' or type_champ == 'ELNO' or type_champ == 'ELEM':
            result = Visu.CELL
        elif type_champ == 'NOEU':
            result = Visu.NODE
        else:
            raise _("type de champs non reconnu")
        return result


    def __visuType( self, selection):
        """
        selection du type de visualisation selon le nom du champ de la selection donnée en paramètre
        ScalarMap
        DeformedShape
        """
        nom_champ = cata[selection.nom_cham].nom
        nom_type  = cata[selection.nom_cham].type

        if nom_champ == 'DEPL' and selection.nom_cmp[0] == 'TOUT_CMP':
            result = DeformedShape
        elif nom_type == 'ELGA':
            result = GaussPointsOnField
        else:
            result = ScalarMap
        #result = [ ScalarMap, DeformedShape, IsoSurfaces, CutPlanes,  Plot2D]
        return result

    def Show( self ) :
        """
        Lance la visualisation dans SALOME
        """
        self.__Show( self.fichier, self.medInfo, self.entityType, self.visuType, self.salomeParam )


    def __Show( self, medFilePath, medInfo, entity, visuType, salomeParam ) :
        """
        Lecture d'un fichier MED par le composant VISU de SALOME.

        @type     medFilePath : string
        @param  medFilePath:  chemin du fichier MED. Le chemin medFileName doit etre sur la meme machine que le composant VISU

        @type     medInfo:  class
        @param  medInfo:  informations sur le fichier MED ( meshName, fieldName, iteration )

        @type     entity: object ?
        @param  entity:  type d'entité

        @type     visuType :     integer
        @param  visuType:      type de visualisation

        @type     salomeParam:  dictionary.
        @param  salomeParam:  parametre Salome pour initialistion composant VISU de pylotage
        """

        try:
          salomeVisu = Visu.Visu( **salomeParam )
        except Exception, e:
          UTMESS('A','STANLEY_19',valk=[salomeParam['machineName']])
          raise _("Erreur lors de la visualisation.\n\nParametres Salome :%s\n\nErreur :\n%s\n\n") % (salomeParam, e)


        ok = salomeVisu.readMED( medFilePath, medInfo.name, entity )
        if not ok:
            raise _("Erreur lecture fichier MED :") + medFilePath

        # title: nom du champ
        title = cata[self.selection.nom_cham].nom

        if visuType == ScalarMap: # CS_pbruno :attention par defaut on trace le module du champs
            ok = salomeVisu.ScalarMap( medInfo.fieldName, medInfo.iteration, title)
        elif visuType== DeformedShape:
            ok = salomeVisu.DeformedShape( medInfo.fieldName, medInfo.iteration, title)
        elif visuType== IsoSurfaces:
            ok = salomeVisu.IsoSurfaces( medInfo.fieldName, medInfo.iteration, title)
        elif visuType== CutPlanes:
            planePositions =[-14.97,-10, -5.6, -4.8, -4,-3.2,-2.4,-1.6,-0.8, 0.0]
            ok = salomeVisu.DisplayCutPlanes( medInfo.fieldName, medInfo.iteration,  title, Visu.XY, 0.,0., planePositions )
        elif visuType== GaussPointsOnField:
            ok = salomeVisu.GaussPointsOnField( medInfo.fieldName, medInfo.iteration, title)
        else:
            raise _("Erreur type de visualisation non supporté")

        if not ok:
            raise _("Erreur visualisation dans SALOME")

        UTMESS('I','STANLEY_20')


# =========================================================================

class COURBES( VISU ):
    def __init__( self,  l_courbes, param, selection ):

        VISU .__init__( self, param)

        # Si on n'a pas trouvé de session Salome ouverte on sort
        if not self.studyName: return

        self.tables     = {}
        self.l_courbes  = l_courbes
        self.selection  = selection

        # selon mode recopie sur le poste utilisateur de fichiers si nécessaire
        if   self.param['mode'] == 'LOCAL' :
                self.__init_local( )
        elif self.param['mode'] == 'DISTANT' :
                self.__init_distant( )
        elif self.param['mode'] == 'WINDOWS' :
                self.__init_windows( )
        else:
                raise _("Erreur MODE non implémenté, choix possible : LOCAL, DISTANT, WINDOWS")

        self.Show()

    def __init_local( self ):
        """
        Stanley fonctionne sur le poste local de l'utilisateur
        """
        pass


    def __init_distant( self ):
        """
        Stanley fonctionne sur une machine distante de l'utilisateur.
        Il faut rapatrier le fichier sur la machine contenant salome.
        """
        pass


    def __init_windows( self ):
        """
        mode WINDOWS
        """
        UTMESS('A','STANLEY_18')
        raise _("Arret sur erreur")


    def __writeSalomeTables( self, l_courbes, selection ):
        """
        """
        result =   {}
        tabList = {}

        try:

            for courbe in l_courbes:
                composantName   = courbe[1].split('---')[0].strip()
                if selection.geom[0] == 'POINT' :
                    ordre = 1
                elif selection.geom[0] == 'CHEMIN' :
                    ordre = courbe[1].split('=')[1].strip()

                if not tabList.has_key(  composantName ):
                    tabList[ composantName ] = []  # un tableau par composante
                tabList[ composantName ].insert( int(float(ordre)), str( courbe[0] ))

            for composantName, liste  in tabList.items():
                data            = ""
                theTableName    = "table Stanley"

                newListe =map( string.split, liste )

                m = [[newListe[0][i]] + [newListe[j][i+1] for j in range(len(newListe))] for i in range(0, len(newListe[0]), 2)]

                if selection.geom[0] == 'POINT' :
                    theTableName +='_%s_%s_sur_%s'%( selection.nom_cham,  composantName , selection.nom_va )
                elif selection.geom[0] == 'CHEMIN' :
                    theTableName +='_%s_%s_sur_%s'%( selection.nom_cham,  composantName, 'ABSC_CURV ' + selection.geom[1][0])

                theTableName += ' '+selection.nom_va+' : ' + str( selection.vale_va )

                prefix  = '#TITLE: ' + theTableName + os.linesep
                data += prefix

                for a in m :
                    for b in a :
                        data+=b+" "
                    data+=os.linesep
                theTxtFilePathName = os.path.join( '/tmp',  composantName )
                if os.path.exists( theTxtFilePathName):
                    os.remove( theTxtFilePathName )
                f = open( theTxtFilePathName,'w')
                f.write( data )
                f.close()
                result [ theTableName ]  = theTxtFilePathName

        except:
            msg = str(sys.exc_info()[0]) +  str(sys.exc_info()[1]) + str(sys.exc_info()[2])
            raise _("Erreur construction table de valeur pour visualisation 2D SALOME") + msg


        return result


    def __Show( self, tables, salomeParam ) :
        """
        Lecture d'un fichier MED par le composant VISU de SALOME.

        @type   tables: dictionary
        @param  tables: dictionnaire key= nom de la table, value = chemin du fichier text contenant la table

        @type     salomeParam:  dictionary.
        @param  salomeParam:  parametre Salome pour initialistion composant VISU de pylotage
        """
        salomeVisu = Visu.Visu(  **salomeParam )

        if self.selection.geom[0] == 'POINT' :
            tableTitle ='_%s_%s_sur_%s'%( self.selection.nom_cham, self.selection.nom_cmp, self.selection.nom_va )
        elif self.selection.geom[0] == 'CHEMIN' :
            tableTitle ='_%s_%s_sur_%s'%( self.selection.nom_cham, self.selection.nom_cmp, 'ABSC_CURV ' + self.selection.geom[1][0])
        tableTitle += ' '+self.selection.nom_va+' : ' + str( self.selection.vale_va )
        ok = salomeVisu.XYPlot2( self.l_courbes, tableTitle )
        if not ok:
            raise 'erreur visualisation PLOT2D dans SALOME'



    def Show( self ) :
        """
        Lance la visualisation dans SALOME
        """
        self.__Show( self.tables, self.salomeParam )


# =========================================================================

class MEDInfo:
    """
    """
    def __init__( self, selection ):
        """
        Recupère les informations( nom maillage, champ ) du fichier MED resultat en sortie de Stanley
        """
        self.name           = selection.contexte.maillage.nom
        self.fieldName      = selection.contexte.resultat.nom
        tailSize            = 8 - len( self.fieldName)
        if tailSize > 0:
            self.fieldName += tailSize * '_'
        self.fieldName     += selection.nom_cham

        tailSize            = 32 - len( self.fieldName )
        if tailSize > 0:
            self.fieldName += tailSize * '_'