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_ViewWindow.h"
26 #include "OCCViewer_ViewFrame.h"
27 #include "OCCViewer_VService.h"
28 #include "OCCViewer_ViewPort3d.h"
29 #include "OCCViewer_ClippingDlg.h"
30 #include "OCCViewer_Utilities.h"
32 #include "SUIT_ViewWindow.h"
33 #include "SUIT_ViewManager.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_ResourceMgr.h"
38 #include "ViewerData_AISShape.hxx"
40 #include "QtxActionToolMgr.h"
41 #include "QtxBackgroundTool.h"
44 #include <QApplication>
45 #include <QColorDialog>
46 #include <QFileDialog>
50 #include <QMouseEvent>
52 #include <QDesktopWidget>
54 #include <AIS_Axis.hxx>
55 #include <Prs3d_Drawer.hxx>
56 #include <AIS_ListIteratorOfListOfInteractive.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 // display isoline on planar faces (box for ex.)
132 myAISContext->IsoOnPlane( true );
134 // create color scale
135 myColorScale = new AIS_ColorScale();
136 myColorScale->SetZLayer( Graphic3d_ZLayerId_TopOSD );
137 myColorScale->SetTransformPersistence( Graphic3d_TransformPers::FromDeprecatedParams( Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0) ) );
139 /* create trihedron */
140 if ( DisplayTrihedron )
142 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
143 myTrihedron = new AIS_Trihedron(anAxis);
144 myTrihedron->SetInfiniteState( Standard_True );
146 Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
147 //myTrihedron->SetColor( Col );
148 myTrihedron->SetArrowColor( Col.Name() );
149 myTrihedron->SetSize(100);
150 Handle(Prs3d_Drawer) drawer = myTrihedron->Attributes();
151 if (drawer->HasOwnDatumAspect()) {
152 Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
153 daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
154 daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
155 daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
159 // set interaction style to standard
160 myInteractionStyle = 0;
162 // set zooming style to standard
166 myPreselectionEnabled = true;
169 mySelectionEnabled = true;
170 myMultiSelectionEnabled = true;
172 // set projection type to orthographic
173 myProjectionType = 0;
174 mySelectionStyle = 0;
175 // set stereo parameters
177 myAnaglyphFilter = 0;
178 myToReverseStereo = 0;
180 myQuadBufferSupport = 0;
181 myStereographicFocusType = 1;
182 myInterocularDistanceType = 1;
183 myStereographicFocusValue = 1.0;
184 myInterocularDistanceValue = 0.05;
185 //set clipping color and texture to standard
186 myClippingColor = QColor( 50, 50, 50 );
187 myDefaultTextureUsed = true;
188 myClippingTexture = QString();
189 myTextureModulated = true;
190 myClippingTextureScale = 1.0;
197 OCCViewer_Viewer::~OCCViewer_Viewer()
199 myAISContext.Nullify();
200 myV3dViewer.Nullify();
205 \return background color of viewer
207 QColor OCCViewer_Viewer::backgroundColor() const
209 return backgroundColor(0);
213 \return background data of viewer
215 Qtx::BackgroundData OCCViewer_Viewer::background() const
217 return background(0);
221 Sets background color [obsolete]
222 \param c - new background color
224 void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
226 setBackgroundColor( 0, c );
231 \param d - new background data
233 void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
235 setBackground( 0, theBackground );
239 Start initialization of view window
240 \param view - view window to be initialized
242 void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
246 view->initSketchers();
247 view->setInteractionStyle( interactionStyle() );
248 view->setProjectionType( projectionType() );
249 view->setSelectionStyle( selectionStyle() );
250 view->setStereoType( stereoType() );
251 view->setAnaglyphFilter( anaglyphFilter() );
252 view->setStereographicFocus( stereographicFocusType(), stereographicFocusValue() );
253 view->setInterocularDistance( interocularDistanceType(), interocularDistanceValue() );
254 view->setReverseStereo( isReverseStereo() );
255 view->setVSync( isVSync() );
256 view->setQuadBufferSupport( isQuadBufferSupport() );
257 view->setZoomingStyle( zoomingStyle() );
258 view->enablePreselection( isPreselectionEnabled() );
259 view->enableSelection( isSelectionEnabled() );
261 OCCViewer_ViewPort3d* vp3d = view->getViewPort();
264 // connect signal from viewport
265 connect(vp3d, SIGNAL(vpClosed(OCCViewer_ViewPort3d*)), this, SLOT(onViewClosed(OCCViewer_ViewPort3d*)));
266 connect(vp3d, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewMapped(OCCViewer_ViewPort3d*)));
272 Creates new view window
273 \param theDesktop - main window of application
275 SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
278 OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
279 // get main view window (created by view frame)
280 OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
281 // initialize main view window
283 // set default background for view window
284 vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
290 Sets new view manager
291 \param theViewManager - new view manager
293 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
295 SUIT_ViewModel::setViewManager(theViewManager);
296 if (theViewManager) {
297 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
298 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
300 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
301 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
303 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
304 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
306 connect(theViewManager, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
307 this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
312 SLOT: called on mouse button press, stores current mouse position as start point for transformations
314 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
316 myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
320 SLOT: called on mouse move, processes transformation or hilighting
322 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
324 if (!mySelectionEnabled) return;
325 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
327 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
329 myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
331 if ( isSelectionEnabled() && isPreselectionEnabled() ) {
332 if (aView->getViewPort()->isBusy()) {
333 QCoreApplication::processEvents();
334 return; // Check that the ViewPort initialization completed
335 // To Prevent call move event if the View port is not initialized
338 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
339 if ( !aView3d.IsNull() ) {
340 myAISContext->MoveTo( theEvent->x(), theEvent->y(), aView3d, Standard_True );
347 SLOT: called on mouse button release, finishes transformation or selection
349 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
351 if (!mySelectionEnabled) return;
352 if (theEvent->button() != Qt::LeftButton) return;
353 if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
355 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
359 myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
360 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
363 myAISContext->ClearCurrents( false );
367 if (myStartPnt == myEndPnt)
369 if ( !isPreselectionEnabled() ) {
370 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
371 if ( !aView3d.IsNull() ) {
372 myAISContext->MoveTo( myEndPnt.x(), myEndPnt.y(), aView3d, Standard_True );
376 if (aHasShift && myMultiSelectionEnabled)
377 myAISContext->ShiftSelect( Standard_True );
379 myAISContext->Select( Standard_True );
383 if (aHasShift && myMultiSelectionEnabled)
384 myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
385 myEndPnt.x(), myEndPnt.y(),
386 aView->getViewPort()->getView(), Standard_False );
388 myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
389 myEndPnt.x(), myEndPnt.y(),
390 aView->getViewPort()->getView(), Standard_False );
392 int Nb = myAISContext->NbSelected();
393 if( Nb>1 && !myMultiSelectionEnabled )
395 myAISContext->InitSelected();
396 Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
397 if( !anOwner.IsNull() )
399 myAISContext->ClearSelected( Standard_False );
400 myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
404 myAISContext->UpdateCurrentViewer();
406 emit selectionChanged();
410 SLOT: called on key press, processes selection in "key free" interaction style
412 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
414 if (!mySelectionEnabled) return;
416 OCCViewer_ViewWindow* aView = qobject_cast<OCCViewer_ViewWindow*>( theWindow );
417 if ( !aView ) return;
419 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
421 switch ( theEvent->key() ) {
424 myAISContext->ClearCurrents( false );
428 if ( !isPreselectionEnabled() ) {
429 Handle(V3d_View) aView3d = aView->getViewPort()->getView();
430 if ( !aView3d.IsNull() ) {
431 myAISContext->MoveTo(myCurPnt.x(), myCurPnt.y(), aView3d, Standard_True );
435 if (aHasShift && myMultiSelectionEnabled)
436 myAISContext->ShiftSelect( Standard_True );
438 myAISContext->Select( Standard_True );
440 emit selectionChanged();
444 if ( isPreselectionEnabled() ) {
445 #if OCC_VERSION_LARGE <= 0x07030000
446 if ( useLocalSelection() )
448 getAISContext()->HilightNextDetected( aView->getViewPort()->getView() );
452 if ( isPreselectionEnabled() ) {
453 #if OCC_VERSION_LARGE <= 0x07030000
454 if ( useLocalSelection() )
456 getAISContext()->HilightPreviousDetected( aView->getViewPort()->getView() );
464 void OCCViewer_Viewer::onViewClosed(OCCViewer_ViewPort3d*)
466 Standard_Integer aViewsNb = 0;
467 for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
469 if ( aViewsNb < 2 ) {
470 //clean up presentations before last view is closed
471 myAISContext->RemoveAll(Standard_False);
475 void OCCViewer_Viewer::onViewMapped(OCCViewer_ViewPort3d* viewPort)
477 setTrihedronShown( true );
478 bool showStaticTrihedron = true;
479 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
480 if ( resMgr ) showStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
481 viewPort->showStaticTrihedron( showStaticTrihedron );
484 int OCCViewer_Viewer::getTopLayerId()
486 if ( myTopLayerId == 0 && !myAISContext->CurrentViewer().IsNull() )
487 myAISContext->CurrentViewer()->AddZLayer( myTopLayerId );
493 \return interaction style
495 int OCCViewer_Viewer::interactionStyle() const
497 return myInteractionStyle;
501 Sets interaction style: 0 - standard, 1 - keyboard free interaction
502 \param theStyle - new interaction style
504 void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
506 myInteractionStyle = theStyle;
507 //!! To be done for view windows
508 if ( !myViewManager )
511 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
512 for ( int i = 0; i < (int)wins.count(); i++ )
514 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
516 win->setInteractionStyle( theStyle );
521 \return projection type
523 int OCCViewer_Viewer::projectionType() const
525 return myProjectionType;
529 Sets projection type: 0 - orthographic, 1 - perspective
530 \param theType - new projection type
532 void OCCViewer_Viewer::setProjectionType( const int theType )
534 if ( myProjectionType != theType ) {
535 if ( theType != OCCViewer_ViewWindow::Stereo )
536 myProjectionType = theType;
538 if ( !myViewManager )
541 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
542 for ( int i = 0; i < (int)wins.count(); i++ )
544 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
546 win->setProjectionType( (OCCViewer_ViewWindow::ProjectionType)theType );
552 int OCCViewer_Viewer::selectionStyle() const
554 return mySelectionStyle;
557 void OCCViewer_Viewer::setSelectionStyle(const int theMode)
559 if (mySelectionStyle != theMode) {
560 mySelectionStyle = theMode;
564 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
565 for (int i = 0; i < (int)wins.count(); i++)
567 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>(wins.at(i));
569 win->setSelectionStyle(theMode);
579 int OCCViewer_Viewer::stereoType() const
586 \param theType - new stereo type
588 void OCCViewer_Viewer::setStereoType( const int theType )
590 myStereoType = theType;
592 if ( !myViewManager )
595 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
596 for ( int i = 0; i < (int)wins.count(); i++ )
598 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
600 win->setStereoType( (OCCViewer_ViewWindow::StereoType)theType );
605 \return stereographic focus type
607 int OCCViewer_Viewer::stereographicFocusType() const
609 return myStereographicFocusType;
613 \return stereographic focus value
615 double OCCViewer_Viewer::stereographicFocusValue() const
617 return myStereographicFocusValue;
621 Sets stereographic focus parameters
622 \param theType - new stereographic focus type
623 \param theValue - new stereographic focus value
625 void OCCViewer_Viewer::setStereographicFocus( const int theType, const double theValue )
627 myStereographicFocusType = theType;
628 myStereographicFocusValue = theValue;
630 if ( !myViewManager )
633 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
634 for ( int i = 0; i < (int)wins.count(); i++ )
636 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
638 win->setStereographicFocus( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
643 \return stereographic focus type
645 int OCCViewer_Viewer::interocularDistanceType() const
647 return myInterocularDistanceType;
651 \return stereographic focus value
653 double OCCViewer_Viewer::interocularDistanceValue() const
655 return myInterocularDistanceValue;
659 Sets interocular distance parameters
660 \param theType - new IOD type
661 \param theValue - new IOD value
663 void OCCViewer_Viewer::setInterocularDistance( const int theType, const double theValue )
665 myInterocularDistanceType = theType;
666 myInterocularDistanceValue = theValue;
668 if ( !myViewManager )
671 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
672 for ( int i = 0; i < (int)wins.count(); i++ )
674 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
676 win->setInterocularDistance( (OCCViewer_ViewWindow::FocusIODType)theType, theValue );
681 \return anaglyph filter
683 int OCCViewer_Viewer::anaglyphFilter() const
685 return myAnaglyphFilter;
690 \param theType - new anaglyph filter
692 void OCCViewer_Viewer::setAnaglyphFilter( const int theType )
694 myAnaglyphFilter = theType;
696 if ( !myViewManager )
699 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
700 for ( int i = 0; i < (int)wins.count(); i++ )
702 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
704 win->setAnaglyphFilter( (OCCViewer_ViewWindow::AnaglyphFilter)theType );
709 \return reverse stereo
711 bool OCCViewer_Viewer::isReverseStereo() const
713 return myToReverseStereo;
718 \param theReverse - enable/disable reverse mode
720 void OCCViewer_Viewer::setReverseStereo( const bool theReverse )
722 myToReverseStereo = theReverse;
724 if ( !myViewManager )
727 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
728 for ( int i = 0; i < (int)wins.count(); i++ )
730 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
732 win->setReverseStereo( theReverse );
739 bool OCCViewer_Viewer::isVSync() const
746 \param theEnable - enable/disable V-Sync mode
748 void OCCViewer_Viewer::setVSync( const bool theEnable )
750 myVSyncMode = theEnable;
752 if ( !myViewManager )
755 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
756 for ( int i = 0; i < (int)wins.count(); i++ )
758 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
760 win->setVSync( theEnable );
765 \return support quad-buffered stereo
767 bool OCCViewer_Viewer::isQuadBufferSupport() const
769 return myQuadBufferSupport;
773 Set support quad-buffered stereo
774 \param theEnable - enable/disable support quad-buffered stereo
776 void OCCViewer_Viewer::setQuadBufferSupport( const bool theEnable )
778 myQuadBufferSupport = theEnable;
780 if ( !myViewManager )
783 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
784 for ( int i = 0; i < (int)wins.count(); i++ )
786 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
788 win->setQuadBufferSupport( theEnable );
793 \return zooming style
795 int OCCViewer_Viewer::zoomingStyle() const
797 return myZoomingStyle;
801 Sets zooming style: 0 - standard, 1 - advanced (at cursor)
802 \param theStyle - new zooming style
804 void OCCViewer_Viewer::setZoomingStyle( const int theStyle )
806 myZoomingStyle = theStyle;
807 //!! To be done for view windows
808 if ( !myViewManager )
811 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
812 for ( int i = 0; i < (int)wins.count(); i++ )
814 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
816 win->setZoomingStyle( theStyle );
821 \return true if preselection is enabled
823 bool OCCViewer_Viewer::isPreselectionEnabled() const
825 return myPreselectionEnabled;
829 Enables/disables preselection
830 \param isEnabled - new status
832 void OCCViewer_Viewer::enablePreselection(bool isEnabled)
834 myPreselectionEnabled = isEnabled;
836 if ( !myViewManager )
839 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
840 for ( int i = 0; i < (int)wins.count(); i++ )
842 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
844 win->enablePreselection( isEnabled );
850 \return true if selection is enabled
852 bool OCCViewer_Viewer::isSelectionEnabled() const
854 return mySelectionEnabled;
858 Enables/disables selection
859 \param isEnabled - new status
861 void OCCViewer_Viewer::enableSelection(bool isEnabled)
863 mySelectionEnabled = isEnabled;
865 //!! To be done for view windows
866 if ( !myViewManager )
869 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
870 for ( int i = 0; i < (int)wins.count(); i++ )
872 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
874 win->updateEnabledDrawMode();
875 win->enableSelection( isEnabled );
880 //clear current selection in the viewer
882 myAISContext->ClearSelected( Standard_True );
888 Sets multiselection enabled status
889 \param isEnabled - new status
891 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
893 myMultiSelectionEnabled = isEnable;
894 //!! To be done for view windows
895 if ( !myViewManager )
898 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
899 for ( int i = 0; i < (int)wins.count(); i++ )
901 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
903 win->updateEnabledDrawMode();
908 Sets a color of the clipped region
909 \param theColor - a new color of the clipped region
911 void OCCViewer_Viewer::setClippingColor( const QColor& theColor )
913 myClippingColor = theColor;
915 if( myInternalClipPlanes.IsEmpty() )
918 Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
919 aMaterialAspect.SetColor( Quantity_Color( theColor.redF(), theColor.greenF(),
920 theColor.blueF(), Quantity_TOC_RGB ) );
921 #if OCC_VERSION_LARGE <= 0x07030000
922 for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
923 myInternalClipPlanes.Value(i)->SetCappingMaterial( aMaterialAspect );
925 for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
926 aPlaneIt.Value()->SetCappingMaterial( aMaterialAspect );
932 \return clipping color
934 QColor OCCViewer_Viewer::clippingColor() const
936 return myClippingColor;
939 // initialize a texture for clipped region
940 Handle(Graphic3d_Texture2Dmanual) initClippingTexture( const bool isDefault, const QString& theTexture,
941 const bool isModulate, const double theScale )
943 QString aTextureFile = isDefault ? ":images/hatch.png" : theTexture;
944 QPixmap px( aTextureFile );
945 const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
946 Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap );
947 if( aTexture->IsDone() ) {
948 aTexture->EnableRepeat();
949 isModulate ? aTexture->EnableModulate() : aTexture->DisableModulate();
950 aTexture->GetParams()->SetScale( Graphic3d_Vec2( 1/( theScale*100 ), -1 / ( theScale*100 ) ) );
956 Sets default texture parameters
957 \param isDefault - use/non-use default texture
958 \param theTexture - new texture of the clipped region
959 \param isModulate - enable/disable texture modulate mode
960 \param theScale - scale factor.
962 void OCCViewer_Viewer::setClippingTextureParams( const bool isDefault, const QString& theTexture,
963 const bool isModulate, const double theScale )
965 myDefaultTextureUsed = isDefault;
966 myClippingTexture = theTexture;
967 myTextureModulated = isModulate;
968 myClippingTextureScale = theScale;
970 if( myInternalClipPlanes.IsEmpty() )
973 Handle(Graphic3d_Texture2Dmanual) aTexture =
974 initClippingTexture( myDefaultTextureUsed, myClippingTexture,
975 myTextureModulated, myClippingTextureScale );
976 #if OCC_VERSION_LARGE <= 0x07030000
977 for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
978 myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
980 for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() )
981 aPlaneIt.Value()->SetCappingTexture( aTexture );
988 \return true if default texture is used
990 bool OCCViewer_Viewer::isDefaultTextureUsed() const
992 return myDefaultTextureUsed;
996 \return clipping texture
998 QString OCCViewer_Viewer::clippingTexture() const
1000 return myClippingTexture;
1004 \return true if texture is modulated
1006 bool OCCViewer_Viewer::isTextureModulated() const
1008 return myTextureModulated;
1012 \return scale factor of texture
1014 double OCCViewer_Viewer::clippingTextureScale() const
1016 return myClippingTextureScale;
1020 Builds popup for occ viewer
1022 void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
1024 thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
1025 thePopup->addAction( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
1027 thePopup->addSeparator();
1029 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1031 //Support of several toolbars in the popup menu
1032 QList<QToolBar*> lst = aView->findChildren<QToolBar*>();
1033 QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
1034 for ( ; it!=last; it++ ) {
1035 if ( (*it)->parentWidget()->isVisible() )
1036 thePopup->addAction( (*it)->toggleViewAction() );
1041 SLOT: called on dump view operation is activated, stores scene to raster file
1043 void OCCViewer_Viewer::onDumpView()
1045 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1047 aView->onDumpView();
1051 SLOT: called if background color is to be changed changed, passes new color to view port
1053 void OCCViewer_Viewer::onChangeBackground()
1055 OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
1059 // get supported gradient types
1060 QStringList gradList;
1061 QIntList idList, txtList;
1062 QString formats = backgroundData( gradList, idList, txtList );
1064 // invoke dialog box
1065 Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(), // initial background
1066 aView, // parent for dialog box
1067 txtList, // allowed texture modes
1068 true, // enable solid color mode
1069 true, // enable gradient mode
1070 false, // disable custom gradient mode
1071 !txtList.isEmpty(), // enable/disable texture mode
1072 gradList, // gradient names
1073 idList, // gradient identifiers
1074 formats ); // image formats
1076 // set chosen background data to the viewer
1077 if ( bgData.isValid() )
1078 aView->setBackground( bgData );
1082 Updates OCC 3D viewer
1084 void OCCViewer_Viewer::update()
1086 if (!myV3dViewer.IsNull())
1087 myV3dViewer->Update();
1089 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1091 aView->updateGravityCoords();
1095 \return objects selected in 3D viewer
1096 \param theList - list to be filled with selected objects
1098 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
1101 for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
1102 theList.Append(myAISContext->SelectedInteractive());
1106 Selects objects in 3D viewer. Other selected objects are left as selected
1107 \param theList - list objects to be selected
1109 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
1111 AIS_ListIteratorOfListOfInteractive aIt;
1112 for (aIt.Initialize(theList); aIt.More(); aIt.Next())
1113 myAISContext->AddOrRemoveSelected(aIt.Value(), false);
1114 myAISContext->UpdateCurrentViewer();
1118 Auxiliary method to emit signal selectionChanged()
1120 void OCCViewer_Viewer::performSelectionChanged()
1122 emit selectionChanged();
1126 * Defines default lights
1128 void OCCViewer_Viewer::setDefaultLights()
1130 // clear all light sources
1131 myV3dViewer->InitDefinedLights();
1132 while ( myV3dViewer->MoreDefinedLights() )
1134 myV3dViewer->DelLight( myV3dViewer->DefinedLight() );
1135 myV3dViewer->InitDefinedLights();
1138 // get light source parameters from preferences
1139 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "OCCViewer", "light_color", QColor( 0, 0, 0 ) );
1140 double aDx = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dx", 0.0 );
1141 double aDy = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dy", 0.0 );
1142 double aDz = SUIT_Session::session()->resourceMgr()->doubleValue( "OCCViewer", "light_dz", -1.0 );
1144 Handle(V3d_DirectionalLight) aLight =
1145 new V3d_DirectionalLight( myV3dViewer, V3d_Zneg, OCCViewer::color( aColor ).Name(), Standard_True );
1146 if( !( aDx == 0 && aDy == 0 && aDz == 0 ) )
1147 aLight->SetDirection( aDx, aDy, aDz );
1148 myV3dViewer->SetLightOn( aLight );
1149 myV3dViewer->SetLightOn( new V3d_AmbientLight( myV3dViewer ) );
1153 Hilights/unhilights object in viewer
1154 \param obj - object to be updated
1155 \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
1156 \param update - update current viewer
1158 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
1159 bool hilight, bool update )
1161 if( !obj.IsNull() ) {
1162 #if OCC_VERSION_LARGE <= 0x07030000
1163 if( !myAISContext->HasOpenedContext() )
1166 if ( hilight && !myAISContext->IsSelected( obj ) )
1167 myAISContext->AddOrRemoveSelected( obj, false );
1168 else if ( !hilight && myAISContext->IsSelected( obj ) )
1169 myAISContext->AddOrRemoveSelected( obj, false );
1170 #if OCC_VERSION_LARGE <= 0x07030000
1176 myV3dViewer->Redraw();
1182 Unhilights all objects in viewer
1183 \param updateviewer - update current viewer
1185 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer, bool unselect )
1187 #if OCC_VERSION_LARGE <= 0x07030000
1188 if ( myAISContext->HasOpenedContext() ) {
1191 myAISContext->ClearSelected( updateviewer );
1193 myAISContext->UnhilightSelected( updateviewer );
1195 #if OCC_VERSION_LARGE <= 0x07030000
1198 myAISContext->ClearCurrents( updateviewer );
1200 myAISContext->UnhilightCurrents( updateviewer );
1208 \return true if object is in viewer or in collector
1209 \param obj - object to be checked
1210 \param onlyInViewer - search object only in viewer (so object must be displayed)
1212 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
1215 AIS_ListOfInteractive List;
1216 myAISContext->DisplayedObjects(List);
1218 AIS_ListIteratorOfListOfInteractive ite(List);
1219 for ( ; ite.More(); ite.Next() )
1220 if( ite.Value()==obj )
1227 \return true if object is displayed in viewer
1228 \param obj - object to be checked
1230 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
1232 return myAISContext->IsDisplayed( obj );
1236 Sets color of object
1237 \param obj - object to be updated
1238 \param color - new color
1239 \param update - update current viewer
1241 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
1242 const QColor& color,
1247 Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
1248 color.green() / 255.,
1249 color.blue() / 255.,
1251 obj->SetColor( CSFColor );
1255 myV3dViewer->Update();
1259 Changes display mode of object
1260 \param obj - object to be processed
1261 \param mode - new display mode
1262 \param update - update current viewer
1264 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
1265 int mode, bool update )
1267 myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, update );
1269 myV3dViewer->Update();
1273 Changes transparency of object
1274 \param obj - object to be processed
1275 \param trans - new transparency
1276 \param update - update current viewer
1278 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
1279 float trans, bool update )
1281 myAISContext->SetTransparency( obj, trans, false );
1282 myAISContext->Redisplay( obj, Standard_False, Standard_True );
1284 myV3dViewer->Update();
1287 bool OCCViewer_Viewer::isColorScaleVisible() const
1289 return !myColorScale.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myColorScale );
1292 void OCCViewer_Viewer::setColorScaleShown( const bool on )
1294 if ( myColorScale.IsNull() )
1298 if ( !myAISContext->IsDisplayed( myColorScale ) )
1299 myAISContext->Display( myColorScale, Standard_True );
1300 myAISContext->Redisplay( myColorScale, Standard_True, Standard_True );
1304 if ( myAISContext->IsDisplayed( myColorScale ) )
1305 myAISContext->Erase( myColorScale, Standard_True );
1310 Changes visibility of trihedron to opposite
1312 void OCCViewer_Viewer::toggleTrihedron()
1314 setTrihedronShown( !isTrihedronVisible() );
1318 \return true if trihedron is visible
1320 bool OCCViewer_Viewer::isTrihedronVisible() const
1322 return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
1326 Sets visibility state of trihedron
1327 \param on - new state
1330 void OCCViewer_Viewer::setTrihedronShown( const bool on )
1332 if ( myTrihedron.IsNull() )
1336 myAISContext->Display( myTrihedron,
1338 -1 /* selection mode */,
1339 Standard_True /* update viewer*/,
1340 Standard_False /* allow decomposition */,
1341 AIS_DS_Displayed /* display status */);
1342 myAISContext->Deactivate( myTrihedron );
1345 myAISContext->Erase( myTrihedron , Standard_True );
1350 \return trihedron size
1352 double OCCViewer_Viewer::trihedronSize() const
1355 if ( !myTrihedron.IsNull() )
1356 sz = myTrihedron->Size();
1361 Changes trihedron size
1362 \param sz - new size
1364 void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative )
1366 if ( myTrihedronSize != sz || isRelative != myIsRelative) {
1367 myTrihedronSize = sz;
1368 myIsRelative = isRelative;
1374 Set number of isolines
1375 \param u - u-isolines (first parametric co-ordinate)
1376 \param v - v-isolines (second parametric co-ordinate)
1378 void OCCViewer_Viewer::setIsos( const int u, const int v )
1380 Handle(AIS_InteractiveContext) ic = getAISContext();
1384 ic->SetIsoNumber( u, AIS_TOI_IsoU );
1385 ic->SetIsoNumber( v, AIS_TOI_IsoV );
1389 \return number of isolines
1390 \param u - to return u-isolines (first parametric co-ordinate)
1391 \param v - to return v-isolines (second parametric co-ordinate)
1393 void OCCViewer_Viewer::isos( int& u, int& v ) const
1395 Handle(AIS_InteractiveContext) ic = getAISContext();
1398 u = ic->IsoNumber( AIS_TOI_IsoU );
1399 v = ic->IsoNumber( AIS_TOI_IsoV );
1404 * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
1406 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
1408 return new OCCViewer_ViewWindow(0, this);
1411 #if OCC_VERSION_LARGE <= 0x07030000
1413 Sets using local selection state
1414 \param theIsUseLocalSelection - state
1416 void OCCViewer_Viewer::setUseLocalSelection(bool theIsUseLocalSelection)
1418 myIsUseLocalSelection = theIsUseLocalSelection;
1422 * Returns true if local context is opened or view model local state is set
1424 bool OCCViewer_Viewer::useLocalSelection() const
1426 if (myIsUseLocalSelection)
1428 Handle(AIS_InteractiveContext) ic = getAISContext();
1429 return !ic.IsNull() && ic->HasOpenedContext();
1434 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
1436 return background( theViewId ).color();
1439 Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
1441 return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
1445 void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
1447 if ( theColor.isValid() ) {
1448 Qtx::BackgroundData bg = background( theViewId );
1449 bg.setColor( theColor );
1450 setBackground( theViewId, bg );
1454 void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
1456 if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
1457 myBackgrounds[theViewId] = theBackground;
1462 Set the show static trihedron flag
1464 void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on)
1466 OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
1467 if ( aView ) aView->showStaticTrihedron( on );
1471 Get new and current trihedron size corresponding to the current model size
1473 bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
1478 //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
1479 Handle(V3d_Viewer) viewer = getViewer3d();
1480 viewer->InitActiveViews();
1481 if(!viewer->MoreActiveViews()) return false;
1483 Handle(V3d_View) view3d = viewer->ActiveView();
1486 if ( view3d.IsNull() )
1489 double aMaxSide = computeSceneSize( view3d );
1492 // The boundary box of the view may be initialized but nullified
1493 // (case of infinite objects)
1494 if ( aMaxSide < Precision::Confusion() )
1497 float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
1499 static float EPS = 5.0E-3;
1500 theSize = getTrihedron()->Size();
1501 theNewSize = aMaxSide*aSizeInPercents / 100.0;
1503 return fabs( theNewSize - theSize ) > theSize * EPS ||
1504 fabs( theNewSize - theSize ) > theNewSize * EPS;
1508 * Compute scene size
1510 double OCCViewer_Viewer::computeSceneSize(const Handle(V3d_View)& view3d) const
1512 double aMaxSide = 0;
1513 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
1515 Bnd_Box aBox = view3d->View()->MinMaxValues();
1516 Xmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().X();
1517 Ymin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Y();
1518 Zmin = aBox.IsVoid() ? RealFirst() : aBox.CornerMin().Z();
1519 Xmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().X();
1520 Ymax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Y();
1521 Zmax = aBox.IsVoid() ? RealLast() : aBox.CornerMax().Z();
1523 if ( Xmin != RealFirst() && Ymin != RealFirst() && Zmin != RealFirst() &&
1524 Xmax != RealLast() && Ymax != RealLast() && Zmax != RealLast() )
1526 aMaxSide = Xmax - Xmin;
1527 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
1528 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
1535 * Update the size of the trihedron
1537 void OCCViewer_Viewer::updateTrihedron() {
1538 if ( myTrihedron.IsNull() )
1542 double newSz, oldSz;
1544 if(computeTrihedronSize(newSz, oldSz))
1545 myTrihedron->SetSize(newSz);
1547 } else if(myTrihedron->Size() != myTrihedronSize) {
1548 myTrihedron->SetSize(myTrihedronSize);
1553 Set number of isolines
1554 \param u - u-isolines (first parametric co-ordinate)
1555 \param v - v-isolines (second parametric co-ordinate)
1557 void OCCViewer_Viewer::setSelectionOptions( bool isPreselectionEnabled, bool isSelectionEnabled )
1559 myPreselectionEnabled = isPreselectionEnabled;
1560 mySelectionEnabled = isSelectionEnabled;
1561 //clear current selection in the viewer
1563 if(!mySelectionEnabled) {
1564 myAISContext->ClearSelected( Standard_True );
1569 Creates clipping plane based on the incoming plane
1571 Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn)
1573 Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( thePlane );
1574 aGraphic3dPlane->SetOn( theIsOn );
1575 aGraphic3dPlane->SetCapping( Standard_True );
1577 // set capping color
1578 Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
1579 aMaterialAspect.SetColor( Quantity_Color( myClippingColor.redF(), myClippingColor.greenF(),
1580 myClippingColor.blueF(), Quantity_TOC_RGB ) );
1581 aGraphic3dPlane->SetCappingMaterial( aMaterialAspect );
1583 // set capping texture
1584 aGraphic3dPlane->SetCappingTexture( initClippingTexture( myDefaultTextureUsed, myClippingTexture,
1585 myTextureModulated, myClippingTextureScale ) );
1587 return aGraphic3dPlane;
1590 Applies clipping planes to clippable objects
1592 void OCCViewer_Viewer::setClipPlanes(ClipPlanesList theList)
1594 // 1. Remove existing clipping planes
1595 myClipPlanes.clear();
1596 myInternalClipPlanes.Clear();
1598 // 2. Create new clipping planes
1599 ClipPlanesList::iterator inIt = theList.begin();
1600 for (;inIt != theList.end(); inIt++ )
1602 OCCViewer_ClipPlane aPlane = *inIt;
1604 double aDx = 0.0, aDy = 0.0, aDz = 0.0;
1605 aPlane.OrientationToXYZ( aDx, aDy, aDz );
1607 gp_Pnt anOrigin( aPlane.X, aPlane.Y, aPlane.Z );
1608 gp_Dir aDirection( aDx, aDy, aDz );
1610 myInternalClipPlanes.Append( createClipPlane( gp_Pln( anOrigin, aDirection ), aPlane.IsOn ) );
1611 myClipPlanes.push_back( aPlane );
1614 // 3. Apply clipping planes
1615 AIS_ListOfInteractive aList;
1616 myAISContext->DisplayedObjects (aList);
1617 for ( AIS_ListIteratorOfListOfInteractive anIter (aList); anIter.More(); anIter.Next() ) {
1618 Handle(AIS_InteractiveObject) anObj = anIter.Value();
1619 Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anObj);
1620 if (!aShape.IsNull() && aShape->IsClippable()) {
1621 aShape->SetClipPlanes(myInternalClipPlanes);
1627 Returns the clipping planes applied to the displayed objects.
1629 ClipPlanesList OCCViewer_Viewer::getClipPlanes() const {
1630 return myClipPlanes;
1633 Applies clipping planes to given object objects
1635 void OCCViewer_Viewer::applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject)
1637 Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (theObject);
1638 if (!aShape.IsNull() && aShape->IsClippable())
1640 aShape->SetClipPlanes (myInternalClipPlanes);
1645 Returns the pointer to the clipping dialog box.
1647 OCCViewer_ClippingDlg* OCCViewer_Viewer::getClippingDlg() const{
1648 return myClippingDlg;
1653 Stores pointer to the clipping dialog box.
1655 void OCCViewer_Viewer::setClippingDlg(OCCViewer_ClippingDlg* theDlg) {
1656 if(myClippingDlg != theDlg) {
1657 myClippingDlg = theDlg;
1662 bool OCCViewer_Viewer::enableDrawMode( bool on )
1664 //!! To be done for view windows
1665 if ( !myViewManager )
1669 QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
1670 for ( int i = 0; i < (int)wins.count(); i++ )
1672 OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
1674 prev = prev || win->enableDrawMode( on );