From c9d6c9f207e9e01be0aaf281afd102c505181297 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Ribes?= Date: Tue, 22 Feb 2011 13:44:52 +0100 Subject: [PATCH] Ajout d'un engine Python pour ADAO Supression de l'ancien en C++ Modification de l'IDL Suppression de studyedit et utilisation de celui du kernel --- configure.ac | 1 - idl/ADAO.idl | 2 +- resources/ADAOCatalog.xml | 4 +- src/daSalome/daGUI/ADAO.py | 0 src/daSalome/daGUI/ADAO_ENGINE.py | 47 ++ src/daSalome/daGUI/Makefile.am | 4 +- src/daSalome/daGUI/daGuiComponent/Makefile.am | 14 - .../daGuiComponent/adaogui_component.cxx | 69 --- .../daGuiComponent/adaogui_component.hxx | 36 -- src/daSalome/daGUI/daGuiImpl/Makefile.am | 1 - src/daSalome/daGUI/daGuiImpl/adaoLogger.py | 43 +- .../daGUI/daGuiImpl/adaoModuleHelper.py | 12 +- .../daGUI/daGuiImpl/adaoStudyEditor.py | 8 +- src/daSalome/daGUI/daGuiImpl/studyedit.py | 443 ------------------ 14 files changed, 96 insertions(+), 588 deletions(-) delete mode 100644 src/daSalome/daGUI/ADAO.py create mode 100644 src/daSalome/daGUI/ADAO_ENGINE.py delete mode 100644 src/daSalome/daGUI/daGuiComponent/Makefile.am delete mode 100644 src/daSalome/daGUI/daGuiComponent/adaogui_component.cxx delete mode 100644 src/daSalome/daGUI/daGuiComponent/adaogui_component.hxx delete mode 100644 src/daSalome/daGUI/daGuiImpl/studyedit.py diff --git a/configure.ac b/configure.ac index 69e251d..945a72c 100644 --- a/configure.ac +++ b/configure.ac @@ -118,7 +118,6 @@ AC_CONFIG_FILES([ src/daSalome/daGUI/daUtils/Makefile src/daSalome/daGUI/daGuiImpl/Makefile src/daSalome/daGUI/daEficasWrapper/Makefile - src/daSalome/daGUI/daGuiComponent/Makefile src/tests/Makefile src/tests/daSalome/Makefile src/tests/daSalome/test000_Blue_AnalysisFile.py diff --git a/idl/ADAO.idl b/idl/ADAO.idl index 533cc97..e0a9650 100644 --- a/idl/ADAO.idl +++ b/idl/ADAO.idl @@ -7,7 +7,7 @@ module ADAO { - interface ADAO_GUI_COMPONENT : Engines::Superv_Component + interface ADAO_COMPONENT : Engines::Component, SALOMEDS::Driver { /*! * Test that the component is ok diff --git a/resources/ADAOCatalog.xml b/resources/ADAOCatalog.xml index d133614..8dc7884 100644 --- a/resources/ADAOCatalog.xml +++ b/resources/ADAOCatalog.xml @@ -16,6 +16,8 @@ - + + ADAO_ENGINE + diff --git a/src/daSalome/daGUI/ADAO.py b/src/daSalome/daGUI/ADAO.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/daSalome/daGUI/ADAO_ENGINE.py b/src/daSalome/daGUI/ADAO_ENGINE.py new file mode 100644 index 0000000..10cc610 --- /dev/null +++ b/src/daSalome/daGUI/ADAO_ENGINE.py @@ -0,0 +1,47 @@ +# Copyright (C) 2011 EDF R&D +# +# 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 +# + +import ADAO__POA +import SALOME_ComponentPy +import SALOME_DriverPy + +from daGuiImpl.adaoLogger import * + +class ADAO_ENGINE(ADAO__POA.ADAO_COMPONENT, + SALOME_ComponentPy.SALOME_ComponentPy_i, + SALOME_DriverPy.SALOME_DriverPy_i): + """ + Pour etre un composant SALOME cette classe Python + doit avoir le nom du composant et heriter de la + classe ADAO_COMPONENT issue de la compilation de l'idl + par omniidl et de la classe SALOME_ComponentPy_i + qui porte les services generaux d'un composant SALOME + """ + def __init__ ( self, orb, poa, contID, containerName, instanceName, + interfaceName ): + debug("Creating ADAO component instance", "ENGINE") + SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa, + contID, containerName, instanceName, interfaceName, 0) + SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName) + + # On stocke dans l'attribut _naming_service, une ref sur le Naming Service + self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb ) + + def print_ping(): + info("ADAO ENGINE Ping", "ENGINE") diff --git a/src/daSalome/daGUI/Makefile.am b/src/daSalome/daGUI/Makefile.am index 748d297..a813d87 100644 --- a/src/daSalome/daGUI/Makefile.am +++ b/src/daSalome/daGUI/Makefile.am @@ -17,8 +17,8 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SUBDIRS = daUtils daGuiImpl daEficasWrapper daGuiComponent +SUBDIRS = daUtils daGuiImpl daEficasWrapper include $(top_srcdir)/adm_local/make_common_starter.am -salomepython_PYTHON= ADAOGUI.py ADAO.py +salomepython_PYTHON= ADAOGUI.py ADAO_ENGINE.py diff --git a/src/daSalome/daGUI/daGuiComponent/Makefile.am b/src/daSalome/daGUI/daGuiComponent/Makefile.am deleted file mode 100644 index f774010..0000000 --- a/src/daSalome/daGUI/daGuiComponent/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ - -include $(top_srcdir)/adm_local/make_common_starter.am - -AM_CFLAGS=$(SALOME_INCLUDES) -fexceptions - -lib_LTLIBRARIES= libADAOEngine.la -salomeinclude_HEADERS= adaogui_component.hxx - -libADAOEngine_la_SOURCES = adaogui_component.cxx -nodist_libADAOEngine_la_SOURCES = -libADAOEngine_la_CXXFLAGS = -I$(top_builddir)/idl $(KERNEL_INCLUDES) -I/usr/include -libADAOEngine_la_LIBADD = -L$(top_builddir)/idl -lADAO ${KERNEL_LIBS} -libADAOEngine_la_LDFLAGS = - diff --git a/src/daSalome/daGUI/daGuiComponent/adaogui_component.cxx b/src/daSalome/daGUI/daGuiComponent/adaogui_component.cxx deleted file mode 100644 index ae1f507..0000000 --- a/src/daSalome/daGUI/daGuiComponent/adaogui_component.cxx +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include "adaogui_component.hxx" - -using namespace std; - -//! Constructor for component "cppcompos" instance -/*! - * - */ -ADAO_GUI_COMPONENT_i::ADAO_GUI_COMPONENT_i(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char *interfaceName) -: Superv_Component_i(orb, poa, contId, instanceName, interfaceName) -{ - _thisObj = this ; - _id = _poa->activate_object(_thisObj); -} - -ADAO_GUI_COMPONENT_i::ADAO_GUI_COMPONENT_i(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - Engines::Container_ptr container, - const char *instanceName, - const char *interfaceName) -: Superv_Component_i(orb, poa, container, instanceName, interfaceName) -{ - _thisObj = this ; - _id = _poa->activate_object(_thisObj); -} - -void -ADAO_GUI_COMPONENT_i::destroy() -{ - Engines_Component_i::destroy(); -} - -CORBA::Boolean -ADAO_GUI_COMPONENT_i::init_service(const char * service_name) -{ - CORBA::Boolean rtn = true; - return rtn; -} - -void -ADAO_GUI_COMPONENT_i::print_ping() -{ - std::cerr << "ADAO_GUI_COMPONENT_i ping" << std::endl; -} -//! Destructor for component "ADAO_GUI_COMPONENT_i" instance -ADAO_GUI_COMPONENT_i::~ADAO_GUI_COMPONENT_i() -{ -} - -extern "C" -{ - PortableServer::ObjectId * ADAOEngine_factory(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char *interfaceName) - { - MESSAGE("PortableServer::ObjectId * ADAOEngine_factory()"); - ADAO_GUI_COMPONENT_i * myEngine = new ADAO_GUI_COMPONENT_i(orb, poa, contId, instanceName, interfaceName); - return myEngine->getId() ; - } -} - diff --git a/src/daSalome/daGUI/daGuiComponent/adaogui_component.hxx b/src/daSalome/daGUI/daGuiComponent/adaogui_component.hxx deleted file mode 100644 index 6873bcb..0000000 --- a/src/daSalome/daGUI/daGuiComponent/adaogui_component.hxx +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _ADAO_GUI_COMPONENT_HXX_ -#define _ADAO_GUI_COMPONENT_HXX_ - -#include -#include "Superv_Component_i.hxx" -#include "ADAO.hh" - -class ADAO_GUI_COMPONENT_i: - public virtual POA_ADAO::ADAO_GUI_COMPONENT, - public virtual Superv_Component_i -{ - public: - ADAO_GUI_COMPONENT_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, const char *interfaceName); - ADAO_GUI_COMPONENT_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, - Engines::Container_ptr container, - const char *instanceName, const char *interfaceName); - virtual ~ADAO_GUI_COMPONENT_i(); - - void destroy(); - CORBA::Boolean init_service(const char * service_name); - - virtual void print_ping(); -}; - -extern "C" -{ - PortableServer::ObjectId * ADAOEngine_factory(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char *interfaceName); -} -#endif - diff --git a/src/daSalome/daGUI/daGuiImpl/Makefile.am b/src/daSalome/daGUI/daGuiImpl/Makefile.am index 704fd44..4f2d529 100644 --- a/src/daSalome/daGUI/daGuiImpl/Makefile.am +++ b/src/daSalome/daGUI/daGuiImpl/Makefile.am @@ -29,7 +29,6 @@ mypkgpython_PYTHON = \ adaoModuleHelper.py \ adaoStudyEditor.py \ adaoLogger.py \ - studyedit.py \ adaoCase.py \ enumerate.py diff --git a/src/daSalome/daGUI/daGuiImpl/adaoLogger.py b/src/daSalome/daGUI/daGuiImpl/adaoLogger.py index 13c24d0..c0c8cad 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoLogger.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoLogger.py @@ -22,15 +22,40 @@ from salome.kernel.logger import Logger from salome.kernel import termcolor adao_logger = Logger("ADAO") +adao_engine_logger = Logger("ADAO ENGINE") -def debug(msg): - adao_logger.setColor(termcolor.GREEN) - adao_logger.debug(msg) +def info(msg, logger = "ADAO"): -def error(msg): - adao_logger.setColor(termcolor.RED) - adao_logger.error(msg) + if logger == "ADAO": + adao_logger.setColor(termcolor.BLUE) + adao_logger.info(msg) + elif logger == "ENGINE": + adao_engine_logger.setColor(termcolor.BLUE) + adao_engine_logger.info(msg) -def warning(msg): - adao_logger.setColor(termcolor.BLUE) - adao_logger.warning(msg) +def debug(msg, logger = "ADAO"): + + if logger == "ADAO": + adao_logger.setColor(termcolor.GREEN) + adao_logger.debug(msg) + elif logger == "ENGINE": + adao_engine_logger.setColor(termcolor.GREEN) + adao_engine_logger.debug(msg) + +def error(msg, logger = "ADAO"): + + if logger == "ADAO": + adao_logger.setColor(termcolor.RED) + adao_logger.error(msg) + elif logger == "ENGINE": + adao_engine_logger.setColor(termcolor.RED) + adao_engine_logger.error(msg) + +def warning(msg, logger = "ADAO"): + + if logger == "ADAO": + adao_logger.setColor(termcolor.CYAN) + adao_logger.warning(msg) + elif logger == "ENGINE": + adao_engine_logger.setColor(termcolor.CYAN) + adao_engine_logger.warning(msg) diff --git a/src/daSalome/daGUI/daGuiImpl/adaoModuleHelper.py b/src/daSalome/daGUI/daGuiImpl/adaoModuleHelper.py index 9a38b9a..a80eb83 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoModuleHelper.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoModuleHelper.py @@ -20,10 +20,6 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -# --- -# Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -# --- -# __all__ = [ "moduleID", @@ -54,14 +50,14 @@ import SALOMEDS_Attributes_idl # Get OMA module's ID ### def moduleID(): - MODULE_ID = 1100 + MODULE_ID = 6100 return MODULE_ID ### # Get OMA object's ID ### def objectID(): - OBJECT_ID = 1110 + OBJECT_ID = 6110 return OBJECT_ID ### @@ -78,7 +74,7 @@ def componentName(): # Note that this name should be (i) the name used for the class implementing # the component CORBA interface and (ii) the name used to declare the component # in the catalog of the module. - return "ADAO" + return "ADAO_ENGINE" # _MEM_ we use here the tr() translation methode to manage constant parameters # in the application. We could have specified instead constant values directly @@ -93,7 +89,7 @@ def modulePixmap(): """ Get the reference pixmap for this module. """ - return "ADAO_small.png" + return "ADAO.png" __verbose__ = None def verbose(): diff --git a/src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py b/src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py index acf16f7..8196087 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py @@ -21,7 +21,9 @@ __author__="aribes/gboulant" from enumerate import Enumerate -import studyedit + +from salome.kernel import studyedit + import adaoModuleHelper from daGuiImpl.adaoCase import AdaoCase @@ -56,7 +58,7 @@ def addInStudy(salomeStudyId, adaoCase): studyEditor = studyedit.getStudyEditor(salomeStudyId) adaoRootEntry = studyEditor.findOrCreateComponent( - engineName = adaoModuleHelper.componentName(), + moduleName = adaoModuleHelper.componentName(), componentName = adaoModuleHelper.componentUserName()) itemName = adaoCase.get_name() @@ -75,7 +77,7 @@ def addInStudy(salomeStudyId, adaoCase): def updateItem(salomeStudyId, salomeStudyItem, adaoCase): studyEditor = studyedit.getStudyEditor(salomeStudyId) - + if salomeStudyItem.GetName()[:-2] != adaoCase.get_name(): itemName = adaoCase.get_name() itemValue = adaoCase.get_filename() diff --git a/src/daSalome/daGUI/daGuiImpl/studyedit.py b/src/daSalome/daGUI/daGuiImpl/studyedit.py deleted file mode 100644 index 074a106..0000000 --- a/src/daSalome/daGUI/daGuiImpl/studyedit.py +++ /dev/null @@ -1,443 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2007-2009 EDF R&D -# -# This file is part of PAL_SRC. -# -# PAL_SRC 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. -# -# PAL_SRC 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 PAL_SRC; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# -""" -This module provides a new class :class:`StudyEditor` to complement -:class:`Study` and :class:`StudyBuilder` classes. -""" - -import re -import salome - -_editors = {} -_DEFAULT_CONTAINER = "FactoryServer" - -def getActiveStudyId(): - """ - Return the ID of the active study. In GUI mode, this function is equivalent - to ``salome.sg.getActiveStudyId()``. Outside GUI, it returns - ``salome.myStudyId`` variable. - """ - salome.salome_init() - if salome.hasDesktop(): - return salome.sg.getActiveStudyId() - else: - return salome.myStudyId - -def getStudyEditor(studyId = None): - """ - Return a :class:`StudyEditor` instance to edit the study with ID - `studyId`. If `studyId` is :const:`None`, return an editor for the current - study. - """ - if studyId is None: - studyId = getActiveStudyId() - if not _editors.has_key(studyId): - _editors[studyId] = StudyEditor(studyId) - return _editors[studyId] - - -class StudyEditor: - """ - This class provides utility methods to complement :class:`Study` and - :class:`StudyBuilder` classes. Those methods may be moved in those classes - in the future. The parameter `studyId` defines the ID of the study to - edit. If it is :const:`None`, the edited study will be the current study. - The preferred way to get a StudyEditor object is through the method - :meth:`getStudyEditor` which allows to reuse existing instances. - - .. attribute:: studyId - - This instance attribute contains the ID of the edited study. This - attribute should not be modified. - - .. attribute:: study - - This instance attribute contains the underlying :class:`Study` object. - It can be used to access the study but the attribute itself should not - be modified. - - .. attribute:: builder - - This instance attribute contains the underlying :class:`StudyBuilder` - object. It can be used to edit the study but the attribute itself - should not be modified. - - """ - def __init__(self, studyId = None): - salome.salome_init() - if studyId is None: - studyId = getActiveStudyId() - self.studyId = studyId - self.study = salome.myStudyManager.GetStudyByID(studyId) - if self.study is None: - raise Exception("Can't create StudyEditor object: " - "Study %d doesn't exist" % studyId) - self.builder = self.study.NewBuilder() - - def findOrCreateComponent(self, engineName, componentName = None, - icon = None, loadEngine = True, - containerName = _DEFAULT_CONTAINER): - """ - Find a component corresponding to the engine named `engineName` in the - study, or create it if none is found. Then eventually load the - corresponding engine and the CORBA objects of this component. - - :type engineName: string - :param engineName: name of the engine corresponding to the component. - - :type componentName: string - :param componentName: name of the new component if created. If - :const:`None`, use `engineName` instead. - - :type icon: string - :param icon: icon for the new component (attribute "AttributePixMap"). - - :type loadEngine: boolean - :param loadEngine: If :const:`True`, find or load the corresponding - engine and associate it with the component. - - :type containerName: string - :param containerName: name of the container in which the component - should be loaded. - - :return: the SComponent found or created. - - """ - sComponent = self.study.FindComponent(engineName) - if sComponent is None: - sComponent = self.builder.NewComponent(engineName) - if componentName is None: - componentName = engineName - self.builder.SetName(sComponent, componentName) - - if icon is not None: - self.setIcon(sComponent, icon) - - if loadEngine: - self.loadComponentEngine(sComponent, containerName) - - return sComponent - - def loadComponentEngine(self, sComponent, - containerName = _DEFAULT_CONTAINER): - """ - Load the engine corresponding to `sComponent` in the container - `containerName`, associate the engine with the component and load the - CORBA objects of this component in the study. - """ - engine = salome.lcc.FindOrLoadComponent(containerName, - sComponent.GetComment()) - self.builder.LoadWith(sComponent, engine) - - def getOrLoadObject(self, item): - """ - Get the CORBA object associated with the SObject `item`, eventually by - first loading it with the corresponding engine. - """ - object = item.GetObject() - if object is None: # the engine has not been loaded yet - sComponent = item.GetFatherComponent() - self.loadComponentEngine(sComponent) - object = item.GetObject() - return object - - def findOrCreateItem(self, fatherItem, name, fileType = None, - fileName = None, comment = None, icon = None, - IOR = None, typeId = None): - """ - Find an object under `fatherItem` in the study with the given - attributes. Return the first one found if at least one exists, - otherwise create a new one with the given attributes and return it. - - See :meth:`setItem` for the description of the parameters. - """ - sObject = self.findItem(fatherItem, name, fileType, fileName, comment, - icon, IOR, typeId) - if sObject is None: - sObject = self.createItem(fatherItem, name, fileType, fileName, - comment, icon, IOR, typeId) - return sObject - - def findItem(self, fatherItem, name = None, fileType = None, - fileName = None, comment = None, icon = None, IOR = None, - typeId = None): - """ - Find an item with given attributes under `fatherItem` in the study. If - none is found, return :const:`None`. If several items correspond to - the parameters, only the first one is returned. The search is made - only on given parameters (i.e. not :const:`None`). To look explicitly - for an empty attribute, use an empty string in the corresponding - parameter. - - See :meth:`setItem` for the description of the parameters. - """ - foundItem = None; - childIterator = self.study.NewChildIterator(fatherItem) - while childIterator.More() and foundItem is None: - childItem = childIterator.Value() - if childItem and \ - (name is None or childItem.GetName() == name) and \ - (fileType is None or \ - self.getFileType(childItem) == fileType) and \ - (fileName is None or \ - self.getFileName(childItem) == fileName) and \ - (comment is None or childItem.GetComment() == comment) and \ - (icon is None or \ - self.getIcon(childItem) == icon) and \ - (IOR is None or childItem.GetIOR() == IOR and \ - (typeId is None or \ - self.getTypeId(childItem) == typeId)): - foundItem = childItem - childIterator.Next() - return foundItem - - def createItem(self, fatherItem, name, fileType = None, fileName = None, - comment = None, icon = None, IOR = None, typeId = None): - """ - Create a new object named `name` under `fatherItem` in the study, with - the given attributes. If an object named `name` already exists under - the father object, the new object is created with a new name `name_X` - where X is the first available index. - - :type fatherItem: SObject - :param fatherItem: item under which the new item will be added. - - :return: new SObject created in the study - - See :meth:`setItem` for the description of the other parameters. - """ - aSObject = self.builder.NewObject(fatherItem) - - aChildIterator = self.study.NewChildIterator(fatherItem) - aMaxId = -1 - aLength = len(name) - aDelim = "_" - anIdRE = re.compile("^" + aDelim + "[0-9]+") - aNameRE = re.compile("^" + name) - while aChildIterator.More(): - aSObj = aChildIterator.Value() - aChildIterator.Next() - aName = aSObj.GetName() - if re.match(aNameRE,aName): - aTmp = aName[aLength:] - if re.match(anIdRE,aTmp): - import string - anId = string.atol(aTmp[1:]) - if aMaxId < anId: - aMaxId = anId - pass - pass - elif aMaxId < 0: - aMaxId = 0 - pass - pass - pass - - aMaxId = aMaxId + 1 - aName = name - if aMaxId > 0: - aName = aName + aDelim + str(aMaxId) - pass - - self.setItem(aSObject, aName, fileType, fileName, comment, icon, - IOR, typeId) - - return aSObject - - def setItem(self, item, name = None, fileType = None, fileName = None, - comment = None, icon = None, IOR = None, typeId = None): - """ - Modify the attributes of an item in the study. Unspecified attributes - (i.e. those set to :const:`None`) are left unchanged. - - :type item: SObject - :param item: item to modify. - - :type name: string - :param name: item name (attribute 'AttributeName'). - - :type fileType: string - :param fileType: item file type (attribute 'AttributeFileType'). - - :type fileName: string - :param fileName: item file name (attribute - 'AttributeExternalFileDef'). - - :type comment: string - :param comment: item comment (attribute 'AttributeComment'). Note that - this attribute will appear in the 'Value' column in - the object browser. - - :type icon: string - :param icon: item icon name (attribute 'AttributePixMap'). - - :type IOR: string - :param IOR: IOR of a CORBA object associated with the item - (attribute 'AttributeIOR'). - - :type typeId: integer - :param typeId: item type (attribute 'AttributeLocalID'). - """ - #print "setItem (ID=%s): name=%s, fileType=%s, fileName=%s, comment=%s, icon=%s, IOR=%s" % (item.GetID(), name, fileType, fileName, comment, icon, IOR) - # Explicit cast is necessary for unicode to string conversion - if name is not None: - self.builder.SetName(item, str(name)) - if fileType is not None: - self.setFileType(item, fileType) - if fileName is not None: - self.setFileName(item, fileName) - if comment is not None: - self.builder.SetComment(item, str(comment)) - if icon is not None: - self.setIcon(item, icon) - if IOR is not None: - self.builder.SetIOR(item, str(IOR)) - if typeId is not None: - self.setTypeId(item, typeId) - - def removeItem(self, item, withChildren = False ): - """ - Remove the given item from the study (the item still is in - the study after the removal) - @param item: the browser object to be removed - @param withChildren: remove children if True - """ - ok = False - try: - if withChildren: - self.builder.RemoveObjectWithChildren(item) - else: - self.builder.RemoveObject(item) - ok = True - except: - ok = False - - return ok - - def setItemAtTag(self, fatherItem, tag, name = None, fileType = None, - fileName = None, comment = None, icon = None, IOR = None, - typeId = None): - """ - Find an item tagged `tag` under `fatherItem` in the study tree or - create it if there is none, then set its attributes. - - :type fatherItem: SObject - :param fatherItem: item under which the tagged item will be looked for - and eventually created. - - :type tag: integer - :param tag: tag of the item to look for. - - :return: the SObject at `tag` if found or created successfully, or - :const:`None` if an error happened. - - See :meth:`setItem` for the description of the other parameters. - """ - found, sObj = fatherItem.FindSubObject(tag) - if not found: - sObj = self.builder.NewObjectToTag(fatherItem, tag) - self.setItem(sObj, name, fileType, fileName, comment, icon, - IOR, typeId) - return sObj - - def getAttributeValue(self, sObject, attributeName, default = None): - """ - Return the value of the attribute named `attributeName` on the object - `sObject`, or `default` if the attribute doesn't exist. - """ - value = default - found, attr = self.builder.FindAttribute(sObject, attributeName) - if found: - value = attr.Value() - return value - - def setAttributeValue(self, sObject, attributeName, attributeValue): - """ - Set the value of the attribute named `attributeName` on the object - `sObject` to the value `attributeValue`. - """ - attr = self.builder.FindOrCreateAttribute(sObject, attributeName) - attr.SetValue(attributeValue) - - def getTypeId(self, sObject): - """ - Return the value of the attribute "AttributeLocalID" of the object - `sObject`, or :const:`None` if it is not set. - """ - return self.getAttributeValue(sObject, "AttributeLocalID") - - def setTypeId(self, sObject, value): - """ - Set the attribute "AttributeLocalID" of the object `sObject` to the - value `value`. - """ - self.setAttributeValue(sObject, "AttributeLocalID", value) - - def getFileType(self, sObject): - """ - Return the value of the attribute "AttributeFileType" of the object - `sObject`, or an empty string if it is not set. - """ - return self.getAttributeValue(sObject, "AttributeFileType", "") - - def setFileType(self, sObject, value): - """ - Set the attribute "AttributeFileType" of the object `sObject` to the - value `value`. - """ - # Explicit cast is necessary for unicode to string conversion - self.setAttributeValue(sObject, "AttributeFileType", str(value)) - - def getFileName(self, sObject): - """ - Return the value of the attribute "AttributeExternalFileDef" of the - object `sObject`, or an empty string if it is not set. - """ - return self.getAttributeValue(sObject, "AttributeExternalFileDef", "") - - def setFileName(self, sObject, value): - """ - Set the attribute "AttributeExternalFileDef" of the object `sObject` - to the value `value`. - """ - # Explicit cast is necessary for unicode to string conversion - self.setAttributeValue(sObject, "AttributeExternalFileDef", - str(value)) - - def getIcon(self, sObject): - """ - Return the value of the attribute "AttributePixMap" of the object - `sObject`, or an empty string if it is not set. - """ - value = "" - found, attr = self.builder.FindAttribute(sObject, "AttributePixMap") - if found and attr.HasPixMap(): - value = attr.GetPixMap() - return value - - def setIcon(self, sObject, value): - """ - Set the attribute "AttributePixMap" of the object `sObject` to the - value `value`. - """ - attr = self.builder.FindOrCreateAttribute(sObject, "AttributePixMap") - # Explicit cast is necessary for unicode to string conversion - attr.SetPixMap(str(value)) -- 2.39.2