1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <YACSGui_TreeViewItem.h>
22 #include <YACSGui_TreeView.h>
23 #include <YACSGui_Executor.h>
24 #include <YACSGui_LogViewer.h>
26 #include <guiContext.hxx>
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
32 #include <OutPort.hxx>
34 #include <OutGate.hxx>
35 #include <OutputDataStreamPort.hxx>
38 #include <ForEachLoop.hxx>
40 #include <ComposedNode.hxx>
42 #include <CORBAComponent.hxx>
48 #include "YacsTrace.hxx"
50 using namespace YACS::ENGINE;
51 using namespace YACS::HMI;
54 static const char * const closed_xpm[]={
80 static const char* const open_xpm[]={
106 /* ================ items for tree view in edition mode ================ */
108 // YACSGui_ViewItem class:
110 YACSGui_ViewItem::YACSGui_ViewItem( QListView* theParent,
111 QListViewItem* theAfter ):
112 QListViewItem( theParent, theAfter ),
117 YACSGui_ViewItem::YACSGui_ViewItem( QListViewItem* theParent,
118 QListViewItem* theAfter ):
119 QListViewItem( theParent, theAfter ),
121 myBlockSelect( false )
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
132 bool YACSGui_ViewItem::blockSelection( const bool toBlock )
134 bool prevVal = myBlockSelect;
135 myBlockSelect = toBlock;
140 \brief Verifiee whether actions performed in select() method are blocked
141 (see blockSelection method for more dscription)
142 \return blocking value
144 bool YACSGui_ViewItem::selectionBlocked() const
146 return myBlockSelect;
149 void YACSGui_ViewItem::select( bool isSelected )
151 if ( selectionBlocked() )
154 //printf(">> YACSGui_ViewItem::select( %d ) \n", isSelected );
156 if ( !isSelected ) // do nothing
159 // select item in tree view
160 QListView* aListView = listView();
164 bool block = aListView->signalsBlocked();
165 aListView->blockSignals( true );
167 blockSelection( true );
168 aListView->clearSelection();
169 aListView->setCurrentItem( this );
170 aListView->setSelected( this, true );
171 aListView->ensureItemVisible( this );
172 blockSelection( false );
174 aListView->blockSignals( block );
176 if ( YACSGui_EditionTreeView* aETV = dynamic_cast<YACSGui_EditionTreeView*>(aListView) )
177 aETV->emitSelectionChanged();
180 void YACSGui_ViewItem::removeNodeItem( YACS::HMI::Subject* theSNode )
182 //printf( "YACSGui_ViewItem::removeNodeItem (this=%s)\n", text(0).latin1() );
183 QListViewItem* aNodesL = this;
184 if( !aNodesL->parent() )
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")) )
192 YACSGui_NodeViewItem* aNode = 0;
193 QListViewItem* aChild = aNodesL->firstChild();
196 if ( aNode = dynamic_cast<YACSGui_NodeViewItem*>(aChild) )
197 if ( aNode->getSNode() == theSNode )
199 //printf(">> the son is found\n");
203 aChild = aChild->nextSibling();
208 if( YACS::HMI::SubjectNode* aSNode = dynamic_cast<SubjectNode*>( theSNode ) )
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++ )
216 SubjectControlLink* aControlLink = *cIt;
219 Subject* aParentSNode = aControlLink->getSubjectOutNode()->getParent();
220 aParentSNode->update( REMOVE, CONTROLLINK, aControlLink );
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++ )
230 SubjectLink* aDataLink = *dIt;
233 Subject* aParentSNode = aDataLink->getSubjectOutNode()->getParent();
234 aParentSNode->update( REMOVE, DATALINK, aDataLink );
238 //printf( ">> remove port links\n" );
239 std::list<SubjectDataPort*> aDataPorts;
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 );
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 );
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 );
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 );
259 std::list<SubjectDataPort*>::iterator dpIt = aDataPorts.begin();
260 std::list<SubjectDataPort*>::iterator dpItEnd = aDataPorts.end();
261 for( ; dpIt != dpItEnd; dpIt++ )
263 SubjectDataPort* aDataPort = *dpIt;
266 std::list<SubjectLink*> lsl = aDataPort->getListOfSubjectLink();
267 for( std::list<SubjectLink*>::iterator it = lsl.begin(); it != lsl.end(); ++it )
269 SubjectLink* aLink = *it;
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 ) )
279 //printf( ">> lowest common ancestor : %s\n", aLowestCommonAncestor->getName().c_str() );
280 aLowestCommonAncestor->update( REMOVE, DATALINK, aLink );
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)
294 std::pair<OutPort *, InPort *> outin = std::pair<OutPort *, InPort *>((*it1).second, (*it1).first);
295 globalList.push_back(outin);
297 std::vector< std::pair<OutPort *, InPort *> >::iterator it2;
298 for (it2 = globalList.begin(); it2 != globalList.end(); ++it2)
300 if (GuiContext::getCurrent()->_mapOfSubjectLink.count(*it2))
302 SubjectLink* aLink = GuiContext::getCurrent()->_mapOfSubjectLink[*it2];
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 ) )
312 //printf( ">> lowest common ancestor : %s\n", aLowestCommonAncestor->getName().c_str() );
313 aLowestCommonAncestor->update( REMOVE, DATALINK, aLink );
320 DEBTRACE(">> delete the son item");
321 aNodesL->takeItem(aNode);
327 void YACSGui_ViewItem::removeLinkItem( YACS::HMI::Subject* theSLink )
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 )
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();
341 DEBTRACE( ">> item : " << aChildLinks->text(0).latin1() );
342 aLinksL = dynamic_cast<YACSGui_LabelViewItem*>(aChildLinks);
343 if ( aLinksL && aLinksL->text(0).compare(QString("Links")) == 0 )
345 aChildLinks = aChildLinks->nextSibling();
351 // find the link item published under in the Links folder to delete
352 QListViewItem* aChild = aLinksL->firstChild();
357 if ( YACSGui_LinkViewItem* aLink = dynamic_cast<YACSGui_LinkViewItem*>(aChild) )
358 if ( aLink->getSLink() == aSLink )
360 DEBTRACE(">> the data link is found");
361 aLinksL->takeItem(aChild);
368 if ( YACSGui_ControlLinkViewItem* aCLink = dynamic_cast<YACSGui_ControlLinkViewItem*>(aChild) )
369 if ( aCLink->getSLink() == aSCLink )
371 DEBTRACE(">> the control link is found");
372 aLinksL->takeItem(aChild);
378 aChild = aChild->nextSibling();
383 // YACSGui_LabelViewItem class:
385 YACSGui_LabelViewItem::YACSGui_LabelViewItem( QListView* theParent,
386 QListViewItem* theAfter,
387 const QString theName ):
388 YACSGui_ViewItem( theParent, theAfter ),
391 if ( !myName.isEmpty() )
392 setText( 0, myName );
393 setPixmap( 0, icon() );
396 YACSGui_LabelViewItem::YACSGui_LabelViewItem( QListViewItem* theParent,
397 QListViewItem* theAfter,
398 const QString theName ):
399 YACSGui_ViewItem( theParent, theAfter ),
402 if ( !myName.isEmpty() )
403 setText( 0, myName );
404 setPixmap( 0, icon() );
407 QString YACSGui_LabelViewItem::name() const
412 QPixmap YACSGui_LabelViewItem::icon() const
415 return QPixmap( (const char**) open_xpm );
416 return QPixmap( (const char**) closed_xpm );
419 void YACSGui_LabelViewItem::select( bool isSelected )
421 //printf(">> YACSGui_ReferenceViewItem::select( %d ) does nothing\n", isSelected);
424 void YACSGui_LabelViewItem::update( const bool theIsRecursive )
429 // YACSGui_ReferenceViewItem class:
431 YACSGui_ReferenceViewItem::YACSGui_ReferenceViewItem( QListView* theParent,
432 QListViewItem* theAfter,
433 YACS::HMI::SubjectReference* theSReference ):
434 YACSGui_ViewItem( theParent, theAfter ),
435 mySReference( theSReference )
437 if ( mySReference ) mySReference->attach(this);
439 QString aName = name();
440 if ( !aName.isEmpty() )
442 setPixmap( 0, icon() );
445 YACSGui_ReferenceViewItem::YACSGui_ReferenceViewItem( QListViewItem* theParent,
446 QListViewItem* theAfter,
447 YACS::HMI::SubjectReference* theSReference ):
448 YACSGui_ViewItem( theParent, theAfter ),
449 mySReference( theSReference )
451 if ( mySReference ) mySReference->attach(this);
453 QString aName = name();
454 if ( !aName.isEmpty() )
456 setPixmap( 0, icon() );
459 YACSGui_ReferenceViewItem::~YACSGui_ReferenceViewItem()
461 if ( mySReference ) mySReference->detach(this);
464 void YACSGui_ReferenceViewItem::select(bool isSelected)
466 //printf(">> YACSGui_ReferenceViewItem::select( %d ) does nothing\n", isSelected);
467 DEBTRACE(">> YACSGui_ReferenceViewItem::select( " << isSelected << " ) does nothing");
470 void YACSGui_ReferenceViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
472 //printf(">> YACSGui_ReferenceViewItem::update\n");
473 DEBTRACE(">> YACSGui_ReferenceViewItem::update");
480 GuiObserver::update(event, type, son);
484 QString YACSGui_ReferenceViewItem::name() const
489 aName = QString("* ") + QString(getNode()->getRootNode()->getChildName(getNode()));
494 QColor YACSGui_ReferenceViewItem::color( const ColorRole theCR ) const
501 clr = QColor( 255, 0, 0 );
503 case HighlightedText:
504 clr = QColor( 255, 255, 255 );
510 QPixmap YACSGui_ReferenceViewItem::icon() const
515 YACS::ENGINE::Node* YACSGui_ReferenceViewItem::getNode() const
520 if ( SubjectServiceNode* aSSN = dynamic_cast<SubjectServiceNode*>( mySReference->getParent() ) )
521 aRet = aSSN->getNode();
526 void YACSGui_ReferenceViewItem::paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align )
528 QColorGroup col_group( cg );
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 ) );
537 p->fillRect( 0, 0, w, height(), cg.brush( QColorGroup::Base ) );
540 if ( listView() && !listView()->allColumnsShowFocus() )
541 W = width( p->fontMetrics(), listView(), c );
543 QListViewItem::paintCell( p, col_group, c, W<w ? W : w, align );
546 void YACSGui_ReferenceViewItem::update( const bool theIsRecursive )
548 setText( 0, name() ); // only rename
551 // YACSGui_PortViewItem class:
553 YACSGui_PortViewItem::YACSGui_PortViewItem( QListView* theParent,
554 QListViewItem* theAfter,
555 YACS::HMI::SubjectDataPort* theSPort ):
556 YACSGui_ViewItem( theParent, theAfter ),
561 mySPort->attach( this );
563 QString aName = name();
564 if ( !aName.isEmpty() )
566 setPixmap( 0, icon() );
570 YACSGui_PortViewItem::YACSGui_PortViewItem( QListViewItem* theParent,
571 QListViewItem* theAfter,
572 YACS::HMI::SubjectDataPort* theSPort ):
573 YACSGui_ViewItem( theParent, theAfter ),
578 mySPort->attach( this );
580 QString aName = name();
581 if ( !aName.isEmpty() )
583 setPixmap( 0, icon() );
587 YACSGui_PortViewItem::~YACSGui_PortViewItem()
589 if ( mySPort ) mySPort->detach(this);
592 QString YACSGui_PortViewItem::name() const
596 DataPort* aDataPort = getPort();
598 aName = aDataPort->getName();
603 QPixmap YACSGui_PortViewItem::icon() const
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"));
614 if ( !anIconName.isEmpty() )
615 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
620 YACS::ENGINE::DataPort* YACSGui_PortViewItem::getPort() const
622 return ( mySPort ? mySPort->getPort() : 0 );
625 void YACSGui_PortViewItem::update( const bool theIsRecursive )
630 // YACSGui_DataTypeItem class:
635 YACSGui_DataTypeItem::YACSGui_DataTypeItem( QListView* theParent,
636 QListViewItem* theAfter,
637 YACS::HMI::SubjectDataType* theSDataType )
638 : YACSGui_ViewItem( theParent, theAfter ),
639 mySDataType( theSDataType )
642 theSDataType->attach( this );
644 QString aName = name();
645 if ( !aName.isEmpty() )
647 setPixmap( 0, icon() );
653 YACSGui_DataTypeItem::YACSGui_DataTypeItem( QListViewItem* theParent,
654 QListViewItem* theAfter,
655 YACS::HMI::SubjectDataType* theSDataType )
656 : YACSGui_ViewItem( theParent, theAfter ),
657 mySDataType( theSDataType )
660 theSDataType->attach( this );
662 QString aName = name();
663 if ( !aName.isEmpty() )
665 setPixmap( 0, icon() );
671 YACSGui_DataTypeItem::~YACSGui_DataTypeItem()
676 \brief Updates item in accordance with GUI event
678 void YACSGui_DataTypeItem::update( YACS::HMI::GuiEvent event,
680 YACS::HMI::Subject* son )
682 //printf(">> YACSGui_DataTypeItem::update\n");
683 DEBTRACE(">> YACSGui_DataTypeItem::update");
690 GuiObserver::update( event, type, son );
696 \brief Gets item name
698 QString YACSGui_DataTypeItem::name() const
702 aName = QString( mySDataType->getName() );
707 \brief Gets item icon
709 QPixmap YACSGui_DataTypeItem::icon()
712 QString anIconName( QObject::tr( "ICON_TEXT" ) );
714 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false );
719 void YACSGui_DataTypeItem::update( const bool /*theIsRecursive*/ )
721 // nothing to be updated
724 // YACSGui_NodeViewItem class:
726 YACSGui_NodeViewItem::YACSGui_NodeViewItem( QListView* theParent,
727 QListViewItem* theAfter,
728 YACS::HMI::SubjectNode* theSNode ):
729 YACSGui_ViewItem( theParent, theAfter ),
732 if ( mySNode ) mySNode->attach(this);
734 QString aName = name();
735 if ( !aName.isEmpty() )
737 setPixmap( 0, icon() );
740 YACSGui_NodeViewItem::YACSGui_NodeViewItem( QListViewItem* theParent,
741 QListViewItem* theAfter,
742 YACS::HMI::SubjectNode* theSNode ):
743 YACSGui_ViewItem( theParent, theAfter ),
746 if ( mySNode ) mySNode->attach(this);
748 QString aName = name();
749 if ( !aName.isEmpty() )
751 setPixmap( 0, icon() );
754 YACSGui_NodeViewItem::~YACSGui_NodeViewItem()
756 if ( mySNode ) mySNode->detach(this);
759 void YACSGui_NodeViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
761 DEBTRACE(">> YACSGui_NodeViewItem::update");
772 case INPUTDATASTREAMPORT:
773 case OUTPUTDATASTREAMPORT:
775 // rename a port item (this = node item)
776 //printf("NodeViewItem: EDIT port\n");
790 // add a reference item (this = node item)
791 //printf("NodeViewItem: ADDREF\n");
792 addReferenceItem(son);
800 case INPUTDATASTREAMPORT:
801 case OUTPUTDATASTREAMPORT:
803 // add a port item (this = node item)
804 //printf("NodeViewItem: ADD port\n");
819 case SALOMEPYTHONNODE:
826 // remove a node inside a block (this = block item)
827 DEBTRACE("NodeViewItem: ADD");
840 // Readdress this event to schema item
841 YACSGui_SchemaViewItem* aSchema =
842 dynamic_cast<YACSGui_SchemaViewItem*>( listView()->firstChild() );
844 aSchema->update( event, type, son );
850 // remove a link item (this = out node item)
851 DEBTRACE("NodeViewItem: REMOVE link");
857 case INPUTDATASTREAMPORT:
858 case OUTPUTDATASTREAMPORT:
860 // remove a port item (this = node item)
861 DEBTRACE("NodeViewItem: REMOVE port");
876 case SALOMEPYTHONNODE:
883 // remove a node inside a block (this = block item)
884 //printf("NodeViewItem: REMOVE\n");
890 // remove a reference to a component (this = service node item)
891 //printf("NodeViewItem: REMOVE reference\n");
892 removeReferenceItem(son);
904 case INPUTDATASTREAMPORT:
905 case OUTPUTDATASTREAMPORT:
907 // move up a port item (this = node item)
908 //printf("NodeViewItem: UP port\n");
921 case INPUTDATASTREAMPORT:
922 case OUTPUTDATASTREAMPORT:
924 // move down a port item (this = node item)
925 DEBTRACE("NodeViewItem: DOWN port");
926 moveDownPortItem(son);
936 // add link item (this = composed node item)
937 DEBTRACE("NodeViewItem: ADDLINK");
942 GuiObserver::update(event, type, son);
946 QString YACSGui_NodeViewItem::name() const
951 aName = QString(getNode()->getName());
956 QPixmap YACSGui_NodeViewItem::icon( YACS::ENGINE::Node* theNode )
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"));
969 anIconName = QString(QObject::tr("ICON_NODE_OBJECT"));
971 if ( !anIconName.isEmpty() )
972 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
977 QPixmap YACSGui_NodeViewItem::icon() const
979 return icon( getNode() );
982 YACS::ENGINE::Node* YACSGui_NodeViewItem::getNode() const
984 return ( mySNode ? mySNode->getNode() : 0 );
987 void YACSGui_NodeViewItem::update( const bool theIsRecursive )
989 if ( theIsRecursive ) // total update
991 ComposedNode* aComposedNode = dynamic_cast<ComposedNode*>( getNode() );
993 std::list<SubjectNode*> aChildrenToMove;
995 QListViewItem* aChild = firstChild();
999 { // this node is a block
1000 if ( YACSGui_NodeViewItem* aChildNode = dynamic_cast<YACSGui_NodeViewItem*>( aChild ) )
1002 if ( !aComposedNode->isInMyDescendance( aChildNode->getNode() ) )
1003 { // a current child is not in the block now
1004 aChildrenToMove.push_back( aChildNode->getSNode() );
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)
1014 aChild = firstChild();
1017 if ( YACSGui_EditionTreeView* anETV = dynamic_cast<YACSGui_EditionTreeView*>(listView()) )
1018 anETV->displayChildren( this );
1020 if ( aComposedNode )
1021 if ( YACSGui_SchemaViewItem* aSchema = dynamic_cast<YACSGui_SchemaViewItem*>(listView()->firstChild()) )
1023 //aSchema->update( true, 0, this );
1025 if ( !aChildrenToMove.empty() )
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;
1032 // find the last view item under "Nodes" label
1033 YACSGui_NodeViewItem* aLast = 0;
1034 QListViewItem* aChildL = aNodesL->firstChild();
1037 if ( YACSGui_NodeViewItem* aChildLNodeItem = dynamic_cast<YACSGui_NodeViewItem*>(aChildL) )
1038 aLast = aChildLNodeItem;
1039 aChildL = aChildL->nextSibling();
1042 if ( YACSGui_EditionTreeView* anETV = dynamic_cast<YACSGui_EditionTreeView*>(listView()) )
1044 std::list<SubjectNode*>::iterator anIt = aChildrenToMove.begin();
1045 for (; anIt != aChildrenToMove.end(); anIt++)
1047 // create list view items after the last view item under "Nodes" label
1048 aLast = anETV->displayNodeWithPorts( aNodesL, aLast, *anIt );
1056 setText( 0, name() ); // only rename
1059 void YACSGui_NodeViewItem::renamePortItem( YACS::HMI::Subject* theSPort )
1061 if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1063 YACSGui_PortViewItem* aPort = 0;
1064 QListViewItem* aChild = firstChild();
1067 if ( aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1068 if ( aPort->getPort() == aSPort->getPort() )
1070 //printf(">> the son is found\n");
1074 aChild = aChild->nextSibling();
1079 //printf(">> rename the son item\n");
1080 aPort->setText( 0, aPort->name() );
1085 void YACSGui_NodeViewItem::addPortItem( YACS::HMI::Subject* theSPort )
1087 if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1089 Port* aPort = aSPort->getPort();
1090 if ( !aPort ) return;
1092 if ( isPublished(aPort) ) return;
1094 YACSGui_PortViewItem* aPortItem = new YACSGui_PortViewItem( this, 0, aSPort );
1095 if ( !aPortItem ) return;
1098 // find the port, after which aPort is stored in the engine
1099 if ( dynamic_cast<InPort*>(aPort) )
1101 std::list<InPort *> anInPorts = getNode()->getSetOfInPort();
1102 std::list<InPort *>::iterator InPortsIter = anInPorts.begin();
1103 for(; InPortsIter != anInPorts.end(); InPortsIter++)
1105 if ( *InPortsIter == aPort ) break;
1106 anAfter = *InPortsIter;
1109 else if ( dynamic_cast<OutPort*>(aPort) )
1111 std::list<OutPort *> anOutPorts = getNode()->getSetOfOutPort();
1112 std::list<OutPort *>::iterator OutPortsIter = anOutPorts.begin();
1113 for(; OutPortsIter != anOutPorts.end(); OutPortsIter++)
1115 if ( *OutPortsIter == aPort ) break;
1116 anAfter = *OutPortsIter;
1120 // find the port, after which aPortItem should be stored in the tree
1121 YACSGui_PortViewItem* anAfterItem = 0;
1123 QListViewItem* aChild;
1124 if ( dynamic_cast<InPort*>(aPort) )
1125 aChild = firstChild();
1126 else if ( dynamic_cast<OutPort*>(aPort) )
1128 // find tree view item corresponds to the last input port
1129 QListViewItem* aLastInPort = firstChild();
1130 while( aLastInPort )
1132 if ( YACSGui_PortViewItem* aFirstOutPortItem = dynamic_cast<YACSGui_PortViewItem*>(aLastInPort->nextSibling()) )
1133 if ( dynamic_cast<OutPort*>(aFirstOutPortItem->getPort()) )
1135 aLastInPort = aLastInPort->nextSibling();
1137 aChild = aLastInPort;
1141 aPortItem->moveItem(aLastInPort);
1148 if ( anAfterItem = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1149 if ( anAfterItem->getPort() == anAfter )
1151 //printf(">> the son is found\n");
1152 aPortItem->moveItem(anAfterItem);
1156 aChild = aChild->nextSibling();
1161 void YACSGui_NodeViewItem::removePortItem( YACS::HMI::Subject* theSPort )
1163 if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1165 QListViewItem* aChild = firstChild();
1168 if ( YACSGui_PortViewItem* aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1169 if ( aPort->getPort() == aSPort->getPort() )
1171 //printf(">> the son is found\n");
1177 aChild = aChild->nextSibling();
1182 void YACSGui_NodeViewItem::addNodeItem( YACS::HMI::Subject* theSNode )
1184 if ( SubjectNode* aSNode = dynamic_cast<SubjectNode*>(theSNode) )
1186 YACSGui_NodeViewItem* aNodeItem = new YACSGui_NodeViewItem( this, 0, aSNode );
1188 if ( SubjectComposedNode* aSCompNode = dynamic_cast<SubjectComposedNode*>(aSNode) )
1189 YACSGui_LabelViewItem* aLinksItem = new YACSGui_LabelViewItem( aNodeItem, 0, QObject::tr( "LINKS" ) );
1193 void YACSGui_NodeViewItem::moveUpPortItem( YACS::HMI::Subject* theSPort )
1195 if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1197 QListViewItem* aChild = firstChild();
1200 if ( YACSGui_PortViewItem* aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild->nextSibling()) )
1201 if ( aPort->getPort() == aSPort->getPort() )
1204 aChild = aChild->nextSibling();
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;
1211 if ( dynamic_cast<InPort*>(aSPort->getPort()) && dynamic_cast<InPort*>(aCPort->getPort())
1213 dynamic_cast<OutPort*>(aSPort->getPort()) && dynamic_cast<OutPort*>(aCPort->getPort()) )
1214 //if ( dynamic_cast<InPort*>(aSPort->getPort())
1216 // aChild->text(0).compare( QString("Gate") ) )
1218 aChild->moveItem(aChild->nextSibling());
1223 void YACSGui_NodeViewItem::moveDownPortItem( YACS::HMI::Subject* theSPort )
1225 if ( SubjectDataPort* aSPort = dynamic_cast<SubjectDataPort*>(theSPort) )
1227 QListViewItem* aChild = firstChild();
1230 if ( YACSGui_PortViewItem* aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1231 if ( aPort->getPort() == aSPort->getPort() )
1233 //printf(">> the son is found\n");
1237 aChild = aChild->nextSibling();
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;
1244 YACSGui_PortViewItem* aCNPort = dynamic_cast<YACSGui_PortViewItem*>(aChild->nextSibling());
1245 if ( !aCNPort ) return;
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());
1253 bool YACSGui_NodeViewItem::isPublished( YACS::ENGINE::Port* thePort )
1255 QListViewItem* aChild = firstChild();
1258 if ( YACSGui_PortViewItem* aPort = dynamic_cast<YACSGui_PortViewItem*>(aChild) )
1259 if ( aPort->getPort() == thePort )
1261 aChild = aChild->nextSibling();
1266 void YACSGui_NodeViewItem::addReferenceItem( YACS::HMI::Subject* theSRef )
1268 if ( SubjectReference* aSRef = dynamic_cast<SubjectReference*>(theSRef) )
1270 // get component subject of the given reference
1271 if ( SubjectComponent* aSComp = dynamic_cast<SubjectComponent*>(aSRef->getReference()) )
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;
1278 ComponentInstance* aComp = aSComp->getComponent();
1279 if ( aComp && aComp->getKind() != CORBAComponent::KIND )
1281 // get container corresponds to the component
1282 Container* aCont = aComp->getContainer();
1285 QListViewItem* aContItem = 0;
1286 QListViewItem* aChild = aContainersL->firstChild();
1289 if ( YACSGui_ContainerViewItem* aC = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
1290 if ( aC->getContainer() == aCont )
1295 aChild = aChild->nextSibling();
1300 // find component view item corresponds to the aSComp
1301 QListViewItem* aCompItem = 0;
1302 QListViewItem* aChild = aContItem->firstChild();
1305 if ( YACSGui_ComponentViewItem* aC = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
1306 if ( aC->getComponent() == aComp )
1311 aChild = aChild->nextSibling();
1316 // add a new reference to the end
1317 QListViewItem* anAfter = 0;
1319 if ( QListViewItem* aChild = aCompItem->firstChild() )
1321 while( aChild->nextSibling() )
1322 aChild = aChild->nextSibling();
1326 new YACSGui_ReferenceViewItem( aCompItem, anAfter, aSRef );
1332 { // it is a CORBA component
1333 // find component view item corresponds to the aSComp
1334 QListViewItem* aCompItem = 0;
1335 QListViewItem* aChild = aContainersL->firstChild();
1338 if ( YACSGui_ComponentViewItem* aC = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
1339 if ( aC->getComponent() == aComp )
1344 aChild = aChild->nextSibling();
1349 // add a new reference to the end
1350 QListViewItem* anAfter = 0;
1352 if ( QListViewItem* aChild = aCompItem->firstChild() )
1354 while( aChild->nextSibling() )
1355 aChild = aChild->nextSibling();
1359 new YACSGui_ReferenceViewItem( aCompItem, anAfter, aSRef );
1366 void YACSGui_NodeViewItem::removeReferenceItem( YACS::HMI::Subject* theSRef )
1368 if ( SubjectReference* aSRef = dynamic_cast<SubjectReference*>(theSRef) )
1370 // get component subject of the given reference
1371 if ( SubjectComponent* aSComp = dynamic_cast<SubjectComponent*>(aSRef->getReference()) )
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;
1378 ComponentInstance* aComp = aSComp->getComponent();
1379 if ( aComp && aComp->getKind() != CORBAComponent::KIND )
1381 // get container corresponds to the component
1382 Container* aCont = aComp->getContainer();
1385 QListViewItem* aContItem = 0;
1386 QListViewItem* aChild = aContainersL->firstChild();
1389 if ( YACSGui_ContainerViewItem* aC = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
1390 if ( aC->getContainer() == aCont )
1395 aChild = aChild->nextSibling();
1400 // find component view item corresponds to the aSComp
1401 QListViewItem* aCompItem = 0;
1402 QListViewItem* aChild = aContItem->firstChild();
1405 if ( YACSGui_ComponentViewItem* aC = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
1406 if ( aC->getComponent() == aComp )
1411 aChild = aChild->nextSibling();
1416 // delete a given reference
1417 if ( QListViewItem* aChild = aCompItem->firstChild() )
1421 if ( YACSGui_ReferenceViewItem* aRefItem = dynamic_cast<YACSGui_ReferenceViewItem*>(aChild) )
1422 if ( aRefItem->getSReference() == aSRef )
1424 aCompItem->takeItem(aChild);
1428 aChild = aChild->nextSibling();
1436 { // it is a CORBA component
1437 // find component view item corresponds to the aSComp
1438 QListViewItem* aCompItem = 0;
1439 QListViewItem* aChild = aContainersL->firstChild();
1442 if ( YACSGui_ComponentViewItem* aC = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
1443 if ( aC->getComponent() == aComp )
1448 aChild = aChild->nextSibling();
1453 // delete a given reference
1454 if ( QListViewItem* aChild = aCompItem->firstChild() )
1458 if ( YACSGui_ReferenceViewItem* aRefItem = dynamic_cast<YACSGui_ReferenceViewItem*>(aChild) )
1459 if ( aRefItem->getSReference() == aSRef )
1461 aCompItem->takeItem(aChild);
1465 aChild = aChild->nextSibling();
1474 void YACSGui_NodeViewItem::addLinkItem( YACS::HMI::Subject* theSLink )
1476 DEBTRACE("YACSGui_NodeViewItem::addLinkItem");
1477 SubjectLink* aSLink = dynamic_cast<SubjectLink*>(theSLink);
1478 SubjectControlLink* aSCLink = dynamic_cast<SubjectControlLink*>(theSLink);
1479 if ( aSLink || aSCLink )
1481 // get the "Links" label view item under this node view item
1482 YACSGui_LabelViewItem* aLinksL = 0;
1483 QListViewItem* aChildLinks = firstChild();
1484 while( aChildLinks )
1486 aLinksL = dynamic_cast<YACSGui_LabelViewItem*>(aChildLinks);
1487 if ( aLinksL && aLinksL->text(0).compare(QString("Links")) == 0 )
1489 aChildLinks = aChildLinks->nextSibling();
1495 // find the last link item published under in the Links folder
1496 QListViewItem* anAfter = 0;
1497 if ( QListViewItem* aChild = aLinksL->firstChild() )
1499 while( aChild->nextSibling() )
1500 aChild = aChild->nextSibling();
1504 if ( aSLink ) new YACSGui_LinkViewItem( aLinksL, anAfter, aSLink );
1505 else if ( aSCLink ) new YACSGui_ControlLinkViewItem( aLinksL, anAfter, aSCLink );
1509 // YACSGui_LinkViewItem class:
1511 YACSGui_LinkViewItem::YACSGui_LinkViewItem( QListView* theParent,
1512 QListViewItem* theAfter,
1513 YACS::HMI::SubjectLink* theSLink ):
1514 YACSGui_ViewItem( theParent, theAfter ),
1519 mySLink->attach(this);
1521 QString aName = name();
1522 if ( !aName.isEmpty() )
1523 setText( 0, aName );
1524 setPixmap( 0, icon() );
1528 YACSGui_LinkViewItem::YACSGui_LinkViewItem( QListViewItem* theParent,
1529 QListViewItem* theAfter,
1530 YACS::HMI::SubjectLink* theSLink ):
1531 YACSGui_ViewItem( theParent, theAfter ),
1536 mySLink->attach(this);
1538 QString aName = name();
1539 if ( !aName.isEmpty() )
1540 setText( 0, aName );
1541 setPixmap( 0, icon() );
1545 YACSGui_LinkViewItem::~YACSGui_LinkViewItem()
1547 if ( mySLink ) mySLink->detach(this);
1550 QString YACSGui_LinkViewItem::name() const
1554 if ( !mySLink ) return aName;
1556 DataPort* anOutPort = mySLink->getSubjectOutPort()->getPort();
1557 DataPort* anInPort = mySLink->getSubjectInPort()->getPort();
1558 if ( anOutPort && anInPort )
1560 Node* anOutPortNode = anOutPort->getNode();
1561 ComposedNode* aRootO = 0;
1562 if ( dynamic_cast<Bloc*>( anOutPortNode->getFather() ) )
1563 aRootO = anOutPortNode->getFather();
1565 aRootO = anOutPortNode->getRootNode();
1567 Node* anInPortNode = anInPort->getNode();
1568 ComposedNode* aRootI = 0;
1569 if ( dynamic_cast<Bloc*>( anInPortNode->getFather() ) )
1570 aRootI = anInPortNode->getFather();
1572 aRootI = anInPortNode->getRootNode();
1574 ComposedNode* aRoot = 0;
1575 if ( aRootO->isInMyDescendance(aRootI) )
1577 else if ( aRootI->isInMyDescendance(aRootO) )
1583 // find the nearest common ancestor for anOutNode and anInNode
1584 Proc* aProc = dynamic_cast<Proc*>(aRootI->getRootNode());
1585 if ( !aProc ) return aName;
1588 while ( aRootI->getFather() != aProc )
1590 if ( aBlocOut = dynamic_cast<Bloc*>(aRootI->getFather()->isInMyDescendance(aRootO)) )
1592 aBlocIn = dynamic_cast<Bloc*>(aRootI);
1595 aRootI = aRootI->getFather();
1598 if ( aBlocOut && aBlocIn )
1599 aRoot = aBlocOut->getFather();
1603 aName += QString(aRoot->getChildName(anOutPortNode));
1605 aName += QString(".%1").arg(anOutPort->getName());
1606 aName += QString(" --> ");
1609 aName += QString(aRoot->getChildName(anInPortNode));
1611 aName += QString(".%1").arg(anInPort->getName());
1617 QPixmap YACSGui_LinkViewItem::icon() const
1623 if ( !mySLink ) return aRes;
1625 if ( DataPort* anOutPort = mySLink->getSubjectOutPort()->getPort() )
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"));
1632 if ( !anIconName.isEmpty() )
1633 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
1639 void YACSGui_LinkViewItem::update( const bool theIsRecursive )
1644 // YACSGui_ControlLinkViewItem class:
1646 YACSGui_ControlLinkViewItem::YACSGui_ControlLinkViewItem( QListView* theParent,
1647 QListViewItem* theAfter,
1648 YACS::HMI::SubjectControlLink* theSLink ):
1649 YACSGui_ViewItem( theParent, theAfter ),
1654 mySLink->attach(this);
1656 QString aName = name();
1657 if ( !aName.isEmpty() )
1658 setText( 0, aName );
1659 setPixmap( 0, icon() );
1663 YACSGui_ControlLinkViewItem::YACSGui_ControlLinkViewItem( QListViewItem* theParent,
1664 QListViewItem* theAfter,
1665 YACS::HMI::SubjectControlLink* theSLink ):
1666 YACSGui_ViewItem( theParent, theAfter ),
1671 mySLink->attach(this);
1673 QString aName = name();
1674 if ( !aName.isEmpty() )
1675 setText( 0, aName );
1676 setPixmap( 0, icon() );
1680 YACSGui_ControlLinkViewItem::~YACSGui_ControlLinkViewItem()
1682 if ( mySLink ) mySLink->detach(this);
1685 QString YACSGui_ControlLinkViewItem::name() const
1689 if ( !mySLink ) return aName;
1691 Node* anOutPortNode = mySLink->getSubjectOutNode()->getNode();
1692 ComposedNode* aRootO = 0;
1693 if ( dynamic_cast<Bloc*>( anOutPortNode->getFather() ) )
1694 aRootO = anOutPortNode->getFather();
1696 aRootO = anOutPortNode->getRootNode();
1698 Node* anInPortNode = mySLink->getSubjectInNode()->getNode();
1699 ComposedNode* aRootI = 0;
1700 if ( dynamic_cast<Bloc*>( anInPortNode->getFather() ) )
1701 aRootI = anInPortNode->getFather();
1703 aRootI = anInPortNode->getRootNode();
1705 ComposedNode* aRoot = 0;
1706 if ( aRootO->isInMyDescendance(aRootI) )
1708 else if ( aRootI->isInMyDescendance(aRootO) )
1714 // find the nearest common ancestor for anOutNode and anInNode
1715 Proc* aProc = dynamic_cast<Proc*>(aRootI->getRootNode());
1716 if ( !aProc ) return aName;
1718 while ( aRootI->getFather() != aProc )
1720 if ( aBlocOut = dynamic_cast<Bloc*>(aRootI->getFather()->isInMyDescendance(aRootO)) )
1722 aBlocIn = dynamic_cast<Bloc*>(aRootI);
1725 aRootI = aRootI->getFather();
1728 if ( aBlocOut && aBlocIn )
1729 aRoot = aBlocOut->getFather();
1733 aName += QString(aRoot->getChildName(anOutPortNode));
1735 aName += QString(" --> ");
1738 aName += QString(aRoot->getChildName(anInPortNode));
1743 QPixmap YACSGui_ControlLinkViewItem::icon() const
1749 anIconName = QString(QObject::tr("ICON_CONTROL_LINK_OBJECT"));
1750 if ( !anIconName.isEmpty() )
1751 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
1756 void YACSGui_ControlLinkViewItem::update( const bool theIsRecursive )
1761 // YACSGui_SchemaViewItem class:
1763 YACSGui_SchemaViewItem::YACSGui_SchemaViewItem( QListView* theParent,
1764 QListViewItem* theAfter,
1765 YACS::HMI::SubjectProc* theSProc ):
1766 YACSGui_ViewItem( theParent, theAfter ),
1769 if ( mySProc ) mySProc->attach(this);
1772 setText( 0, QString( getProc()->getName() ) );
1773 setPixmap( 0, icon() );
1776 YACSGui_SchemaViewItem::YACSGui_SchemaViewItem( QListViewItem* theParent,
1777 QListViewItem* theAfter,
1778 YACS::HMI::SubjectProc* theSProc ):
1779 YACSGui_ViewItem( theParent, theAfter ),
1782 if ( mySProc ) mySProc->attach(this);
1785 setText( 0, QString( getProc()->getName() ) );
1786 setPixmap( 0, icon() );
1789 YACSGui_SchemaViewItem::~YACSGui_SchemaViewItem()
1791 if ( mySProc ) mySProc->detach(this);
1794 YACSGui_LabelViewItem* YACSGui_SchemaViewItem::buildDataTypesTree()
1796 GuiContext* aContext = GuiContext::getCurrent();
1800 YACS::ENGINE::Proc* aProc = aContext->getProc();
1804 // Create "Data Types" label
1806 YACSGui_LabelViewItem* aDataTypesItem =
1807 new YACSGui_LabelViewItem( this, 0, QObject::tr( "DT_DATA_TYPES" ) );
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;
1816 // Create "Objref" label
1817 myRootDataTypeItems[ YACS::ENGINE::Objref ] =
1818 new YACSGui_LabelViewItem( aDataTypesItem, aSimpleItem, QObject::tr( "DT_OBJREF" ) );
1820 // Create "Sequence" label
1821 myRootDataTypeItems[ YACS::ENGINE::Sequence ] = new YACSGui_LabelViewItem(
1822 aDataTypesItem, myRootDataTypeItems[ YACS::ENGINE::Objref ], QObject::tr( "DT_SEQUENCE" ) );
1824 // Create "Array" label
1825 myRootDataTypeItems[ YACS::ENGINE::Array ] = new YACSGui_LabelViewItem(
1826 aDataTypesItem, myRootDataTypeItems[ YACS::ENGINE::Sequence ], QObject::tr( "DT_ARRAY" ) );
1828 // Create "Struct" label
1829 myRootDataTypeItems[ YACS::ENGINE::Struct ] = new YACSGui_LabelViewItem(
1830 aDataTypesItem, myRootDataTypeItems[ YACS::ENGINE::Array ], QObject::tr( "DT_STRUCT" ) );
1832 // Iterate through DataTypes and build tree
1834 std::map<std::string, YACS::HMI::SubjectDataType*>::iterator it;
1835 for ( it = aContext->_mapOfSubjectDataType.begin();
1836 it != aContext->_mapOfSubjectDataType.end(); ++it )
1838 std::string aName = (*it).first;
1839 YACS::HMI::SubjectDataType* aSub = (*it).second;
1843 addDataTypeItem( aSub );
1846 return aDataTypesItem;
1849 void YACSGui_SchemaViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
1851 DEBTRACE(">> YACSGui_SchemaViewItem::update");
1873 case SALOMEPYTHONNODE:
1880 // add a node item (this = schema item)
1881 DEBTRACE("SchemaViewItem: ADD node");
1887 // add a container item (this = schema item)
1888 DEBTRACE("SchemaViewItem: ADD container");
1889 addContainerItem(son);
1894 DEBTRACE("SchemaViewItem: ADD data type");
1895 addDataTypeItem( son );
1907 // remove a container item (this = schema item)
1908 DEBTRACE("SchemaViewItem: REMOVE container");
1909 removeContainerItem(son);
1914 // remove a CORBA component item (this = schema item)
1915 DEBTRACE("SchemaViewItem: REMOVE component");
1916 removeComponentItem(son);
1921 // remove a CORBA component item (this = schema item)
1922 DEBTRACE("SchemaViewItem: REMOVE Data type");
1923 removeDataTypeItem( son );
1929 // remove a link item (this = schema item)
1930 DEBTRACE("SchemaViewItem: REMOVE link");
1931 removeLinkItem(son);
1945 case SALOMEPYTHONNODE:
1952 DEBTRACE("SchemaViewItem: REMOVE");
1953 removeNodeItem(son);
1960 case ADDCONTROLLINK:
1962 // add link item (this = schema item)
1963 DEBTRACE("SchemaViewItem: ADDLINK");
1968 GuiObserver::update(event, type, son);
1972 QPixmap YACSGui_SchemaViewItem::icon() const
1976 QString anIconName = QString(QObject::tr("ICON_SCHEMA_OBJECT"));
1977 if ( !anIconName.isEmpty() )
1978 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
1983 YACS::ENGINE::Proc* YACSGui_SchemaViewItem::getProc() const
1985 return ( mySProc ? dynamic_cast<Proc*>(mySProc->getNode()) : 0 );
1988 void YACSGui_SchemaViewItem::update( const bool theIsRecursive,
1989 YACS::HMI::Subject* theSon,
1990 YACSGui_NodeViewItem* theBlocItem )
1992 if ( theIsRecursive ) // total update
1994 if ( SubjectNode* aNodeSon = dynamic_cast<SubjectNode*>(theSon) ) // theSon is a node
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;
2000 // find list view item before theSon
2001 YACSGui_NodeViewItem* anAfter = 0;
2002 YACSGui_NodeViewItem* anUpdated = 0;
2003 QListViewItem* aChild = aNodesL->firstChild();
2005 if ( YACSGui_NodeViewItem* aFirst = dynamic_cast<YACSGui_NodeViewItem*>(aChild) )
2006 if ( aFirst->getSNode() == aNodeSon )
2012 if ( YACSGui_NodeViewItem* aNext = dynamic_cast<YACSGui_NodeViewItem*>(aChild->nextSibling()) )
2013 if ( aNext->getSNode() == aNodeSon )
2015 anAfter = dynamic_cast<YACSGui_NodeViewItem*>(aChild);
2019 aChild = aChild->nextSibling();
2025 if ( YACSGui_EditionTreeView* anETV = dynamic_cast<YACSGui_EditionTreeView*>(listView()) )
2027 bool anIsOpen = anUpdated->isOpen();
2029 // remove list view item for theSon from the tree
2030 aNodesL->takeItem(anUpdated);
2033 // recreate list view item for theSon
2034 if ( anUpdated = anETV->displayNodeWithPorts( aNodesL, anAfter, aNodeSon ) )
2035 anUpdated->setOpen(anIsOpen);
2039 else if ( !theSon && theBlocItem ) // theSon is null => remove any nodes under theBlocItem
2040 // and add these nodes under "Nodes" label
2042 Bloc* aBloc = dynamic_cast<Bloc*>( theBlocItem->getNode() );
2043 if ( !aBloc ) return;
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;
2049 QListViewItem* aChild = theBlocItem->firstChild();
2052 if ( YACSGui_NodeViewItem* aChildNodeItem = dynamic_cast<YACSGui_NodeViewItem*>(aChild) )
2053 if ( !aBloc->isInMyDescendance( aChildNodeItem->getNode() ) )
2055 //printf(">> Delete and insert : %s\n",aChildNodeItem->getNode()->getName().c_str());
2056 QListViewItem* anAuxItem = aChild->nextSibling();
2058 // remove view item from theBlocItem
2060 aNodesL->insertItem(aChild);
2066 aChild = aChild->nextSibling();
2070 else if ( mySProc ) // only rename
2071 setText( 0, QString( mySProc->getName() ) );
2075 \brief Add data type item in tree view
2077 void YACSGui_SchemaViewItem::addDataTypeItem( YACS::HMI::Subject* theSDataType )
2079 YACS::HMI::SubjectDataType* aSub =
2080 dynamic_cast<YACS::HMI::SubjectDataType*>( theSDataType );
2085 GuiContext* aContext = GuiContext::getCurrent();
2089 YACS::ENGINE::Proc* aProc = aContext->getProc();
2093 std::string aName = aSub->getName();
2095 if ( aProc->typeMap.find( aName ) == aProc->typeMap.end() )
2098 YACS::ENGINE::TypeCode* aTypeCode = aProc->typeMap[ aName ];
2102 DynType aDynType = aTypeCode->kind();
2104 // Create types item if necessary
2105 if ( myRootDataTypeItems.find( aDynType ) == myRootDataTypeItems.end() )
2108 QListViewItem* aFatherItem = myRootDataTypeItems[ aDynType ];
2110 // Create new item under aFatherItem
2111 new YACSGui_DataTypeItem( aFatherItem, 0, aSub );
2115 void YACSGui_SchemaViewItem::addNodeItem( YACS::HMI::Subject* theSNode )
2117 if ( SubjectNode* aSNode = dynamic_cast<SubjectNode*>(theSNode) )
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;
2123 QListViewItem* anAfter = 0;
2125 if ( QListViewItem* aChild = aNodesL->firstChild() )
2127 while( aChild->nextSibling() )
2128 aChild = aChild->nextSibling();
2132 YACSGui_NodeViewItem* aNodeItem = new YACSGui_NodeViewItem( aNodesL, anAfter, aSNode );
2134 if ( SubjectComposedNode* aSCompNode = dynamic_cast<SubjectComposedNode*>(aSNode) )
2135 YACSGui_LabelViewItem* aLinksItem = new YACSGui_LabelViewItem( aNodeItem, 0, QObject::tr( "LINKS" ) );
2139 void YACSGui_SchemaViewItem::addContainerItem( YACS::HMI::Subject* theSContainer )
2141 if ( SubjectContainer* aSContainer = dynamic_cast<SubjectContainer*>(theSContainer) )
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;
2147 QListViewItem* anAfter = 0;
2149 if ( QListViewItem* aChild = aContainersL->firstChild() )
2151 while( aChild->nextSibling() )
2152 aChild = aChild->nextSibling();
2156 new YACSGui_ContainerViewItem( aContainersL, anAfter, aSContainer );
2160 void YACSGui_SchemaViewItem::removeContainerItem( YACS::HMI::Subject* theSContainer )
2162 if ( SubjectContainer* aSContainer = dynamic_cast<SubjectContainer*>(theSContainer) )
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;
2168 QListViewItem* aChild = aContainersL->firstChild();
2171 if ( YACSGui_ContainerViewItem* aCont = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
2172 if ( aCont->getSContainer() == aSContainer )
2174 aContainersL->takeItem(aChild);
2178 aChild = aChild->nextSibling();
2183 void YACSGui_SchemaViewItem::removeDataTypeItem( YACS::HMI::Subject* theSDataType )
2185 YACS::HMI::SubjectDataType* aSub =
2186 dynamic_cast<YACS::HMI::SubjectDataType*>( theSDataType );
2191 GuiContext* aContext = GuiContext::getCurrent();
2195 YACS::ENGINE::Proc* aProc = aContext->getProc();
2199 std::string aName = aSub->getName();
2201 if ( aProc->typeMap.find( aName ) == aProc->typeMap.end() )
2204 YACS::ENGINE::TypeCode* aTypeCode = aProc->typeMap[ aName ];
2208 DynType aDynType = aTypeCode->kind();
2209 if ( myRootDataTypeItems.find( aDynType ) == myRootDataTypeItems.end() )
2212 // find item corresponding to aSub
2214 QListViewItem* aFatherItem = myRootDataTypeItems[ aDynType ];
2216 QListViewItemIterator it( aFatherItem );
\r
2217 QListViewItem* toRemoveItem = 0;
\r
2218 while ( it.current() )
\r
2220 YACSGui_DataTypeItem* currItem = dynamic_cast<YACSGui_DataTypeItem*>( it.current() );
\r
2221 if ( currItem && currItem->getSDataType() == aSub )
\r
2223 toRemoveItem = currItem;
\r
2229 if ( !toRemoveItem )
2234 aFatherItem->takeItem( toRemoveItem );
2235 delete toRemoveItem;
2238 void YACSGui_SchemaViewItem::removeComponentItem( YACS::HMI::Subject* theSComponent )
2240 // ! for CORBA components only
2241 if ( SubjectComponent* aSComponent = dynamic_cast<SubjectComponent*>(theSComponent) )
2243 CORBAComponent* aCComp = dynamic_cast<CORBAComponent*>(aSComponent->getComponent());
2244 if ( !aCComp ) return;
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;
2250 QListViewItem* aChild = aContainersL->firstChild();
2253 if ( YACSGui_ComponentViewItem* aCont = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
2254 if ( aCont->getSComponent() == aSComponent )
2256 aContainersL->takeItem(aChild);
2260 aChild = aChild->nextSibling();
2265 void YACSGui_SchemaViewItem::addLinkItem( YACS::HMI::Subject* theSLink )
2267 DEBTRACE("YACSGui_SchemaViewItem::addLinkItem");
2268 SubjectLink* aSLink = dynamic_cast<SubjectLink*>(theSLink);
2269 SubjectControlLink* aSCLink = dynamic_cast<SubjectControlLink*>(theSLink);
2270 if ( aSLink || aSCLink )
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;
2276 QListViewItem* anAfter = 0;
2278 if ( QListViewItem* aChild = aLinksL->firstChild() )
2280 while( aChild->nextSibling() )
2281 aChild = aChild->nextSibling();
2285 if ( aSLink ) new YACSGui_LinkViewItem( aLinksL, anAfter, aSLink );
2286 else if ( aSCLink ) new YACSGui_ControlLinkViewItem( aLinksL, anAfter, aSCLink );
2290 // YACSGui_ContainerViewItem class:
2292 YACSGui_ContainerViewItem::YACSGui_ContainerViewItem( QListView* theParent,
2293 QListViewItem* theAfter,
2294 YACS::HMI::SubjectContainer* theSContainer ):
2295 YACSGui_ViewItem( theParent, theAfter ),
2296 mySContainer( theSContainer )
2300 mySContainer->attach(this);
2302 QString aName = name();
2303 if ( !aName.isEmpty() )
2304 setText( 0, aName );
2305 setPixmap( 0, icon() );
2309 YACSGui_ContainerViewItem::YACSGui_ContainerViewItem( QListViewItem* theParent,
2310 QListViewItem* theAfter,
2311 YACS::HMI::SubjectContainer* theSContainer ):
2312 YACSGui_ViewItem( theParent, theAfter ),
2313 mySContainer( theSContainer )
2317 mySContainer->attach(this);
2319 QString aName = name();
2320 if ( !aName.isEmpty() )
2321 setText( 0, aName );
2322 setPixmap( 0, icon() );
2326 YACSGui_ContainerViewItem::~YACSGui_ContainerViewItem()
2328 if ( mySContainer ) mySContainer->detach(this);
2331 void YACSGui_ContainerViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
2333 //printf(">> YACSGui_ContainerViewItem::update\n");
2334 DEBTRACE(">> YACSGui_ContainerViewItem::update");
2345 // add a component item (this = container item)
2346 //printf("ContainerViewItem: ADD component\n");
2347 addComponentItem(son);
2359 // remove a component item (this = container item)
2360 //printf("ContainerViewItem: REMOVE component\n");
2361 removeComponentItem(son);
2369 GuiObserver::update(event, type, son);
2373 QString YACSGui_ContainerViewItem::name() const
2375 return ( mySContainer ? QString(mySContainer->getName()) : QString("") );
2378 QPixmap YACSGui_ContainerViewItem::icon() const
2382 if ( getContainer() )
2383 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", QObject::tr("ICON_CONTAINER_OBJECT"));
2388 YACS::ENGINE::Container* YACSGui_ContainerViewItem::getContainer() const
2390 return ( mySContainer ? mySContainer->getContainer() : 0 );
2393 void YACSGui_ContainerViewItem::update( YACSGui_ComponentViewItem* theComponent )
2397 takeItem(theComponent);
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;
2404 // find new container view item, under which theComponent view item should be moved
2405 YACSGui_ContainerViewItem* aCont = 0;
2406 QListViewItem* aChild = aContsL->firstChild();
2409 if ( YACSGui_ContainerViewItem* aChildContItem = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
2410 if ( aChildContItem->getContainer() == theComponent->getComponent()->getContainer() )
2412 aCont = aChildContItem;
2415 aChild = aChild->nextSibling();
2418 if ( aCont ) aCont->insertItem(theComponent);
2421 setText( 0, name() ); // only rename
2424 void YACSGui_ContainerViewItem::addComponentItem( YACS::HMI::Subject* theSComponent )
2426 if ( SubjectComponent* aSComponent = dynamic_cast<SubjectComponent*>(theSComponent) )
2428 QListViewItem* anAfter = 0;
2430 if ( QListViewItem* aChild = firstChild() )
2432 while( aChild->nextSibling() )
2433 aChild = aChild->nextSibling();
2437 new YACSGui_ComponentViewItem( this, anAfter, aSComponent );
2441 void YACSGui_ContainerViewItem::removeComponentItem( YACS::HMI::Subject* theSComponent )
2443 if ( SubjectComponent* aSComponent = dynamic_cast<SubjectComponent*>(theSComponent) )
2445 QListViewItem* aChild = firstChild();
2448 if ( YACSGui_ComponentViewItem* aComp = dynamic_cast<YACSGui_ComponentViewItem*>(aChild) )
2449 if ( aComp->getSComponent() == aSComponent )
2456 aChild = aChild->nextSibling();
2461 // YACSGui_ComponentViewItem class:
2463 YACSGui_ComponentViewItem::YACSGui_ComponentViewItem( QListView* theParent,
2464 QListViewItem* theAfter,
2465 YACS::HMI::SubjectComponent* theSComponent ):
2466 YACSGui_ViewItem( theParent, theAfter ),
2467 mySComponent( theSComponent )
2471 mySComponent->attach(this);
2473 QString anInstName = instanceName();
2474 if ( !anInstName.isEmpty() )
2475 setText( 0, anInstName );
2476 setPixmap( 0, icon() );
2480 YACSGui_ComponentViewItem::YACSGui_ComponentViewItem( QListViewItem* theParent,
2481 QListViewItem* theAfter,
2482 YACS::HMI::SubjectComponent* theSComponent ):
2483 YACSGui_ViewItem( theParent, theAfter ),
2484 mySComponent( theSComponent )
2488 mySComponent->attach(this);
2490 QString anInstName = instanceName();
2491 if ( !anInstName.isEmpty() )
2492 setText( 0, anInstName );
2493 setPixmap( 0, icon() );
2497 YACSGui_ComponentViewItem::~YACSGui_ComponentViewItem()
2499 if ( mySComponent ) mySComponent->detach(this);
2502 void YACSGui_ComponentViewItem::update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
2504 //printf(">> YACSGui_ComponentViewItem::update\n");
2505 DEBTRACE(">> YACSGui_ComponentViewItem::update\n");
2522 GuiObserver::update(event, type, son);
2526 QString YACSGui_ComponentViewItem::name() const
2528 return instanceName();
2531 QString YACSGui_ComponentViewItem::instanceName() const
2533 QString instName ="";
2535 instName = mySComponent->getComponent()->getInstanceName();
2539 QPixmap YACSGui_ComponentViewItem::icon() const
2543 if ( getComponent() )
2544 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", QObject::tr("ICON_COMPONENT_OBJECT"));
2549 YACS::ENGINE::ComponentInstance* YACSGui_ComponentViewItem::getComponent() const
2551 return ( mySComponent ? mySComponent->getComponent() : 0 );
2554 void YACSGui_ComponentViewItem::update( const bool theMove )
2558 // find the container view item under which this component is published now
2559 YACSGui_ContainerViewItem* aCont = 0;
2560 QListViewItem* aParent = parent();
2563 if ( aCont = dynamic_cast<YACSGui_ContainerViewItem*>(aParent) )
2565 aParent = aParent->parent();
2568 if ( aCont ) aCont->update(this);
2571 setText( 0, name() ); // only rename
2574 void YACSGui_ComponentViewItem::move( YACS::HMI::Subject* theSReference )
2576 //printf( "YACSGui_ComponentViewItem::move %s\n", theSReference->getName().c_str() );
2578 SubjectServiceNode* aSServiceNode = dynamic_cast<SubjectServiceNode*>( theSReference );
2582 ServiceNode* aServiceNode = dynamic_cast<ServiceNode*>( aSServiceNode->getNode() );
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;
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 )
2595 //printf( "ContainerViewItem - %s\n", aChildContainer->text(0).latin1() );
2596 if( YACSGui_ContainerViewItem* aChildContItem = dynamic_cast<YACSGui_ContainerViewItem*>(aChildContainer) )
2598 QListViewItem* aChildComponent = aChildContItem->firstChild();
2599 while( aChildComponent )
2601 //printf( " ComponentViewItem - %s\n", aChildComponent->text(0).latin1() );
2602 if( YACSGui_ComponentViewItem* aChildCompItem = dynamic_cast<YACSGui_ComponentViewItem*>(aChildComponent) )
2604 QListViewItem* aChildReference = aChildCompItem->firstChild();
2605 while( aChildReference )
2607 //printf( " ReferenceViewItem - %s\n", aChildReference->text(0).latin1() );
2608 if( YACSGui_ReferenceViewItem* aChildRefItem = dynamic_cast<YACSGui_ReferenceViewItem*>(aChildReference) )
2610 if( !aReference && aChildRefItem->getNode() == aServiceNode )
2611 aReference = aChildRefItem;
2613 aChildReference = aChildReference->nextSibling();
2616 if( !aComponent && aChildCompItem->getComponent() == aServiceNode->getComponent() )
2617 aComponent = aChildCompItem;
2619 aChildComponent = aChildComponent->nextSibling();
2622 aChildContainer = aChildContainer->nextSibling();
2625 //printf( "Reference - %s\n", aReference->name().latin1() );
2626 takeItem( aReference );
2628 aComponent->insertItem( aReference );
2632 /* ================ items for tree view in run mode ================ */
2634 // YACSGui_ComposedNodeViewItem class:
2636 YACSGui_ComposedNodeViewItem::YACSGui_ComposedNodeViewItem(QListView *parent,
2638 YACS::ENGINE::ComposedNode *node)
2639 : YACSGui_ViewItem(parent, 0),
2642 setText( 0, label );
2645 setPixmap( 0, icon() );
2648 YACS::HMI::Subject* aSub = getSubject();
2650 aSub->attach( this );
2653 YACSGui_ComposedNodeViewItem::YACSGui_ComposedNodeViewItem(QListViewItem *parent,
2655 YACS::ENGINE::ComposedNode *node)
2656 : YACSGui_ViewItem(parent, 0),
2659 setText( 0, label );
2664 YACS::HMI::Subject* aSub = getSubject();
2666 aSub->attach( this );
2669 YACSGui_ComposedNodeViewItem::~YACSGui_ComposedNodeViewItem()
2672 YACS::HMI::Subject* aSub = getSubject();
2674 aSub->detach( this );
2677 YACS::HMI::Subject* YACSGui_ComposedNodeViewItem::getSubject() const
2679 YACS::HMI::Subject* aSub = 0;
2683 GuiContext* aContext = GuiContext::getCurrent();
2686 if ( aContext->_mapOfSubjectNode.find( _node ) != aContext->_mapOfSubjectNode.end() )
2687 aSub = aContext->_mapOfSubjectNode[ _node ];
2694 void YACSGui_ComposedNodeViewItem::paintCell( QPainter *p, const QColorGroup &cg,
2695 int column, int w, int alignment )
2697 //MESSAGE("ComposedNodeViewItem::paintCell " << column);
2698 QColorGroup _cg( cg );
2699 QColor c = _cg.text();
2702 _cg.setColor( QColorGroup::Text, _cf );
2703 if ( dynamic_cast<Proc*>(getNode()) )
2704 _cg.setColor( QColorGroup::Background, statusBgColor() );
2707 p->fillRect( 0, 0, w, height(), cg.brush( QColorGroup::Base ) );
2710 if ( listView() && !listView()->allColumnsShowFocus() )
2711 W = width( p->fontMetrics(), listView(), column );
2713 QListViewItem::paintCell( p, _cg, column, W<w ? W : w, alignment );
2715 if (column == 1) _cg.setColor( QColorGroup::Text, c );
2718 QColor YACSGui_ComposedNodeViewItem::statusBgColor() const
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);
2735 void YACSGui_ComposedNodeViewItem::setState(int state)
2737 //MESSAGE("ComposedNodeViewItem::setState: " << state);
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();
2762 void YACSGui_ComposedNodeViewItem::setStatus(int status)
2764 if ( dynamic_cast<Proc*>(getNode()) ) // this veiw item is a schema (root) view item
2766 QString aStatus("");
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";
2785 QPixmap YACSGui_ComposedNodeViewItem::icon() const
2789 QString anIconName = QString(QObject::tr("ICON_SCHEMA_OBJECT"));
2790 if ( !anIconName.isEmpty() )
2791 aRes = SUIT_Session::session()->resourceMgr()->loadPixmap("YACS", anIconName, false);
2796 void YACSGui_ComposedNodeViewItem::update( const bool theIsRecursive )
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()) );
2804 { // this is a composed node
2810 void YACSGui_ComposedNodeViewItem::popup(YACSGui_Executor* anExecutor,const QPoint & point)
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);
2819 int id=menu.exec(point);
2822 std::string msg = anExecutor->getErrorDetails(getNode());
2823 LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
2824 log->setCaption("Error Details");
2829 std::string msg = anExecutor->getErrorReport(getNode());
2830 LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
2831 log->setCaption("Error Report");
2836 std::string msg = anExecutor->getContainerLog();
2838 LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
2840 log->setCaption("Schema container log");
2845 // YACSGui_ElementaryNodeViewItem class:
2847 YACSGui_ElementaryNodeViewItem::YACSGui_ElementaryNodeViewItem(QListView *parent,
2848 const QString &text,
2850 YACS::ENGINE::ElementaryNode *node)
2852 QCheckListItem(parent, text, tt),
2853 myBlockSelect( false )
2859 YACS::HMI::Subject* aSub = getSubject();
2861 aSub->attach( this );
2864 YACSGui_ElementaryNodeViewItem::YACSGui_ElementaryNodeViewItem(QListViewItem *parent,
2865 const QString &text,
2867 YACS::ENGINE::ElementaryNode *node)
2868 : QCheckListItem(parent, text, tt),
2869 myBlockSelect( false )
2875 YACS::HMI::Subject* aSub = getSubject();
2877 aSub->attach( this );
2880 YACSGui_ElementaryNodeViewItem::~YACSGui_ElementaryNodeViewItem()
2883 YACS::HMI::Subject* aSub = getSubject();
2885 aSub->detach( this );
2888 YACS::HMI::Subject* YACSGui_ElementaryNodeViewItem::getSubject() const
2890 YACS::HMI::Subject* aSub = 0;
2894 GuiContext* aContext = GuiContext::getCurrent();
2897 if ( aContext->_mapOfSubjectNode.find( _node ) != aContext->_mapOfSubjectNode.end() )
2898 aSub = aContext->_mapOfSubjectNode[ _node ];
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
2912 bool YACSGui_ElementaryNodeViewItem::blockSelection( const bool toBlock )
2914 bool prevVal = myBlockSelect;
2915 myBlockSelect = toBlock;
2920 \brief Verifiee whether actions performed in select() method are blocked
2921 (see blockSelection method for more dscription)
2922 \return blocking value
2924 bool YACSGui_ElementaryNodeViewItem::selectionBlocked() const
2926 return myBlockSelect;
2930 \brief Selects item in tree view
2931 \param isSelected specifies whether item has to be selected
2933 void YACSGui_ElementaryNodeViewItem::select( bool isSelected )
2935 if ( selectionBlocked() )
2938 //printf(">> YACSGui_ViewItem::select( %d ) \n", isSelected );
2940 if ( !isSelected ) // do nothing
2943 // select item in tree view
2944 QListView* aListView = listView();
2948 blockSelection( true );
2949 aListView->clearSelection();
2950 aListView->setCurrentItem( this );
2951 aListView->setSelected( this, true );
2952 aListView->ensureItemVisible( this );
2953 blockSelection( false );
2956 void YACSGui_ElementaryNodeViewItem::paintCell( QPainter *p, const QColorGroup &cg,
2957 int column, int width, int alignment )
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 );
2966 void YACSGui_ElementaryNodeViewItem::setState(int state)
2968 //MESSAGE("ElementaryNodeViewItem::setState: " << state);
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();
2993 void YACSGui_ElementaryNodeViewItem::update( const bool theIsRecursive )
2999 void YACSGui_ElementaryNodeViewItem::popup(YACSGui_Executor* anExecutor,const QPoint & point)
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);
3008 std::string msg = anExecutor->getErrorDetails(getNode());
3009 LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
3010 log->setCaption("Error Details");
3015 std::string msg = anExecutor->getErrorReport(getNode());
3016 LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
3017 log->setCaption("Error Report");
3023 std::string file = anExecutor->getContainerLog(getNode());
3028 msg="This node has no container";
3029 LogViewer* log=new LogViewer(msg,listView(),"dialog",WDestructiveClose);
3030 log->setCaption("Node container log");
3032 log->readFile(file);