1 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from qtsalome import *
22 from omniORB import CORBA
23 from SALOME_NamingServicePy import *
24 from LifeCycleCORBA import *
26 import SALOMEDS_Attributes_idl
29 ################################################
34 __MODULE_NAME__ = "ATOMGEN"
37 __CMD_IMPORT_XML__ = 4000
38 __CMD_EXPORT_XML__ = 4001
39 __CMD_RUN_ALGO__ = 4002
40 __CMD_RUN_ALGO1__ = 4010
45 ################################################
48 # get SALOME PyQt interface
50 sgPyQt = SalomePyQt.SalomePyQt()
52 # get SALOME Swig interface
54 sg = libSALOME_Swig.SALOMEGUI_Swig()
56 ################################################
57 # Global intializations
60 orb = CORBA.ORB_init( [''], CORBA.ORB_ID )
62 # create naming service instance
63 naming_service = SALOME_NamingServicePy_i( orb )
65 # create life cycle CORBA instance
66 lcc = LifeCycleCORBA( orb )
68 ################################################
75 return qApp.translate( "ATOMGENGUI", s )
77 def processException( e ):
81 print "Exception has been caught:", e
84 def warning( message, title = None ):
86 Show Warning message box
88 if not title: title = tr( "WARNING" )
89 QMessageBox.warning( sgPyQt.getDesktop(), title, message )
92 # --- get ATOMGEN engine ---
100 engine = lcc.FindOrLoadComponent( "FactoryServerPy", __MODULE_NAME__ )
103 # --- get active study ---
108 obj = naming_service.Resolve( '/Study' )
109 study = obj._narrow( SALOMEDS.Study )
114 ################################################
115 # Call back GUI methods
120 This method is called when GUI module is being created
122 Creates menus, toolbars and performs other internal
125 print "ATOMGENGUI::initialize"
126 global __study_data__
127 # get selection object
128 selection = sgPyQt.getSelection()
129 selection.ClearIObjects()
130 __study_data__[ "selection" ] = selection
131 print "ATOMGENGUI::initialize done"
136 This method is called when GUI module is being created
138 Should return a map of the SALOME dockable windows id's
139 needed to be opened when module is activated.
141 print "ATOMGENGUI::windows"
143 winMap[ SalomePyQt.WT_ObjectBrowser ] = Qt.LeftDockWidgetArea
144 winMap[ SalomePyQt.WT_PyConsole ] = Qt.BottomDockWidgetArea
149 This method is called when GUI module is being created
151 Should return a list of the SALOME view window types
152 needed to be opened when module is activated.
154 print "ATOMGENGUI::views"
159 This method is called when GUI module is being activated.
161 print "ATOMGENGUI::activate"
164 global __study_data__
165 myStudy = _getStudy()
166 _getEngine().study = myStudy
169 __study_data__[ "actions" ] = {}
170 a = sgPyQt.createAction( __CMD_IMPORT_XML__,
171 tr( "MEN_IMPORT_XML" ),
172 tr( "TOP_IMPORT_XML" ),
173 tr( "STB_IMPORT_XML" ) )
174 __study_data__[ "actions" ][ __CMD_IMPORT_XML__ ] = a
175 a = sgPyQt.createAction( __CMD_EXPORT_XML__,
176 tr( "MEN_EXPORT_XML" ),
177 tr( "TOP_EXPORT_XML" ),
178 tr( "STB_EXPORT_XML" ) )
179 __study_data__[ "actions" ][ __CMD_EXPORT_XML__ ] = a
182 fileMnu = sgPyQt.createMenu( QApplication.translate( "ATOMGENGUI", "MEN_FILE" ), -1, -1 )
183 sgPyQt.createMenu( sgPyQt.createSeparator(), fileMnu, -1, 20 )
184 sgPyQt.createMenu( __CMD_IMPORT_XML__, fileMnu, 20 )
185 sgPyQt.createMenu( __CMD_EXPORT_XML__, fileMnu, 20 )
186 sgPyQt.createMenu( sgPyQt.createSeparator(), fileMnu, -1, 20 )
189 selection = __study_data__[ "selection" ]
190 selection.ClearIObjects()
191 selection.currentSelectionChanged.connect( selectionChanged )
200 This method is called when GUI module is being deactivated.
202 print "ATOMGENGUI::deactivate"
205 selection = __study_data__[ "selection" ]
206 selection.ClearIObjects()
207 selection.currentSelectionChanged.disconnect( selectionChanged )
215 def createPopupMenu( popup, context ):
217 This method is called when popup menu is requested
219 Should analyze the selection and fill in the popup menu
220 with the corresponding actions
222 print "ATOMGENGUI::createPopupMenu: popup =", popup, "; context =", context
223 selected = selectedItems()
225 for entry in selected:
226 sobject = myStudy.FindObjectID( entry )
227 if sobject and sobject.GetObject() and sobject.GetObject()._narrow( ATOMGEN_ORB.Molecule ):
231 a = sgPyQt.action( __CMD_RUN_ALGO__ )
232 if isOk and a and context == "ObjectBrowser":
237 def OnGUIEvent( commandId ):
239 This method is called when user activates some GUI action
240 <commandId> is an ID of the GUI action.
242 print "ATOMGENGUI::OnGUIEvent: commandId =", commandId
243 if dict_command.has_key( commandId ):
245 dict_command[ commandId ]()
247 processException( e )
249 print "ATOMGENGUI::OnGUIEvent: Action is not implemented: ", commandId
252 ################################################
253 # GUI actions implementation
255 from rundlg_ui import Ui_RunDlg
257 class RunDlg(QDialog, Ui_RunDlg):
259 Run Algo simple dialog box
265 QDialog.__init__(self, sgPyQt.getDesktop())
269 self.selectionChanged()
272 def onCheckAll(self):
274 Called when user switches <Process all> check box
276 self.acLab.setEnabled( not self.allCheck.isChecked() )
277 self.acName.setEnabled( not self.allCheck.isChecked() )
279 selection = __study_data__[ "selection" ]
280 if not self.allCheck.isChecked():
281 selection.currentSelectionChanged.connect(self.selectionChanged)
283 selection.currentSelectionChanged.connect(self.selectionChanged)
286 def selectionChanged(self):
288 Called when selection is changed
291 selected = selectedItems()
292 for entry in selected:
293 sobject = myStudy.FindObjectID(entry)
295 obj = sobject.GetObject()
296 if obj and obj._narrow( ATOMGEN_ORB.Molecule ):
297 self.selected.append( obj._narrow( ATOMGEN_ORB.Molecule ) )
298 if len( self.selected ) == 1:
299 self.acName.setText( self.selected[0].getName() )
300 elif len( self.selected ) > 1:
301 self.acName.setText(" %d objects selected"%len( self.selected ) )
303 self.acName.setText( "" )
310 data = [] # all data to be processed
311 if not self.allCheck.isChecked():
314 component = myStudy.FindComponent( "ATOMGEN" )
315 if not component: return
316 iter = myStudy.NewChildIterator( component )
318 sobject = iter.Value()
319 if sobject and sobject.GetObject() and sobject.GetObject()._narrow ( ATOMGEN_ORB.Molecule ):
320 data.append( sobject.GetObject()._narrow( ATOMGEN_ORB.Molecule ) )
323 if not len( data ): return
324 if not len(_getEngine().processData( data )):
325 warning( "ALGO_ERROR" )
327 sgPyQt.updateObjBrowser()
343 Gets list of entries of selected objects
345 nbSel = sg.SelectedCount()
347 for i in range(nbSel):
348 selected.append(sg.getSelected(i))
351 def selectionChanged():
353 Global selection changed slot
355 selected = selectedItems()
356 print "--> Selected objects: %d"%len(selected)
361 Import XML file action slot
363 print "--> onImportXml() is started"
365 filters.append( tr( "XML_FILES" ) )
366 fileName = sgPyQt.getFileName( sgPyQt.getDesktop(),
371 fileName = unicode(fileName)
373 if len(fileName) > 0 :
374 if not _getEngine().importXmlFile( str( fileName ) ):
375 warning( "IMPORT_ERROR" )
377 sgPyQt.updateObjBrowser()
378 print "--> onImportXml() is finished"
383 Export XML file action slot
385 print "--> onExportXml() is started"
387 filters.append( tr( "XML_FILES" ) )
388 fileName = sgPyQt.getFileName( sgPyQt.getDesktop(),
393 fileName = unicode(fileName)
395 if len(fileName) > 0 :
396 if not _getEngine().exportXmlFile( str( fileName ) ):
397 warning( "EXPORT_ERROR" )
398 print "--> onExportXml() is finished"
402 print "--> onRunAlgo() is started !!!"
407 myRunDlg.activateWindow()
409 print "--> onRunAlgol() is finished"
412 ################################################
413 # action-to-function map
416 __CMD_IMPORT_XML__ : onImportXml,
417 __CMD_EXPORT_XML__ : onExportXml,
418 __CMD_RUN_ALGO__ : onRunAlgo,
419 __CMD_RUN_ALGO1__ : onRunAlgo,