Version: 8.3.0
YACS::HMI::EditionScript Class Reference

#include <EditionScript.hxx>

Inheritance diagram for YACS::HMI::EditionScript:
Collaboration diagram for YACS::HMI::EditionScript:

Public Slots

virtual void onApply ()
 
virtual void onCancel ()
 
virtual void onScriptModified ()
 
virtual void onEdit ()
 
virtual void on_tb_options_toggled (bool checked)
 
virtual void on_remote_toggled (bool checked)
 
virtual void fillContainerPanel ()
 
virtual void changeContainer (int)
 
virtual void update (GuiEvent event, int type, Subject *son)
 
- Public Slots inherited from YACS::HMI::EditionElementaryNode
virtual void onApply ()
 
virtual void onCancel ()
 
virtual void onPortIndexChanged (int index)
 
virtual void onCommitData (QWidget *editor)
 

Public Member Functions

 EditionScript (Subject *subject, QWidget *parent=0, const char *name=0)
 
virtual ~EditionScript ()
 
virtual void synchronize ()
 
- Public Member Functions inherited from YACS::HMI::EditionElementaryNode
 EditionElementaryNode (Subject *subject, QWidget *parent=0, const char *name=0)
 
virtual ~EditionElementaryNode ()
 
virtual void setEditablePorts (bool isEditable)
 
- Public Member Functions inherited from YACS::HMI::EditionNode
 EditionNode (Subject *subject, QWidget *parent=0, const char *name=0)
 
virtual ~EditionNode ()
 
virtual void update (GuiEvent event, int type, Subject *son)
 
- Public Member Functions inherited from YACS::HMI::ItemEdition
 ItemEdition (Subject *subject, QWidget *parent=0, const char *name=0)
 
virtual ~ItemEdition ()
 
virtual void select (bool isSelected)
 
virtual void setName (std::string name)
 
virtual void setEdited (bool isEdited)
 
- Public Member Functions inherited from FormEditItem
 FormEditItem (QWidget *parent=0)
 
virtual ~FormEditItem ()
 
- Public Member Functions inherited from YACS::HMI::ItemEditionBase
 ItemEditionBase (Subject *subject)
 
virtual ~ItemEditionBase ()
 
virtual SubjectgetSubject ()
 
- Public Member Functions inherited from YACS::HMI::GuiObserver
 GuiObserver ()
 
virtual ~GuiObserver ()
 
virtual void incrementSubjects (Subject *subject)
 
virtual void decrementSubjects (Subject *subject)
 
int getNbSubjects ()
 
bool isDestructible ()
 

Protected Attributes

SubjectInlineNode_subInlineNode
 
QTextEdit * _sci
 
QVBoxLayout * _glayout
 
QVBoxLayout * _portslayout
 
QPushButton * _editor
 
bool _checked
 
bool _remote
 
QFrame * fr_options
 
QFrame * fr_container
 
ComboBoxcb_container
 
QRadioButton * radiolocal
 
QRadioButton * radioremote
 
FormContainerDecoratorformcontainer
 
- Protected Attributes inherited from YACS::HMI::EditionElementaryNode
SubjectElementaryNode_subElemNode
 
QTabWidget * _twPorts
 
TablePortsEdition_tvInPorts
 
TablePortsEdition_tvOutPorts
 
ValueDelegate_valueDelegate
 
- Protected Attributes inherited from YACS::HMI::EditionNode
QLineEdit_le_fullName
 
SubjectNode_subjectNode
 
- Protected Attributes inherited from YACS::HMI::ItemEdition
bool _isEdited
 
bool _haveScript
 
- Protected Attributes inherited from FormEditItem
WidEditItem_wid
 
- Protected Attributes inherited from YACS::HMI::ItemEditionBase
Subject_subject
 
int _stackId
 
std::string _name
 
std::string _type
 
std::string _category
 
- Protected Attributes inherited from YACS::HMI::GuiObserver
std::set< Subject * > _subjectSet
 
bool _destructible
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::HMI::ItemEdition
static std::string filterName (const std::string &name)
 
- Protected Member Functions inherited from YACS::HMI::EditionElementaryNode
virtual bool hasInputPorts ()
 
virtual bool hasOutputPorts ()
 
virtual void createTablePorts (QLayout *layout)
 
- Static Protected Attributes inherited from YACS::HMI::GuiObserver
static std::map< int, std::string > _eventNameMap
 

Detailed Description

Definition at line 39 of file EditionScript.hxx.

Constructor & Destructor Documentation

EditionScript::EditionScript ( Subject subject,
QWidget parent = 0,
const char *  name = 0 
)

Definition at line 49 of file EditionScript.cxx.

References _editor, _glayout, YACS::HMI::ItemEdition::_haveScript, _portslayout, _sci, _subInlineNode, YACS::HMI::ItemEditionBase::_subject, FormEditItem::_wid, cb_container, changeContainer(), YACS::HMI::EditionElementaryNode::createTablePorts(), fillContainerPanel(), formcontainer, fr_container, fr_options, YACS::ENGINE::InlineNode::getContainer(), YACS::HMI::SubjectNode::getNode(), YACS::HMI::QtGuiContext::getQtCurrent(), YACS::ENGINE::InlineNode::getScript(), on_remote_toggled(), on_tb_options_toggled(), onEdit(), onScriptModified(), YACS::HMI::Resource::pythonExternalEditor, radiolocal, radioremote, YACS::HMI::EditionElementaryNode::setEditablePorts(), update(), YACS::HMI::UPDATE, and YASSERT.

52  : EditionElementaryNode(subject, parent, name)
53 {
54  _subInlineNode = 0;
55  _sci = 0;
56 
57  _subInlineNode = dynamic_cast<SubjectInlineNode*>(_subject);
59 
60  QSplitter *splitter = new QSplitter(this);
61  splitter->setOrientation(Qt::Vertical);
62  _wid->gridLayout1->addWidget(splitter);
63 
64  QWidget* widg=new QWidget;
65  _portslayout = new QVBoxLayout;
66  widg->setLayout(_portslayout);
67  _portslayout->setMargin(1);
68  splitter->addWidget(widg);
69 
70  QWidget* window=new QWidget;
71  _glayout=new QVBoxLayout;
72  window->setLayout(_glayout);
73  _glayout->setMargin(1);
74  splitter->addWidget(window);
75 
76  //add an options section in ports layout for execution mode (local or remote)
77  QHBoxLayout* hboxLayout = new QHBoxLayout();
78  hboxLayout->setMargin(0);
79  QToolButton* tb_options = new QToolButton();
80  tb_options->setCheckable(true);
81  QIcon icon;
82  icon.addFile("icons:icon_down.png");
83  icon.addFile("icons:icon_up.png", QSize(), QIcon::Normal, QIcon::On);
84  tb_options->setIcon(icon);
85  hboxLayout->addWidget(tb_options);
86 
87  QLabel* label = new QLabel("Execution Mode");
88  QFont font;
89  font.setBold(true);
90  font.setWeight(75);
91  label->setFont(font);
92  hboxLayout->addWidget(label);
93 
94  _portslayout->addLayout(hboxLayout);
95 
96  fr_options = new QFrame();
97  QHBoxLayout* hboxLayout1 = new QHBoxLayout(fr_options);
98  hboxLayout1->setMargin(0);
99  radiolocal= new QRadioButton("YACS");
100  radioremote= new QRadioButton("Container");
101  radiolocal->setChecked(true);
102  hboxLayout1->addWidget(radiolocal);
103  hboxLayout1->addWidget(radioremote);
104  hboxLayout->addWidget(fr_options);
105 
106  fr_container = new QFrame();
107  QHBoxLayout* hboxLayout2 = new QHBoxLayout(fr_container);
108  hboxLayout2->setMargin(0);
109  QLabel* laContainer = new QLabel("Container:");
110  hboxLayout2->addWidget(laContainer);
111  cb_container = new ComboBox();
112  hboxLayout2->addWidget(cb_container);
113  _portslayout->addWidget(fr_container);
114 
115  //
116  YACS::ENGINE::InlineNode *pyNode(dynamic_cast<YACS::ENGINE::InlineNode*>(_subInlineNode->getNode()));
117  YACS::ENGINE::Container *cont(pyNode->getContainer());
118  formcontainer = new FormContainerDecorator(cont,this);
119  _portslayout->addWidget(formcontainer);
120  //_portslayout->addWidget(formcontainer->getWidget());
121  //end of insertion of execution mode
122 
124  setEditablePorts(true);
125 
126  _haveScript = true;
127 #ifdef HAS_PYEDITOR
128  _sci = new PyEditor_Editor(this);
129 #else
130  _sci = new QTextEdit(this);
131 #endif
132  _wid->gridLayout->removeItem(_wid->spacerItem);
133 
134  _editor = new QPushButton("External Editor", this);
135  connect(_editor, SIGNAL(clicked()), this, SLOT(onEdit()));
136  if(!Resource::pythonExternalEditor.isEmpty())
137  {
138  _glayout->addWidget( _editor );
139  }
140  _glayout->addWidget( _sci );
141 
142  if (!QtGuiContext::getQtCurrent()->isEdition())
143  _sci->setReadOnly(true);
144 
145  if (YACS::ENGINE::InlineNode* pyNode =
146  dynamic_cast<YACS::ENGINE::InlineNode*>(_subInlineNode->getNode()))
147  {
148  _sci->append(pyNode->getScript().c_str());
149  }
150  connect(_sci, SIGNAL(textChanged()), this, SLOT(onScriptModified()));
151 
152  connect(tb_options, SIGNAL(toggled(bool)), this, SLOT(on_tb_options_toggled(bool)));
153  connect(radioremote, SIGNAL(toggled(bool)), this, SLOT(on_remote_toggled(bool)));
154  connect(cb_container, SIGNAL(mousePressed()), this, SLOT(fillContainerPanel()));
155  connect(cb_container, SIGNAL(activated(int)), this, SLOT(changeContainer(int)));
156 
157  update(UPDATE,0,0);
158  on_tb_options_toggled(false);
159 }
EditionScript::~EditionScript ( )
virtual

