1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_DataModel.h"
23 #include "HYDROGUI_DataObject.h"
24 #include "HYDROGUI_Displayer.h"
25 #include "HYDROGUI_GVSelector.h"
26 #include "HYDROGUI_InputPanel.h"
27 #include "HYDROGUI_ObjSelector.h"
28 #include "HYDROGUI_OCCDisplayer.h"
29 #include "HYDROGUI_OCCSelector.h"
30 #include "HYDROGUI_Operations.h"
31 #include "HYDROGUI_PrsImage.h"
32 #include "HYDROGUI_Tool.h"
33 #include "HYDROGUI_UpdateFlags.h"
34 #include "HYDROGUI_Shape.h"
35 #include "HYDROGUI_VTKPrs.h"
36 #include "HYDROGUI_VTKPrsDisplayer.h"
37 #include "HYDROGUI_AbstractDisplayer.h"
38 #include "HYDROGUI_PolylineOp.h"
39 #include "HYDROGUI_SetColorOp.h"
40 #include "HYDROGUI_ImportGeomObjectOp.h"
41 #include "HYDROGUI_ShowHideOp.h"
43 #include <HYDROData_Tool.h>
44 #include <HYDROData_Image.h>
45 #include <HYDROData_Stream.h>
46 #include <HYDROData_Profile.h>
47 #include <HYDROData_Lambert93.h>
48 #include <HYDROData_Polyline3D.h>
50 #include <HYDROData_OperationsFactory.h>
52 #include <CurveCreator_Utils.hxx>
54 #include <GraphicsView_ViewFrame.h>
55 #include <GraphicsView_ViewManager.h>
56 #include <GraphicsView_ViewPort.h>
57 #include <GraphicsView_Viewer.h>
59 #include <ImageComposer_CutOperator.h>
60 #include <ImageComposer_CropOperator.h>
61 #include <ImageComposer_FuseOperator.h>
63 #include <LightApp_Application.h>
64 #include <LightApp_DataOwner.h>
65 #include <LightApp_GVSelector.h>
66 #include <LightApp_SelectionMgr.h>
67 #include <LightApp_UpdateFlags.h>
69 #include <SalomeApp_Study.h>
71 #include <OCCViewer_ViewFrame.h>
72 #include <OCCViewer_ViewManager.h>
73 #include <OCCViewer_ViewModel.h>
75 #include <SALOME_Event.h>
77 #include <SUIT_DataBrowser.h>
78 #include <SUIT_DataObject.h>
79 #include <SUIT_ViewManager.h>
80 #include <SUIT_ResourceMgr.h>
81 #include <SUIT_Desktop.h>
82 #include <SUIT_Study.h>
83 #include <SUIT_Session.h>
85 #include <SVTK_ViewManager.h>
86 #include <SVTK_ViewModel.h>
87 #include <SVTK_ViewWindow.h>
88 #include <SVTK_Selector.h>
90 #include <OCCViewer_ViewPort3d.h>
92 #include <GEOMUtils.hxx>
93 #include <GeometryGUI.h>
95 #include <SALOMEDS_wrap.hxx>
98 #include <QApplication>
99 #include <QGraphicsSceneMouseEvent>
101 #include <QMouseEvent>
102 #include <QStatusBar>
105 static int ViewManagerId = 0;
107 extern "C" HYDRO_EXPORT CAM_Module* createModule()
109 return new HYDROGUI_Module();
112 extern "C" HYDRO_EXPORT char* getModuleVersion()
114 return (char*)HYDRO_VERSION;
117 HYDROGUI_Module::HYDROGUI_Module()
118 : LightApp_Module( "HYDRO" ),
121 myIsUpdateEnabled( true )
125 HYDROGUI_Module::~HYDROGUI_Module()
129 int HYDROGUI_Module::getStudyId() const
131 LightApp_Application* anApp = getApp();
132 return anApp ? anApp->activeStudy()->id() : 0;
135 void HYDROGUI_Module::initialize( CAM_Application* theApp )
137 LightApp_Module::initialize( theApp );
140 createUndoRedoActions();
145 setMenuShown( false );
146 setToolShown( false );
148 myDisplayer = new HYDROGUI_Displayer( this );
149 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
150 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
153 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
155 bool aRes = LightApp_Module::activateModule( theStudy );
157 LightApp_Application* anApp = getApp();
158 SUIT_Desktop* aDesktop = anApp->desktop();
160 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
162 setMenuShown( true );
163 setToolShown( true );
165 #ifndef DISABLE_PYCONSOLE
166 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
167 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
170 // Remove defunct view managers from the map.
171 // It's essential to do this before "update( UF_All )" call!
172 QList<int> anObsoleteIds;
173 ViewManagerList anAllViewManagers = anApp->viewManagers();
174 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
175 ViewManagerMapIterator anIter( myViewManagerMap );
176 while( anIter.hasNext() ) {
177 int anId = anIter.next().key();
178 const ViewManagerInfo& anInfo = anIter.value();
180 aHydroViewManagers << anInfo.first;
182 if ( !anAllViewManagers.contains( anInfo.first ) ) {
183 anObsoleteIds << anId;
186 foreach ( const int anId, anObsoleteIds ) {
187 myViewManagerMap.remove( anId );
188 myObjectStateMap.remove( anId );
189 myShapesMap.remove( anId );
190 myVTKPrsMap.remove( anId );
192 // Replace the default selector for all view managers.
193 // Add view managers created outside of HYDRO module to the map.
194 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
195 createSelector( aViewManager ); // replace the default selector
196 if ( !aHydroViewManagers.contains( aViewManager ) ) {
197 ViewManagerInfo anInfo( aViewManager, VMR_General );
198 myViewManagerMap.insert( ViewManagerId++, anInfo );
204 updateCommandsStatus();
206 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
208 ViewManagerList anOCCViewManagers;
209 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
210 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
211 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
212 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
213 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
214 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
215 if ( aViewFrame && aViewFrame->getViewPort() ) {
216 aViewFrame->getViewPort()->installEventFilter( this );
222 SalomeApp_Study* aStudy =
223 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
225 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
226 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
227 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
228 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
229 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
230 if( !GEOM_var->_is_nil() ) {
231 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
236 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
237 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
238 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
243 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
246 ViewManagerMapIterator anIter( myViewManagerMap );
247 while( anIter.hasNext() )
248 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
249 getApp()->removeViewManager( aViewManager );
250 myViewManagerMap.clear();
253 ViewManagerList anOCCViewManagers;
254 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
255 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
256 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
257 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
261 myObjectStateMap.clear();
266 // clear the status bar
267 SUIT_Desktop* aDesktop = getApp()->desktop();
268 if ( aDesktop && aDesktop->statusBar() ) {
269 aDesktop->statusBar()->clearMessage();
272 // clear the data model's list of copying objects
273 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
275 setMenuShown( false );
276 setToolShown( false );
278 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
280 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
282 myActiveOperationMap.clear();
283 return LightApp_Module::deactivateModule( theStudy );
286 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
289 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
290 #ifndef DISABLE_PYCONSOLE
291 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
293 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
296 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
298 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
301 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
305 HYDROGUI_DataModel* aModel = getDataModel();
307 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
308 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
309 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
310 bool anIsVTKView = theClient == SVTK_Viewer::Type();
311 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
314 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
316 bool anIsSelectedDataObjects = false;
317 bool anIsVisibleInSelection = false;
318 bool anIsHiddenInSelection = false;
320 bool anIsImage = false;
321 bool anIsImportedImage = false;
322 bool anIsImageHasRefs = false;
323 bool anIsFusedImage = false;
324 bool anIsCutImage = false;
325 bool anIsSplittedImage = false;
326 bool anIsMustObjectBeUpdated = false;
327 bool anIsPolyline = false;
328 bool anIsPolyline3D = false;
329 bool anIsProfile = false;
330 bool anIsValidProfile = false;
331 bool anAllAreProfiles = false;
332 bool anIsBathymetry = false;
333 bool anIsCalculation = false;
334 bool anIsImmersibleZone = false;
335 bool anIsVisualState = false;
336 bool anIsRegion = false;
337 bool anIsZone = false;
338 bool anIsObstacle = false;
339 bool anIsStricklerTable = false;
340 bool anIsLandCover = false;
341 bool anIsStream = false;
342 bool anIsChannel = false;
343 bool anIsDigue = false;
344 bool anIsDummyObject3D = false;
345 bool anIsGroup = false;
346 bool anIsObjectCanBeColored = false;
348 bool isStreamHasBottom = false;
350 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
351 SUIT_DataOwnerPtrList anOwners;
352 aSelectionMgr->selected( anOwners );
353 if( anIsObjectBrowser && anOwners.size()==1 )
355 QString anEntry = anOwners[0]->keyString();
356 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
358 isRoot = aStudy->isComponent( anEntry );
361 // Check the selected GEOM objects (take into account the Object Browser only)
362 if ( anIsObjectBrowser ) {
363 QList<GEOM::shape_type> anObstacleTypes =
364 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
365 QList<GEOM::shape_type> aPolylineTypes =
366 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
368 bool isCanBeImportedAsObstacle =
369 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
370 bool isCanBeImportedAsPolyline =
371 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
373 // Add import as obstacle action
374 if ( isCanBeImportedAsObstacle ) {
375 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
377 // Add import as polyline action
378 if ( isCanBeImportedAsPolyline ) {
379 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
382 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
383 theMenu->addSeparator();
387 // check the selected data model objects
388 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
389 int aNbOfSelectedProfiles = 0;
390 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
392 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
393 if( !anObject.IsNull() )
395 anIsSelectedDataObjects = true;
397 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
398 anIsVisibleInSelection |= aVisibility;
399 anIsHiddenInSelection |= !aVisibility;
401 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
403 anIsMustObjectBeUpdated = true;
406 ObjectKind anObjectKind = anObject->GetKind();
407 if( anObjectKind == KIND_IMAGE )
410 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
411 if( !anImage.IsNull() )
413 anIsImportedImage = anImage->HasLocalPoints();
414 anIsImageHasRefs = anImage->HasReferences();
415 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
417 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
419 QString anOperatorName = anOperator->name();
420 if( anOperatorName == ImageComposer_FuseOperator::Type() )
421 anIsFusedImage = true;
422 else if( anOperatorName == ImageComposer_CutOperator::Type() )
424 else if( anOperatorName == ImageComposer_CropOperator::Type() )
425 anIsSplittedImage = true;
430 else if( anObjectKind == KIND_POLYLINEXY )
432 else if( anObjectKind == KIND_POLYLINE )
433 anIsPolyline3D = true;
434 else if( anObjectKind == KIND_PROFILE )
437 aNbOfSelectedProfiles++;
439 Handle(HYDROData_Profile) aProfile =
440 Handle(HYDROData_Profile)::DownCast( anObject );
441 if( !aProfile.IsNull() && aProfile->IsValid() ) {
442 anIsValidProfile = true;
445 else if( anObjectKind == KIND_CALCULATION )
446 anIsCalculation = true;
447 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
448 anIsImmersibleZone = true;
449 else if( anObjectKind == KIND_VISUAL_STATE )
450 anIsVisualState = true;
451 else if( anObjectKind == KIND_REGION )
453 else if( anObjectKind == KIND_ZONE )
455 else if( anObjectKind == KIND_BATHYMETRY )
456 anIsBathymetry = true;
457 else if( anObjectKind == KIND_OBSTACLE )
459 else if( anObjectKind == KIND_STRICKLER_TABLE )
460 anIsStricklerTable = true;
461 else if( anObjectKind == KIND_LAND_COVER )
462 anIsLandCover = true;
463 else if( anObjectKind == KIND_STREAM )
466 Handle(HYDROData_Stream) aStream =
467 Handle(HYDROData_Stream)::DownCast( anObject );
468 if ( !aStream.IsNull() )
469 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
471 else if( anObjectKind == KIND_CHANNEL )
473 else if( anObjectKind == KIND_DIGUE )
475 else if( anObjectKind == KIND_DUMMY_3D )
476 anIsDummyObject3D = true;
477 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
481 if ( !anIsObjectCanBeColored )
482 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
485 // Check if all selected objects are profiles
486 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
487 ( aNbOfSelectedProfiles == aSeq.Length() );
489 // check the selected partitions
490 if( !anIsSelectedDataObjects && anIsObjectBrowser )
492 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
493 if( aSelectedPartition != KIND_UNKNOWN )
495 switch( aSelectedPartition )
498 theMenu->addAction( action( ImportImageId ) );
500 case KIND_BATHYMETRY:
501 theMenu->addAction( action( ImportBathymetryId ) );
503 case KIND_ARTIFICIAL_OBJECT:
504 theMenu->addAction( action( CreateChannelId ) );
505 theMenu->addAction( action( CreateDigueId ) );
507 case KIND_NATURAL_OBJECT:
508 theMenu->addAction( action( CreateImmersibleZoneId ) );
509 theMenu->addAction( action( CreateStreamId ) );
512 theMenu->addAction( action( ImportObstacleFromFileId ) );
513 theMenu->addAction( action( CreateBoxId ) );
514 theMenu->addAction( action( CreateCylinderId ) );
516 case KIND_STRICKLER_TABLE:
517 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
519 case KIND_LAND_COVER:
520 theMenu->addAction( action( CreateLandCoverId ) );
522 case KIND_CALCULATION:
523 theMenu->addAction( action( CreateCalculationId ) );
525 case KIND_POLYLINEXY:
526 theMenu->addAction( action( CreatePolylineId ) );
529 theMenu->addAction( action( CreatePolyline3DId ) );
532 theMenu->addAction( action( CreateProfileId ) );
533 theMenu->addAction( action( ImportProfilesId ) );
534 theMenu->addAction( action( AllGeoreferencementId ) );
536 case KIND_VISUAL_STATE:
537 theMenu->addAction( action( SaveVisualStateId ) );
540 theMenu->addSeparator();
544 if( anIsSelectedDataObjects )
546 if ( anIsMustObjectBeUpdated )
548 theMenu->addAction( action( UpdateObjectId ) );
549 theMenu->addSeparator();
553 theMenu->addAction( action( ForcedUpdateObjectId ) );
554 theMenu->addSeparator();
558 if( aSeq.Length() == 1 )
562 if( anIsImportedImage )
563 theMenu->addAction( action( EditImportedImageId ) );
564 else if( anIsImageHasRefs )
567 theMenu->addAction( action( EditFusedImageId ) );
568 else if( anIsCutImage )
569 theMenu->addAction( action( EditCutImageId ) );
570 else if( anIsSplittedImage )
571 theMenu->addAction( action( EditSplittedImageId ) );
574 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
575 theMenu->addAction( action( ExportImageId ) );
576 theMenu->addSeparator();
578 if( anIsImageHasRefs )
580 theMenu->addAction( action( RemoveImageRefsId ) );
581 theMenu->addSeparator();
584 theMenu->addAction( action( FuseImagesId ) );
585 theMenu->addAction( action( CutImagesId ) );
586 theMenu->addAction( action( SplitImageId ) );
587 theMenu->addSeparator();
589 else if( anIsBathymetry )
591 theMenu->addAction( action( EditImportedBathymetryId ) );
592 theMenu->addAction( action( BathymetryBoundsId ) );
593 theMenu->addSeparator();
595 else if( anIsPolyline )
597 theMenu->addAction( action( EditPolylineId ) );
598 theMenu->addSeparator();
600 else if( anIsPolyline3D )
602 theMenu->addAction( action( EditPolyline3DId ) );
603 theMenu->addSeparator();
605 else if( anIsProfile )
607 theMenu->addAction( action( EditProfileId ) );
608 theMenu->addAction( action( SelectedGeoreferencementId ) );
609 theMenu->addSeparator();
611 else if( anIsCalculation )
613 theMenu->addAction( action( EditCalculationId ) );
614 theMenu->addAction( action( ExportCalculationId ) );
615 theMenu->addSeparator();
617 else if( anIsImmersibleZone )
619 theMenu->addAction( action( EditImmersibleZoneId ) );
620 theMenu->addSeparator();
622 else if( anIsStream )
624 theMenu->addAction( action( EditStreamId ) );
625 if ( action( RiverBottomContextId ) )
627 theMenu->addAction( action( RiverBottomContextId ) );
628 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
630 theMenu->addAction( action( ProfileInterpolateId ) );
631 theMenu->addSeparator();
633 else if( anIsChannel )
635 theMenu->addAction( action( EditChannelId ) );
636 theMenu->addSeparator();
640 theMenu->addAction( action( EditDigueId ) );
641 theMenu->addSeparator();
643 else if( anIsObstacle )
645 theMenu->addAction( action( TranslateObstacleId ) );
646 theMenu->addSeparator();
648 else if( anIsStricklerTable )
650 theMenu->addAction( action( EditStricklerTableId ) );
651 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
652 theMenu->addAction( action( DuplicateStricklerTableId ) );
653 theMenu->addSeparator();
655 else if( anIsLandCover )
657 theMenu->addAction( action( EditLandCoverId ) );
658 theMenu->addSeparator();
660 else if( anIsVisualState && anIsObjectBrowser )
662 theMenu->addAction( action( SaveVisualStateId ) );
663 theMenu->addAction( action( LoadVisualStateId ) );
664 theMenu->addSeparator();
667 // Add set color action for geometrical objects
668 if ( anIsObjectCanBeColored )
670 theMenu->addAction( action( SetColorId ) );
671 theMenu->addSeparator();
673 } else if ( anAllAreProfiles ) {
674 theMenu->addAction( action( SelectedGeoreferencementId ) );
675 theMenu->addSeparator();
678 if (anIsPolyline || anIsPolyline3D)
679 theMenu->addAction( action( ExportPolylineId ) );
682 QAction* aCopyAction = action( CopyId );
683 if( aCopyAction && aCopyAction->isEnabled() ) {
684 theMenu->addAction( action( CopyId ) );
685 theMenu->addSeparator();
689 if( !anIsDummyObject3D )
690 theMenu->addAction( action( DeleteId ) );
692 theMenu->addSeparator();
694 if( anIsImage || anIsPolyline || anIsPolyline3D ||
695 anIsImmersibleZone || anIsZone || anIsRegion ||
696 anIsBathymetry || anIsObstacle || anIsStream ||
697 anIsChannel || anIsDigue || anIsDummyObject3D ||
698 anIsValidProfile || anIsGroup || anIsLandCover )
700 if( anIsHiddenInSelection )
701 theMenu->addAction( action( ShowId ) );
702 theMenu->addAction( action( ShowOnlyId ) );
703 if( anIsVisibleInSelection )
704 theMenu->addAction( action( HideId ) );
705 theMenu->addSeparator();
711 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
712 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
713 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
714 theMenu->addAction( action( DeleteId ) );
716 theMenu->addSeparator();
717 theMenu->addAction( action( SetZLevelId ) );
718 theMenu->addSeparator();
721 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
723 theMenu->addAction( action( ShowAllId ) );
724 theMenu->addAction( action( HideAllId ) );
725 theMenu->addSeparator();
728 if ( anIsOCCView || anIsVTKView )
730 theMenu->addSeparator();
731 theMenu->addAction( action( CopyViewerPositionId ) );
735 theMenu->addAction( action( EditLocalCSId ) );
737 if( anIsObjectBrowser && anOwners.size()==1 )
739 if( aSeq.Size() > 0 )
741 Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
742 if( !anObject.IsNull() )
744 theMenu->addSeparator();
745 theMenu->addAction( action( SubmersibleId ) );
746 action( SubmersibleId )->setCheckable( true );
747 action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
753 void HYDROGUI_Module::createPreferences()
755 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
756 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
758 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
759 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
761 // Set property cursor type
762 QList<QVariant> aCursorTypeIndicesList;
763 QList<QVariant> aCursorTypeIconsList;
765 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
766 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
767 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
768 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
769 aCursorTypeIndicesList << i;
770 aCursorTypeIconsList << pixmap;
773 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
774 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
776 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
777 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
778 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
780 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
781 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
782 LightApp_Preferences::DblSpin, "HYDRO", "default_strickler_coefficient" );
783 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
784 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
785 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
786 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
789 QCursor HYDROGUI_Module::getPrefEditCursor() const
791 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
792 if ( aCursorType >= Qt::BlankCursor)
794 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
798 void HYDROGUI_Module::update( const int flags )
800 if ( !isUpdateEnabled() )
803 QApplication::setOverrideCursor( Qt::WaitCursor );
805 // To prevent calling this method recursively
806 // from one of the methods called below
807 setUpdateEnabled( false );
809 // store selected objects
810 QStringList aSelectedEntries = storeSelection();
812 bool aDoFitAll = flags & UF_FitAll;
815 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
816 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
819 if( ( flags & UF_Viewer ) )
820 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
822 if( ( flags & UF_OCCViewer ) )
823 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
825 if( ( flags & UF_VTKViewer ) )
826 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
828 if( ( flags & UF_Model ) && getDataModel() && getApp() )
830 getDataModel()->update( getStudyId() );
832 // Temporary workaround to prevent breaking
833 // the selection in the object browser.
834 // Note: processEvents() should be called after updateGV(),
835 // otherwise the application crashes from time to time.
836 //RKV: qApp->processEvents();
837 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
838 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
839 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
840 if ( isResizeOnExpandItem && anObjectBrowser ) {
841 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
843 getApp()->updateObjectBrowser( true );
844 if ( isResizeOnExpandItem && anObjectBrowser ) {
845 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
849 // Object browser is currently updated by using UF_Model flag
850 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
851 getApp()->updateObjectBrowser( true );
853 if( ( flags & UF_Controls ) && getApp() )
854 getApp()->updateActions();
856 // restore selected objects
857 restoreSelection( aSelectedEntries );
859 setUpdateEnabled( true );
861 QApplication::restoreOverrideCursor();
864 void HYDROGUI_Module::updateCommandsStatus()
866 LightApp_Module::updateCommandsStatus();
868 updateUndoRedoControls();
870 action( CopyId )->setEnabled( getDataModel()->canCopy() );
871 action( PasteId )->setEnabled( getDataModel()->canPaste() );
874 void HYDROGUI_Module::selectionChanged()
876 LightApp_Module::selectionChanged();
877 updateCommandsStatus();
880 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
882 return (HYDROGUI_DataModel*)dataModel();
885 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
890 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
892 return myOCCDisplayer;
895 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
897 return myVTKDisplayer;
900 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
902 if( myViewManagerMap.contains( theId ) )
904 return myViewManagerMap[ theId ].first;
909 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
911 if( myViewManagerMap.contains( theId ) )
913 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
914 GraphicsView_ViewManager* aViewManager =
915 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
917 return aViewManager->getViewer();
922 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
924 if( myViewManagerMap.contains( theId ) )
926 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
927 OCCViewer_ViewManager* aViewManager =
928 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
930 return aViewManager->getOCCViewer();
935 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
937 if( myViewManagerMap.contains( theId ) )
939 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
940 SVTK_ViewManager* aViewManager =
941 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
943 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
948 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
950 ViewManagerMapIterator anIter( myViewManagerMap );
951 while( anIter.hasNext() )
953 int anId = anIter.next().key();
954 const ViewManagerInfo& anInfo = anIter.value();
955 if( anInfo.first == theViewManager )
961 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
963 int anId = getViewManagerId( theViewManager );
966 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
967 return anInfo.second;
972 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
973 const ViewManagerRole theRole )
975 int anId = getViewManagerId( theViewManager );
978 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
979 anInfo.second = theRole;
983 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
984 const Handle(HYDROData_Entity)& theObject ) const
986 if( theObject.IsNull() )
992 foreach( int aViewId, myObjectStateMap.keys() )
994 if( isObjectVisible( aViewId, theObject ) )
1000 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1001 if( anIter1 != myObjectStateMap.end() )
1003 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1004 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1006 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1007 if( anIter2 != aEntry2ObjectStateMap.end() )
1009 const ObjectState& anObjectState = anIter2.value();
1010 return anObjectState.Visibility;
1016 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1017 const Handle(HYDROData_Entity)& theObject,
1018 const bool theState )
1020 if( !theObject.IsNull() )
1022 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1023 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1025 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1026 anObjectState.Visibility = theState;
1028 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1031 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1032 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1033 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1034 if ( visState != Qtx::UnpresentableState )
1035 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1040 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1041 const bool theState )
1043 if( !theObject.IsNull() )
1045 // Process OCC shapes
1046 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1047 while( aShapesMapIter != myShapesMap.end() )
1049 const ListOfShapes& aShapesList = aShapesMapIter.value();
1050 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1052 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1054 aShape->setIsToUpdate( theState );
1059 // Process VTK shapes
1060 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1061 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1063 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1064 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1066 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1068 aShape->setIsToUpdate( theState );
1076 /////////////////// OCC SHAPES PROCESSING
1077 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1078 ObjectKind theKind ) const
1080 QList<HYDROGUI_Shape*> aResult;
1082 if ( myShapesMap.contains( theViewId ) )
1084 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1085 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1087 if( aShape && aShape->getObject()->GetKind()==theKind )
1088 aResult.append( aShape );
1094 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1095 const Handle(HYDROData_Entity)& theObject ) const
1097 HYDROGUI_Shape* aResShape = NULL;
1098 if( theObject.IsNull() )
1101 if ( myShapesMap.contains( theViewId ) )
1103 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1104 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1106 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1117 void HYDROGUI_Module::setObjectShape( const int theViewId,
1118 const Handle(HYDROData_Entity)& theObject,
1119 HYDROGUI_Shape* theShape )
1121 if( theObject.IsNull() )
1124 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1125 aViewShapes.append( theShape );
1128 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1129 const Handle(HYDROData_Entity)& theObject )
1131 if ( !myShapesMap.contains( theViewId ) )
1134 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1135 Handle(HYDROData_Entity) anObject;
1136 for ( int i = 0; i < aViewShapes.length(); )
1138 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1139 anObject = aShape->getObject();
1140 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1143 aViewShapes.removeAt( i );
1151 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1153 if ( !myShapesMap.contains( theViewId ) )
1156 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1157 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1159 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1164 myShapesMap.remove( theViewId );
1166 /////////////////// END OF OCC SHAPES PROCESSING
1168 /////////////////// VTKPrs PROCESSING
1169 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1170 const Handle(HYDROData_Entity)& theObject ) const
1172 HYDROGUI_VTKPrs* aResShape = NULL;
1173 if( theObject.IsNull() )
1176 if ( myVTKPrsMap.contains( theViewId ) )
1178 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1179 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1181 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1192 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1193 const Handle(HYDROData_Entity)& theObject,
1194 HYDROGUI_VTKPrs* theShape )
1196 if( theObject.IsNull() )
1199 if( theShape && theShape->needScalarBar() )
1201 // Compute the new global Z range from the added presentation and the old global Z range.
1202 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1203 double* aRange = theShape->getInternalZRange();
1204 bool anIsUpdate = false;
1205 if ( aRange[0] < aGlobalRange[0] )
1207 aGlobalRange[0] = aRange[0];
1210 if ( aRange[1] > aGlobalRange[1] )
1212 aGlobalRange[1] = aRange[1];
1218 updateVTKZRange( theViewId, aGlobalRange );
1222 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1223 aViewShapes.append( theShape );
1226 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1227 const QString& theEntry )
1229 if ( !myVTKPrsMap.contains( theViewId ) )
1232 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1233 Handle(HYDROData_Entity) anObject;
1235 for ( int i = 0; i < aViewShapes.length(); )
1237 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1238 anObject = aShape->getObject();
1239 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1240 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1243 aViewShapes.removeAt( i );
1250 // Invalidate global Z range
1251 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1252 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1255 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1256 const Handle(HYDROData_Entity)& theObject )
1258 if ( !myVTKPrsMap.contains( theViewId ) )
1261 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1262 Handle(HYDROData_Entity) anObject;
1263 for ( int i = 0; i < aViewShapes.length(); )
1265 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1266 anObject = aShape->getObject();
1267 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1270 aViewShapes.removeAt( i );
1277 // Invalidate global Z range
1278 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1279 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1282 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1284 if ( !myVTKPrsMap.contains( theViewId ) )
1287 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1288 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1290 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1295 myVTKPrsMap.remove( theViewId );
1298 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1300 if ( myVTKPrsMap.contains( theViewId ) )
1302 // For the given viewer id update all VTK presentations ...
1303 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1304 HYDROGUI_VTKPrs* aShape;
1305 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1307 aShape = aViewShapes.at( i );
1308 if ( aShape && aShape->needScalarBar() )
1310 aShape->setZRange( theRange );
1314 // ... and update the global color legend scalar bar.
1315 getVTKDisplayer()->SetZRange( theViewId, theRange );
1317 /////////////////// END OF VTKPrs PROCESSING
1319 CAM_DataModel* HYDROGUI_Module::createDataModel()
1321 return new HYDROGUI_DataModel( this );
1324 void HYDROGUI_Module::customEvent( QEvent* e )
1326 int aType = e->type();
1327 if ( aType == NewViewEvent )
1329 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1330 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1332 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1334 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1335 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1337 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1339 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1340 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1342 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1343 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1344 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1346 //ouv: temporarily commented
1347 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1350 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1351 update( UF_Viewer );
1353 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1359 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1361 QEvent::Type aType = theEvent->type();
1362 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1364 if( aType == QEvent::Show )
1366 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1367 e->setData( theObj );
1368 QApplication::postEvent( this, e );
1369 theObj->removeEventFilter( this );
1372 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1374 if( aType == QEvent::Leave )
1376 SUIT_Desktop* aDesktop = getApp()->desktop();
1377 if ( aDesktop && aDesktop->statusBar() ) {
1378 aDesktop->statusBar()->clearMessage();
1382 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1384 if( aType == QEvent::Leave )
1386 SUIT_Desktop* aDesktop = getApp()->desktop();
1387 if ( aDesktop && aDesktop->statusBar() ) {
1388 aDesktop->statusBar()->clearMessage();
1393 return LightApp_Module::eventFilter( theObj, theEvent );
1396 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1398 LightApp_Module::onViewManagerAdded( theViewManager );
1400 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1402 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1403 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1405 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1407 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1408 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1409 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1410 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1412 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1414 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1415 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1416 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1417 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1420 createSelector( theViewManager ); // replace the default selector
1422 ViewManagerInfo anInfo( theViewManager, VMR_General );
1423 myViewManagerMap.insert( ViewManagerId++, anInfo );
1426 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1428 LightApp_Module::onViewManagerRemoved( theViewManager );
1430 createSelector( theViewManager ); // replace the default selector
1432 int anId = getViewManagerId( theViewManager );
1435 OCCViewer_ViewManager* anOCCViewManager =
1436 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1437 if ( anOCCViewManager )
1439 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1441 removeViewShapes( (size_t)anOCCViewer );
1444 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1446 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1449 getVTKDisplayer()->EraseScalarBar( anId, true );
1450 removeViewShapes( (size_t)aVTKViewer );
1454 myViewManagerMap.remove( anId );
1458 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1460 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1462 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1464 aViewFrame->installEventFilter( this );
1466 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1468 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1469 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1472 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1474 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1476 aViewFrame->onTopView();
1478 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1480 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1482 aViewPort->installEventFilter( this );
1486 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1488 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1490 aViewFrame->installEventFilter( this );
1495 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1497 /* ouv: currently unused
1498 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1500 SUIT_ViewManager* aViewManager = 0;
1502 QObject* aParent = aViewPort;
1503 while( aParent = aParent->parent() )
1505 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1507 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1509 aViewManager = aViewer->getViewManager();
1518 double aMouseX = theEvent->scenePos().x();
1519 double aMouseY = theEvent->scenePos().y();
1521 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1522 if( aRole == VMR_General )
1524 int aXDeg = 0, aYDeg = 0;
1525 int aXMin = 0, aYMin = 0;
1526 double aXSec = 0, aYSec = 0;
1527 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1528 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1530 QString aDegSymbol( QChar( 0x00B0 ) );
1531 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1532 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1534 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1536 else if( aRole == VMR_TransformImage )
1537 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1542 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1543 const bool theIsInit,
1544 const bool theIsForced,
1545 const bool theDoFitAll )
1547 QList<int> aViewManagerIdList;
1549 // currently, all views are updated
1550 ViewManagerMapIterator anIter( myViewManagerMap );
1551 while( anIter.hasNext() )
1553 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1555 if ( theDisplayer->IsApplicable( aViewManager ) )
1557 int anId = anIter.key();
1558 aViewManagerIdList.append( anId );
1562 QListIterator<int> anIdIter( aViewManagerIdList );
1563 while( anIdIter.hasNext() )
1565 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1569 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1571 if( !theViewManager )
1574 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1575 if( !aSelectionMgr )
1578 QString aViewType = theViewManager->getType();
1579 if( aViewType != GraphicsView_Viewer::Type() &&
1580 aViewType != OCCViewer_Viewer::Type())
1583 QList<SUIT_Selector*> aSelectorList;
1584 aSelectionMgr->selectors( aViewType, aSelectorList );
1586 // disable all alien selectors
1587 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1588 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1590 SUIT_Selector* aSelector = *anIter;
1591 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1592 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1593 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1594 aSelector->setEnabled( false );
1597 if ( aViewType == GraphicsView_Viewer::Type() )
1599 GraphicsView_ViewManager* aViewManager =
1600 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1602 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1604 else if ( aViewType == OCCViewer_Viewer::Type() )
1606 OCCViewer_ViewManager* aViewManager =
1607 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1609 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1613 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1615 bool aPrevState = myIsUpdateEnabled;
1616 myIsUpdateEnabled = theState;
1620 bool HYDROGUI_Module::isUpdateEnabled() const
1622 return myIsUpdateEnabled;
1625 QStringList HYDROGUI_Module::storeSelection() const
1627 QStringList anEntryList;
1628 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1630 SUIT_DataOwnerPtrList aList( true );
1631 aSelectionMgr->selected( aList );
1633 SUIT_DataOwnerPtrList::iterator anIter;
1634 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1636 const LightApp_DataOwner* anOwner =
1637 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1639 anEntryList.append( anOwner->entry() );
1645 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1647 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1649 SUIT_DataOwnerPtrList aList( true );
1650 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1651 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1652 aSelectionMgr->setSelected( aList );
1656 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1659 bool doShow = false;
1660 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1662 aDisplayer->SaveCursorViewPosition( theViewWindow );
1663 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1667 // Show the coordinates in the status bar
1668 SUIT_Desktop* aDesktop = getApp()->desktop();
1669 if ( aDesktop && aDesktop->statusBar() )
1671 gp_Pnt aWPnt( X, Y, Z );
1672 int aStudyId = application()->activeStudy()->id();
1673 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1674 double WX = aWPnt.X(), WY = aWPnt.Y();
1676 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1677 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1678 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1679 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1680 QString aMsg = tr( "COORDINATES_INFO" );
1681 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1682 aDesktop->statusBar()->showMessage( aMsg );
1688 * Returns stack of active operations;
1690 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1692 return myActiveOperationMap;
1696 * Returns the module active operation. If the active operation is show/hide,
1697 * the method returns the previous operation if it is.
1699 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1701 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1703 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1705 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1707 aVIt.previous(); // skip the top show/hide operation
1708 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1715 * \brief Virtual public slot
1717 * This method is called after the object inserted into data view to update their visibility state
1718 * This is default implementation
1720 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1722 if ( !isActiveModule() )
1725 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1727 // change visibility of object
1728 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1731 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1733 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1734 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1735 if ( visState == Qtx::UnpresentableState )
1738 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1739 treeModel->setVisibilityState( id, visState );
1741 bool vis = visState == Qtx::ShownState;
1742 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1745 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1747 update( UF_OCCViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );