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