Salome HOME
NRI : Temporary modification for reading catalog of modules.
[modules/kernel.git] / src / SALOMEGUI / SALOMEGUI_Desktop.cxx
1 using namespace std;
2 //  File      : SALOMEGUI_Desktop.cxx
3 //  Created   : Thu Jun 14 12:02:58 2001
4 //  Author    : Nicolas REJNERI
5 //  Project   : SALOME
6 //  Module    : SALOMEGUI
7 //  Copyright : Open CASCADE
8 //  $Header$
9
10 #include "SALOMEGUI_Desktop.h"
11 #include "SALOME_Selection.h"
12 #include "SALOME_ListIteratorOfListIO.hxx"
13
14 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
15
16 /*!
17     Constructor 
18 */
19 SALOMEGUI_Desktop::SALOMEGUI_Desktop(SALOME_NamingService* name_service) :
20   QAD_Desktop( name_service )
21 {
22   QAD_ASSERT_DEBUG_ONLY( !myStdActions.isEmpty() );
23   //myStdActions.at( FileOpenId )->setEnabled( true );
24   //myStdActions.at( FileSaveId )->setEnabled( true );
25   //myStdActions.at( FileSaveAsId )->setEnabled( true );
26 }
27
28 /*!
29     Disable file actions for DEMO 
30 */
31 void SALOMEGUI_Desktop::updateDesktop( UpdateCommand  cmd )
32 {
33   QAD_Desktop::updateDesktop( cmd  );
34   
35   QAD_ASSERT_DEBUG_ONLY( !myStdActions.isEmpty() );
36   //myStdActions.at( FileOpenId )->setEnabled( true );
37   //myStdActions.at( FileSaveId )->setEnabled( true );
38   //myStdActions.at( FileSaveAsId )->setEnabled( true );
39 }
40
41 QString SALOMEGUI_Desktop::getComponentFromSelection()
42 {
43   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
44   /* copy the list */
45   SALOME_ListIO List;
46   SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
47   for (; Itinit.More(); Itinit.Next()) {
48     List.Append(Itinit.Value());
49   }
50   
51   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
52
53   SALOME_ListIteratorOfListIO It( List );
54   QString parentComp;
55
56   for (; It.More(); It.Next()) {
57     Handle(SALOME_InteractiveObject) IObject = It.Value();
58
59     if (!IObject->hasEntry()) continue;
60
61     SALOMEDS::SObject_var  obj = aStudy->FindObjectID( IObject->getEntry() );
62     
63     if ( !obj->_is_nil() ) {
64       SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
65       if ( !comp->_is_nil() ) {
66         SALOMEDS::GenericAttribute_var anAttr;
67         SALOMEDS::AttributeName_var    aName;
68         if (comp->FindAttribute(anAttr, "AttributeName")) {
69           aName = SALOMEDS::AttributeName::_narrow(anAttr);
70           QString compName(aName->Value());
71           if (parentComp.isNull())
72             parentComp = compName;
73           else if (parentComp.compare(compName) != 0) { // objects belonging to different components are selected
74             parentComp = QString::null;
75             break;
76           }
77         }
78       }
79     }
80   }
81
82   return parentComp;
83 }