Salome HOME
NRI : Add message (GUI lib not found).
[modules/kernel.git] / src / SALOMEGUI / SALOMEGUI_Swig.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SALOMEGUI_Swig.cxx
4 // Created   : ven oct 12 15:44:16 CEST 2001
5 // Author    : Paul RASCLE, EDF
6 // Project   : SALOME
7 // Copyright : EDF 2001
8
9 // Modified  : Mon Jul 29 21:38:07 2002
10 // Author    : Nicolas REJNERI
11 // Copyright : OPEN CASCADE 2002
12 // $Header$
13 //=============================================================================
14
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "QAD_Study.h"
18 #include "QAD_RightFrame.h"
19 #include "QAD_StudyFrame.h"
20 #include "SALOMEGUI_Swig.hxx"
21 #include "utilities.h"
22
23 #include "SALOME_Selection.h"
24 #include "SALOME_InteractiveObject.hxx"
25 #include "SALOME_ListIteratorOfListIO.hxx"
26
27
28 /*!
29   Constructor
30 */
31 SALOMEGUI_Swig::SALOMEGUI_Swig(): _studyId(0)
32 {
33   //  MESSAGE("Constructeur");
34 }
35
36 /*!
37   Destructor
38 */
39 SALOMEGUI_Swig::~SALOMEGUI_Swig()
40 {
41   //  MESSAGE("Destructeur");
42 }
43
44 /*!
45   Call when updated object browser.
46 */
47 void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection )
48 {
49   QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
50   myActiveStudy->updateObjBrowser( updateSelection );
51 }
52
53 /*!
54   Returns active Study Id.
55 */
56 int SALOMEGUI_Swig::getActiveStudyId()
57 {
58   // NRI 24-02-03 :
59   //  if (_studyId ==0)
60   //    {
61   //  QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
62   //  _name = myStudy->getTitle();
63   _studyId = QAD_Application::getDesktop()->getActiveStudy()->getStudyId();
64   SCRUTE(_studyId);
65   //    }
66   return _studyId;
67 }
68
69 /*!
70   Returns active Study Name.
71 */
72 const char *SALOMEGUI_Swig::getActiveStudyName()
73 {
74   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
75   _name = myStudy->getTitle();
76   // NRI 24-02-03 :
77   //if (_studyId ==0) 
78   //  getActiveStudyId();
79   return _name.latin1();
80 }
81
82 /*!
83   Returns the name of component.
84 */
85 const char* SALOMEGUI_Swig::getComponentName( const char* ComponentUserName )
86 {
87   return QAD_Application::getDesktop()->getComponentName( ComponentUserName );
88 }
89 /*!
90   Returns the user name of component.
91 */
92 const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName )
93 {
94   return QAD_Application::getDesktop()->getComponentUserName( ComponentName );
95 }
96
97 /*!
98   Returns the number of selected objects.
99 */
100 int SALOMEGUI_Swig::SelectedCount()
101 {
102   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
103   SALOME_Selection* Sel
104     = SALOME_Selection::Selection( myStudy->getSelection() );
105   return Sel->IObjectCount();
106 }
107
108 /*!
109   Returns the selected object at index i.
110 */
111 const char* SALOMEGUI_Swig::getSelected(int i)
112 {
113   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
114   SALOME_Selection* Sel
115     = SALOME_Selection::Selection( myStudy->getSelection() );
116   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
117   int index = 0;
118   for(;It.More();It.Next())
119     {
120       Handle(SALOME_InteractiveObject) IObject = It.Value();
121       if ( i == index++ )
122         {
123           if ( IObject->hasEntry() )
124             return IObject->getEntry();
125         }
126     }
127   return "";
128 }
129
130 /*!
131   Add object with Entry into selection.
132 */
133 void SALOMEGUI_Swig::AddIObject(const char *Entry)
134 {
135   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
136   SALOME_Selection* Sel
137     = SALOME_Selection::Selection( myStudy->getSelection() );
138
139   if ( !SALOMEGUI_Swig::IsInCurrentView( Entry ) )
140     return;
141   
142   Handle(SALOME_InteractiveObject) IO = 
143     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
144   Sel->AddIObject( IO );
145 }
146
147
148 /*!
149   Removes object with Entry into selection.
150 */
151 void SALOMEGUI_Swig::RemoveIObject(const char *Entry)
152 {
153   QAD_Study* myStudy
154     = QAD_Application::getDesktop()->getActiveStudy();
155   SALOME_Selection* Sel
156     = SALOME_Selection::Selection( myStudy->getSelection() );
157
158   if ( !SALOMEGUI_Swig::IsInCurrentView( Entry ) )
159     return;
160
161   Handle(SALOME_InteractiveObject) IO = 
162     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
163   Sel->RemoveIObject( IO );
164 }
165
166
167 /*!
168   Removes all objects into selection.
169 */
170 void SALOMEGUI_Swig::ClearIObjects()
171 {
172   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
173   SALOME_Selection* Sel
174     = SALOME_Selection::Selection( myStudy->getSelection() );
175   Sel->ClearIObjects();
176 }
177
178 /*!
179   Display
180 */              
181 void SALOMEGUI_Swig::Display(const char *Entry)
182 {
183   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
184
185   if ( !SALOMEGUI_Swig::IsInCurrentView( Entry ) )
186     return;
187
188   Handle(SALOME_InteractiveObject) IO = 
189     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
190
191   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Display(IO);
192 }
193
194 /*!
195   Display only
196 */
197 void SALOMEGUI_Swig::DisplayOnly(const char *Entry)
198 {
199   if ( !SALOMEGUI_Swig::IsInCurrentView( Entry ) )
200     return;
201
202   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
203
204   Handle(SALOME_InteractiveObject) IO = 
205     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
206
207   if ( !IO.IsNull() ) {
208     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->DisplayOnly(IO);
209   }
210 }
211
212 /*!
213   Erase
214 */
215 void SALOMEGUI_Swig::Erase(const char *Entry)
216 {
217   if ( !SALOMEGUI_Swig::IsInCurrentView( Entry ) )
218     return;
219
220   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
221
222   Handle(SALOME_InteractiveObject) IO = 
223     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
224
225   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Erase(IO);
226 }
227
228 /*!
229   Display all
230 */
231 void SALOMEGUI_Swig::DisplayAll()
232 {
233   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
234   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->DisplayAll();
235 }
236
237 /*!
238   Erse only
239 */
240 void SALOMEGUI_Swig::EraseAll()
241 {
242   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
243   SALOME_Selection* Sel 
244     = SALOME_Selection::Selection( myStudy->getSelection() );
245   
246   Sel->ClearIObjects();
247   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->EraseAll();
248 }
249
250 /*!
251   Check
252 */
253 bool SALOMEGUI_Swig::IsInCurrentView(const char *Entry)
254 {
255   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
256   return myStudy->isInViewer( Entry, myStudy->getActiveStudyFrame()->entry() );
257 }
258
259 vtkRenderer *SALOMEGUI_Swig::getRenderer(int viewId)
260 {
261   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
262   int nbStudyFrames = myStudy->getStudyFramesCount();
263   vtkRenderer *myRenderer = NULL;
264   if (viewId == -1) // find the first frame with VTK viewer & get renderer
265     {
266       int i=0;
267       for(i=0; i<nbStudyFrames; i++)
268         {
269           if ( myStudy->getStudyFrame(i)->getTypeView() == VIEW_VTK )
270             {
271               myRenderer = myStudy->getStudyFrame(i)->getRightFrame()->getViewFrame()->getRenderer();
272               break;
273             }
274         }
275     }
276   else     // get the VTK renderer of a given frame
277     {
278       SCRUTE(viewId);
279       if ((viewId >=0) && (viewId <nbStudyFrames))
280         myRenderer = myStudy->getStudyFrame(viewId)->getRightFrame()->getViewFrame()->getRenderer();
281     }
282   if (myRenderer == NULL) INFOS("No VTK Renderer available !");
283   return myRenderer;
284 }