]> SALOME platform Git repositories - modules/kernel.git/blob - src/Container/SALOME_Container.py
Salome HOME
CCAR: _id not initialized
[modules/kernel.git] / src / Container / SALOME_Container.py
1 #! /usr/bin/env python
2 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 #  This library is free software; you can redistribute it and/or
8 #  modify it under the terms of the GNU Lesser General Public
9 #  License as published by the Free Software Foundation; either
10 #  version 2.1 of the License.
11 #
12 #  This library is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  Lesser General Public License for more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public
18 #  License along with this library; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 #  SALOME Container : implementation of container and engine for Kernel
24 #  File   : SALOME_Container.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : SALOME
27 #  $Header$
28 #
29 ## @package SALOME_Container
30 # \brief python implementation of container interface for Kernel
31 #
32 #
33
34 import os
35 import sys
36 import string
37 from omniORB import CORBA, PortableServer
38 import SALOMEDS 
39 import Engines, Engines__POA
40 from SALOME_NamingServicePy import *
41 from SALOME_ComponentPy import *
42
43 from SALOME_utilities import *
44 from Utils_Identity import getShortHostName
45 from launchConfigureParser import verbose
46
47 #=============================================================================
48
49 #define an implementation of the container interface for embedding in Container implemented in C++
50
51 class SALOME_Container_i:
52     _orb = None
53     _poa = None
54     _containerName = ""
55     _naming_service = None
56
57     #-------------------------------------------------------------------------
58
59     def __init__(self ,containerName, containerIORStr):
60         MESSAGE( "SALOME_Container_i::__init__" )
61         self._orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
62         self._poa = self._orb.resolve_initial_references("RootPOA")
63         self._containerName = containerName
64         if verbose(): print "SALOME_Container.SALOME_Container_i : _containerName ",self._containerName
65         #self._naming_service = SALOME_NamingServicePy_i(self._orb)
66         self._container = self._orb.string_to_object(containerIORStr)
67
68     #-------------------------------------------------------------------------
69
70     def import_component(self, componentName):
71         MESSAGE( "SALOME_Container_i::import_component" )
72         ret=""
73         try:
74             if verbose(): print "try import ",componentName
75             __import__(componentName)
76             if verbose(): print "import ",componentName," successful"
77         except:
78             import traceback
79             ret=traceback.format_exc(10)
80             if verbose():
81               traceback.print_exc()
82               print "import ",componentName," not possible"
83         return ret
84         
85     #-------------------------------------------------------------------------
86
87     def create_component_instance(self, componentName, instanceName, studyId):
88         MESSAGE( "SALOME_Container_i::create_component_instance" )
89         comp_iors=""
90         try:
91             component=__import__(componentName)
92             factory=getattr(component,componentName)
93             comp_i=factory(self._orb,
94                            self._poa,
95                            self._container,
96                            self._containerName,
97                            instanceName,
98                            componentName)
99
100             MESSAGE( "SALOME_Container_i::create_component_instance : OK")
101             comp_o = comp_i._this()
102             comp_iors = self._orb.object_to_string(comp_o)
103         except:
104             import traceback
105             traceback.print_exc()
106             MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
107         return comp_iors 
108         
109