Salome HOME
PR: merge SalomePro 1_2d = mergefrom_BRANCH_MergeV1_2d
[modules/kernel.git] / src / OCCViewer / OCCViewer_ViewFrame.cxx
1 //  SALOME OCCViewer : build OCC Viewer into Salome desktop
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   : OCCViewer_ViewFrame.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "OCCViewer_ViewFrame.h"
31 #include "OCCViewer_Viewer3d.h"
32 #include "OCCViewer_ViewPort.h"
33 #include "OCCViewer_ViewPort3d.h"
34
35 #include "QAD.h"
36 #include "QAD_Tools.h"
37 #include "QAD_Desktop.h"
38 #include "QAD_ViewFrame.h"
39 #include "QAD_MessageBox.h"
40 #include "QAD_Application.h"
41 #include "utilities.h"
42
43 #include "QAD_Config.h"
44 #include "QAD_Settings.h"
45 #include "SALOME_Selection.h"
46 #include "SALOME_AISShape.hxx"
47
48 // QT Include
49 #include <qapplication.h>
50
51 // Open CASCADE Include
52 #include <V3d_View.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Visual3d_View.hxx>
55
56 /*!
57     Constructor
58 */
59 OCCViewer_ViewFrame::OCCViewer_ViewFrame(QWidget* parent, const QString& title) 
60   : QAD_ViewFrame (parent, "")
61 {
62   initialize();
63 }
64
65 /*!
66     Constructor
67 */
68 OCCViewer_ViewFrame::OCCViewer_ViewFrame( QWidget* parent ) 
69   : QAD_ViewFrame (parent, "")
70 {
71   initialize();
72 }
73
74 /*!
75     Destructor
76 */
77 OCCViewer_ViewFrame::~OCCViewer_ViewFrame()
78 {
79   cleanup();
80 }
81
82 /*!
83     Init viewframe
84 */
85 void OCCViewer_ViewFrame::initialize()
86 {
87   myViewPort = NULL;
88   myViewer   = new OCCViewer_Viewer3d( this );
89   
90   /* enable/disable selection */
91   myViewer->enableSelection( true );
92   myViewer->enableMultipleSelection( true );
93 }
94
95 /*!
96     Cleanup viewframe 
97 */
98 void OCCViewer_ViewFrame::cleanup()
99 {
100   
101
102
103 /*!
104     Sets the viewport for this frame
105 */
106 void OCCViewer_ViewFrame::setViewPort( OCCViewer_ViewPort* view )
107 {
108   myViewPort = view;
109   initViewPort();               
110   setCentralWidget ( myViewPort );
111 }
112
113 /*!
114     Inits the viewport for this frame
115 */
116 void OCCViewer_ViewFrame::initViewPort()
117 {
118   /* Active Key Event */
119   setFocus();
120
121   /* Initial attributes */
122   myViewPort->setCursor( cursor() );
123   myViewPort->setBackgroundColor( backgroundColor() );
124   
125   QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyPress (QKeyEvent*)), 
126                                 this, SIGNAL(vfKeyPress(QKeyEvent*))) );
127
128   /*  Listen to my viewport */  
129   QAD_ASSERT ( QObject::connect(myViewPort, 
130                                 SIGNAL(vpTransformationStarted (OCCViewer_ViewPort::OperationType)), 
131                                 this, 
132                                 SIGNAL(vfTransformationStarted(OCCViewer_ViewPort::OperationType))) );
133   QAD_ASSERT ( QObject::connect( myViewPort, 
134                                  SIGNAL(vpTransformationFinished (OCCViewer_ViewPort::OperationType)),
135                                  this, 
136                                  SIGNAL(vfTransformationFinished(OCCViewer_ViewPort::OperationType))) );
137
138   QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpDrawExternal (QPainter*)), 
139                                 this, SIGNAL(vfDrawExternal(QPainter*))) );     
140   QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMousePress (QMouseEvent*)), 
141                                 this, SIGNAL(vfMousePress(QMouseEvent*))) );
142   QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseRelease (QMouseEvent*)), 
143                                 this, SIGNAL(vfMouseRelease(QMouseEvent*))) );
144   QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseMove (QMouseEvent*)), 
145                                 this, SIGNAL(vfMouseMove(QMouseEvent*))) );
146   QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpMouseDoubleClick (QMouseEvent*)), 
147                                 this, SIGNAL(vfMouseDoubleClick(QMouseEvent*))) );
148
149   QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyPress (QKeyEvent*)), 
150                                 this, SIGNAL(vfKeyPress(QKeyEvent*))) );
151   QAD_ASSERT ( QObject::connect(myViewPort, SIGNAL(vpKeyRelease (QKeyEvent*)), 
152                                 this, SIGNAL(vfKeyRelease(QKeyEvent*))) );
153 }
154
155 /*!
156   Returns widget containing 3D-Viewer
157 */
158 QWidget* OCCViewer_ViewFrame::getViewWidget() 
159 {
160   return (QWidget*)getViewPort();
161 }
162
163 /*!
164     Returns the viewport of this frame  
165 */
166 OCCViewer_ViewPort* OCCViewer_ViewFrame::getViewPort() const
167 {
168   return myViewPort;
169 }
170
171 /*!
172     Sets the cursor for the viewframe's viewport
173 */
174 void OCCViewer_ViewFrame::setCursor( const QCursor& cursor)
175 {
176   if ( myViewPort ) 
177     myViewPort->QWidget::setCursor(cursor);
178 }
179
180 /*!
181     Returns the current cursor 
182 */
183 QCursor OCCViewer_ViewFrame::cursor() const
184 {
185   if ( myViewPort ) 
186     return myViewPort->cursor();
187   return QMainWindow::cursor();
188 }
189
190 /*!
191     Set background of the viewport
192 */
193 void OCCViewer_ViewFrame::setBackgroundColor( const QColor& color)
194 {
195   if ( myViewPort )
196     myViewPort->setBackgroundColor(color);
197 }
198
199 /*!
200     Returns background of the viewport
201 */
202 QColor OCCViewer_ViewFrame::backgroundColor() const
203 {
204   if ( myViewPort )
205     return myViewPort->backgroundColor();
206   return QMainWindow::backgroundColor();
207 }
208
209 /*!
210     Sets the parent viewer for the window
211 */
212 void OCCViewer_ViewFrame::setViewer(OCCViewer_Viewer3d* viewer)
213 {
214   myViewer = viewer;
215 }
216
217 /*!
218   Returns the parent viewer for the window
219 */
220 OCCViewer_Viewer3d* OCCViewer_ViewFrame::getViewer() const
221 {
222   return myViewer;
223 }
224
225 /*!
226     Returns 'true' if viewframe is visible
227 */
228 void OCCViewer_ViewFrame::setVisible( bool visible )
229 {
230   if ( visible == QWidget::isVisible() )
231     return;
232   
233   if ( visible ) show();
234   else hide();
235 }
236
237 /*!
238    Called when viewframe is about to close
239 */
240 void OCCViewer_ViewFrame::closeEvent(QCloseEvent* e)
241 {
242   emit vfViewClosing(e);  /* notify our viewer */
243 }
244
245 /*!
246    Called when viewframe is resized 
247 */
248 void OCCViewer_ViewFrame::resizeEvent(QResizeEvent* e)
249 {
250   emit vfResize(e);     
251 }
252
253 void OCCViewer_ViewFrame::keyPressEvent( QKeyEvent *k )
254 {
255   emit vfKeyPress(k);
256 }
257
258 /*!
259     Fits all objects in the active view
260 */
261 void OCCViewer_ViewFrame::onViewFitAll()
262 {
263   myViewPort->fitAll();
264 }
265
266 /*!
267     Fits all obejcts within a rectangular area of the active view
268 */
269 void OCCViewer_ViewFrame::onViewFitArea()
270 {
271   myViewPort->activateWindowFit();
272   QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_SKETCHAREA") );
273 }
274
275 /*!
276     Moves the active view
277 */
278 void OCCViewer_ViewFrame::onViewPan()
279 {
280   myViewPort->activatePanning();
281 }
282
283 /*!
284     Zooms the active view
285 */
286 void OCCViewer_ViewFrame::onViewZoom()
287 {
288   myViewPort->activateZoom();
289 }
290
291 /*!
292     Sets a new center of the active view
293 */
294 void OCCViewer_ViewFrame::onViewGlobalPan()
295 {
296   myViewPort->activateGlobalPanning();
297   QAD_Application::getDesktop()->putInfo( tr("PRP_VW3D_POINTCENTER") );
298 }
299
300 /*!
301     Rotates the active view
302 */
303 void OCCViewer_ViewFrame::onViewRotate()
304 {
305   myViewPort->activateRotation();
306 }
307
308 /*!
309     Reset the active view
310 */
311 void OCCViewer_ViewFrame::onViewReset()
312 {
313   myViewPort->reset();
314 }
315
316 /*!
317     Provides front projection of the active view
318 */
319 void OCCViewer_ViewFrame::onViewFront()
320 {
321   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
322   if ( !view3d.IsNull() ) view3d->SetProj (V3d_Xpos);
323   onViewFitAll();
324 }
325
326 /*!
327     Provides back projection of the active view
328 */
329 void OCCViewer_ViewFrame::onViewBack()
330 {
331   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
332   if ( !view3d.IsNull() ) view3d->SetProj (V3d_Xneg);
333   onViewFitAll();
334 }
335
336 /*!
337     Provides right projection of the active view
338 */
339 void OCCViewer_ViewFrame::onViewRight()
340 {
341   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
342   if ( !view3d.IsNull() ) view3d->SetProj (V3d_Yneg);
343   onViewFitAll();
344 }
345
346 /*!
347     Provides left projection of the active view
348 */
349 void OCCViewer_ViewFrame::onViewLeft()
350 {
351   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
352   if ( !view3d.IsNull() ) view3d->SetProj (V3d_Ypos);
353   onViewFitAll();
354 }
355
356 /*!
357     Provides bottom projection of the active view
358 */
359 void OCCViewer_ViewFrame::onViewBottom()
360 {
361   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
362   if ( !view3d.IsNull() ) view3d->SetProj(V3d_Zneg);
363   onViewFitAll();
364 }
365
366 /*!
367     Provides top projection of the active view
368 */
369 void OCCViewer_ViewFrame::onViewTop()
370 {
371   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
372   if ( !view3d.IsNull() ) view3d->SetProj( V3d_Zpos );
373   onViewFitAll();
374 }
375
376 /*!
377   Display/hide Trihedron
378 */
379 void OCCViewer_ViewFrame::onViewTrihedron()
380 {
381   if (!myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() ))
382     myViewer->getAISContext()->Display( myViewer->getTrihedron() );
383   else
384     myViewer->getAISContext()->Erase( myViewer->getTrihedron() );
385   onAdjustTrihedron();
386 }
387
388 void OCCViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
389 {
390   myViewer->rename(IObject, newName);
391 }
392
393 void OCCViewer_ViewFrame::unHighlightAll() 
394 {
395   myViewer->unHighlightAll();
396 }
397
398 void OCCViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight, bool update ) 
399 {
400   myViewer->highlight(IObject, highlight, update);
401 }
402
403 bool OCCViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject ) 
404 {
405   return myViewer->isInViewer( IObject );
406 }
407
408 bool OCCViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject ) 
409 {
410   return myViewer->isVisible( IObject );
411 }
412
413 void OCCViewer_ViewFrame::setPopupServer( QAD_Application* App )
414 {
415   myViewer->setPopupServer( App );
416 }
417
418 void OCCViewer_ViewFrame::undo(SALOMEDS::Study_var aStudy,
419                                   const char* StudyFrameEntry)
420 {
421   AIS_ListOfInteractive List1;
422   myViewer->getAISContext()->ObjectsInCollector(List1);
423   AIS_ListIteratorOfListOfInteractive ite1(List1);
424   while (ite1.More()) {
425     if (ite1.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
426       Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite1.Value());
427       if ( aSh->hasIO() ) {
428         Handle(SALOME_InteractiveObject) IO = aSh->getIO();
429         if ( IO->hasEntry() ) { 
430           if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry))
431             myViewer->getAISContext()->Display(aSh);
432         }
433       }
434     }
435     ite1.Next();
436   }
437   
438   AIS_ListOfInteractive List;
439   myViewer->getAISContext()->DisplayedObjects(List);
440   AIS_ListIteratorOfListOfInteractive ite(List);
441   while (ite.More()) {
442     if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
443       Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite.Value());
444       if ( aSh->hasIO() ) {
445         Handle(SALOME_InteractiveObject) IO = aSh->getIO();
446         if ( IO->hasEntry() ) { 
447           if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry ))
448             myViewer->getAISContext()->Erase(aSh,true,true);
449         }
450       }
451     }
452     ite.Next();
453   }
454 }
455
456 void OCCViewer_ViewFrame::redo(SALOMEDS::Study_var aStudy,
457                                   const char* StudyFrameEntry)
458 {
459   SALOMEDS::SObject_var RefSO;
460   SALOMEDS::SObject_var SO = aStudy->FindObjectID( StudyFrameEntry );
461   SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
462   for (; it->More();it->Next()){
463     SALOMEDS::SObject_var CSO= it->Value();
464     if (CSO->ReferencedObject(RefSO)) {
465       
466       AIS_ListOfInteractive List;
467       myViewer->getAISContext()->ObjectsInCollector(List);
468       AIS_ListIteratorOfListOfInteractive ite(List);
469       while (ite.More()) {
470         if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
471           Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite.Value());
472           if ( aSh->hasIO() ) {
473             Handle(SALOME_InteractiveObject) IO = aSh->getIO();
474             if ( IO->hasEntry() ) { 
475               if ( strcmp(IO->getEntry(),RefSO->GetID()) == 0 )
476                 myViewer->getAISContext()->Display(aSh, false);
477             }
478           }
479         }
480         ite.Next();
481       }
482       
483     }
484   }
485   
486   AIS_ListOfInteractive List1;
487   myViewer->getAISContext()->DisplayedObjects(List1);
488   AIS_ListIteratorOfListOfInteractive ite1(List1);
489   while (ite1.More()) {
490     if (ite1.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
491       Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite1.Value());
492       if ( aSh->hasIO() ) {
493         Handle(SALOME_InteractiveObject) IO = aSh->getIO();
494         if ( IO->hasEntry() ) { 
495           if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry ))
496             myViewer->getAISContext()->Erase(aSh,false,true);
497         }
498       }
499     }
500     ite1.Next();
501   }
502   Repaint();
503 }
504
505 /* selection */
506 Handle(SALOME_InteractiveObject) OCCViewer_ViewFrame::FindIObject(const char* Entry)
507 {
508   Handle(SALOME_InteractiveObject) IO;
509   Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
510       
511   AIS_ListOfInteractive List;
512   ic->DisplayedObjects(List);
513   AIS_ListOfInteractive List1;
514   ic->ObjectsInCollector(List1);
515   List.Append(List1);
516
517   AIS_ListIteratorOfListOfInteractive ite(List);
518   while (ite.More()) {
519     if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
520       Handle(SALOME_AISShape) aSh
521         = Handle(SALOME_AISShape)::DownCast(ite.Value());
522       if ( aSh->hasIO() ) {
523         IO = aSh->getIO();
524         if ( IO->hasEntry() ) {
525           if ( strcmp( IO->getEntry(), Entry ) == 0 ) {
526             MESSAGE ( "IO found")
527             return IO;
528           }
529         }
530       }
531     }
532     ite.Next();
533   }
534   MESSAGE ( "IO not found")
535   return IO;
536 }
537
538 /* display */           
539 void OCCViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
540 {
541   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
542   SALOME_Selection* Sel
543     = SALOME_Selection::Selection( myStudy->getSelection() );
544
545   Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
546
547   AIS_ListOfInteractive List;
548   ic->DisplayedObjects(List);
549   AIS_ListOfInteractive List1;
550   ic->ObjectsInCollector(List1);
551   List.Append(List1);
552   
553   AIS_ListIteratorOfListOfInteractive ite(List);
554   while (ite.More()) {
555     if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
556       Handle(SALOME_AISShape) aSh
557         = Handle(SALOME_AISShape)::DownCast(ite.Value());
558       if ( aSh->hasIO() ) {
559         Handle(SALOME_InteractiveObject) IO = aSh->getIO();
560         if ( IO->isSame( IObject ) ) {
561           ic->Display(aSh, false);
562           //      ic->AddOrRemoveCurrentObject(aSh, false); repeated in Viewer3d after next statement
563           Sel->AddIObject(IO, false);
564           break;
565         }
566       }
567     }
568     ite.Next();
569   }
570   if (update)
571     Repaint();
572 }
573
574 void OCCViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject)
575 {
576   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
577   SALOME_Selection* Sel
578     = SALOME_Selection::Selection( myStudy->getSelection() );
579
580   Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
581   
582   AIS_ListOfInteractive List;
583   ic->DisplayedObjects(List);
584   AIS_ListOfInteractive List1;
585   ic->ObjectsInCollector(List1);
586   List.Append(List1);
587   
588   AIS_ListIteratorOfListOfInteractive ite(List);
589   while (ite.More()) {
590     if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape))) {
591       Handle(SALOME_AISShape) aSh
592         = Handle(SALOME_AISShape)::DownCast(ite.Value());
593       if ( aSh->hasIO() ) {
594         Handle(SALOME_InteractiveObject) IO = aSh->getIO();
595         if ( !IO->isSame( IObject ) ) {
596           ic->Erase(aSh, false);
597           Sel->RemoveIObject(IO, false);
598         } else {
599           ic->Display(aSh, false);
600           Sel->AddIObject(IO, false);
601         }
602       }
603     }
604     ite.Next();
605   }
606   Repaint();
607 }
608 void OCCViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
609 {
610   QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
611   SALOME_Selection* Sel
612     = SALOME_Selection::Selection( myStudy->getSelection() );
613
614   Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
615   
616   AIS_ListOfInteractive List;
617   ic->DisplayedObjects(List);
618   AIS_ListIteratorOfListOfInteractive ite(List);
619   while (ite.More()) 
620     {
621       if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape)))
622         {
623           Handle(SALOME_AISShape) aSh
624             = Handle(SALOME_AISShape)::DownCast(ite.Value());
625           if ( aSh->hasIO() )
626             {
627               Handle(SALOME_InteractiveObject) IO = aSh->getIO();
628               if ( IO->isSame( IObject ) )
629                 {
630                   ic->Erase(aSh, false);
631                   Sel->RemoveIObject(IO, false);
632                   break;
633                 }
634             }
635         }
636       ite.Next();
637     }
638   if (update)
639     Repaint();
640 }
641
642 void OCCViewer_ViewFrame::DisplayAll()
643 {
644   myViewer->getAISContext()->DisplayAll(Standard_False,Standard_True);
645 }
646 void OCCViewer_ViewFrame::EraseAll()
647 {
648   Standard_Boolean isTrihedronDisplayed = 
649     myViewer->getAISContext()->IsDisplayed( myViewer->getTrihedron() );
650   myViewer->getAISContext()->EraseAll();
651   if (isTrihedronDisplayed)
652     myViewer->getAISContext()->Display( myViewer->getTrihedron() );
653   else
654     Repaint();
655 }
656
657
658
659 void OCCViewer_ViewFrame::Repaint()
660 {
661   onAdjustTrihedron();
662   myViewer->getViewer3d()->Update();
663 }
664
665 void OCCViewer_ViewFrame::onAdjustTrihedron()
666 {
667   Handle (AIS_InteractiveContext) ic = myViewer->getAISContext();
668   
669   if (!ic->IsDisplayed(myViewer->getTrihedron())) 
670     return;
671   else 
672     {
673       AIS_ListOfInteractive List;
674       ic->Erase( myViewer->getTrihedron() );
675       ic->DisplayedObjects(List);
676       ic->Display( myViewer->getTrihedron() ); 
677       if (List.IsEmpty())
678         {
679           myViewer->setTrihedronSize(100);
680           return;
681         }
682     }
683   
684   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)myViewPort)->getView();
685   
686   if (!view3d.IsNull())
687     {
688       double Xmin=0, Ymin=0, Zmin=0, Xmax=0, Ymax=0, Zmax=0;
689       double aMaxSide; 
690       double aPercents;
691      
692       view3d->View()->MinMaxValues(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
693
694       if (Xmin==RealFirst() || Ymin==RealFirst() || Zmin==RealFirst() ||
695           Xmax==RealLast()  || Ymax==RealLast()  || Zmax==RealLast())
696         return;
697            
698       aMaxSide = Xmax - Xmin;
699       if (aMaxSide < Ymax -Ymin) aMaxSide = Ymax -Ymin;
700       if (aMaxSide < Zmax -Zmin) aMaxSide = Zmax -Zmin;
701       
702       static float aSizeInPercents = 105;
703       QString aSetting = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
704       if (!aSetting.isEmpty())  aSizeInPercents = aSetting.toFloat();
705
706       static float EPS = 5.0E-3;
707       float aSize = myViewer->getTrihedron()->Size();
708       float aNewSize = aMaxSide*aSizeInPercents/100.0;
709       // if the new trihedron size have sufficient difference, then apply the value
710       if(fabs(aNewSize-aSize) > aSize*EPS || fabs(aNewSize-aSize) > aNewSize*EPS)
711         myViewer->setTrihedronSize(aNewSize);
712     }
713 }