1 #include <qpopupmenu.h>
2 #include <qcolordialog.h>
5 #include <vtkRenderer.h>
6 #include <vtkActorCollection.h>
8 #include "SUIT_Session.h"
10 #include "SVTK_Selection.h"
11 #include "SVTK_ViewModel.h"
12 #include "SVTK_ViewWindow.h"
15 #include "SVTK_RenderWindowInteractor.h"
16 #include "SVTK_RenderWindow.h"
20 #include "SALOME_Actor.h"
21 #include "SALOME_InteractiveObject.hxx"
23 #include "Utils_ORB_INIT.hxx"
24 #include "Utils_SINGLETON.hxx"
25 #include "SALOME_ModuleCatalog_impl.hxx"
26 #include "SALOME_NamingService.hxx"
28 #include "SALOMEDSClient.hxx"
29 #include "SALOMEDS_StudyManager.hxx"
31 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
32 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
33 // SALOMEDS::StudyManager - no linkage with SalomeApp.
35 static _PTR(Study) getStudyDS()
37 SALOMEDSClient_Study* aStudy = NULL;
38 _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
40 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
41 // id of its underlying SALOMEDS::Study
42 SUIT_Application* app = SUIT_Session::session()->activeApplication();
43 if ( !app ) return _PTR(Study)(aStudy);
44 SUIT_Study* stud = app->activeStudy();
45 if ( !stud ) return _PTR(Study)(aStudy);
46 const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
47 // get SALOMEDS_Study with this id from StudyMgr
48 return aMgr->GetStudyByID( id );
51 //==========================================================
57 //==========================================================
63 //==========================================================
66 ::createView( SUIT_Desktop* theDesktop )
68 return new SVTK_ViewWindow( theDesktop, this );
71 //==========================================================
74 ::setViewManager(SUIT_ViewManager* theViewManager)
76 SUIT_ViewModel::setViewManager(theViewManager);
81 connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
82 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
84 connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
85 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
87 connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
88 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
91 //==========================================================
94 ::contextMenuPopup(QPopupMenu* thePopup)
96 if (thePopup->count() > 0) thePopup->insertSeparator();
97 thePopup->insertItem("Change background...", this, SLOT(onChangeBgColor()));
98 if(SUIT_ViewWindow* aViewWindow = myViewManager->getActiveView()){
99 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
100 if(!aView->getToolBar()->isVisible()){
101 thePopup->insertSeparator();
102 thePopup->insertItem("Show toolbar", this, SLOT(onShowToolbar()));
108 //==========================================================
111 ::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
113 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
114 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
115 switch(event->button()) {
117 aRWI->LeftButtonPressed(event) ;
120 aRWI->MiddleButtonPressed(event) ;
123 aRWI->RightButtonPressed(event) ;
132 //==========================================================
135 ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
137 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
138 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
139 aRWI->MouseMove( event );
144 //==========================================================
147 ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
149 if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
150 if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
151 switch(event->button()) {
153 aRWI->LeftButtonReleased(event) ;
156 aRWI->MiddleButtonReleased(event) ;
159 aRWI->RightButtonReleased(event) ;
168 //==========================================================
171 ::enableSelection(bool isEnabled)
173 mySelectionEnabled = isEnabled;
174 //!! To be done for view windows
177 //==========================================================
180 ::enableMultiselection(bool isEnable)
182 myMultiSelectionEnabled = isEnable;
183 //!! To be done for view windows
186 //==========================================================
191 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
192 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
193 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
194 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
195 QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView);
196 if ( aColor.isValid() )
197 aView->setBackgroundColor(aColor);
201 //==========================================================
206 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
207 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
208 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
209 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
210 aView->getToolBar()->show();
213 //==========================================================
216 ::Display( const SALOME_VTKPrs* prs )
218 // try do downcast object
219 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
222 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
223 // get SALOMEDS Study
224 _PTR(Study) aStudy(getStudyDS());
225 anActorCollection->InitTraversal();
226 while(vtkActor* anActor = anActorCollection->GetNextActor()){
227 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
228 // Set visibility flag
229 Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
230 if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
231 ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
233 // just display the object
234 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
235 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
236 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
237 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
238 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()){
239 aRWI->Display(anAct,false);
240 if(anAct->IsSetCamera()){
241 vtkRenderer* aRenderer = aView->getRenderer();
242 anAct->SetCamera( aRenderer->GetActiveCamera() );
254 //==========================================================
257 ::Erase( const SALOME_VTKPrs* prs, const bool forced )
259 // try do downcast object
260 if(const SVTK_Prs* aPrs = dynamic_cast<const SVTK_Prs*>( prs )){
263 if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
264 // get SALOMEDS Study
265 _PTR(Study) aStudy(getStudyDS());
266 anActorCollection->InitTraversal();
267 while(vtkActor* anActor = anActorCollection->GetNextActor())
268 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
269 // Set visibility flag
270 Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
271 if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
272 ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
274 // just display the object
275 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
276 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
277 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
278 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
279 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
281 aRWI->Remove(anAct,false);
283 aRWI->Erase(anAct,forced);
290 //==========================================================
293 ::EraseAll( const bool forced )
295 _PTR(Study) aStudy(getStudyDS());
296 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
297 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
298 if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
299 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
300 vtkRenderer* aRenderer = aView->getRenderer();
301 vtkActorCollection* anActorCollection = aRenderer->GetActors();
302 anActorCollection->InitTraversal();
303 while(vtkActor* anActor = anActorCollection->GetNextActor()){
304 if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
305 // Set visibility flag
306 Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
307 if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
308 ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
310 aRenderer->RemoveActor(anAct);
313 anAct->SetVisibility( false );
314 // erase dependent actors
315 vtkActorCollection* aCollection = vtkActorCollection::New();
316 anAct->GetChildActors( aCollection );
317 aCollection->InitTraversal();
318 while(vtkActor* aSubAct = aCollection->GetNextActor())
319 aSubAct->SetVisibility( false );
320 aCollection->Delete();
330 //==========================================================
333 ::CreatePrs( const char* entry )
335 SVTK_Prs* prs = new SVTK_Prs();
337 vtkRenderer* rnr = ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getRenderer();
338 vtkActorCollection* theActors = rnr->GetActors();
339 theActors->InitTraversal();
341 while( ( ac = theActors->GetNextActor() ) ) {
342 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
343 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
344 prs->AddObject( ac );
351 //==========================================================
354 ::BeforeDisplay( SALOME_Displayer* d )
356 d->BeforeDisplay( this, SALOME_VTKViewType() );
359 //==========================================================
361 SVTK_Viewer::AfterDisplay( SALOME_Displayer* d )
363 d->AfterDisplay( this, SALOME_VTKViewType() );
366 //==========================================================
369 ::isVisible( const Handle(SALOME_InteractiveObject)& io )
371 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
372 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
373 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
374 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
375 if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
376 if(!aRWI->isVisible( io ))
381 //==========================================================
386 // if (theUpdateTrihedron) onAdjustTrihedron();
387 QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
388 for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
389 if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
390 if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
391 if(SVTK_RenderWindow* aRW = aView->getRenderWindow())
397 ::onSelectionChanged()
399 emit selectionChanged();