1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include <qpopupmenu.h>
20 #include <qcolordialog.h>
22 #include <vtkCamera.h>
23 #include <vtkRenderer.h>
24 #include <vtkActorCollection.h>
26 #include "SUIT_Session.h"
28 #include "SVTK_Selection.h"
29 #include "SVTK_ViewModel.h"
30 #include "SVTK_ViewWindow.h"
31 #include "SVTK_View.h"
32 #include "SVTK_MainWindow.h"
35 #include "VTKViewer_ViewModel.h"
37 #include <SALOME_Actor.h>
38 #include <SALOME_InteractiveObject.hxx>
40 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
41 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
42 // SALOMEDS::StudyManager - no linkage with SalomeApp.
44 // Temporarily commented to avoid awful dependecy on SALOMEDS
45 // TODO: better mechanism of storing display/erse status in a study
46 // should be provided...
47 //static _PTR(Study) getStudyDS()
49 // SALOMEDSClient_Study* aStudy = NULL;
50 // _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
51 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
52 // id of its underlying SALOMEDS::Study
53 // SUIT_Application* app = SUIT_Session::session()->activeApplication();
54 // if ( !app ) return _PTR(Study)(aStudy);
55 // SUIT_Study* stud = app->activeStudy();
56 // if ( !stud ) return _PTR(Study)(aStudy);
57 // const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
58 // get SALOMEDS_Study with this id from StudyMgr
59 // return aMgr->GetStudyByID( id );
62 //==========================================================
63 SVTK_Viewer::SVTK_Viewer()
65 myTrihedronSize = 105;
68 //==========================================================
69 SVTK_Viewer::~SVTK_Viewer()
75 ::backgroundColor() const
82 ::setBackgroundColor( const QColor& theColor )
84 if ( !theColor.isValid() )
87 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
88 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
89 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
90 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
91 aView->getMainWindow()->SetBackgroundColor(theColor);
99 //==========================================================
102 createView( SUIT_Desktop* theDesktop )
104 SVTK_ViewWindow* aViewWindow = new SVTK_ViewWindow(theDesktop);
105 aViewWindow->Initialize(this);
107 aViewWindow->setBackgroundColor( backgroundColor() );
108 aViewWindow->SetTrihedronSize( trihedronSize() );
113 int SVTK_Viewer::trihedronSize() const
115 return myTrihedronSize;
118 void SVTK_Viewer::setTrihedronSize( const int sz )
120 myTrihedronSize = sz;
122 SUIT_ViewManager* vm = getViewManager();
126 QPtrVector<SUIT_ViewWindow> vec = vm->getViews();
127 for ( int i = 0; i < vec.count(); i++ )
129 SUIT_ViewWindow* win = vec.at( i );
130 if ( !win || !win->inherits( "SVTK_ViewWindow" ) )
133 SVTK_ViewWindow* vw = (SVTK_ViewWindow*)win;
134 vw->SetTrihedronSize( sz );
138 //==========================================================
139 void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
141 SUIT_ViewModel::setViewManager(theViewManager);
143 if ( !theViewManager )
146 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
147 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
149 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
150 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
152 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
153 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
156 //==========================================================
159 ::contextMenuPopup( QPopupMenu* thePopup )
161 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
162 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
164 thePopup->insertSeparator();
166 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
167 if ( !aView->getView()->GetMainWindow()->getToolBar()->isVisible() ){
168 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
173 //==========================================================
176 ::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
179 //==========================================================
182 ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
185 //==========================================================
188 ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
191 //==========================================================
194 ::enableSelection(bool isEnabled)
196 mySelectionEnabled = isEnabled;
197 //!! To be done for view windows
200 //==========================================================
203 ::enableMultiselection(bool isEnable)
205 myMultiSelectionEnabled = isEnable;
206 //!! To be done for view windows
213 if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
217 //==========================================================
222 if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){
223 QColor aColor = QColorDialog::getColor( backgroundColor(), aView);
224 setBackgroundColor(aColor);
228 //==========================================================
233 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
234 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
235 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i))){
236 aView->getView()->GetMainWindow()->getToolBar()->show();
241 //==========================================================
244 ::Display( const SALOME_VTKPrs* prs )
246 // try do downcast object
247 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
250 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
251 // get SALOMEDS Study
252 // Temporarily commented to avoid awful dependecy on SALOMEDS
253 // TODO: better mechanism of storing display/erse status in a study
254 // should be provided...
255 // _PTR(Study) aStudy(getStudyDS());
256 anActorCollection->InitTraversal();
257 while(vtkActor* anActor = anActorCollection->GetNextActor()){
258 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
259 // Set visibility flag
260 // Temporarily commented to avoid awful dependecy on SALOMEDS
261 // TODO: better mechanism of storing display/erse status in a study
262 // should be provided...
263 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
264 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
265 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
267 // just display the object
268 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
269 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
270 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
271 if(SVTK_View* aView = aViewWindow->getView()){
272 aView->Display(anAct,false);
273 if(anAct->IsSetCamera()){
274 vtkRenderer* aRenderer = aView->getRenderer();
275 anAct->SetCamera( aRenderer->GetActiveCamera() );
286 //==========================================================
289 ::Erase( const SALOME_VTKPrs* prs, const bool forced )
291 // try do downcast object
292 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
295 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
296 // get SALOMEDS Study
297 // Temporarily commented to avoid awful dependecy on SALOMEDS
298 // TODO: better mechanism of storing display/erse status in a study
299 // should be provided...
300 //_PTR(Study) aStudy(getStudyDS());
301 anActorCollection->InitTraversal();
302 while(vtkActor* anActor = anActorCollection->GetNextActor())
303 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
304 // Set visibility flag
305 // Temporarily commented to avoid awful dependecy on SALOMEDS
306 // TODO: better mechanism of storing display/erse status in a study
307 // should be provided...
308 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
309 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
310 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
312 // just display the object
313 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
314 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
315 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
316 if(SVTK_View* aView = aViewWindow->getView())
318 aView->Remove(anAct,false);
320 aView->Erase(anAct,forced);
327 //==========================================================
330 ::EraseAll( const bool forced )
332 // Temporarily commented to avoid awful dependecy on SALOMEDS
333 // TODO: better mechanism of storing display/erse status in a study
334 // should be provided...
335 //_PTR(Study) aStudy(getStudyDS());
336 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
337 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
338 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
339 if(SVTK_View* aView = aViewWindow->getView()){
340 vtkRenderer* aRenderer = aView->getRenderer();
341 vtkActorCollection* anActorCollection = aRenderer->GetActors();
342 anActorCollection->InitTraversal();
343 while(vtkActor* anActor = anActorCollection->GetNextActor()){
344 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
345 // Set visibility flag
346 // Temporarily commented to avoid awful dependecy on SALOMEDS
347 // TODO: better mechanism of storing display/erse status in a study
348 // should be provided...
349 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
350 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
351 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
353 aRenderer->RemoveActor(anAct);
356 anAct->SetVisibility( false );
357 // erase dependent actors
358 vtkActorCollection* aCollection = vtkActorCollection::New();
359 anAct->GetChildActors( aCollection );
360 aCollection->InitTraversal();
361 while(vtkActor* aSubAct = aCollection->GetNextActor())
362 aSubAct->SetVisibility( false );
363 aCollection->Delete();
372 //==========================================================
375 ::CreatePrs( const char* entry )
377 SVTK_Prs* prs = new SVTK_Prs();
379 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
380 if(SVTK_View* aView = aViewWindow->getView()){
381 vtkRenderer* aRenderer = aView->getRenderer();
382 vtkActorCollection* theActors = aRenderer->GetActors();
383 theActors->InitTraversal();
385 while( ( ac = theActors->GetNextActor() ) ) {
386 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
387 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
388 prs->AddObject( ac );
396 //==========================================================
399 ::BeforeDisplay( SALOME_Displayer* d )
401 d->BeforeDisplay( this, SALOME_VTKViewType() );
404 //==========================================================
406 SVTK_Viewer::AfterDisplay( SALOME_Displayer* d )
408 d->AfterDisplay( this, SALOME_VTKViewType() );
411 //==========================================================
414 ::isVisible( const Handle(SALOME_InteractiveObject)& io )
416 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
417 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
418 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
419 if(SVTK_View* aView = aViewWindow->getView())
420 if(!aView->isVisible( io ))
426 //==========================================================
431 // if (theUpdateTrihedron) onAdjustTrihedron();
432 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
433 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
434 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
435 if(SVTK_View* aView = aViewWindow->getView())