]> SALOME platform Git repositories - modules/gui.git/blob - src/SOCC/SOCC_ViewModel.cxx
Salome HOME
Copyrights update
[modules/gui.git] / src / SOCC / SOCC_ViewModel.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 #include "SOCC_ViewModel.h"\r
20 \r
21 #include "SOCC_Prs.h"\r
22 #include "SOCC_ViewWindow.h"\r
23 \r
24 #include "SUIT_Session.h"\r
25 #include "SUIT_Application.h"\r
26 \r
27 //#include "ToolsGUI.h"\r
28 \r
29 // Temporarily commented to avoid awful dependecy on SALOMEDS\r
30 // TODO: better mechanism of storing display/erse status in a study\r
31 // should be provided...\r
32 //#include <SALOMEconfig.h>\r
33 //#include CORBA_CLIENT_HEADER(SALOMEDS)\r
34 \r
35 #include <AIS_ListIteratorOfListOfInteractive.hxx>\r
36 #include <Visual3d_View.hxx>\r
37 \r
38 #include <SALOME_AISShape.hxx>\r
39 #include <SALOME_AISObject.hxx>\r
40 \r
41 // Temporarily commented to avoid awful dependecy on SALOMEDS\r
42 // TODO: better mechanism of storing display/erse status in a study\r
43 // should be provided...\r
44 //#include <Utils_ORB_INIT.hxx>\r
45 //#include <Utils_SINGLETON.hxx>\r
46 //#include <SALOME_ModuleCatalog_impl.hxx>\r
47 //#include <SALOME_NamingService.hxx>\r
48 \r
49 //#include "SALOMEDSClient.hxx"\r
50 //#include "SALOMEDS_StudyManager.hxx"\r
51 \r
52 #include <AIS_TypeOfIso.hxx>\r
53 \r
54 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.\r
55 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from \r
56 // SALOMEDS::StudyManager - no linkage with SalomeApp. \r
57 \r
58 // Temporarily commented to avoid awful dependecy on SALOMEDS\r
59 // TODO: better mechanism of storing display/erse status in a study\r
60 // should be provided...\r
61 //static _PTR(Study) getStudyDS() \r
62 //{\r
63 //  SALOMEDSClient_Study* aStudy = NULL;\r
64 //  _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );\r
65 \r
66   // get id of SUIT_Study, if it's a SalomeApp_Study, it will return\r
67   //    id of its underlying SALOMEDS::Study\r
68 //  SUIT_Application* app = SUIT_Session::session()->activeApplication();\r
69 //  if ( !app )  return _PTR(Study)(aStudy); \r
70 //  SUIT_Study* stud = app->activeStudy();\r
71 //  if ( !stud ) return _PTR(Study)(aStudy);  \r
72 //  const int id = stud->id(); // virtual method, must return SALOMEDS_Study id\r
73   // get SALOMEDS_Study with this id from StudyMgr\r
74 //  return aMgr->GetStudyByID( id );\r
75 //}\r
76 \r
77 SOCC_Viewer::SOCC_Viewer( bool DisplayTrihedron )\r
78 : OCCViewer_Viewer( DisplayTrihedron )\r
79 {\r
80 }\r
81 \r
82 SOCC_Viewer::~SOCC_Viewer()\r
83 {\r
84 }\r
85 \r
86 bool SOCC_Viewer::highlight( const Handle(SALOME_InteractiveObject)& obj,\r
87                              bool hilight, bool upd )\r
88 {\r
89   bool isInLocal = getAISContext()->HasOpenedContext();\r
90   //SUIT_Study* ActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();\r
91   //SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );\r
92 \r
93   AIS_ListOfInteractive List;\r
94   getAISContext()->DisplayedObjects(List);\r
95   \r
96   AIS_ListIteratorOfListOfInteractive ite(List);\r
97   for ( ; ite.More(); ite.Next() )\r
98   {\r
99     Handle(SALOME_InteractiveObject) anObj =\r
100       Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );\r
101 \r
102     if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )\r
103     {\r
104       if ( !isInLocal )\r
105           OCCViewer_Viewer::highlight( ite.Value(), hilight, false );\r
106       // highlight subshapes only when local selection is active\r
107       else\r
108       {\r
109         /*if ( ite.Value()->IsKind( STANDARD_TYPE( SALOME_AISShape ) ) )\r
110         {\r
111           Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast( ite.Value() );\r
112           TColStd_IndexedMapOfInteger MapIndex;\r
113           Sel->GetIndex( IObject, MapIndex );\r
114           aSh->highlightSubShapes( MapIndex, highlight );\r
115         }*/\r
116       }\r
117       break;\r
118     }\r
119   }\r
120     \r
121   if( upd )\r
122     update();\r
123     \r
124   return false;\r
125 }\r
126 \r
127 bool SOCC_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& obj,\r
128                               bool onlyInViewer )\r
129 {\r
130   AIS_ListOfInteractive List;\r
131   getAISContext()->DisplayedObjects(List);\r
132 \r
133   if( !onlyInViewer ) {\r
134     AIS_ListOfInteractive List1;\r
135     getAISContext()->ObjectsInCollector(List1);\r
136     List.Append(List1);\r
137   }\r
138 \r
139   AIS_ListIteratorOfListOfInteractive ite(List);\r
140   for ( ; ite.More(); ite.Next() )\r
141   {\r
142     Handle(SALOME_InteractiveObject) anObj =\r
143         Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );\r
144 \r
145     if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )\r
146       return true;\r
147   }\r
148   return false;\r
149 }\r
150 \r
151 bool SOCC_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& obj )\r
152 {\r
153   AIS_ListOfInteractive List;\r
154   getAISContext()->DisplayedObjects( List );\r
155 \r
156   AIS_ListIteratorOfListOfInteractive ite( List );\r
157   for ( ; ite.More(); ite.Next() )\r
158   {\r
159     Handle(SALOME_InteractiveObject) anObj =\r
160       Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );\r
161 \r
162     if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )\r
163       return getAISContext()->IsDisplayed( ite.Value() );\r
164   }\r
165   \r
166   return false;\r
167 }\r
168 \r
169 void SOCC_Viewer::setColor( const Handle(SALOME_InteractiveObject)& obj,\r
170                             const QColor& color, bool update )\r
171 {\r
172   AIS_ListOfInteractive List;\r
173   getAISContext()->DisplayedObjects(List);\r
174   \r
175   AIS_ListIteratorOfListOfInteractive ite(List);\r
176   for ( ; ite.More(); ite.Next() )\r
177   {\r
178     Handle(SALOME_InteractiveObject) anObj =\r
179         Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );\r
180 \r
181     if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )\r
182     {\r
183       OCCViewer_Viewer::setColor( ite.Value(), color, update );\r
184       return;\r
185     }\r
186   }\r
187 }\r
188 \r
189 void SOCC_Viewer::switchRepresentation( const Handle(SALOME_InteractiveObject)& obj,\r
190                                         int mode, bool update )\r
191 {\r
192   AIS_ListOfInteractive List;\r
193   getAISContext()->DisplayedObjects(List);\r
194   \r
195   AIS_ListIteratorOfListOfInteractive ite(List);\r
196   for ( ; ite.More(); ite.Next() )\r
197   {\r
198     Handle(SALOME_InteractiveObject) anObj =\r
199         Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );\r
200 \r
201     if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )\r
202     {\r
203       OCCViewer_Viewer::switchRepresentation( ite.Value(), mode, update );\r
204       return;\r
205     }\r
206   }\r
207 }\r
208 \r
209 void SOCC_Viewer::setTransparency( const Handle(SALOME_InteractiveObject)& obj,\r
210                                    float trans, bool update )\r
211 {\r
212   AIS_ListOfInteractive List;\r
213   getAISContext()->DisplayedObjects( List );\r
214   \r
215   AIS_ListIteratorOfListOfInteractive ite( List );\r
216   for ( ; ite.More(); ite.Next() )\r
217   {\r
218     Handle(SALOME_InteractiveObject) anObj =\r
219         Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );\r
220 \r
221     if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )\r
222     {\r
223       OCCViewer_Viewer::setTransparency( ite.Value(), trans, update );\r
224       return;\r
225     }\r
226   }\r
227 }\r
228 \r
229 void SOCC_Viewer::rename( const Handle(SALOME_InteractiveObject)& obj,\r
230                           const QString& name )\r
231 {\r
232   AIS_ListOfInteractive List;\r
233   getAISContext()->DisplayedObjects(List);\r
234   \r
235   AIS_ListIteratorOfListOfInteractive ite(List);\r
236   while (ite.More())\r
237   {\r
238     if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape)))\r
239     {\r
240       Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite.Value());\r
241       \r
242       if ( aSh->hasIO() )\r
243       {\r
244         Handle(SALOME_InteractiveObject) IO = aSh->getIO();\r
245         if ( IO->isSame( obj ) )\r
246         {\r
247           aSh->setName( (char*)name.latin1() );\r
248           break;\r
249         }\r
250       }\r
251     }\r
252     else if ( ite.Value()->IsKind( STANDARD_TYPE( SALOME_AISObject ) ) )\r
253     {\r
254       Handle(SALOME_AISObject) aSh = Handle(SALOME_AISObject)::DownCast( ite.Value() );\r
255 \r
256       // Add code here, if someone create a MODULE_AISObject.\r
257     }\r
258     ite.Next();\r
259   }\r
260 }\r
261 \r
262 //=======================================================================\r
263 // name    : Display\r
264 // Purpose : Display presentation\r
265 //=======================================================================\r
266 void SOCC_Viewer::Display( const SALOME_OCCPrs* prs )\r
267 {\r
268   // try do downcast object\r
269   const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( prs );\r
270   if ( !anOCCPrs || anOCCPrs->IsNull() )\r
271     return;\r
272 \r
273   // get SALOMEDS Study\r
274   // Temporarily commented to avoid awful dependecy on SALOMEDS\r
275   // TODO: better mechanism of storing display/erse status in a study\r
276   // should be provided...\r
277   //  _PTR(Study) study(getStudyDS());\r
278 \r
279   // get context\r
280   Handle (AIS_InteractiveContext) ic = getAISContext();\r
281 \r
282   // get all displayed objects\r
283   AIS_ListOfInteractive List;\r
284   ic->DisplayedObjects( List );\r
285   // get objects in the collector\r
286   AIS_ListOfInteractive ListCollector;\r
287   ic->ObjectsInCollector( ListCollector );\r
288 \r
289   // get objects to be displayed\r
290   AIS_ListOfInteractive anAISObjects;\r
291   anOCCPrs->GetObjects( anAISObjects );\r
292 \r
293   AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );\r
294   for ( ; aIter.More(); aIter.Next() )\r
295   {\r
296     Handle(AIS_InteractiveObject) anAIS = aIter.Value();\r
297     if ( !anAIS.IsNull() )\r
298     {\r
299       // try to find presentation in the viewer\r
300       bool bDisplayed = false;\r
301       AIS_ListIteratorOfListOfInteractive ite( List );\r
302       for ( ; ite.More(); ite.Next() )\r
303       {\r
304         // compare presentations by handles\r
305         // if the object is already displayed - nothing to do more\r
306         if ( ite.Value() == anAIS )\r
307         {\r
308           // Deactivate object if necessary\r
309           if ( !anOCCPrs->ToActivate() )\r
310             ic->Deactivate( anAIS );\r
311           bDisplayed = true;\r
312           break;\r
313         }\r
314       }\r
315 \r
316       if ( bDisplayed )\r
317         continue;\r
318 \r
319       // then try to find presentation in the collector\r
320       bDisplayed = false;\r
321       ite.Initialize( ListCollector );\r
322       for ( ; ite.More(); ite.Next() )\r
323       {\r
324         // compare presentations by handles\r
325         // if the object is in collector - display it\r
326         if ( ite.Value() == anAIS )\r
327         {\r
328           ic->DisplayFromCollector( anAIS, false );\r
329 \r
330           // Deactivate object if necessary\r
331           if ( !anOCCPrs->ToActivate() )\r
332             ic->Deactivate( anAIS );\r
333           bDisplayed = true;\r
334 \r
335           // Set visibility flag\r
336           // Temporarily commented to avoid awful dependecy on SALOMEDS\r
337           // TODO: better mechanism of storing display/erse status in a study\r
338           // should be provided...\r
339           //Handle(SALOME_InteractiveObject) anObj =\r
340           //  Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );\r
341           //if ( !anObj.IsNull() && anObj->hasEntry() )\r
342           //{\r
343           //  if ( study )\r
344           //    ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );\r
345           //}\r
346           break;\r
347         }\r
348       }\r
349       if ( bDisplayed )\r
350         continue;\r
351 \r
352       // if object is not displayed and not found in the collector - display it\r
353       if ( anAIS->IsKind( STANDARD_TYPE(AIS_Trihedron) ) )\r
354       {\r
355         Handle(AIS_Trihedron) aTrh = Handle(AIS_Trihedron)::DownCast( anAIS );\r
356         double aNewSize = 100, aSize = 100;\r
357         getTrihedronSize( aNewSize, aSize );\r
358         aTrh->SetSize( aTrh == getTrihedron() ? aNewSize : 0.5 * aNewSize );\r
359       }\r
360 \r
361       ic->Display( anAIS, false );\r
362 \r
363       // Set visibility flag\r
364       // Temporarily commented to avoid awful dependecy on SALOMEDS\r
365       // TODO: better mechanism of storing display/erse status in a study\r
366       // should be provided...\r
367       //Handle(SALOME_InteractiveObject) anObj =\r
368       //  Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );\r
369       //if ( !anObj.IsNull() && anObj->hasEntry() )\r
370       //{\r
371       //  if ( study  )\r
372       //    ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );\r
373       //}\r
374 \r
375       // Deactivate object if necessary\r
376       if ( !anOCCPrs->ToActivate() )\r
377         ic->Deactivate( anAIS );\r
378     }\r
379   }\r
380 }\r
381 \r
382 //=======================================================================\r
383 // name    : Erase\r
384 // Purpose : Erase presentation\r
385 //=======================================================================\r
386 void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool forced )\r
387 {\r
388   // try do downcast object\r
389   const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( prs );\r
390   if ( !anOCCPrs || anOCCPrs->IsNull() )\r
391     return;\r
392 \r
393   // get SALOMEDS Study\r
394   // Temporarily commented to avoid awful dependecy on SALOMEDS\r
395   // TODO: better mechanism of storing display/erse status in a study\r
396   // should be provided...\r
397   //  _PTR(Study) study(getStudyDS());\r
398 \r
399   // get context\r
400   Handle(AIS_InteractiveContext) ic = getAISContext();\r
401 \r
402   // get objects to be erased\r
403   AIS_ListOfInteractive anAISObjects;\r
404   anOCCPrs->GetObjects( anAISObjects );\r
405 \r
406   AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );\r
407   for ( ; aIter.More(); aIter.Next() ) {\r
408     Handle(AIS_InteractiveObject) anAIS = aIter.Value();\r
409     if ( !anAIS.IsNull() ) {\r
410       // erase the object from context : move it to collector\r
411       ic->Erase( anAIS, false, forced ? false : true );\r
412 \r
413       // Set visibility flag if necessary\r
414       // Temporarily commented to avoid awful dependecy on SALOMEDS\r
415       // TODO: better mechanism of storing display/erse status in a study\r
416       // should be provided...\r
417       //if ( !forced )\r
418       //{\r
419       //  Handle(SALOME_InteractiveObject) anObj =\r
420       //    Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );\r
421       //  if ( !anObj.IsNull() && anObj->hasEntry() )\r
422       //  {\r
423       //  if ( study )\r
424       //    ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );\r
425       //  }\r
426       //}\r
427     }\r
428   }\r
429 }\r
430 \r
431 //=======================================================================\r
432 // name    : EraseAll\r
433 // Purpose : Erase all presentations\r
434 //=======================================================================\r
435 void SOCC_Viewer::EraseAll( const bool forced )\r
436 {\r
437   // get SALOMEDS Study\r
438   // Temporarily commented to avoid awful dependecy on SALOMEDS\r
439   // TODO: better mechanism of storing display/erse status in a study\r
440   // should be provided...\r
441   //  _PTR(Study) study(getStudyDS());\r
442 \r
443   // get context\r
444   Handle(AIS_InteractiveContext) ic = getAISContext();\r
445 \r
446   // check if trihedron is displayed\r
447   Standard_Boolean isTrihedronDisplayed = ic->IsDisplayed( getTrihedron() );\r
448 \r
449   // get objects to be erased (all currently displayed objects)\r
450   AIS_ListOfInteractive aList;\r
451   ic->DisplayedObjects( aList );\r
452   AIS_ListIteratorOfListOfInteractive anIter( aList );\r
453   for ( ; anIter.More(); anIter.Next() ) {\r
454     if ( isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron ) )\r
455       continue;\r
456 \r
457     // erase an object\r
458     Handle(AIS_InteractiveObject) anIO = anIter.Value();\r
459     ic->Erase( anIO, false, forced ? false : true );\r
460     \r
461     // Set visibility flag if necessary\r
462     // Temporarily commented to avoid awful dependecy on SALOMEDS\r
463     // TODO: better mechanism of storing display/erse status in a study\r
464     // should be provided...\r
465     //if ( !forced ) {\r
466     //  Handle(SALOME_InteractiveObject) anObj =\r
467     //  Handle(SALOME_InteractiveObject)::DownCast( anIO->GetOwner() );\r
468 \r
469     //  if ( !anObj.IsNull() && anObj->hasEntry() ) {\r
470     //  if ( study )\r
471     //    ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );\r
472     //  }\r
473     //}\r
474   }\r
475 \r
476   // display trihedron if necessary\r
477   if ( isTrihedronDisplayed )\r
478     getAISContext()->Display( getTrihedron() );\r
479   else\r
480     Repaint();\r
481 }\r
482 \r
483 //=======================================================================\r
484 // name    : CreatePrs\r
485 // Purpose : Create presentation corresponding to the entry\r
486 //=======================================================================\r
487 SALOME_Prs* SOCC_Viewer::CreatePrs( const char* entry )\r
488 {\r
489   SOCC_Prs* prs = new SOCC_Prs();\r
490   if ( entry )\r
491   {\r
492     // get context\r
493     Handle(AIS_InteractiveContext) ic = getAISContext();\r
494 \r
495     // get displayed objects\r
496     AIS_ListOfInteractive List;\r
497     ic->DisplayedObjects( List );\r
498     // get objects in the collector\r
499     AIS_ListOfInteractive ListCollector;\r
500     ic->ObjectsInCollector( ListCollector );\r
501     List.Append( ListCollector );\r
502 \r
503     AIS_ListIteratorOfListOfInteractive ite( List );\r
504     for ( ; ite.More(); ite.Next() )\r
505     {\r
506       Handle(SALOME_InteractiveObject) anObj =\r
507         Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );\r
508 \r
509       if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), entry ) == 0 )\r
510         prs->AddObject( ite.Value() );\r
511     }\r
512   }\r
513   return prs;\r
514 }\r
515 \r
516 //=======================================================================\r
517 // name    : LocalSelection\r
518 // Purpose : Activates selection of sub shapes\r
519 //=======================================================================\r
520 void SOCC_Viewer::LocalSelection( const SALOME_OCCPrs* thePrs, const int theMode )\r
521 {\r
522   Handle(AIS_InteractiveContext) ic = getAISContext();\r
523   \r
524   const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( thePrs );\r
525   if ( ic.IsNull() )\r
526     return;\r
527   \r
528   // Open local context if there is no one\r
529   bool allObjects = thePrs == 0 || thePrs->IsNull();\r
530   if ( !ic->HasOpenedContext() ) {\r
531     ic->ClearCurrents( false );\r
532     ic->OpenLocalContext( allObjects, true, true );\r
533   }\r
534 \r
535   AIS_ListOfInteractive anObjs;\r
536   // Get objects to be activated\r
537   if ( allObjects ) \r
538     ic->DisplayedObjects( anObjs );\r
539   else\r
540     anOCCPrs->GetObjects( anObjs );\r
541 \r
542   // Activate selection of objects from prs\r
543   AIS_ListIteratorOfListOfInteractive aIter( anObjs );\r
544   for ( ; aIter.More(); aIter.Next() ) {\r
545     Handle(AIS_InteractiveObject) anAIS = aIter.Value();\r
546     if ( !anAIS.IsNull() )\r
547     {\r
548       if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )\r
549       {\r
550         ic->Load( anAIS, -1, false );\r
551         ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );\r
552       }\r
553       else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )\r
554       {\r
555         ic->Load( anAIS, -1, false );\r
556         ic->Activate( anAIS, theMode );\r
557       }\r
558     }\r
559   }\r
560 }\r
561 \r
562 //=======================================================================\r
563 // name    : GlobalSelection\r
564 // Purpose : Deactivates selection of sub shapes\r
565 //=======================================================================\r
566 void SOCC_Viewer::GlobalSelection( const bool update ) const\r
567 {\r
568   Handle(AIS_InteractiveContext) ic = getAISContext();\r
569   if ( !ic.IsNull() )\r
570   {\r
571     ic->CloseAllContexts( false );\r
572     if ( update )\r
573       ic->CurrentViewer()->Redraw();\r
574   }\r
575 }\r
576 \r
577 //=======================================================================\r
578 // name    : BeforeDisplay\r
579 // Purpose : Axiluary method called before displaying of objects\r
580 //=======================================================================\r
581 void  SOCC_Viewer::BeforeDisplay( SALOME_Displayer* d )\r
582 {\r
583   d->BeforeDisplay( this, SALOME_OCCViewType() );\r
584 }\r
585 \r
586 //=======================================================================\r
587 // name    : AfterDisplay\r
588 // Purpose : Axiluary method called after displaying of objects\r
589 //=======================================================================\r
590 void SOCC_Viewer::AfterDisplay( SALOME_Displayer* d )\r
591 {\r
592   d->AfterDisplay( this, SALOME_OCCViewType() );\r
593 }\r
594 \r
595 //=======================================================================\r
596 // name    : getTrihedronSize\r
597 // Purpose : Get new and current trihedron size corresponding to the\r
598 //           current model size\r
599 //=======================================================================\r
600 bool SOCC_Viewer::getTrihedronSize( double& theNewSize, double& theSize )\r
601 {\r
602   theNewSize = 100;\r
603   theSize = 100;\r
604 \r
605   //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization\r
606   Handle(V3d_Viewer) viewer = getViewer3d();\r
607   viewer->InitActiveViews();\r
608   if(!viewer->MoreActiveViews()) return false;\r
609 \r
610   Handle(V3d_View) view3d = viewer->ActiveView();\r
611   //SRN: END of fix\r
612 \r
613   if ( view3d.IsNull() )\r
614     return false;\r
615 \r
616   double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;\r
617   double aMaxSide;\r
618 \r
619   view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );\r
620 \r
621   if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||\r
622        Xmax == RealLast()  || Ymax == RealLast()  || Zmax == RealLast() )\r
623     return false;\r
624 \r
625   aMaxSide = Xmax - Xmin;\r
626   if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;\r
627   if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;\r
628 \r
629   float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("Viewer","TrihedronSize", 105.);\r
630 \r
631   static float EPS = 5.0E-3;\r
632   theSize = getTrihedron()->Size();\r
633   theNewSize = aMaxSide*aSizeInPercents / 100.0;\r
634 \r
635   return fabs( theNewSize - theSize ) > theSize * EPS ||\r
636          fabs( theNewSize - theSize) > theNewSize * EPS;\r
637 }\r
638 \r
639 //=======================================================================\r
640 // name    : Repaint\r
641 // Purpose : \r
642 //=======================================================================\r
643 void SOCC_Viewer::Repaint()\r
644 {\r
645 //  onAdjustTrihedron();\r
646   getViewer3d()->Update();\r
647 }\r
648 \r
649 //=======================================================================\r
650 // name    : createView\r
651 // Purpose : create SOCC_ViewWindow\r
652 //=======================================================================\r
653 SUIT_ViewWindow* SOCC_Viewer::createView( SUIT_Desktop* theDesktop )\r
654 {\r
655   SOCC_ViewWindow* view = new SOCC_ViewWindow(theDesktop, this);\r
656   initView( view );\r
657   return view;\r
658 }\r