Definition at line 161 of file EditionScript.cxx.

162 {
163 }

Member Function Documentation

void EditionScript::changeContainer ( int  index)
virtualslot

Definition at line 339 of file EditionScript.cxx.

References _subInlineNode, cb_container, YACS::ENGINE::Proc::containerMap, DEBTRACE, FormContainerDecorator::FillPanel(), formcontainer, YACS::ENGINE::InlineNode::getContainer(), YACS::HMI::GuiContext::getCurrent(), YACS::HMI::SubjectNode::getNode(), YACS::HMI::GuiContext::getProc(), YACS::HMI::SubjectInlineNode::setContainer(), and YASSERT.

Referenced by EditionScript(), and fillContainerPanel().

340 {
341  DEBTRACE("EditionScript::changeContainer ");
342  string contName = cb_container->itemText(index).toStdString();
343  DEBTRACE(contName);
345  YACS::ENGINE::Container *oldContainer = pyNode->getContainer();
346 
347  YACS::ENGINE::Container *newContainer = 0;
349  if (proc->containerMap.count(contName))
350  newContainer = proc->containerMap[contName];
351  if (!newContainer)
352  {
353  DEBTRACE("-------------> not found : " << contName);
354  return;
355  }
356  YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(newContainer));
357  SubjectContainerBase *scnt(GuiContext::getCurrent()->_mapOfSubjectContainer[newContainer]);
358 
360 
361  // show the selected container parameters
362  formcontainer->FillPanel(newContainer);
363 }
void EditionScript::fillContainerPanel ( )
virtualslot

Definition at line 315 of file EditionScript.cxx.

