Version: 8.3.0
Menus.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "Menus.hxx"
21 #include "QtGuiContext.hxx"
22 #include "guiObservers.hxx"
23 #include "DataPort.hxx"
24 #include "DataNode.hxx"
25 #include "ServiceNode.hxx"
26 #include "InlineNode.hxx"
27 
28 #include <QMenu>
29 
30 //#define _DEVDEBUG_
31 #include "YacsTrace.hxx"
32 #include "chrono.hxx"
33 
34 using namespace std;
35 using namespace YACS::HMI;
36 using namespace YACS::ENGINE;
37 
38 //=======================================================================================
39 
40 MenusBase::MenusBase()
41 {
42  _dummyAct = new QAction(tr("Elapse Time Statistics"), this);
43 // _dummyAct->setShortcut(tr("Ctrl+y"));
44  _dummyAct->setStatusTip(tr("Elapse Time Statistics"));
45  _dummyAct->setToolTip(tr("Elapse Time Statistics"));
46  connect(_dummyAct, SIGNAL(triggered()), this, SLOT(dummyAction()));
47 }
48 
49 MenusBase::~MenusBase()
50 {
51 }
52 
53 void MenusBase::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
54 {
55  QMenu menu(m, caller);
56  menu.addAction(_dummyAct);
57  menu.exec(globalPos);
58 }
59 
60 void MenusBase::dummyAction()
61 {
62  DEBTRACE("MenusBase::dummyAction");
63  QtGuiContext::_counters->stats();
64 }
65 
66 void MenusBase::foreachAction(QAction* act)
67 {
68  DEBTRACE(act->text().toStdString());
69  GenericGui *gmain = QtGuiContext::getQtCurrent()->getGMain();
70  gmain->createForEachLoop(act->text().toStdString());
71 }
72 
73 void MenusBase::putGraphInForeachAction(QAction* act)
74 {
75  DEBTRACE(act->text().toStdString());
76  GenericGui *gmain = QtGuiContext::getQtCurrent()->getGMain();
77  gmain->putGraphInForeachLoop(act->text().toStdString());
78 }
79 
80 void MenusBase::addHeader(QMenu &m, const QString &h)
81 {
82  m.addAction(_dummyAct);
83  _dummyAct->setText(h);
84  QFont f = _dummyAct->font();
85  f.setBold(true);
86  _dummyAct->setFont(f);
87  m.addSeparator();
88 }
89 
90 void MenusBase::buildForEachMenu(QMenu *m, QActionGroup* actgroup)
91 {
92  QPixmap pixmap;
93  pixmap.load("icons:new_foreach_loop_node.png");
94 
95  QMenu *ForEachMenu=m->addMenu(QIcon(pixmap),"ForEach Loop");
96 
97  Proc* proc = GuiContext::getCurrent()->getProc();
98  std::map<std::string, TypeCode*>::const_iterator it = proc->typeMap.begin();
99  QAction* act;
100  for (; it != proc->typeMap.end(); ++it)
101  {
102  act=actgroup->addAction((*it).first.c_str());
103  ForEachMenu->addAction(act);
104  }
105 }
106 
107 void MenusBase::addForEachMenu(QMenu *m, QActionGroup* actgroup)
108 {
109  buildForEachMenu(m, actgroup);
110  connect(actgroup, SIGNAL(triggered(QAction*)), this, SLOT(foreachAction(QAction*)));
111 }
112 
113 void MenusBase::addForEachMenuToPutGraph(QMenu *m, QActionGroup* actgroup)
114 {
115  buildForEachMenu(m, actgroup);
116  connect(actgroup, SIGNAL(triggered(QAction*)), this, SLOT(putGraphInForeachAction(QAction*)));
117 }
118 
119 //=======================================================================================
120 
121 ComposedNodeMenu::ComposedNodeMenu() : MenusBase()
122 {
123 }
124 
126 {
127 }
128 
129 void ComposedNodeMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
130 {
132  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
133  QMenu menu(m, caller);
134  QActionGroup actgroup(this);
135  addHeader(menu, m);
136  if (isEdition)
137  {
138  QMenu *CNmenu = menu.addMenu(tr("Create Node"));
139  CNmenu->addAction(gmain->_nodeFromCatalogAct);
140  // CNmenu->addSeparator();
141  // CNmenu->addAction(gmain->_cppNodeAct);
142  // CNmenu->addAction(gmain->_XMLNodeAct);
143  CNmenu->addSeparator();
144  CNmenu->addAction(gmain->_inlineScriptNodeAct);
145  CNmenu->addAction(gmain->_inlineFunctionNodeAct);
146  CNmenu->addSeparator();
147  CNmenu->addAction(gmain->_inDataNodeAct);
148  CNmenu->addAction(gmain->_outDataNodeAct);
149  CNmenu->addAction(gmain->_inStudyNodeAct);
150  CNmenu->addAction(gmain->_outStudyNodeAct);
151  CNmenu->addSeparator();
152  CNmenu->addAction(gmain->_blockNodeAct);
153  CNmenu->addSeparator();
154  CNmenu->addAction(gmain->_FORNodeAct);
155  addForEachMenu(CNmenu,&actgroup);
156  CNmenu->addAction(gmain->_WHILENodeAct);
157  CNmenu->addAction(gmain->_SWITCHNodeAct);
158  CNmenu->addAction(gmain->_OptimizerLoopAct);
159  menu.addSeparator();
160  }
161 // menu.addAction(gmain->_toggleSceneItemVisibleAct);
162  menu.addAction(gmain->_arrangeLocalNodesAct);
163  menu.addAction(gmain->_arrangeRecurseNodesAct);
164  menu.addSeparator();
165  menu.addAction(gmain->_showOnlyCtrlLinksAct);
166  menu.addAction(gmain->_showCtrlLinksAct);
167  menu.addAction(gmain->_hideCtrlLinksAct);
168  menu.addAction(gmain->_emphasisPortLinksAct);
169  menu.addAction(gmain->_deEmphasizeAllAct);
170  menu.addSeparator();
171  menu.addAction(gmain->_zoomToBlocAct);
172  menu.addAction(gmain->_centerOnNodeAct);
173  menu.addAction(gmain->_shrinkExpand);
174  menu.addAction(gmain->_shrinkExpandChildren);
175  menu.addAction(gmain->_shrinkExpandElementaryRecursively);
176  menu.addAction(gmain->_computeLinkAct);
177 // menu.addAction(gmain->_toggleAutomaticComputeLinkAct);
178 // menu.addAction(gmain->_toggleSimplifyLinkAct);
179 // menu.addAction(gmain->_toggleForce2NodesLinkAct);
180 // menu.addAction(gmain->_toggleAddRowColsAct);
181  if (isEdition)
182  {
183  menu.addSeparator();
184  menu.addAction(gmain->_deleteItemAct);
185  menu.addAction(gmain->_cutItemAct);
186  menu.addAction(gmain->_copyItemAct);
187  menu.addAction(gmain->_pasteItemAct);
188  menu.addAction(gmain->_putInBlocAct);
189 
191  SubjectNode *sin = dynamic_cast<SubjectNode*>(sub);
192  if(sin && !sin->isValid())
193  {
194  menu.addSeparator();
195  menu.addAction(gmain->_getErrorReportAct);
196  menu.addAction(gmain->_getErrorDetailsAct);
197  }
198  }
199  else
200  {
201  menu.addAction(gmain->_getErrorReportAct);
202  menu.addAction(gmain->_getErrorDetailsAct);
203  }
204  menu.exec(globalPos);
205 }
206 
207 //=======================================================================================
208 
210 {
211 }
212 
214 {
215 }
216 
217 void ProcMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
218 {
220  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
221  QMenu menu(m, caller);
222  addHeader(menu, m);
223  QActionGroup actgroup(this);
224  QActionGroup actgroup2(this);
225  if (isEdition)
226  {
227  menu.addAction(gmain->_runLoadedSchemaAct);
228  menu.addSeparator();
229  menu.addAction(gmain->_importDataTypeAct);
230  menu.addAction(gmain->_newContainerAct);
231  menu.addAction(gmain->_newHPContainerAct);
232  QMenu *CNmenu = menu.addMenu(tr("Create Node"));
233  CNmenu->addAction(gmain->_nodeFromCatalogAct);
234  // CNmenu->addSeparator();
235  // CNmenu->addAction(gmain->_cppNodeAct);
236  // CNmenu->addAction(gmain->_XMLNodeAct);
237  CNmenu->addSeparator();
238  CNmenu->addAction(gmain->_inlineScriptNodeAct);
239  CNmenu->addAction(gmain->_inlineFunctionNodeAct);
240  CNmenu->addSeparator();
241  CNmenu->addAction(gmain->_inDataNodeAct);
242  CNmenu->addAction(gmain->_outDataNodeAct);
243  CNmenu->addAction(gmain->_inStudyNodeAct);
244  CNmenu->addAction(gmain->_outStudyNodeAct);
245  CNmenu->addSeparator();
246  CNmenu->addAction(gmain->_blockNodeAct);
247  CNmenu->addSeparator();
248  CNmenu->addAction(gmain->_FORNodeAct);
249  addForEachMenu(CNmenu,&actgroup);
250  CNmenu->addAction(gmain->_WHILENodeAct);
251  CNmenu->addAction(gmain->_SWITCHNodeAct);
252  CNmenu->addAction(gmain->_OptimizerLoopAct);
253  menu.addSeparator();
254  menu.addAction(gmain->_pasteItemAct);
255 
256  QMenu *PINmenu = menu.addMenu(tr("Put Graph Content in Node"));
257  PINmenu->addAction(gmain->_putGraphInBlocAct);
258  PINmenu->addSeparator();
259  PINmenu->addAction(gmain->_putGraphInForLoopAct);
260  addForEachMenuToPutGraph(PINmenu,&actgroup2);
261  PINmenu->addAction(gmain->_putGraphInWhileLoopAct);
262  PINmenu->addAction(gmain->_putGraphInOptimizerLoopAct);
263 
264  menu.addSeparator();
265  }
266  menu.addAction(gmain->_getYacsContainerLogAct);
267  menu.addSeparator();
268  menu.addAction(gmain->_showAllLinksAct);
269  menu.addAction(gmain->_hideAllLinksAct);
270  menu.addAction(gmain->_deEmphasizeAllAct);
271  menu.addSeparator();
272 // menu.addAction(gmain->_toggleSceneItemVisibleAct);
273  menu.addAction(gmain->_arrangeLocalNodesAct);
274  menu.addAction(gmain->_arrangeRecurseNodesAct);
275  menu.addSeparator();
276  menu.addAction(gmain->_zoomToBlocAct);
277  menu.addAction(gmain->_centerOnNodeAct);
278  menu.addAction(gmain->_shrinkExpand);
279  menu.addAction(gmain->_shrinkExpandChildren);
280  menu.addAction(gmain->_shrinkExpandElementaryRecursively);
281  menu.addAction(gmain->_computeLinkAct);
282 // menu.addAction(gmain->_toggleAutomaticComputeLinkAct);
283 // menu.addAction(gmain->_toggleSimplifyLinkAct);
284 // menu.addAction(gmain->_toggleForce2NodesLinkAct);
285 // menu.addAction(gmain->_toggleAddRowColsAct);
286  if (!isEdition)
287  {
288  menu.addAction(gmain->_getErrorReportAct);
289  menu.addAction(gmain->_getErrorDetailsAct);
290  menu.addAction(gmain->_shutdownProcAct);
291  }
292  menu.exec(globalPos);
293 }
294 
295 //=======================================================================================
296 
298 {
299 }
300 
302 {
303 }
304 
305 void NodeMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
306 {
308  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
309  QMenu menu(m, caller);
310  addHeader(menu, m);
311  if (isEdition)
312  {
313  menu.addAction(gmain->_deleteItemAct);
314  menu.addAction(gmain->_cutItemAct);
315  menu.addAction(gmain->_copyItemAct);
316  menu.addAction(gmain->_pasteItemAct);
317  }
318  menu.addSeparator();
319  menu.addAction(gmain->_showOnlyCtrlLinksAct);
320  menu.addAction(gmain->_showCtrlLinksAct);
321  menu.addAction(gmain->_hideCtrlLinksAct);
322  menu.addAction(gmain->_emphasisPortLinksAct);
323  menu.addAction(gmain->_deEmphasizeAllAct);
324  menu.addSeparator();
325  menu.addAction(gmain->_zoomToBlocAct);
326  menu.addAction(gmain->_centerOnNodeAct);
327  menu.exec(globalPos);
328 }
329 
330 //=======================================================================================
331 
333 {
334 }
335 
337 {
338 }
339 
340 void HeaderNodeMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
341 {
343  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
344  QMenu menu(m, caller);
345  addHeader(menu, m);
346  if (isEdition)
347  {
348  menu.addAction(gmain->_deleteItemAct);
349  }
350  menu.exec(globalPos);
351 }
352 
353 //=======================================================================================
354 
356 {
357 }
358 
360 {
361 }
362 
363 void LinkMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
364 {
366  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
367  QMenu menu(m, caller);
368  addHeader(menu, m);
369  menu.addAction(gmain->_showOnlyLinkAct);
370  menu.addAction(gmain->_showLinkAct);
371  menu.addAction(gmain->_hideLinkAct);
372  menu.addAction(gmain->_emphasisLinkAct);
373  menu.addAction(gmain->_deEmphasizeAllAct);
374  if (isEdition)
375  {
376  menu.addSeparator();
377  menu.addAction(gmain->_deleteItemAct);
378  }
379  menu.exec(globalPos);
380 }
381 
382 //=======================================================================================
383 
385 {
386 }
387 
389 {
390 }
391 
392 void ElementaryNodeMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
393 {
395  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
396  QMenu menu(m, caller);
397  addHeader(menu, m);
398  if (isEdition)
399  {
400 // Subject* sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
401 // SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(sub);
402 // if (ssn)
403 // {
404 // menu.addAction(gmain->_newContainerAct);
405 // menu.addSeparator();
406 // }
408  SubjectNode *sin = dynamic_cast<SubjectNode*>(sub);
409  if(sin && !sin->isValid())
410  {
411  menu.addAction(gmain->_getErrorReportAct);
412  menu.addSeparator();
413  }
414  menu.addAction(gmain->_deleteItemAct);
415  menu.addAction(gmain->_cutItemAct);
416  menu.addAction(gmain->_copyItemAct);
417  menu.addAction(gmain->_pasteItemAct);
418  menu.addAction(gmain->_putInBlocAct);
419  }
420  else
421  {
422  menu.addAction(gmain->_getErrorReportAct);
423  menu.addAction(gmain->_getErrorDetailsAct);
424  menu.addAction(gmain->_getContainerLogAct);
425  }
426  menu.addSeparator();
427  menu.addAction(gmain->_showOnlyCtrlLinksAct);
428  menu.addAction(gmain->_showCtrlLinksAct);
429  menu.addAction(gmain->_hideCtrlLinksAct);
430  menu.addAction(gmain->_emphasisPortLinksAct);
431  menu.addAction(gmain->_deEmphasizeAllAct);
432  menu.addSeparator();
433  menu.addAction(gmain->_zoomToBlocAct);
434  menu.addAction(gmain->_centerOnNodeAct);
435  menu.addAction(gmain->_shrinkExpand);
436 // menu.addSeparator();
437 // menu.addAction(gmain->_toggleSceneItemVisibleAct);
438  menu.exec(globalPos);
439 }
440 
441 //=======================================================================================
442 
444 {
445 }
446 
448 {
449 }
450 
451 void InPortMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
452 {
454  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
455  QMenu menu(m, caller);
456  addHeader(menu, m);
457  menu.addAction(gmain->_showOnlyPortLinksAct);
458  menu.addAction(gmain->_showPortLinksAct);
459  menu.addAction(gmain->_hidePortLinksAct);
460  menu.addAction(gmain->_emphasisPortLinksAct);
461  menu.addAction(gmain->_deEmphasizeAllAct);
462  if (isEdition)
463  {
465  SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(sub);
466  Node *parent = 0;
467  if (sdp) parent = sdp->getPort()->getNode();
468  if (parent)
469  if (dynamic_cast<DataNode*>(parent) || dynamic_cast<InlineNode*>(parent))
470  {
471  menu.addSeparator();
472  menu.addAction(gmain->_deleteItemAct);
473  }
474  }
475  menu.exec(globalPos);
476 }
477 
478 //=======================================================================================
479 
481 {
482 }
483 
485 {
486 }
487 
488 void OutPortMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
489 {
491  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
492  QMenu menu(m, caller);
493  addHeader(menu, m);
494  menu.addAction(gmain->_showOnlyPortLinksAct);
495  menu.addAction(gmain->_showPortLinksAct);
496  menu.addAction(gmain->_hidePortLinksAct);
497  menu.addAction(gmain->_emphasisPortLinksAct);
498  menu.addAction(gmain->_deEmphasizeAllAct);
499  if (isEdition)
500  {
502  SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(sub);
503  Node *parent = 0;
504  if (sdp) parent = sdp->getPort()->getNode();
505  if (parent)
506  if (dynamic_cast<DataNode*>(parent) || dynamic_cast<InlineNode*>(parent))
507  {
508  menu.addSeparator();
509  menu.addAction(gmain->_deleteItemAct);
510  }
511  }
512  menu.exec(globalPos);
513 }
514 
515 //=======================================================================================
516 
518 {
519 }
520 
522 {
523 }
524 
525 void CtrlInPortMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
526 {
528  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
529  QMenu menu(m, caller);
530  addHeader(menu, m);
531  menu.addAction(gmain->_showOnlyCtrlLinksAct);
532  menu.addAction(gmain->_showCtrlLinksAct);
533  menu.addAction(gmain->_hideCtrlLinksAct);
534  menu.addAction(gmain->_emphasisCtrlLinksAct);
535  menu.addAction(gmain->_deEmphasizeAllAct);
536  if (isEdition)
537  {
538  //menu.addSeparator();
539  //menu.addAction(gmain->_deleteItemAct);
540  }
541  menu.exec(globalPos);
542 }
543 
544 //=======================================================================================
545 
547 {
548 }
549 
551 {
552 }
553 
554 void CtrlOutPortMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
555 {
557  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
558  QMenu menu(m, caller);
559  addHeader(menu, m);
560  menu.addAction(gmain->_showOnlyCtrlLinksAct);
561  menu.addAction(gmain->_showCtrlLinksAct);
562  menu.addAction(gmain->_hideCtrlLinksAct);
563  menu.addAction(gmain->_emphasisCtrlLinksAct);
564  menu.addAction(gmain->_deEmphasizeAllAct);
565  if (isEdition)
566  {
567  //menu.addSeparator();
568  //menu.addAction(gmain->_deleteItemAct);
569  }
570  menu.exec(globalPos);
571 }
572 
573 //=======================================================================================
574 
576 {
577 }
578 
580 {
581 }
582 
583 void ReferenceMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
584 {
586  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
587  QMenu menu(m, caller);
588  addHeader(menu, m);
589  menu.addAction(gmain->_selectReferenceAct);
590  menu.exec(globalPos);
591 }
592 
593 //=======================================================================================
594 
596 {
597 }
598 
600 {
601 }
602 
603 void ContainerDirMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
604 {
606  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
607  QMenu menu(m, caller);
608  addHeader(menu, m);
609  if (isEdition)
610  {
611  menu.addAction(gmain->_newContainerAct);
612  menu.addAction(gmain->_newHPContainerAct);
613  }
614  menu.exec(globalPos);
615 }
616 
617 //=======================================================================================
618 
620 {
621 }
622 
624 {
625 }
626 
627 void ComponentInstanceMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
628 {
630  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
631  QMenu menu(m, caller);
632  addHeader(menu, m);
633  if (isEdition)
634  {
635  menu.addAction(gmain->_selectComponentInstanceAct);
636  menu.addAction(gmain->_newSalomeComponentAct);
637  }
638  menu.exec(globalPos);
639 }
640 
641 //=======================================================================================
642 
644 {
645 }
646 
648 {
649 }
650 
651 void ContainerMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString& m)
652 {
654  bool isEdition = QtGuiContext::getQtCurrent()->isEdition();
655  QMenu menu(m, caller);
656  addHeader(menu, m);
657  if (isEdition)
658  {
659  menu.addAction(gmain->_deleteItemAct);
660  }
661  menu.exec(globalPos);
662 }
663