1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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_ViewFrame.h"
25 #include "OCCViewer_VService.h"
26 #include "OCCViewer_ViewPort3d.h"
27 #include "OCCViewer_ClippingDlg.h"
28 #include "OCCViewer_Utilities.h"
30 #include "SUIT_ViewWindow.h"
31 #include "SUIT_ViewManager.h"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SUIT_ResourceMgr.h"
36 #include "ViewerData_AISShape.hxx"
38 #include "QtxActionToolMgr.h"
39 #include "QtxBackgroundTool.h"
42 #include <QApplication>
43 #include <QColorDialog>
44 #include <QFileDialog>
48 #include <QMouseEvent>
50 #include <QDesktopWidget>
52 #include <AIS_Axis.hxx>
53 #include <Prs3d_Drawer.hxx>
54 #include <AIS_ListIteratorOfListOfInteractive.hxx>
55 #include <StdSelect_ViewerSelector3d.hxx>
57 #include <Graphic3d_Texture2Dmanual.hxx>
58 #include <Graphic3d_MaterialAspect.hxx>
59 #include <Graphic3d_TextureParams.hxx>
61 #include <Geom_Axis2Placement.hxx>
62 #include <Prs3d_Drawer.hxx>
63 #include <Prs3d_DatumAspect.hxx>
64 #include <Prs3d_LineAspect.hxx>
65 #include <Prs3d_TextAspect.hxx>
67 #include <V3d_DirectionalLight.hxx>
68 #include <V3d_AmbientLight.hxx>
70 #include <Basics_OCCTVersion.hxx>
74 void setCappingColor(const Handle(Graphic3d_ClipPlane)& plane, const QColor& color)
76 Quantity_Color qcolor( color.redF(), color.greenF(), color.blueF(), Quantity_TOC_RGB );
77 #if OCC_VERSION_LARGE < 0x07040000
78 Graphic3d_MaterialAspect aspect;
79 aspect.SetColor( qcolor );
80 plane->SetCappingMaterial( aspect );
82 plane->SetCappingColor( qcolor );
88 Get data for supported background modes: gradient types, identifiers and supported image formats
90 QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
92 gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") <<
93 tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
94 tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") <<
95 tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT");
96 idList << HorizontalGradient << VerticalGradient <<
97 Diagonal1Gradient << Diagonal2Gradient <<
98 Corner1Gradient << Corner2Gradient <<
99 Corner3Gradient << Corner4Gradient;
100 txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
101 return tr("BG_IMAGE_FILES");
105 Get data for supported stereo pair modes: stereo types and identifiers
107 void OCCViewer_Viewer::stereoData( QStringList& typeList, QIntList& idList)
109 typeList << tr("ST_QUADBUFFER") << tr("ST_ANAGLYPH") <<
110 tr("ST_ROWINTERLACED") << tr("ST_COLUMNINTERLACED") <<
111 tr("ST_CHESSBOARD") << tr("ST_SIDEBYSIDE") <<
113 idList << QuadBufferType << AnaglyphType <<
114 RowInterlacedType << ColumnInterlacedType <<
115 ChessBoardType << SideBySideType <<
121 \param DisplayTrihedron - is trihedron displayed
123 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
125 myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
128 myTrihedronSize(100),
129 #if OCC_VERSION_LARGE <= 0x07030000
130 myIsUseLocalSelection(false),
132 myClippingDlg (NULL),
135 // init CasCade viewers
136 myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
137 //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
141 myAISContext = new AIS_InteractiveContext( myV3dViewer );
142 myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor( Quantity_NOC_WHITE );
143 myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetColor( Quantity_NOC_WHITE );
145 // display isoline on planar faces (box for ex.)
146 myAISContext->IsoOnPlane( true );
148 // create color scale
149 myColorScale = new AIS_ColorScale();
150 myColorScale->SetZLayer( Graphic3d_ZLayerId_TopOSD );
151 myColorScale->SetTransformPersistence( Graphic3d_TransformPers::FromDeprecatedParams( Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0) ) );
153 /* create trihedron */
154 if ( DisplayTrihedron )
156 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
157 myTrihedron = new AIS_Trihedron(anAxis);
158 myTrihedron->SetInfiniteState( Standard_True );
160 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
161 //myTrihedron->SetColor( Col );
162 myTrihedron->SetArrowColor( Col.Name() );
163 myTrihedron->SetSize(100);
164 Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
165 if (drawer->HasOwnDatumAspect()) {
166 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
167 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
168 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
169 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
173 // set interaction style to standard
174 myInteractionStyle = 0;
176 // set zooming style to standard
180 myPreselectionEnabled = true;
183 mySelectionEnabled = true;
184 myMultiSelectionEnabled = true;
186 // set projection type to orthographic
187 myProjectionType = 0;
188 mySelectionStyle = OCCViewer_ViewWindow::RectStyle;
189 // set stereo parameters
191 myAnaglyphFilter = 0;
192 myToReverseStereo = 0;
194 myQuadBufferSupport = 0;
195 myStereographicFocusType = 1;
196 myInterocularDistanceType = 1;
197 myStereographicFocusValue = 1.0;
198 myInterocularDistanceValue = 0.05;
199 //set clipping color and texture to standard
200 myClippingColor = QColor( 50, 50, 50 );
201 myDefaultTextureUsed = true;
202 myClippingTexture = QString();
203 myTextureModulated = true;
204 myClippingTextureScale = 1.0;
211 OCCViewer_Viewer::~OCCViewer_Viewer()
213 myAISContext.Nullify();
214 myV3dViewer.Nullify();
219 \return background color of viewer
221 QColor OCCViewer_Viewer::backgroundColor() const
223 return backgroundColor(0);
227 \return background data of viewer
229 Qtx::BackgroundData OCCViewer_Viewer::background() const
231 return background(0);
235 Sets background color [obsolete]
236 \param c - new background color
238 void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
240 setBackgroundColor( 0, c );
245 \param d - new background data
247 void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
249 setBackground( 0, theBackground );
253 Start initialization of view window
254 \param view - view window to be initialized
256 void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
260 view->initSketchers();
261 view->setInteractionStyle( interactionStyle() );
262 view->setProjectionType( projectionType() );
263 view->setSelectionStyle( selectionStyle() );
264 view->setStereoType( stereoType() );
265 view->setAnaglyphFilter( anaglyphFilter() );
266 view->setStereographicFocus( stereographicFocusType(), stereographicFocusValue() );
267 view->setInterocularDistance( interocularDistanceType(), interocularDistanceValue() );
268 view->setReverseStereo( isReverseStereo() );
269 view->setVSync( isVSync() );
270 view->setQuadBufferSupport( isQuadBufferSupport() );
271 view->setZoomingStyle( zoomingStyle() );
272 view->enablePreselection( isPreselectionEnabled() );
273 view->enableSelection( isSelectionEnabled() );
275 OCCViewer_ViewPort3d* vp3d = view->getViewPort();
278 // connect signal from viewport
279 connect(vp3d, SIGNAL(vpClosed(OCCViewer_ViewPort3d*)), this, SLOT(onViewClosed(OCCViewer_ViewPort3d*)));
280 connect(vp3d, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewMapped(OCCViewer_ViewPort3d*)));
286 Creates new view window
287 \param theDesktop - main window of application
289 SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
292 OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
293 // get main view window (created by view frame)
294 OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
295 // initialize main view window
297 // set default background for view window
298 vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
304 Sets new view manager
305 \param theViewManager - new view manager
307 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
309 SUIT_ViewModel::setViewManager(theViewManager);
310 if (theViewManager) {
311 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
312 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
314 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
315 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
317 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
318 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
320 connect(theViewManager, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
321 this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
326 SLOT: called on mouse button press, stores current mouse position as start point for transformations
328 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
330 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
334 SLOT: called on mouse move, processes transformation or hilighting
336 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
338 if (!mySelectionEnabled) return;
339 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
341 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
343 myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
345 if ( isSelectionEnabled() && isPreselectionEnabled() ) {
346 if (aView->getViewPort()->isBusy()) {
347 QCoreApplication::processEvents();
348 return; // Check that the ViewPort initialization completed
349 // To Prevent call move event if the View port is not initialized
352 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
353 if ( !aView3d.IsNull() ) {
354 myAISContext->MoveTo( theEvent->x(), theEvent->y(), aView3d, Standard_True );
361 SLOT: called on mouse button release, finishes transformation or selection
363 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
365 if (!mySelectionEnabled) return;
366 if (theEvent->button() != Qt::LeftButton) return;
367 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
369 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
373 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
374 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
376 if (myStartPnt == myEndPnt)
379 myAISContext->ClearCurrents( false );
382 if ( !isPreselectionEnabled() ) {
383 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
384 if ( !aView3d.IsNull() ) {
385 myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
389 if (aHasShift && myMultiSelectionEnabled)
390 myAISContext->ShiftSelect( Standard_True );
392 myAISContext->Select( Standard_True );
393 emit selectionChanged();
398 // if (aHasShift && myMultiSelectionEnabled)
399 // myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
400 // myEndPnt.x(), myEndPnt.y(),
401 // aView->getViewPort()->getView(), Standard_False );
403 // myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
404 // myEndPnt.x(), myEndPnt.y(),
405 // aView->getViewPort()->getView(), Standard_False );
407 // int Nb = myAISContext->NbSelected();
408 // if( Nb>1 && !myMultiSelectionEnabled )
410 // myAISContext->InitSelected();
411 // Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
412 // if( !anOwner.IsNull() )
414 // myAISContext->ClearSelected( Standard_False );
415 // myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
419 // myAISContext->UpdateCurrentViewer();
424 SLOT: called on key press, processes selection in "key free" interaction style
426 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
428 if (!mySelectionEnabled) return;
430 OCCViewer_ViewWindow* aView = qobject_cast<OCCViewer_ViewWindow*>( theWindow );
431 if ( !aView ) return;
433 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
435 switch ( theEvent->key() ) {
438 myAISContext->ClearCurrents( false );
442 if ( !isPreselectionEnabled() ) {
443 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
444 if ( !aView3d.IsNull() ) {
445 myAISContext->MoveTo(myCurPnt.x(), myCurPnt.y(), aView3d, Standard_True );
449 if (aHasShift && myMultiSelectionEnabled)
450 myAISContext->ShiftSelect( Standard_True );
452 myAISContext->Select( Standard_True );
454 emit selectionChanged();
458 if ( isPreselectionEnabled() ) {
459 #if OCC_VERSION_LARGE <= 0x07030000
460 if ( useLocalSelection() )
462 getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
466 if ( isPreselectionEnabled() ) {
467 #if OCC_VERSION_LARGE <= 0x07030000
468 if ( useLocalSelection() )
470 getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
478 void OCCViewer_Viewer::onViewClosed(OCCViewer_ViewPort3d*)
480 Standard_Integer aViewsNb = 0;
481 for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
483 if ( aViewsNb < 2 ) {
484 //clean up presentations before last view is closed
485 myAISContext->RemoveAll(Standard_False);
489 void OCCViewer_Viewer::onViewMapped(OCCViewer_ViewPort3d* viewPort)
491 setTrihedronShown( true );
492 bool showStaticTrihedron = true;
493 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
494 if ( resMgr ) showStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
495 viewPort->showStaticTrihedron( showStaticTrihedron );
498 int OCCViewer_Viewer::getTopLayerId()
500 if ( myTopLayerId == 0 && !myAISContext->CurrentViewer().IsNull() )
501 myAISContext->CurrentViewer()->AddZLayer( myTopLayerId );
507 \return interaction style
509 int OCCViewer_Viewer::interactionStyle() const
511 return myInteractionStyle;
515 Sets interaction style: 0 - standard, 1 - keyboard free interaction
516 \param theStyle - new interaction style
518 void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
520 myInteractionStyle = theStyle;
521 //!! To be done for view windows
522 if ( !myViewManager )
525 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
526 for ( int i = 0; i < (int)wins.count(); i++ )
528 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
530 win->setInteractionStyle( theStyle );
535 \return projection type
537 int OCCViewer_Viewer::projectionType() const
539 return myProjectionType;
543 Sets projection type: 0 - orthographic, 1 - perspective
544 \param theType - new projection type
546 void OCCViewer_Viewer::setProjectionType( const int theType )
548 if ( myProjectionType != theType ) {
549 if ( theType != OCCViewer_ViewWindow::Stereo )
550 myProjectionType = theType;
552 if ( !myViewManager )
555 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
556 for ( int i = 0; i < (int)wins.count(); i++ )
558 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
560 win->setProjectionType( (OCCViewer_ViewWindow::ProjectionType)theType );
566 OCCViewer_ViewWindow::SelectionStyle OCCViewer_Viewer::selectionStyle() const
568 return mySelectionStyle;
571 void OCCViewer_Viewer::setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle theMode)
573 if (mySelectionStyle != theMode) {
574 mySelectionStyle = theMode;
578 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
579 for (int i = 0; i < (int)wins.count(); i++)
581 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>(wins.at(i));
583 win->setSelectionStyle(theMode);
593 int OCCViewer_Viewer::stereoType() const
600 \param theType - new stereo type
602 void OCCViewer_Viewer::setStereoType( const int theType )
604 myStereoType = theType;
606 if ( !myViewManager )
609 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
610 for ( int i = 0; i < (int)wins.count(); i++ )
612 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
614 win->setStereoType( (OCCViewer_ViewWindow::StereoType)theType );
619 \return stereographic focus type
621 int OCCViewer_Viewer::stereographicFocusType() const
623 return myStereographicFocusType;
627 \return stereographic focus value
629 double OCCViewer_Viewer::stereographicFocusValue() const
631 return myStereographicFocusValue;
635 Sets stereographic focus parameters
636 \param theType - new stereographic focus type
637 \param theValue - new stereographic focus value
639 void OCCViewer_Viewer::setStereographicFocus( const int theType, const double theValue )
641 myStereographicFocusType = theType;
642 myStereographicFocusValue = theValue;
644 if ( !myViewManager )
647 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
648 for ( int i = 0; i < (int)wins.count(); i++ )
650 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
652 win->setStereographicFocus( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
657 \return stereographic focus type
659 int OCCViewer_Viewer::interocularDistanceType() const
661 return myInterocularDistanceType;
665 \return stereographic focus value
667 double OCCViewer_Viewer::interocularDistanceValue() const
669 return myInterocularDistanceValue;
673 Sets interocular distance parameters
674 \param theType - new IOD type
675 \param theValue - new IOD value
677 void OCCViewer_Viewer::setInterocularDistance( const int theType, const double theValue )
679 myInterocularDistanceType = theType;
680 myInterocularDistanceValue = theValue;
682 if ( !myViewManager )
685 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
686 for ( int i = 0; i < (int)wins.count(); i++ )
688 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
690 win->setInterocularDistance( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
695 \return anaglyph filter
697 int OCCViewer_Viewer::anaglyphFilter() const
699 return myAnaglyphFilter;
704 \param theType - new anaglyph filter
706 void OCCViewer_Viewer::setAnaglyphFilter( const int theType )
708 myAnaglyphFilter = theType;
710 if ( !myViewManager )
713 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
714 for ( int i = 0; i < (int)wins.count(); i++ )
716 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
718 win->setAnaglyphFilter( (OCCViewer_ViewWindow::AnaglyphFilter)theType );
723 \return reverse stereo
725 bool OCCViewer_Viewer::isReverseStereo() const
727 return myToReverseStereo;
732 \param theReverse - enable/disable reverse mode
734 void OCCViewer_Viewer::setReverseStereo( const bool theReverse )
736 myToReverseStereo = theReverse;
738 if ( !myViewManager )
741 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
742 for ( int i = 0; i < (int)wins.count(); i++ )
744 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
746 win->setReverseStereo( theReverse );
753 bool OCCViewer_Viewer::isVSync() const
760 \param theEnable - enable/disable V-Sync mode
762 void OCCViewer_Viewer::setVSync( const bool theEnable )
764 myVSyncMode = theEnable;
766 if ( !myViewManager )
769 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
770 for ( int i = 0; i < (int)wins.count(); i++ )
772 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
774 win->setVSync( theEnable );
779 \return support quad-buffered stereo
781 bool OCCViewer_Viewer::isQuadBufferSupport() const
783 return myQuadBufferSupport;
787 Set support quad-buffered stereo
788 \param theEnable - enable/disable support quad-buffered stereo
790 void OCCViewer_Viewer::setQuadBufferSupport( const bool theEnable )
792 myQuadBufferSupport = theEnable;
794 if ( !myViewManager )
797 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
798 for ( int i = 0; i < (int)wins.count(); i++ )
800 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
802 win->setQuadBufferSupport( theEnable );
807 \return zooming style
809 int OCCViewer_Viewer::zoomingStyle() const
811 return myZoomingStyle;
815 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
816 \param theStyle - new zooming style
818 void OCCViewer_Viewer::setZoomingStyle( const int theStyle )
820 myZoomingStyle = theStyle;
821 //!! To be done for view windows
822 if ( !myViewManager )
825 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
826 for ( int i = 0; i < (int)wins.count(); i++ )
828 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
830 win->setZoomingStyle( theStyle );
835 \return true if preselection is enabled
837 bool OCCViewer_Viewer::isPreselectionEnabled() const
839 return myPreselectionEnabled;
843 Enables/disables preselection
844 \param isEnabled - new status
846 void OCCViewer_Viewer::enablePreselection(bool isEnabled)
848 myPreselectionEnabled = isEnabled;
850 if ( !myViewManager )
853 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
854 for ( int i = 0; i < (int)wins.count(); i++ )
856 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
858 win->enablePreselection( isEnabled );
864 \return true if selection is enabled
866 bool OCCViewer_Viewer::isSelectionEnabled() const
868 return mySelectionEnabled;
872 Enables/disables selection
873 \param isEnabled - new status
875 void OCCViewer_Viewer::enableSelection(bool isEnabled)
877 mySelectionEnabled = isEnabled;
879 //!! To be done for view windows
880 if ( !myViewManager )
883 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
884 for ( int i = 0; i < (int)wins.count(); i++ )
886 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
888 win->updateEnabledDrawMode();
889 win->enableSelection( isEnabled );
894 //clear current selection in the viewer
896 myAISContext->ClearSelected( Standard_True );
902 Sets multiselection enabled status
903 \param isEnabled - new status
905 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
907 myMultiSelectionEnabled = isEnable;
908 //!! To be done for view windows
909 if ( !myViewManager )
912 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
913 for ( int i = 0; i < (int)wins.count(); i++ )
915 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
917 win->updateEnabledDrawMode();
922 Sets a color of the clipped region
923 \param theColor - a new color of the clipped region
925 void OCCViewer_Viewer::setClippingColor( const QColor& theColor )
927 myClippingColor = theColor;
929 if( myInternalClipPlanes.IsEmpty() )
932 for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
933 setCappingColor( aPlaneIt.Value(), theColor );
939 \return clipping color
941 QColor OCCViewer_Viewer::clippingColor() const
943 return myClippingColor;
946 // initialize a texture for clipped region
947 Handle(Graphic3d_Texture2Dmanual) initClippingTexture( const bool isDefault, const QString& theTexture,
948 const bool isModulate, const double theScale )
950 QString aTextureFile = isDefault ? ":images/hatch.png" : theTexture;
951 QPixmap px( aTextureFile );
952 const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
953 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap );
954 if( aTexture->IsDone() ) {
955 aTexture->EnableRepeat();
956 isModulate ? aTexture->EnableModulate() : aTexture->DisableModulate();
957 aTexture->GetParams()->SetScale( Graphic3d_Vec2( 1/( theScale*100 ), -1 / ( theScale*100 ) ) );
963 Sets default texture parameters
964 \param isDefault - use/non-use default texture
965 \param theTexture - new texture of the clipped region
966 \param isModulate - enable/disable texture modulate mode
967 \param theScale - scale factor.
969 void OCCViewer_Viewer::setClippingTextureParams( const bool isDefault, const QString& theTexture,
970 const bool isModulate, const double theScale )
972 myDefaultTextureUsed = isDefault;
973 myClippingTexture = theTexture;
974 myTextureModulated = isModulate;
975 myClippingTextureScale = theScale;
977 if( myInternalClipPlanes.IsEmpty() )
980 Handle(Graphic3d_Texture2Dmanual) aTexture =
981 initClippingTexture( myDefaultTextureUsed, myClippingTexture,
982 myTextureModulated, myClippingTextureScale );
983 #if OCC_VERSION_LARGE <= 0x07030000
984 for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
985 myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
987 for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
988 aPlaneIt.Value()->SetCappingTexture( aTexture );
995 \return true if default texture is used
997 bool OCCViewer_Viewer::isDefaultTextureUsed() const
999 return myDefaultTextureUsed;
1003 \return clipping texture
1005 QString OCCViewer_Viewer::clippingTexture() const
1007 return myClippingTexture;
1011 \return true if texture is modulated
1013 bool OCCViewer_Viewer::isTextureModulated() const
1015 return myTextureModulated;
1019 \return scale factor of texture
1021 double OCCViewer_Viewer::clippingTextureScale() const
1023 return myClippingTextureScale;
1027 Builds popup for occ viewer
1029 void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
1031 thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
1032 thePopup->addAction( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
1034 thePopup->addSeparator();
1036 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1038 //Support of several toolbars in the popup menu
1039 QList<QToolBar*> lst = aView->findChildren<QToolBar*>();
1040 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
1041 for ( ; it!=last; it++ ) {
1042 if ( (*it)->parentWidget()->isVisible() )
1043 thePopup->addAction( (*it)->toggleViewAction() );
1048 SLOT: called on dump view operation is activated, stores scene to raster file
1050 void OCCViewer_Viewer::onDumpView()
1052 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1054 aView->onDumpView();
1058 SLOT: called if background color is to be changed changed, passes new color to view port
1060 void OCCViewer_Viewer::onChangeBackground()
1062 OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
1066 // get supported gradient types
1067 QStringList gradList;
1068 QIntList idList, txtList;
1069 QString formats = backgroundData( gradList, idList, txtList );
1071 // invoke dialog box
1072 Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
1073 aView, // parent for dialog box
1074 txtList, // allowed texture modes
1075 true, // enable solid color mode
1076 true, // enable gradient mode
1077 false, // disable custom gradient mode
1078 !txtList.isEmpty(), // enable/disable texture mode
1079 gradList, // gradient names
1080 idList, // gradient identifiers
1081 formats ); // image formats
1083 // set chosen background data to the viewer
1084 if ( bgData.isValid() )
1085 aView->setBackground( bgData );
1089 Updates OCC 3D viewer
1091 void OCCViewer_Viewer::update()
1093 if (!myV3dViewer.IsNull())
1094 myV3dViewer->Update();
1096 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1098 aView->updateGravityCoords();
1102 \return objects selected in 3D viewer
1103 \param theList - list to be filled with selected objects
1105 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
1108 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
1109 theList.Append(myAISContext->SelectedInteractive());
1113 Selects objects in 3D viewer. Other selected objects are left as selected
1114 \param theList - list objects to be selected
1116 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
1118 AIS_ListIteratorOfListOfInteractive aIt;
1119 for (aIt.Initialize(theList); aIt.More(); aIt.Next())
1120 myAISContext->AddOrRemoveSelected(aIt.Value(), false);
1121 myAISContext->UpdateCurrentViewer();
1125 Auxiliary method to emit signal selectionChanged()
1127 void OCCViewer_Viewer::performSelectionChanged()
1129 emit selectionChanged();
1133 * Defines default lights
1135 void OCCViewer_Viewer::setDefaultLights()
1137 // clear all light sources
1138 myV3dViewer->InitDefinedLights();
1139 while ( myV3dViewer->MoreDefinedLights() )
1141 myV3dViewer->DelLight( myV3dViewer->DefinedLight() );
1142 myV3dViewer->InitDefinedLights();
1145 // get light source parameters from preferences
1146 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "OCCViewer", "light_color", QColor( 0, 0, 0 ) );
1147 double aDx = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dx", 0.0 );
1148 double aDy = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dy", 0.0 );
1149 double aDz = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dz", -1.0 );
1151 Handle(V3d_DirectionalLight) aLight =
1152 new V3d_DirectionalLight( V3d_Zneg, OCCViewer::color( aColor ).Name(), Standard_True );
1153 myV3dViewer->AddLight( aLight );
1154 if( !( aDx == 0 && aDy == 0 && aDz == 0 ) )
1155 aLight->SetDirection( aDx, aDy, aDz );
1156 myV3dViewer->SetLightOn( aLight );
1157 Handle(V3d_AmbientLight) ambLight = new V3d_AmbientLight();
1158 myV3dViewer->AddLight( ambLight );
1159 myV3dViewer->SetLightOn( ambLight );
1163 Hilights/unhilights object in viewer
1164 \param obj - object to be updated
1165 \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
1166 \param update - update current viewer
1168 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
1169 bool hilight, bool update )
1171 if( !obj.IsNull() ) {
1172 #if OCC_VERSION_LARGE <= 0x07030000
1173 if( !myAISContext->HasOpenedContext() )
1176 if ( hilight && !myAISContext->IsSelected( obj ) )
1177 myAISContext->AddOrRemoveSelected( obj, false );
1178 else if ( !hilight && myAISContext->IsSelected( obj ) )
1179 myAISContext->AddOrRemoveSelected( obj, false );
1180 #if OCC_VERSION_LARGE <= 0x07030000
1186 myV3dViewer->Redraw();
1192 Unhilights all objects in viewer
1193 \param updateviewer - update current viewer
1195 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
1197 #if OCC_VERSION_LARGE <= 0x07030000
1198 if ( myAISContext->HasOpenedContext() ) {
1201 myAISContext->ClearSelected( updateviewer );
1203 myAISContext->UnhilightSelected( updateviewer );
1205 #if OCC_VERSION_LARGE <= 0x07030000
1208 myAISContext->ClearCurrents( updateviewer );
1210 myAISContext->UnhilightCurrents( updateviewer );
1218 \return true if object is in viewer or in collector
1219 \param obj - object to be checked
1220 \param onlyInViewer - search object only in viewer (so object must be displayed)
1222 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
1225 AIS_ListOfInteractive List;
1226 myAISContext->DisplayedObjects(List);
1228 AIS_ListIteratorOfListOfInteractive ite(List);
1229 for ( ; ite.More(); ite.Next() )
1230 if( ite.Value()==obj )
1237 \return true if object is displayed in viewer
1238 \param obj - object to be checked
1240 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
1242 return myAISContext->IsDisplayed( obj );
1246 Sets color of object
1247 \param obj - object to be updated
1248 \param color - new color
1249 \param update - update current viewer
1251 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
1252 const QColor& color,
1257 Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
1258 color.green() / 255.,
1259 color.blue() / 255.,
1261 obj->SetColor( CSFColor );
1265 myV3dViewer->Update();
1269 Changes display mode of object
1270 \param obj - object to be processed
1271 \param mode - new display mode
1272 \param update - update current viewer
1274 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
1275 int mode, bool update )
1277 myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, update );
1279 myV3dViewer->Update();
1283 Changes transparency of object
1284 \param obj - object to be processed
1285 \param trans - new transparency
1286 \param update - update current viewer
1288 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
1289 float trans, bool update )
1291 myAISContext->SetTransparency( obj, trans, false );
1292 myAISContext->Redisplay( obj, Standard_False, Standard_True );
1294 myV3dViewer->Update();
1297 bool OCCViewer_Viewer::isColorScaleVisible() const
1299 return !myColorScale.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myColorScale );
1302 void OCCViewer_Viewer::setColorScaleShown( const bool on )
1304 if ( myColorScale.IsNull() )
1308 if ( !myAISContext->IsDisplayed( myColorScale ) )
1309 myAISContext->Display( myColorScale, Standard_True );
1310 myAISContext->Redisplay( myColorScale, Standard_True, Standard_True );
1314 if ( myAISContext->IsDisplayed( myColorScale ) )
1315 myAISContext->Erase( myColorScale, Standard_True );
1320 Changes visibility of trihedron to opposite
1322 void OCCViewer_Viewer::toggleTrihedron()
1324 setTrihedronShown( !isTrihedronVisible() );
1328 \return true if trihedron is visible
1330 bool OCCViewer_Viewer::isTrihedronVisible() const
1332 return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
1336 Sets visibility state of trihedron
1337 \param on - new state
1340 void OCCViewer_Viewer::setTrihedronShown( const bool on )
1342 if ( myTrihedron.IsNull() )
1346 myAISContext->Display( myTrihedron,
1348 -1 /* selection mode */,
1349 Standard_True /* update viewer*/,
1350 Standard_False /* allow decomposition */,
1351 AIS_DS_Displayed /* display status */);
1352 myAISContext->Deactivate( myTrihedron );
1355 myAISContext->Erase( myTrihedron , Standard_True );
1360 \return trihedron size
1362 double OCCViewer_Viewer::trihedronSize() const
1365 if ( !myTrihedron.IsNull() )
1366 sz = myTrihedron->Size();
1371 Changes trihedron size
1372 \param sz - new size
1374 void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative )
1376 if ( myTrihedronSize != sz || isRelative != myIsRelative) {
1377 myTrihedronSize = sz;
1378 myIsRelative = isRelative;
1384 Set number of isolines
1385 \param u - u-isolines (first parametric co-ordinate)
1386 \param v - v-isolines (second parametric co-ordinate)
1388 void OCCViewer_Viewer::setIsos( const int u, const int v )
1390 Handle(AIS_InteractiveContext) ic = getAISContext();
1394 ic->SetIsoNumber( u, AIS_TOI_IsoU );
1395 ic->SetIsoNumber( v, AIS_TOI_IsoV );
1399 \return number of isolines
1400 \param u - to return u-isolines (first parametric co-ordinate)
1401 \param v - to return v-isolines (second parametric co-ordinate)
1403 void OCCViewer_Viewer::isos( int& u, int& v ) const
1405 Handle(AIS_InteractiveContext) ic = getAISContext();
1408 u = ic->IsoNumber( AIS_TOI_IsoU );
1409 v = ic->IsoNumber( AIS_TOI_IsoV );
1414 * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
1416 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
1418 return new OCCViewer_ViewWindow(0, this);
1421 #if OCC_VERSION_LARGE <= 0x07030000
1423 Sets using local selection state
1424 \param theIsUseLocalSelection - state
1426 void OCCViewer_Viewer::setUseLocalSelection(bool theIsUseLocalSelection)
1428 myIsUseLocalSelection = theIsUseLocalSelection;
1432 * Returns true if local context is opened or view model local state is set
1434 bool OCCViewer_Viewer::useLocalSelection() const
1436 if (myIsUseLocalSelection)
1438 Handle(AIS_InteractiveContext) ic = getAISContext();
1439 return !ic.IsNull() && ic->HasOpenedContext();
1444 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
1446 return background( theViewId ).color();
1449 Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
1451 return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
1455 void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
1457 if ( theColor.isValid() ) {
1458 Qtx::BackgroundData bg = background( theViewId );
1459 bg.setColor( theColor );
1460 setBackground( theViewId, bg );
1464 void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
1466 if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
1467 myBackgrounds[theViewId] = theBackground;
1472 Set the show static trihedron flag
1474 void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on)
1476 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1477 if ( aView ) aView->showStaticTrihedron( on );
1481 Get new and current trihedron size corresponding to the current model size
1483 bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
1488 //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
1489 Handle(V3d_Viewer) viewer = getViewer3d();
1490 viewer->InitActiveViews();
1491 if(!viewer->MoreActiveViews()) return false;
1493 Handle(V3d_View) view3d = viewer->ActiveView();
1496 if ( view3d.IsNull() )
1499 double aMaxSide = computeSceneSize( view3d );
1502 // The boundary box of the view may be initialized but nullified
1503 // (case of infinite objects)
1504 if ( aMaxSide < Precision::Confusion() )
1507 float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
1509 static float EPS = 5.0E-3;
1510 theSize = getTrihedron()->Size();
1511 theNewSize = aMaxSide*aSizeInPercents / 100.0;
1513 return fabs( theNewSize - theSize ) > theSize * EPS ||
1514 fabs( theNewSize - theSize ) > theNewSize * EPS;
1518 * Compute scene size
1520 double OCCViewer_Viewer::computeSceneSize(const Handle(V3d_View)& view3d) const
1522 double aMaxSide = 0;
1523 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
1525 Bnd_Box aBox = view3d->View()->MinMaxValues();
1526 Xmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
1527 Ymin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
1528 Zmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
1529 Xmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
1530 Ymax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
1531 Zmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
1533 if ( Xmin != RealFirst() && Ymin != RealFirst() && Zmin != RealFirst() &&
1534 Xmax != RealLast() && Ymax != RealLast() && Zmax != RealLast() )
1536 aMaxSide = Xmax - Xmin;
1537 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
1538 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
1545 * Update the size of the trihedron
1547 void OCCViewer_Viewer::updateTrihedron() {
1548 if ( myTrihedron.IsNull() )
1552 double newSz, oldSz;
1554 if(computeTrihedronSize(newSz, oldSz))
1555 myTrihedron->SetSize(newSz);
1557 } else if(myTrihedron->Size() != myTrihedronSize) {
1558 myTrihedron->SetSize(myTrihedronSize);
1563 Set number of isolines
1564 \param u - u-isolines (first parametric co-ordinate)
1565 \param v - v-isolines (second parametric co-ordinate)
1567 void OCCViewer_Viewer::setSelectionOptions( bool isPreselectionEnabled, bool isSelectionEnabled )
1569 myPreselectionEnabled = isPreselectionEnabled;
1570 mySelectionEnabled = isSelectionEnabled;
1571 //clear current selection in the viewer
1573 if(!mySelectionEnabled) {
1574 myAISContext->ClearSelected( Standard_True );
1579 Creates clipping plane based on the incoming plane
1581 Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn)
1583 Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( thePlane );
1584 aGraphic3dPlane->SetOn( theIsOn );
1585 aGraphic3dPlane->SetCapping( Standard_True );
1587 // set capping color
1588 setCappingColor( aGraphic3dPlane, myClippingColor );
1590 // set capping texture
1591 aGraphic3dPlane->SetCappingTexture( initClippingTexture( myDefaultTextureUsed, myClippingTexture,
1592 myTextureModulated, myClippingTextureScale ) );
1594 return aGraphic3dPlane;
1597 Applies clipping planes to clippable objects
1599 void OCCViewer_Viewer::setClipPlanes(ClipPlanesList theList)
1601 // 1. Remove existing clipping planes
1602 myClipPlanes.clear();
1603 myInternalClipPlanes.Clear();
1605 // 2. Create new clipping planes
1606 ClipPlanesList::iterator inIt = theList.begin();
1607 for (;inIt != theList.end(); inIt++ )
1609 OCCViewer_ClipPlane aPlane = *inIt;
1611 double aDx = 0.0, aDy = 0.0, aDz = 0.0;
1612 aPlane.OrientationToXYZ( aDx, aDy, aDz );
1614 gp_Pnt anOrigin( aPlane.X, aPlane.Y, aPlane.Z );
1615 gp_Dir aDirection( aDx, aDy, aDz );
1617 myInternalClipPlanes.Append( createClipPlane( gp_Pln( anOrigin, aDirection ), aPlane.IsOn ) );
1618 myClipPlanes.push_back( aPlane );
1621 // 3. Apply clipping planes
1622 AIS_ListOfInteractive aList;
1623 myAISContext->DisplayedObjects (aList);
1624 for ( AIS_ListIteratorOfListOfInteractive anIter (aList); anIter.More(); anIter.Next() ) {
1625 Handle(AIS_InteractiveObject) anObj = anIter.Value();
1626 Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anObj);
1627 if (!aShape.IsNull() && aShape->IsClippable()) {
1628 aShape->SetClipPlanes(myInternalClipPlanes);
1634 Returns the clipping planes applied to the displayed objects.
1636 ClipPlanesList OCCViewer_Viewer::getClipPlanes() const {
1637 return myClipPlanes;
1640 Applies clipping planes to given object objects
1642 void OCCViewer_Viewer::applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject)
1644 Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (theObject);
1645 if (!aShape.IsNull() && aShape->IsClippable())
1647 aShape->SetClipPlanes (myInternalClipPlanes);
1652 Returns the pointer to the clipping dialog box.
1654 OCCViewer_ClippingDlg* OCCViewer_Viewer::getClippingDlg() const{
1655 return myClippingDlg;
1660 Stores pointer to the clipping dialog box.
1662 void OCCViewer_Viewer::setClippingDlg(OCCViewer_ClippingDlg* theDlg) {
1663 if(myClippingDlg != theDlg) {
1664 myClippingDlg = theDlg;
1669 bool OCCViewer_Viewer::enableDrawMode( bool on )
1671 //!! To be done for view windows
1672 if ( !myViewManager )
1676 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
1677 for ( int i = 0; i < (int)wins.count(); i++ )
1679 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
1681 prev = prev || win->enableDrawMode( on );