Back to index

salome-gui  6.5.0
OCCViewer_ViewModel.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "OCCViewer_ViewModel.h"
00024 #include "OCCViewer_ViewWindow.h"
00025 #include "OCCViewer_ViewFrame.h"
00026 #include "OCCViewer_VService.h"
00027 #include "OCCViewer_ViewPort3d.h"
00028 
00029 #include "SUIT_ViewWindow.h"
00030 #include "SUIT_ViewManager.h"
00031 #include "SUIT_Desktop.h"
00032 #include "SUIT_Session.h"
00033 #include "SUIT_ResourceMgr.h"
00034 
00035 #include "QtxActionToolMgr.h"
00036 #include "QtxBackgroundTool.h"
00037 
00038 #include <QPainter>
00039 #include <QApplication>
00040 #include <QColorDialog>
00041 #include <QFileDialog>
00042 #include <QPalette>
00043 #include <QKeyEvent>
00044 #include <QMenu>
00045 #include <QMouseEvent>
00046 #include <QToolBar>
00047 #include <QDesktopWidget>
00048 
00049 #include <AIS_Axis.hxx>
00050 #include <AIS_Drawer.hxx>
00051 #include <AIS_ListOfInteractive.hxx>
00052 #include <AIS_ListIteratorOfListOfInteractive.hxx>
00053 
00054 #include <Geom_Axis2Placement.hxx>
00055 #include <Prs3d_Drawer.hxx>
00056 #include <Prs3d_DatumAspect.hxx>
00057 #include <Prs3d_LineAspect.hxx>
00058 #include <Prs3d_LengthAspect.hxx>
00059 #include <Prs3d_AngleAspect.hxx>
00060 #include <Prs3d_TextAspect.hxx>
00061 
00062 #include <Visual3d_View.hxx>
00063 
00064 #include <Basics_OCCTVersion.hxx>
00065 
00066 // VSR: Uncomment below line to allow texture background support in OCC viewer
00067 #define OCC_ENABLE_TEXTURED_BACKGROUND
00068 
00072 QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
00073 {
00074   gradList << tr("GT_HORIZONTALGRADIENT")    << tr("GT_VERTICALGRADIENT")       <<
00075               tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
00076               tr("GT_FIRSTCORNERGRADIENT")   << tr("GT_SECONDCORNERGRADIENT")   <<
00077               tr("GT_THIRDCORNERGRADIENT")   << tr("GT_FORTHCORNERGRADIENT");
00078   idList   << HorizontalGradient             << VerticalGradient  <<
00079               Diagonal1Gradient              << Diagonal2Gradient <<
00080               Corner1Gradient                << Corner2Gradient   <<
00081               Corner3Gradient                << Corner4Gradient;
00082 #if OCC_VERSION_LARGE > 0x06050200 // enabled since OCCT 6.5.3, since in previous version this functionality is buggy
00083 #ifdef OCC_ENABLE_TEXTURED_BACKGROUND
00084   txtList  << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
00085 #endif
00086 #endif
00087   return tr("BG_IMAGE_FILES");
00088 }
00089 
00094 OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
00095 : SUIT_ViewModel(),
00096   myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
00097   myIsRelative(true),
00098   myTopLayerId( 0 ),
00099   myTrihedronSize(100)
00100 {
00101   // init CasCade viewers
00102   myV3dViewer = OCCViewer_VService::Viewer3d( "", (short*) "Viewer3d", "", 1000.,
00103                                               V3d_XposYnegZpos, true, true );
00104 
00105   myV3dViewer->Init();
00106 
00107   myV3dCollector = OCCViewer_VService::Viewer3d( "", (short*) "Collector3d", "", 1000.,
00108                                                  V3d_XposYnegZpos, true, true );
00109   myV3dCollector->Init();
00110 
00111   // init selector
00112   myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector);
00113 
00114   myAISContext->SelectionColor( Quantity_NOC_WHITE );
00115   
00116   // display isoline on planar faces (box for ex.)
00117   myAISContext->IsoOnPlane( true );
00118 
00119   double h = QApplication::desktop()->screenGeometry( QApplication::desktop()->primaryScreen() ).height() / 300. ;
00120   Handle(Prs3d_Drawer) drawer = myAISContext->DefaultDrawer();
00121   Handle(Prs3d_TextAspect) ta = drawer->TextAspect();
00122   ta->SetHeight(100); // VSR: workaround for CAS.CADE bug (is it really needed ???)
00123   ta->SetHeight(h);
00124   drawer->SetTextAspect(ta);
00125   drawer->AngleAspect()->SetTextAspect(ta);
00126   drawer->LengthAspect()->SetTextAspect(ta);
00127   
00128   /* create trihedron */
00129   if( DisplayTrihedron )
00130   {
00131     Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
00132     myTrihedron = new AIS_Trihedron(anAxis);
00133     myTrihedron->SetInfiniteState( Standard_True );
00134 
00135     Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
00136     //myTrihedron->SetColor( Col );
00137     myTrihedron->SetArrowColor( Col.Name() );
00138     myTrihedron->SetSize(100);
00139     Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
00140     if (drawer->HasDatumAspect()) {
00141         Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
00142         daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
00143         daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
00144         daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
00145     }
00146 
00147     myAISContext->Display(myTrihedron);
00148     myAISContext->Deactivate(myTrihedron);
00149     }
00150 
00151   // set interaction style to standard
00152   myInteractionStyle = 0;
00153 
00154   // set zooming style to standard
00155   myZoomingStyle = 0;
00156 
00157   // selection
00158   mySelectionEnabled = true;
00159   myMultiSelectionEnabled = true;
00160   
00161   
00162   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00163   if(resMgr)
00164     myShowStaticTrihedron = resMgr->booleanValue( "OCCViewer", "show_static_trihedron", true );
00165 }
00166 
00170 OCCViewer_Viewer::~OCCViewer_Viewer() 
00171 {
00172 }
00173 
00178 QColor OCCViewer_Viewer::backgroundColor() const
00179 {
00180   return backgroundColor(0);
00181 }
00182 
00186 Qtx::BackgroundData OCCViewer_Viewer::background() const
00187 {
00188   return background(0);
00189 }
00190 
00195 void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
00196 {
00197   setBackgroundColor( 0, c );
00198 }
00199 
00204 void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
00205 {
00206   setBackground( 0, theBackground );
00207 }
00208 
00213 void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
00214 {
00215   if ( view ) {
00216     view->initLayout();
00217     view->initSketchers();
00218     view->setInteractionStyle( interactionStyle() );
00219     view->setZoomingStyle( zoomingStyle() );
00220     
00221     OCCViewer_ViewPort3d* vp3d = view->getViewPort();
00222     if ( vp3d )
00223     {
00224       vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL);
00225     }
00226   }
00227 }
00228 
00233 SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
00234 {
00235   // create view frame
00236   OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
00237   // get main view window (created by view frame)
00238   OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
00239   // initialize main view window
00240   initView( vw );
00241   // set default background for view window
00242   vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
00243   return view;
00244 }
00245 
00250 void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
00251 {
00252   SUIT_ViewModel::setViewManager(theViewManager);
00253   if (theViewManager) {
00254     connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
00255             this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
00256 
00257     connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), 
00258             this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
00259 
00260     connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
00261             this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
00262 
00263     connect(theViewManager, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), 
00264             this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
00265   }
00266 }
00267 
00271 void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
00272 {
00273   myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
00274 }
00275 
00279 void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
00280 {
00281   if (!mySelectionEnabled) return;
00282   if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
00283 
00284   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
00285 
00286   if ( isSelectionEnabled() ) {
00287     if (aView->getViewPort()->isBusy()) {
00288       QCoreApplication::processEvents();
00289       return; // Check that the ViewPort initialization completed
00290                                                 // To Prevent call move event if the View port is not initialized
00291                                                 // IPAL 20883
00292     }
00293     Handle(V3d_View) aView3d = aView->getViewPort()->getView();
00294     if ( !aView3d.IsNull() ) {
00295       myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
00296     }
00297   }
00298 }
00299 
00300 
00304 void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
00305 {
00306   if (!mySelectionEnabled) return;
00307   if (theEvent->button() != Qt::LeftButton) return;
00308   if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
00309 
00310   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
00311   if (!aView || aView->interactionStyle() != SUIT_ViewModel::STANDARD)
00312     return;
00313 
00314   myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
00315   bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
00316   
00317   if (!aHasShift) emit deselection();
00318 
00319   if (myStartPnt == myEndPnt)
00320   {
00321     if (aHasShift && myMultiSelectionEnabled)
00322       myAISContext->ShiftSelect();
00323     else
00324       myAISContext->Select();
00325   }
00326   else
00327   {
00328     if (aHasShift && myMultiSelectionEnabled)
00329       myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
00330                                 myEndPnt.x(), myEndPnt.y(),
00331                                 aView->getViewPort()->getView(), Standard_False );
00332     else
00333       myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
00334                            myEndPnt.x(), myEndPnt.y(),
00335                            aView->getViewPort()->getView(), Standard_False );
00336 
00337     int Nb = myAISContext->NbSelected();
00338     if( Nb>1 && !myMultiSelectionEnabled )
00339     {
00340         myAISContext->InitSelected();
00341         Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
00342         if( !anOwner.IsNull() )
00343         {
00344             myAISContext->ClearSelected( Standard_False );
00345             myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
00346         }
00347     }
00348 
00349     myAISContext->UpdateCurrentViewer();
00350   }
00351   emit selectionChanged();
00352 }
00353 
00357 void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEvent)
00358 {
00359   if (!mySelectionEnabled) return;
00360   if (theEvent->key() != Qt::Key_S) return;
00361   if (!theWindow->inherits("OCCViewer_ViewWindow")) return;
00362 
00363   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
00364   if (!aView || aView->interactionStyle() != SUIT_ViewModel::KEY_FREE)
00365     return;
00366 
00367   emit deselection();
00368   myAISContext->Select();
00369 
00370   emit selectionChanged();
00371 }
00372 
00373 int OCCViewer_Viewer::getTopLayerId()
00374 {
00375 #if OCC_VERSION_LARGE > 0x06050200
00376   if ( myTopLayerId == 0 && !myAISContext->CurrentViewer().IsNull() )    
00377     myAISContext->CurrentViewer()->AddZLayer( myTopLayerId );
00378 #endif
00379 
00380   return myTopLayerId;
00381 }
00382 
00386 int OCCViewer_Viewer::interactionStyle() const
00387 {
00388   return myInteractionStyle;
00389 }
00390 
00395 void OCCViewer_Viewer::setInteractionStyle( const int theStyle )
00396 {
00397   myInteractionStyle = theStyle;
00399   if ( !myViewManager )
00400     return;
00401 
00402   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
00403   for ( int i = 0; i < (int)wins.count(); i++ )
00404   {
00405     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
00406     if ( win )
00407       win->setInteractionStyle( theStyle );
00408   }
00409 }
00410 
00414 int OCCViewer_Viewer::zoomingStyle() const
00415 {
00416   return myZoomingStyle;
00417 }
00418 
00423 void OCCViewer_Viewer::setZoomingStyle( const int theStyle )
00424 {
00425   myZoomingStyle = theStyle;
00427   if ( !myViewManager )
00428     return;
00429 
00430   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
00431   for ( int i = 0; i < (int)wins.count(); i++ )
00432   {
00433     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
00434     if ( win )
00435       win->setZoomingStyle( theStyle );
00436   }
00437 }
00438 
00443 void OCCViewer_Viewer::enableSelection(bool isEnabled)
00444 {
00445   mySelectionEnabled = isEnabled;
00447   if ( !myViewManager )
00448     return;
00449 
00450   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
00451   for ( int i = 0; i < (int)wins.count(); i++ )
00452   {
00453     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
00454     if ( win )
00455       win->updateEnabledDrawMode();
00456   }
00457 }
00458 
00463 void OCCViewer_Viewer::enableMultiselection(bool isEnable)
00464 {
00465   myMultiSelectionEnabled = isEnable;
00467   if ( !myViewManager )
00468     return;
00469 
00470   QVector<SUIT_ViewWindow*> wins = myViewManager->getViews();
00471   for ( int i = 0; i < (int)wins.count(); i++ )
00472   {
00473     OCCViewer_ViewWindow* win = ::qobject_cast<OCCViewer_ViewWindow*>( wins.at( i ) );
00474     if ( win )
00475       win->updateEnabledDrawMode();
00476   }
00477 }
00478 
00482 void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
00483 {
00484   thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
00485   thePopup->addAction( tr( "MEN_CHANGE_BACKGROUND" ), this, SLOT( onChangeBackground() ) );
00486 
00487   thePopup->addSeparator();
00488 
00489   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
00490 
00491   //Support of several toolbars in the popup menu
00492   QList<QToolBar*> lst = qFindChildren<QToolBar*>( aView );
00493   QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
00494   for ( ; it!=last; it++ ) {
00495     if ( (*it)->parentWidget()->isVisible() )
00496       thePopup->addAction( (*it)->toggleViewAction() );
00497   }
00498 }
00499 
00503 void OCCViewer_Viewer::onDumpView()
00504 {
00505   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
00506   if ( aView )
00507     aView->onDumpView();
00508 }
00509 
00513 void OCCViewer_Viewer::onChangeBackground()
00514 {
00515   OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
00516   if ( !aView )
00517     return;
00518 
00519   // get supported gradient types
00520   QStringList gradList;
00521   QIntList    idList, txtList;
00522   QString     formats = backgroundData( gradList, idList, txtList );
00523 
00524   // invoke dialog box
00525   Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView->background(),  // initial background
00526                                                            aView,                // parent for dialog box
00527                                                            txtList,              // allowed texture modes
00528                                                            true,                 // enable solid color mode
00529                                                            true,                 // enable gradient mode
00530                                                            false,                // disable custom gradient mode
00531                                                            !txtList.isEmpty(),   // enable/disable texture mode
00532                                                            gradList,             // gradient names
00533                                                            idList,               // gradient identifiers
00534                                                            formats );            // image formats
00535 
00536   // set chosen background data to the viewer
00537   if ( bgData.isValid() )
00538     aView->setBackground( bgData );
00539 }
00540 
00544 void OCCViewer_Viewer::update()
00545 {
00546   if (!myV3dViewer.IsNull())
00547     myV3dViewer->Update();
00548 
00549   OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
00550   if ( aView )
00551     aView->updateGravityCoords();
00552 }
00553 
00558 void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
00559 {
00560   theList.Clear();
00561   for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
00562     theList.Append(myAISContext->SelectedInteractive());
00563 }
00564 
00569 void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
00570 {
00571   AIS_ListIteratorOfListOfInteractive aIt;
00572   for (aIt.Initialize(theList); aIt.More(); aIt.Next())
00573     myAISContext->AddOrRemoveSelected(aIt.Value(), false);
00574   myAISContext->UpdateCurrentViewer();
00575 }
00576 
00580 void OCCViewer_Viewer::performSelectionChanged()
00581 {
00582     emit selectionChanged();
00583 }
00584 
00591 bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
00592                                   bool hilight, bool update )
00593 {
00594   bool isInLocal = myAISContext->HasOpenedContext();
00595   if( !obj.IsNull() )
00596     if( !isInLocal )
00597     {
00598       if ( hilight && !myAISContext->IsSelected( obj ) )
00599         myAISContext->AddOrRemoveCurrentObject( obj, false );
00600       else if ( !hilight && myAISContext->IsSelected( obj ) )
00601         myAISContext->AddOrRemoveCurrentObject( obj, false );
00602     }
00603 
00604   if ( update )
00605     myV3dViewer->Redraw();
00606     
00607   return false;
00608 }
00609 
00614 bool OCCViewer_Viewer::unHighlightAll( bool updateviewer )
00615 {
00616   if ( myAISContext->HasOpenedContext() )
00617     myAISContext->ClearSelected( updateviewer );
00618   else
00619     myAISContext->ClearCurrents( updateviewer );
00620   return false;
00621 }
00622 
00628 bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
00629                                    bool onlyInViewer )
00630 {
00631   AIS_ListOfInteractive List;
00632   myAISContext->DisplayedObjects(List);
00633 
00634   if( !onlyInViewer )
00635   {
00636     AIS_ListOfInteractive List1;
00637     myAISContext->ObjectsInCollector(List1);
00638     List.Append(List1);
00639   }
00640 
00641   AIS_ListIteratorOfListOfInteractive ite(List);
00642   for ( ; ite.More(); ite.Next() )
00643     if( ite.Value()==obj )
00644       return true;
00645 
00646   return false;
00647 }
00648 
00653 bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
00654 {
00655   return myAISContext->IsDisplayed( obj );
00656 }
00657 
00664 void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
00665                                  const QColor& color,
00666                                  bool update )
00667 {
00668   if( !obj.IsNull() )
00669   {
00670     Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
00671                                                color.green() / 255.,
00672                                                color.blue() / 255.,
00673                                                Quantity_TOC_RGB );
00674     obj->SetColor( CSFColor );
00675   }
00676 
00677   if( update )
00678     myV3dViewer->Update();
00679 }
00680 
00687 void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
00688                                              int mode, bool update )
00689 {
00690   myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, update );
00691   if( update )
00692     myV3dViewer->Update();
00693 }
00694 
00701 void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
00702                                         float trans, bool update )
00703 {
00704   myAISContext->SetTransparency( obj, trans, false );
00705   myAISContext->Redisplay( obj, Standard_False, Standard_True );
00706   if( update )
00707     myV3dViewer->Update();
00708 }
00709 
00713 void OCCViewer_Viewer::toggleTrihedron()
00714 {
00715   setTrihedronShown( !isTrihedronVisible() );
00716 }
00717 
00721 bool OCCViewer_Viewer::isTrihedronVisible() const
00722 {
00723   return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
00724 }
00725 
00731 void OCCViewer_Viewer::setTrihedronShown( const bool on )
00732 {
00733   if ( myTrihedron.IsNull() )
00734     return;
00735 
00736   if ( on )
00737     myAISContext->Display( myTrihedron );
00738   else
00739     myAISContext->Erase( myTrihedron );
00740 }
00741 
00745 double OCCViewer_Viewer::trihedronSize() const
00746 {
00747   double sz = 0;
00748   if ( !myTrihedron.IsNull() )
00749     sz = myTrihedron->Size();
00750   return sz;
00751 }
00752 
00757 void OCCViewer_Viewer::setTrihedronSize( const double sz, bool isRelative )
00758 {
00759   if ( myTrihedronSize != sz || isRelative != myIsRelative) {
00760     myTrihedronSize = sz; 
00761     myIsRelative = isRelative;
00762     updateTrihedron();
00763   }
00764 }
00765 
00771 void OCCViewer_Viewer::setIsos( const int u, const int v )
00772 {
00773   Handle(AIS_InteractiveContext) ic = getAISContext();
00774   if ( ic.IsNull() )
00775   return;
00776 
00777   ic->SetIsoNumber( u, AIS_TOI_IsoU );
00778   ic->SetIsoNumber( v, AIS_TOI_IsoV );
00779 }
00780 
00786 void OCCViewer_Viewer::isos( int& u, int& v ) const
00787 {
00788   Handle(AIS_InteractiveContext) ic = getAISContext();
00789   if ( !ic.IsNull() )
00790   {
00791     u = ic->IsoNumber( AIS_TOI_IsoU );
00792     v = ic->IsoNumber( AIS_TOI_IsoV );
00793   }
00794 }
00795 
00796 /* 
00797  * Returns a new OCCViewer_ViewWindow instance which will be placed as a sub window in ViewFrame
00798  */
00799 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
00800 {
00801   return new OCCViewer_ViewWindow( 0,  this);
00802 }
00803 
00804 // obsolete  
00805 QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
00806 {
00807   return background( theViewId ).color();
00808 }
00809 
00810 Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
00811 {
00812   return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
00813 }
00814 
00815 // obsolete
00816 void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
00817 {
00818   if ( theColor.isValid() ) {
00819     Qtx::BackgroundData bg = background( theViewId );
00820     bg.setColor( theColor );
00821     setBackground( theViewId, bg );
00822   }
00823 }
00824 
00825 void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
00826 {
00827   if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
00828     myBackgrounds[theViewId] = theBackground;    
00829 }
00830 
00831 
00835 void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on) {
00836   if(myShowStaticTrihedron != on) {
00837     OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
00838     if(!aView)
00839       return;
00840 
00841     OCCViewer_ViewPort3d* vp3d = aView->getViewPort();
00842     if(vp3d) {
00843       myShowStaticTrihedron = on;
00844       vp3d->updateStaticTriedronVisibility();
00845     }
00846   }
00847 }
00848 
00852 bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize )
00853 {
00854   theNewSize = 100;
00855   theSize = 100;
00856 
00857   //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
00858   Handle(V3d_Viewer) viewer = getViewer3d();
00859   viewer->InitActiveViews();
00860   if(!viewer->MoreActiveViews()) return false;
00861 
00862   Handle(V3d_View) view3d = viewer->ActiveView();
00863   //SRN: END of fix
00864 
00865   if ( view3d.IsNull() )
00866     return false;
00867 
00868   double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
00869   double aMaxSide;
00870 
00871   view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
00872 
00873   if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||
00874        Xmax == RealLast()  || Ymax == RealLast()  || Zmax == RealLast() )
00875     return false;
00876 
00877   aMaxSide = Xmax - Xmin;
00878   if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
00879   if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
00880 
00881   // IPAL21687
00882   // The boundary box of the view may be initialized but nullified
00883   // (case of infinite objects)
00884   if ( aMaxSide < Precision::Confusion() )
00885     return false;
00886 
00887   float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("OCCViewer","trihedron_size", 100.);
00888 
00889   static float EPS = 5.0E-3;
00890   theSize = getTrihedron()->Size();
00891   theNewSize = aMaxSide*aSizeInPercents / 100.0;
00892 
00893   return fabs( theNewSize - theSize ) > theSize * EPS ||
00894          fabs( theNewSize - theSize) > theNewSize * EPS;
00895 }
00896 
00900 void OCCViewer_Viewer::updateTrihedron() {
00901   if(myIsRelative){
00902     double newSz, oldSz;
00903     
00904     if(computeTrihedronSize(newSz, oldSz))
00905       myTrihedron->SetSize(newSz);
00906     
00907   } else if(myTrihedron->Size() != myTrihedronSize) {
00908     myTrihedron->SetSize(myTrihedronSize);
00909   }
00910 }