2 #include "nodeEdition.h"
3 #include "guiContext.hxx"
5 #include "InlineNode.hxx"
6 #include "TypeCode.hxx"
10 #include <qpushbutton.h>
13 #ifdef HAVE_QEXTSCINTILLA_H
14 #include <qextscintilla.h>
15 #include <qextscintillalexerpython.h>
19 #include "YacsTrace.hxx"
27 using namespace YACS::HMI;
29 #ifdef HAVE_QEXTSCINTILLA_H
30 class myQextScintilla: public QextScintilla
33 myQextScintilla(QWidget *parent=0, const char *name=0, WFlags f=0)
34 : QextScintilla(parent, name, f) {};
36 virtual QSize sizeHint() const { return QSize(350, 150); };
40 itemEdition::itemEdition(Subject* subject)
41 : GuiObserver(), _subject(subject)
43 _subject->attach(this);
45 _name = _subject->getName();
47 _category = "Unknown";
48 ProcInvoc* invoc = GuiContext::getCurrent()->getInvoc();
49 if (SubjectNode * sub = dynamic_cast<SubjectNode*>(_subject))
52 _type = invoc->getTypeName(invoc->getTypeOfNode(sub->getNode()));
54 else if (SubjectDataPort * sub = dynamic_cast<SubjectDataPort*>(_subject))
57 _type = invoc->getTypeName(invoc->getTypeOfPort(sub->getPort()));
59 else if (SubjectLink * sub = dynamic_cast<SubjectLink*>(_subject))
64 else if (SubjectControlLink * sub = dynamic_cast<SubjectControlLink*>(_subject))
66 _category = "ControlLink";
67 _type = "Control Link";
69 else if (SubjectDataType * sub = dynamic_cast<SubjectDataType*>(_subject))
72 switch (sub->getTypeCode()->kind())
74 case YACS::ENGINE::Double: _type = "Double"; break;
75 case YACS::ENGINE::Int: _type = "Int"; break;
76 case YACS::ENGINE::String: _type = "String"; break;
77 case YACS::ENGINE::Bool: _type = "Bool"; break;
78 case YACS::ENGINE::Objref: _type = "Objref"; break;
79 case YACS::ENGINE::Sequence: _type = "Sequence"; break;
80 case YACS::ENGINE::Array: _type = "Array"; break;
81 case YACS::ENGINE::Struct: _type = "Struct"; break;
82 default: _type = "None or Unknown";
85 else if (SubjectComponent * sub = dynamic_cast<SubjectComponent*>(_subject))
87 _category = "Component";
88 _type = "Salome Component";
90 else if (SubjectContainer * sub = dynamic_cast<SubjectContainer*>(_subject))
92 _category = "Container";
93 _type = "Salome Container";
97 itemEdition::~itemEdition()
101 void itemEdition::select(bool isSelected)
103 DEBTRACE("NodeEdition::select " << isSelected);
105 GuiContext::getCurrent()->getWidgetStack()->raiseWidget(_stackId);
109 void itemEdition::update(GuiEvent event, int type, Subject* son)
113 Subject* itemEdition::getSubject()
119 NodeEdition::NodeEdition(Subject* subject,
123 : wiNodeEdition(parent, name, fl), itemEdition(subject)
125 DEBTRACE("NodeEdition::NodeEdition " << name);
126 string category = _category + " type:";
127 laNodeType->setText(category.c_str());
128 category = _category + " name:";
129 laNodeName->setText(category.c_str());
130 liNodeType->setText(_type);
131 liNodeName->setText(_name.c_str());
132 liNodeType->setText(_type);
140 if (_subFuncNode = dynamic_cast<SubjectPyFuncNode*>(_subject))
141 if (YACS::ENGINE::InlineFuncNode *pyFuncNode
142 = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(_subFuncNode->getNode()))
144 _funcName = pyFuncNode->getFname();
145 QLabel* laFuncName = new QLabel( this, "laFuncName" );
146 layout5->addWidget( laFuncName );
147 laFuncName->setText("Function Name:");
148 _liFuncName = new QLineEdit( this, "liFuncName" );
149 layout5->addWidget( _liFuncName );
150 _liFuncName->setText(_funcName);
151 connect(_liFuncName, SIGNAL(textChanged(const QString&)), this, SLOT(onFuncNameModified(const QString&)));
154 if (_subInlineNode = dynamic_cast<SubjectInlineNode*>(_subject))
157 #ifdef HAVE_QEXTSCINTILLA_H
158 _sci = new myQextScintilla( this, "Python Editor" );
160 _sci = new QTextEdit( this, "Python Editor" );
162 wiNodeEditionLayout->removeItem(spacer2);
163 layout5->addWidget( _sci );
164 #ifdef HAVE_QEXTSCINTILLA_H
166 QextScintillaLexerPython *lex = new QextScintillaLexerPython(_sci);
168 _sci->setBraceMatching(QextScintilla::SloppyBraceMatch);
169 _sci->setAutoIndent(1);
170 _sci->setIndentationWidth(4);
171 _sci->setIndentationGuides(1);
172 _sci->setIndentationsUseTabs(0);
173 _sci->setAutoCompletionThreshold(2);
175 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(_subInlineNode->getNode()))
177 _sci->append(pyNode->getScript());
179 connect(_sci, SIGNAL(textChanged()), this, SLOT(onScriptModified()));
181 _stackId = GuiContext::getCurrent()->getWidgetStack()->addWidget(this);
182 DEBTRACE("_stackId " << _stackId);
183 //GuiContext::getCurrent()->getWidgetStack()->raiseWidget(_stackId);
186 NodeEdition::~NodeEdition()
190 void NodeEdition::setName(std::string name)
196 void NodeEdition::onApply()
198 string name = liNodeName->text().latin1();
199 bool nameEdited = false;
203 bool ret = _subject->setName(name);
210 bool funcNameEdited = false;
213 funcNameEdited = true;
214 string funcName = _liFuncName->text().latin1();
215 if (funcName != _funcName)
217 bool ret = _subFuncNode->setFunctionName(funcName);
220 funcNameEdited = false;
221 _funcName = funcName;
225 bool scriptEdited = false;
228 if (_sci->isModified())
231 bool ret = _subInlineNode->setScript(_sci->text().latin1());
234 scriptEdited = false;
238 bool edited = nameEdited || funcNameEdited || scriptEdited;
242 void NodeEdition::onCancel()
244 liNodeName->setText(_name.c_str());
246 _sci->setText(_subInlineNode->getScript());
248 _liFuncName->setText(_funcName);
252 void NodeEdition::onModify(const QString &text)
254 if (_name != text.latin1()) setEdited(true);
257 void NodeEdition::onFuncNameModified(const QString &text)
259 if (_funcName != text.latin1()) setEdited(true);
262 void NodeEdition::onScriptModified()
267 void NodeEdition::setEdited(bool isEdited)
269 btApply->setEnabled(isEdited);
270 btCancel->setEnabled(isEdited);
273 void NodeEdition::update(GuiEvent event, int type, Subject* son)
275 DEBTRACE("NodeEdition::update ");
276 NodeEdition *item = 0;
280 item = new NodeEdition(son,
281 GuiContext::getCurrent()->getWidgetStack(),
282 son->getName().c_str());
287 case YACS::HMI::SALOMEPROC:
288 case YACS::HMI::BLOC:
289 case YACS::HMI::FOREACHLOOP:
290 case YACS::HMI::OPTIMIZERLOOP:
291 case YACS::HMI::FORLOOP:
292 case YACS::HMI::WHILELOOP:
293 case YACS::HMI::SWITCH:
294 case YACS::HMI::PYTHONNODE:
295 case YACS::HMI::PYFUNCNODE:
296 case YACS::HMI::CORBANODE:
297 case YACS::HMI::SALOMENODE:
298 case YACS::HMI::CPPNODE:
299 case YACS::HMI::SALOMEPYTHONNODE:
300 case YACS::HMI::XMLNODE:
301 case YACS::HMI::PRESETNODE:
302 case YACS::HMI::OUTNODE:
303 case YACS::HMI::STUDYINNODE:
304 case YACS::HMI::STUDYOUTNODE:
305 case YACS::HMI::SPLITTERNODE:
306 case YACS::HMI::DFTODSFORLOOPNODE:
307 case YACS::HMI::DSTODFFORLOOPNODE:
308 case YACS::HMI::INPUTPORT:
309 case YACS::HMI::OUTPUTPORT:
310 case YACS::HMI::INPUTDATASTREAMPORT:
311 case YACS::HMI::OUTPUTDATASTREAMPORT:
312 case YACS::HMI::CONTAINER:
313 case YACS::HMI::COMPONENT:
314 case YACS::HMI::REFERENCE:
315 case YACS::HMI::DATATYPE:
316 item = new NodeEdition(son,
317 GuiContext::getCurrent()->getWidgetStack(),
318 son->getName().c_str());
321 DEBTRACE("NodeEdition::update() ADD, type not handled:" << type);
327 case YACS::HMI::DATALINK:
328 item = new NodeEdition(son,
329 GuiContext::getCurrent()->getWidgetStack(),
330 son->getName().c_str());
333 DEBTRACE("NodeEdition::update() ADDLINK, type not handled:" << type);
339 case YACS::HMI::CONTROLLINK:
340 item = new NodeEdition(son,
341 GuiContext::getCurrent()->getWidgetStack(),
342 son->getName().c_str());
345 DEBTRACE("NodeEdition::update() ADDCONTROLLINK, type not handled:" << type);
349 DEBTRACE("NodeEdition::update(), event not handled: " << event);