Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / SALOMEGUI / SALOMEGUI_Desktop.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEGUI_Desktop.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "SALOMEGUI_Desktop.h"
31 #include "SALOME_Selection.h"
32 #include "SALOME_ListIteratorOfListIO.hxx"
33
34 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
35
36 /*!
37     Constructor 
38 */
39 SALOMEGUI_Desktop::SALOMEGUI_Desktop(SALOME_NamingService* name_service) :
40   QAD_Desktop( name_service )
41 {
42   QAD_ASSERT_DEBUG_ONLY( !myStdActions.isEmpty() );
43   //myStdActions.at( FileOpenId )->setEnabled( true );
44   //myStdActions.at( FileSaveId )->setEnabled( true );
45   //myStdActions.at( FileSaveAsId )->setEnabled( true );
46 }
47
48 /*!
49     Disable file actions for DEMO 
50 */
51 void SALOMEGUI_Desktop::updateDesktop( UpdateCommand  cmd )
52 {
53   QAD_Desktop::updateDesktop( cmd  );
54   
55   QAD_ASSERT_DEBUG_ONLY( !myStdActions.isEmpty() );
56   //myStdActions.at( FileOpenId )->setEnabled( true );
57   //myStdActions.at( FileSaveId )->setEnabled( true );
58   //myStdActions.at( FileSaveAsId )->setEnabled( true );
59 }
60
61 QString SALOMEGUI_Desktop::getComponentFromSelection()
62 {
63   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
64   /* copy the list */
65   SALOME_ListIO List;
66   SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
67   for (; Itinit.More(); Itinit.Next()) {
68     List.Append(Itinit.Value());
69   }
70   
71   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
72
73   SALOME_ListIteratorOfListIO It( List );
74   QString parentComp;
75
76   for (; It.More(); It.Next()) {
77     Handle(SALOME_InteractiveObject) IObject = It.Value();
78
79     if (!IObject->hasEntry()) continue;
80
81     SALOMEDS::SObject_var  obj = aStudy->FindObjectID( IObject->getEntry() );
82     
83     if ( !obj->_is_nil() ) {
84       SALOMEDS::SComponent_var comp = obj->GetFatherComponent();
85       if ( !comp->_is_nil() ) {
86         SALOMEDS::GenericAttribute_var anAttr;
87         SALOMEDS::AttributeName_var    aName;
88         if (comp->FindAttribute(anAttr, "AttributeName")) {
89           aName = SALOMEDS::AttributeName::_narrow(anAttr);
90           QString compName(aName->Value());
91           if (parentComp.isNull())
92             parentComp = compName;
93           else if (parentComp.compare(compName) != 0) { // objects belonging to different components are selected
94             parentComp = QString::null;
95             break;
96           }
97         }
98       }
99     }
100   }
101
102   return parentComp;
103 }