40 #include <QMessageBox> 
   50 using namespace YACS::ENGINE;
 
   51 using namespace YACS::HMI;
 
   53 GuiEditor::GuiEditor()
 
   57   _table    = 
"________________"  ; 
 
   58   _table   += 
"________________"  ; 
 
   59   _table   += 
" !\"#$%&'()*+,-./" ; 
 
   60   _table   += 
"0123456789:;<=>?"  ; 
 
   61   _table   += 
"@ABCDEFGHIJKLMNO"  ; 
 
   62   _table   += 
"PQRSTUVWXYZ[\\]^_" ; 
 
   63   _table   += 
"`abcdefghijklmno"  ; 
 
   64   _table   += 
"pqrstuvwxyz{|}~_"  ; 
 
   65   _table   += 
"________________"  ; 
 
   66   _table   += 
"________________"  ; 
 
   67   _table   += 
"_icLoY|-_ca-__r-" ;  
 
   68   _table   += 
"-_23'u_..10\"___?" ;  
 
   69   _table   += 
"AAAAAAACEEEEIIII"  ; 
 
   70   _table   += 
"DNOOOOOx0UUUUYPB"  ; 
 
   71   _table   += 
"aaaaaaaceeeeiiii"  ; 
 
   72   _table   += 
"onooooo-0uuuuypy"  ; 
 
   75   DEBTRACE(_table.size() << 
" " << _table);
 
   78 GuiEditor::~GuiEditor()
 
   85   DEBTRACE(
"GuiEditor::CreateNodeFromCatalog");
 
   88   for (
int i=0; 
i<nb; 
i++)
 
   93       DEBTRACE(compoName << 
"/" << service);
 
   94       _createNode(catalog, cnode, service, compoName,createNewComponentInstance);
 
  100   DEBTRACE(
"GuiEditor::CreateNode " << typeNode);
 
  103   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
 
  106       DEBTRACE(
"GuiEditor::CreateNode : invalid selection!");
 
  114       DEBTRACE(
"GuiEditor::CreateNode : no ComposedNode selected!");
 
  118   return _createNode(catalog, cnode, typeNode, 
"", Resource::COMPONENT_INSTANCE_NEW); 
 
  124                                     std::string compoName,
 
  125                                     bool createNewComponentInstance)
 
  131   string name = service;
 
  132   if (name == 
"PresetNode")
 
  138   bool nameInUse = 
true;
 
  139   std::stringstream tryname;
 
  143       long newid = GuiContext::getCurrent()->getNewId();
 
  145       tryname << name << newid;
 
  146       if (newid > 100000) 
break; 
 
  147       for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
 
  149           if ((*it)->getName() == tryname.str())
 
  153   name = tryname.str();
 
  159       map<int, SubjectNode*> bodyMap = aSwitch->
getBodyMap();
 
  160       if (bodyMap.empty()) swCase = 1;
 
  163           map<int, SubjectNode*>::reverse_iterator rit = bodyMap.rbegin();
 
  164           swCase = (*rit).first + 1;
 
  166       aNewNode = aSwitch->
addNode(catalog, compoName, service, name, createNewComponentInstance, swCase);
 
  170   else if (cnode && (dynamic_cast<SubjectBloc*>(cnode) == 0) && cnode->
getChild() != 0)
 
  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)
 
  188               aNewNode = newbloc->
addNode(catalog, compoName, service, name, createNewComponentInstance);
 
  197     aNewNode = cnode->
addNode(catalog, compoName, service, name, createNewComponentInstance);
 
  205   DEBTRACE(
"GuiEditor::AddTypeFromCatalog");
 
  206   SubjectProc* sProc = QtGuiContext::getQtCurrent()->getSubjectProc();
 
  209   for (
int i=0; 
i<nb; 
i++)
 
  219 void GuiEditor::CreateBloc()
 
  225 void GuiEditor::CreateForLoop()
 
  227   DEBTRACE(
"GuiEditor::CreateForLoop");
 
  228   CreateNode(
"ForLoop");
 
  231 void GuiEditor::CreateForEachLoop(std::string type)
 
  233   DEBTRACE(
"GuiEditor::CreateForEachLoop");
 
  238   std::string typeName=
"ForEachLoop_"+type;
 
  246   CreateNode(typeName);
 
  249 void GuiEditor::CreateWhileLoop()
 
  251   DEBTRACE(
"GuiEditor::CreateWhileLoop");
 
  252   CreateNode(
"WhileLoop");
 
  255 void GuiEditor::CreateSwitch()
 
  257   DEBTRACE(
"GuiEditor::CreateSwitch");
 
  258   CreateNode(
"Switch");
 
  261 void GuiEditor::CreateOptimizerLoop()
 
  263   DEBTRACE(
"GuiEditor::CreateOptimizerLoop");
 
  264   CreateNode(
"OptimizerLoop");
 
  267 void GuiEditor::CreateContainer()
 
  269   DEBTRACE(
"GuiEditor::CreateContainer");
 
  270   SubjectProc *sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
 
  275       std::stringstream name;
 
  276       long newid = GuiContext::getCurrent()->getNewId();
 
  277       if (newid > 100000) 
break; 
 
  279       name << 
"container" << newid;
 
  284 void GuiEditor::CreateHPContainer()
 
  286   DEBTRACE(
"GuiEditor::CreateHPContainer");
 
  287   SubjectProc *sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
 
  292       std::stringstream name;
 
  293       long newid = GuiContext::getCurrent()->getNewId();
 
  294       if (newid > 100000) 
break;
 
  296       name << 
"container" << newid;
 
  301 void GuiEditor::CreateComponentInstance()
 
  303   DEBTRACE(
"GuiEditor::CreateComponentInstance");
 
  304   SubjectProc *sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
 
  306   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
 
  310       DEBTRACE(
"GuiEditor::CreateComponentInstance: " << 
"selection is not a component");
 
  325   DEBTRACE(
"GuiEditor::CreateInputPort");
 
  329       std::stringstream aName;
 
  331       while (newid < 100000)
 
  333           newid = GuiContext::getCurrent()->getNewId();
 
  335           aName << 
"i" << newid;
 
  360   DEBTRACE(
"GuiEditor::CreateOutputPort");
 
  364       std::stringstream aName;
 
  366       while (newid < 100000)
 
  368           newid = GuiContext::getCurrent()->getNewId();
 
  370           aName << 
