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