Salome HOME
Prepare the fix of padder plugin for the usecases defined by SpherePadder tests
authorboulant <boulant>
Fri, 23 Nov 2012 17:45:33 +0000 (17:45 +0000)
committerboulant <boulant>
Fri, 23 Nov 2012 17:45:33 +0000 (17:45 +0000)
src/Tools/padder/meshjob/impl/MeshJobManager_i.cxx
src/Tools/padder/spadderpy/__init__.py
src/Tools/padder/unittests/usecase_meshJobManager.py

index 95e092dfb1a398815e103254c8f484349a8e2076..d1760f2ab6566f740a918a5bbb26e96615267fda 100644 (file)
@@ -270,14 +270,21 @@ CORBA::Long MeshJobManager_i::initialize(const MESHJOB::MeshJobParameterList & m
       listSteelBarMesh.push_back(currentMesh);
       break;
     default:
-      LOG("The type of the file is not recognized");
+      _lastErrorMessage =
+       std::string("The type of the file ")+
+       std::string(currentMesh.file_name)+
+       std::string(" is not recognized");
+      LOG(_lastErrorMessage);
       return JOBID_UNDEFINED;
     }
   }
   
-  if ( listConcreteMesh.size() != 1 ) {
+  // It is not possible to specify more than one concrete
+  // file. Converselly, it is possible to specify no concrete file.
+  if ( listConcreteMesh.size() > 1 ) {
     // Not consistent with the specification
-    LOG("You specify more than one concrete mesh");
+    _lastErrorMessage = std::string("You specify more than one concrete mesh (not authorized)");
+    LOG(_lastErrorMessage);
     return JOBID_UNDEFINED;
   }
   
index 911cf5b96a9c534a6f23bbe1fbd3f59d7326d922..f50546b050bfe9d3ec8b19ca8dc27f6f8509ab12 100644 (file)
@@ -31,10 +31,24 @@ def getRootDir():
 
 def getTestDataDir():
     '''
-    This function gives the absolute path to the directory containing
-    the data files for test (realistic med files).
+    This function gives the absolute path to the SMESH directory
+    containing the data files for the padder plugin test (realistic
+    med files).
     '''
-    datadir=os.path.join(getRootDir(),"share/salome/resources/smesh/padderexe")
+    datadir = os.path.join(getRootDir(),"share/salome/resources/smesh/padderdata")
+    return datadir
+
+def getTestPadderDataDir():
+    """
+    This function gives the absolute path to the PADDER directory
+    containing the data files for the padder plugin test. WARNING:
+    this directory is a directory of the external program SpherePadder
+    that is wrapped by the padder plugin. We use the shell variable
+    PADDERHOME (defined by the SALOME environment) to localize this
+    folder. 
+    """
+    PADDERHOME = os.environ['PADDERHOME']
+    datadir = os.path.join(PADDERHOME,"tests")
     return datadir
 
 import MESHJOB # to get the enum constant values
index 09a8c09ea18dc63fcda77614c94a1a166a6c2fbf..ecc613831bdcc0fcf0af6cd94da9668dbd69d25b 100644 (file)
 # This script illustrates the standard use case of the component
 # MeshJobManager from within a SALOME script.
 
-
 #
 # Preparing the configuration parameters
 #
+import sys
 import os
+import time
 from salome.smesh.spadder.configreader import ConfigReader, printConfig
 
 configReader = ConfigReader()
@@ -35,15 +36,13 @@ defaultConfig = configReader.getDefaultConfig()
 printConfig(defaultConfig)
 
 from salome.smesh import spadder
-file_concrete=os.path.join(spadder.getTestDataDir(),"concrete.med")
-file_steelbar=os.path.join(spadder.getTestDataDir(),"ferraill.med")
 
 import salome
 import MESHJOB
 
 #
-# Setup the configuration in the component. When first have to load
-# the catalog of SPADDER components, then load the component
+# Setup the configuration in the component. We first have to load the
+# catalog of SPADDER components, then load the component
 # MeshJobManager, and finally configure this component.
 #
 spadder.loadSpadderCatalog()
@@ -53,27 +52,118 @@ component = salome.lcc.FindOrLoadComponent("FactoryServer","MeshJobManager")
 config = MESHJOB.ConfigParameter(resname=defaultConfig.resname,
                                  binpath=defaultConfig.binpath,
                                  envpath=defaultConfig.envpath)
-component.configure("localhost",config)
+
+configId = "localhost"
+component.configure(configId,config)
+
 
 #
 # Prepare the job parameters and initialize the job
 #
-meshJobParameterList = []
-param = MESHJOB.MeshJobParameter(file_name=file_concrete,
-                                 file_type=MESHJOB.MED_CONCRETE,
-                                 group_name="concrete")
-meshJobParameterList.append(param)
+def test00_parameters():
+    """Test using a concrete mesh and a single steelbar mesh""" 
+    file_concrete=os.path.join(spadder.getTestDataDir(),"concrete.med")
+    file_steelbar=os.path.join(spadder.getTestDataDir(),"ferraill.med")
+
+    meshJobParameterList = []
+    param = MESHJOB.MeshJobParameter(file_name=file_concrete,
+                                     file_type=MESHJOB.MED_CONCRETE,
+                                     group_name="concrete")
+    meshJobParameterList.append(param)
+
+    param = MESHJOB.MeshJobParameter(file_name=file_steelbar,
+                                     file_type=MESHJOB.MED_STEELBAR,
+                                     group_name="steelbar")
+    meshJobParameterList.append(param)
+    return meshJobParameterList
+
+def test01_parameters():
+    """One concrete mesh and two steelbar meshes"""
+    datadir = os.path.join(spadder.getTestPadderDataDir(),"test01")
+    meshJobParameterList = []
+
+    medfile = os.path.join(datadir,"concrete.med")
+    param = MESHJOB.MeshJobParameter(file_name=medfile,
+                                     file_type=MESHJOB.MED_CONCRETE,
+                                     group_name="concrete")
+    meshJobParameterList.append(param)
+    
+    medfile = os.path.join(datadir,"ferraill.med")
+    param = MESHJOB.MeshJobParameter(file_name=medfile,
+                                     file_type=MESHJOB.MED_STEELBAR,
+                                     group_name="ferraill")
+    meshJobParameterList.append(param)
+
+    medfile = os.path.join(datadir,"ferrtran.med")
+    param = MESHJOB.MeshJobParameter(file_name=medfile,
+                                     file_type=MESHJOB.MED_STEELBAR,
+                                     group_name="ferrtran")
+    meshJobParameterList.append(param)
+    
+    return meshJobParameterList
+
+def test02_parameters():
+    """One steelbar mesh only, without a concrete mesh"""
+    datadir = os.path.join(spadder.getTestPadderDataDir(),"test02")
+    meshJobParameterList = []
+
+    medfile = os.path.join(datadir,"cadreef.med")
+    param = MESHJOB.MeshJobParameter(file_name=medfile,
+                                     file_type=MESHJOB.MED_STEELBAR,
+                                     group_name="cadre")
+    meshJobParameterList.append(param)
+    return meshJobParameterList
+
+def test03_parameters():
+    """One concrete mesh only, without a steelbar mesh"""
+    datadir = os.path.join(spadder.getTestPadderDataDir(),"test03")
+    meshJobParameterList = []
+
+    medfile = os.path.join(datadir,"concrete.med")
+    param = MESHJOB.MeshJobParameter(file_name=medfile,
+                                     file_type=MESHJOB.MED_CONCRETE,
+                                     group_name="concrete")
+    meshJobParameterList.append(param)
+    return meshJobParameterList
+
+#
+# Choose here the use case
+#
+
+#meshJobParameterList = test00_parameters()
+#meshJobParameterList = test01_parameters()
+meshJobParameterList = test02_parameters()
+#meshJobParameterList = test03_parameters()
 
-param = MESHJOB.MeshJobParameter(file_name=file_steelbar,
-                                 file_type=MESHJOB.MED_STEELBAR,
-                                 group_name="steelbar")
-meshJobParameterList.append(param)
-jobid = component.initialize(meshJobParameterList, "localhost")
+#
+# Prepare, start and follow-up the job
+#
+jobid = component.initialize(meshJobParameterList, configId)
+if jobid<0:
+    msg = component.getLastErrorMessage()
+    print "ERR: %s"%msg
+    sys.exit(1)
+    
+created = False
+nbiter  = 0
+while not created:
+    state = component.getState(jobid)
+    print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
+    if state == "CREATED":
+        created = True
+    time.sleep(0.5)
+    nbiter+=1
 
 #
 # Start the execution of the job identified by its job id.
 #
 ok=component.start(jobid)
+if not ok:
+    msg = component.getLastErrorMessage()
+    print "ERR: %s"%msg
+    sys.exit(1)
+
+print "job started: %s"%ok
 
 #
 # This part illustrates how you can follow the execution of the job.
@@ -84,7 +174,6 @@ all_states = run_states+end_states;
 
 ended  = False
 nbiter = 0
-import time
 while not ended:
     state = component.getState(jobid)
     print "MeshJobManager ["+str(nbiter)+"] : state = "+str(state)
@@ -95,6 +184,8 @@ while not ended:
         
 if state not in end_states:
     print "ERR: jobid = "+str(jobid)+" ended abnormally with state="+str(state)
+    msg = component.getLastErrorMessage()
+    print "ERR: %s"%msg    
 else:
     print "OK:  jobid = "+str(jobid)+" ended with state="+str(state)
     meshJobResults = component.finalize(jobid)