1 // Copyright (C) 2007-2019 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.h"
25 #include "OCCViewer_ViewFrame.h"
26 #include "OCCViewer_VService.h"
27 #include "OCCViewer_ViewPort3d.h"
28 #include "OCCViewer_ClippingDlg.h"
29 #include "OCCViewer_Utilities.h"
31 #include "SUIT_ViewWindow.h"
32 #include "SUIT_ViewManager.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_ResourceMgr.h"
37 #include "ViewerData_AISShape.hxx"
39 #include "QtxActionToolMgr.h"
40 #include "QtxBackgroundTool.h"
43 #include <QApplication>
44 #include <QColorDialog>
45 #include <QFileDialog>
49 #include <QMouseEvent>
51 #include <QDesktopWidget>
53 #include <AIS_Axis.hxx>
54 #include <Prs3d_Drawer.hxx>
55 #include <AIS_ListIteratorOfListOfInteractive.hxx>
56 #include <StdSelect_ViewerSelector3d.hxx>
58 #include <Graphic3d_Texture2Dmanual.hxx>
59 #include <Graphic3d_MaterialAspect.hxx>
60 #include <Graphic3d_TextureParams.hxx>
62 #include <Geom_Axis2Placement.hxx>
63 #include <Prs3d_Drawer.hxx>
64 #include <Prs3d_DatumAspect.hxx>
65 #include <Prs3d_LineAspect.hxx>
66 #include <Prs3d_TextAspect.hxx>
68 #include <V3d_DirectionalLight.hxx>
69 #include <V3d_AmbientLight.hxx>
71 #include <Basics_OCCTVersion.hxx>
74 Get data for supported background modes: gradient types, identifiers and supported image formats
76 QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
78 gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") <<
79 tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
80 tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") <<
81 tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT");
82 idList << HorizontalGradient << VerticalGradient <<
83 Diagonal1Gradient << Diagonal2Gradient <<
84 Corner1Gradient << Corner2Gradient <<
85 Corner3Gradient << Corner4Gradient;
86 txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
87 return tr("BG_IMAGE_FILES");
91 Get data for supported stereo pair modes: stereo types and identifiers
93 void OCCViewer_Viewer::stereoData( QStringList& typeList, QIntList& idList)
95 typeList << tr("ST_QUADBUFFER") << tr("ST_ANAGLYPH") <<
96 tr("ST_ROWINTERLACED") << tr("ST_COLUMNINTERLACED") <<
97 tr("ST_CHESSBOARD") << tr("ST_SIDEBYSIDE") <<
99 idList << QuadBufferType << AnaglyphType <<
100 RowInterlacedType << ColumnInterlacedType <<
101 ChessBoardType << SideBySideType <<
107 \param DisplayTrihedron - is trihedron displayed
109 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
111 myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
114 myTrihedronSize(100),
115 #if OCC_VERSION_LARGE <= 0x07030000
116 myIsUseLocalSelection(false),
118 myClippingDlg (NULL),
121 // init CasCade viewers
122 myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() );
123 //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
127 myAISContext = new AIS_InteractiveContext( myV3dViewer );
128 myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor( Quantity_NOC_WHITE );
129 myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetColor( Quantity_NOC_WHITE );
131 // Set overlap detection for common behaviour of Rect selection and Polygon selection
132 // (both selects an object with partial overlap)
133 myAISContext->MainSelector()->AllowOverlapDetection(true);
135 // display isoline on planar faces (box for ex.)
136 myAISContext->IsoOnPlane( true );
138 // create color scale
139 myColorScale = new AIS_ColorScale();
140 myColorScale->SetZLayer( Graphic3d_ZLayerId_TopOSD );
141 myColorScale->SetTransformPersistence( Graphic3d_TransformPers::FromDeprecatedParams( Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0) ) );
143 /* create trihedron */
144 if ( DisplayTrihedron )
146 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
147 myTrihedron = new AIS_Trihedron(anAxis);
148 myTrihedron->SetInfiniteState( Standard_True );
150 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
151 //myTrihedron->SetColor( Col );
152 myTrihedron->SetArrowColor( Col.Name() );
153 myTrihedron->SetSize(100);
154 Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
155 if (drawer->HasOwnDatumAspect()) {
156 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
157 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
158 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
159 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
163 // set interaction style to standard
164 myInteractionStyle = 0;
166 // set zooming style to standard
170 myPreselectionEnabled = true;
173 mySelectionEnabled = true;
174 myMultiSelectionEnabled = true;
176 // set projection type to orthographic
177 myProjectionType = 0;
178 mySelectionStyle = OCCViewer_ViewWindow::RectStyle;
179 // set stereo parameters
181 myAnaglyphFilter = 0;
182 myToReverseStereo = 0;
184 myQuadBufferSupport = 0;
185 myStereographicFocusType = 1;
186 myInterocularDistanceType = 1;
187 myStereographicFocusValue = 1.0;
188 myInterocularDistanceValue = 0.05;
189 //set clipping color and texture to standard
190 myClippingColor = QColor( 50, 50, 50 );
191 myDefaultTextureUsed = true;
192 myClippingTexture = QString();
193 myTextureModulated = true;
194 myClippingTextureScale = 1.0;
201 OCCViewer_Viewer::~OCCViewer_Viewer()
203 myAISContext.Nullify();
204 myV3dViewer.Nullify();
209 \return background color of viewer
211 QColor OCCViewer_Viewer::backgroundColor() const
213 return backgroundColor(0);
217 \return background data of viewer
219 Qtx::BackgroundData OCCViewer_Viewer::background() const
221 return background(0);
225 Sets background color [obsolete]
226 \param c - new background color
228 void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
230 setBackgroundColor( 0, c );
235 \param d - new background data
237 void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
239 setBackground( 0, theBackground );
243 Start initialization of view window
244 \param view - view window to be initialized
246 void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
250 view->initSketchers();
251 view->setInteractionStyle( interactionStyle() );
252 view->setProjectionType( projectionType() );
253 view->setSelectionStyle( selectionStyle() );
254 view->setStereoType( stereoType() );
255 view->setAnaglyphFilter( anaglyphFilter() );
256 view->setStereographicFocus( stereographicFocusType(), stereographicFocusValue() );
257 view->setInterocularDistance( interocularDistanceType(), interocularDistanceValue() );
258 view->setReverseStereo( isReverseStereo() );
259 view->setVSync( isVSync() );
260 view->setQuadBufferSupport( isQuadBufferSupport() );
261 view->setZoomingStyle( zoomingStyle() );
262 view->enablePreselection( isPreselectionEnabled() );
263 view->enableSelection( isSelectionEnabled() );
265 OCCViewer_ViewPort3d* vp3d = view->getViewPort();
268 // connect signal from viewport
269 connect(vp3d, SIGNAL(vpClosed(OCCViewer_ViewPort3d*)), this, SLOT(onViewClosed(OCCViewer_ViewPort3d*)));
270 connect(vp3d, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewMapped(OCCViewer_ViewPort3d*)));
276 Creates new view window
277 \param theDesktop - main window of application
279 SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
282 OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
283 // get main view window (created by view frame)
284 OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
285 // initialize main view window
287 // set default background for view window
288 vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
294 Sets new view manager
295 \param theViewManager - new view manager
297 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
299 SUIT_ViewModel::setViewManager(theViewManager);
300 if (theViewManager) {
301 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
302 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
304 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
305 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
307 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
308 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
310 connect(theViewManager, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
311 this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
316 SLOT: called on mouse button press, stores current mouse position as start point for transformations
318 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
320 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
324 SLOT: called on mouse move, processes transformation or hilighting
326 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
328 if (!mySelectionEnabled) return;
329 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
331 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
333 myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
335 if ( isSelectionEnabled() && isPreselectionEnabled() ) {
336 if (aView->getViewPort()->isBusy()) {
337 QCoreApplication::processEvents();
338 return; // Check that the ViewPort initialization completed
339 // To Prevent call move event if the View port is not initialized
342 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
343 if ( !aView3d.IsNull() ) {
344 myAISContext->MoveTo( theEvent->x(), theEvent->y(), aView3d, Standard_True );
351 SLOT: called on mouse button release, finishes transformation or selection
353 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
355 if (!mySelectionEnabled) return;
356 if (theEvent->button() != Qt::LeftButton) return;
357 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
359 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
363 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
364 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
367 if (myStartPnt == myEndPnt)
370 myAISContext->ClearCurrents( false );
373 if ( !isPreselectionEnabled() ) {
374 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
375 if ( !aView3d.IsNull() ) {
376 myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
380 if (aHasShift && myMultiSelectionEnabled)
381 myAISContext->ShiftSelect( Standard_True );
383 myAISContext->Select( Standard_True );
387 // if (aHasShift && myMultiSelectionEnabled)
388 // myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
389 // myEndPnt.x(), myEndPnt.y(),
390 // aView->getViewPort()->getView(), Standard_False );
392 // myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
393 // myEndPnt.x(), myEndPnt.y(),
394 // aView->getViewPort()->getView(), Standard_False );
396 // int Nb = myAISContext->NbSelected();
397 // if( Nb>1 && !myMultiSelectionEnabled )
399 // myAISContext->InitSelected();
400 // Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
401 // if( !anOwner.IsNull() )
403 // myAISContext->ClearSelected( Standard_False );
404 // myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
408 // myAISContext->UpdateCurrentViewer();
410 emit selectionChanged();
414 SLOT: called on key press, processes selection in "key free" interaction style
416 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
418 if (!mySelectionEnabled) return;
420 OCCViewer_ViewWindow* aView = qobject_cast<OCCViewer_ViewWindow*>( theWindow );
421 if ( !aView ) return;
423 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
425 switch ( theEvent->key() ) {
428 myAISContext->ClearCurrents( false );
432 if ( !isPreselectionEnabled() ) {
433 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
434 if ( !aView3d.IsNull() ) {
435 myAISContext->MoveTo(myCurPnt.x(), myCurPnt.y(), aView3d, Standard_True );
439 if (aHasShift && myMultiSelectionEnabled)
440 myAISContext->ShiftSelect( Standard_True );
442 myAISContext->Select( Standard_True );
444 emit selectionChanged();
448 if ( isPreselectionEnabled() ) {
449 #if OCC_VERSION_LARGE <= 0x07030000
450 if ( useLocalSelection() )
452 getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
456 if ( isPreselectionEnabled() ) {
457 #if OCC_VERSION_LARGE <= 0x07030000
458 if ( useLocalSelection() )
460 getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
468 void OCCViewer_Viewer::onViewClosed(OCCViewer_ViewPort3d*)
470 Standard_Integer aViewsNb = 0;
471 for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
473 if ( aViewsNb < 2 ) {
474 //clean up presentations before last view is closed
475 myAISContext->RemoveAll(Standard_False);
479 void OCCViewer_Viewer::onViewMapped(OCCViewer_ViewPort3d* viewPort)
481 setTrihedronShown( true );
482 bool showStaticTrihedron = true;
483 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
484 if ( resMgr ) showStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
485 viewPort->showStaticTrihedron( showStaticTrihedron );
488 int OCCViewer_Viewer::getTopLayerId()
490 if ( myTopLayerId == 0 && !myAISContext->CurrentViewer().IsNull() )
491 myAISContext->CurrentViewer()->AddZLayer( myTopLayerId );
497 \return interaction style
499 int OCCViewer_Viewer::interactionStyle() const
501 return myInteractionStyle;
505 Sets interaction style: 0 - standard, 1 - keyboard free interaction
506 \param theStyle - new interaction style
508 void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
510 myInteractionStyle = theStyle;
511 //!! To be done for view windows
512 if ( !myViewManager )
515 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
516 for ( int i = 0; i < (int)wins.count(); i++ )
518 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
520 win->setInteractionStyle( theStyle );
525 \return projection type
527 int OCCViewer_Viewer::projectionType() const
529 return myProjectionType;
533 Sets projection type: 0 - orthographic, 1 - perspective
534 \param theType - new projection type
536 void OCCViewer_Viewer::setProjectionType( const int theType )
538 if ( myProjectionType != theType ) {
539 if ( theType != OCCViewer_ViewWindow::Stereo )
540 myProjectionType = theType;
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->setProjectionType( (OCCViewer_ViewWindow::ProjectionType)theType );
556 OCCViewer_ViewWindow::SelectionStyle OCCViewer_Viewer::selectionStyle() const
558 return mySelectionStyle;
561 void OCCViewer_Viewer::setSelectionStyle(OCCViewer_ViewWindow::SelectionStyle theMode)
563 if (mySelectionStyle != theMode) {
564 mySelectionStyle = theMode;
568 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
569 for (int i = 0; i < (int)wins.count(); i++)
571 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>(wins.at(i));
573 win->setSelectionStyle(theMode);
583 int OCCViewer_Viewer::stereoType() const
590 \param theType - new stereo type
592 void OCCViewer_Viewer::setStereoType( const int theType )
594 myStereoType = theType;
596 if ( !myViewManager )
599 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
600 for ( int i = 0; i < (int)wins.count(); i++ )
602 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
604 win->setStereoType( (OCCViewer_ViewWindow::StereoType)theType );
609 \return stereographic focus type
611 int OCCViewer_Viewer::stereographicFocusType() const
613 return myStereographicFocusType;
617 \return stereographic focus value
619 double OCCViewer_Viewer::stereographicFocusValue() const
621 return myStereographicFocusValue;
625 Sets stereographic focus parameters
626 \param theType - new stereographic focus type
627 \param theValue - new stereographic focus value
629 void OCCViewer_Viewer::setStereographicFocus( const int theType, const double theValue )
631 myStereographicFocusType = theType;
632 myStereographicFocusValue = theValue;
634 if ( !myViewManager )
637 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
638 for ( int i = 0; i < (int)wins.count(); i++ )
640 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
642 win->setStereographicFocus( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
647 \return stereographic focus type
649 int OCCViewer_Viewer::interocularDistanceType() const
651 return myInterocularDistanceType;
655 \return stereographic focus value
657 double OCCViewer_Viewer::interocularDistanceValue() const
659 return myInterocularDistanceValue;
663 Sets interocular distance parameters
664 \param theType - new IOD type
665 \param theValue - new IOD value
667 void OCCViewer_Viewer::setInterocularDistance( const int theType, const double theValue )
669 myInterocularDistanceType = theType;
670 myInterocularDistanceValue = theValue;
672 if ( !myViewManager )
675 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
676 for ( int i = 0; i < (int)wins.count(); i++ )
678 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
680 win->setInterocularDistance( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
685 \return anaglyph filter
687 int OCCViewer_Viewer::anaglyphFilter() const
689 return myAnaglyphFilter;
694 \param theType - new anaglyph filter
696 void OCCViewer_Viewer::setAnaglyphFilter( const int theType )
698 myAnaglyphFilter = theType;
700 if ( !myViewManager )
703 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
704 for ( int i = 0; i < (int)wins.count(); i++ )
706 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
708 win->setAnaglyphFilter( (OCCViewer_ViewWindow::AnaglyphFilter)theType );
713 \return reverse stereo
715 bool OCCViewer_Viewer::isReverseStereo() const
717 return myToReverseStereo;
722 \param theReverse - enable/disable reverse mode
724 void OCCViewer_Viewer::setReverseStereo( const bool theReverse )
726 myToReverseStereo = theReverse;
728 if ( !myViewManager )
731 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
732 for ( int i = 0; i < (int)wins.count(); i++ )
734 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
736 win->setReverseStereo( theReverse );
743 bool OCCViewer_Viewer::isVSync() const
750 \param theEnable - enable/disable V-Sync mode
752 void OCCViewer_Viewer::setVSync( const bool theEnable )
754 myVSyncMode = theEnable;
756 if ( !myViewManager )
759 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
760 for ( int i = 0; i < (int)wins.count(); i++ )
762 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
764 win->setVSync( theEnable );
769 \return support quad-buffered stereo
771 bool OCCViewer_Viewer::isQuadBufferSupport() const
773 return myQuadBufferSupport;
777 Set support quad-buffered stereo
778 \param theEnable - enable/disable support quad-buffered stereo
780 void OCCViewer_Viewer::setQuadBufferSupport( const bool theEnable )
782 myQuadBufferSupport = theEnable;
784 if ( !myViewManager )
787 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
788 for ( int i = 0; i < (int)wins.count(); i++ )
790 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
792 win->setQuadBufferSupport( theEnable );
797 \return zooming style
799 int OCCViewer_Viewer::zoomingStyle() const
801 return myZoomingStyle;
805 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
806 \param theStyle - new zooming style
808 void OCCViewer_Viewer::setZoomingStyle( const int theStyle )
810 myZoomingStyle = theStyle;
811 //!! To be done for view windows
812 if ( !myViewManager )
815 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
816 for ( int i = 0; i < (int)wins.count(); i++ )
818 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
820 win->setZoomingStyle( theStyle );
825 \return true if preselection is enabled
827 bool OCCViewer_Viewer::isPreselectionEnabled() const
829 return myPreselectionEnabled;
833 Enables/disables preselection
834 \param isEnabled - new status
836 void OCCViewer_Viewer::enablePreselection(bool isEnabled)
838 myPreselectionEnabled = isEnabled;
840 if ( !myViewManager )
843 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
844 for ( int i = 0; i < (int)wins.count(); i++ )
846 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
848 win->enablePreselection( isEnabled );
854 \return true if selection is enabled
856 bool OCCViewer_Viewer::isSelectionEnabled() const
858 return mySelectionEnabled;
862 Enables/disables selection
863 \param isEnabled - new status
865 void OCCViewer_Viewer::enableSelection(bool isEnabled)
867 mySelectionEnabled = isEnabled;
869 //!! To be done for view windows
870 if ( !myViewManager )
873 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
874 for ( int i = 0; i < (int)wins.count(); i++ )
876 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
878 win->updateEnabledDrawMode();
879 win->enableSelection( isEnabled );
884 //clear current selection in the viewer
886 myAISContext->ClearSelected( Standard_True );
892 Sets multiselection enabled status
893 \param isEnabled - new status
895 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
897 myMultiSelectionEnabled = isEnable;
898 //!! To be done for view windows
899 if ( !myViewManager )
902 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
903 for ( int i = 0; i < (int)wins.count(); i++ )
905 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
907 win->updateEnabledDrawMode();
912 Sets a color of the clipped region
913 \param theColor - a new color of the clipped region
915 void OCCViewer_Viewer::setClippingColor( const QColor& theColor )
917 myClippingColor = theColor;
919 if( myInternalClipPlanes.IsEmpty() )
922 Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
923 aMaterialAspect.SetColor( Quantity_Color( theColor.redF(), theColor.greenF(),
924 theColor.blueF(), Quantity_TOC_RGB ) );
925 #if OCC_VERSION_LARGE <= 0x07030000
926 for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
927 myInternalClipPlanes.Value(i)->SetCappingMaterial( aMaterialAspect );
929 for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
930 aPlaneIt.Value()->SetCappingMaterial( aMaterialAspect );
936 \return clipping color
938 QColor OCCViewer_Viewer::clippingColor() const
940 return myClippingColor;
943 // initialize a texture for clipped region
944 Handle(Graphic3d_Texture2Dmanual) initClippingTexture( const bool isDefault, const QString& theTexture,
945 const bool isModulate, const double theScale )
947 QString aTextureFile = isDefault ? ":images/hatch.png" : theTexture;
948 QPixmap px( aTextureFile );
949 const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
950 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap );
951 if( aTexture->IsDone() ) {
952 aTexture->EnableRepeat();
953 isModulate ? aTexture->EnableModulate() : aTexture->DisableModulate();
954 aTexture->GetParams()->SetScale( Graphic3d_Vec2( 1/( theScale*100 ), -1 / ( theScale*100 ) ) );
960 Sets default texture parameters
961 \param isDefault - use/non-use default texture
962 \param theTexture - new texture of the clipped region
963 \param isModulate - enable/disable texture modulate mode
964 \param theScale - scale factor.
966 void OCCViewer_Viewer::setClippingTextureParams( const bool isDefault, const QString& theTexture,
967 const bool isModulate, const double theScale )
969 myDefaultTextureUsed = isDefault;
970 myClippingTexture = theTexture;
971 myTextureModulated = isModulate;
972 myClippingTextureScale = theScale;
974 if( myInternalClipPlanes.IsEmpty() )
977 Handle(Graphic3d_Texture2Dmanual) aTexture =
978 initClippingTexture( myDefaultTextureUsed, myClippingTexture,
979 myTextureModulated, myClippingTextureScale );
980 #if OCC_VERSION_LARGE <= 0x07030000
981 for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
982 myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
984 for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
985 aPlaneIt.Value()->SetCappingTexture( aTexture );
992 \return true if default texture is used
994 bool OCCViewer_Viewer::isDefaultTextureUsed() const
996 return myDefaultTextureUsed;
1000 \return clipping texture
1002 QString OCCViewer_Viewer::clippingTexture() const
1004 return myClippingTexture;
1008 \return true if texture is modulated
1010 bool OCCViewer_Viewer::isTextureModulated() const
1012 return myTextureModulated;
1016 \return scale factor of texture
1018 double OCCViewer_Viewer::clippingTextureScale() const
1020 return myClippingTextureScale;
1024 Builds popup for occ viewer
1026 void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
1028 thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
1029 thePopup->addAction( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
1031 thePopup->addSeparator();
1033 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1035 //Support of several toolbars in the popup menu
1036 QList<QToolBar*> lst = aView->findChildren<QToolBar*>();
1037 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
1038 for ( ; it!=last; it++ ) {
1039 if ( (*it)->parentWidget()->isVisible() )
1040 thePopup->addAction( (*it)->toggleViewAction() );
1045 SLOT: called on dump view operation is activated, stores scene to raster file
1047 void OCCViewer_Viewer::onDumpView()
1049 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1051 aView->onDumpView();
1055 SLOT: called if background color is to be changed changed, passes new color to view port
1057 void OCCViewer_Viewer::onChangeBackground()
1059 OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
1063 // get supported gradient types
1064 QStringList gradList;
1065 QIntList idList, txtList;
1066 QString formats = backgroundData( gradList, idList, txtList );
1068 // invoke dialog box
1069 Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
1070 aView, // parent for dialog box
1071 txtList, // allowed texture modes
1072 true, // enable solid color mode
1073 true, // enable gradient mode
1074 false, // disable custom gradient mode
1075 !txtList.isEmpty(), // enable/disable texture mode
1076 gradList, // gradient names
1077 idList, // gradient identifiers
1078 formats ); // image formats
1080 // set chosen background data to the viewer
1081 if ( bgData.isValid() )
1082 aView->setBackground( bgData );
1086 Updates OCC 3D viewer
1088 void OCCViewer_Viewer::update()
1090 if (!myV3dViewer.IsNull())
1091 myV3dViewer->Update();
1093 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1095 aView->updateGravityCoords();
1099 \return objects selected in 3D viewer
1100 \param theList - list to be filled with selected objects
1102 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
1105 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
1106 theList.Append(myAISContext->SelectedInteractive());
1110 Selects objects in 3D viewer. Other selected objects are left as selected
1111 \param theList - list objects to be selected
1113 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
1115 AIS_ListIteratorOfListOfInteractive aIt;
1116 for (aIt.Initialize(theList); aIt.More(); aIt.Next())
1117 myAISContext->AddOrRemoveSelected(aIt.Value(), false);
1118 myAISContext->UpdateCurrentViewer();
1122 Auxiliary method to emit signal selectionChanged()
1124 void OCCViewer_Viewer::performSelectionChanged()
1126 emit selectionChanged();
1130 * Defines default lights
1132 void OCCViewer_Viewer::setDefaultLights()
1134 // clear all light sources
1135 myV3dViewer->InitDefinedLights();
1136 while ( myV3dViewer->MoreDefinedLights() )
1138 myV3dViewer->DelLight( myV3dViewer->DefinedLight() );
1139 myV3dViewer->InitDefinedLights();
1142 // get light source parameters from preferences
1143 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "OCCViewer", "light_color", QColor( 0, 0, 0 ) );
1144 double aDx = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dx", 0.0 );
1145 double aDy = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dy", 0.0 );
1146 double aDz = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dz", -1.0 );
1148 Handle(V3d_DirectionalLight) aLight =
1149 new V3d_DirectionalLight( V3d_Zneg, OCCViewer::color( aColor ).Name(), Standard_True );
1150 myV3dViewer->AddLight( aLight );
1151 if( !( aDx == 0 && aDy == 0 && aDz == 0 ) )
1152 aLight->SetDirection( aDx, aDy, aDz );
1153 myV3dViewer->SetLightOn( aLight );
1154 Handle(V3d_AmbientLight) ambLight = new V3d_AmbientLight();
1155 myV3dViewer->AddLight( ambLight );
1156 myV3dViewer->SetLightOn( ambLight );
1160 Hilights/unhilights object in viewer
1161 \param obj - object to be updated
1162 \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
1163 \param update - update current viewer
1165 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
1166 bool hilight, bool update )
1168 if( !obj.IsNull() ) {
1169 #if OCC_VERSION_LARGE <= 0x07030000
1170 if( !myAISContext->HasOpenedContext() )
1173 if ( hilight && !myAISContext->IsSelected( obj ) )
1174 myAISContext->AddOrRemoveSelected( obj, false );
1175 else if ( !hilight && myAISContext->IsSelected( obj ) )
1176 myAISContext->AddOrRemoveSelected( obj, false );
1177 #if OCC_VERSION_LARGE <= 0x07030000
1183 myV3dViewer->Redraw();
1189 Unhilights all objects in viewer
1190 \param updateviewer - update current viewer
1192 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
1194 #if OCC_VERSION_LARGE <= 0x07030000
1195 if ( myAISContext->HasOpenedContext() ) {
1198 myAISContext->ClearSelected( updateviewer );
1200 myAISContext->UnhilightSelected( updateviewer );
1202 #if OCC_VERSION_LARGE <= 0x07030000
1205 myAISContext->ClearCurrents( updateviewer );
1207 myAISContext->UnhilightCurrents( updateviewer );
1215 \return true if object is in viewer or in collector
1216 \param obj - object to be checked
1217 \param onlyInViewer - search object only in viewer (so object must be displayed)
1219 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
1222 AIS_ListOfInteractive List;
1223 myAISContext->DisplayedObjects(List);
1225 AIS_ListIteratorOfListOfInteractive ite(List);
1226 for ( ; ite.More(); ite.Next() )
1227 if( ite.Value()==obj )
1234 \return true if object is displayed in viewer
1235 \param obj - object to be checked
1237 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
1239 return myAISContext->IsDisplayed( obj );
1243 Sets color of object
1244 \param obj - object to be updated
1245 \param color - new color
1246 \param update - update current viewer
1248 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
1249 const QColor& color,
1254 Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
1255 color.green() / 255.,
1256 color.blue() / 255.,
1258 obj->SetColor( CSFColor );
1262 myV3dViewer->Update();
1266 Changes display mode of object
1267 \param obj - object to be processed
1268 \param mode - new display mode
1269 \param update - update current viewer
1271 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
1272 int mode, bool update )
1274 myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, update );
1276 myV3dViewer->Update();
1280 Changes transparency of object
1281 \param obj - object to be processed
1282 \param trans - new transparency
1283 \param update - update current viewer
1285 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
1286 float trans, bool update )
1288 myAISContext->SetTransparency( obj, trans, false );
1289 myAISContext->Redisplay( obj, Standard_False, Standard_True );
1291 myV3dViewer->Update();
1294 bool OCCViewer_Viewer::isColorScaleVisible() const
1296 return !myColorScale.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myColorScale );
1299 void OCCViewer_Viewer::setColorScaleShown( const bool on )
1301 if ( myColorScale.IsNull() )
1305 if ( !myAISContext->IsDisplayed( myColorScale ) )
1306 myAISContext->Display( myColorScale, Standard_True );
1307 myAISContext->Redisplay( myColorScale, Standard_True, Standard_True );
1311 if ( myAISContext->IsDisplayed( myColorScale ) )
1312 myAISContext->Erase( myColorScale, Standard_True );
1317 Changes visibility of trihedron to opposite
1319 void OCCViewer_Viewer::toggleTrihedron()
1321 setTrihedronShown( !isTrihedronVisible() );
1325 \return true if trihedron is visible
1327 bool OCCViewer_Viewer::isTrihedronVisible() const
1329 return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
1333 Sets visibility state of trihedron
1334 \param on - new state
1337 void OCCViewer_Viewer::setTrihedronShown( const bool on )
1339 if ( myTrihedron.IsNull() )
1343 myAISContext->Display( myTrihedron,
1345 -1 /* selection mode */,
1346 Standard_True /* update viewer*/,
1347 Standard_False /* allow decomposition */,
1348 AIS_DS_Displayed /* display status */);
1349 myAISContext->Deactivate( myTrihedron );
1352 myAISContext->Erase( myTrihedron , Standard_True );
1357 \return trihedron size
1359 double OCCViewer_Viewer::trihedronSize() const
1362 if ( !myTrihedron.IsNull() )
1363 sz = myTrihedron->Size();
1368 Changes trihedron size
1369 \param sz - new size
1371 void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative )
1373 if ( myTrihedronSize != sz || isRelative != myIsRelative) {
1374 myTrihedronSize = sz;
1375 myIsRelative = isRelative;
1381 Set number of isolines
1382 \param u - u-isolines (first parametric co-ordinate)
1383 \param v - v-isolines (second parametric co-ordinate)
1385 void OCCViewer_Viewer::setIsos( const int u, const int v )
1387 Handle(AIS_InteractiveContext) ic = getAISContext();
1391 ic->SetIsoNumber( u, AIS_TOI_IsoU );
1392 ic->SetIsoNumber( v, AIS_TOI_IsoV );
1396 \return number of isolines
1397 \param u - to return u-isolines (first parametric co-ordinate)
1398 \param v - to return v-isolines (second parametric co-ordinate)
1400 void OCCViewer_Viewer::isos( int& u, int& v ) const
1402 Handle(AIS_InteractiveContext) ic = getAISContext();
1405 u = ic->IsoNumber( AIS_TOI_IsoU );
1406 v = ic->IsoNumber( AIS_TOI_IsoV );
1411 * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
1413 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
1415 return new OCCViewer_ViewWindow(0, this);
1418 #if OCC_VERSION_LARGE <= 0x07030000
1420 Sets using local selection state
1421 \param theIsUseLocalSelection - state
1423 void OCCViewer_Viewer::setUseLocalSelection(bool theIsUseLocalSelection)
1425 myIsUseLocalSelection = theIsUseLocalSelection;
1429 * Returns true if local context is opened or view model local state is set
1431 bool OCCViewer_Viewer::useLocalSelection() const
1433 if (myIsUseLocalSelection)
1435 Handle(AIS_InteractiveContext) ic = getAISContext();
1436 return !ic.IsNull() && ic->HasOpenedContext();
1441 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
1443 return background( theViewId ).color();
1446 Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
1448 return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
1452 void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
1454 if ( theColor.isValid() ) {
1455 Qtx::BackgroundData bg = background( theViewId );
1456 bg.setColor( theColor );
1457 setBackground( theViewId, bg );
1461 void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
1463 if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
1464 myBackgrounds[theViewId] = theBackground;
1469 Set the show static trihedron flag
1471 void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on)
1473 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1474 if ( aView ) aView->showStaticTrihedron( on );
1478 Get new and current trihedron size corresponding to the current model size
1480 bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
1485 //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
1486 Handle(V3d_Viewer) viewer = getViewer3d();
1487 viewer->InitActiveViews();
1488 if(!viewer->MoreActiveViews()) return false;
1490 Handle(V3d_View) view3d = viewer->ActiveView();
1493 if ( view3d.IsNull() )
1496 double aMaxSide = computeSceneSize( view3d );
1499 // The boundary box of the view may be initialized but nullified
1500 // (case of infinite objects)
1501 if ( aMaxSide < Precision::Confusion() )
1504 float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
1506 static float EPS = 5.0E-3;
1507 theSize = getTrihedron()->Size();
1508 theNewSize = aMaxSide*aSizeInPercents / 100.0;
1510 return fabs( theNewSize - theSize ) > theSize * EPS ||
1511 fabs( theNewSize - theSize ) > theNewSize * EPS;
1515 * Compute scene size
1517 double OCCViewer_Viewer::computeSceneSize(const Handle(V3d_View)& view3d) const
1519 double aMaxSide = 0;
1520 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
1522 Bnd_Box aBox = view3d->View()->MinMaxValues();
1523 Xmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
1524 Ymin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
1525 Zmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
1526 Xmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
1527 Ymax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
1528 Zmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
1530 if ( Xmin != RealFirst() && Ymin != RealFirst() && Zmin != RealFirst() &&
1531 Xmax != RealLast() && Ymax != RealLast() && Zmax != RealLast() )
1533 aMaxSide = Xmax - Xmin;
1534 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
1535 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
1542 * Update the size of the trihedron
1544 void OCCViewer_Viewer::updateTrihedron() {
1545 if ( myTrihedron.IsNull() )
1549 double newSz, oldSz;
1551 if(computeTrihedronSize(newSz, oldSz))
1552 myTrihedron->SetSize(newSz);
1554 } else if(myTrihedron->Size() != myTrihedronSize) {
1555 myTrihedron->SetSize(myTrihedronSize);
1560 Set number of isolines
1561 \param u - u-isolines (first parametric co-ordinate)
1562 \param v - v-isolines (second parametric co-ordinate)
1564 void OCCViewer_Viewer::setSelectionOptions( bool isPreselectionEnabled, bool isSelectionEnabled )
1566 myPreselectionEnabled = isPreselectionEnabled;
1567 mySelectionEnabled = isSelectionEnabled;
1568 //clear current selection in the viewer
1570 if(!mySelectionEnabled) {
1571 myAISContext->ClearSelected( Standard_True );
1576 Creates clipping plane based on the incoming plane
1578 Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn)
1580 Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( thePlane );
1581 aGraphic3dPlane->SetOn( theIsOn );
1582 aGraphic3dPlane->SetCapping( Standard_True );
1584 // set capping color
1585 Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
1586 aMaterialAspect.SetColor( Quantity_Color( myClippingColor.redF(), myClippingColor.greenF(),
1587 myClippingColor.blueF(), Quantity_TOC_RGB ) );
1588 aGraphic3dPlane->SetCappingMaterial( aMaterialAspect );
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 );