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_ForLoopNodePage
110 Description : Page for FOR node properties
113 YACSGui_ForLoopNodePage::YACSGui_ForLoopNodePage( QWidget* theParent, const char* theName, WFlags theFlags )
114 : ForLoopNodePage( theParent, theName, theFlags ),
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_ForLoopNodePage::~YACSGui_ForLoopNodePage()
126 if (getInputPanel()) getInputPanel()->removePage(this);
129 void YACSGui_ForLoopNodePage::setSNode( YACS::HMI::SubjectNode* theSNode )
131 if ( !theSNode ) return;
133 if ( dynamic_cast<ForLoop*>( theSNode->getNode() ) )
134 YACSGui_NodePage::setSNode( theSNode );
137 void YACSGui_ForLoopNodePage::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_ForLoopNodePage::notifyNodeStatus( int theStatus )
161 myNodeState->setPaletteForegroundColor(getColor(theStatus));
162 myNodeState->setText(getText(theStatus));
166 void YACSGui_ForLoopNodePage::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_ForLoopNodePage::notifyInPortValues( std::map<std::string,std::string> theInPortName2Value )
187 DEBTRACE("==> ForLoopNodePage : Size of theInPortName2Value : " << theInPortName2Value.size());
189 ForLoop* aForLoopNode = dynamic_cast<ForLoop*>( getNode() );
190 if ( !aForLoopNode ) return;
192 if ( theInPortName2Value.size() == 1 )
195 QString aName(aForLoopNode->edGetNbOfTimesInputPort()->getName());
196 map<string,string>::iterator it = theInPortName2Value.begin();
197 QString aGivenName( (*it).first );
198 if ( !aGivenName.compare(aName) && myNbTimesInputPortValue )
200 QString aValue( (*it).second );
201 if ( !aValue.compare(QString("< ? >")) )
202 myNbTimesInputPortValue->setValue( myNbTimesInputPortValue->minValue() );
204 myNbTimesInputPortValue->setValue( aValue.toInt() );
209 void YACSGui_ForLoopNodePage::notifyOutPortValues( std::map<std::string,std::string> theOutPortName2Value )
211 DEBTRACE("==> ForLoopNodePage : " << theOutPortName2Value.size());
214 void YACSGui_ForLoopNodePage::notifyNodeCreateBody( YACS::HMI::Subject* theSubject )
216 DEBTRACE("YACSGui_ForLoopNodePage::notifyNodeCreateBody");
217 if( myLoopBodyNodeName )
219 QString aBodyName = theSubject->getName();
220 myLoopBodyNodeName->setText( aBodyName );
224 void YACSGui_ForLoopNodePage::checkModifications()
226 if ( !getNode() ) return;
228 // 1) check if the content of the page is really modified (in compare with the content of engine object)
229 bool isModified = false;
231 if ( myNodeName->text().compare(getNodeName()) != 0 ) isModified = true;
232 else if ( YACS::ENGINE::ForLoop* aForLoopNode = dynamic_cast<ForLoop*>( getNode() ) )
233 if( YACS::ENGINE::InputPort* aPort = aForLoopNode->edGetNbOfTimesInputPort() )
236 int aValue = getPortValue( aPort ).toInt( &ok );
237 if( ok && myNbTimesInputPortValue->value() != aValue ) isModified = true;
241 // TODO: compare view mode: expanded or collapsed (not yet in use)
243 // 2) if yes, show a warning message: Apply or Cancel
245 if ( SUIT_MessageBox::warn2(getInputPanel()->getModule()->getApp()->desktop(),
247 tr("APPLY_CANCEL_MODIFICATIONS"),
248 tr("BUT_YES"), tr("BUT_NO"), 0, 1, 0) == 0 )
251 if ( getInputPanel() ) getInputPanel()->emitApply(YACSGui_InputPanel::InlineNodeId);
255 void YACSGui_ForLoopNodePage::onApply()
257 DEBTRACE("YACSGui_ForLoopNodePage::onApply");
259 if ( myNodeName ) setNodeName( myNodeName->text() );
261 // Reset number of times input port value
262 if ( YACS::ENGINE::ForLoop* aForLoopNode = dynamic_cast<ForLoop*>( getNode() ) )
264 if( YACS::ENGINE::InputPort* aPort = aForLoopNode->edGetNbOfTimesInputPort() )
266 int aValue = myNbTimesInputPortValue->value();
267 aPort->edInit( aValue );
268 mySNode->update( EDIT, INPUTPORT, GuiContext::getCurrent()->_mapOfSubjectDataPort[aPort] );
272 // Reset the view mode
278 void YACSGui_ForLoopNodePage::updateState()
280 DEBTRACE("YACSGui_ForLoopNodePage::updateState");
282 if ( myNodeName ) myNodeName->setText( getNodeName() );
284 // Set node full name (read only)
285 if ( myNodeFullName )
286 myNodeFullName->setText( getNode()->getRootNode()->getChildName(getNode()) );
288 // Set number of times input port value and loop body node name
289 if ( YACS::ENGINE::ForLoop* aForLoopNode = dynamic_cast<ForLoop*>( getNode() ) )
291 if( YACS::ENGINE::InputPort* aPort = aForLoopNode->edGetNbOfTimesInputPort() )
294 int aValue = getPortValue( aPort ).toInt( &ok );
295 if( ok && aValue > 1 )
296 myNbTimesInputPortValue->setValue( aValue );
299 if( myLoopBodyNodeName )
301 std::list<Node*> aNodes = aForLoopNode->edGetDirectDescendants();
302 if ( !aNodes.empty() )
306 std::list<Node*>::iterator aNodesIt = aNodes.begin();
307 Node* aNode = *aNodesIt;
309 aBodyName = aNode->getName();
311 myLoopBodyNodeName->setText( aBodyName );
316 // Set view mode of the given FOR node
317 // the following method can be used if its needed:
318 // YACSGui_Graph* aGraph = getInputPanel()->getModule()->getGraph( myProc );
322 void YACSGui_ForLoopNodePage::onNodeNameChanged( const QString& theName )
324 if ( myNodeFullName )
326 QString anOldName = myNodeFullName->text();
327 int aRDotId = anOldName.findRev('.');
328 myNodeFullName->setText( anOldName.replace( aRDotId+1, anOldName.length()-(aRDotId+1), theName ) );