// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include <qpopupmenu.h>
#include <qcolordialog.h>
#include "SVTK_Selection.h"
#include "SVTK_ViewModel.h"
#include "SVTK_ViewWindow.h"
+#include "SVTK_View.h"
+#include "SVTK_MainWindow.h"
#include "SVTK_Prs.h"
#include "VTKViewer_ViewModel.h"
-#include "SVTK_RenderWindowInteractor.h"
-#include "SVTK_RenderWindow.h"
-
-//#include <ToolsGUI.h>
-
#include <SALOME_Actor.h>
#include <SALOME_InteractiveObject.hxx>
-// Temporarily commented to avoid awful dependecy on SALOMEDS
-// TODO: better mechanism of storing display/erse status in a study
-// should be provided...
-//#include "Utils_ORB_INIT.hxx"
-//#include "Utils_SINGLETON.hxx"
-//#include "SALOME_ModuleCatalog_impl.hxx"
-//#include "SALOME_NamingService.hxx"
-
-//#include "SALOMEDSClient.hxx"
-//#include "SALOMEDS_StudyManager.hxx"
-
// in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
// SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
// SALOMEDS::StudyManager - no linkage with SalomeApp.
// return aMgr->GetStudyByID( id );
//}
-//==========================================================
+/*!
+ Constructor
+*/
SVTK_Viewer::SVTK_Viewer()
{
- myTrihedronSize = 100;
+ myTrihedronSize = 105;
+ myTrihedronRelative = true;
}
-//==========================================================
+/*!
+ Destructor
+*/
SVTK_Viewer::~SVTK_Viewer()
{
}
-QColor SVTK_Viewer::backgroundColor() const
+/*!
+ \return background color
+*/
+QColor
+SVTK_Viewer
+::backgroundColor() const
{
return myBgColor;
}
-void SVTK_Viewer::setBackgroundColor( const QColor& c )
+/*!
+ Changes background color
+ \param theColor - new background color
+*/
+void
+SVTK_Viewer
+::setBackgroundColor( const QColor& theColor )
{
- if ( c.isValid() )
- myBgColor = c;
+ if ( !theColor.isValid() )
+ return;
+
+ QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
+ for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
+ if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
+ if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
+ aView->setBackgroundColor(theColor);
+ }
+ }
+ }
+
+ myBgColor = theColor;
}
-//==========================================================
-SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
+/*!Create new instance of view window on desktop \a theDesktop.
+ *\retval SUIT_ViewWindow* - created view window pointer.
+ */
+SUIT_ViewWindow*
+SVTK_Viewer::
+createView( SUIT_Desktop* theDesktop )
{
- SVTK_ViewWindow* vw = new SVTK_ViewWindow( theDesktop, this );
- vw->setBackgroundColor( backgroundColor() );
- vw->SetTrihedronSize( trihedronSize() );
- return vw;
+ TViewWindow* aViewWindow = new TViewWindow(theDesktop);
+ aViewWindow->Initialize(this);
+
+ aViewWindow->setBackgroundColor( backgroundColor() );
+ aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() );
+
+ return aViewWindow;
}
+/*!
+ \return trihedron size
+*/
int SVTK_Viewer::trihedronSize() const
{
return myTrihedronSize;
}
-void SVTK_Viewer::setTrihedronSize( const int sz )
+/*!
+ \return true if thihedron changes size in accordance with bounding box
+*/
+bool SVTK_Viewer::trihedronRelative() const
{
- myTrihedronSize = sz;
-
- SUIT_ViewManager* vm = getViewManager();
- if ( !vm )
- return;
-
- QPtrVector<SUIT_ViewWindow> vec = vm->getViews();
- for ( int i = 0; i < vec.count(); i++ )
- {
- SUIT_ViewWindow* win = vec.at( i );
- if ( !win || !win->inherits( "SVTK_ViewWindow" ) )
- continue;
+ return myTrihedronRelative;
+}
- SVTK_ViewWindow* vw = (SVTK_ViewWindow*)win;
- vw->SetTrihedronSize( sz );
+/*!
+ Sets trihedron size and relativeness( whether thihedron changes size in accordance with bounding box)
+ \param theSize - new size
+ \param theRelative - new relativeness
+*/
+void SVTK_Viewer::setTrihedronSize( const int theSize, const bool theRelative )
+{
+ myTrihedronSize = theSize;
+ myTrihedronRelative = theRelative;
+
+ if (SUIT_ViewManager* aViewManager = getViewManager()) {
+ QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
+ for (int i = 0; i < aViews.count(); i++) {
+ if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i))) {
+ aView->SetTrihedronSize(theSize, theRelative);
+ }
+ }
}
}
-//==========================================================
+/*!
+ Sets new view manager
+ \param theViewManager - new view manager
+*/
void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
{
SUIT_ViewModel::setViewManager(theViewManager);
this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
}
-//==========================================================
-void SVTK_Viewer::contextMenuPopup( QPopupMenu* thePopup )
+/*!
+ Builds popup for vtk viewer
+*/
+void
+SVTK_Viewer
+::contextMenuPopup( QPopupMenu* thePopup )
{
thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
thePopup->insertSeparator();
- SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView());
- if ( aView && !aView->getToolBar()->isVisible() )
- thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
-}
-
-//==========================================================
-void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
- if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
- if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
- switch(event->button()) {
- case LeftButton:
- aRWI->LeftButtonPressed(event) ;
- break ;
- case MidButton:
- aRWI->MiddleButtonPressed(event) ;
- break ;
- case RightButton:
- aRWI->RightButtonPressed(event) ;
- break;
- default:
- break ;
- }
+ if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
+ if ( !aView->getMainWindow()->getToolBar()->isVisible() ){
+ thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
}
}
}
-//==========================================================
+/*!
+ SLOT: called on mouse button press, empty implementation
+*/
+void
+SVTK_Viewer
+::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
+{}
+
+/*!
+ SLOT: called on mouse move, empty implementation
+*/
void
SVTK_Viewer
::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
- if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
- if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
- aRWI->MouseMove( event );
- }
- }
-}
+{}
-//==========================================================
+/*!
+ SLOT: called on mouse button release, empty implementation
+*/
void
SVTK_Viewer
::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
- if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
- if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
- switch(event->button()) {
- case LeftButton:
- aRWI->LeftButtonReleased(event) ;
- break ;
- case MidButton:
- aRWI->MiddleButtonReleased(event) ;
- break ;
- case RightButton:
- aRWI->RightButtonReleased(event) ;
- break;
- default:
- break ;
- }
- }
- }
-}
+{}
-//==========================================================
+/*!
+ Enables/disables selection
+ \param isEnabled - new state
+*/
void
SVTK_Viewer
::enableSelection(bool isEnabled)
//!! To be done for view windows
}
-//==========================================================
+/*!
+ Enables/disables selection of many object
+ \param isEnabled - new state
+*/
void
SVTK_Viewer
::enableMultiselection(bool isEnable)
//!! To be done for view windows
}
-void SVTK_Viewer::onDumpView()
+/*!
+ SLOT: called on dump view operation is activated, stores scene to raster file
+*/
+void
+SVTK_Viewer
+::onDumpView()
{
- SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
- if ( aView )
+ if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
aView->onDumpView();
}
-//==========================================================
-void SVTK_Viewer::onChangeBgColor()
+/*!
+ SLOT: called if background color is to be changed changed, passes new color to view port
+*/
+void
+SVTK_Viewer
+::onChangeBgColor()
{
- SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
- if ( aView ) {
- QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView );
- if ( aColor.isValid() )
- aView->setBackgroundColor( aColor );
+ if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){
+ QColor aColor = QColorDialog::getColor( backgroundColor(), aView);
+ setBackgroundColor(aColor);
}
}
-//==========================================================
+/*!
+ SLOT: called when popup item "Show toolbar" is activated, shows toolbar of active view window
+*/
void
SVTK_Viewer
::onShowToolbar()
{
QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
- for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
- if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
- if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
- aView->getToolBar()->show();
+ for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
+ if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i))){
+ aView->getMainWindow()->getToolBar()->show();
+ }
+ }
}
-//==========================================================
+/*!
+ Display presentation
+ \param prs - presentation
+*/
void
SVTK_Viewer
::Display( const SALOME_VTKPrs* prs )
// just display the object
QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
- if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
- if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
- if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()){
- aRWI->Display(anAct,false);
- if(anAct->IsSetCamera()){
- vtkRenderer* aRenderer = aView->getRenderer();
- anAct->SetCamera( aRenderer->GetActiveCamera() );
- }
+ if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
+ if(SVTK_View* aView = aViewWindow->getView()){
+ aView->Display(anAct,false);
+ if(anAct->IsSetCamera()){
+ vtkRenderer* aRenderer = aView->getRenderer();
+ anAct->SetCamera( aRenderer->GetActiveCamera() );
}
}
}
}
}
-//==========================================================
+/*!
+ Erase presentation
+ \param prs - presentation
+ \param forced - removes object from view
+*/
void
SVTK_Viewer
::Erase( const SALOME_VTKPrs* prs, const bool forced )
// just display the object
QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
- if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
- if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
- if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
- if ( forced )
- aRWI->Remove(anAct,false);
- else
- aRWI->Erase(anAct,forced);
+ if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
+ if(SVTK_View* aView = aViewWindow->getView())
+ if ( forced )
+ aView->Remove(anAct,false);
+ else
+ aView->Erase(anAct,forced);
}
}
}
}
}
-
-//==========================================================
+
+/*!
+ Erase all presentations
+ \param forced - removes all objects from view
+*/
void
SVTK_Viewer
::EraseAll( const bool forced )
//_PTR(Study) aStudy(getStudyDS());
QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
- if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
- if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
-
- aView->unHighlightAll();
-
+ if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
+ if(SVTK_View* aView = aViewWindow->getView()){
vtkRenderer* aRenderer = aView->getRenderer();
vtkActorCollection* anActorCollection = aRenderer->GetActors();
anActorCollection->InitTraversal();
}
}
}
- }
}
Repaint();
}
-//==========================================================
+/*!
+ Create presentation corresponding to the entry
+ \param entry - entry
+*/
SALOME_Prs*
SVTK_Viewer
::CreatePrs( const char* entry )
{
SVTK_Prs* prs = new SVTK_Prs();
if ( entry ) {
- vtkRenderer* rnr = ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getRenderer();
- vtkActorCollection* theActors = rnr->GetActors();
- theActors->InitTraversal();
- vtkActor* ac;
- while( ( ac = theActors->GetNextActor() ) ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
- prs->AddObject( ac );
+ if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
+ if(SVTK_View* aView = aViewWindow->getView()){
+ vtkRenderer* aRenderer = aView->getRenderer();
+ vtkActorCollection* theActors = aRenderer->GetActors();
+ theActors->InitTraversal();
+ vtkActor* ac;
+ while( ( ac = theActors->GetNextActor() ) ) {
+ SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
+ if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
+ prs->AddObject( ac );
+ }
+ }
}
- }
}
return prs;
}
-//==========================================================
+/*!
+ Auxiliary method called before displaying of objects
+*/
void
SVTK_Viewer
::BeforeDisplay( SALOME_Displayer* d )
d->BeforeDisplay( this, SALOME_VTKViewType() );
}
-//==========================================================
+/*!
+ Auxiliary method called after displaying of objects
+*/
void
SVTK_Viewer::AfterDisplay( SALOME_Displayer* d )
{
d->AfterDisplay( this, SALOME_VTKViewType() );
}
-//==========================================================
+/*!
+ \return true if object is displayed in viewer
+ \param obj - object to be checked
+*/
bool
SVTK_Viewer
::isVisible( const Handle(SALOME_InteractiveObject)& io )
QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
- if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
- if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
- if(!aRWI->isVisible( io ))
- return false;
+ if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
+ if(SVTK_View* aView = aViewWnd->getView())
+ if(!aView->isVisible( io ))
+ return false;
+
return true;
}
-//==========================================================
+/*!
+ Updates current viewer
+*/
void
SVTK_Viewer
::Repaint()
// if (theUpdateTrihedron) onAdjustTrihedron();
QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
- if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
- if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
- if(SVTK_RenderWindow* aRW = aView->getRenderWindow())
- aRW->update();
+ if(TViewWindow* aViewWindow = dynamic_cast<TViewWindow*>(aViews.at(i)))
+ if(SVTK_View* aView = aViewWindow->getView())
+ aView->Repaint();
}
-
-void
-SVTK_Viewer
-::onSelectionChanged()
-{
- emit selectionChanged();
-}
-