1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <PythonNode.hxx>
24 #include <SALOME_ResourcesManager.hxx>
25 #include <SALOME_LifeCycleCORBA.hxx>
27 #include <YACSGui_InputPanel.h>
28 #include <YACSGui_Module.h>
29 #include <YACSGui_PlusMinusGrp.h>
30 #include <YACSGui_Table.h>
31 #include <YACSGui_Graph.h>
32 #include <YACSGui_Executor.h>
33 #include <YACSGui_TreeView.h>
34 #include <YACSGui_TreeViewItem.h>
35 #include <YACSGui_LogViewer.h>
37 #include <YACSPrs_ElementaryNode.h>
39 #include <QxGraph_Canvas.h>
41 #include <LightApp_Application.h>
42 #include <CAM_Application.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_Application.h>
45 #include <SUIT_MessageBox.h>
46 #include <LogWindow.h>
49 #include <OutPort.hxx>
50 #include <InputPort.hxx>
51 #include <OutputPort.hxx>
52 #include <CalStreamPort.hxx>
53 #include <ConditionInputPort.hxx>
54 #include <ForLoop.hxx>
55 #include <ForEachLoop.hxx>
56 #include <WhileLoop.hxx>
58 #include <CORBAPorts.hxx>
59 #include <PythonPorts.hxx>
60 #include <XMLPorts.hxx>
61 #include <InlineNode.hxx>
62 #include <ServiceNode.hxx>
63 #include <ServiceInlineNode.hxx>
64 #include <CORBANode.hxx>
65 #include <SalomePythonNode.hxx>
66 #include <CppNode.hxx>
67 #include <XMLNode.hxx>
68 #include <Exception.hxx>
69 #include <Catalog.hxx>
70 #include <ComponentDefinition.hxx>
71 #include <CORBAComponent.hxx>
72 #include <CppComponent.hxx>
73 #include <SalomeComponent.hxx>
74 #include <SalomePythonComponent.hxx>
75 #include <RuntimeSALOME.hxx>
77 #include <qwindowsstyle.h>
78 #include <qpushbutton.h>
82 #include <qlineedit.h>
83 #include <qbuttongroup.h>
84 #include <qradiobutton.h>
85 #include <qcombobox.h>
86 #include <qtextedit.h>
87 #include <qtoolbutton.h>
89 #include <qprogressbar.h>
90 #include <qobjectlist.h>
91 #include <qfiledialog.h>
92 #include <qcheckbox.h>
97 #include "YacsTrace.hxx"
102 using namespace YACS;
103 using namespace YACS::ENGINE;
104 using namespace YACS::HMI;
109 Class : YACSGui_ContainerPage
110 Description : Page for container properties
113 YACSGui_ContainerPage::YACSGui_ContainerPage( QWidget* theParent, const char* theName, WFlags theFlags )
114 : ContainerPage( theParent, theName, theFlags ),
118 showAdvanced->setChecked(false);
120 connect(showAdvanced, SIGNAL(clicked()), this, SLOT(onShowAdvanced()));
123 YACSGui_ContainerPage::~YACSGui_ContainerPage()
125 if (getInputPanel()) getInputPanel()->removePage(this);
127 if ( mySContainer ) mySContainer->detach(this);
130 void YACSGui_ContainerPage::select( bool isSelected )
132 DEBTRACE(">> YACSGui_ContainerPage::select");
135 void YACSGui_ContainerPage::update( YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
137 DEBTRACE(">> YACSGui_ContainerPage::update");
142 if ( !type && !son && mySContainer )
144 mySContainer->detach(this);
150 GuiObserver::update(event, type, son);
154 void YACSGui_ContainerPage::setSContainer(YACS::HMI::SubjectContainer* theSContainer )
156 if ( mySContainer != theSContainer )
158 if ( mySContainer ) mySContainer->detach(this); //detach from old container
159 mySContainer = theSContainer;
160 if ( mySContainer ) mySContainer->attach(this); // attach to new container
168 // set "Container Name" fields to read only if the user is editing a service node
169 ServiceNode* aService = 0;
170 if ( YACSGui_EditionTreeView * aETV =
171 dynamic_cast<YACSGui_EditionTreeView*>(getInputPanel()->getModule()->activeTreeView()) )
173 std::list<QListViewItem*> aList = aETV->getSelected();
175 if ( YACSGui_NodeViewItem* aNode = dynamic_cast<YACSGui_NodeViewItem*>(aList.front()) )
176 aService = dynamic_cast<ServiceNode*>(aNode->getNode());
181 myDefinitionName->setReadOnly(true);
182 myExecutionName->setReadOnly(true);
186 myDefinitionName->setReadOnly(false);
187 myExecutionName->setReadOnly(false);
192 YACS::ENGINE::Container* YACSGui_ContainerPage::getContainer() const
194 return ( mySContainer ? mySContainer->getContainer() : 0 );
197 YACS::ENGINE::SalomeContainer* YACSGui_ContainerPage::getSalomeContainer() const
199 return ( mySContainer ? dynamic_cast<SalomeContainer*>(mySContainer->getContainer()) : 0 );
202 QString YACSGui_ContainerPage::getDefinitionName() const
204 return ( mySContainer ? QString( mySContainer->getName() ) : QString("") );
207 bool YACSGui_ContainerPage::setDefinitionName( const QString& theName )
209 DEBTRACE("YACSGui_ContainerPage::setDefinitionName " << theName.latin1());
210 // --- TODO: create a command in hmi for container rename.
212 bool alreadyExists = false;
213 GuiContext* aContext = GuiContext::getCurrent();
214 if ( getContainer() )
216 map<Container*, SubjectContainer*>::const_iterator it;
217 for(it = aContext->_mapOfSubjectContainer.begin(); it !=aContext->_mapOfSubjectContainer.end(); ++it)
219 if ( QString::compare(theName, (*it).first->getName().c_str()) == 0)
228 DEBTRACE("set name " << theName.latin1());
229 string oldName = getContainer()->getName();
230 getContainer()->setName( theName.latin1() );
231 aContext->getProc()->containerMap.erase(oldName);
232 aContext->getProc()->containerMap[theName.latin1()] = getContainer();
234 mySContainer->update( RENAME, 0, mySContainer );
240 QString YACSGui_ContainerPage::getExecutionName() const
243 if (getSalomeContainer())
245 string nc = getSalomeContainer()->getProperty("container_name");
251 void YACSGui_ContainerPage::setExecutionName( const QString& theName )
253 if ( getSalomeContainer() )
255 getSalomeContainer()->setProperty( "container_name", theName.latin1() );
256 mySContainer->update( RENAME, 0, mySContainer );
260 YACSGui_InputPanel* YACSGui_ContainerPage::getInputPanel() const
262 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
266 YACSGui_Module* aModule = dynamic_cast<YACSGui_Module*>( anApp->activeModule() );
270 return aModule->getInputPanel();
273 void YACSGui_ContainerPage::fillHostNames() const
275 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
276 SALOME_NamingService* namingService = anApp->namingService();
278 CORBA::Object_var obj = namingService->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
279 if ( !CORBA::is_nil(obj) )
280 if ( Engines::ResourcesManager_var aResManager=Engines::ResourcesManager::_narrow(obj) )
282 Engines::CompoList aCompoList ;
283 Engines::MachineParameters params;
284 anApp->lcc()->preSet(params);
286 Engines::MachineList* aMachineList = aResManager->GetFittingResources( params, aCompoList );
289 myHostName->insertItem( QString("localhost") );
290 for ( unsigned int i = 0; i < aMachineList->length(); i++ )
292 const char* aMachine = (*aMachineList)[i];
293 myHostName->insertItem( QString(aMachine) );
298 QString YACSGui_ContainerPage::getHostName() const
300 if ( getSalomeContainer() )
302 QString aHN(getSalomeContainer()->_params.hostname);
309 void YACSGui_ContainerPage::setHostName( const QString& theHostName )
311 if ( getSalomeContainer() )
312 getSalomeContainer()->setProperty( "hostname", theHostName.latin1() );
315 int YACSGui_ContainerPage::getMemMb() const
317 return ( getSalomeContainer() ? getSalomeContainer()->_params.mem_mb : 0 );
320 void YACSGui_ContainerPage::setMemMb(const int theMem)
322 if ( getSalomeContainer() )
323 getSalomeContainer()->setProperty( "mem_mb", QString("%1").arg(theMem).latin1() );
326 int YACSGui_ContainerPage::getCpuClock() const
328 return ( getSalomeContainer() ? getSalomeContainer()->_params.cpu_clock : 0 );
331 void YACSGui_ContainerPage::setCpuClock(const int theClock)
333 if ( getSalomeContainer() )
334 getSalomeContainer()->setProperty( "cpu_clock", QString("%1").arg(theClock).latin1() );
337 int YACSGui_ContainerPage::getNbProcPerNode() const
339 return ( getSalomeContainer() ? getSalomeContainer()->_params.nb_proc_per_node : 0 );
342 void YACSGui_ContainerPage::setNbProcPerNode(const int theNbProc)
344 if ( getSalomeContainer() )
345 getSalomeContainer()->setProperty( "nb_proc_per_node", QString("%1").arg(theNbProc).latin1() );
348 int YACSGui_ContainerPage::getNbNode() const
350 return ( getSalomeContainer() ? getSalomeContainer()->_params.nb_node : 0 );
353 void YACSGui_ContainerPage::setNbNode(const int theNbNode)
355 if ( getSalomeContainer() )
356 getSalomeContainer()->setProperty( "nb_node", QString("%1").arg(theNbNode).latin1() );
359 bool YACSGui_ContainerPage::getMpiUsage() const
361 return ( getSalomeContainer() ? getSalomeContainer()->_params.isMPI : false );
364 void YACSGui_ContainerPage::setMpiUsage(const bool on)
366 if ( getSalomeContainer() )
367 getSalomeContainer()->setProperty( "isMPI", on ? "true" : "false" );
370 QString YACSGui_ContainerPage::getParallelLib() const
372 return ( getSalomeContainer() ? QString(getSalomeContainer()->_params.parallelLib) : QString("") );
375 void YACSGui_ContainerPage::setParallelLib( const QString& theLib)
377 if ( getSalomeContainer() )
378 getSalomeContainer()->setProperty( "parallelLib", theLib.latin1() );
381 int YACSGui_ContainerPage::getNbComponentNodes() const
383 return ( getSalomeContainer() ? getSalomeContainer()->_params.nb_component_nodes : 0 );
386 void YACSGui_ContainerPage::setNbComponentNodes(const int theNbComponentNodes)
388 if ( getSalomeContainer() )
389 getSalomeContainer()->setProperty( "nb_component_nodes", QString("%1").arg(theNbComponentNodes).latin1() );
392 QString YACSGui_ContainerPage::getWorkingDir() const
394 return ( getSalomeContainer() ? QString(getSalomeContainer()->_params.workingdir) : QString("") );
397 void YACSGui_ContainerPage::setWorkingDir( const QString& theWD)
399 if ( getSalomeContainer() )
400 getSalomeContainer()->setProperty( "workingdir", theWD.latin1() );
403 void YACSGui_ContainerPage::checkModifications( bool& theWarnToShow, bool& theToApply )
405 if ( !getContainer() || !theWarnToShow && !theToApply ) return;
407 // 1) check if the content of the page is really modified (in compare with the content of engine object)
408 bool isModified = false;
409 if ( myDefinitionName->text().compare(getDefinitionName()) != 0
411 myExecutionName->text().compare(getExecutionName()) != 0
413 myHostName->currentText().compare(getHostName()) != 0
415 myMemMb->value() != getMemMb()
417 myCpuClock->value() != getCpuClock()
419 myNbProcPerNode->value() != getNbProcPerNode()
421 myNbNode->value() != getNbNode()
423 ( myMpiUsage->currentItem() ? false : true ) != getMpiUsage()
425 myParallelLib->text().compare(getParallelLib()) != 0
427 myNbComponentNodes->value() != getNbComponentNodes()
429 myWorkingDir->text().compare(getWorkingDir()) != 0
432 // 2) if yes, show a warning message: Apply or Cancel
436 theWarnToShow = false;
437 if ( SUIT_MessageBox::warn2(getInputPanel()->getModule()->getApp()->desktop(),
439 tr("APPLY_CANCEL_MODIFICATIONS"),
440 tr("BUT_YES"), tr("BUT_NO"), 0, 1, 0) == 0 )
444 if ( getInputPanel() ) getInputPanel()->emitApply(YACSGui_InputPanel::ContainerId);
449 else if ( theToApply )
452 if ( getInputPanel() ) getInputPanel()->emitApply(YACSGui_InputPanel::ContainerId);
456 void YACSGui_ContainerPage::onShowAdvanced()
458 if(showAdvanced->isChecked()) {
465 void YACSGui_ContainerPage::updateState()
467 // Set container name
469 if ( myDefinitionName )
471 QString defName = getDefinitionName();
472 if (QString::compare(defName, "DefaultContainer") == 0)
473 myDefinitionName->setReadOnly(true);
475 myDefinitionName->setReadOnly(false);
476 myDefinitionName->setText(defName);
480 if ( myExecutionName )
481 myExecutionName->setText(getExecutionName());
485 myHostName->setCurrentText(getHostName());
489 myMemMb->setValue(getMemMb());
493 myCpuClock->setValue(getCpuClock());
495 // Set nb_proc_per_node
496 if ( myNbProcPerNode )
497 myNbProcPerNode->setValue(getNbProcPerNode());
501 myNbNode->setValue(getNbNode());
505 myMpiUsage->setCurrentItem( getMpiUsage() ? 0 : 1 );
507 // Set parallel library
509 myParallelLib->setText(getParallelLib());
511 // Set nb_component_nodes
512 if ( myNbComponentNodes )
513 myNbComponentNodes->setValue(getNbComponentNodes());
515 // Set working directory
517 myWorkingDir->setText(getWorkingDir());
521 void YACSGui_ContainerPage::onApply()
523 if ( myDefinitionName )
524 if (! setDefinitionName(myDefinitionName->text().latin1()))
525 if (getContainer()) myDefinitionName->setText(getContainer()->getName());
527 if ( myExecutionName )
528 setExecutionName(myExecutionName->text().latin1());
531 setHostName(myHostName->currentText().latin1());
534 setMemMb(myMemMb->value());
537 setCpuClock(myCpuClock->value());
539 if ( myNbProcPerNode )
540 setNbProcPerNode(myNbProcPerNode->value());
543 setNbNode(myNbNode->value());
546 setMpiUsage( myMpiUsage->currentItem() ? false : true );
549 setParallelLib(myParallelLib->text().latin1());
551 if ( myNbComponentNodes )
552 setNbComponentNodes(myNbComponentNodes->value());
555 setWorkingDir(myWorkingDir->text().latin1());
557 //mySContainer->update( EDIT, 0, mySContainer );