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;
66 myTrihedronRelative = true;
69 //==========================================================
70 SVTK_Viewer::~SVTK_Viewer()
76 ::backgroundColor() const
83 ::setBackgroundColor( const QColor& theColor )
85 if ( !theColor.isValid() )
88 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
89 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
90 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
91 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
92 aView->setBackgroundColor(theColor);
100 //==========================================================
103 createView( SUIT_Desktop* theDesktop )
105 TViewWindow* aViewWindow = new TViewWindow(theDesktop);
106 aViewWindow->Initialize(this);
108 aViewWindow->setBackgroundColor( backgroundColor() );
109 aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() );
114 int SVTK_Viewer::trihedronSize() const
116 return myTrihedronSize;
119 bool SVTK_Viewer::trihedronRelative() const
121 return myTrihedronRelative;
124 void SVTK_Viewer::setTrihedronSize( const int theSize, const bool theRelative )
126 myTrihedronSize = theSize;
127 myTrihedronRelative = theRelative;
129 if (SUIT_ViewManager* aViewManager = getViewManager()) {
130 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
131 for (int i = 0; i < aViews.count(); i++) {
132 if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i))) {
133 aView->SetTrihedronSize(theSize, theRelative);
139 //==========================================================
140 void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
142 SUIT_ViewModel::setViewManager(theViewManager);
144 if ( !theViewManager )
147 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
148 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
150 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
151 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
153 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
154 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
157 //==========================================================
160 ::contextMenuPopup( QPopupMenu* thePopup )
162 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
163 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
165 thePopup->insertSeparator();
167 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
168 if ( !aView->getMainWindow()->getToolBar()->isVisible() ){
169 thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
174 //==========================================================
177 ::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
180 //==========================================================
183 ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
186 //==========================================================
189 ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
192 //==========================================================
195 ::enableSelection(bool isEnabled)
197 mySelectionEnabled = isEnabled;
198 //!! To be done for view windows
201 //==========================================================
204 ::enableMultiselection(bool isEnable)
206 myMultiSelectionEnabled = isEnable;
207 //!! To be done for view windows
214 if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
218 //==========================================================
223 if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){
224 QColor aColor = QColorDialog::getColor( backgroundColor(), aView);
225 setBackgroundColor(aColor);
229 //==========================================================
234 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
235 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
236 if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i))){
237 aView->getMainWindow()->getToolBar()->show();
242 //==========================================================
245 ::Display( const SALOME_VTKPrs* prs )
247 // try do downcast object
248 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
251 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
252 // get SALOMEDS Study
253 // Temporarily commented to avoid awful dependecy on SALOMEDS
254 // TODO: better mechanism of storing display/erse status in a study
255 // should be provided...
256 // _PTR(Study) aStudy(getStudyDS());
257 anActorCollection->InitTraversal();
258 while(vtkActor* anActor = anActorCollection->GetNextActor()){
259 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
260 // Set visibility flag
261 // Temporarily commented to avoid awful dependecy on SALOMEDS
262 // TODO: better mechanism of storing display/erse status in a study
263 // should be provided...
264 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
265 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
266 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
268 // just display the object
269 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
270 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
271 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
272 if(SVTK_View* aView = aViewWindow->getView()){
273 aView->Display(anAct,false);
274 if(anAct->IsSetCamera()){
275 vtkRenderer* aRenderer = aView->getRenderer();
276 anAct->SetCamera( aRenderer->GetActiveCamera() );
287 //==========================================================
290 ::Erase( const SALOME_VTKPrs* prs, const bool forced )
292 // try do downcast object
293 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
296 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
297 // get SALOMEDS Study
298 // Temporarily commented to avoid awful dependecy on SALOMEDS
299 // TODO: better mechanism of storing display/erse status in a study
300 // should be provided...
301 //_PTR(Study) aStudy(getStudyDS());
302 anActorCollection->InitTraversal();
303 while(vtkActor* anActor = anActorCollection->GetNextActor())
304 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
305 // Set visibility flag
306 // Temporarily commented to avoid awful dependecy on SALOMEDS
307 // TODO: better mechanism of storing display/erse status in a study
308 // should be provided...
309 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
310 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
311 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
313 // just display the object
314 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
315 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
316 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
317 if(SVTK_View* aView = aViewWindow->getView())
319 aView->Remove(anAct,false);
321 aView->Erase(anAct,forced);
328 //==========================================================
331 ::EraseAll( const bool forced )
333 // Temporarily commented to avoid awful dependecy on SALOMEDS
334 // TODO: better mechanism of storing display/erse status in a study
335 // should be provided...
336 //_PTR(Study) aStudy(getStudyDS());
337 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
338 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
339 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
340 if(SVTK_View* aView = aViewWindow->getView()){
341 vtkRenderer* aRenderer = aView->getRenderer();
342 vtkActorCollection* anActorCollection = aRenderer->GetActors();
343 anActorCollection->InitTraversal();
344 while(vtkActor* anActor = anActorCollection->GetNextActor()){
345 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
346 // Set visibility flag
347 // Temporarily commented to avoid awful dependecy on SALOMEDS
348 // TODO: better mechanism of storing display/erse status in a study
349 // should be provided...
350 //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
351 //if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
352 // ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
354 aRenderer->RemoveActor(anAct);
357 anAct->SetVisibility( false );
358 // erase dependent actors
359 vtkActorCollection* aCollection = vtkActorCollection::New();
360 anAct->GetChildActors( aCollection );
361 aCollection->InitTraversal();
362 while(vtkActor* aSubAct = aCollection->GetNextActor())
363 aSubAct->SetVisibility( false );
364 aCollection->Delete();
373 //==========================================================
376 ::CreatePrs( const char* entry )
378 SVTK_Prs* prs = new SVTK_Prs();
380 if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
381 if(SVTK_View* aView = aViewWindow->getView()){
382 vtkRenderer* aRenderer = aView->getRenderer();
383 vtkActorCollection* theActors = aRenderer->GetActors();
384 theActors->InitTraversal();
386 while( ( ac = theActors->GetNextActor() ) ) {
387 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
388 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
389 prs->AddObject( ac );
397 //==========================================================
400 ::BeforeDisplay( SALOME_Displayer* d )
402 d->BeforeDisplay( this, SALOME_VTKViewType() );
405 //==========================================================
407 SVTK_Viewer::AfterDisplay( SALOME_Displayer* d )
409 d->AfterDisplay( this, SALOME_VTKViewType() );
412 //==========================================================
415 ::isVisible( const Handle(SALOME_InteractiveObject)& io )
417 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
418 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
419 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
420 if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
421 if(SVTK_View* aView = aViewWnd->getView())
422 if(!aView->isVisible( io ))
428 //==========================================================
433 // if (theUpdateTrihedron) onAdjustTrihedron();
434 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
435 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
436 if(TViewWindow* aViewWindow = dynamic_cast<TViewWindow*>(aViews.at(i)))
437 if(SVTK_View* aView = aViewWindow->getView())