Salome HOME
c50a41dda7e654fa9519e829a813650acd5e2086
[modules/yacs.git] / src / genericgui / GuiEditor.cxx
1 // Copyright (C) 2006-2014  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 <Python.h>
21 #include "GuiEditor.hxx"
22 #include "RuntimeSALOME.hxx"
23 #include "Proc.hxx"
24 #include "Node.hxx"
25 #include "ForEachLoop.hxx"
26 #include "Catalog.hxx"
27 #include "Container.hxx"
28 #include "ComponentInstance.hxx"
29 #include "guiObservers.hxx"
30 #include "QtGuiContext.hxx"
31 #include "TypeCode.hxx"
32 #include "Scene.hxx"
33 #include "SceneComposedNodeItem.hxx"
34 #include "SceneLinkItem.hxx"
35 #include "Catalog.hxx"
36 #include "ItemMimeData.hxx"
37 #include "Message.hxx"
38 #include "Resource.hxx"
39 #include "FormUndoRedo.hxx"
40 #include <QMessageBox>
41
42 #include <string>
43 #include <sstream>
44 #include <iostream>
45
46 //#define _DEVDEBUG_
47 #include "YacsTrace.hxx"
48
49 using namespace std;
50 using namespace YACS::ENGINE;
51 using namespace YACS::HMI;
52
53 GuiEditor::GuiEditor()
54 {
55   // approximative conversion from latin1 to US ascii (removing accentuation)
56   DEBTRACE("GuiEditor::GuiEditor");
57   _table    = "________________"  ; //   0 -  15
58   _table   += "________________"  ; //  16 -  31
59   _table   += " !\"#$%&'()*+,-./" ; //  32 -  47
60   _table   += "0123456789:;<=>?"  ; //  48 -  63
61   _table   += "@ABCDEFGHIJKLMNO"  ; //  64 -  79
62   _table   += "PQRSTUVWXYZ[\\]^_" ; //  80 -  95
63   _table   += "`abcdefghijklmno"  ; //  96 - 111
64   _table   += "pqrstuvwxyz{|}~_"  ; // 112 - 127
65   _table   += "________________"  ; // 128 - 143
66   _table   += "________________"  ; // 144 - 159
67   _table   += "_icLoY|-_ca-__r-" ;  // 160 - 175
68   _table   += "-_23'u_..10\"___?" ;  // 176 - 191
69   _table   += "AAAAAAACEEEEIIII"  ; // 192 - 207
70   _table   += "DNOOOOOx0UUUUYPB"  ; // 208 - 223
71   _table   += "aaaaaaaceeeeiiii"  ; // 224 - 239
72   _table   += "onooooo-0uuuuypy"  ; // 240 - 255
73   //_table[167] = char(167); // '§'
74   //_table[176] = char(176); // '°'
75   DEBTRACE(_table.size() << " " << _table);
76 }
77
78 GuiEditor::~GuiEditor()
79 {
80   DEBTRACE("GuiEditor::~GuiEditor");
81 }
82
83 void GuiEditor::CreateNodeFromCatalog(const ItemMimeData* myData, SubjectComposedNode *cnode,bool createNewComponentInstance)
84 {
85   DEBTRACE("GuiEditor::CreateNodeFromCatalog");
86   int nb = myData->getDataSize();
87   DEBTRACE(nb);
88   for (int i=0; i<nb; i++)
89     {
90       Catalog* catalog = myData->getCatalog(i);
91       string compoName =  myData->getCompo(i);
92       string service = myData->getType(i);
93       DEBTRACE(compoName << "/" << service);
94       _createNode(catalog, cnode, service, compoName,createNewComponentInstance);
95     }
96 }
97
98 SubjectNode* GuiEditor::CreateNode(std::string typeNode)
99 {
100   DEBTRACE("GuiEditor::CreateNode " << typeNode);
101   YACS::ENGINE::Catalog *catalog = YACS::ENGINE::getSALOMERuntime()->getBuiltinCatalog();
102
103   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
104   if (!sub)
105     {
106       DEBTRACE("GuiEditor::CreateNode : invalid selection!");
107       return 0;
108     }
109   DEBTRACE(sub->getName());
110
111   YACS::HMI::SubjectComposedNode *cnode = dynamic_cast< YACS::HMI::SubjectComposedNode*>(sub);
112   if (!cnode)
113     {
114       DEBTRACE("GuiEditor::CreateNode : no ComposedNode selected!");
115       return 0;
116     }
117
118   return _createNode(catalog, cnode, typeNode, "", Resource::COMPONENT_INSTANCE_NEW); 
119 }
120
121 SubjectNode* GuiEditor::_createNode(YACS::ENGINE::Catalog* catalog,
122                                     SubjectComposedNode *cnode,
123                                     std::string service,
124                                     std::string compoName,
125                                     bool createNewComponentInstance)
126 {
127   SubjectNode* aNewNode = 0;
128
129   // --- find a name not used
130
131   string name = service;
132   if (name == "PresetNode")
133     name = "DataIn";
134   Node *node =cnode->getNode();
135   ComposedNode *father = dynamic_cast<ComposedNode*>(node);
136   YASSERT(father);
137   list<Node*> children = father->edGetDirectDescendants();
138   bool nameInUse = true;
139   std::stringstream tryname;
140   while (nameInUse)
141     {
142       nameInUse = false;
143       long newid = GuiContext::getCurrent()->getNewId();
144       tryname.str("");
145       tryname << name << newid;
146       if (newid > 100000) break; 
147       for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
148         {
149           if ((*it)->getName() == tryname.str())
150             nameInUse = true;
151         }
152     }
153   name = tryname.str();
154
155   int swCase = 0;
156   SubjectSwitch *aSwitch = dynamic_cast<SubjectSwitch*>(cnode);
157   if (aSwitch)
158     {
159       map<int, SubjectNode*> bodyMap = aSwitch->getBodyMap();
160       if (bodyMap.empty()) swCase = 1;
161       else
162         {
163           map<int, SubjectNode*>::reverse_iterator rit = bodyMap.rbegin();
164           swCase = (*rit).first + 1;
165         }
166       aNewNode = aSwitch->addNode(catalog, compoName, service, name, createNewComponentInstance, swCase);
167       if (!aNewNode)
168         Message mess;
169     }
170   else if (cnode && (dynamic_cast<SubjectBloc*>(cnode) == 0) && cnode->getChild() != 0)
171     {
172       // loop with a body : can't add a node
173       QMessageBox msgBox;
174       std::string msg;
175       msg="This loop has already a body. It is not possible to add directly another node\n";
176       msg=msg+"Do you want to put the existing node in a bloc and add the new node in this bloc ?\n";
177       msgBox.setText(msg.c_str());
178       msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No );
179       msgBox.setDefaultButton(QMessageBox::No);
180       int ret = msgBox.exec();
181       if(ret == QMessageBox::Yes)
182         {
183           // User wants to put body node in bloc
184           if (cnode->getChild()->putInComposedNode("Bloc1","Bloc"))
185             {
186               //the bloc has been successfully created. Add the new node
187               SubjectBloc* newbloc = dynamic_cast<SubjectBloc*>(cnode->getChild());
188               aNewNode = newbloc->addNode(catalog, compoName, service, name, createNewComponentInstance);
189               if (!aNewNode)
190                 Message mess;
191             }
192           else
193             Message mess;
194         }
195     }
196   else if (cnode)
197     aNewNode = cnode->addNode(catalog, compoName, service, name, createNewComponentInstance);
198     if (!aNewNode)
199       Message mess;
200   return aNewNode;
201 }
202
203 void GuiEditor::AddTypeFromCatalog(const ItemMimeData* myData)
204 {
205   DEBTRACE("GuiEditor::AddTypeFromCatalog");
206   SubjectProc* sProc = QtGuiContext::getQtCurrent()->getSubjectProc();
207   int nb = myData->getDataSize();
208   DEBTRACE(nb);
209   for (int i=0; i<nb; i++)
210     {
211       Catalog* catalog = myData->getCatalog(i);
212       DEBTRACE("catalog " << catalog);
213       string aType = myData->getType(i);
214       DEBTRACE(aType);
215       sProc->addDataType(catalog, aType);
216     }
217 }
218
219 void GuiEditor::CreateBloc()
220 {
221   DEBTRACE("GuiEditor::CreateBloc");
222   CreateNode("Bloc");
223 }
224
225 void GuiEditor::CreateForLoop()
226 {
227   DEBTRACE("GuiEditor::CreateForLoop");
228   CreateNode("ForLoop");
229 }
230
231 void GuiEditor::CreateForEachLoop(std::string type)
232 {
233   DEBTRACE("GuiEditor::CreateForEachLoop");
234   // The ForEachLoop node for datatype type must exist in builtin catalog
235   // So  create it in builtin catalog if it does not exist and datatype is loaded in the current Proc
236   YACS::ENGINE::Catalog *catalog = YACS::ENGINE::getSALOMERuntime()->getBuiltinCatalog();
237   Proc* proc = GuiContext::getCurrent()->getProc();
238   std::string typeName="ForEachLoop_"+type;
239   if (!catalog->_composednodeMap.count(typeName))
240     {
241       if(proc->typeMap.count(type))
242         {
243           catalog->_composednodeMap[typeName]=new ForEachLoop(typeName,proc->typeMap[type]);
244         }
245     }
246   CreateNode(typeName);
247 }
248
249 void GuiEditor::CreateWhileLoop()
250 {
251   DEBTRACE("GuiEditor::CreateWhileLoop");
252   CreateNode("WhileLoop");
253 }
254
255 void GuiEditor::CreateSwitch()
256 {
257   DEBTRACE("GuiEditor::CreateSwitch");
258   CreateNode("Switch");
259 }
260
261 void GuiEditor::CreateOptimizerLoop()
262 {
263   DEBTRACE("GuiEditor::CreateOptimizerLoop");
264   CreateNode("OptimizerLoop");
265 }
266
267 void GuiEditor::CreateContainer()
268 {
269   DEBTRACE("GuiEditor::CreateContainer");
270   SubjectProc *sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
271   YASSERT(sproc);
272   SubjectContainer *scont = 0;
273   while (!scont)
274     {
275       std::stringstream name;
276       long newid = GuiContext::getCurrent()->getNewId();
277       if (newid > 100000) break; 
278       name.str("");
279       name << "container" << newid;
280       scont = sproc->addContainer(name.str());
281     }
282 }
283
284 void GuiEditor::CreateComponentInstance()
285 {
286   DEBTRACE("GuiEditor::CreateComponentInstance");
287   SubjectProc *sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
288   YASSERT(sproc);
289   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
290   SubjectComponent *sco = dynamic_cast<SubjectComponent*>(sub);
291   if (!sco)
292     {
293       DEBTRACE("GuiEditor::CreateComponentInstance: " << "selection is not a component");
294       return;
295     }
296   string compoName = sco->getComponent()->getCompoName();
297   string containerName = sco->getComponent()->getContainer()->getName();
298   sproc->addComponent(compoName, containerName);
299 }
300
301
302 SubjectDataPort* GuiEditor::CreateInputPort(SubjectElementaryNode* seNode, 
303                                             std::string name,
304                                             YACS::ENGINE::Catalog *catalog,
305                                             std::string type,
306                                             SubjectDataPort* before)
307 {
308   DEBTRACE("GuiEditor::CreateInputPort");
309   SubjectDataPort *sdp = 0;
310   if (name.empty())
311     {
312       std::stringstream aName;
313       long newid = 0;
314       while (newid < 100000)
315         {
316           newid = GuiContext::getCurrent()->getNewId();
317           aName.str("");
318           aName << "i" << newid;
319           try
320             {
321               seNode->getNode()->getInputPort(aName.str());
322             }
323           catch(Exception& ex)
324             {
325               break;
326             }
327         }
328       sdp = seNode->addInputPort(catalog,type, aName.str());
329     }
330   else
331     sdp = seNode->addInputPort(catalog,type, name);
332   if (!sdp)
333     Message mess;
334   return sdp;
335 }
336
337 SubjectDataPort*  GuiEditor::CreateOutputPort(SubjectElementaryNode* seNode, 
338                                               std::string name,
339                                               YACS::ENGINE::Catalog *catalog,
340                                               std::string type,
341                                               SubjectDataPort* before)
342 {
343   DEBTRACE("GuiEditor::CreateOutputPort");
344   SubjectDataPort *sdp = 0;
345   if (name.empty())
346     {
347       std::stringstream aName;
348       long newid = 0;
349       while (newid < 100000)
350         {
351           newid = GuiContext::getCurrent()->getNewId();
352           aName.str("");
353           aName << "o" << newid;
354           try
355             {
356               seNode->getNode()->getOutputPort(aName.str());
357             }
358           catch(Exception& ex)
359             {
360               break;
361             }
362         }
363       sdp = seNode->addOutputPort(catalog,type, aName.str());
364     }
365   else
366     sdp = seNode->addOutputPort(catalog,type, name);
367   if (!sdp)
368     Message mess;
369   return sdp;
370 }
371
372 /*!
373  * Subject shrink or expand, command from popup menu: needs a valid selection
374  */
375 void GuiEditor::shrinkExpand(Qt::KeyboardModifiers kbModifiers) {
376   DEBTRACE("GuiEditor::shrinkExpand");
377
378   Subject* sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
379   if (!sub) {
380     DEBTRACE("GuiEditor::shrinkExpand : invalid selection!");
381     return;
382   };
383
384   if (! QtGuiContext::getQtCurrent()->_mapOfSceneItem.count(sub)) {
385     DEBTRACE("GuiEditor::shrinkExpand: no scene item corresponding to this subject");
386     return;
387   };
388
389   SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
390   SceneNodeItem *sni = dynamic_cast<SceneNodeItem*>(item);
391   if (!sni) {
392     DEBTRACE("GuiEditor::shrinkExpand: no scene node item corresponding to this subject");
393     return;
394   };
395
396   ShrinkMode aShrinkMode = CurrentNode;
397   if (kbModifiers == Qt::ControlModifier) {
398     aShrinkMode = ElementaryNodes;
399   } else if (kbModifiers == (Qt::ShiftModifier|Qt::ControlModifier)) {
400     aShrinkMode = ChildrenNodes;
401   }
402
403   sni->reorganizeShrinkExpand(aShrinkMode);
404   sni->showOutScopeLinks();
405   sni->updateLinks();
406 }
407
408 /*!
409  * Subject destruction, command from popup menu: needs a valid selection
410  */
411 void GuiEditor::DeleteSubject()
412 {
413   DEBTRACE("GuiEditor::DeleteSubject");
414   if (!QtGuiContext::getQtCurrent()->isEdition()) return;
415   QModelIndexList selList
416     = QtGuiContext::getQtCurrent()->getSelectionModel()->selectedIndexes();
417   if (selList.isEmpty())
418     return;
419
420   QModelIndex selected = selList.front();
421   if (!selected.isValid())
422     return;
423
424   SchemaItem *selItem = static_cast<SchemaItem*>(selected.internalPointer());
425   if (!selItem) return;
426   Subject *subToRemove = selItem->getSubject();
427   Subject *subParent = subToRemove->getParent();
428   DeleteSubject(subParent, subToRemove);
429 }
430
431 /*!
432  * Subject destruction, command from button in port table view or via selection
433  */
434 void GuiEditor::DeleteSubject(Subject* parent,
435                               Subject* toRemove)
436 {
437   DEBTRACE("GuiEditor::DeleteSubject "<<parent->getName()<<" "<<toRemove->getName());
438   if (!QtGuiContext::getQtCurrent()->isEdition()) return;
439   toRemove->askRegisterUndoDestroy();
440   if(!parent->destroy(toRemove))
441     Message mess;
442 }
443
444 void GuiEditor::CutSubject()
445 {
446   DEBTRACE("GuiEditor::CutSubject");
447   if (!QtGuiContext::getQtCurrent()->isEdition()) return;
448   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
449   if (!sub)
450     {
451       Message mess("GuiEditor::Cut : invalid selection!");
452       return;
453     }
454   DEBTRACE(sub->getName());
455   QtGuiContext::getQtCurrent()->setSubjectToCut(sub);
456 }
457
458 void GuiEditor::CopySubject()
459 {
460   DEBTRACE("GuiEditor::CopySubject");
461   if (!QtGuiContext::getQtCurrent()->isEdition()) return;
462   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
463   if (!sub)
464     {
465       Message mess("GuiEditor::Copy : invalid selection!");
466       return;
467     }
468   DEBTRACE(sub->getName());
469   QtGuiContext::getQtCurrent()->setSubjectToCopy(sub);
470 }
471
472 void GuiEditor::PasteSubject()
473 {
474   DEBTRACE("GuiEditor::PasteSubject");
475   if (!QtGuiContext::getQtCurrent()->isEdition()) return;
476   Subject *newParent = QtGuiContext::getQtCurrent()->getSelectedSubject();
477   if (!newParent)
478     {
479       Message mess("GuiEditor::Paste : invalid selection!");
480       return;
481     }
482   bool isCut = false;
483   Subject *sub = QtGuiContext::getQtCurrent()->getSubjectToPaste(isCut);
484   if (!sub)
485     {
486       Message mess("Nothing to paste");
487       return;
488     }
489   if (SubjectNode *snode = dynamic_cast<SubjectNode*>(sub))
490     {
491       if (isCut)
492         {
493           DEBTRACE("cut");
494           if (!snode->reparent(newParent))
495             Message mess;
496         }
497       else
498         {
499           DEBTRACE("copy");
500           if (!snode->copy(newParent))
501             Message mess;
502         }
503       return;
504     }
505   Message mess("Paste not possible for this kind of object");
506 }
507
508 void GuiEditor::PutSubjectInBloc()
509 {
510   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
511   if (!sub)
512     {
513       Message mess("GuiEditor::PutSubjectInBloc : invalid selection!");
514       return;
515     }
516   if (SubjectNode *snode = dynamic_cast<SubjectNode*>(sub))
517     {
518       //Build the set of children node names
519       Node* node=snode->getNode();
520       ComposedNode* father=node->getFather();
521       std::list<Node*> children = father->edGetDirectDescendants();
522       std::set<std::string> names;
523       for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
524         names.insert((*it)->getName());
525
526       std::stringstream tryname;
527       long newid=0;
528       while (newid < 100000)
529         {
530           tryname.str("");
531           tryname << "Bloc" << newid;
532           if(names.find(tryname.str()) == names.end())break;
533           newid++;
534         }
535       
536       if (!snode->putInComposedNode(tryname.str(),"Bloc"))
537         Message mess;
538
539       return;
540     }
541   Message mess("Put in Bloc not possible for this kind of object");
542 }
543
544 void GuiEditor::PutGraphInNode(std::string typeNode)
545 {
546   // put graph in Bloc node before
547   std::string blocname = PutGraphInBloc();
548   // put the built bloc into target node type
549   Proc* proc = GuiContext::getCurrent()->getProc();
550   Node* bloc = proc->getChildByShortName(blocname);
551   SubjectNode * sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc];
552   // create a target node
553   SubjectNode * snode = CreateNode(typeNode);
554   // put the built bloc into target node
555   sbloc->putInComposedNode(snode->getName(), typeNode);
556   // select a target node
557   YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
558   QtGuiContext::getQtCurrent()->setSelectedSubject(subproc);
559   arrangeNodes(false);
560 }
561
562 std::string GuiEditor::PutGraphInBloc()
563 {
564   Proc* proc = GuiContext::getCurrent()->getProc();
565   std::list<Node *> children = proc->edGetDirectDescendants();
566
567   //get the set of children node names
568   std::set<std::string> names;
569   for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
570     names.insert((*it)->getName());
571
572   //get the next numbered name
573   std::stringstream tryname;
574   long newid = GuiContext::getCurrent()->getNewId();
575   while (newid < 100000)
576     {
577       tryname.str("");
578       tryname << "Bloc" << newid;
579       if(names.find(tryname.str()) == names.end())break;
580       newid++;
581     }
582   std::string blocname = tryname.str();
583
584   //put one by one the child nodes of Proc node into a new Bloc node
585   std::map< std::string, std::pair<QPointF, QPointF> > aMapOfNodePosition;
586   SceneItem *item = 0;
587   SceneNodeItem *inode = 0;
588   SubjectNode * snode = 0;
589   for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
590     {
591       snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
592       snode->saveLinks();
593       item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
594       YASSERT(item);
595       inode = dynamic_cast<SceneNodeItem*>(item);
596       YASSERT(inode);
597       // save current node position to restore it after reparenting
598       aMapOfNodePosition[snode->getName()] = std::make_pair(inode->pos(), QPointF(inode->getExpandedX(), inode->getExpandedY()));
599       // put in Bloc node
600       snode->putInComposedNode(blocname, "Bloc", false);
601     }
602   for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
603     {
604       snode = 0;
605       snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
606       snode->restoreLinks();
607       item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
608       YASSERT(item);
609       inode = dynamic_cast<SceneNodeItem*>(item);
610       YASSERT(inode);
611       // restore node position
612       inode->setPos(aMapOfNodePosition[snode->getName()].first);
613       // update node position for shrink/expand operation
614       inode->setExpandedPos(aMapOfNodePosition[snode->getName()].second);
615       // notify node about position changing
616       inode->checkGeometryChange();
617     }
618   Node* bloc = proc->getChildByShortName(blocname);
619   SubjectNode* sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc];
620   item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sbloc];
621   YASSERT(item);
622   // notify bloc about child position changing
623   item->checkGeometryChange();
624   // select a target bloc
625   YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
626   QtGuiContext::getQtCurrent()->setSelectedSubject(subproc);
627   return blocname;
628 }
629
630 void GuiEditor::rebuildLinks()
631 {
632 // --- only global link redraw for now...
633   DEBTRACE("GuiEditor::rebuildLinks");
634   YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
635   SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
636   SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
637   proc->rebuildLinks();
638 }
639
640 void GuiEditor::arrangeNodes(bool isRecursive)
641 {
642   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
643   if (!sub)
644     {
645       DEBTRACE("GuiEditor::arrangeNodes : invalid selection!");
646       return;
647     }
648   DEBTRACE(sub->getName());
649
650   if (! QtGuiContext::getQtCurrent()->_mapOfSceneItem.count(sub))
651     {
652       DEBTRACE("no scene item corresponding to this subject");
653       return;
654     }
655   SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
656   SceneComposedNodeItem *sci = dynamic_cast<SceneComposedNodeItem*>(item);
657   if (! sci)
658     {
659       DEBTRACE("no scene composed node item corresponding to this subject");
660       return;
661     }
662   sci->arrangeNodes(isRecursive);
663 //   if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
664 //     {
665 //       YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
666 //       SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
667 //       SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
668 //       proc->rebuildLinks();
669 //     }
670 }
671
672 void GuiEditor::arrangeProc()
673 {
674   YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
675   SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
676   SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
677   proc->arrangeNodes(true);
678 }
679
680 void GuiEditor::showUndo(QWidget *parent)
681 {
682   FormUndoRedo *undo = new FormUndoRedo(parent);
683   undo->tabWidget->setCurrentWidget(undo->undoTab);
684   undo->exec();
685 }
686
687 void GuiEditor::showRedo(QWidget *parent)
688 {
689   FormUndoRedo *redo = new FormUndoRedo(parent);
690   redo->tabWidget->setCurrentWidget(redo->redoTab);
691   redo->exec();
692 }
693
694 /*! Replace accentuated characters from latin1 to US ascii equivalent without accent.
695 *   I did not found anything to do that in Qt...
696 */
697 QString GuiEditor::asciiFilter(const QString & name)
698 {
699   DEBTRACE(name.toStdString());
700   string aName = name.toAscii().data();
701   DEBTRACE(aName);
702   for (int i=0; i < aName.size(); i++)
703     {
704       int v = (unsigned char)(aName[i]);
705       DEBTRACE(v << " " << _table[v]);
706       aName[i] = _table[v];
707     }
708   DEBTRACE(aName);
709   return aName.c_str();
710 }