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_TextAspect.hxx>
60 #include <Visual3d_View.hxx>
63 // VSR: Uncomment below line to allow texture background support in OCC viewer
64 #define OCC_ENABLE_TEXTURED_BACKGROUND
67 Get data for supported background modes: gradient types, identifiers and supported image formats
69 QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
71 gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") <<
72 tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
73 tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") <<
74 tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT");
75 idList << HorizontalGradient << VerticalGradient <<
76 Diagonal1Gradient << Diagonal2Gradient <<
77 Corner1Gradient << Corner2Gradient <<
78 Corner3Gradient << Corner4Gradient;
79 #if OCC_VERSION_LARGE > 0x06050200 // enabled since OCCT 6.5.3, since in previous version this functionality is buggy
80 #ifdef OCC_ENABLE_TEXTURED_BACKGROUND
81 txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
84 return tr("BG_IMAGE_FILES");
89 \param DisplayTrihedron - is trihedron displayed
91 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
93 myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
98 // init CasCade viewers
99 myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
100 //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
101 myV3dViewer->SetDefaultLights();
103 #if OCC_VERSION_LARGE <= 0x06060000 // Porting to OCCT higher 6.6.0 version
104 myV3dCollector = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Collector3d").ToExtString() );
105 //myV3dCollector->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
106 myV3dCollector->SetDefaultLights();
110 #if OCC_VERSION_LARGE <= 0x06060000
111 myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector );
113 myAISContext = new AIS_InteractiveContext( myV3dViewer );
115 myAISContext->SelectionColor( Quantity_NOC_WHITE );
117 // display isoline on planar faces (box for ex.)
118 myAISContext->IsoOnPlane( true );
120 /* create trihedron */
121 if ( DisplayTrihedron )
123 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
124 myTrihedron = new AIS_Trihedron(anAxis);
125 myTrihedron->SetInfiniteState( Standard_True );
127 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
128 //myTrihedron->SetColor( Col );
129 myTrihedron->SetArrowColor( Col.Name() );
130 myTrihedron->SetSize(100);
131 Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
132 if (drawer->HasDatumAspect()) {
133 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
134 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
135 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
136 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
140 // set interaction style to standard
141 myInteractionStyle = 0;
143 // set zooming style to standard
147 myPreselectionEnabled = true;
150 mySelectionEnabled = true;
151 myMultiSelectionEnabled = true;
154 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
156 myShowStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
162 OCCViewer_Viewer::~OCCViewer_Viewer()
164 myAISContext.Nullify();
165 myV3dViewer.Nullify();
166 #if OCC_VERSION_LARGE <= 0x06060000
167 myV3dCollector.Nullify();
173 \return background color of viewer
175 QColor OCCViewer_Viewer::backgroundColor() const
177 return backgroundColor(0);
181 \return background data of viewer
183 Qtx::BackgroundData OCCViewer_Viewer::background() const
185 return background(0);
189 Sets background color [obsolete]
190 \param c - new background color
192 void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
194 setBackgroundColor( 0, c );
199 \param d - new background data
201 void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
203 setBackground( 0, theBackground );
207 Start initialization of view window
208 \param view - view window to be initialized
210 void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
214 view->initSketchers();
215 view->setInteractionStyle( interactionStyle() );
216 view->setZoomingStyle( zoomingStyle() );
217 view->enablePreselection( isPreselectionEnabled() );
218 view->enableSelection( isSelectionEnabled() );
220 OCCViewer_ViewPort3d* vp3d = view->getViewPort();
223 vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL);
229 Creates new view window
230 \param theDesktop - main window of application
232 SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
235 OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
236 // get main view window (created by view frame)
237 OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
238 // initialize main view window
240 // set default background for view window
241 vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
242 // connect signal from viewport
243 connect(view->getViewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
244 connect(view->getViewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
249 Sets new view manager
250 \param theViewManager - new view manager
252 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
254 SUIT_ViewModel::setViewManager(theViewManager);
255 if (theViewManager) {
256 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
257 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
259 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
260 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
262 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
263 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
265 connect(theViewManager, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
266 this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
271 SLOT: called on mouse button press, stores current mouse position as start point for transformations
273 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
275 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
279 SLOT: called on mouse move, processes transformation or hilighting
281 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
283 if (!mySelectionEnabled) return;
284 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
286 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
288 myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
290 if ( isSelectionEnabled() && isPreselectionEnabled() ) {
291 if (aView->getViewPort()->isBusy()) {
292 QCoreApplication::processEvents();
293 return; // Check that the ViewPort initialization completed
294 // To Prevent call move event if the View port is not initialized
297 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
298 if ( !aView3d.IsNull() ) {
299 myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
306 SLOT: called on mouse button release, finishes transformation or selection
308 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
310 if (!mySelectionEnabled) return;
311 if (theEvent->button() != Qt::LeftButton) return;
312 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
314 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
318 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
319 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
321 if (!aHasShift) emit deselection();
323 if (myStartPnt == myEndPnt)
325 if ( !isPreselectionEnabled() ) {
326 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
327 if ( !aView3d.IsNull() ) {
328 myAISContext->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d);
332 if (aHasShift && myMultiSelectionEnabled)
333 myAISContext->ShiftSelect();
335 myAISContext->Select();
339 if (aHasShift && myMultiSelectionEnabled)
340 myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
341 myEndPnt.x(), myEndPnt.y(),
342 aView->getViewPort()->getView(), Standard_False );
344 myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
345 myEndPnt.x(), myEndPnt.y(),
346 aView->getViewPort()->getView(), Standard_False );
348 int Nb = myAISContext->NbSelected();
349 if( Nb>1 && !myMultiSelectionEnabled )
351 myAISContext->InitSelected();
352 Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
353 if( !anOwner.IsNull() )
355 myAISContext->ClearSelected( Standard_False );
356 myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
360 myAISContext->UpdateCurrentViewer();
362 emit selectionChanged();
366 SLOT: called on key press, processes selection in "key free" interaction style
368 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
370 if (!mySelectionEnabled) return;
371 if (theEvent->key() != Qt::Key_S) return;
372 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
374 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
375 if (!aView || aView->interactionStyle() != SUIT_ViewModel::KEY_FREE)
380 if ( !isPreselectionEnabled() ) {
381 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
382 if ( !aView3d.IsNull() ) {
383 myAISContext->MoveTo(myCurPnt.x(), myCurPnt.y(), aView3d);
387 myAISContext->Select();
389 emit selectionChanged();
392 void OCCViewer_Viewer::onViewClosed()
394 Standard_Integer aViewsNb = 0;
395 for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
397 if ( aViewsNb < 2 ) {
398 //clean up presentations before last view is closed
399 myAISContext->RemoveAll(Standard_False);
403 void OCCViewer_Viewer::onViewMapped()
405 setTrihedronShown( true );
408 int OCCViewer_Viewer::getTopLayerId()
410 #if OCC_VERSION_LARGE > 0x06050200
411 if ( myTopLayerId == 0 && !myAISContext->CurrentViewer().IsNull() )
412 myAISContext->CurrentViewer()->AddZLayer( myTopLayerId );
419 \return interaction style
421 int OCCViewer_Viewer::interactionStyle() const
423 return myInteractionStyle;
427 Sets interaction style: 0 - standard, 1 - keyboard free interaction
428 \param theStyle - new interaction style
430 void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
432 myInteractionStyle = theStyle;
433 //!! To be done for view windows
434 if ( !myViewManager )
437 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
438 for ( int i = 0; i < (int)wins.count(); i++ )
440 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
442 win->setInteractionStyle( theStyle );
447 \return zooming style
449 int OCCViewer_Viewer::zoomingStyle() const
451 return myZoomingStyle;
455 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
456 \param theStyle - new zooming style
458 void OCCViewer_Viewer::setZoomingStyle( const int theStyle )
460 myZoomingStyle = theStyle;
461 //!! To be done for view windows
462 if ( !myViewManager )
465 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
466 for ( int i = 0; i < (int)wins.count(); i++ )
468 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
470 win->setZoomingStyle( theStyle );
475 \return true if preselection is enabled
477 bool OCCViewer_Viewer::isPreselectionEnabled() const
479 return myPreselectionEnabled;
483 Enables/disables preselection
484 \param isEnabled - new status
486 void OCCViewer_Viewer::enablePreselection(bool isEnabled)
488 myPreselectionEnabled = isEnabled;
490 if ( !myViewManager )
493 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
494 for ( int i = 0; i < (int)wins.count(); i++ )
496 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
498 win->enablePreselection( isEnabled );
504 \return true if selection is enabled
506 bool OCCViewer_Viewer::isSelectionEnabled() const
508 return mySelectionEnabled;
512 Enables/disables selection
513 \param isEnabled - new status
515 void OCCViewer_Viewer::enableSelection(bool isEnabled)
517 mySelectionEnabled = isEnabled;
519 //!! To be done for view windows
520 if ( !myViewManager )
523 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
524 for ( int i = 0; i < (int)wins.count(); i++ )
526 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
528 win->updateEnabledDrawMode();
529 win->enableSelection( isEnabled );
535 Sets multiselection enabled status
536 \param isEnabled - new status
538 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
540 myMultiSelectionEnabled = isEnable;
541 //!! To be done for view windows
542 if ( !myViewManager )
545 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
546 for ( int i = 0; i < (int)wins.count(); i++ )
548 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
550 win->updateEnabledDrawMode();
555 Builds popup for occ viewer
557 void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
559 thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
560 thePopup->addAction( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
562 thePopup->addSeparator();
564 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
566 //Support of several toolbars in the popup menu
567 QList<QToolBar*> lst = qFindChildren<QToolBar*>( aView );
568 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
569 for ( ; it!=last; it++ ) {
570 if ( (*it)->parentWidget()->isVisible() )
571 thePopup->addAction( (*it)->toggleViewAction() );
576 SLOT: called on dump view operation is activated, stores scene to raster file
578 void OCCViewer_Viewer::onDumpView()
580 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
586 SLOT: called if background color is to be changed changed, passes new color to view port
588 void OCCViewer_Viewer::onChangeBackground()
590 OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
594 // get supported gradient types
595 QStringList gradList;
596 QIntList idList, txtList;
597 QString formats = backgroundData( gradList, idList, txtList );
600 Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
601 aView, // parent for dialog box
602 txtList, // allowed texture modes
603 true, // enable solid color mode
604 true, // enable gradient mode
605 false, // disable custom gradient mode
606 !txtList.isEmpty(), // enable/disable texture mode
607 gradList, // gradient names
608 idList, // gradient identifiers
609 formats ); // image formats
611 // set chosen background data to the viewer
612 if ( bgData.isValid() )
613 aView->setBackground( bgData );
617 Updates OCC 3D viewer
619 void OCCViewer_Viewer::update()
621 if (!myV3dViewer.IsNull())
622 myV3dViewer->Update();
624 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
626 aView->updateGravityCoords();
630 \return objects selected in 3D viewer
631 \param theList - list to be filled with selected objects
633 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
636 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
637 theList.Append(myAISContext->SelectedInteractive());
641 Selects objects in 3D viewer. Other selected objects are left as selected
642 \param theList - list objects to be selected
644 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
646 AIS_ListIteratorOfListOfInteractive aIt;
647 for (aIt.Initialize(theList); aIt.More(); aIt.Next())
648 myAISContext->AddOrRemoveSelected(aIt.Value(), false);
649 myAISContext->UpdateCurrentViewer();
653 Auxiliary method to emit signal selectionChanged()
655 void OCCViewer_Viewer::performSelectionChanged()
657 emit selectionChanged();
661 Hilights/unhilights object in viewer
662 \param obj - object to be updated
663 \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
664 \param update - update current viewer
666 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
667 bool hilight, bool update )
669 bool isInLocal = myAISContext->HasOpenedContext();
673 if ( hilight && !myAISContext->IsSelected( obj ) )
674 myAISContext->AddOrRemoveCurrentObject( obj, false );
675 else if ( !hilight && myAISContext->IsSelected( obj ) )
676 myAISContext->AddOrRemoveCurrentObject( obj, false );
680 myV3dViewer->Redraw();
686 Unhilights all objects in viewer
687 \param updateviewer - update current viewer
689 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
691 if ( myAISContext->HasOpenedContext() ) {
693 myAISContext->ClearSelected( updateviewer );
695 myAISContext->UnhilightSelected( updateviewer );
699 myAISContext->ClearCurrents( updateviewer );
701 myAISContext->UnhilightCurrents( updateviewer );
709 \return true if object is in viewer or in collector
710 \param obj - object to be checked
711 \param onlyInViewer - search object only in viewer (so object must be displayed)
713 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
716 AIS_ListOfInteractive List;
717 myAISContext->DisplayedObjects(List);
719 #if OCC_VERSION_LARGE <= 0x06060000
722 AIS_ListOfInteractive List1;
723 myAISContext->ObjectsInCollector(List1);
728 AIS_ListIteratorOfListOfInteractive ite(List);
729 for ( ; ite.More(); ite.Next() )
730 if( ite.Value()==obj )
737 \return true if object is displayed in viewer
738 \param obj - object to be checked
740 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
742 return myAISContext->IsDisplayed( obj );
747 \param obj - object to be updated
748 \param color - new color
749 \param update - update current viewer
751 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
757 Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
758 color.green() / 255.,
761 obj->SetColor( CSFColor );
765 myV3dViewer->Update();
769 Changes display mode of object
770 \param obj - object to be processed
771 \param mode - new display mode
772 \param update - update current viewer
774 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
775 int mode, bool update )
777 myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, update );
779 myV3dViewer->Update();
783 Changes transparency of object
784 \param obj - object to be processed
785 \param trans - new transparency
786 \param update - update current viewer
788 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
789 float trans, bool update )
791 myAISContext->SetTransparency( obj, trans, false );
792 myAISContext->Redisplay( obj, Standard_False, Standard_True );
794 myV3dViewer->Update();
798 Changes visibility of trihedron to opposite
800 void OCCViewer_Viewer::toggleTrihedron()
802 setTrihedronShown( !isTrihedronVisible() );
806 \return true if trihedron is visible
808 bool OCCViewer_Viewer::isTrihedronVisible() const
810 return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
814 Sets visibility state of trihedron
815 \param on - new state
818 void OCCViewer_Viewer::setTrihedronShown( const bool on )
820 if ( myTrihedron.IsNull() )
824 myAISContext->Display( myTrihedron );
825 myAISContext->Deactivate(myTrihedron);
828 myAISContext->Erase( myTrihedron );
833 \return trihedron size
835 double OCCViewer_Viewer::trihedronSize() const
838 if ( !myTrihedron.IsNull() )
839 sz = myTrihedron->Size();
844 Changes trihedron size
847 void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative )
849 if ( myTrihedronSize != sz || isRelative != myIsRelative) {
850 myTrihedronSize = sz;
851 myIsRelative = isRelative;
857 Set number of isolines
858 \param u - u-isolines (first parametric co-ordinate)
859 \param v - v-isolines (second parametric co-ordinate)
861 void OCCViewer_Viewer::setIsos( const int u, const int v )
863 Handle(AIS_InteractiveContext) ic = getAISContext();
867 ic->SetIsoNumber( u, AIS_TOI_IsoU );
868 ic->SetIsoNumber( v, AIS_TOI_IsoV );
872 \return number of isolines
873 \param u - to return u-isolines (first parametric co-ordinate)
874 \param v - to return v-isolines (second parametric co-ordinate)
876 void OCCViewer_Viewer::isos( int& u, int& v ) const
878 Handle(AIS_InteractiveContext) ic = getAISContext();
881 u = ic->IsoNumber( AIS_TOI_IsoU );
882 v = ic->IsoNumber( AIS_TOI_IsoV );
887 * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
889 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
891 return new OCCViewer_ViewWindow( 0, this);
895 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
897 return background( theViewId ).color();
900 Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
902 return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
906 void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
908 if ( theColor.isValid() ) {
909 Qtx::BackgroundData bg = background( theViewId );
910 bg.setColor( theColor );
911 setBackground( theViewId, bg );
915 void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
917 if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
918 myBackgrounds[theViewId] = theBackground;
923 Set the show static trihedron flag
925 void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on) {
926 if(myShowStaticTrihedron != on) {
927 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
931 OCCViewer_ViewPort3d* vp3d = aView->getViewPort();
933 myShowStaticTrihedron = on;
934 vp3d->updateStaticTriedronVisibility();
940 Get new and current trihedron size corresponding to the current model size
942 bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
947 //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
948 Handle(V3d_Viewer) viewer = getViewer3d();
949 viewer->InitActiveViews();
950 if(!viewer->MoreActiveViews()) return false;
952 Handle(V3d_View) view3d = viewer->ActiveView();
955 if ( view3d.IsNull() )
958 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
961 view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
963 if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||
964 Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() )
967 aMaxSide = Xmax - Xmin;
968 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
969 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
972 // The boundary box of the view may be initialized but nullified
973 // (case of infinite objects)
974 if ( aMaxSide < Precision::Confusion() )
977 float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
979 static float EPS = 5.0E-3;
980 theSize = getTrihedron()->Size();
981 theNewSize = aMaxSide*aSizeInPercents / 100.0;
983 return fabs( theNewSize - theSize ) > theSize * EPS ||
984 fabs( theNewSize - theSize) > theNewSize * EPS;
988 * Update the size of the trihedron
990 void OCCViewer_Viewer::updateTrihedron() {
991 if ( myTrihedron.IsNull() )
997 if(computeTrihedronSize(newSz, oldSz))
998 myTrihedron->SetSize(newSz);
1000 } else if(myTrihedron->Size() != myTrihedronSize) {
1001 myTrihedron->SetSize(myTrihedronSize);
1006 Set number of isolines
1007 \param u - u-isolines (first parametric co-ordinate)
1008 \param v - v-isolines (second parametric co-ordinate)
1010 void OCCViewer_Viewer::setSelectionOptions( bool isPreselectionEnabled, bool isSelectionEnabled )
1012 myPreselectionEnabled = isPreselectionEnabled;
1013 mySelectionEnabled = isSelectionEnabled;