1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_Displayer.h"
28 #include "HYDROGUI_GVSelector.h"
29 #include "HYDROGUI_InputPanel.h"
30 #include "HYDROGUI_ObjSelector.h"
31 #include "HYDROGUI_OCCDisplayer.h"
32 #include "HYDROGUI_OCCSelector.h"
33 #include "HYDROGUI_Operations.h"
34 #include "HYDROGUI_PrsImage.h"
35 #include "HYDROGUI_Tool.h"
36 #include "HYDROGUI_UpdateFlags.h"
37 #include "HYDROGUI_Shape.h"
38 #include "HYDROGUI_VTKPrs.h"
39 #include "HYDROGUI_VTKPrsDisplayer.h"
40 #include "HYDROGUI_AbstractDisplayer.h"
41 #include "HYDROGUI_PolylineOp.h"
43 #include <HYDROData_Image.h>
44 #include <HYDROData_Profile.h>
45 #include <HYDROData_Lambert93.h>
46 #include <HYDROData_Tool.h>
48 #include <HYDROData_OperationsFactory.h>
50 #include <GraphicsView_ViewFrame.h>
51 #include <GraphicsView_ViewManager.h>
52 #include <GraphicsView_ViewPort.h>
53 #include <GraphicsView_Viewer.h>
55 #include <ImageComposer_CutOperator.h>
56 #include <ImageComposer_CropOperator.h>
57 #include <ImageComposer_FuseOperator.h>
59 #include <LightApp_Application.h>
60 #include <LightApp_DataOwner.h>
61 #include <LightApp_GVSelector.h>
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_UpdateFlags.h>
65 #include <OCCViewer_ViewFrame.h>
66 #include <OCCViewer_ViewManager.h>
67 #include <OCCViewer_ViewModel.h>
69 #include <SALOME_Event.h>
71 #include <SUIT_DataBrowser.h>
72 #include <SUIT_Desktop.h>
73 #include <SUIT_Study.h>
74 #include <SUIT_ViewManager.h>
76 #include <SVTK_ViewManager.h>
77 #include <SVTK_ViewModel.h>
78 #include <SVTK_Selector.h>
80 #include <OCCViewer_ViewPort3d.h>
82 #include <GEOMUtils.hxx>
85 #include <QApplication>
86 #include <QGraphicsSceneMouseEvent>
88 #include <QMouseEvent>
91 static int ViewManagerId = 0;
93 extern "C" HYDRO_EXPORT CAM_Module* createModule()
95 return new HYDROGUI_Module();
98 extern "C" HYDRO_EXPORT char* getModuleVersion()
100 return (char*)HYDRO_VERSION;
103 HYDROGUI_Module::HYDROGUI_Module()
104 : LightApp_Module( "HYDRO" ),
107 myIsUpdateEnabled( true )
111 HYDROGUI_Module::~HYDROGUI_Module()
115 int HYDROGUI_Module::getStudyId() const
117 LightApp_Application* anApp = getApp();
118 return anApp ? anApp->activeStudy()->id() : 0;
121 void HYDROGUI_Module::initialize( CAM_Application* theApp )
123 LightApp_Module::initialize( theApp );
126 createUndoRedoActions();
131 setMenuShown( false );
132 setToolShown( false );
134 myDisplayer = new HYDROGUI_Displayer( this );
135 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
136 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
139 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
141 bool aRes = LightApp_Module::activateModule( theStudy );
143 LightApp_Application* anApp = getApp();
144 SUIT_Desktop* aDesktop = anApp->desktop();
146 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
148 setMenuShown( true );
149 setToolShown( true );
151 #ifndef DISABLE_PYCONSOLE
152 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
153 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
156 // Remove defunct view managers from the map.
157 // It's essential to do this before "update( UF_All )" call!
158 QList<int> anObsoleteIds;
159 ViewManagerList anAllViewManagers = anApp->viewManagers();
160 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
161 ViewManagerMapIterator anIter( myViewManagerMap );
162 while( anIter.hasNext() ) {
163 int anId = anIter.next().key();
164 const ViewManagerInfo& anInfo = anIter.value();
166 aHydroViewManagers << anInfo.first;
168 if ( !anAllViewManagers.contains( anInfo.first ) ) {
169 anObsoleteIds << anId;
172 foreach ( const int anId, anObsoleteIds ) {
173 myViewManagerMap.remove( anId );
174 myObjectStateMap.remove( anId );
175 myShapesMap.remove( anId );
176 myVTKPrsMap.remove( anId );
178 // Replace the default selector for all view managers.
179 // Add view managers created outside of HYDRO module to the map.
180 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
181 createSelector( aViewManager ); // replace the default selector
182 if ( !aHydroViewManagers.contains( aViewManager ) ) {
183 ViewManagerInfo anInfo( aViewManager, VMR_General );
184 myViewManagerMap.insert( ViewManagerId++, anInfo );
190 updateCommandsStatus();
192 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
193 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
195 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
197 ViewManagerList anOCCViewManagers;
198 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
199 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
200 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
201 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
202 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
203 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
204 if ( aViewFrame && aViewFrame->getViewPort() ) {
205 aViewFrame->getViewPort()->installEventFilter( this );
213 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
216 ViewManagerMapIterator anIter( myViewManagerMap );
217 while( anIter.hasNext() )
218 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
219 getApp()->removeViewManager( aViewManager );
220 myViewManagerMap.clear();
223 ViewManagerList anOCCViewManagers;
224 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
225 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
226 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
227 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
231 myObjectStateMap.clear();
236 // clear the data model's list of copying objects
237 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
239 setMenuShown( false );
240 setToolShown( false );
242 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
244 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
245 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
247 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
249 return LightApp_Module::deactivateModule( theStudy );
252 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
255 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
256 #ifndef DISABLE_PYCONSOLE
257 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
259 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
262 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
264 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
267 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
271 HYDROGUI_DataModel* aModel = getDataModel();
273 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
274 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
275 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
276 bool anIsVTKView = theClient == SVTK_Viewer::Type();
277 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
280 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
282 bool anIsSelectedDataObjects = false;
283 bool anIsVisibleInSelection = false;
284 bool anIsHiddenInSelection = false;
286 bool anIsImage = false;
287 bool anIsImportedImage = false;
288 bool anIsImageHasRefs = false;
289 bool anIsFusedImage = false;
290 bool anIsCutImage = false;
291 bool anIsSplittedImage = false;
292 bool anIsMustObjectBeUpdated = false;
293 bool anIsPolyline = false;
294 bool anIsPolyline3D = false;
295 bool anIsProfile = false;
296 bool anIsValidProfile = false;
297 bool anAllAreProfiles = false;
298 bool anIsBathymetry = false;
299 bool anIsCalculation = false;
300 bool anIsImmersibleZone = false;
301 bool anIsVisualState = false;
302 bool anIsRegion = false;
303 bool anIsZone = false;
304 bool anIsObstacle = false;
305 bool anIsStream = false;
306 bool anIsChannel = false;
307 bool anIsDigue = false;
308 bool anIsGeomObject = false;
310 // check the selected GEOM objects
311 if ( anIsObjectBrowser && !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
312 theMenu->addAction( action( ImportGeomObjectId ) );
313 theMenu->addSeparator();
316 // check the selected data model objects
317 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
318 int aNbOfSelectedProfiles = 0;
319 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
321 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
322 if( !anObject.IsNull() )
324 anIsSelectedDataObjects = true;
326 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
327 anIsVisibleInSelection |= aVisibility;
328 anIsHiddenInSelection |= !aVisibility;
330 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
332 anIsMustObjectBeUpdated = true;
335 ObjectKind anObjectKind = anObject->GetKind();
336 if( anObjectKind == KIND_IMAGE )
339 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
340 if( !anImage.IsNull() )
342 anIsImportedImage = anImage->HasLocalPoints();
343 anIsImageHasRefs = anImage->HasReferences();
344 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
346 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
348 QString anOperatorName = anOperator->name();
349 if( anOperatorName == ImageComposer_FuseOperator::Type() )
350 anIsFusedImage = true;
351 else if( anOperatorName == ImageComposer_CutOperator::Type() )
353 else if( anOperatorName == ImageComposer_CropOperator::Type() )
354 anIsSplittedImage = true;
359 else if( anObjectKind == KIND_POLYLINEXY )
361 else if( anObjectKind == KIND_POLYLINE )
362 anIsPolyline3D = true;
363 else if( anObjectKind == KIND_PROFILE )
366 aNbOfSelectedProfiles++;
368 Handle(HYDROData_Profile) aProfile =
369 Handle(HYDROData_Profile)::DownCast( anObject );
370 if( !aProfile.IsNull() && aProfile->IsValid() ) {
371 anIsValidProfile = true;
374 else if( anObjectKind == KIND_CALCULATION )
375 anIsCalculation = true;
376 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
377 anIsImmersibleZone = true;
378 else if( anObjectKind == KIND_VISUAL_STATE )
379 anIsVisualState = true;
380 else if( anObjectKind == KIND_REGION )
382 else if( anObjectKind == KIND_ZONE )
384 else if( anObjectKind == KIND_BATHYMETRY )
385 anIsBathymetry = true;
386 else if( anObjectKind == KIND_OBSTACLE )
388 else if( anObjectKind == KIND_STREAM )
390 else if( anObjectKind == KIND_CHANNEL )
392 else if( anObjectKind == KIND_DIGUE )
396 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
399 // Check if all selected objects are profiles
400 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
401 ( aNbOfSelectedProfiles == aSeq.Length() );
403 // check the selected partitions
404 if( !anIsSelectedDataObjects && anIsObjectBrowser )
406 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
407 if( aSelectedPartition != KIND_UNKNOWN )
409 switch( aSelectedPartition )
412 theMenu->addAction( action( ImportImageId ) );
414 case KIND_BATHYMETRY:
415 theMenu->addAction( action( ImportBathymetryId ) );
417 case KIND_ARTIFICIAL_OBJECT:
418 theMenu->addAction( action( CreateChannelId ) );
419 theMenu->addAction( action( CreateDigueId ) );
421 case KIND_NATURAL_OBJECT:
422 theMenu->addAction( action( CreateImmersibleZoneId ) );
423 theMenu->addAction( action( CreateStreamId ) );
426 theMenu->addAction( action( ImportObstacleFromFileId ) );
427 theMenu->addAction( action( CreateBoxId ) );
428 theMenu->addAction( action( CreateCylinderId ) );
430 case KIND_CALCULATION:
431 theMenu->addAction( action( CreateCalculationId ) );
433 case KIND_POLYLINEXY:
434 theMenu->addAction( action( CreatePolylineId ) );
437 theMenu->addAction( action( CreatePolyline3DId ) );
440 theMenu->addAction( action( CreateProfileId ) );
441 theMenu->addAction( action( ImportProfilesId ) );
442 theMenu->addAction( action( AllGeoreferencementId ) );
444 case KIND_VISUAL_STATE:
445 theMenu->addAction( action( SaveVisualStateId ) );
448 theMenu->addSeparator();
452 if( anIsSelectedDataObjects )
454 if ( anIsMustObjectBeUpdated )
456 theMenu->addAction( action( UpdateObjectId ) );
457 theMenu->addSeparator();
460 if( aSeq.Length() == 1 )
464 if( anIsImportedImage )
465 theMenu->addAction( action( EditImportedImageId ) );
466 else if( anIsImageHasRefs )
469 theMenu->addAction( action( EditFusedImageId ) );
470 else if( anIsCutImage )
471 theMenu->addAction( action( EditCutImageId ) );
472 else if( anIsSplittedImage )
473 theMenu->addAction( action( EditSplittedImageId ) );
476 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
477 theMenu->addAction( action( ExportImageId ) );
478 theMenu->addSeparator();
480 if( anIsImageHasRefs )
482 theMenu->addAction( action( RemoveImageRefsId ) );
483 theMenu->addSeparator();
486 theMenu->addAction( action( FuseImagesId ) );
487 theMenu->addAction( action( CutImagesId ) );
488 theMenu->addAction( action( SplitImageId ) );
489 theMenu->addSeparator();
491 else if( anIsBathymetry )
493 theMenu->addAction( action( EditImportedBathymetryId ) );
494 theMenu->addSeparator();
496 else if( anIsPolyline )
498 theMenu->addAction( action( EditPolylineId ) );
499 theMenu->addSeparator();
501 else if( anIsPolyline3D )
503 theMenu->addAction( action( EditPolyline3DId ) );
504 theMenu->addSeparator();
506 else if( anIsProfile )
508 theMenu->addAction( action( EditProfileId ) );
509 theMenu->addAction( action( SelectedGeoreferencementId ) );
510 theMenu->addSeparator();
512 else if( anIsCalculation )
514 theMenu->addAction( action( EditCalculationId ) );
515 theMenu->addAction( action( ExportCalculationId ) );
516 theMenu->addSeparator();
518 else if( anIsImmersibleZone )
520 theMenu->addAction( action( EditImmersibleZoneId ) );
521 theMenu->addSeparator();
523 else if( anIsStream )
525 theMenu->addAction( action( EditStreamId ) );
526 theMenu->addSeparator();
528 else if( anIsChannel )
530 theMenu->addAction( action( EditChannelId ) );
531 theMenu->addSeparator();
535 theMenu->addAction( action( EditDigueId ) );
536 theMenu->addSeparator();
538 else if( anIsVisualState && anIsObjectBrowser )
540 theMenu->addAction( action( SaveVisualStateId ) );
541 theMenu->addAction( action( LoadVisualStateId ) );
542 theMenu->addSeparator();
545 // Add set color action for geometrical objects
546 if ( anIsGeomObject )
548 theMenu->addAction( action( SetColorId ) );
549 theMenu->addSeparator();
551 } else if ( anAllAreProfiles ) {
552 theMenu->addAction( action( SelectedGeoreferencementId ) );
553 theMenu->addSeparator();
556 theMenu->addAction( action( DeleteId ) );
557 theMenu->addSeparator();
559 if( anIsImage || anIsPolyline || anIsPolyline3D ||
560 anIsImmersibleZone || anIsZone || anIsRegion ||
561 anIsBathymetry || anIsObstacle || anIsStream ||
562 anIsChannel || anIsDigue || anIsValidProfile )
564 if( anIsHiddenInSelection )
565 theMenu->addAction( action( ShowId ) );
566 theMenu->addAction( action( ShowOnlyId ) );
567 if( anIsVisibleInSelection )
568 theMenu->addAction( action( HideId ) );
569 theMenu->addSeparator();
575 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
576 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
577 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
578 theMenu->addAction( action( DeleteId ) );
581 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
583 theMenu->addAction( action( ShowAllId ) );
584 theMenu->addAction( action( HideAllId ) );
585 theMenu->addSeparator();
589 void HYDROGUI_Module::update( const int flags )
591 if( !isUpdateEnabled() )
594 QApplication::setOverrideCursor( Qt::WaitCursor );
596 // To prevent calling this method recursively
597 // from one of the methods called below
598 setUpdateEnabled( false );
600 // store selected objects
601 QStringList aSelectedEntries = storeSelection();
603 bool aDoFitAll = flags & UF_FitAll;
604 if( ( flags & UF_Viewer ) )
605 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
607 if( ( flags & UF_OCCViewer ) )
608 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
610 if( ( flags & UF_VTKViewer ) )
611 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
613 if( ( flags & UF_Model ) && getDataModel() && getApp() )
615 getDataModel()->update( getStudyId() );
617 // Temporary workaround to prevent breaking
618 // the selection in the object browser.
619 // Note: processEvents() should be called after updateGV(),
620 // otherwise the application crashes from time to time.
621 //RKV: qApp->processEvents();
622 getApp()->updateObjectBrowser( true );
625 // Object browser is currently updated by using UF_Model flag
626 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
627 getApp()->updateObjectBrowser( true );
629 if( ( flags & UF_Controls ) && getApp() )
630 getApp()->updateActions();
632 // restore selected objects
633 restoreSelection( aSelectedEntries );
635 setUpdateEnabled( true );
637 QApplication::restoreOverrideCursor();
640 void HYDROGUI_Module::updateCommandsStatus()
642 LightApp_Module::updateCommandsStatus();
644 updateUndoRedoControls();
646 action( CopyId )->setEnabled( getDataModel()->canCopy() );
647 action( PasteId )->setEnabled( getDataModel()->canPaste() );
650 void HYDROGUI_Module::selectionChanged()
652 LightApp_Module::selectionChanged();
653 updateCommandsStatus();
656 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
658 return (HYDROGUI_DataModel*)dataModel();
661 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
666 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
668 return myOCCDisplayer;
671 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
673 return myVTKDisplayer;
676 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
678 if( myViewManagerMap.contains( theId ) )
680 return myViewManagerMap[ theId ].first;
685 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
687 if( myViewManagerMap.contains( theId ) )
689 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
690 GraphicsView_ViewManager* aViewManager =
691 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
693 return aViewManager->getViewer();
698 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
700 if( myViewManagerMap.contains( theId ) )
702 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
703 OCCViewer_ViewManager* aViewManager =
704 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
706 return aViewManager->getOCCViewer();
711 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
713 if( myViewManagerMap.contains( theId ) )
715 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
716 SVTK_ViewManager* aViewManager =
717 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
719 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
724 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
726 ViewManagerMapIterator anIter( myViewManagerMap );
727 while( anIter.hasNext() )
729 int anId = anIter.next().key();
730 const ViewManagerInfo& anInfo = anIter.value();
731 if( anInfo.first == theViewManager )
737 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
739 int anId = getViewManagerId( theViewManager );
742 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
743 return anInfo.second;
748 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
749 const ViewManagerRole theRole )
751 int anId = getViewManagerId( theViewManager );
754 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
755 anInfo.second = theRole;
759 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
760 const Handle(HYDROData_Entity)& theObject ) const
762 if( theObject.IsNull() )
765 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
766 if( anIter1 != myObjectStateMap.end() )
768 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
769 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
770 if( anIter2 != aName2ObjectStateMap.end() )
772 const ObjectState& anObjectState = anIter2.value();
773 return anObjectState.Visibility;
779 void HYDROGUI_Module::setObjectVisible( const int theViewId,
780 const Handle(HYDROData_Entity)& theObject,
781 const bool theState )
783 if( !theObject.IsNull() )
785 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
786 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
787 anObjectState.Visibility = theState;
791 /////////////////// OCC SHAPES PROCESSING
792 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
793 const Handle(HYDROData_Entity)& theObject ) const
795 HYDROGUI_Shape* aResShape = NULL;
796 if( theObject.IsNull() )
799 if ( myShapesMap.contains( theViewId ) )
801 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
802 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
804 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
815 void HYDROGUI_Module::setObjectShape( const int theViewId,
816 const Handle(HYDROData_Entity)& theObject,
817 HYDROGUI_Shape* theShape )
819 if( theObject.IsNull() )
822 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
823 aViewShapes.append( theShape );
826 void HYDROGUI_Module::removeObjectShape( const int theViewId,
827 const Handle(HYDROData_Entity)& theObject )
829 if ( !myShapesMap.contains( theViewId ) )
832 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
833 Handle(HYDROData_Entity) anObject;
834 for ( int i = 0; i < aViewShapes.length(); )
836 HYDROGUI_Shape* aShape = aViewShapes.at( i );
837 anObject = aShape->getObject();
838 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
841 aViewShapes.removeAt( i );
849 void HYDROGUI_Module::removeViewShapes( const int theViewId )
851 if ( !myShapesMap.contains( theViewId ) )
854 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
855 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
857 HYDROGUI_Shape* aShape = aViewShapes.at( i );
862 myShapesMap.remove( theViewId );
864 /////////////////// END OF OCC SHAPES PROCESSING
866 /////////////////// VTKPrs PROCESSING
867 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
868 const Handle(HYDROData_Entity)& theObject ) const
870 HYDROGUI_VTKPrs* aResShape = NULL;
871 if( theObject.IsNull() )
874 if ( myVTKPrsMap.contains( theViewId ) )
876 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
877 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
879 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
890 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
891 const Handle(HYDROData_Entity)& theObject,
892 HYDROGUI_VTKPrs* theShape )
894 if( theObject.IsNull() )
897 // Compute the new global Z range from the added presentation and the old global Z range.
898 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
899 double* aRange = theShape->getInternalZRange();
900 bool anIsUpdate = false;
901 if ( aRange[0] < aGlobalRange[0] )
903 aGlobalRange[0] = aRange[0];
906 if ( aRange[1] > aGlobalRange[1] )
908 aGlobalRange[1] = aRange[1];
914 updateVTKZRange( theViewId, aGlobalRange );
917 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
918 aViewShapes.append( theShape );
921 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
922 const Handle(HYDROData_Entity)& theObject )
924 if ( !myVTKPrsMap.contains( theViewId ) )
927 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
928 Handle(HYDROData_Entity) anObject;
929 for ( int i = 0; i < aViewShapes.length(); )
931 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
932 anObject = aShape->getObject();
933 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
936 aViewShapes.removeAt( i );
943 // Invalidate global Z range
944 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
945 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
948 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
950 if ( !myVTKPrsMap.contains( theViewId ) )
953 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
954 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
956 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
961 myVTKPrsMap.remove( theViewId );
964 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
966 if ( myVTKPrsMap.contains( theViewId ) )
968 // For the given viewer id update all VTK presentations ...
969 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
970 HYDROGUI_VTKPrs* aShape;
971 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
973 aShape = aViewShapes.at( i );
976 aShape->setZRange( theRange );
980 // ... and update the global color legend scalar bar.
981 getVTKDisplayer()->SetZRange( theViewId, theRange );
983 /////////////////// END OF VTKPrs PROCESSING
985 CAM_DataModel* HYDROGUI_Module::createDataModel()
987 return new HYDROGUI_DataModel( this );
990 void HYDROGUI_Module::customEvent( QEvent* e )
992 int aType = e->type();
993 if ( aType == NewViewEvent )
995 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
996 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
998 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1000 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1001 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1003 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1005 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1006 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1008 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1009 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1010 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1012 //ouv: temporarily commented
1013 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1016 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1017 update( UF_Viewer );
1019 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1025 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1027 QEvent::Type aType = theEvent->type();
1028 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1030 if( aType == QEvent::Show )
1032 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1033 e->setData( theObj );
1034 QApplication::postEvent( this, e );
1035 theObj->removeEventFilter( this );
1038 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1040 if( aType == QEvent::Leave )
1042 SUIT_Desktop* aDesktop = getApp()->desktop();
1043 if ( aDesktop && aDesktop->statusBar() ) {
1044 aDesktop->statusBar()->clearMessage();
1049 return LightApp_Module::eventFilter( theObj, theEvent );
1052 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1054 LightApp_Module::onViewManagerAdded( theViewManager );
1056 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1058 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1059 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1061 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1063 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1064 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1065 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1066 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1069 createSelector( theViewManager ); // replace the default selector
1071 ViewManagerInfo anInfo( theViewManager, VMR_General );
1072 myViewManagerMap.insert( ViewManagerId++, anInfo );
1075 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1077 LightApp_Module::onViewManagerRemoved( theViewManager );
1079 createSelector( theViewManager ); // replace the default selector
1081 int anId = getViewManagerId( theViewManager );
1084 OCCViewer_ViewManager* anOCCViewManager =
1085 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1086 if ( anOCCViewManager )
1088 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1090 removeViewShapes( (size_t)anOCCViewer );
1093 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1095 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1098 getVTKDisplayer()->DeleteScalarBar( anId );
1099 removeViewShapes( (size_t)aVTKViewer );
1103 myViewManagerMap.remove( anId );
1107 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1109 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1111 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1113 aViewFrame->installEventFilter( this );
1115 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1117 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1118 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1121 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1123 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1125 aViewFrame->onTopView();
1127 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1129 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1131 aViewPort->installEventFilter( this );
1137 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1139 /* ouv: currently unused
1140 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1142 SUIT_ViewManager* aViewManager = 0;
1144 QObject* aParent = aViewPort;
1145 while( aParent = aParent->parent() )
1147 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1149 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1151 aViewManager = aViewer->getViewManager();
1160 double aMouseX = theEvent->scenePos().x();
1161 double aMouseY = theEvent->scenePos().y();
1163 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1164 if( aRole == VMR_General )
1166 int aXDeg = 0, aYDeg = 0;
1167 int aXMin = 0, aYMin = 0;
1168 double aXSec = 0, aYSec = 0;
1169 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1170 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1172 QString aDegSymbol( QChar( 0x00B0 ) );
1173 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1174 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1176 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1178 else if( aRole == VMR_TransformImage )
1179 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1184 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1185 const bool theIsInit,
1186 const bool theIsForced,
1187 const bool theDoFitAll )
1189 QList<int> aViewManagerIdList;
1191 // currently, all views are updated
1192 ViewManagerMapIterator anIter( myViewManagerMap );
1193 while( anIter.hasNext() )
1195 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1197 if ( theDisplayer->IsApplicable( aViewManager ) )
1199 int anId = anIter.key();
1200 aViewManagerIdList.append( anId );
1204 QListIterator<int> anIdIter( aViewManagerIdList );
1205 while( anIdIter.hasNext() )
1207 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1211 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1213 if( !theViewManager )
1216 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1217 if( !aSelectionMgr )
1220 QString aViewType = theViewManager->getType();
1221 if( aViewType != GraphicsView_Viewer::Type() &&
1222 aViewType != OCCViewer_Viewer::Type())
1225 QList<SUIT_Selector*> aSelectorList;
1226 aSelectionMgr->selectors( aViewType, aSelectorList );
1228 // disable all alien selectors
1229 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1230 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1232 SUIT_Selector* aSelector = *anIter;
1233 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1234 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1235 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1236 aSelector->setEnabled( false );
1239 if ( aViewType == GraphicsView_Viewer::Type() )
1241 GraphicsView_ViewManager* aViewManager =
1242 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1244 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1246 else if ( aViewType == OCCViewer_Viewer::Type() )
1248 OCCViewer_ViewManager* aViewManager =
1249 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1251 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1255 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1257 bool aPrevState = myIsUpdateEnabled;
1258 myIsUpdateEnabled = theState;
1262 bool HYDROGUI_Module::isUpdateEnabled() const
1264 return myIsUpdateEnabled;
1267 QStringList HYDROGUI_Module::storeSelection() const
1269 QStringList anEntryList;
1270 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1272 SUIT_DataOwnerPtrList aList( true );
1273 aSelectionMgr->selected( aList );
1275 SUIT_DataOwnerPtrList::iterator anIter;
1276 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1278 const LightApp_DataOwner* anOwner =
1279 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1281 anEntryList.append( anOwner->entry() );
1287 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1289 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1291 SUIT_DataOwnerPtrList aList( true );
1292 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1293 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1294 aSelectionMgr->setSelected( aList );
1298 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1300 OCCViewer_ViewWindow* anOCCViewWindow =
1301 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1302 if ( !anOCCViewWindow ) {
1306 // Get the selected point coordinates
1307 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1312 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1313 aViewPort->getView() );
1315 // Show the coordinates in the status bar
1316 SUIT_Desktop* aDesktop = getApp()->desktop();
1317 if ( aDesktop && aDesktop->statusBar() ) {
1318 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1319 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1320 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );