]> SALOME platform Git repositories - modules/yacs.git/blob - src/gui/YACSGui_TreeViewItem.cxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / gui / YACSGui_TreeViewItem.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <YACSGui_TreeViewItem.h>
22 #include <YACSGui_TreeView.h>
23 #include <YACSGui_Executor.h>
24 #include <YACSGui_LogViewer.h>
25
26 #include <guiContext.hxx>
27
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30
31 #include <InPort.hxx>
32 #include <OutPort.hxx>
33
34 #include <OutGate.hxx>
35 #include <OutputDataStreamPort.hxx>
36
37 #include <Loop.hxx>
38 #include <ForEachLoop.hxx>
39 #include <Switch.hxx>
40 #include <ComposedNode.hxx>
41
42 #include <CORBAComponent.hxx>
43
44 #include <qpainter.h>
45 #include <qpalette.h>
46
47 //#define _DEVDEBUG_
48 #include "YacsTrace.hxx"
49
50 using namespace YACS::ENGINE;
51 using namespace YACS::HMI;
52
53 /* XPM */
54 static const char * const closed_xpm[]={
55     "16 16 6 1",
56     ". c None",
57     "b c #ffff00",
58     "d c #000000",
59     "* c #999999",
60     "a c #cccccc",
61     "c c #ffffff",
62     "................",
63     "................",
64     "..*****.........",
65     ".*ababa*........",
66     "*abababa******..",
67     "*cccccccccccc*d.",
68     "*cbababababab*d.",
69     "*cabababababa*d.",
70     "*cbababababab*d.",
71     "*cabababababa*d.",
72     "*cbababababab*d.",
73     "*cabababababa*d.",
74     "*cbababababab*d.",
75     "**************d.",
76     ".dddddddddddddd.",
77     "................"};
78
79 /* XPM */
80 static const char* const open_xpm[]={
81     "16 16 6 1",
82     ". c None",
83     "b c #ffff00",
84     "d c #000000",
85     "* c #999999",
86     "c c #cccccc",
87     "a c #ffffff",
88     "................",
89     "................",
90     "...*****........",
91     "..*aaaaa*.......",
92     ".*abcbcba******.",
93     ".*acbcbcaaaaaa*d",
94     ".*abcbcbcbcbcb*d",
95     "*************b*d",
96     "*aaaaaaaaaa**c*d",
97     "*abcbcbcbcbbd**d",
98     ".*abcbcbcbcbcd*d",
99     ".*acbcbcbcbcbd*d",
100     "..*acbcbcbcbb*dd",
101     "..*************d",
102     "...ddddddddddddd",
103     "................"};
104
105
106 /* ================ items for tree view in edition mode ================ */
107
108 // YACSGui_ViewItem class:
109
110 YACSGui_ViewItem::YACSGui_ViewItem( QListView* theParent, 
111                                     QListViewItem* theAfter ):
112   QListViewItem( theParent, theAfter ),
113   GuiObserver()
114 {
115 }
116
117 YACSGui_ViewItem::YACSGui_ViewItem( QListViewItem* theParent, 
118                                     QListViewItem* theAfter ):
119   QListViewItem( theParent, theAfter ),
120   GuiObserver(),
121   myBlockSelect( false )
122 {
123 }
124
125 /*!
126   \brief Block actions performed in select() method. Usually this method is called 
127          from select() in order to avoid circularity because of synchronization: 
128          selection in 2D viewer --> selection in tree view --> selection in 2D viewer --> etc.
129   \param toBlock block selection
130   \return previous blocking value 
131 */
132 bool YACSGui_ViewItem::blockSelection( const bool toBlock )
133 {
134   bool prevVal = myBlockSelect;
135   myBlockSelect = toBlock;
136   return prevVal;
137 }
138
139 /*!
140   \brief Verifiee whether actions performed in select() method are blocked
141          (see blockSelection method for more dscription)
142   \return blocking value 
143 */
144 bool YACSGui_ViewItem::selectionBlocked() const
145 {
146   return myBlockSelect;
147 }
148
149 void YACSGui_ViewItem::select( bool isSelected )
150 {
151   if ( selectionBlocked() )
152     return;
153
154   //printf(">> YACSGui_ViewItem::select( %d ) \n", isSelected );
155
156   if ( !isSelected ) // do nothing
157     return;
158
159   // select item in tree view
160   QListView* aListView = listView();
161   if ( !aListView )
162     return;
163
164   bool block = aListView->signalsBlocked();
165   aListView->blockSignals( true );
166
167   blockSelection( true );
168   aListView->clearSelection();
169   aListView->setCurrentItem( this );
170   aListView->setSelected( this, true );
171   aListView->ensureItemVisible( this );
172   blockSelection( false );
173
174   aListView->blockSignals( block );
175   
176   if ( YACSGui_EditionTreeView* aETV = dynamic_cast<YACSGui_EditionTreeView*>(aListView) )
177     aETV->emitSelectionChanged();
178 }
179
180 void YACSGui_ViewItem::removeNodeItem( YACS::HMI::Subject* theSNode )
181 {
182   //printf( "YACSGui_ViewItem::removeNodeItem (this=%s)\n", text(0).latin1() );
183   QListViewItem* aNodesL = this;
184   if( !aNodesL->parent() )
185   {
186     // get the "Nodes" label view item, which is used as a parent for first level nodes
187     aNodesL = firstChild()->nextSibling();
188     if ( !aNodesL || aNodesL->text(0).compare(QString("Nodes")) )
189       return;
190   }
191
192   YACSGui_NodeViewItem* aNode = 0;
193   QListViewItem* aChild = aNodesL->firstChild();
194   while( aChild )
195   {
196     if ( aNode = dynamic_cast<YACSGui_NodeViewItem*>(aChild) )
197       if ( aNode->getSNode() == theSNode )
198       {
199         //printf(">> the son is found\n");
200         break;
201       }
202
203     aChild = aChild->nextSibling();
204   }    
205
206   if ( aNode )
207   {
208     if( YACS::HMI::SubjectNode* aSNode = dynamic_cast<SubjectNode*>( theSNode ) )
209     {
210       //printf( ">> remove control links\n" );
211       std::list<SubjectControlLink*> aControlLinks = aSNode->getSubjectControlLinks();
212       std::list<SubjectControlLink*>::iterator cIt = aControlLinks.begin();
213       std::list<SubjectControlLink*>::iterator cItEnd = aControlLinks.end();
214       for( ; cIt != cItEnd; cIt++ )
215       {
216         SubjectControlLink* aControlLink = *cIt;
217         if( aControlLink )
218         {
219           Subject* aParentSNode = aControlLink->getSubjectOutNode()->getParent();
220           aParentSNode->update( REMOVE, CONTROLLINK, aControlLink );
221         }
222       }
223
224       //printf( ">> remove data links\n" );
225       std::list<SubjectLink*> aDataLinks = aSNode->getSubjectLinks();
226       std::list<SubjectLink*>::iterator dIt = aDataLinks.begin();
227       std::list<SubjectLink*>::iterator dItEnd = aDataLinks.end();
228       for( ; dIt != dItEnd; dIt++ )
229       {
230         SubjectLink* aDataLink = *dIt;
231         if( aDataLink )
232         {
233           Subject* aParentSNode = aDataLink->getSubjectOutNode()->getParent();
234           aParentSNode->update( REMOVE, DATALINK, aDataLink );
235         }
236       }
237
238       //printf( ">> remove port links\n" );
239       std::list<SubjectDataPort*> aDataPorts;
240
241       std::list<SubjectInputPort*> anInputPorts = aSNode->getSubjectInputPorts();
242       for( std::list<SubjectInputPort*>::iterator pIt = anInputPorts.begin(); pIt != anInputPorts.end(); pIt++ )
243         aDataPorts.push_back( *pIt );
244
245       std::list<SubjectOutputPort*> anOutputPorts = aSNode->getSubjectOutputPorts();
246       for( std::list<SubjectOutputPort*>::iterator pIt = anOutputPorts.begin(); pIt != anOutputPorts.end(); pIt++ )
247         aDataPorts.push_back( *pIt );
248
249       std::list<SubjectInputDataStreamPort*> anInputDataStreamPorts = aSNode->getSubjectInputDataStreamPorts();
250       for( std::list<SubjectInputDataStreamPort*>::iterator pIt = anInputDataStreamPorts.begin();
251            pIt != anInputDataStreamPorts.end(); pIt++ )
252         aDataPorts.push_back( *pIt );
253
254       std::list<SubjectOutputDataStreamPort*> anOutputDataStreamPorts = aSNode->getSubjectOutputDataStreamPorts();
255       for( std::list<SubjectOutputDataStreamPort*>::iterator pIt = anOutputDataStreamPorts.begin();
256            pIt != anOutputDataStreamPorts.end(); pIt++ )
257         aDataPorts.push_back( *pIt );
258
259       std::list<SubjectDataPort*>::iterator dpIt = aDataPorts.begin();
260       std::list<SubjectDataPort*>::iterator dpItEnd = aDataPorts.end();
261       for( ; dpIt != dpItEnd; dpIt++ )
262       {
263         SubjectDataPort* aDataPort = *dpIt;
264         if( aDataPort )
265         {
266           std::list<SubjectLink*> lsl = aDataPort->getListOfSubjectLink();
267           for( std::list<SubjectLink*>::iterator it = lsl.begin(); it != lsl.end(); ++it )
268           {
269             SubjectLink* aLink = *it;
270             if( aLink )
271             {
272               //printf( ">> link : %s\n", aLink->getName().c_str() );
273               SubjectNode* aNode1 = aLink->getSubjectInNode();
274               SubjectNode* aNode2 = aLink->getSubjectOutNode();
275               //printf( ">> nodes : %s - %s\n", aNode1->getName().c_str(), aNode2->getName().c_str() );
276               if( SubjectComposedNode* aLowestCommonAncestor =
277                   SubjectComposedNode::getLowestCommonAncestor( aNode1, aNode2 ) )
278               {
279                 //printf( ">> lowest common ancestor : %s\n", aLowestCommonAncestor->getName().c_str() );
280                 aLowestCommonAncestor->update( REMOVE, DATALINK, aLink );
281               }
282             }
283           }
284         }
285       }
286
287       //printf( ">> remove leaving/coming current scope links\n" );
288       std::vector< std::pair<OutPort *, InPort *> > listLeaving  = aSNode->getNode()->getSetOfLinksLeavingCurrentScope();
289       std::vector< std::pair<InPort *, OutPort *> > listIncoming = aSNode->getNode()->getSetOfLinksComingInCurrentScope();
290       std::vector< std::pair<OutPort *, InPort *> > globalList = listLeaving;
291       std::vector< std::pair<InPort *, OutPort *> >::iterator it1;
292       for (it1 = listIncoming.begin(); it1 != listIncoming.end(); ++it1)
293       {
294         std::pair<OutPort *, InPort *> outin = std::pair<OutPort *, InPort *>((*it1).second, (*it1).first);
295         globalList.push_back(outin);
296       }
297       std::vector< std::pair<OutPort *, InPort *> >::iterator it2;
298       for (it2 = globalList.begin(); it2 != globalList.end(); ++it2)
299       {
300         if (GuiContext::getCurrent()->_mapOfSubjectLink.count(*it2))
301         {
302           SubjectLink* aLink = GuiContext::getCurrent()->_mapOfSubjectLink[*it2];
303           if( aLink )
304           {
305             //printf( ">> link : %s\n", aLink->getName().c_str() );
306             SubjectNode* aNode1 = aLink->getSubjectInNode();
307             SubjectNode* aNode2 = aLink->getSubjectOutNode();
308             //printf( ">> nodes : %s - %s\n", aNode1->getName().c_str(), aNode2->getName().c_str() );
309             if( SubjectComposedNode* aLowestCommonAncestor =
310                 SubjectComposedNode::getLowestCommonAncestor( aNode1, aNode2 ) )
311             {
312               //printf( ">> lowest common ancestor : %s\n", aLowestCommonAncestor->getName().c_str() );
313               aLowestCommonAncestor->update( REMOVE, DATALINK, aLink );
314             }
315           }
316         }
317       }
318     }
319
320     DEBTRACE(">> delete the son item");
321     aNodesL->takeItem(aNode);
322     delete aNode;
323     aNode = 0;
324   }
325 }
326
327 void YACSGui_ViewItem::removeLinkItem( YACS::HMI::Subject* theSLink )
328 {
329   DEBTRACE( "YACSGui_ViewItem::removeLinkItem " << text(0).latin1() );
330   SubjectLink* aSLink = dynamic_cast<SubjectLink*>(theSLink);
331   SubjectControlLink* aSCLink = dynamic_cast<SubjectControlLink*>(theSLink);
332   if ( aSLink || aSCLink )
333   {
334     // get the "Links" label view item under the parent node of this node view item
335     YACSGui_LabelViewItem* aLinksL = 0;
336     QListViewItem* aChildLinks = this;
337     if( !aChildLinks->parent() )
338       aChildLinks = aChildLinks->firstChild();
339     while( aChildLinks )
340     {
341       DEBTRACE( ">> item : " << aChildLinks->text(0).latin1() );
342       aLinksL = dynamic_cast<YACSGui_LabelViewItem*>(aChildLinks);
343       if ( aLinksL && aLinksL->text(0).compare(QString("Links")) == 0 )
344         break;
345       aChildLinks = aChildLinks->nextSibling();
346     }
347
348     if ( !aLinksL )
349       return;
350
351     // find the link item published under in the Links folder to delete
352     QListViewItem* aChild = aLinksL->firstChild();
353     while( aChild )
354     {
355       if ( aSLink )
356       {
357         if ( YACSGui_LinkViewItem* aLink = dynamic_cast<YACSGui_LinkViewItem*>(aChild) )
358           if ( aLink->getSLink() == aSLink )
359           {
360             DEBTRACE(">> the data link is found");
361             aLinksL->takeItem(aChild);
362             delete aChild;
363             break;
364           }
365       }
366       else if ( aSCLink )
367       {
368         if ( YACSGui_ControlLinkViewItem* aCLink = dynamic_cast<YACSGui_ControlLinkViewItem*>(aChild) )
369           if ( aCLink->getSLink() == aSCLink )
370           {
371             DEBTRACE(">> the control link is found");
372             aLinksL->takeItem(aChild);
373             delete aChild;
374             break;
375           }
376       }
377       
378       aChild = aChild->nextSibling();
379     }
380   }
381 }
382
383 // YACSGui_LabelViewItem class:
384
385 YACSGui_LabelViewItem::YACSGui_LabelViewItem( QListView* theParent, 
386                                               QListViewItem* theAfter, 
387                                               const QString theName ):
388   YACSGui_ViewItem( theParent, theAfter ),
389   myName( theName )
390 {
391   if ( !myName.isEmpty() )
392     setText( 0, myName );
393   setPixmap( 0, icon() );
394 }
395
396 YACSGui_LabelViewItem::YACSGui_LabelViewItem( QListViewItem* theParent, 
397                                               QListViewItem* theAfter, 
398                                               const QString theName ):
399   YACSGui_ViewItem( theParent, theAfter ),
400   myName( theName )
401 {
402   if ( !myName.isEmpty() )
403     setText( 0, myName );
404   setPixmap( 0, icon() );
405 }
406  
407 QString YACSGui_LabelViewItem::name() const
408 {
409   return myName;
410 }
411
412 QPixmap YACSGui_LabelViewItem::icon() const
413 {
414   if ( isOpen() )
415     return QPixmap( (const char**) open_xpm );
416   return QPixmap( (const char**) closed_xpm );
417 }
418
419 void YACSGui_LabelViewItem::select( bool isSelected )
420 {
421   //printf(">> YACSGui_ReferenceViewItem::select( %d ) does nothing\n", isSelected);
422 }
423
424 void YACSGui_LabelViewItem::update( const bool theIsRecursive )
425 {
426
427 }
428
429 // YACSGui_ReferenceViewItem class:
430
431 YACSGui_ReferenceViewItem::YACSGui_ReferenceViewItem( QListView* theParent, 
432                                                       QListViewItem* theAfter,
433                                                       YACS::HMI::SubjectReference* theSReference ):
434   YACSGui_ViewItem( theParent, theAfter ),
435   mySReference( theSReference )
436 {
437   if ( mySReference ) mySReference->attach(this);
438   
439   QString aName = name();
440   if ( !aName.isEmpty() )
441     setText( 0, aName );
442   setPixmap( 0, icon() );
443 }
444
445 YACSGui_ReferenceViewItem::YACSGui_ReferenceViewItem( QListViewItem* theParent, 
446                                             QListViewItem* theAfter,
447                                             YACS::HMI::SubjectReference* theSReference ):
448   YACSGui_ViewItem( theParent, theAfter ),
449   mySReference( theSReference )
450 {
451   if ( mySReference ) mySReference->attach(this);
452
453   QString aName = name();
454   if ( !aName.isEmpty() )
455     setText( 0, aName );
456   setPixmap( 0, icon() );
457 }
458
459 YACSGui_ReferenceViewItem::~YACSGui_ReferenceViewItem()
460 {
461   if ( mySReference ) mySReference->detach(this);
462 }
463
464 void YACSGui_ReferenceViewItem::select(bool isSelected)
465 {
466   //printf(">> YACSGui_ReferenceViewItem::select( %d ) does nothing\n", isSelected);
467   DEBTRACE(">> YACSGui_ReferenceViewItem::select( " << isSelected << " ) does nothing");
468 }
469
470 void YACSGui_ReferenceViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
471 {
472   //printf(">> YACSGui_ReferenceViewItem::update\n");
473   DEBTRACE(">> YACSGui_ReferenceViewItem::update");
474   switch (event)
475   {
476   case RENAME:
477     update();
478     break;
479   default:
480     GuiObserver::update(event, type, son);
481   }
482 }
483   
484 QString YACSGui_ReferenceViewItem::name() const
485 {
486   QString aName;
487   
488   if (getNode())
489     aName = QString("* ") + QString(getNode()->getRootNode()->getChildName(getNode()));
490
491   return aName;
492 }
493
494 QColor YACSGui_ReferenceViewItem::color( const ColorRole theCR ) const
495 {
496   QColor clr;
497   switch ( theCR )
498   {
499   case Text:
500   case Highlight:
501     clr = QColor( 255, 0, 0 );
502     break;
503   case HighlightedText:
504     clr = QColor( 255, 255, 255 );
505     break;
506   }
507   return clr;
508 }
509
510 QPixmap YACSGui_ReferenceViewItem::icon() const
511 {
512   return QPixmap();
513 }
514
515 YACS::ENGINE::Node* YACSGui_ReferenceViewItem::getNode() const
516 {
517   Node* aRet = 0;
518
519   if ( mySReference )
520     if ( SubjectServiceNode* aSSN = dynamic_cast<SubjectServiceNode*>( mySReference->getParent() ) )
521       aRet = aSSN->getNode();
522
523   return aRet;
524 }
525
526 void YACSGui_ReferenceViewItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align )
527 {
528   QColorGroup col_group( cg );
529
530   if ( color( YACSGui_ReferenceViewItem::Text ).isValid() )
531     col_group.setColor( QColorGroup::Text, color( YACSGui_ReferenceViewItem::Text ) );
532   if ( color( YACSGui_ReferenceViewItem::Highlight ).isValid() )
533     col_group.setColor( QColorGroup::Highlight, color( YACSGui_ReferenceViewItem::Highlight ) );
534   if ( color( YACSGui_ReferenceViewItem::HighlightedText ).isValid() )
535     col_group.setColor( QColorGroup::HighlightedText, color( YACSGui_ReferenceViewItem::HighlightedText ) );
536
537   p->fillRect( 0, 0, w, height(), cg.brush( QColorGroup::Base ) );
538
539   int W = w;
540   if ( listView() && !listView()->allColumnsShowFocus() )
541     W = width( p->fontMetrics(), listView(), c );
542
543   QListViewItem::paintCell( p, col_group, c, W<w ? W : w, align );
544 }
545
546 void YACSGui_ReferenceViewItem::update( const bool theIsRecursive )
547 {
548   setText( 0, name() ); // only rename
549 }
550
551 // YACSGui_PortViewItem class:
552
553 YACSGui_PortViewItem::YACSGui_PortViewItem( QListView* theParent, 
554                                             QListViewItem* theAfter,
555                                             YACS::HMI::SubjectDataPort* theSPort ):
556   YACSGui_ViewItem( theParent, theAfter ),
557   mySPort( theSPort )
558 {
559   if ( mySPort )
560   {
561     mySPort->attach( this );
562
563     QString aName = name();
564     if ( !aName.isEmpty() )
565       setText( 0, aName );
566     setPixmap( 0, icon() );
567   }
568 }
569
570 YACSGui_PortViewItem::YACSGui_PortViewItem( QListViewItem* theParent, 
571                                             QListViewItem* theAfter,
572                                             YACS::HMI::SubjectDataPort* theSPort ):
573   YACSGui_ViewItem( theParent, theAfter ),
574   mySPort( theSPort )
575 {
576   if ( mySPort )
577   {
578     mySPort->attach( this );
579     
580     QString aName = name();
581     if ( !aName.isEmpty() )
582       setText( 0, aName );
583     setPixmap( 0, icon() );
584   }
585 }
586
587 YACSGui_PortViewItem::~YACSGui_PortViewItem()
588 {
589   if ( mySPort ) mySPort->detach(this);
590 }
591
592 QString YACSGui_PortViewItem::name() const
593 {
594   QString aName = "";
595
596   DataPort* aDataPort = getPort();
597   if (aDataPort)
598     aName = aDataPort->getName();
599   
600   return aName;
601 }
602
603 QPixmap YACSGui_PortViewItem::icon() const
604 {
605   QPixmap aRes;
606   
607   QString anIconName;
608
609   if ( dynamic_cast<OutPort*>( getPort() ) )
610     anIconName = QString(QObject::tr("ICON_OUT_PORT_OBJECT"));
611   else if ( dynamic_cast<InPort*>( getPort() ) )
612     anIconName = QString(QObject::tr("ICON_IN_PORT_OBJECT"));
613
614   if ( !anIconName.isEmpty() )
615     aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS",  anIconName, false);
616   
617   return aRes;
618 }
619
620 YACS::ENGINE::DataPort* YACSGui_PortViewItem::getPort() const
621 {
622   return ( mySPort ? mySPort->getPort() : 0 );
623 }
624
625 void YACSGui_PortViewItem::update( const bool theIsRecursive )
626 {
627
628 }
629
630 // YACSGui_DataTypeItem class:
631
632 /*!
633   \brief Constructor
634 */
635 YACSGui_DataTypeItem::YACSGui_DataTypeItem( QListView*                  theParent,
636                                             QListViewItem*              theAfter,
637                                             YACS::HMI::SubjectDataType* theSDataType )
638 : YACSGui_ViewItem( theParent, theAfter ),
639   mySDataType( theSDataType )
640 {
641   if ( theSDataType ) 
642     theSDataType->attach( this );
643
644   QString aName = name();
645   if ( !aName.isEmpty() )
646     setText( 0, aName );
647   setPixmap( 0, icon() );
648 }
649
650 /*!
651   \brief Constructor
652 */
653 YACSGui_DataTypeItem::YACSGui_DataTypeItem( QListViewItem* theParent, 
654                                             QListViewItem* theAfter,
655                                             YACS::HMI::SubjectDataType* theSDataType )
656 : YACSGui_ViewItem( theParent, theAfter ),
657   mySDataType( theSDataType )
658 {
659   if ( theSDataType ) 
660     theSDataType->attach( this );
661
662   QString aName = name();
663   if ( !aName.isEmpty() )
664     setText( 0, aName );
665   setPixmap( 0, icon() );
666 }
667
668 /*!
669   \brief Destructor
670 */
671 YACSGui_DataTypeItem::~YACSGui_DataTypeItem()
672 {
673 }
674   
675 /*!
676   \brief Updates item in accordance with GUI event
677 */
678 void YACSGui_DataTypeItem::update( YACS::HMI::GuiEvent event, 
679                                    int type, 
680                                    YACS::HMI::Subject* son )
681 {
682   //printf(">> YACSGui_DataTypeItem::update\n");
683   DEBTRACE(">> YACSGui_DataTypeItem::update");
684   switch ( event )
685   {
686   case RENAME:
687     update();
688     break;
689   default:
690     GuiObserver::update( event, type, son );
691     break;
692   }
693 }
694
695 /*!
696   \brief Gets item name
697 */
698 QString YACSGui_DataTypeItem::name() const
699 {
700   QString aName;
701   if ( mySDataType )
702     aName = QString( mySDataType->getName() );
703   return aName;
704 }
705
706 /*!
707   \brief Gets item icon
708 */
709 QPixmap YACSGui_DataTypeItem::icon()
710 {
711   QPixmap aRes;
712   QString anIconName( QObject::tr( "ICON_TEXT" ) ); 
713   
714   aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false );
715
716   return aRes;
717 }
718   
719 void YACSGui_DataTypeItem::update( const bool /*theIsRecursive*/ )
720 {
721   // nothing to be updated
722 }
723
724 // YACSGui_NodeViewItem class:
725
726 YACSGui_NodeViewItem::YACSGui_NodeViewItem( QListView* theParent, 
727                                             QListViewItem* theAfter,
728                                             YACS::HMI::SubjectNode* theSNode ):
729   YACSGui_ViewItem( theParent, theAfter ),
730   mySNode( theSNode )
731 {
732   if ( mySNode ) mySNode->attach(this);
733
734   QString aName = name();
735   if ( !aName.isEmpty() )
736     setText( 0, aName );
737   setPixmap( 0, icon() );
738 }
739
740 YACSGui_NodeViewItem::YACSGui_NodeViewItem( QListViewItem* theParent, 
741                                             QListViewItem* theAfter,
742                                             YACS::HMI::SubjectNode* theSNode ):
743   YACSGui_ViewItem( theParent, theAfter ),
744   mySNode( theSNode )
745 {
746   if ( mySNode ) mySNode->attach(this);
747
748   QString aName = name();
749   if ( !aName.isEmpty() )
750     setText( 0, aName );
751   setPixmap( 0, icon() );
752 }
753
754 YACSGui_NodeViewItem::~YACSGui_NodeViewItem()
755 {
756   if ( mySNode ) mySNode->detach(this);
757 }
758
759 void YACSGui_NodeViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
760 {
761   DEBTRACE(">> YACSGui_NodeViewItem::update");
762   switch (event)
763   {
764   case RENAME:
765     update();
766     break;
767   case EDIT:
768     switch (type)
769     {
770     case INPUTPORT:
771     case OUTPUTPORT:
772     case INPUTDATASTREAMPORT:
773     case OUTPUTDATASTREAMPORT:
774       {
775         // rename a port item (this = node item)
776         //printf("NodeViewItem:  EDIT port\n");
777         renamePortItem(son);
778       }
779       break;
780     default:
781       {
782         if ( !type )
783           update(true);
784       }
785       break;
786     }
787     break;
788   case ADDREF:
789     {
790       // add a reference item (this = node item)
791       //printf("NodeViewItem:  ADDREF\n");
792       addReferenceItem(son);
793     }
794     break;
795   case ADD:
796     switch (type)
797     {
798     case INPUTPORT:
799     case OUTPUTPORT:
800     case INPUTDATASTREAMPORT:
801     case OUTPUTDATASTREAMPORT:
802       {
803         // add a port item (this = node item)
804         //printf("NodeViewItem:  ADD port\n");
805         addPortItem(son);
806       }
807       break;
808     case BLOC:
809     case FOREACHLOOP:
810     case OPTIMIZERLOOP:
811     case FORLOOP:
812     case WHILELOOP:
813     case SWITCH:
814     case PYTHONNODE:
815     case PYFUNCNODE:
816     case CORBANODE:
817     case SALOMENODE:
818     case CPPNODE:
819     case SALOMEPYTHONNODE:
820     case PRESETNODE:
821     case OUTNODE:
822     case STUDYINNODE:
823     case STUDYOUTNODE:
824     case XMLNODE:
825       {
826         // remove a node inside a block (this = block item)
827         DEBTRACE("NodeViewItem:  ADD");
828         addNodeItem(son);
829       }
830       break;
831     default:
832       break;
833     }
834     break;
835   case REMOVE:
836     switch (type)
837     {
838     case DATATYPE:
839       {
840         // Readdress this event to schema item 
841         YACSGui_SchemaViewItem* aSchema = 
842           dynamic_cast<YACSGui_SchemaViewItem*>( listView()->firstChild() );
843           if ( aSchema )
844             aSchema->update( event, type, son );
845       }
846       break;
847     case DATALINK:
848     case CONTROLLINK:
849       {
850         // remove a link item (this = out node item)
851         DEBTRACE("NodeViewItem:  REMOVE link");
852         removeLinkItem(son);
853       }
854       break;
855     case INPUTPORT:
856     case OUTPUTPORT:
857     case INPUTDATASTREAMPORT:
858     case OUTPUTDATASTREAMPORT:
859       {
860         // remove a port item (this = node item)
861         DEBTRACE("NodeViewItem:  REMOVE port");
862         removePortItem(son);
863       }
864       break;
865     case BLOC:
866     case FOREACHLOOP:
867     case OPTIMIZERLOOP:
868     case FORLOOP:
869     case WHILELOOP:
870     case SWITCH:
871     case PYTHONNODE:
872     case PYFUNCNODE:
873     case CORBANODE:
874     case SALOMENODE:
875     case CPPNODE:
876     case SALOMEPYTHONNODE:
877     case PRESETNODE:
878     case OUTNODE:
879     case STUDYINNODE:
880     case STUDYOUTNODE:
881     case XMLNODE:
882       {
883         // remove a node inside a block (this = block item)
884         //printf("NodeViewItem:  REMOVE\n");
885         removeNodeItem(son);
886       }
887       break;
888     case REFERENCE:
889       {
890         // remove a reference to a component (this = service node item)
891         //printf("NodeViewItem:  REMOVE reference\n");
892         removeReferenceItem(son);
893       }
894       break;
895     default:
896       break;
897     }
898     break;
899   case UP:
900     switch (type)
901     {
902     case INPUTPORT:
903     case OUTPUTPORT:
904     case INPUTDATASTREAMPORT:
905     case OUTPUTDATASTREAMPORT: 
906       {
907         // move up a port item (this = node item)
908         //printf("NodeViewItem:  UP port\n");
909         moveUpPortItem(son);
910       }
911       break;
912     default:
913       break;
914     }
915     break;
916   case DOWN:
917     switch (type)
918     {
919     case INPUTPORT:
920     case OUTPUTPORT:
921     case INPUTDATASTREAMPORT:
922     case OUTPUTDATASTREAMPORT: 
923       {
924         // move down a port item (this = node item)
925         DEBTRACE("NodeViewItem:  DOWN port");
926         moveDownPortItem(son);
927       }
928       break;
929     default:
930       break;
931     }
932     break;
933   case ADDLINK:
934   case ADDCONTROLLINK:
935     {
936       // add link item (this = composed node item)
937       DEBTRACE("NodeViewItem:  ADDLINK");
938       addLinkItem(son);
939     }
940     break;
941   default:
942     GuiObserver::update(event, type, son);
943   }
944 }
945   
946 QString YACSGui_NodeViewItem::name() const
947 {
948   QString aName;
949   
950   if (getNode())
951     aName = QString(getNode()->getName());
952
953   return aName;
954 }
955
956 QPixmap YACSGui_NodeViewItem::icon( YACS::ENGINE::Node* theNode )
957 {
958   QPixmap aRes;
959
960   QString anIconName;
961     
962   if ( dynamic_cast<Bloc*>( theNode ) )
963     anIconName = QString(QObject::tr("ICON_BLOCK_OBJECT"));
964   else if ( dynamic_cast<Loop*>( theNode ) || dynamic_cast<ForEachLoop*>( theNode ) )
965     anIconName = QString(QObject::tr("ICON_LOOP_NODE_OBJECT"));
966   else if ( dynamic_cast<Switch*>( theNode ) )
967     anIconName = QString(QObject::tr("ICON_SWITCH_NODE_OBJECT"));
968   else
969     anIconName = QString(QObject::tr("ICON_NODE_OBJECT"));
970   
971   if ( !anIconName.isEmpty() )
972     aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
973   
974   return aRes;
975 }
976
977 QPixmap YACSGui_NodeViewItem::icon() const
978 {
979   return icon( getNode() );
980 }
981
982 YACS::ENGINE::Node* YACSGui_NodeViewItem::getNode() const
983 {
984   return ( mySNode ? mySNode->getNode() : 0 );
985 }
986
987 void YACSGui_NodeViewItem::update( const bool theIsRecursive )
988 {
989   if ( theIsRecursive ) // total update
990   {
991     ComposedNode* aComposedNode = dynamic_cast<ComposedNode*>( getNode() );
992     
993     std::list<SubjectNode*> aChildrenToMove;
994     
995     QListViewItem* aChild = firstChild();
996     while( aChild )
997     {
998       if ( aComposedNode )
999       { // this node is a block
1000         if ( YACSGui_NodeViewItem* aChildNode = dynamic_cast<YACSGui_NodeViewItem*>( aChild ) )
1001         {
1002           if ( !aComposedNode->isInMyDescendance( aChildNode->getNode() ) )
1003           { // a current child is not in the block now
1004             aChildrenToMove.push_back( aChildNode->getSNode() );
1005           }
1006         }
1007       }
1008       
1009       // remove old child objects of this view item (this case is suitable for the elementary nodes,
1010       // where we delete and recreate its ports)
1011       takeItem(aChild);
1012       delete aChild;
1013       
1014       aChild = firstChild();
1015     }
1016     
1017     if ( YACSGui_EditionTreeView* anETV = dynamic_cast<YACSGui_EditionTreeView*>(listView()) )
1018       anETV->displayChildren( this );
1019
1020     if ( aComposedNode )
1021       if ( YACSGui_SchemaViewItem* aSchema = dynamic_cast<YACSGui_SchemaViewItem*>(listView()->firstChild()) )
1022       {
1023         //aSchema->update( true, 0, this );
1024         
1025         if ( !aChildrenToMove.empty() )
1026         { 
1027           // get the "Nodes" label view item, which is used as a parent for first level nodes
1028           YACSGui_LabelViewItem* aNodesL = 
1029             dynamic_cast<YACSGui_LabelViewItem*>(listView()->firstChild()->firstChild()->nextSibling());
1030           if ( !aNodesL || aNodesL->text(0).compare(QString("Nodes")) ) return;
1031         
1032           // find the last view item under "Nodes" label
1033           YACSGui_NodeViewItem* aLast = 0;
1034           QListViewItem* aChildL = aNodesL->firstChild();
1035           while( aChildL )
1036           {
1037             if ( YACSGui_NodeViewItem* aChildLNodeItem = dynamic_cast<YACSGui_NodeViewItem*>(aChildL) )
1038               aLast = aChildLNodeItem;
1039             aChildL = aChildL->nextSibling();
1040           }
1041         
1042           if ( YACSGui_EditionTreeView* anETV = dynamic_cast<YACSGui_EditionTreeView*>(listView()) )
1043           {
1044             std::list<SubjectNode*>::iterator anIt = aChildrenToMove.begin();
1045             for (; anIt != aChildrenToMove.end(); anIt++)
1046             {
1047               // create list view items after the last view item under "Nodes" label
1048               aLast = anETV->displayNodeWithPorts( aNodesL, aLast, *anIt );
1049             }
1050           }
1051
1052         }
1053       }
1054   }
1055   
1056   setText( 0, name() ); // only rename
1057 }
1058
1059 void YACSGui_NodeViewItem::renamePortItem( YACS::HMI::Subject* theSPort )
1060 {
1061   if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1062   {
1063     YACSGui_PortViewItem* aPort = 0;
1064     QListViewItem* aChild = firstChild();
1065     while( aChild )
1066     {
1067       if ( aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1068         if ( aPort->getPort() == aSPort->getPort() )
1069         {
1070           //printf(">> the son is found\n");
1071           break;
1072         }
1073       
1074       aChild = aChild->nextSibling();
1075     }
1076     
1077     if ( aPort )
1078     {
1079       //printf(">> rename the son item\n");
1080       aPort->setText( 0, aPort->name() );
1081     }
1082   }
1083 }
1084
1085 void YACSGui_NodeViewItem::addPortItem( YACS::HMI::Subject* theSPort )
1086 {
1087   if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1088   {
1089     Port* aPort = aSPort->getPort();
1090     if ( !aPort ) return;
1091
1092     if ( isPublished(aPort) ) return;
1093
1094     YACSGui_PortViewItem* aPortItem = new YACSGui_PortViewItem( this, 0, aSPort );
1095     if ( !aPortItem ) return;
1096
1097     Port* anAfter = 0;
1098     // find the port, after which aPort is stored in the engine
1099     if ( dynamic_cast<InPort*>(aPort) )
1100     {
1101       std::list<InPort *> anInPorts = getNode()->getSetOfInPort();
1102       std::list<InPort *>::iterator InPortsIter = anInPorts.begin();
1103       for(; InPortsIter != anInPorts.end(); InPortsIter++)
1104       {
1105         if ( *InPortsIter == aPort ) break;
1106         anAfter = *InPortsIter;
1107       }
1108     }
1109     else if ( dynamic_cast<OutPort*>(aPort) )
1110     {
1111       std::list<OutPort *> anOutPorts = getNode()->getSetOfOutPort();
1112       std::list<OutPort *>::iterator OutPortsIter = anOutPorts.begin();
1113       for(; OutPortsIter != anOutPorts.end(); OutPortsIter++)
1114       {
1115         if ( *OutPortsIter == aPort ) break;
1116         anAfter = *OutPortsIter;
1117       }
1118     }
1119     
1120     // find the port, after which aPortItem should be stored in the tree
1121     YACSGui_PortViewItem* anAfterItem = 0;
1122
1123     QListViewItem* aChild;
1124     if ( dynamic_cast<InPort*>(aPort) )
1125       aChild = firstChild();
1126     else if ( dynamic_cast<OutPort*>(aPort) )
1127     {
1128       // find tree view item corresponds to the last input port
1129       QListViewItem* aLastInPort = firstChild();
1130       while( aLastInPort )
1131       {
1132         if ( YACSGui_PortViewItem* aFirstOutPortItem = dynamic_cast<YACSGui_PortViewItem*>(aLastInPort->nextSibling()) )
1133           if ( dynamic_cast<OutPort*>(aFirstOutPortItem->getPort()) )
1134             break;
1135         aLastInPort = aLastInPort->nextSibling();
1136       }
1137       aChild = aLastInPort;
1138       
1139       if ( !anAfter )
1140       {
1141         aPortItem->moveItem(aLastInPort);
1142         return;
1143       }
1144     }
1145
1146     while( aChild )
1147     {
1148       if ( anAfterItem = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1149         if ( anAfterItem->getPort() == anAfter )
1150         {
1151           //printf(">> the son is found\n");
1152           aPortItem->moveItem(anAfterItem);
1153           break;
1154         }
1155       
1156       aChild = aChild->nextSibling();
1157     }
1158   }
1159 }
1160
1161 void YACSGui_NodeViewItem::removePortItem( YACS::HMI::Subject* theSPort )
1162 {
1163   if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1164   {
1165     QListViewItem* aChild = firstChild();
1166     while( aChild )
1167     {
1168       if ( YACSGui_PortViewItem* aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1169         if ( aPort->getPort() == aSPort->getPort() )
1170         {
1171           //printf(">> the son is found\n");
1172           takeItem(aChild);
1173           delete aChild;
1174           break;
1175         }
1176       
1177       aChild = aChild->nextSibling();
1178     }
1179   }
1180 }
1181
1182 void YACSGui_NodeViewItem::addNodeItem( YACS::HMI::Subject* theSNode )
1183 {
1184   if ( SubjectNode* aSNode = dynamic_cast<SubjectNode*>(theSNode) )
1185   {
1186     YACSGui_NodeViewItem* aNodeItem = new YACSGui_NodeViewItem( this, 0, aSNode );
1187
1188     if ( SubjectComposedNode* aSCompNode = dynamic_cast<SubjectComposedNode*>(aSNode) )
1189       YACSGui_LabelViewItem* aLinksItem = new YACSGui_LabelViewItem( aNodeItem, 0, QObject::tr( "LINKS" ) );
1190   }
1191 }
1192
1193 void YACSGui_NodeViewItem::moveUpPortItem( YACS::HMI::Subject* theSPort )
1194 {
1195   if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1196   {
1197     QListViewItem* aChild = firstChild();
1198     while( aChild )
1199     {
1200       if ( YACSGui_PortViewItem* aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild->nextSibling()) )
1201         if ( aPort->getPort() == aSPort->getPort() )
1202           break;
1203       
1204       aChild = aChild->nextSibling();
1205     }
1206
1207     // here aChild is an after item for old position of theSPort
1208     YACSGui_PortViewItem* aCPort = dynamic_cast<YACSGui_PortViewItem*>(aChild);
1209     if ( !aCPort ) return;
1210
1211     if ( dynamic_cast<InPort*>(aSPort->getPort()) && dynamic_cast<InPort*>(aCPort->getPort())
1212          ||
1213          dynamic_cast<OutPort*>(aSPort->getPort()) && dynamic_cast<OutPort*>(aCPort->getPort()) )
1214     //if ( dynamic_cast<InPort*>(aSPort->getPort())
1215     //     ||
1216     //     aChild->text(0).compare( QString("Gate") ) )
1217       {
1218         aChild->moveItem(aChild->nextSibling());
1219       }
1220   }
1221 }
1222
1223 void YACSGui_NodeViewItem::moveDownPortItem( YACS::HMI::Subject* theSPort )
1224 {
1225   if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1226   {
1227     QListViewItem* aChild = firstChild();
1228     while( aChild )
1229     {
1230       if ( YACSGui_PortViewItem* aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1231         if ( aPort->getPort() == aSPort->getPort() )
1232         {
1233           //printf(">> the son is found\n");
1234           break;
1235         }
1236       
1237       aChild = aChild->nextSibling();
1238     }
1239
1240     // here aChild is an item corresponding to the old position of theSPort
1241     YACSGui_PortViewItem* aCPort = dynamic_cast<YACSGui_PortViewItem*>(aChild);
1242     if ( !aCPort ) return;
1243
1244     YACSGui_PortViewItem* aCNPort = dynamic_cast<YACSGui_PortViewItem*>(aChild->nextSibling());
1245     if ( !aCNPort ) return;
1246
1247     if ( !dynamic_cast<InPort*>(aCPort->getPort()) || !dynamic_cast<OutPort*>(aCNPort->getPort()) )
1248     //if ( aChild->nextSibling()->text(0).compare( QString("Gate") ) )
1249       aChild->moveItem(aChild->nextSibling());
1250   }
1251 }
1252
1253 bool YACSGui_NodeViewItem::isPublished( YACS::ENGINE::Port* thePort )
1254 {
1255   QListViewItem* aChild = firstChild();
1256   while( aChild )
1257   {
1258     if ( YACSGui_PortViewItem* aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1259       if ( aPort->getPort() == thePort )
1260         return true;
1261     aChild = aChild->nextSibling();
1262   }
1263   return false;
1264 }
1265
1266 void YACSGui_NodeViewItem::addReferenceItem( YACS::HMI::Subject* theSRef )
1267 {
1268   if ( SubjectReference* aSRef = dynamic_cast<SubjectReference*>(theSRef) )
1269   {
1270     // get component subject of the given reference
1271     if ( SubjectComponent* aSComp = dynamic_cast<SubjectComponent*>(aSRef->getReference()) )
1272     {     
1273       // get "Containers" label view item
1274       YACSGui_LabelViewItem* aContainersL = 
1275         dynamic_cast<YACSGui_LabelViewItem*>(listView()->firstChild()->firstChild()->nextSibling()->nextSibling()->nextSibling());
1276       if ( !aContainersL || aContainersL->text(0).compare(QString("Containers")) ) return;
1277   
1278       ComponentInstance* aComp = aSComp->getComponent();
1279       if ( aComp && aComp->getKind() != CORBAComponent::KIND )
1280       {
1281         // get container corresponds to the component
1282         Container* aCont = aComp->getContainer();
1283         if ( aCont )
1284         {
1285           QListViewItem* aContItem = 0;
1286           QListViewItem* aChild = aContainersL->firstChild();
1287           while( aChild )
1288           {
1289             if ( YACSGui_ContainerViewItem* aC = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
1290               if ( aC->getContainer() == aCont )
1291               {
1292                 aContItem = aChild;
1293                 break;
1294               }
1295             aChild = aChild->nextSibling();
1296           }
1297
1298           if ( aContItem )
1299           {
1300             // find component view item corresponds to the aSComp
1301             QListViewItem* aCompItem = 0;
1302             QListViewItem* aChild = aContItem->firstChild();
1303             while( aChild )
1304             {
1305               if ( YACSGui_ComponentViewItem* aC = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
1306                 if ( aC->getComponent() == aComp )
1307                 {
1308                   aCompItem = aChild;
1309                   break;
1310                 }
1311               aChild = aChild->nextSibling();
1312             }
1313             
1314             if ( aCompItem )
1315             {
1316               // add a new reference to the end
1317               QListViewItem* anAfter = 0;
1318               
1319               if ( QListViewItem* aChild = aCompItem->firstChild() )
1320               {
1321                 while( aChild->nextSibling() )
1322                   aChild = aChild->nextSibling();
1323                 anAfter = aChild;
1324               }
1325
1326               new YACSGui_ReferenceViewItem( aCompItem, anAfter, aSRef );
1327             }
1328           }
1329         }
1330       }
1331       else
1332       { // it is a CORBA component
1333         // find component view item corresponds to the aSComp
1334         QListViewItem* aCompItem = 0;
1335         QListViewItem* aChild = aContainersL->firstChild();
1336         while( aChild )
1337         {
1338           if ( YACSGui_ComponentViewItem* aC = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
1339             if ( aC->getComponent() == aComp )
1340             {
1341               aCompItem = aChild;
1342               break;
1343             }
1344           aChild = aChild->nextSibling();
1345         }
1346             
1347         if ( aCompItem )
1348         {
1349           // add a new reference to the end
1350           QListViewItem* anAfter = 0;
1351           
1352           if ( QListViewItem* aChild = aCompItem->firstChild() )
1353           {
1354             while( aChild->nextSibling() )
1355               aChild = aChild->nextSibling();
1356             anAfter = aChild;
1357           }
1358           
1359           new YACSGui_ReferenceViewItem( aCompItem, anAfter, aSRef );
1360         }
1361       }
1362     }
1363   }
1364 }
1365
1366 void YACSGui_NodeViewItem::removeReferenceItem( YACS::HMI::Subject* theSRef )
1367 {
1368   if ( SubjectReference* aSRef = dynamic_cast<SubjectReference*>(theSRef) )
1369   {
1370     // get component subject of the given reference
1371     if ( SubjectComponent* aSComp = dynamic_cast<SubjectComponent*>(aSRef->getReference()) )
1372     {     
1373       // get "Containers" label view item
1374       YACSGui_LabelViewItem* aContainersL = 
1375         dynamic_cast<YACSGui_LabelViewItem*>(listView()->firstChild()->firstChild()->nextSibling()->nextSibling()->nextSibling());
1376       if ( !aContainersL || aContainersL->text(0).compare(QString("Containers")) ) return;
1377   
1378       ComponentInstance* aComp = aSComp->getComponent();
1379       if ( aComp && aComp->getKind() != CORBAComponent::KIND )
1380       {
1381         // get container corresponds to the component
1382         Container* aCont = aComp->getContainer();
1383         if ( aCont )
1384         {
1385           QListViewItem* aContItem = 0;
1386           QListViewItem* aChild = aContainersL->firstChild();
1387           while( aChild )
1388           {
1389             if ( YACSGui_ContainerViewItem* aC = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
1390               if ( aC->getContainer() == aCont )
1391               {
1392                 aContItem = aChild;
1393                 break;
1394               }
1395             aChild = aChild->nextSibling();
1396           }
1397
1398           if ( aContItem )
1399           {
1400             // find component view item corresponds to the aSComp
1401             QListViewItem* aCompItem = 0;
1402             QListViewItem* aChild = aContItem->firstChild();
1403             while( aChild )
1404             {
1405               if ( YACSGui_ComponentViewItem* aC = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
1406                 if ( aC->getComponent() == aComp )
1407                 {
1408                   aCompItem = aChild;
1409                   break;
1410                 }
1411               aChild = aChild->nextSibling();
1412             }
1413             
1414             if ( aCompItem )
1415             {
1416               // delete a given reference
1417               if ( QListViewItem* aChild = aCompItem->firstChild() )
1418               {
1419                 while( aChild )
1420                 {
1421                   if ( YACSGui_ReferenceViewItem* aRefItem = dynamic_cast<YACSGui_ReferenceViewItem*>(aChild) )
1422                     if ( aRefItem->getSReference() == aSRef )
1423                     {
1424                       aCompItem->takeItem(aChild);
1425                       delete aChild;
1426                       break;
1427                     }
1428                   aChild = aChild->nextSibling();
1429                 }
1430               }
1431             }
1432           }
1433         }
1434       }
1435       else
1436       { // it is a CORBA component
1437         // find component view item corresponds to the aSComp
1438         QListViewItem* aCompItem = 0;
1439         QListViewItem* aChild = aContainersL->firstChild();
1440         while( aChild )
1441         {
1442           if ( YACSGui_ComponentViewItem* aC = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
1443             if ( aC->getComponent() == aComp )
1444             {
1445               aCompItem = aChild;
1446               break;
1447             }
1448           aChild = aChild->nextSibling();
1449         }
1450             
1451         if ( aCompItem )
1452         {
1453           // delete a given reference
1454           if ( QListViewItem* aChild = aCompItem->firstChild() )
1455           {
1456             while( aChild )
1457             {
1458               if ( YACSGui_ReferenceViewItem* aRefItem = dynamic_cast<YACSGui_ReferenceViewItem*>(aChild) )
1459                 if ( aRefItem->getSReference() == aSRef )
1460                 {
1461                   aCompItem->takeItem(aChild);
1462                   delete aChild;
1463                   break;
1464                 }
1465               aChild = aChild->nextSibling();
1466             }
1467           }
1468         }
1469       }
1470     }
1471   }
1472 }
1473
1474 void YACSGui_NodeViewItem::addLinkItem( YACS::HMI::Subject* theSLink )
1475 {
1476   DEBTRACE("YACSGui_NodeViewItem::addLinkItem");
1477   SubjectLink* aSLink = dynamic_cast<SubjectLink*>(theSLink);
1478   SubjectControlLink* aSCLink = dynamic_cast<SubjectControlLink*>(theSLink);
1479   if ( aSLink || aSCLink )
1480   {
1481     // get the "Links" label view item under this node view item
1482     YACSGui_LabelViewItem* aLinksL = 0;
1483     QListViewItem* aChildLinks = firstChild();
1484     while( aChildLinks )
1485     {
1486       aLinksL = dynamic_cast<YACSGui_LabelViewItem*>(aChildLinks);
1487       if ( aLinksL && aLinksL->text(0).compare(QString("Links")) == 0 )
1488         break;
1489       aChildLinks = aChildLinks->nextSibling();
1490     }
1491
1492     if ( !aLinksL )
1493       return;
1494
1495     // find the last link item published under in the Links folder
1496     QListViewItem* anAfter = 0;
1497     if ( QListViewItem* aChild = aLinksL->firstChild() )
1498     {
1499       while( aChild->nextSibling() )
1500         aChild = aChild->nextSibling();
1501       anAfter = aChild;
1502     }
1503
1504     if ( aSLink ) new YACSGui_LinkViewItem( aLinksL, anAfter, aSLink );
1505     else if ( aSCLink ) new YACSGui_ControlLinkViewItem( aLinksL, anAfter, aSCLink );
1506   }
1507 }
1508
1509 // YACSGui_LinkViewItem class:
1510
1511 YACSGui_LinkViewItem::YACSGui_LinkViewItem( QListView* theParent, 
1512                                             QListViewItem* theAfter,
1513                                             YACS::HMI::SubjectLink* theSLink ):
1514   YACSGui_ViewItem( theParent, theAfter ),
1515   mySLink( theSLink )
1516 {
1517   if ( mySLink )
1518   {
1519     mySLink->attach(this);
1520     
1521     QString aName = name();
1522     if ( !aName.isEmpty() )
1523       setText( 0, aName );
1524     setPixmap( 0, icon() );
1525   }
1526 }
1527
1528 YACSGui_LinkViewItem::YACSGui_LinkViewItem( QListViewItem* theParent, 
1529                                             QListViewItem* theAfter,
1530                                             YACS::HMI::SubjectLink* theSLink ):
1531   YACSGui_ViewItem( theParent, theAfter ),
1532   mySLink( theSLink )
1533 {
1534   if ( mySLink )
1535   {
1536     mySLink->attach(this);
1537     
1538     QString aName = name();
1539     if ( !aName.isEmpty() )
1540       setText( 0, aName );
1541     setPixmap( 0, icon() );
1542   }
1543 }
1544
1545 YACSGui_LinkViewItem::~YACSGui_LinkViewItem()
1546 {
1547   if ( mySLink ) mySLink->detach(this);
1548 }
1549
1550 QString YACSGui_LinkViewItem::name() const
1551 {
1552   QString aName = "";
1553
1554   if ( !mySLink ) return aName;
1555
1556   DataPort* anOutPort = mySLink->getSubjectOutPort()->getPort();
1557   DataPort* anInPort = mySLink->getSubjectInPort()->getPort();
1558   if ( anOutPort && anInPort )
1559   {
1560     Node* anOutPortNode = anOutPort->getNode();
1561     ComposedNode* aRootO = 0;
1562     if ( dynamic_cast<Bloc*>( anOutPortNode->getFather() ) )
1563       aRootO = anOutPortNode->getFather();
1564     else
1565       aRootO = anOutPortNode->getRootNode();
1566
1567     Node* anInPortNode = anInPort->getNode();
1568     ComposedNode* aRootI = 0;
1569     if ( dynamic_cast<Bloc*>( anInPortNode->getFather() ) )
1570       aRootI = anInPortNode->getFather();
1571     else
1572       aRootI = anInPortNode->getRootNode();
1573
1574     ComposedNode* aRoot = 0;
1575     if ( aRootO->isInMyDescendance(aRootI) )
1576       aRoot = aRootO;
1577     else if ( aRootI->isInMyDescendance(aRootO) )
1578       aRoot = aRootI;
1579     else
1580     {
1581       Bloc* aBlocOut = 0;
1582       Bloc* aBlocIn = 0;
1583       // find the nearest common ancestor for anOutNode and anInNode
1584       Proc* aProc = dynamic_cast<Proc*>(aRootI->getRootNode());
1585       if ( !aProc ) return aName;
1586
1587       aRoot = aProc;
1588       while ( aRootI->getFather() != aProc )
1589       {
1590         if ( aBlocOut = dynamic_cast<Bloc*>(aRootI->getFather()->isInMyDescendance(aRootO)) )
1591         {
1592           aBlocIn = dynamic_cast<Bloc*>(aRootI);
1593           break;
1594         }
1595         aRootI = aRootI->getFather();
1596       }
1597       
1598       if ( aBlocOut && aBlocIn )
1599         aRoot = aBlocOut->getFather();
1600     }
1601
1602     if (aRoot)
1603       aName += QString(aRoot->getChildName(anOutPortNode));
1604     
1605     aName += QString(".%1").arg(anOutPort->getName());
1606     aName += QString(" --> ");
1607             
1608     if (aRoot)
1609       aName += QString(aRoot->getChildName(anInPortNode));
1610     
1611     aName += QString(".%1").arg(anInPort->getName());
1612   }
1613
1614   return aName;
1615 }
1616
1617 QPixmap YACSGui_LinkViewItem::icon() const
1618 {
1619   QPixmap aRes;
1620   
1621   QString anIconName;
1622
1623   if ( !mySLink ) return aRes;
1624
1625   if ( DataPort* anOutPort = mySLink->getSubjectOutPort()->getPort() )
1626   {
1627     if ( dynamic_cast<OutputDataStreamPort*>( anOutPort ) )
1628       anIconName = QString(QObject::tr("ICON_STREAM_LINK_OBJECT"));
1629     else if ( dynamic_cast<OutputPort*>( anOutPort ) )
1630       anIconName = QString(QObject::tr("ICON_DATA_LINK_OBJECT"));
1631
1632     if ( !anIconName.isEmpty() )
1633       aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS",  anIconName, false);
1634   }
1635
1636   return aRes;
1637 }
1638
1639 void YACSGui_LinkViewItem::update( const bool theIsRecursive )
1640 {
1641
1642 }
1643
1644 // YACSGui_ControlLinkViewItem class:
1645
1646 YACSGui_ControlLinkViewItem::YACSGui_ControlLinkViewItem( QListView* theParent, 
1647                                                           QListViewItem* theAfter,
1648                                                           YACS::HMI::SubjectControlLink* theSLink ):
1649   YACSGui_ViewItem( theParent, theAfter ),
1650   mySLink( theSLink )
1651 {
1652   if ( mySLink )
1653   {
1654     mySLink->attach(this);
1655     
1656     QString aName = name();
1657     if ( !aName.isEmpty() )
1658       setText( 0, aName );
1659     setPixmap( 0, icon() );
1660   }
1661 }
1662
1663 YACSGui_ControlLinkViewItem::YACSGui_ControlLinkViewItem( QListViewItem* theParent, 
1664                                                           QListViewItem* theAfter,
1665                                                           YACS::HMI::SubjectControlLink* theSLink ):
1666   YACSGui_ViewItem( theParent, theAfter ),
1667   mySLink( theSLink )
1668 {
1669   if ( mySLink )
1670   {
1671     mySLink->attach(this);
1672     
1673     QString aName = name();
1674     if ( !aName.isEmpty() )
1675       setText( 0, aName );
1676     setPixmap( 0, icon() );
1677   }
1678 }
1679   
1680 YACSGui_ControlLinkViewItem::~YACSGui_ControlLinkViewItem()
1681 {
1682   if ( mySLink ) mySLink->detach(this);
1683 }
1684
1685 QString YACSGui_ControlLinkViewItem::name() const
1686 {
1687   QString aName = "";
1688
1689   if ( !mySLink ) return aName;
1690
1691   Node* anOutPortNode = mySLink->getSubjectOutNode()->getNode();
1692   ComposedNode* aRootO = 0;
1693   if ( dynamic_cast<Bloc*>( anOutPortNode->getFather() ) )
1694     aRootO = anOutPortNode->getFather();
1695   else
1696     aRootO = anOutPortNode->getRootNode();
1697   
1698   Node* anInPortNode = mySLink->getSubjectInNode()->getNode();
1699   ComposedNode* aRootI = 0;
1700   if ( dynamic_cast<Bloc*>( anInPortNode->getFather() ) )
1701     aRootI = anInPortNode->getFather();
1702   else
1703     aRootI = anInPortNode->getRootNode();
1704
1705   ComposedNode* aRoot = 0;
1706   if ( aRootO->isInMyDescendance(aRootI) )
1707     aRoot = aRootO;
1708   else if ( aRootI->isInMyDescendance(aRootO) )
1709     aRoot = aRootI;
1710   else
1711   {
1712     Bloc* aBlocOut = 0;
1713     Bloc* aBlocIn = 0;
1714     // find the nearest common ancestor for anOutNode and anInNode
1715     Proc* aProc = dynamic_cast<Proc*>(aRootI->getRootNode());
1716     if ( !aProc ) return aName;
1717     
1718     while ( aRootI->getFather() != aProc )
1719     {
1720       if ( aBlocOut = dynamic_cast<Bloc*>(aRootI->getFather()->isInMyDescendance(aRootO)) )
1721       {
1722         aBlocIn = dynamic_cast<Bloc*>(aRootI);
1723         break;
1724       }
1725       aRootI = aRootI->getFather();
1726     }
1727     
1728     if ( aBlocOut && aBlocIn )
1729       aRoot = aBlocOut->getFather();
1730   }
1731   
1732   if (aRoot)
1733     aName += QString(aRoot->getChildName(anOutPortNode));
1734
1735   aName += QString(" --> ");
1736     
1737   if (aRoot)
1738     aName += QString(aRoot->getChildName(anInPortNode));
1739     
1740   return aName;
1741 }
1742
1743 QPixmap YACSGui_ControlLinkViewItem::icon() const
1744 {
1745   QPixmap aRes;
1746   
1747   QString anIconName;
1748
1749   anIconName = QString(QObject::tr("ICON_CONTROL_LINK_OBJECT"));
1750   if ( !anIconName.isEmpty() )
1751     aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS",  anIconName, false);
1752   
1753   return aRes;
1754 }
1755
1756 void YACSGui_ControlLinkViewItem::update( const bool theIsRecursive )
1757 {
1758
1759 }
1760
1761 // YACSGui_SchemaViewItem class:
1762
1763 YACSGui_SchemaViewItem::YACSGui_SchemaViewItem( QListView* theParent, 
1764                                                 QListViewItem* theAfter, 
1765                                                 YACS::HMI::SubjectProc* theSProc ):
1766   YACSGui_ViewItem( theParent, theAfter ),
1767   mySProc( theSProc )
1768 {
1769   if ( mySProc ) mySProc->attach(this);
1770
1771   if ( getProc() )
1772     setText( 0, QString( getProc()->getName() ) );
1773   setPixmap( 0, icon() );
1774 }
1775
1776 YACSGui_SchemaViewItem::YACSGui_SchemaViewItem( QListViewItem* theParent,
1777                                                 QListViewItem* theAfter,
1778                                                 YACS::HMI::SubjectProc* theSProc ):
1779   YACSGui_ViewItem( theParent, theAfter ),
1780   mySProc( theSProc )
1781 {
1782   if ( mySProc ) mySProc->attach(this);
1783   
1784   if ( getProc() )
1785     setText( 0, QString( getProc()->getName() ) );
1786   setPixmap( 0, icon() );
1787 }
1788
1789 YACSGui_SchemaViewItem::~YACSGui_SchemaViewItem()
1790 {
1791   if ( mySProc ) mySProc->detach(this);
1792 }
1793
1794 YACSGui_LabelViewItem* YACSGui_SchemaViewItem::buildDataTypesTree()
1795 {
1796   GuiContext* aContext = GuiContext::getCurrent();
1797   if ( !aContext )
1798     return 0;
1799
1800   YACS::ENGINE::Proc* aProc = aContext->getProc();
1801   if ( !aProc )
1802     return 0;
1803
1804   // Create "Data Types" label
1805
1806   YACSGui_LabelViewItem* aDataTypesItem = 
1807     new YACSGui_LabelViewItem( this, 0, QObject::tr( "DT_DATA_TYPES" ) );
1808
1809   // Create "Simple" label
1810   YACSGui_LabelViewItem* aSimpleItem = new YACSGui_LabelViewItem( aDataTypesItem, 0, QObject::tr( "DT_SIMPLE" ) );
1811   myRootDataTypeItems[ YACS::ENGINE::Double ] = aSimpleItem;
1812   myRootDataTypeItems[ YACS::ENGINE::Int ] = aSimpleItem;
1813   myRootDataTypeItems[ YACS::ENGINE::String ] = aSimpleItem;
1814   myRootDataTypeItems[ YACS::ENGINE::Bool ] = aSimpleItem;
1815
1816   // Create "Objref" label
1817   myRootDataTypeItems[ YACS::ENGINE::Objref ] = 
1818     new YACSGui_LabelViewItem( aDataTypesItem, aSimpleItem, QObject::tr( "DT_OBJREF" ) );
1819
1820   // Create "Sequence" label
1821   myRootDataTypeItems[ YACS::ENGINE::Sequence ] = new YACSGui_LabelViewItem( 
1822     aDataTypesItem, myRootDataTypeItems[ YACS::ENGINE::Objref ], QObject::tr( "DT_SEQUENCE" ) );
1823
1824   // Create "Array" label
1825   myRootDataTypeItems[ YACS::ENGINE::Array ] = new YACSGui_LabelViewItem( 
1826     aDataTypesItem, myRootDataTypeItems[ YACS::ENGINE::Sequence ], QObject::tr( "DT_ARRAY" ) );
1827
1828   // Create "Struct" label
1829   myRootDataTypeItems[ YACS::ENGINE::Struct ] = new YACSGui_LabelViewItem( 
1830     aDataTypesItem, myRootDataTypeItems[ YACS::ENGINE::Array ], QObject::tr( "DT_STRUCT" ) );
1831
1832   // Iterate through DataTypes and build tree
1833
1834   std::map<std::string, YACS::HMI::SubjectDataType*>::iterator it;
1835   for ( it = aContext->_mapOfSubjectDataType.begin(); 
1836         it != aContext->_mapOfSubjectDataType.end(); ++it )
1837   {
1838     std::string aName = (*it).first;
1839     YACS::HMI::SubjectDataType* aSub = (*it).second;
1840     if ( !aSub )
1841       continue;
1842     
1843     addDataTypeItem( aSub );
1844   }
1845
1846   return aDataTypesItem;
1847 }
1848
1849 void YACSGui_SchemaViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
1850 {
1851   DEBTRACE(">> YACSGui_SchemaViewItem::update");
1852   switch (event)
1853   {
1854   case RENAME:
1855     update();
1856   case EDIT:
1857     update(true, son);
1858     break;
1859   case ADD:
1860     switch (type)
1861     {
1862     case BLOC:
1863     case FOREACHLOOP:
1864     case OPTIMIZERLOOP:
1865     case FORLOOP:
1866     case WHILELOOP:
1867     case SWITCH:
1868     case PYTHONNODE:
1869     case PYFUNCNODE:
1870     case CORBANODE:
1871     case SALOMENODE:
1872     case CPPNODE:
1873     case SALOMEPYTHONNODE:
1874     case PRESETNODE:
1875     case OUTNODE:
1876     case STUDYINNODE:
1877     case STUDYOUTNODE:
1878     case XMLNODE:
1879       {
1880         // add a node item (this = schema item)
1881         DEBTRACE("SchemaViewItem:  ADD node");
1882         addNodeItem(son);
1883       }
1884       break;
1885     case CONTAINER:
1886       {
1887         // add a container item (this = schema item)
1888         DEBTRACE("SchemaViewItem:  ADD container");
1889         addContainerItem(son);
1890       }
1891       break;
1892     case DATATYPE:
1893       {
1894         DEBTRACE("SchemaViewItem:  ADD data type");
1895         addDataTypeItem( son );
1896       }
1897       break;
1898     default:
1899       break;
1900     }
1901     break;
1902   case REMOVE:
1903     switch (type)
1904     {
1905     case CONTAINER:
1906       {
1907         // remove a container item (this = schema item)
1908         DEBTRACE("SchemaViewItem:  REMOVE container");
1909         removeContainerItem(son);
1910       }
1911       break;
1912     case COMPONENT:
1913       {
1914         // remove a CORBA component item (this = schema item)
1915         DEBTRACE("SchemaViewItem:  REMOVE component");
1916         removeComponentItem(son);
1917       }
1918       break;
1919     case DATATYPE:
1920       {
1921         // remove a CORBA component item (this = schema item)
1922         DEBTRACE("SchemaViewItem:  REMOVE Data type");
1923         removeDataTypeItem( son );
1924       }
1925       break;
1926     case DATALINK:
1927     case CONTROLLINK:
1928       {
1929         // remove a link item (this = schema item)
1930         DEBTRACE("SchemaViewItem:  REMOVE link");
1931         removeLinkItem(son);
1932       }
1933       break;
1934     case BLOC:
1935     case FOREACHLOOP:
1936     case OPTIMIZERLOOP:
1937     case FORLOOP:
1938     case WHILELOOP:
1939     case SWITCH:
1940     case PYTHONNODE:
1941     case PYFUNCNODE:
1942     case CORBANODE:
1943     case SALOMENODE:
1944     case CPPNODE:
1945     case SALOMEPYTHONNODE:
1946     case PRESETNODE:
1947     case OUTNODE:
1948     case STUDYINNODE:
1949     case STUDYOUTNODE:
1950     case XMLNODE:
1951       {
1952         DEBTRACE("SchemaViewItem:  REMOVE");
1953         removeNodeItem(son);
1954       }
1955     default:
1956       break;
1957     }
1958     break;
1959   case ADDLINK:
1960   case ADDCONTROLLINK:
1961     {
1962       // add link item (this = schema item)
1963       DEBTRACE("SchemaViewItem:  ADDLINK");
1964       addLinkItem(son);
1965     }
1966     break;
1967   default:
1968     GuiObserver::update(event, type, son);
1969   }
1970 }
1971
1972 QPixmap YACSGui_SchemaViewItem::icon() const
1973 {
1974   QPixmap aRes;
1975
1976   QString anIconName = QString(QObject::tr("ICON_SCHEMA_OBJECT"));
1977   if ( !anIconName.isEmpty() )
1978     aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
1979   
1980   return aRes;
1981 }
1982
1983 YACS::ENGINE::Proc* YACSGui_SchemaViewItem::getProc() const
1984 {
1985   return ( mySProc ? dynamic_cast<Proc*>(mySProc->getNode()) : 0 );
1986 }
1987
1988 void YACSGui_SchemaViewItem::update( const bool theIsRecursive,
1989                                      YACS::HMI::Subject* theSon,
1990                                      YACSGui_NodeViewItem* theBlocItem )
1991 {
1992   if ( theIsRecursive ) // total update
1993   {
1994     if ( SubjectNode* aNodeSon = dynamic_cast<SubjectNode*>(theSon) ) // theSon is a node
1995     {
1996       // get the "Nodes" label view item, which is used as a parent for first level nodes
1997       YACSGui_LabelViewItem* aNodesL = dynamic_cast<YACSGui_LabelViewItem*>(firstChild()->nextSibling());
1998       if ( !aNodesL || aNodesL->text(0).compare(QString("Nodes")) ) return;
1999
2000       // find list view item before theSon
2001       YACSGui_NodeViewItem* anAfter = 0;
2002       YACSGui_NodeViewItem* anUpdated = 0;
2003       QListViewItem* aChild = aNodesL->firstChild();
2004
2005       if ( YACSGui_NodeViewItem* aFirst = dynamic_cast<YACSGui_NodeViewItem*>(aChild) )
2006         if ( aFirst->getSNode() == aNodeSon )
2007           anUpdated = aFirst;
2008         else
2009         {
2010           while( aChild )
2011           {
2012             if ( YACSGui_NodeViewItem* aNext = dynamic_cast<YACSGui_NodeViewItem*>(aChild->nextSibling()) )
2013               if ( aNext->getSNode() == aNodeSon )
2014               {
2015                 anAfter = dynamic_cast<YACSGui_NodeViewItem*>(aChild);
2016                 anUpdated = aNext;
2017                 break;
2018               }
2019             aChild = aChild->nextSibling();
2020           }
2021         }
2022       
2023       if ( anUpdated )
2024       {
2025         if ( YACSGui_EditionTreeView* anETV = dynamic_cast<YACSGui_EditionTreeView*>(listView()) )
2026         {
2027           bool anIsOpen = anUpdated->isOpen();
2028
2029           // remove list view item for theSon from the tree
2030           aNodesL->takeItem(anUpdated);
2031           delete anUpdated;
2032           
2033           // recreate list view item for theSon
2034           if ( anUpdated = anETV->displayNodeWithPorts( aNodesL, anAfter, aNodeSon ) )
2035             anUpdated->setOpen(anIsOpen);
2036         }
2037       }
2038     }
2039     else if ( !theSon && theBlocItem ) // theSon is null => remove any nodes under theBlocItem
2040                                        //                   and add these nodes under "Nodes" label
2041     {
2042       Bloc* aBloc = dynamic_cast<Bloc*>( theBlocItem->getNode() );
2043       if ( !aBloc ) return;
2044
2045       // get the "Nodes" label view item, which is used as a parent for first level nodes
2046       YACSGui_LabelViewItem* aNodesL = dynamic_cast<YACSGui_LabelViewItem*>(firstChild()->nextSibling());
2047       if ( !aNodesL || aNodesL->text(0).compare(QString("Nodes")) ) return;
2048
2049       QListViewItem* aChild = theBlocItem->firstChild();
2050       while( aChild )
2051       {
2052         if ( YACSGui_NodeViewItem* aChildNodeItem = dynamic_cast<YACSGui_NodeViewItem*>(aChild) )
2053           if ( !aBloc->isInMyDescendance( aChildNodeItem->getNode() ) )
2054           {
2055             //printf(">> Delete and insert : %s\n",aChildNodeItem->getNode()->getName().c_str());
2056             QListViewItem* anAuxItem = aChild->nextSibling();
2057
2058             // remove view item from theBlocItem 
2059             takeItem(aChild);
2060             aNodesL->insertItem(aChild);
2061                     
2062             aChild = anAuxItem;
2063             continue;
2064           }
2065         
2066         aChild = aChild->nextSibling();
2067       }
2068     }
2069   }
2070   else if ( mySProc ) // only rename
2071     setText( 0, QString( mySProc->getName() ) );
2072 }
2073
2074 /*!
2075   \brief Add data type item in tree view
2076 */
2077 void YACSGui_SchemaViewItem::addDataTypeItem( YACS::HMI::Subject* theSDataType )
2078 {
2079   YACS::HMI::SubjectDataType* aSub = 
2080     dynamic_cast<YACS::HMI::SubjectDataType*>( theSDataType );
2081
2082   if ( !aSub )
2083     return;
2084   
2085   GuiContext* aContext = GuiContext::getCurrent();
2086   if ( !aContext )
2087     return;
2088
2089   YACS::ENGINE::Proc* aProc = aContext->getProc();
2090   if ( !aProc )
2091     return;
2092
2093   std::string aName = aSub->getName();
2094
2095   if ( aProc->typeMap.find( aName ) == aProc->typeMap.end() )
2096     return;
2097
2098   YACS::ENGINE::TypeCode* aTypeCode = aProc->typeMap[ aName ];
2099   if ( !aTypeCode )
2100     return;
2101
2102   DynType aDynType = aTypeCode->kind();
2103
2104   // Create types item if necessary
2105   if ( myRootDataTypeItems.find( aDynType ) == myRootDataTypeItems.end() )
2106     return;
2107   
2108   QListViewItem* aFatherItem = myRootDataTypeItems[ aDynType ];
2109
2110   // Create new item under aFatherItem
2111   new YACSGui_DataTypeItem( aFatherItem, 0, aSub );
2112 }
2113
2114
2115 void YACSGui_SchemaViewItem::addNodeItem( YACS::HMI::Subject* theSNode )
2116 {
2117   if ( SubjectNode* aSNode = dynamic_cast<SubjectNode*>(theSNode) )
2118   {
2119     // get the "Nodes" label view item, which is used as a parent for first level nodes
2120     YACSGui_LabelViewItem* aNodesL = dynamic_cast<YACSGui_LabelViewItem*>(firstChild()->nextSibling());
2121     if ( !aNodesL || aNodesL->text(0).compare(QString("Nodes")) ) return;
2122
2123     QListViewItem* anAfter = 0;
2124
2125     if ( QListViewItem* aChild = aNodesL->firstChild() )
2126     {
2127       while( aChild->nextSibling() )
2128         aChild = aChild->nextSibling();
2129       anAfter = aChild;
2130     }
2131
2132     YACSGui_NodeViewItem* aNodeItem = new YACSGui_NodeViewItem( aNodesL, anAfter, aSNode );
2133
2134     if ( SubjectComposedNode* aSCompNode = dynamic_cast<SubjectComposedNode*>(aSNode) )
2135       YACSGui_LabelViewItem* aLinksItem = new YACSGui_LabelViewItem( aNodeItem, 0, QObject::tr( "LINKS" ) );
2136   }
2137 }
2138
2139 void YACSGui_SchemaViewItem::addContainerItem( YACS::HMI::Subject* theSContainer )
2140 {
2141   if ( SubjectContainer* aSContainer = dynamic_cast<SubjectContainer*>(theSContainer) )
2142   {
2143     // get the "Containers" label view item
2144     YACSGui_LabelViewItem* aContainersL = dynamic_cast<YACSGui_LabelViewItem*>(firstChild()->nextSibling()->nextSibling()->nextSibling());
2145     if ( !aContainersL || aContainersL->text(0).compare(QString("Containers")) ) return;
2146
2147     QListViewItem* anAfter = 0;
2148
2149     if ( QListViewItem* aChild = aContainersL->firstChild() )
2150     {
2151       while( aChild->nextSibling() )
2152         aChild = aChild->nextSibling();
2153       anAfter = aChild;
2154     }
2155
2156     new YACSGui_ContainerViewItem( aContainersL, anAfter, aSContainer );
2157   }
2158 }
2159
2160 void YACSGui_SchemaViewItem::removeContainerItem( YACS::HMI::Subject* theSContainer )
2161 {
2162   if ( SubjectContainer* aSContainer = dynamic_cast<SubjectContainer*>(theSContainer) )
2163   {
2164     // get the "Containers" label view item
2165     YACSGui_LabelViewItem* aContainersL = dynamic_cast<YACSGui_LabelViewItem*>(firstChild()->nextSibling()->nextSibling()->nextSibling());
2166     if ( !aContainersL || aContainersL->text(0).compare(QString("Containers")) ) return;
2167
2168     QListViewItem* aChild = aContainersL->firstChild();
2169     while( aChild )
2170     {
2171       if ( YACSGui_ContainerViewItem* aCont = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
2172         if ( aCont->getSContainer() == aSContainer )
2173         {
2174           aContainersL->takeItem(aChild);
2175           delete aChild;
2176           break;
2177         }
2178       aChild = aChild->nextSibling();
2179     }
2180   }
2181 }
2182
2183 void YACSGui_SchemaViewItem::removeDataTypeItem( YACS::HMI::Subject* theSDataType )
2184 {
2185   YACS::HMI::SubjectDataType* aSub = 
2186     dynamic_cast<YACS::HMI::SubjectDataType*>( theSDataType );
2187
2188   if ( !aSub )
2189     return;
2190   
2191   GuiContext* aContext = GuiContext::getCurrent();
2192   if ( !aContext )
2193     return;
2194
2195   YACS::ENGINE::Proc* aProc = aContext->getProc();
2196   if ( !aProc )
2197     return;
2198
2199   std::string aName = aSub->getName();
2200
2201   if ( aProc->typeMap.find( aName ) == aProc->typeMap.end() )
2202     return;
2203
2204   YACS::ENGINE::TypeCode* aTypeCode = aProc->typeMap[ aName ];
2205   if ( !aTypeCode )
2206     return;
2207
2208   DynType aDynType = aTypeCode->kind();
2209   if ( myRootDataTypeItems.find( aDynType ) == myRootDataTypeItems.end() )
2210     return;
2211
2212   // find item corresponding to aSub
2213
2214   QListViewItem* aFatherItem = myRootDataTypeItems[ aDynType ];
2215
2216   QListViewItemIterator it( aFatherItem );\r
2217   QListViewItem* toRemoveItem = 0;\r
2218   while ( it.current() ) \r
2219   {\r
2220     YACSGui_DataTypeItem* currItem = dynamic_cast<YACSGui_DataTypeItem*>( it.current() );\r
2221     if ( currItem && currItem->getSDataType() == aSub )\r
2222     {\r
2223       toRemoveItem = currItem;\r
2224       break;\r
2225     }\r
2226     ++it;\r
2227   }
2228
2229   if ( !toRemoveItem )
2230     return;
2231
2232   // remove item
2233   
2234   aFatherItem->takeItem( toRemoveItem );
2235   delete toRemoveItem;
2236 }
2237
2238 void YACSGui_SchemaViewItem::removeComponentItem( YACS::HMI::Subject* theSComponent )
2239 {
2240   // ! for CORBA components only
2241   if ( SubjectComponent* aSComponent = dynamic_cast<SubjectComponent*>(theSComponent) )
2242   {
2243     CORBAComponent* aCComp = dynamic_cast<CORBAComponent*>(aSComponent->getComponent());
2244     if ( !aCComp ) return;
2245
2246     // get the "Containers" label view item
2247     YACSGui_LabelViewItem* aContainersL = dynamic_cast<YACSGui_LabelViewItem*>(firstChild()->nextSibling()->nextSibling()->nextSibling());
2248     if ( !aContainersL || aContainersL->text(0).compare(QString("Containers")) ) return;
2249
2250     QListViewItem* aChild = aContainersL->firstChild();
2251     while( aChild )
2252     {
2253       if ( YACSGui_ComponentViewItem* aCont = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
2254         if ( aCont->getSComponent() == aSComponent )
2255         {
2256           aContainersL->takeItem(aChild);
2257           delete aChild;
2258           break;
2259         }
2260       aChild = aChild->nextSibling();
2261     }
2262   }
2263 }
2264
2265 void YACSGui_SchemaViewItem::addLinkItem( YACS::HMI::Subject* theSLink )
2266 {
2267   DEBTRACE("YACSGui_SchemaViewItem::addLinkItem");
2268   SubjectLink* aSLink = dynamic_cast<SubjectLink*>(theSLink);
2269   SubjectControlLink* aSCLink = dynamic_cast<SubjectControlLink*>(theSLink);
2270   if ( aSLink || aSCLink )
2271   {
2272     // get the "Links" label view item under the schema (root) view item
2273     YACSGui_LabelViewItem* aLinksL = dynamic_cast<YACSGui_LabelViewItem*>(firstChild()->nextSibling()->nextSibling());
2274     if ( !aLinksL || aLinksL->text(0).compare(QString("Links")) ) return;
2275
2276     QListViewItem* anAfter = 0;
2277
2278     if ( QListViewItem* aChild = aLinksL->firstChild() )
2279     {
2280       while( aChild->nextSibling() )
2281         aChild = aChild->nextSibling();
2282       anAfter = aChild;
2283     }
2284
2285     if ( aSLink ) new YACSGui_LinkViewItem( aLinksL, anAfter, aSLink );
2286     else if ( aSCLink ) new YACSGui_ControlLinkViewItem( aLinksL, anAfter, aSCLink );
2287   }
2288 }
2289
2290 // YACSGui_ContainerViewItem class:
2291
2292 YACSGui_ContainerViewItem::YACSGui_ContainerViewItem(  QListView* theParent, 
2293                                                        QListViewItem* theAfter,
2294                                                        YACS::HMI::SubjectContainer* theSContainer ):
2295   YACSGui_ViewItem( theParent, theAfter ),
2296   mySContainer( theSContainer )
2297 {
2298   if ( mySContainer )
2299   {
2300     mySContainer->attach(this);
2301
2302     QString aName = name();
2303     if ( !aName.isEmpty() )
2304       setText( 0, aName );
2305     setPixmap( 0, icon() );
2306   }
2307 }
2308
2309 YACSGui_ContainerViewItem::YACSGui_ContainerViewItem(  QListViewItem* theParent, 
2310                                                        QListViewItem* theAfter,
2311                                                        YACS::HMI::SubjectContainer* theSContainer ):
2312   YACSGui_ViewItem( theParent, theAfter ),
2313   mySContainer( theSContainer )
2314 {
2315   if ( mySContainer )
2316   {
2317     mySContainer->attach(this);
2318
2319     QString aName = name();
2320     if ( !aName.isEmpty() )
2321       setText( 0, aName );
2322     setPixmap( 0, icon() );
2323   }
2324 }
2325
2326 YACSGui_ContainerViewItem::~YACSGui_ContainerViewItem()
2327 {
2328   if ( mySContainer ) mySContainer->detach(this);
2329 }
2330
2331 void YACSGui_ContainerViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
2332 {
2333   //printf(">> YACSGui_ContainerViewItem::update\n");
2334   DEBTRACE(">> YACSGui_ContainerViewItem::update");
2335   switch (event)
2336   {
2337   case RENAME:
2338     update();
2339     break;
2340   case ADD:
2341     switch (type)
2342     {
2343     case COMPONENT:
2344       {
2345         // add a component item (this = container item)
2346         //printf("ContainerViewItem:  ADD component\n");
2347         addComponentItem(son);
2348       }
2349       break;
2350     default:
2351       break;
2352     }
2353     break;
2354   case REMOVE:
2355     switch (type)
2356     {
2357     case COMPONENT:
2358       {
2359         // remove a component item (this = container item)
2360         //printf("ContainerViewItem:  REMOVE component\n");
2361         removeComponentItem(son);
2362       }
2363       break;
2364     default:
2365       break;
2366     }
2367     break;
2368   default:
2369     GuiObserver::update(event, type, son);
2370   }
2371 }
2372
2373 QString YACSGui_ContainerViewItem::name() const
2374 {
2375   return ( mySContainer ? QString(mySContainer->getName()) : QString("") );
2376 }
2377
2378 QPixmap YACSGui_ContainerViewItem::icon() const
2379 {
2380   QPixmap aRes;
2381   
2382   if ( getContainer() )
2383     aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS",  QObject::tr("ICON_CONTAINER_OBJECT"));
2384
2385   return aRes;
2386 }
2387
2388 YACS::ENGINE::Container* YACSGui_ContainerViewItem::getContainer() const
2389 {
2390   return ( mySContainer ? mySContainer->getContainer() : 0 );
2391 }
2392
2393 void YACSGui_ContainerViewItem::update( YACSGui_ComponentViewItem* theComponent )
2394 {
2395   if ( theComponent )
2396   {
2397     takeItem(theComponent);
2398     
2399     // get the "Containers" label view item
2400     YACSGui_LabelViewItem* aContsL = 
2401       dynamic_cast<YACSGui_LabelViewItem*>(listView()->firstChild()->firstChild()->nextSibling()->nextSibling()->nextSibling());
2402     if ( !aContsL || aContsL->text(0).compare(QString("Containers")) ) return;
2403
2404     // find new container view item, under which theComponent view item should be moved
2405     YACSGui_ContainerViewItem* aCont = 0;
2406     QListViewItem* aChild = aContsL->firstChild();
2407     while( aChild )
2408     {
2409       if ( YACSGui_ContainerViewItem* aChildContItem = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
2410         if ( aChildContItem->getContainer() == theComponent->getComponent()->getContainer() )
2411         {
2412           aCont = aChildContItem;
2413           break;
2414         }
2415       aChild = aChild->nextSibling();
2416     }
2417
2418     if ( aCont ) aCont->insertItem(theComponent);
2419   }
2420
2421   setText( 0, name() ); // only rename
2422 }
2423
2424 void YACSGui_ContainerViewItem::addComponentItem( YACS::HMI::Subject* theSComponent )
2425 {
2426   if ( SubjectComponent* aSComponent = dynamic_cast<SubjectComponent*>(theSComponent) )
2427   {
2428     QListViewItem* anAfter = 0;
2429
2430     if ( QListViewItem* aChild = firstChild() )
2431     {
2432       while( aChild->nextSibling() )
2433         aChild = aChild->nextSibling();
2434       anAfter = aChild;
2435     }
2436     
2437     new YACSGui_ComponentViewItem( this, anAfter, aSComponent );
2438   }
2439 }
2440
2441 void YACSGui_ContainerViewItem::removeComponentItem( YACS::HMI::Subject* theSComponent )
2442 {
2443   if ( SubjectComponent* aSComponent = dynamic_cast<SubjectComponent*>(theSComponent) )
2444   {
2445     QListViewItem* aChild = firstChild();
2446     while( aChild )
2447     {
2448       if ( YACSGui_ComponentViewItem* aComp = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
2449         if ( aComp->getSComponent() == aSComponent )
2450         {
2451           takeItem(aChild);
2452           delete aChild;
2453           break;
2454         }
2455       
2456       aChild = aChild->nextSibling();
2457     }
2458   }
2459 }
2460
2461 // YACSGui_ComponentViewItem class:
2462
2463 YACSGui_ComponentViewItem::YACSGui_ComponentViewItem( QListView* theParent, 
2464                                                       QListViewItem* theAfter,
2465                                                       YACS::HMI::SubjectComponent* theSComponent ):
2466   YACSGui_ViewItem( theParent, theAfter ),
2467   mySComponent( theSComponent )
2468 {
2469   if ( mySComponent )
2470   {
2471     mySComponent->attach(this);
2472     
2473     QString anInstName = instanceName();
2474     if ( !anInstName.isEmpty() )
2475       setText( 0, anInstName );
2476     setPixmap( 0, icon() );
2477   }
2478 }
2479
2480 YACSGui_ComponentViewItem::YACSGui_ComponentViewItem( QListViewItem* theParent, 
2481                                                       QListViewItem* theAfter,
2482                                                       YACS::HMI::SubjectComponent* theSComponent ):
2483   YACSGui_ViewItem( theParent, theAfter ),
2484   mySComponent( theSComponent )
2485 {
2486   if ( mySComponent )
2487   {
2488     mySComponent->attach(this);
2489
2490     QString anInstName = instanceName();
2491     if ( !anInstName.isEmpty() )
2492       setText( 0, anInstName );
2493     setPixmap( 0, icon() );
2494   }
2495 }
2496
2497 YACSGui_ComponentViewItem::~YACSGui_ComponentViewItem()
2498 {
2499   if ( mySComponent ) mySComponent->detach(this);
2500 }
2501
2502 void YACSGui_ComponentViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
2503 {
2504   //printf(">> YACSGui_ComponentViewItem::update\n");
2505   DEBTRACE(">> YACSGui_ComponentViewItem::update\n");
2506   switch (event)
2507   {
2508   case RENAME:
2509     update();
2510     break;
2511   case EDIT:
2512     switch (type)
2513     {
2514     case REFERENCE:
2515       break;
2516     default:
2517       update(true);
2518       break;
2519     }
2520     break;
2521   default:
2522     GuiObserver::update(event, type, son);
2523   }
2524 }
2525  
2526 QString YACSGui_ComponentViewItem::name() const
2527 {
2528   return instanceName();
2529 }
2530
2531 QString YACSGui_ComponentViewItem::instanceName() const
2532 {
2533   QString instName ="";
2534   if (mySComponent)
2535     instName = mySComponent->getComponent()->getInstanceName();
2536   return instName;
2537 }
2538
2539 QPixmap YACSGui_ComponentViewItem::icon() const
2540 {
2541   QPixmap aRes;
2542
2543   if ( getComponent() )
2544     aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS",  QObject::tr("ICON_COMPONENT_OBJECT"));
2545
2546   return aRes;
2547 }
2548
2549 YACS::ENGINE::ComponentInstance* YACSGui_ComponentViewItem::getComponent() const
2550 {
2551   return ( mySComponent ? mySComponent->getComponent() : 0 );
2552 }
2553
2554 void YACSGui_ComponentViewItem::update( const bool theMove )
2555 {
2556   if ( theMove )
2557   {
2558     // find the container view item under which this component is published now
2559     YACSGui_ContainerViewItem* aCont = 0;
2560     QListViewItem* aParent = parent();
2561     while( aParent )
2562     {
2563       if ( aCont = dynamic_cast<YACSGui_ContainerViewItem*>(aParent) )
2564         break;
2565       aParent = aParent->parent();
2566     }
2567
2568     if ( aCont ) aCont->update(this);
2569   }
2570
2571   setText( 0, name() ); // only rename
2572 }
2573
2574 void YACSGui_ComponentViewItem::move( YACS::HMI::Subject* theSReference )
2575 {
2576   //printf( "YACSGui_ComponentViewItem::move %s\n", theSReference->getName().c_str() );
2577
2578   SubjectServiceNode* aSServiceNode = dynamic_cast<SubjectServiceNode*>( theSReference );
2579
2580   if( aSServiceNode )
2581   {
2582     ServiceNode* aServiceNode = dynamic_cast<ServiceNode*>( aSServiceNode->getNode() );
2583
2584     // get the "Containers" label view item
2585     YACSGui_LabelViewItem* aContsL = 
2586       dynamic_cast<YACSGui_LabelViewItem*>(listView()->firstChild()->firstChild()->nextSibling()->nextSibling()->nextSibling());
2587     if ( !aContsL || aContsL->text(0).compare(QString("Containers")) ) return;
2588
2589     // find new component view item, under which theReference view item should be moved
2590     YACSGui_ReferenceViewItem* aReference = 0;
2591     YACSGui_ComponentViewItem* aComponent = 0;
2592     QListViewItem* aChildContainer = aContsL->firstChild();
2593     while( aChildContainer )
2594     {
2595       //printf( "ContainerViewItem - %s\n", aChildContainer->text(0).latin1() );
2596       if( YACSGui_ContainerViewItem* aChildContItem = dynamic_cast<YACSGui_ContainerViewItem*>(aChildContainer) )
2597       {
2598         QListViewItem* aChildComponent = aChildContItem->firstChild();
2599         while( aChildComponent )
2600         {
2601           //printf( "  ComponentViewItem - %s\n", aChildComponent->text(0).latin1() );
2602           if( YACSGui_ComponentViewItem* aChildCompItem = dynamic_cast<YACSGui_ComponentViewItem*>(aChildComponent) )
2603           {
2604             QListViewItem* aChildReference = aChildCompItem->firstChild();
2605             while( aChildReference )
2606             {
2607               //printf( "    ReferenceViewItem - %s\n", aChildReference->text(0).latin1() );
2608               if( YACSGui_ReferenceViewItem* aChildRefItem = dynamic_cast<YACSGui_ReferenceViewItem*>(aChildReference) )
2609               {
2610                 if( !aReference && aChildRefItem->getNode() == aServiceNode )
2611                   aReference = aChildRefItem;
2612               }
2613               aChildReference = aChildReference->nextSibling();
2614             }
2615
2616             if( !aComponent && aChildCompItem->getComponent() == aServiceNode->getComponent() )
2617               aComponent = aChildCompItem;
2618           }
2619           aChildComponent = aChildComponent->nextSibling();
2620         }
2621       }
2622       aChildContainer = aChildContainer->nextSibling();
2623     }
2624
2625     //printf( "Reference - %s\n", aReference->name().latin1() );
2626     takeItem( aReference );
2627     if( aComponent )
2628       aComponent->insertItem( aReference );
2629   }
2630 }
2631
2632 /* ================ items for tree view in run mode ================ */
2633
2634 // YACSGui_ComposedNodeViewItem class:
2635
2636 YACSGui_ComposedNodeViewItem::YACSGui_ComposedNodeViewItem(QListView *parent,
2637                                                            QString label,
2638                                                            YACS::ENGINE::ComposedNode *node)
2639   : YACSGui_ViewItem(parent, 0),
2640     _node(node)
2641 {
2642   setText( 0, label );
2643
2644   _cf = Qt::black;
2645   setPixmap( 0, icon() );
2646
2647   // attach to HMI 
2648   YACS::HMI::Subject* aSub = getSubject();
2649   if ( aSub )
2650     aSub->attach( this );
2651 }
2652
2653 YACSGui_ComposedNodeViewItem::YACSGui_ComposedNodeViewItem(QListViewItem *parent,
2654                                                            QString label,
2655                                                            YACS::ENGINE::ComposedNode *node)
2656   : YACSGui_ViewItem(parent, 0),
2657     _node(node)
2658 {
2659   setText( 0, label );
2660
2661   _cf = Qt::black;
2662
2663   // attach to HMI 
2664   YACS::HMI::Subject* aSub = getSubject();
2665   if ( aSub )
2666     aSub->attach( this );
2667 }
2668
2669 YACSGui_ComposedNodeViewItem::~YACSGui_ComposedNodeViewItem()
2670 {
2671   // detach from HMI 
2672   YACS::HMI::Subject* aSub = getSubject();
2673   if ( aSub )
2674     aSub->detach( this );
2675 }
2676
2677 YACS::HMI::Subject* YACSGui_ComposedNodeViewItem::getSubject() const
2678 {
2679   YACS::HMI::Subject* aSub = 0;
2680
2681   if ( _node )
2682   {
2683     GuiContext* aContext = GuiContext::getCurrent();
2684     if ( aContext )
2685     {
2686       if ( aContext->_mapOfSubjectNode.find( _node ) != aContext->_mapOfSubjectNode.end() )
2687         aSub = aContext->_mapOfSubjectNode[ _node ];
2688     }
2689   }
2690
2691   return aSub;
2692 }
2693
2694 void YACSGui_ComposedNodeViewItem::paintCell( QPainter *p, const QColorGroup &cg,
2695                                               int column, int w, int alignment )
2696 {
2697   //MESSAGE("ComposedNodeViewItem::paintCell " << column);
2698   QColorGroup _cg( cg );
2699   QColor c = _cg.text();
2700   if (column == 1)
2701   {
2702     _cg.setColor( QColorGroup::Text, _cf );
2703     if ( dynamic_cast<Proc*>(getNode()) )
2704       _cg.setColor( QColorGroup::Background, statusBgColor() );
2705   }
2706
2707   p->fillRect( 0, 0, w, height(), cg.brush( QColorGroup::Base ) );
2708
2709   int W = w;
2710   if ( listView() && !listView()->allColumnsShowFocus() )
2711     W = width( p->fontMetrics(), listView(), column );
2712
2713   QListViewItem::paintCell( p, _cg, column, W<w ? W : w, alignment );
2714
2715   if (column == 1) _cg.setColor( QColorGroup::Text, c );
2716 }
2717
2718 QColor YACSGui_ComposedNodeViewItem::statusBgColor() const
2719 {
2720   QColor wbg;
2721   switch (_state)
2722     {
2723     case YACS::NOTYETINITIALIZED: wbg.setHsv( 45, 50, 255); break;
2724     case YACS::INITIALISED:       wbg.setHsv( 90, 50, 255); break;
2725     case YACS::RUNNING:           wbg.setHsv(135, 50, 255); break;
2726     case YACS::WAITINGTASKS:      wbg.setHsv(180, 50, 255); break;
2727     case YACS::PAUSED:            wbg.setHsv(225, 50, 255); break;
2728     case YACS::FINISHED:          wbg.setHsv(270, 50, 255); break;
2729     case YACS::STOPPED:           wbg.setHsv(315, 50, 255); break;
2730     default:                      wbg.setHsv(360, 50, 255);
2731     }
2732   return wbg;
2733 }
2734
2735 void YACSGui_ComposedNodeViewItem::setState(int state)
2736 {
2737   //MESSAGE("ComposedNodeViewItem::setState: " << state);
2738   _state = state;
2739   switch (_state)
2740     {
2741     case YACS::UNDEFINED:    _cf=Qt::lightGray;       setText(1,"UNDEFINED");    repaint(); break;
2742     case YACS::INVALID:      _cf=Qt::red;             setText(1,"INVALID");      repaint(); break;
2743     case YACS::READY:        _cf=Qt::gray;            setText(1,"READY");        repaint(); break;
2744     case YACS::TOLOAD:       _cf=Qt::darkYellow;      setText(1,"TOLOAD");       repaint(); break;
2745     case YACS::LOADED:       _cf=Qt::darkMagenta;     setText(1,"LOADED");       repaint(); break;
2746     case YACS::TOACTIVATE:   _cf=Qt::darkCyan;        setText(1,"TOACTIVATE");   repaint(); break;
2747     case YACS::ACTIVATED:    _cf=Qt::darkBlue;        setText(1,"ACTIVATED");    repaint(); break;
2748     case YACS::DESACTIVATED: _cf=Qt::gray;            setText(1,"DESACTIVATED"); repaint(); break;
2749     case YACS::DONE:         _cf=Qt::darkGreen;       setText(1,"DONE");         repaint(); break;
2750     case YACS::SUSPENDED:    _cf=Qt::gray;            setText(1,"SUSPENDED");    repaint(); break;
2751     case YACS::LOADFAILED:   _cf.setHsv(320,255,255); setText(1,"LOADFAILED");   repaint(); break;
2752     case YACS::EXECFAILED:   _cf.setHsv( 20,255,255); setText(1,"EXECFAILED");   repaint(); break;
2753     case YACS::PAUSE:        _cf.setHsv(180,255,255); setText(1,"PAUSE");        repaint(); break;
2754     case YACS::INTERNALERR:  _cf.setHsv(340,255,255); setText(1,"INTERNALERR");  repaint(); break;
2755     case YACS::DISABLED:     _cf.setHsv( 40,255,255); setText(1,"DISABLED");     repaint(); break;
2756     case YACS::FAILED:       _cf.setHsv( 20,255,255); setText(1,"FAILED");       repaint(); break;
2757     case YACS::ERROR:        _cf.setHsv(  0,255,255); setText(1,"ERROR");        repaint(); break;
2758     default:                 _cf=Qt::lightGray; repaint();
2759     }
2760 }
2761
2762 void YACSGui_ComposedNodeViewItem::setStatus(int status)
2763 {
2764   if ( dynamic_cast<Proc*>(getNode()) ) // this veiw item is a schema (root) view item
2765   {
2766     QString aStatus("");
2767
2768     _state = status;
2769     switch (_state)
2770     {
2771     case YACS::NOTYETINITIALIZED: aStatus = "Not Yet Initialized"; break;
2772     case YACS::INITIALISED:       aStatus = "Initialized"; break;
2773     case YACS::RUNNING:           aStatus = "Running"; break;
2774     case YACS::WAITINGTASKS:      aStatus = "Waiting Tasks"; break;
2775     case YACS::PAUSED:            aStatus = "Paused"; break;
2776     case YACS::FINISHED:          aStatus = "Finished"; break;
2777     case YACS::STOPPED:           aStatus = "Stopped"; break;
2778     default:                      aStatus = "Status Unknown";
2779     }
2780     setText(1,aStatus);
2781     repaint();
2782   }
2783 }
2784
2785 QPixmap YACSGui_ComposedNodeViewItem::icon() const
2786 {
2787   QPixmap aRes;
2788
2789   QString anIconName = QString(QObject::tr("ICON_SCHEMA_OBJECT"));
2790   if ( !anIconName.isEmpty() )
2791     aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
2792   
2793   return aRes;
2794 }
2795
2796 void YACSGui_ComposedNodeViewItem::update( const bool theIsRecursive )
2797 {
2798   if ( this == listView()->firstChild() )
2799   { // this is a root schema object
2800     if ( YACSGui_RunTreeView* aRTV = dynamic_cast<YACSGui_RunTreeView*>( listView() ) )
2801       setText( 0, QString(aRTV->getProc()->getName()) );
2802   }
2803   else
2804   { // this is a composed node
2805     // update state
2806     // ...
2807   }
2808 }
2809
2810 void YACSGui_ComposedNodeViewItem::popup(YACSGui_Executor* anExecutor,const QPoint & point)
2811 {
2812   QPopupMenu menu(listView());
2813   menu.insertItem("Error Details",0);
2814   menu.insertItem("Error Report",1);
2815   if ( this == listView()->firstChild() )
2816     { //root schema object
2817       menu.insertItem("Schema container log",2);
2818     }
2819   int id=menu.exec(point);
2820   if(id==0)
2821     {
2822       std::string msg = anExecutor->getErrorDetails(getNode());
2823       LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
2824       log->setCaption("Error Details");
2825       log->show();
2826     }
2827   else if(id==1)
2828     {
2829       std::string msg = anExecutor->getErrorReport(getNode());
2830       LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
2831       log->setCaption("Error Report");
2832       log->show();
2833     }
2834   else if(id==2)
2835     {
2836       std::string msg = anExecutor->getContainerLog();
2837       DEBTRACE(msg);
2838       LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
2839       log->readFile(msg);
2840       log->setCaption("Schema container log");
2841       log->show();
2842     }
2843 }
2844
2845 // YACSGui_ElementaryNodeViewItem class:
2846
2847 YACSGui_ElementaryNodeViewItem::YACSGui_ElementaryNodeViewItem(QListView *parent,
2848                                                                const QString &text,
2849                                                                Type tt,
2850                                                                YACS::ENGINE::ElementaryNode *node)
2851   : GuiObserver(), 
2852     QCheckListItem(parent, text, tt),
2853     myBlockSelect( false )
2854 {
2855   _cf = Qt::green;
2856   _node = node;
2857
2858   // attach to HMI 
2859   YACS::HMI::Subject* aSub = getSubject();
2860   if ( aSub )
2861     aSub->attach( this );
2862 }
2863
2864 YACSGui_ElementaryNodeViewItem::YACSGui_ElementaryNodeViewItem(QListViewItem *parent,
2865                                                                const QString &text,
2866                                                                Type tt,
2867                                                                YACS::ENGINE::ElementaryNode *node)
2868   : QCheckListItem(parent, text, tt),
2869     myBlockSelect( false )
2870 {
2871   _cf = Qt::green;
2872   _node = node;
2873
2874   // attach to HMI 
2875   YACS::HMI::Subject* aSub = getSubject();
2876   if ( aSub )
2877     aSub->attach( this );
2878 }
2879
2880 YACSGui_ElementaryNodeViewItem::~YACSGui_ElementaryNodeViewItem()
2881 {
2882   // detach from HMI 
2883   YACS::HMI::Subject* aSub = getSubject();
2884   if ( aSub )
2885     aSub->detach( this );
2886 }
2887
2888 YACS::HMI::Subject* YACSGui_ElementaryNodeViewItem::getSubject() const
2889 {
2890   YACS::HMI::Subject* aSub = 0;
2891
2892   if ( _node )
2893   {
2894     GuiContext* aContext = GuiContext::getCurrent();
2895     if ( aContext )
2896     {
2897       if ( aContext->_mapOfSubjectNode.find( _node ) != aContext->_mapOfSubjectNode.end() )
2898         aSub = aContext->_mapOfSubjectNode[ _node ];
2899     }
2900   }
2901
2902   return aSub;
2903 }
2904
2905 /*!
2906   \brief Block actions performed in select() method. Usually this method is called 
2907          from select() in order to avoid circularity because of synchronization: 
2908          selection in 2D viewer --> selection in tree view --> selection in 2D viewer --> etc.
2909   \param toBlock block selection
2910   \return previous blocking value 
2911 */
2912 bool YACSGui_ElementaryNodeViewItem::blockSelection( const bool toBlock )
2913 {
2914   bool prevVal = myBlockSelect;
2915   myBlockSelect = toBlock;
2916   return prevVal;
2917 }
2918
2919 /*!
2920   \brief Verifiee whether actions performed in select() method are blocked
2921          (see blockSelection method for more dscription)
2922   \return blocking value 
2923 */
2924 bool YACSGui_ElementaryNodeViewItem::selectionBlocked() const
2925 {
2926   return myBlockSelect;
2927 }
2928
2929 /*!
2930   \brief Selects item in tree view 
2931   \param isSelected specifies whether item has to be selected
2932 */
2933 void YACSGui_ElementaryNodeViewItem::select( bool isSelected )
2934 {
2935   if ( selectionBlocked() )
2936     return;
2937
2938   //printf(">> YACSGui_ViewItem::select( %d ) \n", isSelected );
2939
2940   if ( !isSelected ) // do nothing
2941     return;
2942
2943   // select item in tree view
2944   QListView* aListView = listView();
2945   if ( !aListView )
2946     return;
2947
2948   blockSelection( true );
2949   aListView->clearSelection();
2950   aListView->setCurrentItem( this );
2951   aListView->setSelected( this, true );
2952   aListView->ensureItemVisible( this );
2953   blockSelection( false );
2954 }
2955
2956 void YACSGui_ElementaryNodeViewItem::paintCell( QPainter *p, const QColorGroup &cg,
2957                                                 int column, int width, int alignment )
2958 {
2959   QColorGroup _cg( cg );
2960   QColor c = _cg.text();
2961   if (column == 1) _cg.setColor( QColorGroup::Text, _cf );  
2962   QCheckListItem::paintCell( p, _cg, column, width, alignment );
2963   if (column == 1) _cg.setColor( QColorGroup::Text, c );
2964 }
2965
2966 void YACSGui_ElementaryNodeViewItem::setState(int state)
2967 {
2968   //MESSAGE("ElementaryNodeViewItem::setState: " << state);
2969   _state = state;
2970   switch (_state)
2971     {
2972     case YACS::UNDEFINED:    _cf=Qt::lightGray;       setText(1,"UNDEFINED");    repaint(); break;
2973     case YACS::INVALID:      _cf=Qt::red;             setText(1,"INVALID");      repaint(); break;
2974     case YACS::READY:        _cf=Qt::gray;            setText(1,"READY");        repaint(); break;
2975     case YACS::TOLOAD:       _cf=Qt::darkYellow;      setText(1,"TOLOAD");       repaint(); break;
2976     case YACS::LOADED:       _cf=Qt::darkMagenta;     setText(1,"LOADED");       repaint(); break;
2977     case YACS::TOACTIVATE:   _cf=Qt::darkCyan;        setText(1,"TOACTIVATE");   repaint(); break;
2978     case YACS::ACTIVATED:    _cf=Qt::darkBlue;        setText(1,"ACTIVATED");    repaint(); break;
2979     case YACS::DESACTIVATED: _cf=Qt::gray;            setText(1,"DESACTIVATED"); repaint(); break;
2980     case YACS::DONE:         _cf=Qt::darkGreen;       setText(1,"DONE");         repaint(); break;
2981     case YACS::SUSPENDED:    _cf=Qt::gray;            setText(1,"SUSPENDED");    repaint(); break;
2982     case YACS::LOADFAILED:   _cf.setHsv(320,255,255); setText(1,"LOADFAILED");   repaint(); break;
2983     case YACS::EXECFAILED:   _cf.setHsv( 20,255,255); setText(1,"EXECFAILED");   repaint(); break;
2984     case YACS::PAUSE:        _cf.setHsv(180,255,255); setText(1,"PAUSE");        repaint(); break;
2985     case YACS::INTERNALERR:  _cf.setHsv(340,255,255); setText(1,"INTERNALERR");  repaint(); break;
2986     case YACS::DISABLED:     _cf.setHsv( 40,255,255); setText(1,"DISABLED");     repaint(); break;
2987     case YACS::FAILED:       _cf.setHsv( 20,255,255); setText(1,"FAILED");       repaint(); break;
2988     case YACS::ERROR:        _cf.setHsv(  0,255,255); setText(1,"ERROR");        repaint(); break;
2989     default:                 _cf=Qt::lightGray; repaint();
2990    }
2991 }
2992
2993 void YACSGui_ElementaryNodeViewItem::update( const bool theIsRecursive )
2994 {
2995   // update state
2996   // ...
2997 }
2998
2999 void YACSGui_ElementaryNodeViewItem::popup(YACSGui_Executor* anExecutor,const QPoint & point)
3000 {
3001   QPopupMenu menu(listView());
3002   menu.insertItem("Error Details",0);
3003   menu.insertItem("Error Report",1);
3004   menu.insertItem("Node container log",2);
3005   int id=menu.exec(point);
3006   if(id==0)
3007     {
3008       std::string msg = anExecutor->getErrorDetails(getNode());
3009       LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
3010       log->setCaption("Error Details");
3011       log->show();
3012     }
3013   else if(id==1)
3014     {
3015       std::string msg = anExecutor->getErrorReport(getNode());
3016       LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
3017       log->setCaption("Error Report");
3018       log->show();
3019     }
3020   else if(id==2)
3021     {
3022       std::string msg;
3023       std::string file = anExecutor->getContainerLog(getNode());
3024       DEBTRACE(file);
3025       if(file != "")
3026         msg=file;
3027       else
3028         msg="This node has no container";
3029       LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
3030       log->setCaption("Node container log");
3031       if(file != "")
3032         log->readFile(file);
3033       log->show();
3034     }
3035 }