From 9a1f5bcb28cd7fcb449cdfdefc8ea5e414dacfe4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9?= Date: Tue, 27 Apr 2010 13:32:43 +0200 Subject: [PATCH] - Debut du GUI SALOME pour DATASSIM --- configure.ac | 2 + resources/Makefile.am | 2 +- resources/SalomeApp.xml | 11 ++ src/daSalome/Makefile.am | 2 + src/daSalome/daGUI/DATASSIMGUI.py | 77 ++++++++ src/daSalome/daGUI/Makefile.am | 24 +++ .../daGUI/daGuiImpl/DATASSIMGUI_impl.py | 145 +++++++++++++++ src/daSalome/daGUI/daGuiImpl/Makefile.am | 30 ++++ src/daSalome/daGUI/daGuiImpl/__init__.py | 0 .../daGUI/daGuiImpl/datassimGuiManager.py | 63 +++++++ src/daSalome/daGUI/daGuiImpl/enumerate.py | 168 ++++++++++++++++++ 11 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 resources/SalomeApp.xml create mode 100644 src/daSalome/daGUI/DATASSIMGUI.py create mode 100644 src/daSalome/daGUI/Makefile.am create mode 100644 src/daSalome/daGUI/daGuiImpl/DATASSIMGUI_impl.py create mode 100644 src/daSalome/daGUI/daGuiImpl/Makefile.am create mode 100644 src/daSalome/daGUI/daGuiImpl/__init__.py create mode 100644 src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py create mode 100644 src/daSalome/daGUI/daGuiImpl/enumerate.py diff --git a/configure.ac b/configure.ac index 5f48ce9..e11af4b 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,8 @@ AC_CONFIG_FILES([ src/Makefile src/daComposant/Makefile src/daSalome/Makefile + src/daSalome/daGUI/Makefile + src/daSalome/daGUI/daGuiImpl/Makefile bin/Makefile ]) AC_OUTPUT diff --git a/resources/Makefile.am b/resources/Makefile.am index 18cfec9..1dd593d 100644 --- a/resources/Makefile.am +++ b/resources/Makefile.am @@ -1,7 +1,7 @@ include $(top_srcdir)/adm_local/make_common_starter.am -DATA_INST = DATASSIMCatalog.xml DATASSIMSchemaCatalog.xml +DATA_INST = DATASSIMCatalog.xml DATASSIMSchemaCatalog.xml SalomeApp.xml salomeres_DATA = ${DATA_INST} EXTRA_DIST = ${DATA_INST} diff --git a/resources/SalomeApp.xml b/resources/SalomeApp.xml new file mode 100644 index 0000000..fc882c1 --- /dev/null +++ b/resources/SalomeApp.xml @@ -0,0 +1,11 @@ + +
+ + + +
+
+ + +
+
diff --git a/src/daSalome/Makefile.am b/src/daSalome/Makefile.am index 666e6bf..ec0181f 100644 --- a/src/daSalome/Makefile.am +++ b/src/daSalome/Makefile.am @@ -1,5 +1,7 @@ include $(top_srcdir)/adm_local/make_common_starter.am +SUBDIRS= daGUI + EXTRA_DIST = daYacsSchemaCreator daYacsIntegration DIR = $(top_srcdir)/src/daSalome/ diff --git a/src/daSalome/daGUI/DATASSIMGUI.py b/src/daSalome/daGUI/DATASSIMGUI.py new file mode 100644 index 0000000..3bc6c12 --- /dev/null +++ b/src/daSalome/daGUI/DATASSIMGUI.py @@ -0,0 +1,77 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2010 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 +# + +""" +This python file provides the implementation of the interface of the GUI part of +this SALOME module. This interface is required by the SALOME GUI framework. +We use here a proxy module named under the alias GuiImpl for at least three +reasons: +1. To Keep the required interface as clear as possible in this file; +2. The concrete implementation can be substituted by an alternative version; +3. We could mix several concrete implementations provided by different proxy + modules, for example for test purposes. +""" + +from daGuiImpl import DATASSIMGUI_impl as GuiImpl + + +# called when module is initialized +# perform initialization actions +def initialize(): + GuiImpl.initialize() + +# called when module is initialized +# return map of popup windows to be used by the module +def windows(): + return GuiImpl.windows() + +# called when module is initialized +# export module's preferences +def createPreferences(): + GuiImpl.createPreferences() + +# called when module is activated +# returns True if activating is successfull and False otherwise +def activate(): + return GuiImpl.activate() + +# called when module is deactivated +def deactivate(): + GuiImpl.deactivate() + +# called when active study is changed +# active study ID is passed as parameter +def activeStudyChanged( studyID ): + GuiImpl.activeStudyChanged( studyID ) + +# called when popup menu is invoked +# popup menu and menu context are passed as parameters +def createPopupMenu( popup, context ): + GuiImpl.createPopupMenu(popup, context ) + +# called when GUI action is activated +# action ID is passed as parameter +def OnGUIEvent(commandID) : + GuiImpl.OnGUIEvent(commandID) + +# called when module's preferences are changed +# preference's resources section and setting name are passed as parameters +def preferenceChanged( section, setting ): + GuiImpl.preferenceChanged( section, setting ) diff --git a/src/daSalome/daGUI/Makefile.am b/src/daSalome/daGUI/Makefile.am new file mode 100644 index 0000000..f71a46b --- /dev/null +++ b/src/daSalome/daGUI/Makefile.am @@ -0,0 +1,24 @@ +# Copyright (C) 2010 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 +# + +SUBDIRS = daGuiImpl + +include $(top_srcdir)/adm_local/make_common_starter.am + +salomepython_PYTHON= DATASSIMGUI.py diff --git a/src/daSalome/daGUI/daGuiImpl/DATASSIMGUI_impl.py b/src/daSalome/daGUI/daGuiImpl/DATASSIMGUI_impl.py new file mode 100644 index 0000000..76dfa11 --- /dev/null +++ b/src/daSalome/daGUI/daGuiImpl/DATASSIMGUI_impl.py @@ -0,0 +1,145 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2010 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 +# + +__author__="aribes/gboulant" + +from PyQt4.QtGui import * +from PyQt4.QtCore import * + +import SalomePyQt +sgPyQt = SalomePyQt.SalomePyQt() + +################################################ +# GUI context class +# Used to store actions, menus, toolbars, etc... +################################################ +# A gui context instance is created for each study. The dictionnary __study2context__ +# keeps the mapping in memory. This context contains graphical objects that have +# to be created for each study. It contains at least the ui component builder that +# creates the menu and toolbar items (must be created for every study) + +from daGuiImpl.datassimGuiManager import DatassimGuiUiComponentBuilder +class GUIcontext: + uiComponentBuilder = None + def __init__(self): + self.uiComponentBuilder = DatassimGuiUiComponentBuilder() + + +__study2context__ = {} +__current_context__ = None +def _setContext( studyID ): + global __study2context__, __current_context__ + if not __study2context__.has_key(studyID): + __study2context__[studyID] = GUIcontext() + pass + __current_context__ = __study2context__[studyID] + return __current_context__ + +#from oma.salome.omaGuiManager import OmaGuiActionImpl +#actionImpl = OmaGuiActionImpl() +# This object does not need to be embedded in a GUI context object. A single +# instance for all studies is a priori sufficient. + +################################################ +# Implementation of SALOME GUI interface +################################################ + +# called when module is initialized +# perform initialization actions +def initialize(): + pass + +# called when module is initialized +# return map of popup windows to be used by the module +def windows(): + wm = {} + wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea + wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea + return wm + +# called when module is initialized +# return list of 2d/3d views to be used ny the module +def views(): + return [] + +def createPreferences(): + """ + Called when module is initialized. Export module's preferences. + """ + pass + +# called when module is activated +# returns True if activating is successfull and False otherwise +def activate(): + ctx = _setContext( sgPyQt.getStudyId() ) + return True + +# called when module is deactivated +def deactivate(): + pass + +# called when active study is changed +# active study ID is passed as parameter +def activeStudyChanged( studyID ): + ctx = _setContext( sgPyQt.getStudyId() ) + pass + + +# called when popup menu is invoked +# popup menu and menu context are passed as parameters +def createPopupMenu( popup, context ): + pass +# activeStudyId = sgPyQt.getStudyId() +# if omaModuleHelper.verbose() : print "OMAGUI.createPopupMenu(): context = %s" % context +# ctx = _setContext( sgPyQt.getStudyId() ) +# selcount, selected = omaGuiHelper.getAllSelected(activeStudyId) +# if selcount == 1: +# selectedItem = omaGuiHelper.getSelectedItem(activeStudyId) +# popup = ctx.uiComponentBuilder.createPopupMenuOnItem(popup, activeStudyId, selectedItem) + +def OnGUIEvent(actionId) : + """ + Called when an event is raised from a graphic item (click on menu item or + toolbar button). The actionId value is the ID associated to the item. + """ + pass +# actionImpl.processAction(actionId) + + +# called when module's preferences are changed +# preference's resources section and setting name are passed as parameters +def preferenceChanged( section, setting ): + pass + +# called when active view is changed +# view ID is passed as parameter +def activeViewChanged( viewID ): + pass + +# called when active view is cloned +# cloned view ID is passed as parameter +def viewCloned( viewID ): + pass + +# called when active view is viewClosed +# view ID is passed as parameter +def viewClosed( viewID ): + pass + diff --git a/src/daSalome/daGUI/daGuiImpl/Makefile.am b/src/daSalome/daGUI/daGuiImpl/Makefile.am new file mode 100644 index 0000000..b0781de --- /dev/null +++ b/src/daSalome/daGUI/daGuiImpl/Makefile.am @@ -0,0 +1,30 @@ +# Copyright (C) 2010 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 +# + +include $(top_srcdir)/adm_local/make_common_starter.am + +mypkgpythondir =$(salomepythondir)/daGuiImpl + +mypkgpython_PYTHON = \ + __init__.py \ + DATASSIMGUI_impl.py \ + datassimGuiManager.py \ + enumerate.py + + diff --git a/src/daSalome/daGUI/daGuiImpl/__init__.py b/src/daSalome/daGUI/daGuiImpl/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py new file mode 100644 index 0000000..17f1ec7 --- /dev/null +++ b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py @@ -0,0 +1,63 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2010 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 +# + +""" +This file centralizes the definitions and implementations of ui components used +in the GUI part of the module. +""" + +__author__ = "aribes/gboulant" + +import traceback +from PyQt4.QtCore import QObject +import SalomePyQt +sgPyQt = SalomePyQt.SalomePyQt() + +from daGuiImpl.enumerate import Enumerate +# +# ============================================================================== +# Classes to manage the building of UI components +# ============================================================================== +# +UI_ELT_IDS = Enumerate([ + 'DATASSIM_MENU_ID', + ],offset=950) + +ACTIONS_MAP={ +} + +class DatassimGuiUiComponentBuilder: + """ + The initialisation of this class creates the graphic components involved + in the GUI (menu, menu item, toolbar). A ui component builder should be + created for each opened study and associated to its context (see usage in OMAGUI.py). + """ + def __init__(self): + self.initUiComponents() + + def initUiComponents(self): + + objectTR = QObject() + + # create top-level menu + mid = sgPyQt.createMenu( "DATASSIM", -1, UI_ELT_IDS.DATASSIM_MENU_ID, sgPyQt.defaultMenuGroup() ) + # create toolbar + tid = sgPyQt.createTool( "DATASSIM" ) + diff --git a/src/daSalome/daGUI/daGuiImpl/enumerate.py b/src/daSalome/daGUI/daGuiImpl/enumerate.py new file mode 100644 index 0000000..35bfdf6 --- /dev/null +++ b/src/daSalome/daGUI/daGuiImpl/enumerate.py @@ -0,0 +1,168 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# 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 +# + +__author__ = "gboulant" +__date__ = "$1 avr. 2010 09:08:02$" + +class Enumerate(object): + """ + This class emulates a C-like enum for python. + """ + def __init__(self, keys, offset=0): + """ + Canonical constructor + @keys a list of keys string to be used as the enum symbols + """ + self._dict_keynumbers = {} + for number, key in enumerate(keys): + value = offset+number + setattr(self, key, value) + self._dict_keynumbers[key] = value + + + def contains(self, key): + """ + Return true if this enumerate contains the specified key + @key a key to test + """ + return (key in self._dict_keynumbers.keys()) + + def isValid(self, value): + return (value in self._dict_keynumbers.values()) + + def listkeys(self): + list = self._dict_keynumbers.keys() + list.sort() + return list + + def listvalues(self): + list = self._dict_keynumbers.values() + list.sort() + return list + +# +# ============================================================================== +# Basic use cases and unit test functions +# ============================================================================== +# + +def TEST_simple(): + TYPES_LIST=Enumerate([ + 'SEP', + 'OTHER' + ]) + print TYPES_LIST.listvalues() + return True + +def TEST_createFromList(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH']) + + print codes.KERNEL + print codes.GEOM + if (codes.KERNEL == 0 and codes.GEOM == 2): + return True + else: + return False + +def TEST_createFromString(): + aList = "KERNEL GUI GEOM MED" + + codes = Enumerate(aList.split()) + + print codes.KERNEL + print codes.GEOM + if (codes.KERNEL == 0 and codes.GEOM == 2): + return True + else: + return False + +def TEST_contains(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH']) + + print "VISU in enumerate?", codes.contains("VISU") + if ( not codes.contains("VISU") ): + return True + else: + return False + +def TEST_isValid(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH']) + + if ( not codes.isValid(23) ): + return True + else: + return False + +def TEST_offset(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH'], offset=20) + + print codes.KERNEL + print codes.GEOM + if (codes.KERNEL == 20 and codes.GEOM == 22): + return True + else: + return False + +def TEST_listvalues(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH'], offset=20) + + print codes.listvalues() + if codes.listvalues() != [20,21,22,23,24]: + return False + return True + + +if __name__ == "__main__": + import unittester + unittester.run("enumerate","TEST_simple") + unittester.run("enumerate","TEST_createFromList") + unittester.run("enumerate","TEST_createFromString") + unittester.run("enumerate","TEST_contains") + unittester.run("enumerate","TEST_isValid") + unittester.run("enumerate","TEST_offset") + unittester.run("enumerate","TEST_listvalues") -- 2.39.2