+
+/*
+ * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
+ */
+OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
+{
+ return new OCCViewer_ViewWindow(0, this);
+}
+
+// obsolete
+QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
+{
+ return background( theViewId ).color();
+}
+
+Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
+{
+ return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
+}
+
+// obsolete
+void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
+{
+ if ( theColor.isValid() ) {
+ Qtx::BackgroundData bg = background( theViewId );
+ bg.setColor( theColor );
+ setBackground( theViewId, bg );
+ }
+}
+
+void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
+{
+ if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
+ myBackgrounds[theViewId] = theBackground;
+}
+
+
+/*!
+ Set the show static trihedron flag
+*/
+void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on)
+{
+ OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
+ if ( aView ) aView->showStaticTrihedron( on );
+}
+
+/*!
+ Get new and current trihedron size corresponding to the current model size
+*/
+bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
+{
+ theNewSize = 100;
+ theSize = 100;
+
+ //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
+ Handle(V3d_Viewer) viewer = getViewer3d();
+ viewer->InitActiveViews();
+ if(!viewer->MoreActiveViews()) return false;
+
+ Handle(V3d_View) view3d = viewer->ActiveView();
+ //SRN: END of fix
+
+ if ( view3d.IsNull() )
+ return false;
+
+ double aMaxSide = computeSceneSize( view3d );
+
+ // IPAL21687
+ // The boundary box of the view may be initialized but nullified
+ // (case of infinite objects)
+ if ( aMaxSide < Precision::Confusion() )
+ return false;
+
+ float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("3DViewer","trihedron_size", 100.);
+
+ static float EPS = 5.0E-3;
+ theSize = getTrihedron()->Size();
+ theNewSize = aMaxSide*aSizeInPercents / 100.0;
+
+ return fabs( theNewSize - theSize ) > theSize * EPS ||
+ fabs( theNewSize - theSize ) > theNewSize * EPS;
+}
+
+/*!
+ * Compute scene size
+ */
+double OCCViewer_Viewer::computeSceneSize(const Handle(V3d_View)& view3d) const
+{
+ double aMaxSide = 0;
+ double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
+
+ view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
+
+ if ( Xmin != RealFirst() && Ymin != RealFirst() && Zmin != RealFirst() &&
+ Xmax != RealLast() && Ymax != RealLast() && Zmax != RealLast() )
+ {
+ aMaxSide = Xmax - Xmin;
+ if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
+ if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
+ }
+
+ return aMaxSide;
+}
+
+/*!
+ * Update the size of the trihedron
+ */
+void OCCViewer_Viewer::updateTrihedron() {
+ if ( myTrihedron.IsNull() )
+ return;
+
+ if(myIsRelative){
+ double newSz, oldSz;
+
+ if(computeTrihedronSize(newSz, oldSz))
+ myTrihedron->SetSize(newSz);
+
+ } else if(myTrihedron->Size() != myTrihedronSize) {
+ myTrihedron->SetSize(myTrihedronSize);
+ }
+}
+
+/*!
+ Set number of isolines
+ \param u - u-isolines (first parametric co-ordinate)
+ \param v - v-isolines (second parametric co-ordinate)
+*/
+void OCCViewer_Viewer::setSelectionOptions( bool isPreselectionEnabled, bool isSelectionEnabled )
+{
+ myPreselectionEnabled = isPreselectionEnabled;
+ mySelectionEnabled = isSelectionEnabled;
+ //clear current selection in the viewer
+
+ if(!mySelectionEnabled) {
+ myAISContext->ClearSelected( Standard_True );
+ }
+}
+
+
+/*!
+ Applies clipping planes to clippable objects
+*/
+void OCCViewer_Viewer::setClipPlanes(ClipPlanesList theList)
+{
+ // 1. Remove existing clipping planes
+ myClipPlanes.clear();
+ myInternalClipPlanes.Clear();
+
+ // 2. Create new clipping planes
+ ClipPlanesList::iterator inIt = theList.begin();
+ for (;inIt != theList.end(); inIt++ )
+ {
+ OCCViewer_ClipPlane aPlane = *inIt;
+
+ double aDx = 0.0, aDy = 0.0, aDz = 0.0;
+ aPlane.OrientationToXYZ( aDx, aDy, aDz );
+
+ gp_Pnt anOrigin( aPlane.X, aPlane.Y, aPlane.Z );
+ gp_Dir aDirection( aDx, aDy, aDz );
+
+ Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( gp_Pln( anOrigin, aDirection ) );
+ aGraphic3dPlane->SetOn( aPlane.IsOn );
+
+ myInternalClipPlanes.Append( aGraphic3dPlane );
+ myClipPlanes.push_back( aPlane );
+ }
+
+ // 3. Apply clipping planes
+ AIS_ListOfInteractive aList;
+ myAISContext->DisplayedObjects (aList);
+ for ( AIS_ListIteratorOfListOfInteractive anIter (aList); anIter.More(); anIter.Next() ) {
+ Handle(AIS_InteractiveObject) anObj = anIter.Value();
+ Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anObj);
+ if (!aShape.IsNull() && aShape->IsClippable()) {
+ aShape->SetClipPlanes(myInternalClipPlanes);
+ }
+ }
+}
+
+/*!
+ Returns the clipping planes applied to the displayed objects.
+*/
+ClipPlanesList OCCViewer_Viewer::getClipPlanes() const {
+ return myClipPlanes;
+}
+/*!
+ Applies clipping planes to given object objects
+*/
+void OCCViewer_Viewer::applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject)
+{
+ Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (theObject);
+ if (!aShape.IsNull() && aShape->IsClippable())
+ {
+ aShape->SetClipPlanes (myInternalClipPlanes);
+ }
+}
+
+/*!
+ Returns the pointer to the clipping dialog box.
+*/
+OCCViewer_ClippingDlg* OCCViewer_Viewer::getClippingDlg() const{
+ return myClippingDlg;
+}
+
+
+/*!
+ Stores pointer to the clipping dialog box.
+*/
+void OCCViewer_Viewer::setClippingDlg(OCCViewer_ClippingDlg* theDlg) {
+ if(myClippingDlg != theDlg) {
+ myClippingDlg = theDlg;
+ }
+}