1 // Copyright (C) 2007-2013 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>
65 // VSR: Uncomment below line to allow texture background support in OCC viewer
66 #define OCC_ENABLE_TEXTURED_BACKGROUND
69 Get data for supported background modes: gradient types, identifiers and supported image formats
71 QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
73 gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") <<
74 tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
75 tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") <<
76 tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT");
77 idList << HorizontalGradient << VerticalGradient <<
78 Diagonal1Gradient << Diagonal2Gradient <<
79 Corner1Gradient << Corner2Gradient <<
80 Corner3Gradient << Corner4Gradient;
81 #if OCC_VERSION_LARGE > 0x06050200 // enabled since OCCT 6.5.3, since in previous version this functionality is buggy
82 #ifdef OCC_ENABLE_TEXTURED_BACKGROUND
83 txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
86 return tr("BG_IMAGE_FILES");
91 \param DisplayTrihedron - is trihedron displayed
93 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
95 myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
100 // init CasCade viewers
101 myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
102 //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
103 myV3dViewer->SetDefaultLights();
105 #if OCC_VERSION_LARGE <= 0x06060000 // Porting to OCCT higher 6.6.0 version
106 myV3dCollector = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Collector3d").ToExtString() );
107 //myV3dCollector->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
108 myV3dCollector->SetDefaultLights();
112 #if OCC_VERSION_LARGE <= 0x06060000
113 myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector );
115 myAISContext = new AIS_InteractiveContext( myV3dViewer );
117 myAISContext->SelectionColor( Quantity_NOC_WHITE );
119 // display isoline on planar faces (box for ex.)
120 myAISContext->IsoOnPlane( true );
123 double h = QApplication::desktop()->screenGeometry( QApplication::desktop()->primaryScreen() ).height() / 300. ;
124 Handle(Prs3d_Drawer) drawer = myAISContext->DefaultDrawer();
125 Handle(Prs3d_TextAspect) ta = drawer->TextAspect();
126 ta->SetHeight(100); // VSR: workaround for CAS.CADE bug (is it really needed ???)
128 drawer->SetTextAspect(ta);
129 drawer->AngleAspect()->SetTextAspect(ta);
130 drawer->LengthAspect()->SetTextAspect(ta);
133 /* create trihedron */
134 if ( DisplayTrihedron )
136 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
137 myTrihedron = new AIS_Trihedron(anAxis);
138 myTrihedron->SetInfiniteState( Standard_True );
140 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
141 //myTrihedron->SetColor( Col );
142 myTrihedron->SetArrowColor( Col.Name() );
143 myTrihedron->SetSize(100);
144 Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
145 if (drawer->HasDatumAspect()) {
146 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
147 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
148 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
149 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
153 // set interaction style to standard
154 myInteractionStyle = 0;
156 // set zooming style to standard
160 myPreselectionEnabled = true;
163 mySelectionEnabled = true;
164 myMultiSelectionEnabled = true;
167 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
169 myShowStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
175 OCCViewer_Viewer::~OCCViewer_Viewer()
177 myAISContext.Nullify();
178 myV3dViewer.Nullify();
179 #if OCC_VERSION_LARGE <= 0x06060000
180 myV3dCollector.Nullify();
186 \return background color of viewer
188 QColor OCCViewer_Viewer::backgroundColor() const
190 return backgroundColor(0);
194 \return background data of viewer
196 Qtx::BackgroundData OCCViewer_Viewer::background() const
198 return background(0);
202 Sets background color [obsolete]
203 \param c - new background color
205 void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
207 setBackgroundColor( 0, c );
212 \param d - new background data
214 void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
216 setBackground( 0, theBackground );
220 Start initialization of view window
221 \param view - view window to be initialized
223 void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
227 view->initSketchers();
228 view->setInteractionStyle( interactionStyle() );
229 view->setZoomingStyle( zoomingStyle() );
230 view->enablePreselection( isPreselectionEnabled() );
231 view->enableSelection( isSelectionEnabled() );
233 OCCViewer_ViewPort3d* vp3d = view->getViewPort();
236 vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL);
242 Creates new view window
243 \param theDesktop - main window of application
245 SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
248 OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
249 // get main view window (created by view frame)
250 OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
251 // initialize main view window
253 // set default background for view window
254 vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
255 // connect signal from viewport
256 connect(view->getViewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
257 connect(view->getViewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
262 Sets new view manager
263 \param theViewManager - new view manager
265 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
267 SUIT_ViewModel::setViewManager(theViewManager);
268 if (theViewManager) {
269 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
270 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
272 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
273 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
275 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
276 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
278 connect(theViewManager, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
279 this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
284 SLOT: called on mouse button press, stores current mouse position as start point for transformations
286 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
288 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
292 SLOT: called on mouse move, processes transformation or hilighting
294 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
296 if (!mySelectionEnabled) return;
297 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
299 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
301 myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
303 if ( isSelectionEnabled() && isPreselectionEnabled() ) {
304 if (aView->getViewPort()->isBusy()) {
305 QCoreApplication::processEvents();
306 return; // Check that the ViewPort initialization completed
307 // To Prevent call move event if the View port is not initialized
310 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
311 if ( !aView3d.IsNull() ) {
312 myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
319 SLOT: called on mouse button release, finishes transformation or selection
321 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
323 if (!mySelectionEnabled) return;
324 if (theEvent->button() != Qt::LeftButton) return;
325 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
327 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
331 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
332 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
334 if (!aHasShift) emit deselection();
336 if (myStartPnt == myEndPnt)
338 if ( !isPreselectionEnabled() ) {
339 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
340 if ( !aView3d.IsNull() ) {
341 myAISContext->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
345 if (aHasShift && myMultiSelectionEnabled)
346 myAISContext->ShiftSelect();
348 myAISContext->Select();
352 if (aHasShift && myMultiSelectionEnabled)
353 myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
354 myEndPnt.x(), myEndPnt.y(),
355 aView->getViewPort()->getView(), Standard_False );
357 myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
358 myEndPnt.x(), myEndPnt.y(),
359 aView->getViewPort()->getView(), Standard_False );
361 int Nb = myAISContext->NbSelected();
362 if( Nb>1 && !myMultiSelectionEnabled )
364 myAISContext->InitSelected();
365 Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
366 if( !anOwner.IsNull() )
368 myAISContext->ClearSelected( Standard_False );
369 myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
373 myAISContext->UpdateCurrentViewer();
375 emit selectionChanged();
379 SLOT: called on key press, processes selection in "key free" interaction style
381 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
383 if (!mySelectionEnabled) return;
384 if (theEvent->key() != Qt::Key_S) return;
385 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
387 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
388 if (!aView || aView->interactionStyle() != SUIT_ViewModel::KEY_FREE)
393 if ( !isPreselectionEnabled() ) {
394 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
395 if ( !aView3d.IsNull() ) {
396 myAISContext->MoveTo(myCurPnt.x(), myCurPnt.y(), aView3d);
400 myAISContext->Select();
402 emit selectionChanged();
405 void OCCViewer_Viewer::onViewClosed()
407 Standard_Integer aViewsNb = 0;
408 for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
410 if ( aViewsNb < 2 ) {
411 //clean up presentations before last view is closed
412 myAISContext->RemoveAll(Standard_False);
416 void OCCViewer_Viewer::onViewMapped()
418 setTrihedronShown( true );
421 int OCCViewer_Viewer::getTopLayerId()
423 #if OCC_VERSION_LARGE > 0x06050200
424 if ( myTopLayerId == 0 && !myAISContext->CurrentViewer().IsNull() )
425 myAISContext->CurrentViewer()->AddZLayer( myTopLayerId );
432 \return interaction style
434 int OCCViewer_Viewer::interactionStyle() const
436 return myInteractionStyle;
440 Sets interaction style: 0 - standard, 1 - keyboard free interaction
441 \param theStyle - new interaction style
443 void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
445 myInteractionStyle = theStyle;
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->setInteractionStyle( theStyle );
460 \return zooming style
462 int OCCViewer_Viewer::zoomingStyle() const
464 return myZoomingStyle;
468 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
469 \param theStyle - new zooming style
471 void OCCViewer_Viewer::setZoomingStyle( const int theStyle )
473 myZoomingStyle = theStyle;
474 //!! To be done for view windows
475 if ( !myViewManager )
478 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
479 for ( int i = 0; i < (int)wins.count(); i++ )
481 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
483 win->setZoomingStyle( theStyle );
488 \return true if preselection is enabled
490 bool OCCViewer_Viewer::isPreselectionEnabled() const
492 return myPreselectionEnabled;
496 Enables/disables preselection
497 \param isEnabled - new status
499 void OCCViewer_Viewer::enablePreselection(bool isEnabled)
501 myPreselectionEnabled = isEnabled;
503 if ( !myViewManager )
506 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
507 for ( int i = 0; i < (int)wins.count(); i++ )
509 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
511 win->enablePreselection( isEnabled );
517 \return true if selection is enabled
519 bool OCCViewer_Viewer::isSelectionEnabled() const
521 return mySelectionEnabled;
525 Enables/disables selection
526 \param isEnabled - new status
528 void OCCViewer_Viewer::enableSelection(bool isEnabled)
530 mySelectionEnabled = isEnabled;
532 //!! To be done for view windows
533 if ( !myViewManager )
536 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
537 for ( int i = 0; i < (int)wins.count(); i++ )
539 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
541 win->updateEnabledDrawMode();
542 win->enableSelection( isEnabled );
548 Sets multiselection enabled status
549 \param isEnabled - new status
551 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
553 myMultiSelectionEnabled = isEnable;
554 //!! To be done for view windows
555 if ( !myViewManager )
558 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
559 for ( int i = 0; i < (int)wins.count(); i++ )
561 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
563 win->updateEnabledDrawMode();
568 Builds popup for occ viewer
570 void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
572 thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
573 thePopup->addAction( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
575 thePopup->addSeparator();
577 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
579 //Support of several toolbars in the popup menu
580 QList<QToolBar*> lst = qFindChildren<QToolBar*>( aView );
581 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
582 for ( ; it!=last; it++ ) {
583 if ( (*it)->parentWidget()->isVisible() )
584 thePopup->addAction( (*it)->toggleViewAction() );
589 SLOT: called on dump view operation is activated, stores scene to raster file
591 void OCCViewer_Viewer::onDumpView()
593 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
599 SLOT: called if background color is to be changed changed, passes new color to view port
601 void OCCViewer_Viewer::onChangeBackground()
603 OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
607 // get supported gradient types
608 QStringList gradList;
609 QIntList idList, txtList;
610 QString formats = backgroundData( gradList, idList, txtList );
613 Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
614 aView, // parent for dialog box
615 txtList, // allowed texture modes
616 true, // enable solid color mode
617 true, // enable gradient mode
618 false, // disable custom gradient mode
619 !txtList.isEmpty(), // enable/disable texture mode
620 gradList, // gradient names
621 idList, // gradient identifiers
622 formats ); // image formats
624 // set chosen background data to the viewer
625 if ( bgData.isValid() )
626 aView->setBackground( bgData );
630 Updates OCC 3D viewer
632 void OCCViewer_Viewer::update()
634 if (!myV3dViewer.IsNull())
635 myV3dViewer->Update();
637 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
639 aView->updateGravityCoords();
643 \return objects selected in 3D viewer
644 \param theList - list to be filled with selected objects
646 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
649 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
650 theList.Append(myAISContext->SelectedInteractive());
654 Selects objects in 3D viewer. Other selected objects are left as selected
655 \param theList - list objects to be selected
657 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
659 AIS_ListIteratorOfListOfInteractive aIt;
660 for (aIt.Initialize(theList); aIt.More(); aIt.Next())
661 myAISContext->AddOrRemoveSelected(aIt.Value(), false);
662 myAISContext->UpdateCurrentViewer();
666 Auxiliary method to emit signal selectionChanged()
668 void OCCViewer_Viewer::performSelectionChanged()
670 emit selectionChanged();
674 Hilights/unhilights object in viewer
675 \param obj - object to be updated
676 \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
677 \param update - update current viewer
679 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
680 bool hilight, bool update )
682 bool isInLocal = myAISContext->HasOpenedContext();
686 if ( hilight && !myAISContext->IsSelected( obj ) )
687 myAISContext->AddOrRemoveCurrentObject( obj, false );
688 else if ( !hilight && myAISContext->IsSelected( obj ) )
689 myAISContext->AddOrRemoveCurrentObject( obj, false );
693 myV3dViewer->Redraw();
699 Unhilights all objects in viewer
700 \param updateviewer - update current viewer
702 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
704 if ( myAISContext->HasOpenedContext() ) {
706 myAISContext->ClearSelected( updateviewer );
708 myAISContext->UnhilightSelected( updateviewer );
712 myAISContext->ClearCurrents( updateviewer );
714 myAISContext->UnhilightCurrents( updateviewer );
722 \return true if object is in viewer or in collector
723 \param obj - object to be checked
724 \param onlyInViewer - search object only in viewer (so object must be displayed)
726 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
729 AIS_ListOfInteractive List;
730 myAISContext->DisplayedObjects(List);
732 #if OCC_VERSION_LARGE <= 0x06060000
735 AIS_ListOfInteractive List1;
736 myAISContext->ObjectsInCollector(List1);
741 AIS_ListIteratorOfListOfInteractive ite(List);
742 for ( ; ite.More(); ite.Next() )
743 if( ite.Value()==obj )
750 \return true if object is displayed in viewer
751 \param obj - object to be checked
753 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
755 return myAISContext->IsDisplayed( obj );
760 \param obj - object to be updated
761 \param color - new color
762 \param update - update current viewer
764 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
770 Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
771 color.green() / 255.,
774 obj->SetColor( CSFColor );
778 myV3dViewer->Update();
782 Changes display mode of object
783 \param obj - object to be processed
784 \param mode - new display mode
785 \param update - update current viewer
787 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
788 int mode, bool update )
790 myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, update );
792 myV3dViewer->Update();
796 Changes transparency of object
797 \param obj - object to be processed
798 \param trans - new transparency
799 \param update - update current viewer
801 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
802 float trans, bool update )
804 myAISContext->SetTransparency( obj, trans, false );
805 myAISContext->Redisplay( obj, Standard_False, Standard_True );
807 myV3dViewer->Update();
811 Changes visibility of trihedron to opposite
813 void OCCViewer_Viewer::toggleTrihedron()
815 setTrihedronShown( !isTrihedronVisible() );
819 \return true if trihedron is visible
821 bool OCCViewer_Viewer::isTrihedronVisible() const
823 return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
827 Sets visibility state of trihedron
828 \param on - new state
831 void OCCViewer_Viewer::setTrihedronShown( const bool on )
833 if ( myTrihedron.IsNull() )
837 myAISContext->Display( myTrihedron );
838 myAISContext->Deactivate(myTrihedron);
841 myAISContext->Erase( myTrihedron );
846 \return trihedron size
848 double OCCViewer_Viewer::trihedronSize() const
851 if ( !myTrihedron.IsNull() )
852 sz = myTrihedron->Size();
857 Changes trihedron size
860 void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative )
862 if ( myTrihedronSize != sz || isRelative != myIsRelative) {
863 myTrihedronSize = sz;
864 myIsRelative = isRelative;
870 Set number of isolines
871 \param u - u-isolines (first parametric co-ordinate)
872 \param v - v-isolines (second parametric co-ordinate)
874 void OCCViewer_Viewer::setIsos( const int u, const int v )
876 Handle(AIS_InteractiveContext) ic = getAISContext();
880 ic->SetIsoNumber( u, AIS_TOI_IsoU );
881 ic->SetIsoNumber( v, AIS_TOI_IsoV );
885 \return number of isolines
886 \param u - to return u-isolines (first parametric co-ordinate)
887 \param v - to return v-isolines (second parametric co-ordinate)
889 void OCCViewer_Viewer::isos( int& u, int& v ) const
891 Handle(AIS_InteractiveContext) ic = getAISContext();
894 u = ic->IsoNumber( AIS_TOI_IsoU );
895 v = ic->IsoNumber( AIS_TOI_IsoV );
900 * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
902 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
904 return new OCCViewer_ViewWindow( 0, this);
908 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
910 return background( theViewId ).color();
913 Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
915 return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
919 void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
921 if ( theColor.isValid() ) {
922 Qtx::BackgroundData bg = background( theViewId );
923 bg.setColor( theColor );
924 setBackground( theViewId, bg );
928 void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
930 if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
931 myBackgrounds[theViewId] = theBackground;
936 Set the show static trihedron flag
938 void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on) {
939 if(myShowStaticTrihedron != on) {
940 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
944 OCCViewer_ViewPort3d* vp3d = aView->getViewPort();
946 myShowStaticTrihedron = on;
947 vp3d->updateStaticTriedronVisibility();
953 Get new and current trihedron size corresponding to the current model size
955 bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
960 //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
961 Handle(V3d_Viewer) viewer = getViewer3d();
962 viewer->InitActiveViews();
963 if(!viewer->MoreActiveViews()) return false;
965 Handle(V3d_View) view3d = viewer->ActiveView();
968 if ( view3d.IsNull() )
971 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
974 view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
976 if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||
977 Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() )
980 aMaxSide = Xmax - Xmin;
981 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
982 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
985 // The boundary box of the view may be initialized but nullified
986 // (case of infinite objects)
987 if ( aMaxSide < Precision::Confusion() )
990 float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
992 static float EPS = 5.0E-3;
993 theSize = getTrihedron()->Size();
994 theNewSize = aMaxSide*aSizeInPercents / 100.0;
996 return fabs( theNewSize - theSize ) > theSize * EPS ||
997 fabs( theNewSize - theSize) > theNewSize * EPS;
1001 * Update the size of the trihedron
1003 void OCCViewer_Viewer::updateTrihedron() {
1004 if ( myTrihedron.IsNull() )
1008 double newSz, oldSz;
1010 if(computeTrihedronSize(newSz, oldSz))
1011 myTrihedron->SetSize(newSz);
1013 } else if(myTrihedron->Size() != myTrihedronSize) {
1014 myTrihedron->SetSize(myTrihedronSize);
1019 Set number of isolines
1020 \param u - u-isolines (first parametric co-ordinate)
1021 \param v - v-isolines (second parametric co-ordinate)
1023 void OCCViewer_Viewer::setSelectionOptions( bool isPreselectionEnabled, bool isSelectionEnabled )
1025 myPreselectionEnabled = isPreselectionEnabled;
1026 mySelectionEnabled = isSelectionEnabled;