References _subInlineNode, cb_container, changeContainer(), YACS::ENGINE::Proc::containerMap, DEBTRACE, FormContainerDecorator::FillPanel(), formcontainer, YACS::ENGINE::InlineNode::getContainer(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Container::getName(), YACS::HMI::SubjectNode::getNode(), and YACS::HMI::GuiContext::getProc().

Referenced by EditionScript(), on_remote_toggled(), onApply(), and update().

316 {
317  DEBTRACE("EditionScript::fillContainerPanel ");
319 
320  cb_container->clear();
321  std::map<string,YACS::ENGINE::Container*>::const_iterator it = proc->containerMap.begin();
322  for(; it != proc->containerMap.end(); ++it)
323  cb_container->addItem( QString((*it).first.c_str()));
324 
326 
327  YACS::ENGINE::Container * cont = pyNode->getContainer();
328  if (cont)
329  {
330  int index = cb_container->findText(cont->getName().c_str());
331  cb_container->setCurrentIndex(index);
332  formcontainer->FillPanel(cont);
333  }
334  else if (cb_container->count()) {
335  changeContainer(0);
336  }
337 }
void EditionScript::on_remote_toggled ( bool  checked)
virtualslot

Definition at line 288 of file EditionScript.cxx.

References _remote, _subInlineNode, DEBTRACE, fillContainerPanel(), formcontainer, fr_container, YACS::ENGINE::InlineNode::getExecutionMode(), YACS::HMI::SubjectNode::getNode(), FormContainerDecorator::hide(), YACS::HMI::SubjectInlineNode::setExecutionMode(), and FormContainerDecorator::show().

Referenced by EditionScript().

289 {
290  DEBTRACE("EditionScript::on_remote_toggled " << checked);
291  _remote=checked;
293  std::string mode = pyNode->getExecutionMode();
294  DEBTRACE(mode);
295 
296  if(checked)
297  {
298  //remote radio button is checked
299  if(mode != "remote")
300  _subInlineNode->setExecutionMode("remote");
301  fr_container->show();
302  formcontainer->show();
304  }
305  else
306  {
307  //remote radio button is unchecked
308  if(mode != "local")
310  fr_container->hide();
311  formcontainer->hide();
312  }
313 }
void EditionScript::on_tb_options_toggled ( bool  checked)
virtualslot

Definition at line 267 of file EditionScript.cxx.

References _checked, _remote, DEBTRACE, formcontainer, fr_container, fr_options, FormContainerDecorator::hide(), and FormContainerDecorator::show().

Referenced by EditionScript().

268 {
269  DEBTRACE("EditionScript::on_tb_options_toggled " << checked);
270  _checked = checked;
271  if(_checked)
272  {
273  fr_options->show();
274  if(_remote)
275  {
276  fr_container->show();
277  formcontainer->show();
278  }
279  }
280  else
281  {
282  fr_options->hide();
283  fr_container->hide();
284  formcontainer->hide();
285  }
286 }
void EditionScript::onApply ( )
virtualslot

Definition at line 180 of file EditionScript.cxx.

References _editor, _glayout, YACS::HMI::ItemEdition::_haveScript, YACS::HMI::ItemEdition::_isEdited, _sci, _subInlineNode, DEBTRACE, fillContainerPanel(), formcontainer, YACS::HMI::GuiContext::getCurrent(), YACS::HMI::EditionElementaryNode::onApply(), FormContainerDecorator::onApply(), YACS::HMI::Resource::pythonExternalEditor, YACS::HMI::Resource::pythonfont, PMMLBasicsTestLauncher::ret, and YACS::HMI::SubjectInlineNode::setScript().

Referenced by YACS::HMI::EditionPyFunc::onApply(), and onEdit().

181 {
182  DEBTRACE("EditionScript::onApply");
183  bool scriptEdited = false;
184 #ifdef HAS_PYEDITOR
185  PyEditor_Settings settings = _sci->settings();
186  settings.setFont(Resource::pythonfont);
187  _sci->setSettings(settings);
188 #endif
189 
190  if(Resource::pythonExternalEditor.isEmpty())
191  {
192  _editor->hide();
193  _glayout->removeWidget(_editor);
194  }
195  else
196  {
197  _editor->show();
198  if(_glayout->itemAt(0)->widget() != _editor)
199  _glayout->insertWidget ( 0, _editor );
200  }
201 
202  if (_haveScript)
203  {
204  if (_sci->document()->isModified())
205  {
206  scriptEdited = true;
207  std::string text=_sci->document()->toPlainText().toStdString();
208  if(text[text.length()-1] != '\n')
209  text=text+'\n';
210  bool ret = _subInlineNode->setScript(text);
211  if (ret) scriptEdited = false;
212  }
213  }
214 
215  bool containerEdited = true;
216  if (formcontainer->onApply()) {
218  containerEdited = false;
219  } else {
220  Message mess(GuiContext::getCurrent()->_lastErrorMessage);
221  return;
222  }
223 
224  _isEdited = _isEdited || scriptEdited || containerEdited;
225 
227 }
void EditionScript::onEdit ( )
virtualslot

Definition at line 244 of file EditionScript.cxx.

References _sci, DEBTRACE, onApply(), options, and YACS::HMI::Resource::pythonExternalEditor.

Referenced by EditionScript().

245 {
246  DEBTRACE("EditionScript::onEdit");
247  QTemporaryFile outFile;
248  if (!outFile.open())
249  return;
250  QString fileName = outFile.fileName();
251  QTextStream out(&outFile);
252  out << _sci->toPlainText();
253  outFile.close();
254 
255  QStringList options=Resource::pythonExternalEditor.split(" ");
256  QString prog=options.takeAt(0);
257  QProcess::execute(prog, QStringList() << options << fileName);
258 
259  QFile inFile(fileName);
260  if (!inFile.open(QIODevice::ReadOnly))
261  return;
262  QTextStream in(&inFile);
263  _sci->setPlainText(in.readAll());
264  onApply();
265 }
void EditionScript::onScriptModified ( )
virtualslot

Definition at line 237 of file EditionScript.cxx.

References YACS::HMI::ItemEdition::_isEdited, DEBTRACE, and YACS::HMI::ItemEdition::setEdited().

Referenced by EditionScript(), and synchronize().

238 {
239  DEBTRACE("EditionScript::onScriptModified");
240  _isEdited = true;
241  setEdited(true);
242 }
void EditionScript::synchronize ( )
virtual

used in derived nodes for synchronisation with schema model.

Reimplemented from YACS::HMI::EditionElementaryNode.

Definition at line 165 of file EditionScript.cxx.

References YACS::HMI::ItemEdition::_isEdited, _sci, _subInlineNode, DEBTRACE, YACS::HMI::SubjectNode::getNode(), YACS::ENGINE::InlineNode::getScript(), onScriptModified(), YACS::HMI::EditionElementaryNode::synchronize(), and YASSERT.

166 {
167  DEBTRACE("EditionScript::synchronize " << this->_isEdited);
170  YASSERT(pyNode);
171  disconnect(_sci, SIGNAL(textChanged()), this, SLOT(onScriptModified()));
172  if (!_isEdited)
173  {
174  _sci->clear();
175  _sci->append(pyNode->getScript().c_str());
176  }
177  connect(_sci, SIGNAL(textChanged()), this, SLOT(onScriptModified()));
178 }
void EditionScript::update ( GuiEvent  event,
int  type,
Subject son 
)
virtualslot

Definition at line 365 of file EditionScript.cxx.

References _remote, _subInlineNode, YACS::HMI::ASSOCIATE, DEBTRACE, YACS::HMI::GuiObserver::eventName(), fillContainerPanel(), FormContainerDecorator::FillPanel(), formcontainer, YACS::HMI::SubjectContainerBase::getContainer(), YACS::ENGINE::InlineNode::getExecutionMode(), YACS::HMI::SubjectNode::getNode(), radiolocal, radioremote, YACS::HMI::EditionNode::update(), YACS::HMI::UPDATE, and YASSERT.

Referenced by gui.graph.MyCanvas::customEvent(), and EditionScript().

366 {
367  DEBTRACE("EditionScript::update " << eventName(event) <<" "<<type<<" "<<son);
368  EditionElementaryNode::update(event, type, son);
369  if(event == ASSOCIATE)
370  {
372  SubjectContainer *scont = dynamic_cast<SubjectContainer*>(son);
373  YASSERT(scont);
375  }
376  else if(event == UPDATE)
377  {
379  std::string mode = pyNode->getExecutionMode();
380  if(mode == "remote")
381  {
382  _remote=true;
383  radioremote->setChecked(true);
384  }
385  else if(mode == "local")
386  {
387  _remote=false;
388  radiolocal->setChecked(true);
389  }
390 
392  }
393 }

Member Data Documentation

bool YACS::HMI::EditionScript::_checked
protected

Definition at line 72 of file EditionScript.hxx.

Referenced by on_tb_options_toggled().

QPushButton* YACS::HMI::EditionScript::_editor
protected

Definition at line 71 of file EditionScript.hxx.

Referenced by EditionScript(), and onApply().

QVBoxLayout* YACS::HMI::EditionScript::_glayout
protected
QVBoxLayout* YACS::HMI::EditionScript::_portslayout
protected

Definition at line 70 of file EditionScript.hxx.

Referenced by EditionScript().

bool YACS::HMI::EditionScript::_remote
protected

Definition at line 73 of file EditionScript.hxx.

Referenced by on_remote_toggled(), on_tb_options_toggled(), and update().

QTextEdit* YACS::HMI::EditionScript::_sci
protected
SubjectInlineNode* YACS::HMI::EditionScript::_subInlineNode
protected
ComboBox* YACS::HMI::EditionScript::cb_container
protected

Definition at line 76 of file EditionScript.hxx.

Referenced by changeContainer(), EditionScript(), and fillContainerPanel().

FormContainerDecorator* YACS::HMI::EditionScript::formcontainer
protected
QFrame* YACS::HMI::EditionScript::fr_container
protected

Definition at line 75 of file EditionScript.hxx.

Referenced by EditionScript(), on_remote_toggled(), and on_tb_options_toggled().

QFrame* YACS::HMI::EditionScript::fr_options
protected

Definition at line 74 of file EditionScript.hxx.

Referenced by EditionScript(), and on_tb_options_toggled().

QRadioButton* YACS::HMI::EditionScript::radiolocal
protected

Definition at line 77 of file EditionScript.hxx.

Referenced by EditionScript(), and update().

QRadioButton* YACS::HMI::EditionScript::radioremote
protected

Definition at line 78 of file EditionScript.hxx.

Referenced by EditionScript(), and update().


The documentation for this class was generated from the following files: