]> SALOME platform Git repositories - modules/gui.git/blob - src/OCCViewer/OCCViewer_ViewModel.cxx
Salome HOME
0acca6fc514813cef08c138401a88ce96d6ab95c
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.cxx
1 // Copyright (C) 2007-2019  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, or (at your option) any later version.
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
23 #include "OCCViewer_ViewModel.h"
24 #include "OCCViewer.h"
25 #include "OCCViewer_ViewWindow.h"
26 #include "OCCViewer_ViewFrame.h"
27 #include "OCCViewer_VService.h"
28 #include "OCCViewer_ViewPort3d.h"
29 #include "OCCViewer_ClippingDlg.h"
30 #include "OCCViewer_Utilities.h"
31
32 #include "SUIT_ViewWindow.h"
33 #include "SUIT_ViewManager.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_ResourceMgr.h"
37
38 #include "ViewerData_AISShape.hxx"
39
40 #include "QtxActionToolMgr.h"
41 #include "QtxBackgroundTool.h"
42
43 #include <QPainter>
44 #include <QApplication>
45 #include <QColorDialog>
46 #include <QFileDialog>
47 #include <QPalette>
48 #include <QKeyEvent>
49 #include <QMenu>
50 #include <QMouseEvent>
51 #include <QToolBar>
52 #include <QDesktopWidget>
53
54 #include <AIS_Axis.hxx>
55 #include <Prs3d_Drawer.hxx>
56 #include <AIS_ListIteratorOfListOfInteractive.hxx>
57
58 #include <Graphic3d_Texture2Dmanual.hxx>
59 #include <Graphic3d_MaterialAspect.hxx>
60 #include <Graphic3d_TextureParams.hxx>
61
62 #include <Geom_Axis2Placement.hxx>
63 #include <Prs3d_Drawer.hxx>
64 #include <Prs3d_DatumAspect.hxx>
65 #include <Prs3d_LineAspect.hxx>
66 #include <Prs3d_TextAspect.hxx>
67
68 #include <V3d_DirectionalLight.hxx>
69 #include <V3d_AmbientLight.hxx>
70
71 #include <Basics_OCCTVersion.hxx>
72
73 /*!
74   Get data for supported background modes: gradient types, identifiers and supported image formats
75 */
76 QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
77 {
78   gradList << tr("GT_HORIZONTALGRADIENT")    << tr("GT_VERTICALGRADIENT")       <<
79               tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
80               tr("GT_FIRSTCORNERGRADIENT")   << tr("GT_SECONDCORNERGRADIENT")   <<
81               tr("GT_THIRDCORNERGRADIENT")   << tr("GT_FORTHCORNERGRADIENT");
82   idList   << HorizontalGradient             << VerticalGradient  <<
83               Diagonal1Gradient              << Diagonal2Gradient <<
84               Corner1Gradient                << Corner2Gradient   <<
85               Corner3Gradient                << Corner4Gradient;
86   txtList  << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
87   return tr("BG_IMAGE_FILES");
88 }
89
90 /*!
91   Get data for supported stereo pair modes: stereo types and identifiers
92 */
93 void OCCViewer_Viewer::stereoData( QStringList& typeList, QIntList& idList)
94 {
95   typeList << tr("ST_QUADBUFFER")    << tr("ST_ANAGLYPH")         <<
96               tr("ST_ROWINTERLACED") << tr("ST_COLUMNINTERLACED") <<
97               tr("ST_CHESSBOARD")    << tr("ST_SIDEBYSIDE")       <<
98               tr("ST_OVERUNDER");
99   idList   << QuadBufferType    << AnaglyphType         <<
100               RowInterlacedType << ColumnInterlacedType <<
101               ChessBoardType    << SideBySideType       <<
102               OverUnderType;
103 }
104
105 /*!
106   Constructor
107   \param DisplayTrihedron - is trihedron displayed
108 */
109 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
110 : SUIT_ViewModel(),
111   myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
112   myIsRelative(true),
113   myTopLayerId( 0 ),
114   myTrihedronSize(100),
115 #if OCC_VERSION_LARGE <= 0x07030000
116   myIsUseLocalSelection(false),
117 #endif
118   myClippingDlg (NULL),
119   myFitter(0)
120 {
121   // init CasCade viewers
122   myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
123   //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
124   setDefaultLights();
125
126   // init selector
127   myAISContext = new AIS_InteractiveContext( myV3dViewer );
128   myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor( Quantity_NOC_WHITE );
129   myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetColor( Quantity_NOC_WHITE );
130   
131   // display isoline on planar faces (box for ex.)
132   myAISContext->IsoOnPlane( true );
133
134   // create color scale
135   myColorScale = new AIS_ColorScale();
136   myColorScale->SetZLayer( Graphic3d_ZLayerId_TopOSD );
137   myColorScale->SetTransformPersistence( Graphic3d_TransformPers::FromDeprecatedParams( Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0) ) );
138   
139   /* create trihedron */
140   if ( DisplayTrihedron )
141   {
142     Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
143     myTrihedron = new AIS_Trihedron(anAxis);
144     myTrihedron->SetInfiniteState( Standard_True );
145
146     Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
147     //myTrihedron->SetColor( Col );
148     myTrihedron->SetArrowColor( Col.Name() );
149     myTrihedron->SetSize(100);
150     Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
151     if (drawer->HasOwnDatumAspect()) {
152       Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
153       daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
154       daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
155       daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
156     }
157   }
158
159   // set interaction style to standard
160   myInteractionStyle = 0;
161
162   // set zooming style to standard
163   myZoomingStyle = 0;
164
165   // preselection
166   myPreselectionEnabled = true;
167
168   // selection
169   mySelectionEnabled = true;
170   myMultiSelectionEnabled = true;
171
172   // set projection type to orthographic
173   myProjectionType = 0;
174   mySelectionStyle = 0;
175   // set stereo parameters
176   myStereoType = 0;
177   myAnaglyphFilter = 0;
178   myToReverseStereo = 0;
179   myVSyncMode = 1;
180   myQuadBufferSupport = 0;
181   myStereographicFocusType = 1;
182   myInterocularDistanceType = 1;
183   myStereographicFocusValue = 1.0;
184   myInterocularDistanceValue = 0.05;
185   //set clipping color and texture to standard
186   myClippingColor = QColor( 50, 50, 50 );
187   myDefaultTextureUsed = true;
188   myClippingTexture = QString();
189   myTextureModulated = true;
190   myClippingTextureScale = 1.0;
191
192 }
193
194 /*!
195   Destructor
196 */
197 OCCViewer_Viewer::~OCCViewer_Viewer() 
198 {
199   myAISContext.Nullify();
200   myV3dViewer.Nullify();
201 }
202
203 /*!
204   [obsolete]
205   \return background color of viewer
206 */
207 QColor OCCViewer_Viewer::backgroundColor() const
208 {
209   return backgroundColor(0);
210 }
211
212 /*!
213   \return background data of viewer
214 */
215 Qtx::BackgroundData OCCViewer_Viewer::background() const
216 {
217   return background(0);
218 }
219
220 /*!
221   Sets background color [obsolete]
222   \param c - new background color
223 */
224 void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
225 {
226   setBackgroundColor( 0, c );
227 }
228
229 /*!
230   Sets background data
231   \param d - new background data
232 */
233 void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
234 {
235   setBackground( 0, theBackground );
236 }
237
238 /*!
239   Start initialization of view window
240   \param view - view window to be initialized
241 */
242 void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
243 {
244   if ( view ) {
245     view->initLayout();
246     view->initSketchers();
247     view->setInteractionStyle( interactionStyle() );
248     view->setProjectionType( projectionType() );
249     view->setSelectionStyle( selectionStyle() );
250     view->setStereoType( stereoType() );
251     view->setAnaglyphFilter( anaglyphFilter() );
252     view->setStereographicFocus( stereographicFocusType(), stereographicFocusValue() );
253     view->setInterocularDistance( interocularDistanceType(), interocularDistanceValue() );
254     view->setReverseStereo( isReverseStereo() );
255     view->setVSync( isVSync() );
256     view->setQuadBufferSupport( isQuadBufferSupport() );
257     view->setZoomingStyle( zoomingStyle() );
258     view->enablePreselection( isPreselectionEnabled() );
259     view->enableSelection( isSelectionEnabled() );
260
261     OCCViewer_ViewPort3d* vp3d = view->getViewPort();
262     if ( vp3d )
263     {
264       // connect signal from viewport
265       connect(vp3d, SIGNAL(vpClosed(OCCViewer_ViewPort3d*)), this, SLOT(onViewClosed(OCCViewer_ViewPort3d*)));
266       connect(vp3d, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewMapped(OCCViewer_ViewPort3d*)));
267     }
268   }
269 }
270
271 /*!
272   Creates new view window
273   \param theDesktop - main window of application
274 */
275 SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
276 {
277   // create view frame
278   OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
279   // get main view window (created by view frame)
280   OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
281   // initialize main view window
282   initView( vw );
283   // set default background for view window
284   vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
285
286   return view;
287 }
288
289 /*!
290   Sets new view manager
291   \param theViewManager - new view manager
292 */
293 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
294 {
295   SUIT_ViewModel::setViewManager(theViewManager);
296   if (theViewManager) {
297     connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
298             this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
299
300     connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), 
301             this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
302
303     connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
304             this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
305
306     connect(theViewManager, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), 
307             this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
308   }
309 }
310
311 /*!
312   SLOT: called on mouse button press, stores current mouse position as start point for transformations
313 */
314 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
315 {
316   myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
317 }
318
319 /*!
320   SLOT: called on mouse move, processes transformation or hilighting
321 */
322 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
323 {
324   if (!mySelectionEnabled) return;
325   if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
326
327   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
328
329   myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
330
331   if ( isSelectionEnabled() && isPreselectionEnabled() ) {
332     if (aView->getViewPort()->isBusy()) {
333       QCoreApplication::processEvents();
334       return; // Check that the ViewPort initialization completed
335                                                 // To Prevent call move event if the View port is not initialized
336                                                 // IPAL 20883
337     }
338     Handle(V3d_View) aView3d = aView->getViewPort()->getView();
339     if ( !aView3d.IsNull() ) {
340       myAISContext->MoveTo( theEvent->x(), theEvent->y(), aView3d, Standard_True );
341     }
342   }
343 }
344
345
346 /*!
347   SLOT: called on mouse button release, finishes transformation or selection
348 */
349 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
350 {
351   if (!mySelectionEnabled) return;
352   if (theEvent->button() != Qt::LeftButton) return;
353   if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
354
355   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
356   if (!aView )
357     return;
358
359   myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
360   bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
361   
362   if (!aHasShift) {
363     myAISContext->ClearCurrents( false );
364     emit deselection();
365   }
366
367   if (myStartPnt == myEndPnt)
368   {
369     if ( !isPreselectionEnabled() ) {
370       Handle(V3d_View) aView3d = aView->getViewPort()->getView();
371       if ( !aView3d.IsNull() ) {
372         myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
373       }
374     }
375
376     if (aHasShift && myMultiSelectionEnabled)
377       myAISContext->ShiftSelect( Standard_True );
378     else 
379       myAISContext->Select( Standard_True );
380   }
381   else
382   {
383     if (aHasShift && myMultiSelectionEnabled)
384       myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
385                                 myEndPnt.x(), myEndPnt.y(),
386                                 aView->getViewPort()->getView(), Standard_False );
387     else
388       myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
389                            myEndPnt.x(), myEndPnt.y(),
390                            aView->getViewPort()->getView(), Standard_False );
391
392     int Nb = myAISContext->NbSelected();
393     if( Nb>1 && !myMultiSelectionEnabled )
394     {
395         myAISContext->InitSelected();
396         Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
397         if( !anOwner.IsNull() )
398         {
399             myAISContext->ClearSelected( Standard_False );
400             myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
401         }
402     }
403
404     myAISContext->UpdateCurrentViewer();
405   }
406   emit selectionChanged();
407 }
408
409 /*!
410   SLOT: called on key press, processes selection in "key free" interaction style
411 */
412 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
413 {
414   if (!mySelectionEnabled) return;
415
416   OCCViewer_ViewWindow* aView = qobject_cast<OCCViewer_ViewWindow*>( theWindow );
417   if ( !aView ) return;
418
419   bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
420
421   switch ( theEvent->key() ) {
422   case  Qt::Key_S:
423     if (!aHasShift) {
424       myAISContext->ClearCurrents( false );
425       emit deselection();
426     }
427
428     if ( !isPreselectionEnabled() ) {
429       Handle(V3d_View) aView3d = aView->getViewPort()->getView();
430       if ( !aView3d.IsNull() ) {
431         myAISContext->MoveTo(myCurPnt.x(), myCurPnt.y(), aView3d, Standard_True );
432       }
433     }
434
435     if (aHasShift && myMultiSelectionEnabled)
436       myAISContext->ShiftSelect( Standard_True );
437     else
438       myAISContext->Select( Standard_True );
439
440     emit selectionChanged();
441
442     break;
443   case  Qt::Key_N:
444     if ( isPreselectionEnabled() ) {
445 #if OCC_VERSION_LARGE <= 0x07030000
446       if ( useLocalSelection() )
447 #endif
448         getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
449     }
450     break;
451   case  Qt::Key_P:
452     if ( isPreselectionEnabled() ) {
453 #if OCC_VERSION_LARGE <= 0x07030000
454       if ( useLocalSelection() )
455 #endif
456         getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
457     }
458     break;
459   default:
460     break;
461   }
462 }
463
464 void OCCViewer_Viewer::onViewClosed(OCCViewer_ViewPort3d*)
465 {
466   Standard_Integer aViewsNb = 0;
467   for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
468     ++aViewsNb;
469   if ( aViewsNb < 2 ) {
470     //clean up presentations before last view is closed
471     myAISContext->RemoveAll(Standard_False);
472   }
473 }
474
475 void OCCViewer_Viewer::onViewMapped(OCCViewer_ViewPort3d* viewPort)
476 {
477   setTrihedronShown( true );
478   bool showStaticTrihedron = true;
479   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
480   if ( resMgr ) showStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
481   viewPort->showStaticTrihedron( showStaticTrihedron );
482 }
483
484 int OCCViewer_Viewer::getTopLayerId()
485 {
486   if ( myTopLayerId == 0 && !myAISContext->CurrentViewer().IsNull() )    
487     myAISContext->CurrentViewer()->AddZLayer( myTopLayerId );
488
489   return myTopLayerId;
490 }
491
492 /*!
493   \return interaction style
494 */
495 int OCCViewer_Viewer::interactionStyle() const
496 {
497   return myInteractionStyle;
498 }
499
500 /*!
501   Sets interaction style: 0 - standard, 1 - keyboard free interaction
502   \param theStyle - new interaction style
503 */
504 void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
505 {
506   myInteractionStyle = theStyle;
507   //!! To be done for view windows
508   if ( !myViewManager )
509     return;
510
511   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
512   for ( int i = 0; i < (int)wins.count(); i++ )
513   {
514     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
515     if ( win )
516       win->setInteractionStyle( theStyle );
517   }
518 }
519
520 /*!
521   \return projection type
522 */
523 int OCCViewer_Viewer::projectionType() const
524 {
525   return myProjectionType;
526 }
527
528 /*!
529   Sets projection type: 0 - orthographic, 1 - perspective
530   \param theType - new projection type
531 */
532 void OCCViewer_Viewer::setProjectionType( const int theType )
533 {
534   if ( myProjectionType != theType ) {
535     if ( theType != OCCViewer_ViewWindow::Stereo )
536       myProjectionType = theType;
537
538     if ( !myViewManager )
539       return;
540
541     QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
542     for ( int i = 0; i < (int)wins.count(); i++ )
543     {
544       OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
545       if ( win )
546         win->setProjectionType( (OCCViewer_ViewWindow::ProjectionType)theType );
547     }
548   }
549 }
550
551
552 int OCCViewer_Viewer::selectionStyle() const
553 {
554   return mySelectionStyle;
555 }
556
557 void OCCViewer_Viewer::setSelectionStyle(const int theMode)
558 {
559   if (mySelectionStyle != theMode) {
560     mySelectionStyle = theMode;
561     if (!myViewManager)
562       return;
563
564     QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
565     for (int i = 0; i < (int)wins.count(); i++)
566     {
567       OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>(wins.at(i));
568       if (win)
569         win->setSelectionStyle(theMode);
570     }
571   }
572 }
573
574
575
576 /*!
577   \return stereo type
578 */
579 int OCCViewer_Viewer::stereoType() const
580 {
581   return myStereoType;
582 }
583
584 /*!
585   Sets stereo type
586   \param theType - new stereo type
587 */
588 void OCCViewer_Viewer::setStereoType( const int theType )
589 {
590   myStereoType = theType;
591
592   if ( !myViewManager )
593     return;
594
595   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
596   for ( int i = 0; i < (int)wins.count(); i++ )
597   {
598     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
599     if ( win )
600       win->setStereoType( (OCCViewer_ViewWindow::StereoType)theType );
601   }
602 }
603
604 /*!
605   \return stereographic focus type
606 */
607 int OCCViewer_Viewer::stereographicFocusType() const
608 {
609   return myStereographicFocusType;
610 }
611
612 /*!
613   \return stereographic focus value
614 */
615 double OCCViewer_Viewer::stereographicFocusValue() const
616 {
617   return myStereographicFocusValue;
618 }
619
620 /*!
621   Sets stereographic focus parameters
622   \param theType - new stereographic focus type
623   \param theValue - new stereographic focus value
624 */
625 void OCCViewer_Viewer::setStereographicFocus( const int theType, const double theValue )
626 {
627   myStereographicFocusType = theType;
628   myStereographicFocusValue = theValue;
629
630   if ( !myViewManager )
631     return;
632
633   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
634   for ( int i = 0; i < (int)wins.count(); i++ )
635   {
636     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
637     if ( win )
638       win->setStereographicFocus( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
639   }
640 }
641
642 /*!
643   \return stereographic focus type
644 */
645 int OCCViewer_Viewer::interocularDistanceType() const
646 {
647   return myInterocularDistanceType;
648 }
649
650 /*!
651   \return stereographic focus value
652 */
653 double OCCViewer_Viewer::interocularDistanceValue() const
654 {
655   return myInterocularDistanceValue;
656 }
657
658 /*!
659   Sets interocular distance parameters
660   \param theType - new IOD type
661   \param theValue - new IOD value
662 */
663 void OCCViewer_Viewer::setInterocularDistance( const int theType, const double theValue )
664 {
665   myInterocularDistanceType = theType;
666   myInterocularDistanceValue = theValue;
667
668   if ( !myViewManager )
669     return;
670
671   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
672   for ( int i = 0; i < (int)wins.count(); i++ )
673   {
674     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
675     if ( win )
676       win->setInterocularDistance( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
677   }
678 }
679
680 /*!
681   \return anaglyph filter
682 */
683 int OCCViewer_Viewer::anaglyphFilter() const
684 {
685   return myAnaglyphFilter;
686 }
687
688 /*!
689   Sets anaglyph filter
690   \param theType - new anaglyph filter
691 */
692 void OCCViewer_Viewer::setAnaglyphFilter( const int theType )
693 {
694   myAnaglyphFilter = theType;
695
696   if ( !myViewManager )
697     return;
698
699   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
700   for ( int i = 0; i < (int)wins.count(); i++ )
701   {
702     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
703     if ( win )
704       win->setAnaglyphFilter( (OCCViewer_ViewWindow::AnaglyphFilter)theType );
705   }
706 }
707
708 /*!
709   \return reverse stereo
710 */
711 bool OCCViewer_Viewer::isReverseStereo() const
712 {
713   return myToReverseStereo;
714 }
715
716 /*!
717   Sets reverse stereo
718   \param theReverse - enable/disable reverse mode
719 */
720 void OCCViewer_Viewer::setReverseStereo( const bool theReverse )
721 {
722   myToReverseStereo = theReverse;
723
724   if ( !myViewManager )
725     return;
726
727   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
728   for ( int i = 0; i < (int)wins.count(); i++ )
729   {
730     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
731     if ( win )
732       win->setReverseStereo( theReverse );
733   }
734 }
735
736 /*!
737   \return V-Sync mode
738 */
739 bool OCCViewer_Viewer::isVSync() const
740 {
741   return myVSyncMode;
742 }
743
744 /*!
745   Set V-Sync mode
746   \param theEnable - enable/disable V-Sync mode
747 */
748 void OCCViewer_Viewer::setVSync( const bool theEnable )
749 {
750   myVSyncMode = theEnable;
751
752   if ( !myViewManager )
753     return;
754
755   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
756   for ( int i = 0; i < (int)wins.count(); i++ )
757   {
758     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
759     if ( win )
760       win->setVSync( theEnable );
761   }
762 }
763
764 /*!
765   \return support quad-buffered stereo
766 */
767 bool OCCViewer_Viewer::isQuadBufferSupport() const
768 {
769   return myQuadBufferSupport;
770 }
771
772 /*!
773   Set support quad-buffered stereo
774   \param theEnable - enable/disable support quad-buffered stereo
775 */
776 void OCCViewer_Viewer::setQuadBufferSupport( const bool theEnable )
777 {
778   myQuadBufferSupport = theEnable;
779
780   if ( !myViewManager )
781     return;
782
783   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
784   for ( int i = 0; i < (int)wins.count(); i++ )
785   {
786     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
787     if ( win )
788       win->setQuadBufferSupport( theEnable );
789   }
790 }
791
792 /*!
793   \return zooming style
794 */
795 int OCCViewer_Viewer::zoomingStyle() const
796 {
797   return myZoomingStyle;
798 }
799
800 /*!
801   Sets zooming style: 0 - standard, 1 - advanced (at cursor)
802   \param theStyle - new zooming style
803 */
804 void OCCViewer_Viewer::setZoomingStyle( const int theStyle )
805 {
806   myZoomingStyle = theStyle;
807   //!! To be done for view windows
808   if ( !myViewManager )
809     return;
810
811   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
812   for ( int i = 0; i < (int)wins.count(); i++ )
813   {
814     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
815     if ( win )
816       win->setZoomingStyle( theStyle );
817   }
818 }
819
820 /*!
821   \return true if preselection is enabled
822 */
823 bool OCCViewer_Viewer::isPreselectionEnabled() const 
824
825   return myPreselectionEnabled; 
826 }
827
828 /*!
829   Enables/disables preselection
830   \param isEnabled - new status
831 */
832 void OCCViewer_Viewer::enablePreselection(bool isEnabled)
833 {
834   myPreselectionEnabled = isEnabled;
835
836   if ( !myViewManager )
837     return;
838
839   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
840   for ( int i = 0; i < (int)wins.count(); i++ )
841   {
842     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
843     if ( win ) {
844       win->enablePreselection( isEnabled );
845     }
846   }
847 }
848
849 /*!
850   \return true if selection is enabled
851 */
852 bool OCCViewer_Viewer::isSelectionEnabled() const 
853
854   return mySelectionEnabled; 
855 }
856
857 /*!
858   Enables/disables selection
859   \param isEnabled - new status
860 */
861 void OCCViewer_Viewer::enableSelection(bool isEnabled)
862 {
863   mySelectionEnabled = isEnabled;
864
865   //!! To be done for view windows
866   if ( !myViewManager )
867     return;
868
869   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
870   for ( int i = 0; i < (int)wins.count(); i++ )
871   {
872     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
873     if ( win ) {
874       win->updateEnabledDrawMode();
875       win->enableSelection( isEnabled );
876     }
877   }
878
879   
880   //clear current selection in the viewer
881   if(!isEnabled) {
882     myAISContext->ClearSelected( Standard_True );
883   }
884
885 }
886
887 /*!
888   Sets multiselection enabled status
889   \param isEnabled - new status
890 */
891 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
892 {
893   myMultiSelectionEnabled = isEnable;
894   //!! To be done for view windows
895   if ( !myViewManager )
896     return;
897
898   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
899   for ( int i = 0; i < (int)wins.count(); i++ )
900   {
901     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
902     if ( win )
903       win->updateEnabledDrawMode();
904   }
905 }
906
907 /*!
908   Sets a color of the clipped region
909   \param theColor - a new color of the clipped region
910 */
911 void OCCViewer_Viewer::setClippingColor( const QColor& theColor )
912 {
913   myClippingColor = theColor;
914
915   if( myInternalClipPlanes.IsEmpty() )
916     return;
917
918   Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
919   aMaterialAspect.SetColor( Quantity_Color( theColor.redF(), theColor.greenF(),
920                                             theColor.blueF(), Quantity_TOC_RGB ) );
921 #if OCC_VERSION_LARGE <= 0x07030000
922   for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
923     myInternalClipPlanes.Value(i)->SetCappingMaterial( aMaterialAspect );
924 #else
925   for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
926     aPlaneIt.Value()->SetCappingMaterial( aMaterialAspect );
927 #endif
928   update();
929 }
930
931 /*!
932   \return clipping color
933 */
934 QColor OCCViewer_Viewer::clippingColor() const
935 {
936   return myClippingColor;
937 }
938
939 // initialize a texture for clipped region
940 Handle(Graphic3d_Texture2Dmanual) initClippingTexture( const bool isDefault, const QString& theTexture,
941                                                        const bool isModulate, const double theScale )
942 {
943   QString aTextureFile = isDefault ? ":images/hatch.png" : theTexture;
944   QPixmap px( aTextureFile );
945   const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
946   Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap );
947   if( aTexture->IsDone() ) {
948     aTexture->EnableRepeat();
949     isModulate ? aTexture->EnableModulate() : aTexture->DisableModulate();
950     aTexture->GetParams()->SetScale( Graphic3d_Vec2( 1/( theScale*100 ), -1 / ( theScale*100 ) ) );
951   }
952   return aTexture;
953 }
954
955 /*!
956   Sets default texture parameters
957   \param isDefault - use/non-use default texture
958   \param theTexture - new texture of the clipped region
959   \param isModulate - enable/disable texture modulate mode
960   \param theScale - scale factor.
961 */
962 void OCCViewer_Viewer::setClippingTextureParams( const bool isDefault, const QString& theTexture,
963                                                  const bool isModulate, const double theScale )
964 {
965   myDefaultTextureUsed = isDefault;
966   myClippingTexture = theTexture;
967   myTextureModulated = isModulate;
968   myClippingTextureScale = theScale;
969
970   if( myInternalClipPlanes.IsEmpty() )
971     return;
972
973   Handle(Graphic3d_Texture2Dmanual) aTexture =
974     initClippingTexture( myDefaultTextureUsed, myClippingTexture,
975                          myTextureModulated, myClippingTextureScale );
976 #if OCC_VERSION_LARGE <= 0x07030000
977   for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
978     myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
979 #else
980   for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
981     aPlaneIt.Value()->SetCappingTexture( aTexture );
982 #endif
983
984   update();
985 }
986
987 /*!
988   \return true if default texture is used
989 */
990 bool OCCViewer_Viewer::isDefaultTextureUsed() const
991 {
992   return myDefaultTextureUsed;
993 }
994
995 /*!
996   \return clipping texture
997 */
998 QString OCCViewer_Viewer::clippingTexture() const
999 {
1000   return myClippingTexture;
1001 }
1002
1003 /*!
1004   \return true if texture is modulated
1005 */
1006 bool OCCViewer_Viewer::isTextureModulated() const
1007 {
1008   return myTextureModulated;
1009 }
1010
1011 /*!
1012   \return scale factor of texture
1013 */
1014 double OCCViewer_Viewer::clippingTextureScale() const
1015 {
1016   return myClippingTextureScale;
1017 }
1018
1019 /*!
1020   Builds popup for occ viewer
1021 */
1022 void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
1023 {
1024   thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
1025   thePopup->addAction( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
1026
1027   thePopup->addSeparator();
1028
1029   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1030
1031   //Support of several toolbars in the popup menu
1032   QList<QToolBar*> lst = aView->findChildren<QToolBar*>();
1033   QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
1034   for ( ; it!=last; it++ ) {
1035     if ( (*it)->parentWidget()->isVisible() )
1036       thePopup->addAction( (*it)->toggleViewAction() );
1037   }
1038 }
1039
1040 /*!
1041   SLOT: called on dump view operation is activated, stores scene to raster file
1042 */
1043 void OCCViewer_Viewer::onDumpView()
1044 {
1045   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1046   if ( aView )
1047     aView->onDumpView();
1048 }
1049
1050 /*!
1051   SLOT: called if background color is to be changed changed, passes new color to view port
1052 */
1053 void OCCViewer_Viewer::onChangeBackground()
1054 {
1055   OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
1056   if ( !aView )
1057     return;
1058
1059   // get supported gradient types
1060   QStringList gradList;
1061   QIntList    idList, txtList;
1062   QString     formats = backgroundData( gradList, idList, txtList );
1063
1064   // invoke dialog box
1065   Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(),  // initial background
1066                                                                    aView,                // parent for dialog box
1067                                                                    txtList,              // allowed texture modes
1068                                                                    true,                 // enable solid color mode
1069                                                                    true,                 // enable gradient mode
1070                                                                    false,                // disable custom gradient mode
1071                                                                    !txtList.isEmpty(),   // enable/disable texture mode
1072                                                                    gradList,             // gradient names
1073                                                                    idList,               // gradient identifiers
1074                                                                    formats );            // image formats
1075
1076   // set chosen background data to the viewer
1077   if ( bgData.isValid() )
1078     aView->setBackground( bgData );
1079 }
1080
1081 /*!
1082   Updates OCC 3D viewer
1083 */
1084 void OCCViewer_Viewer::update()
1085 {
1086   if (!myV3dViewer.IsNull())
1087     myV3dViewer->Update();
1088
1089   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1090   if ( aView )
1091     aView->updateGravityCoords();
1092 }
1093
1094 /*!
1095   \return objects selected in 3D viewer
1096   \param theList - list to be filled with selected objects
1097 */
1098 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
1099 {
1100   theList.Clear();
1101   for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
1102     theList.Append(myAISContext->SelectedInteractive());
1103 }
1104
1105 /*!
1106   Selects objects in 3D viewer. Other selected objects are left as selected
1107   \param theList - list objects to be selected
1108 */
1109 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
1110 {
1111   AIS_ListIteratorOfListOfInteractive aIt;
1112   for (aIt.Initialize(theList); aIt.More(); aIt.Next())
1113     myAISContext->AddOrRemoveSelected(aIt.Value(), false);
1114   myAISContext->UpdateCurrentViewer();
1115 }
1116
1117 /*!
1118   Auxiliary method to emit signal selectionChanged()
1119 */
1120 void OCCViewer_Viewer::performSelectionChanged()
1121 {
1122     emit selectionChanged();
1123 }
1124
1125 /*
1126  * Defines default lights
1127  */
1128 void OCCViewer_Viewer::setDefaultLights()
1129 {
1130   // clear all light sources
1131   myV3dViewer->InitDefinedLights();
1132   while ( myV3dViewer->MoreDefinedLights() )
1133   {
1134     myV3dViewer->DelLight( myV3dViewer->DefinedLight() );
1135     myV3dViewer->InitDefinedLights();
1136   }
1137
1138   // get light source parameters from preferences
1139   QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "OCCViewer", "light_color", QColor( 0, 0, 0 ) );
1140   double aDx = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dx", 0.0 );
1141   double aDy = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dy", 0.0 );
1142   double aDz = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dz", -1.0 );
1143
1144   Handle(V3d_DirectionalLight) aLight =
1145     new V3d_DirectionalLight( myV3dViewer, V3d_Zneg, OCCViewer::color( aColor ).Name(), Standard_True );
1146   if( !( aDx == 0 && aDy == 0 && aDz == 0 ) )
1147     aLight->SetDirection( aDx, aDy, aDz );
1148   myV3dViewer->SetLightOn( aLight );
1149   myV3dViewer->SetLightOn( new V3d_AmbientLight( myV3dViewer ) );
1150 }
1151
1152 /*!
1153   Hilights/unhilights object in viewer
1154   \param obj - object to be updated
1155   \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
1156   \param update - update current viewer
1157 */
1158 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
1159                                   bool hilight, bool update )
1160 {
1161   if( !obj.IsNull() ) {
1162 #if OCC_VERSION_LARGE <= 0x07030000
1163     if( !myAISContext->HasOpenedContext() )
1164       {
1165 #endif
1166         if ( hilight && !myAISContext->IsSelected( obj ) )
1167           myAISContext->AddOrRemoveSelected( obj, false );
1168         else if ( !hilight && myAISContext->IsSelected( obj ) )
1169           myAISContext->AddOrRemoveSelected( obj, false );
1170 #if OCC_VERSION_LARGE <= 0x07030000
1171       }
1172 #endif
1173   }
1174
1175   if ( update )
1176     myV3dViewer->Redraw();
1177   
1178   return false;
1179 }
1180
1181 /*!
1182   Unhilights all objects in viewer
1183   \param updateviewer - update current viewer
1184 */
1185 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
1186 {
1187 #if OCC_VERSION_LARGE <= 0x07030000
1188   if ( myAISContext->HasOpenedContext() ) {
1189 #endif
1190     if ( unselect ) {
1191       myAISContext->ClearSelected( updateviewer );
1192     } else {
1193       myAISContext->UnhilightSelected( updateviewer );
1194     }
1195 #if OCC_VERSION_LARGE <= 0x07030000
1196   } else {
1197    if ( unselect ) {
1198       myAISContext->ClearCurrents( updateviewer );
1199     } else {
1200       myAISContext->UnhilightCurrents( updateviewer );
1201     }
1202   }
1203 #endif
1204   return false;
1205 }
1206
1207 /*!
1208   \return true if object is in viewer or in collector
1209   \param obj - object to be checked
1210   \param onlyInViewer - search object only in viewer (so object must be displayed)
1211 */
1212 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
1213                                    bool onlyInViewer )
1214 {
1215   AIS_ListOfInteractive List;
1216   myAISContext->DisplayedObjects(List);
1217
1218   AIS_ListIteratorOfListOfInteractive ite(List);
1219   for ( ; ite.More(); ite.Next() )
1220     if( ite.Value()==obj )
1221       return true;
1222
1223   return false;
1224 }
1225
1226 /*!
1227   \return true if object is displayed in viewer
1228   \param obj - object to be checked
1229 */
1230 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
1231 {
1232   return myAISContext->IsDisplayed( obj );
1233 }
1234
1235 /*!
1236   Sets color of object
1237   \param obj - object to be updated
1238   \param color - new color
1239   \param update - update current viewer
1240 */
1241 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
1242                                  const QColor& color,
1243                                  bool update )
1244 {
1245   if( !obj.IsNull() )
1246   {
1247     Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
1248                                                color.green() / 255.,
1249                                                color.blue() / 255.,
1250                                                Quantity_TOC_RGB );
1251     obj->SetColor( CSFColor );
1252   }
1253
1254   if( update )
1255     myV3dViewer->Update();
1256 }
1257
1258 /*!
1259   Changes display mode of object
1260   \param obj - object to be processed
1261   \param mode - new display mode
1262   \param update - update current viewer
1263 */
1264 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
1265                                              int mode, bool update )
1266 {
1267   myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, update );
1268   if( update )
1269     myV3dViewer->Update();
1270 }
1271
1272 /*!
1273   Changes transparency of object
1274   \param obj - object to be processed
1275   \param trans - new transparency
1276   \param update - update current viewer
1277 */
1278 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
1279                                         float trans, bool update )
1280 {
1281   myAISContext->SetTransparency( obj, trans, false );
1282   myAISContext->Redisplay( obj, Standard_False, Standard_True );
1283   if( update )
1284     myV3dViewer->Update();
1285 }
1286
1287 bool OCCViewer_Viewer::isColorScaleVisible() const
1288 {
1289   return !myColorScale.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myColorScale );
1290 }
1291
1292 void OCCViewer_Viewer::setColorScaleShown( const bool on )
1293 {
1294   if ( myColorScale.IsNull() )
1295     return;
1296   if ( on )
1297   {
1298     if ( !myAISContext->IsDisplayed( myColorScale ) )
1299       myAISContext->Display( myColorScale, Standard_True );
1300     myAISContext->Redisplay( myColorScale, Standard_True, Standard_True );
1301   }
1302   else
1303   {
1304     if ( myAISContext->IsDisplayed( myColorScale ) )
1305       myAISContext->Erase( myColorScale, Standard_True );
1306   }
1307 }
1308
1309 /*!
1310   Changes visibility of trihedron to opposite
1311 */
1312 void OCCViewer_Viewer::toggleTrihedron()
1313 {
1314   setTrihedronShown( !isTrihedronVisible() );
1315 }
1316
1317 /*!
1318   \return true if trihedron is visible
1319 */
1320 bool OCCViewer_Viewer::isTrihedronVisible() const
1321 {
1322   return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
1323 }
1324
1325 /*!
1326   Sets visibility state of trihedron
1327   \param on - new state
1328 */
1329
1330 void OCCViewer_Viewer::setTrihedronShown( const bool on )
1331 {
1332   if ( myTrihedron.IsNull() )
1333     return;
1334
1335   if ( on ) {
1336     myAISContext->Display( myTrihedron,
1337                            0 /*wireframe*/,
1338                            -1 /* selection mode */,
1339                            Standard_True /* update viewer*/,
1340                            Standard_False /* allow decomposition */,
1341                            AIS_DS_Displayed /* display status */);
1342     myAISContext->Deactivate( myTrihedron );
1343   }
1344   else {
1345     myAISContext->Erase( myTrihedron , Standard_True );
1346   }
1347 }
1348
1349 /*!
1350   \return trihedron size
1351 */
1352 double OCCViewer_Viewer::trihedronSize() const
1353 {
1354   double sz = 0;
1355   if ( !myTrihedron.IsNull() )
1356     sz = myTrihedron->Size();
1357   return sz;
1358 }
1359
1360 /*!
1361   Changes trihedron size
1362   \param sz - new size
1363 */
1364 void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative )
1365 {
1366   if ( myTrihedronSize != sz || isRelative != myIsRelative) {
1367     myTrihedronSize = sz; 
1368     myIsRelative = isRelative;
1369     updateTrihedron();
1370   }
1371 }
1372
1373 /*!
1374   Set number of isolines
1375   \param u - u-isolines (first parametric co-ordinate)
1376   \param v - v-isolines (second parametric co-ordinate)
1377 */
1378 void OCCViewer_Viewer::setIsos( const int u, const int v )
1379 {
1380   Handle(AIS_InteractiveContext) ic = getAISContext();
1381   if ( ic.IsNull() )
1382   return;
1383
1384   ic->SetIsoNumber( u, AIS_TOI_IsoU );
1385   ic->SetIsoNumber( v, AIS_TOI_IsoV );
1386 }
1387
1388 /*!
1389   \return number of isolines
1390   \param u - to return u-isolines (first parametric co-ordinate)
1391   \param v - to return v-isolines (second parametric co-ordinate)
1392 */
1393 void OCCViewer_Viewer::isos( int& u, int& v ) const
1394 {
1395   Handle(AIS_InteractiveContext) ic = getAISContext();
1396   if ( !ic.IsNull() )
1397   {
1398     u = ic->IsoNumber( AIS_TOI_IsoU );
1399     v = ic->IsoNumber( AIS_TOI_IsoV );
1400   }
1401 }
1402
1403 /* 
1404  * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
1405  */
1406 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
1407 {
1408   return new OCCViewer_ViewWindow(0,  this);
1409 }
1410
1411 #if OCC_VERSION_LARGE <= 0x07030000
1412 /*!
1413   Sets using local selection state
1414   \param theIsUseLocalSelection - state
1415 */
1416 void OCCViewer_Viewer::setUseLocalSelection(bool theIsUseLocalSelection)
1417 {
1418   myIsUseLocalSelection = theIsUseLocalSelection;
1419 }
1420
1421 /* 
1422  * Returns true if local context is opened or view model local state is set
1423  */
1424 bool OCCViewer_Viewer::useLocalSelection() const
1425 {
1426   if (myIsUseLocalSelection)
1427     return true;
1428   Handle(AIS_InteractiveContext) ic = getAISContext();
1429   return !ic.IsNull() && ic->HasOpenedContext();
1430 }
1431 #endif
1432
1433 // obsolete  
1434 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
1435 {
1436   return background( theViewId ).color();
1437 }
1438
1439 Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
1440 {
1441   return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
1442 }
1443
1444 // obsolete
1445 void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
1446 {
1447   if ( theColor.isValid() ) {
1448     Qtx::BackgroundData bg = background( theViewId );
1449     bg.setColor( theColor );
1450     setBackground( theViewId, bg );
1451   }
1452 }
1453
1454 void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
1455 {
1456   if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
1457     myBackgrounds[theViewId] = theBackground;    
1458 }
1459
1460
1461 /*!
1462   Set the show static trihedron flag
1463 */
1464 void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on)
1465 {
1466   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1467   if ( aView ) aView->showStaticTrihedron( on );
1468 }
1469
1470 /*!
1471   Get new and current trihedron size corresponding to the current model size
1472 */
1473 bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
1474 {
1475   theNewSize = 100;
1476   theSize = 100;
1477
1478   //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
1479   Handle(V3d_Viewer) viewer = getViewer3d();
1480   viewer->InitActiveViews();
1481   if(!viewer->MoreActiveViews()) return false;
1482
1483   Handle(V3d_View) view3d = viewer->ActiveView();
1484   //SRN: END of fix
1485
1486   if ( view3d.IsNull() )
1487     return false;
1488
1489   double aMaxSide = computeSceneSize( view3d );
1490
1491   // IPAL21687
1492   // The boundary box of the view may be initialized but nullified
1493   // (case of infinite objects)
1494   if ( aMaxSide < Precision::Confusion() )
1495     return false;
1496
1497   float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
1498
1499   static float EPS = 5.0E-3;
1500   theSize = getTrihedron()->Size();
1501   theNewSize = aMaxSide*aSizeInPercents / 100.0;
1502
1503   return fabs( theNewSize - theSize ) > theSize    * EPS ||
1504          fabs( theNewSize - theSize ) > theNewSize * EPS;
1505 }
1506
1507 /*!
1508  * Compute scene size
1509  */
1510 double OCCViewer_Viewer::computeSceneSize(const Handle(V3d_View)& view3d) const
1511 {
1512   double aMaxSide = 0;
1513   double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
1514
1515   Bnd_Box aBox = view3d->View()->MinMaxValues();
1516   Xmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
1517   Ymin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
1518   Zmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
1519   Xmax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().X();
1520   Ymax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Y();
1521   Zmax = aBox.IsVoid() ? RealLast()  : aBox.CornerMax().Z();
1522
1523   if ( Xmin != RealFirst() && Ymin != RealFirst() && Zmin != RealFirst() &&
1524        Xmax != RealLast()  && Ymax != RealLast()  && Zmax != RealLast() )
1525   {
1526     aMaxSide = Xmax - Xmin;
1527     if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
1528     if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
1529   }
1530
1531   return aMaxSide;
1532 }
1533
1534 /*! 
1535  * Update the size of the trihedron
1536  */
1537 void OCCViewer_Viewer::updateTrihedron() {
1538   if ( myTrihedron.IsNull() )
1539     return;
1540
1541   if(myIsRelative){
1542     double newSz, oldSz;
1543     
1544     if(computeTrihedronSize(newSz, oldSz))
1545       myTrihedron->SetSize(newSz);
1546     
1547   } else if(myTrihedron->Size() != myTrihedronSize) {
1548     myTrihedron->SetSize(myTrihedronSize);
1549   }
1550 }
1551
1552 /*!
1553   Set number of isolines
1554   \param u - u-isolines (first parametric co-ordinate)
1555   \param v - v-isolines (second parametric co-ordinate)
1556 */
1557 void OCCViewer_Viewer::setSelectionOptions( bool isPreselectionEnabled, bool isSelectionEnabled )
1558 {
1559   myPreselectionEnabled = isPreselectionEnabled;
1560   mySelectionEnabled = isSelectionEnabled;
1561   //clear current selection in the viewer
1562   
1563   if(!mySelectionEnabled) {
1564     myAISContext->ClearSelected( Standard_True );
1565   }
1566 }
1567
1568 /*!
1569   Creates clipping plane based on the incoming plane
1570 */
1571 Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn)
1572 {
1573   Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( thePlane );
1574   aGraphic3dPlane->SetOn( theIsOn );
1575   aGraphic3dPlane->SetCapping( Standard_True );
1576
1577   // set capping color
1578   Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
1579   aMaterialAspect.SetColor( Quantity_Color( myClippingColor.redF(), myClippingColor.greenF(),
1580                                             myClippingColor.blueF(), Quantity_TOC_RGB ) );
1581   aGraphic3dPlane->SetCappingMaterial( aMaterialAspect );
1582
1583   // set capping texture
1584   aGraphic3dPlane->SetCappingTexture( initClippingTexture( myDefaultTextureUsed, myClippingTexture,
1585                                                            myTextureModulated, myClippingTextureScale ) );
1586
1587   return aGraphic3dPlane;
1588 }
1589 /*!
1590   Applies clipping planes to clippable objects
1591 */
1592 void OCCViewer_Viewer::setClipPlanes(ClipPlanesList theList)
1593 {
1594   // 1. Remove existing clipping planes
1595   myClipPlanes.clear();
1596   myInternalClipPlanes.Clear();
1597
1598   // 2. Create new clipping planes
1599   ClipPlanesList::iterator inIt = theList.begin();
1600   for (;inIt != theList.end(); inIt++ )
1601   {
1602     OCCViewer_ClipPlane aPlane = *inIt;
1603
1604     double aDx = 0.0, aDy = 0.0, aDz = 0.0;
1605     aPlane.OrientationToXYZ( aDx, aDy, aDz );
1606
1607     gp_Pnt anOrigin( aPlane.X, aPlane.Y, aPlane.Z );
1608     gp_Dir aDirection( aDx, aDy, aDz );
1609
1610     myInternalClipPlanes.Append( createClipPlane( gp_Pln( anOrigin, aDirection ), aPlane.IsOn ) );
1611     myClipPlanes.push_back( aPlane );
1612   }
1613
1614   // 3. Apply clipping planes
1615   AIS_ListOfInteractive aList;
1616   myAISContext->DisplayedObjects (aList);
1617   for ( AIS_ListIteratorOfListOfInteractive anIter (aList); anIter.More(); anIter.Next() ) {
1618     Handle(AIS_InteractiveObject) anObj = anIter.Value();
1619     Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anObj);
1620     if (!aShape.IsNull() && aShape->IsClippable()) {
1621       aShape->SetClipPlanes(myInternalClipPlanes);
1622     }
1623   }
1624 }
1625
1626 /*!
1627   Returns the clipping planes applied to the displayed objects.
1628 */
1629 ClipPlanesList OCCViewer_Viewer::getClipPlanes() const {
1630   return myClipPlanes;
1631 }
1632 /*!
1633   Applies clipping planes to given object objects
1634 */
1635 void OCCViewer_Viewer::applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject)
1636 {
1637   Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (theObject);
1638   if (!aShape.IsNull() && aShape->IsClippable())
1639   {
1640     aShape->SetClipPlanes (myInternalClipPlanes);
1641   }
1642 }
1643
1644 /*!
1645   Returns the pointer to the clipping dialog box.
1646 */
1647 OCCViewer_ClippingDlg* OCCViewer_Viewer::getClippingDlg() const{
1648   return myClippingDlg;
1649 }
1650
1651
1652 /*!
1653   Stores pointer to the clipping dialog box.
1654 */
1655 void OCCViewer_Viewer::setClippingDlg(OCCViewer_ClippingDlg* theDlg) {
1656   if(myClippingDlg != theDlg) {
1657     myClippingDlg = theDlg;
1658   }
1659 }
1660
1661
1662 bool OCCViewer_Viewer::enableDrawMode( bool on )
1663 {
1664   //!! To be done for view windows
1665   if ( !myViewManager )
1666     return false;
1667
1668   bool prev = false;
1669   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
1670   for ( int i = 0; i < (int)wins.count(); i++ )
1671   {
1672     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
1673     if ( win ) {
1674       prev = prev || win->enableDrawMode( on ); 
1675     }
1676   }
1677   return prev;
1678 }