"o" << newid;
 
  392 void GuiEditor::shrinkExpand(Qt::KeyboardModifiers kbModifiers) {
 
  393   DEBTRACE(
"GuiEditor::shrinkExpand");
 
  395   Subject* sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
 
  397     DEBTRACE(
"GuiEditor::shrinkExpand : invalid selection!");
 
  401   if (! QtGuiContext::getQtCurrent()->_mapOfSceneItem.count(sub)) {
 
  402     DEBTRACE(
"GuiEditor::shrinkExpand: no scene item corresponding to this subject");
 
  406   SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
 
  409     DEBTRACE(
"GuiEditor::shrinkExpand: no scene node item corresponding to this subject");
 
  414   if (kbModifiers == Qt::ControlModifier) {
 
  416   } 
else if (kbModifiers == (Qt::ShiftModifier|Qt::ControlModifier)) {
 
  428 void GuiEditor::DeleteSubject()
 
  430   DEBTRACE(
"GuiEditor::DeleteSubject");
 
  431   if (!QtGuiContext::getQtCurrent()->isEdition()) 
return;
 
  432   QModelIndexList selList
 
  433     = QtGuiContext::getQtCurrent()->getSelectionModel()->selectedIndexes();
 
  434   if (selList.isEmpty())
 
  437   QModelIndex selected = selList.front();
 
  438   if (!selected.isValid())
 
  442   if (!selItem) 
return;
 
  445   DeleteSubject(subParent, subToRemove);
 
  451 void GuiEditor::DeleteSubject(
Subject* parent,
 
  455   if (!QtGuiContext::getQtCurrent()->isEdition()) 
return;
 
  460   QtGuiContext::getQtCurrent()->setSubjectToCopy(NULL);
 
  463 void GuiEditor::CutSubject()
 
  466   if (!QtGuiContext::getQtCurrent()->isEdition()) 
return;
 
  467   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
 
  470       Message mess(
"GuiEditor::Cut : invalid selection!");
 
  474   QtGuiContext::getQtCurrent()->setSubjectToCut(sub);
 
  477 void GuiEditor::CopySubject()
 
  480   if (!QtGuiContext::getQtCurrent()->isEdition()) 
return;
 
  481   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
 
  484       Message mess(
"GuiEditor::Copy : invalid selection!");
 
  488   QtGuiContext::getQtCurrent()->setSubjectToCopy(sub);
 
  491 void GuiEditor::PasteSubject()
 
  493   DEBTRACE(
"GuiEditor::PasteSubject");
 
  494   if (!QtGuiContext::getQtCurrent()->isEdition()) 
return;
 
  495   Subject *newParent = QtGuiContext::getQtCurrent()->getSelectedSubject();
 
  498       Message mess(
"GuiEditor::Paste : invalid selection!");
 
  502   Subject *sub = QtGuiContext::getQtCurrent()->getSubjectToPaste(isCut);
 
  505       Message mess(
"Nothing to paste");
 
  508   if (
SubjectNode *snode = dynamic_cast<SubjectNode*>(sub))
 
  513           if (!snode->reparent(newParent))
 
  519           if (!snode->copy(newParent))
 
  524   Message mess(
"Paste not possible for this kind of object");
 
  527 void GuiEditor::PutSubjectInBloc()
 
  529   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
 
  532       Message mess(
"GuiEditor::PutSubjectInBloc : invalid selection!");
 
  535   if (
SubjectNode *snode = dynamic_cast<SubjectNode*>(sub))
 
  538       Node* node=snode->getNode();
 
  541       std::set<std::string> names;
 
  542       for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
 
  543         names.insert((*it)->getName());
 
  545       std::stringstream tryname;
 
  547       while (newid < 100000)
 
  550           tryname << 
"Bloc" << newid;
 
  551           if(names.find(tryname.str()) == names.end())
break;
 
  555       if (!snode->putInComposedNode(tryname.str(),
"Bloc"))
 
  560   Message mess(
"Put in Bloc not possible for this kind of object");
 
  563 void GuiEditor::PutGraphInNode(std::string typeNode)
 
  566   std::string blocname = PutGraphInBloc();
 
  570   SubjectNode * sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc];
 
  577   QtGuiContext::getQtCurrent()->setSelectedSubject(subproc);
 
  581 std::string GuiEditor::PutGraphInBloc()
 
  587   std::set<std::string> names;
 
  588   for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
 
  589     names.insert((*it)->getName());
 
  592   std::stringstream tryname;
 
  593   long newid = GuiContext::getCurrent()->getNewId();
 
  594   while (newid < 100000)
 
  597       tryname << 
"Bloc" << newid;
 
  598       if(names.find(tryname.str()) == names.end())
break;
 
  601   std::string blocname = tryname.str();
 
  604   std::map< std::string, std::pair<QPointF, QPointF> > aMapOfNodePosition;
 
  608   for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
 
  610       snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
 
  612       item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
 
  621   for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
 
  624       snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
 
  626       item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
 
  631       inode->setPos(aMapOfNodePosition[snode->
getName()].first);
 
  638   SubjectNode* sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc];
 
  639   item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sbloc];
 
  645   QtGuiContext::getQtCurrent()->setSelectedSubject(subproc);
 
  649 void GuiEditor::rebuildLinks()
 
  652   DEBTRACE(
"GuiEditor::rebuildLinks");
 
  654   SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
 
  659 void GuiEditor::arrangeNodes(
bool isRecursive)
 
  661   Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
 
  664       DEBTRACE(
"GuiEditor::arrangeNodes : invalid selection!");
 
  669   if (! QtGuiContext::getQtCurrent()->_mapOfSceneItem.count(sub))
 
  671       DEBTRACE(
"no scene item corresponding to this subject");
 
  674   SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
 
  678       DEBTRACE(
"no scene composed node item corresponding to this subject");
 
  691 void GuiEditor::arrangeProc()
 
  694   SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
 
  702   undo->tabWidget->setCurrentWidget(undo->undoTab);
 
  709   redo->tabWidget->setCurrentWidget(redo->redoTab);
 
  716 QString GuiEditor::asciiFilter(
const QString & name)
 
  719   string aName = name.toLatin1().data();
 
  721   for (
int i=0; 
i < aName.size(); 
i++)
 
  723       int v = (
unsigned char)(aName[
i]);
 
  725       aName[
i] = _table[v];
 
  728   return aName.c_str();