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>
100 using namespace YACS::ENGINE;
101 using namespace YACS::HMI;
106 Class : YACSGui_ForEachLoopNodePage
107 Description : Page for FOREACH node properties
110 YACSGui_ForEachLoopNodePage::YACSGui_ForEachLoopNodePage( QWidget* theParent, const char* theName, WFlags theFlags )
111 : ForEachLoopNodePage( theParent, theName, theFlags ),
114 connect( myDataPortToDispatchValue, SIGNAL( textChanged( const QString& ) ),
115 this, SLOT( onSeqOfSamplesChanged( const QString& ) ) );
117 // TODO: implement presentation of the FOR node in collapsed mode
118 // temporary solution :
119 myCollapsedRadioButton->setEnabled(false );
121 connect( myNodeName, SIGNAL(textChanged( const QString& )), this, SLOT(onNodeNameChanged( const QString& )) );
124 YACSGui_ForEachLoopNodePage::~YACSGui_ForEachLoopNodePage()
126 if (getInputPanel()) getInputPanel()->removePage(this);
129 void YACSGui_ForEachLoopNodePage::setSNode( YACS::HMI::SubjectNode* theSNode )
131 if ( !theSNode ) return;
133 if ( dynamic_cast<ForEachLoop*>( theSNode->getNode() ) )
134 YACSGui_NodePage::setSNode( theSNode );
137 void YACSGui_ForEachLoopNodePage::setMode( const YACSGui_InputPanel::PageMode theMode )
139 YACSGui_NodePage::setMode(theMode);
141 if ( myMode == YACSGui_InputPanel::EditMode )
143 myNodeName->setReadOnly(false);
144 ViewModeButtonGroup->show();
146 ExecutionGroupBox->hide();
148 else if ( myMode == YACSGui_InputPanel::RunMode )
150 myNodeName->setReadOnly(true);
151 ViewModeButtonGroup->hide();
153 ExecutionGroupBox->show();
157 void YACSGui_ForEachLoopNodePage::notifyNodeStatus( int theStatus )
161 myNodeState->setPaletteForegroundColor(getColor(theStatus));
162 myNodeState->setText(getText(theStatus));
166 void YACSGui_ForEachLoopNodePage::notifyNodeProgress()
170 Proc* aProc = dynamic_cast<Proc*>(getNode()->getRootNode());
171 if ( !aProc ) return;
173 YACSGui_Graph* aGraph = getInputPanel()->getModule()->getGraph( aProc );
174 if ( !aGraph ) return;
176 if ( YACSPrs_ElementaryNode* anItem = aGraph->getItem(getNode()) )
178 int aProgress = (int)( ( (anItem->getStoredPercentage() < 0) ? anItem->getPercentage() :
179 anItem->getStoredPercentage() ) );
180 myProgressBar->setProgress(aProgress);
185 void YACSGui_ForEachLoopNodePage::notifyInPortValues( std::map<std::string,std::string> theInPortName2Value )
187 //printf("==> ForEachLoopNodePage : Size of theInPortName2Value : %d\n",theInPortName2Value.size());
189 ForEachLoop* aForEachLoopNode = dynamic_cast<ForEachLoop*>( getNode() );
190 if ( !aForEachLoopNode ) return;
192 if ( theInPortName2Value.size() == 2 )
194 QString aName1 = QString(aForEachLoopNode->edGetNbOfBranchesPort()->getName());
195 QString aName2 = QString(aForEachLoopNode->edGetSeqOfSamplesPort()->getName());
196 QString aGivenName, aValue;
198 map<string,string>::iterator it = theInPortName2Value.begin();
199 for ( ; it!=theInPortName2Value.end(); it++ )
201 aGivenName = QString( (*it).first );
202 aValue = QString( (*it).second );
204 if ( !aGivenName.compare(aName1) && myNbBranchesInputPortValue )
206 if ( !aValue.compare(QString("< ? >")) )
207 myNbBranchesInputPortValue->setValue( myNbBranchesInputPortValue->minValue() );
209 myNbBranchesInputPortValue->setValue( aValue.toInt() );
212 if ( !aGivenName.compare(aName2) && myDataPortToDispatchValue )
213 { // SmplsCollection port
214 myDataPortToDispatchValue->setText( aValue );
220 void YACSGui_ForEachLoopNodePage::notifyOutPortValues( std::map<std::string,std::string> theOutPortName2Value )
222 //printf("==> ForEachLoopNodePage : Size of theOutPortName2Value : %d\n",theOutPortName2Value.size());
223 // SmplPrt port (no gui control for it in the property page!)
227 void YACSGui_ForEachLoopNodePage::notifyNodeCreateBody( YACS::HMI::Subject* theSubject )
229 if( myLoopBodyNodeName )
231 QString aBodyName = theSubject->getName();
232 myLoopBodyNodeName->setText( aBodyName );
236 void YACSGui_ForEachLoopNodePage::checkModifications()
238 if ( !getNode() ) return;
240 // 1) check if the content of the page is really modified (in compare with the content of engine object)
241 bool isModified = false;
243 if ( myNodeName->text().compare(getNodeName()) != 0 ) isModified = true;
244 else if ( YACS::ENGINE::ForEachLoop* aForEachLoopNode = dynamic_cast<ForEachLoop*>( getNode() ) )
246 if( YACS::ENGINE::InputPort* aBranchesPort = aForEachLoopNode->edGetNbOfBranchesPort() )
249 int aValue = getPortValue( aBranchesPort ).toInt( &ok );
250 if( ok && myNbBranchesInputPortValue->value() != aValue ) isModified = true;
252 if( YACS::ENGINE::InputPort* aSamplesPort = aForEachLoopNode->edGetSeqOfSamplesPort() )
253 if ( myDataPortToDispatchValue->text().compare(getPortValue(aSamplesPort)) ) isModified = true;
257 // TODO: compare view mode: expanded or collapsed (not yet in use)
259 // 2) if yes, show a warning message: Apply or Cancel
261 if ( SUIT_MessageBox::warn2(getInputPanel()->getModule()->getApp()->desktop(),
263 tr("APPLY_CANCEL_MODIFICATIONS"),
264 tr("BUT_YES"), tr("BUT_NO"), 0, 1, 0) == 0 )
267 if ( getInputPanel() ) getInputPanel()->emitApply(YACSGui_InputPanel::InlineNodeId);
271 void YACSGui_ForEachLoopNodePage::onApply()
274 if ( myNodeName ) setNodeName( myNodeName->text() );
276 // Reset number of brances input port value and data port to dispatch value
277 if ( YACS::ENGINE::ForEachLoop* aForEachLoopNode = dynamic_cast<ForEachLoop*>( getNode() ) )
279 if( YACS::ENGINE::InputPort* aBranchesPort = aForEachLoopNode->edGetNbOfBranchesPort() )
281 int aValue = myNbBranchesInputPortValue->value();
282 aBranchesPort->edInit( aValue );
283 mySNode->update( EDIT, INPUTPORT, GuiContext::getCurrent()->_mapOfSubjectDataPort[aBranchesPort] );
286 if( YACS::ENGINE::InputPort* aSamplesPort = aForEachLoopNode->edGetSeqOfSamplesPort() )
288 QString aValue = myDataPortToDispatchValue->text();
289 aSamplesPort->edInit( aValue.latin1() );
290 mySNode->update( EDIT, INPUTPORT, GuiContext::getCurrent()->_mapOfSubjectDataPort[aSamplesPort] );
294 // Reset the view mode
300 void YACSGui_ForEachLoopNodePage::updateState()
303 if ( myNodeName ) myNodeName->setText( getNodeName() );
305 // Set node full name (read only)
306 if ( myNodeFullName )
307 myNodeFullName->setText( getNode()->getRootNode()->getChildName(getNode()) );
309 // Set number of brances input port value, data port to dispatch value and loop body node name
310 if ( YACS::ENGINE::ForEachLoop* aForEachLoopNode = dynamic_cast<ForEachLoop*>( getNode() ) )
312 if( YACS::ENGINE::InputPort* aBranchesPort = aForEachLoopNode->edGetNbOfBranchesPort() )
315 int aValue = getPortValue( aBranchesPort ).toInt( &ok );
316 if( ok && aValue > 1 )
317 myNbBranchesInputPortValue->setValue( aValue );
320 if( YACS::ENGINE::InputPort* aSamplesPort = aForEachLoopNode->edGetSeqOfSamplesPort() )
322 QString aValue = getPortValue( aSamplesPort );
323 myDataPortToDispatchValue->setText( aValue );
326 if( myLoopBodyNodeName )
328 std::list<Node*> aNodes = aForEachLoopNode->edGetDirectDescendants();
329 if ( !aNodes.empty() )
333 std::list<Node*>::iterator aNodesIt = aNodes.begin();
334 Node* aNode = *aNodesIt;
336 aBodyName = aNode->getName();
338 myLoopBodyNodeName->setText( aBodyName );
343 // Set view mode of the given FOREACH node
344 // the following method can be used if its needed:
345 // YACSGui_Graph* aGraph = getInputPanel()->getModule()->getGraph( myProc );
349 void YACSGui_ForEachLoopNodePage::onNodeNameChanged( const QString& theName )
351 if ( myNodeFullName )
353 QString anOldName = myNodeFullName->text();
354 int aRDotId = anOldName.findRev('.');
355 myNodeFullName->setText( anOldName.replace( aRDotId+1, anOldName.length()-(aRDotId+1), theName ) );
359 void YACSGui_ForEachLoopNodePage::onSeqOfSamplesChanged( const QString& theText )
362 QString aText = theText;
363 if( aText.left( 1 ) != "[" )
364 aText.prepend( "[" );
366 if( aText.right( 1 ) != "]" )
369 if( aText != theText )
370 myDataPortToDispatchValue->setText( aText );