1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "OCCViewer_ViewModel.h"
24 #include "OCCViewer_ViewWindow.h"
25 #include "OCCViewer_ViewFrame.h"
26 #include "OCCViewer_VService.h"
27 #include "OCCViewer_ViewPort3d.h"
29 #include "SUIT_ViewWindow.h"
30 #include "SUIT_ViewManager.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SUIT_ResourceMgr.h"
35 #include "QtxActionToolMgr.h"
36 #include "QtxBackgroundTool.h"
39 #include <QApplication>
40 #include <QColorDialog>
41 #include <QFileDialog>
45 #include <QMouseEvent>
47 #include <QDesktopWidget>
49 #include <AIS_Axis.hxx>
50 #include <AIS_Drawer.hxx>
51 #include <AIS_ListOfInteractive.hxx>
52 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <Geom_Axis2Placement.hxx>
55 #include <Prs3d_Drawer.hxx>
56 #include <Prs3d_DatumAspect.hxx>
57 #include <Prs3d_LineAspect.hxx>
58 #include <Prs3d_LengthAspect.hxx>
59 #include <Prs3d_AngleAspect.hxx>
60 #include <Prs3d_TextAspect.hxx>
62 #include <Visual3d_View.hxx>
64 #include <Basics_OCCTVersion.hxx>
66 // VSR: Uncomment below line to allow texture background support in OCC viewer
67 #define OCC_ENABLE_TEXTURED_BACKGROUND
70 Get data for supported background modes: gradient types, identifiers and supported image formats
72 QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
74 gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") <<
75 tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
76 tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") <<
77 tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT");
78 idList << HorizontalGradient << VerticalGradient <<
79 Diagonal1Gradient << Diagonal2Gradient <<
80 Corner1Gradient << Corner2Gradient <<
81 Corner3Gradient << Corner4Gradient;
82 #if OCC_VERSION_LARGE > 0x06050200 // enabled since OCCT 6.5.3, since in previous version this functionality is buggy
83 #ifdef OCC_ENABLE_TEXTURED_BACKGROUND
84 txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
87 return tr("BG_IMAGE_FILES");
92 \param DisplayTrihedron - is trihedron displayed
94 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
96 myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
101 // init CasCade viewers
102 myV3dViewer = OCCViewer_VService::Viewer3d( "", (short*) "Viewer3d", "", 1000.,
103 V3d_XposYnegZpos, true, true );
107 myV3dCollector = OCCViewer_VService::Viewer3d( "", (short*) "Collector3d", "", 1000.,
108 V3d_XposYnegZpos, true, true );
109 myV3dCollector->Init();
112 myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector);
114 myAISContext->SelectionColor( Quantity_NOC_WHITE );
116 // display isoline on planar faces (box for ex.)
117 myAISContext->IsoOnPlane( true );
119 double h = QApplication::desktop()->screenGeometry( QApplication::desktop()->primaryScreen() ).height() / 300. ;
120 Handle(Prs3d_Drawer) drawer = myAISContext->DefaultDrawer();
121 Handle(Prs3d_TextAspect) ta = drawer->TextAspect();
122 ta->SetHeight(100); // VSR: workaround for CAS.CADE bug (is it really needed ???)
124 drawer->SetTextAspect(ta);
125 drawer->AngleAspect()->SetTextAspect(ta);
126 drawer->LengthAspect()->SetTextAspect(ta);
128 /* create trihedron */
129 if( DisplayTrihedron )
131 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
132 myTrihedron = new AIS_Trihedron(anAxis);
133 myTrihedron->SetInfiniteState( Standard_True );
135 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
136 //myTrihedron->SetColor( Col );
137 myTrihedron->SetArrowColor( Col.Name() );
138 myTrihedron->SetSize(100);
139 Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
140 if (drawer->HasDatumAspect()) {
141 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
142 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
143 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
144 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
147 myAISContext->Display(myTrihedron);
148 myAISContext->Deactivate(myTrihedron);
151 // set interaction style to standard
152 myInteractionStyle = 0;
154 // set zooming style to standard
158 mySelectionEnabled = true;
159 myMultiSelectionEnabled = true;
162 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
164 myShowStaticTrihedron = resMgr->booleanValue( "OCCViewer", "show_static_trihedron", true );
170 OCCViewer_Viewer::~OCCViewer_Viewer()
176 \return background color of viewer
178 QColor OCCViewer_Viewer::backgroundColor() const
180 return backgroundColor(0);
184 \return background data of viewer
186 Qtx::BackgroundData OCCViewer_Viewer::background() const
188 return background(0);
192 Sets background color [obsolete]
193 \param c - new background color
195 void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
197 setBackgroundColor( 0, c );
202 \param d - new background data
204 void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
206 setBackground( 0, theBackground );
210 Start initialization of view window
211 \param view - view window to be initialized
213 void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
217 view->initSketchers();
218 view->setInteractionStyle( interactionStyle() );
219 view->setZoomingStyle( zoomingStyle() );
221 OCCViewer_ViewPort3d* vp3d = view->getViewPort();
224 vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL);
230 Creates new view window
231 \param theDesktop - main window of application
233 SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
236 OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
237 // get main view window (created by view frame)
238 OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
239 // initialize main view window
241 // set default background for view window
242 vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
247 Sets new view manager
248 \param theViewManager - new view manager
250 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
252 SUIT_ViewModel::setViewManager(theViewManager);
253 if (theViewManager) {
254 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
255 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
257 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
258 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
260 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
261 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
263 connect(theViewManager, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
264 this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
269 SLOT: called on mouse button press, stores current mouse position as start point for transformations
271 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
273 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
277 SLOT: called on mouse move, processes transformation or hilighting
279 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
281 if (!mySelectionEnabled) return;
282 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
284 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
286 if ( isSelectionEnabled() ) {
287 if (aView->getViewPort()->isBusy()) {
288 QCoreApplication::processEvents();
289 return; // Check that the ViewPort initialization completed
290 // To Prevent call move event if the View port is not initialized
293 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
294 if ( !aView3d.IsNull() ) {
295 myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
302 SLOT: called on mouse button release, finishes transformation or selection
304 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
306 if (!mySelectionEnabled) return;
307 if (theEvent->button() != Qt::LeftButton) return;
308 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
310 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
311 if (!aView || aView->interactionStyle() != SUIT_ViewModel::STANDARD)
314 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
315 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
317 if (!aHasShift) emit deselection();
319 if (myStartPnt == myEndPnt)
321 if (aHasShift && myMultiSelectionEnabled)
322 myAISContext->ShiftSelect();
324 myAISContext->Select();
328 if (aHasShift && myMultiSelectionEnabled)
329 myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
330 myEndPnt.x(), myEndPnt.y(),
331 aView->getViewPort()->getView(), Standard_False );
333 myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
334 myEndPnt.x(), myEndPnt.y(),
335 aView->getViewPort()->getView(), Standard_False );
337 int Nb = myAISContext->NbSelected();
338 if( Nb>1 && !myMultiSelectionEnabled )
340 myAISContext->InitSelected();
341 Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
342 if( !anOwner.IsNull() )
344 myAISContext->ClearSelected( Standard_False );
345 myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
349 myAISContext->UpdateCurrentViewer();
351 emit selectionChanged();
355 SLOT: called on key press, processes selection in "key free" interaction style
357 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
359 if (!mySelectionEnabled) return;
360 if (theEvent->key() != Qt::Key_S) return;
361 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
363 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
364 if (!aView || aView->interactionStyle() != SUIT_ViewModel::KEY_FREE)
368 myAISContext->Select();
370 emit selectionChanged();
373 int OCCViewer_Viewer::getTopLayerId()
375 #if OCC_VERSION_LARGE > 0x06050200
376 if ( myTopLayerId == 0 && !myAISContext->CurrentViewer().IsNull() )
377 myAISContext->CurrentViewer()->AddZLayer( myTopLayerId );
384 \return interaction style
386 int OCCViewer_Viewer::interactionStyle() const
388 return myInteractionStyle;
392 Sets interaction style: 0 - standard, 1 - keyboard free interaction
393 \param theStyle - new interaction style
395 void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
397 myInteractionStyle = theStyle;
398 //!! To be done for view windows
399 if ( !myViewManager )
402 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
403 for ( int i = 0; i < (int)wins.count(); i++ )
405 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
407 win->setInteractionStyle( theStyle );
412 \return zooming style
414 int OCCViewer_Viewer::zoomingStyle() const
416 return myZoomingStyle;
420 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
421 \param theStyle - new zooming style
423 void OCCViewer_Viewer::setZoomingStyle( const int theStyle )
425 myZoomingStyle = theStyle;
426 //!! To be done for view windows
427 if ( !myViewManager )
430 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
431 for ( int i = 0; i < (int)wins.count(); i++ )
433 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
435 win->setZoomingStyle( theStyle );
440 Sets selection enabled status
441 \param isEnabled - new status
443 void OCCViewer_Viewer::enableSelection(bool isEnabled)
445 mySelectionEnabled = isEnabled;
446 //!! To be done for view windows
447 if ( !myViewManager )
450 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
451 for ( int i = 0; i < (int)wins.count(); i++ )
453 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
455 win->updateEnabledDrawMode();
460 Sets multiselection enabled status
461 \param isEnabled - new status
463 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
465 myMultiSelectionEnabled = isEnable;
466 //!! To be done for view windows
467 if ( !myViewManager )
470 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
471 for ( int i = 0; i < (int)wins.count(); i++ )
473 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
475 win->updateEnabledDrawMode();
480 Builds popup for occ viewer
482 void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
484 thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
485 thePopup->addAction( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
487 thePopup->addSeparator();
489 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
491 //Support of several toolbars in the popup menu
492 QList<QToolBar*> lst = qFindChildren<QToolBar*>( aView );
493 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
494 for ( ; it!=last; it++ ) {
495 if ( (*it)->parentWidget()->isVisible() )
496 thePopup->addAction( (*it)->toggleViewAction() );
501 SLOT: called on dump view operation is activated, stores scene to raster file
503 void OCCViewer_Viewer::onDumpView()
505 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
511 SLOT: called if background color is to be changed changed, passes new color to view port
513 void OCCViewer_Viewer::onChangeBackground()
515 OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
519 // get supported gradient types
520 QStringList gradList;
521 QIntList idList, txtList;
522 QString formats = backgroundData( gradList, idList, txtList );
525 Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
526 aView, // parent for dialog box
527 txtList, // allowed texture modes
528 true, // enable solid color mode
529 true, // enable gradient mode
530 false, // disable custom gradient mode
531 !txtList.isEmpty(), // enable/disable texture mode
532 gradList, // gradient names
533 idList, // gradient identifiers
534 formats ); // image formats
536 // set chosen background data to the viewer
537 if ( bgData.isValid() )
538 aView->setBackground( bgData );
542 Updates OCC 3D viewer
544 void OCCViewer_Viewer::update()
546 if (!myV3dViewer.IsNull())
547 myV3dViewer->Update();
549 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
551 aView->updateGravityCoords();
555 \return objects selected in 3D viewer
556 \param theList - list to be filled with selected objects
558 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
561 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
562 theList.Append(myAISContext->SelectedInteractive());
566 Selects objects in 3D viewer. Other selected objects are left as selected
567 \param theList - list objects to be selected
569 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
571 AIS_ListIteratorOfListOfInteractive aIt;
572 for (aIt.Initialize(theList); aIt.More(); aIt.Next())
573 myAISContext->AddOrRemoveSelected(aIt.Value(), false);
574 myAISContext->UpdateCurrentViewer();
578 Auxiliary method to emit signal selectionChanged()
580 void OCCViewer_Viewer::performSelectionChanged()
582 emit selectionChanged();
586 Hilights/unhilights object in viewer
587 \param obj - object to be updated
588 \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
589 \param update - update current viewer
591 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
592 bool hilight, bool update )
594 bool isInLocal = myAISContext->HasOpenedContext();
598 if ( hilight && !myAISContext->IsSelected( obj ) )
599 myAISContext->AddOrRemoveCurrentObject( obj, false );
600 else if ( !hilight && myAISContext->IsSelected( obj ) )
601 myAISContext->AddOrRemoveCurrentObject( obj, false );
605 myV3dViewer->Redraw();
611 Unhilights all objects in viewer
612 \param updateviewer - update current viewer
614 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer )
616 if ( myAISContext->HasOpenedContext() )
617 myAISContext->ClearSelected( updateviewer );
619 myAISContext->ClearCurrents( updateviewer );
624 \return true if object is in viewer or in collector
625 \param obj - object to be checked
626 \param onlyInViewer - search object only in viewer (so object must be displayed)
628 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
631 AIS_ListOfInteractive List;
632 myAISContext->DisplayedObjects(List);
636 AIS_ListOfInteractive List1;
637 myAISContext->ObjectsInCollector(List1);
641 AIS_ListIteratorOfListOfInteractive ite(List);
642 for ( ; ite.More(); ite.Next() )
643 if( ite.Value()==obj )
650 \return true if object is displayed in viewer
651 \param obj - object to be checked
653 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
655 return myAISContext->IsDisplayed( obj );
660 \param obj - object to be updated
661 \param color - new color
662 \param update - update current viewer
664 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
670 Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
671 color.green() / 255.,
674 obj->SetColor( CSFColor );
678 myV3dViewer->Update();
682 Changes display mode of object
683 \param obj - object to be processed
684 \param mode - new display mode
685 \param update - update current viewer
687 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
688 int mode, bool update )
690 myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, update );
692 myV3dViewer->Update();
696 Changes transparency of object
697 \param obj - object to be processed
698 \param trans - new transparency
699 \param update - update current viewer
701 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
702 float trans, bool update )
704 myAISContext->SetTransparency( obj, trans, false );
705 myAISContext->Redisplay( obj, Standard_False, Standard_True );
707 myV3dViewer->Update();
711 Changes visibility of trihedron to opposite
713 void OCCViewer_Viewer::toggleTrihedron()
715 setTrihedronShown( !isTrihedronVisible() );
719 \return true if trihedron is visible
721 bool OCCViewer_Viewer::isTrihedronVisible() const
723 return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
727 Sets visibility state of trihedron
728 \param on - new state
731 void OCCViewer_Viewer::setTrihedronShown( const bool on )
733 if ( myTrihedron.IsNull() )
737 myAISContext->Display( myTrihedron );
739 myAISContext->Erase( myTrihedron );
743 \return trihedron size
745 double OCCViewer_Viewer::trihedronSize() const
748 if ( !myTrihedron.IsNull() )
749 sz = myTrihedron->Size();
754 Changes trihedron size
757 void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative )
759 if ( myTrihedronSize != sz || isRelative != myIsRelative) {
760 myTrihedronSize = sz;
761 myIsRelative = isRelative;
767 Set number of isolines
768 \param u - u-isolines (first parametric co-ordinate)
769 \param v - v-isolines (second parametric co-ordinate)
771 void OCCViewer_Viewer::setIsos( const int u, const int v )
773 Handle(AIS_InteractiveContext) ic = getAISContext();
777 ic->SetIsoNumber( u, AIS_TOI_IsoU );
778 ic->SetIsoNumber( v, AIS_TOI_IsoV );
782 \return number of isolines
783 \param u - to return u-isolines (first parametric co-ordinate)
784 \param v - to return v-isolines (second parametric co-ordinate)
786 void OCCViewer_Viewer::isos( int& u, int& v ) const
788 Handle(AIS_InteractiveContext) ic = getAISContext();
791 u = ic->IsoNumber( AIS_TOI_IsoU );
792 v = ic->IsoNumber( AIS_TOI_IsoV );
797 * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
799 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
801 return new OCCViewer_ViewWindow( 0, this);
805 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
807 return background( theViewId ).color();
810 Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
812 return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
816 void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
818 if ( theColor.isValid() ) {
819 Qtx::BackgroundData bg = background( theViewId );
820 bg.setColor( theColor );
821 setBackground( theViewId, bg );
825 void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
827 if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
828 myBackgrounds[theViewId] = theBackground;
833 Set the show static trihedron flag
835 void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on) {
836 if(myShowStaticTrihedron != on) {
837 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
841 OCCViewer_ViewPort3d* vp3d = aView->getViewPort();
843 myShowStaticTrihedron = on;
844 vp3d->updateStaticTriedronVisibility();
850 Get new and current trihedron size corresponding to the current model size
852 bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
857 //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
858 Handle(V3d_Viewer) viewer = getViewer3d();
859 viewer->InitActiveViews();
860 if(!viewer->MoreActiveViews()) return false;
862 Handle(V3d_View) view3d = viewer->ActiveView();
865 if ( view3d.IsNull() )
868 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
871 view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
873 if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||
874 Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() )
877 aMaxSide = Xmax - Xmin;
878 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
879 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
882 // The boundary box of the view may be initialized but nullified
883 // (case of infinite objects)
884 if ( aMaxSide < Precision::Confusion() )
887 float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("OCCViewer","trihedron_size", 100.);
889 static float EPS = 5.0E-3;
890 theSize = getTrihedron()->Size();
891 theNewSize = aMaxSide*aSizeInPercents / 100.0;
893 return fabs( theNewSize - theSize ) > theSize * EPS ||
894 fabs( theNewSize - theSize) > theNewSize * EPS;
898 * Update the size of the trihedron
900 void OCCViewer_Viewer::updateTrihedron() {
904 if(computeTrihedronSize(newSz, oldSz))
905 myTrihedron->SetSize(newSz);
907 } else if(myTrihedron->Size() != myTrihedronSize) {
908 myTrihedron->SetSize(myTrihedronSize);