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>
49 #include <HYDROData_StricklerTable.h>
51 #include <HYDROData_OperationsFactory.h>
53 #include <CurveCreator_Utils.hxx>
55 #include <GraphicsView_ViewFrame.h>
56 #include <GraphicsView_ViewManager.h>
57 #include <GraphicsView_ViewPort.h>
58 #include <GraphicsView_Viewer.h>
60 #include <ImageComposer_CutOperator.h>
61 #include <ImageComposer_CropOperator.h>
62 #include <ImageComposer_FuseOperator.h>
64 #include <LightApp_Application.h>
65 #include <LightApp_DataOwner.h>
66 #include <LightApp_GVSelector.h>
67 #include <LightApp_SelectionMgr.h>
68 #include <LightApp_UpdateFlags.h>
70 #include <SalomeApp_Study.h>
72 #include <OCCViewer_ViewFrame.h>
73 #include <OCCViewer_ViewManager.h>
74 #include <OCCViewer_ViewModel.h>
76 #include <SALOME_Event.h>
78 #include <SUIT_DataBrowser.h>
79 #include <SUIT_DataObject.h>
80 #include <SUIT_ViewManager.h>
81 #include <SUIT_ResourceMgr.h>
82 #include <SUIT_Desktop.h>
83 #include <SUIT_Study.h>
84 #include <SUIT_Session.h>
86 #include <SVTK_ViewManager.h>
87 #include <SVTK_ViewModel.h>
88 #include <SVTK_ViewWindow.h>
89 #include <SVTK_Selector.h>
91 #include <OCCViewer_ViewPort3d.h>
93 #include <GEOMUtils.hxx>
94 #include <GeometryGUI.h>
96 #include <SALOMEDS_wrap.hxx>
99 #include <QApplication>
100 #include <QGraphicsSceneMouseEvent>
102 #include <QMouseEvent>
103 #include <QStatusBar>
106 static int ViewManagerId = 0;
108 extern "C" HYDRO_EXPORT CAM_Module* createModule()
110 return new HYDROGUI_Module();
113 extern "C" HYDRO_EXPORT char* getModuleVersion()
115 return (char*)HYDRO_VERSION;
118 HYDROGUI_Module::HYDROGUI_Module()
119 : LightApp_Module( "HYDRO" ),
122 myIsUpdateEnabled( true )
126 HYDROGUI_Module::~HYDROGUI_Module()
130 int HYDROGUI_Module::getStudyId() const
132 LightApp_Application* anApp = getApp();
133 return anApp ? anApp->activeStudy()->id() : 0;
136 void HYDROGUI_Module::initialize( CAM_Application* theApp )
138 LightApp_Module::initialize( theApp );
141 createUndoRedoActions();
146 setMenuShown( false );
147 setToolShown( false );
149 myDisplayer = new HYDROGUI_Displayer( this );
150 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
151 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
154 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
156 bool aRes = LightApp_Module::activateModule( theStudy );
158 LightApp_Application* anApp = getApp();
159 SUIT_Desktop* aDesktop = anApp->desktop();
161 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
163 setMenuShown( true );
164 setToolShown( true );
166 #ifndef DISABLE_PYCONSOLE
167 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
168 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
171 // Remove defunct view managers from the map.
172 // It's essential to do this before "update( UF_All )" call!
173 QList<int> anObsoleteIds;
174 ViewManagerList anAllViewManagers = anApp->viewManagers();
175 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
176 ViewManagerMapIterator anIter( myViewManagerMap );
177 while( anIter.hasNext() ) {
178 int anId = anIter.next().key();
179 const ViewManagerInfo& anInfo = anIter.value();
181 aHydroViewManagers << anInfo.first;
183 if ( !anAllViewManagers.contains( anInfo.first ) ) {
184 anObsoleteIds << anId;
187 foreach ( const int anId, anObsoleteIds ) {
188 myViewManagerMap.remove( anId );
189 myObjectStateMap.remove( anId );
190 myShapesMap.remove( anId );
191 myVTKPrsMap.remove( anId );
193 // Replace the default selector for all view managers.
194 // Add view managers created outside of HYDRO module to the map.
195 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
196 createSelector( aViewManager ); // replace the default selector
197 if ( !aHydroViewManagers.contains( aViewManager ) ) {
198 ViewManagerInfo anInfo( aViewManager, VMR_General );
199 myViewManagerMap.insert( ViewManagerId++, anInfo );
205 updateCommandsStatus();
207 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
209 ViewManagerList anOCCViewManagers;
210 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
211 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
212 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
213 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
214 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
215 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
216 if ( aViewFrame && aViewFrame->getViewPort() ) {
217 aViewFrame->getViewPort()->installEventFilter( this );
223 SalomeApp_Study* aStudy =
224 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
226 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
227 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
228 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
229 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
230 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
231 if( !GEOM_var->_is_nil() ) {
232 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
237 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
238 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
239 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
244 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
247 ViewManagerMapIterator anIter( myViewManagerMap );
248 while( anIter.hasNext() )
249 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
250 getApp()->removeViewManager( aViewManager );
251 myViewManagerMap.clear();
254 ViewManagerList anOCCViewManagers;
255 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
256 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
257 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
258 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
262 myObjectStateMap.clear();
267 // clear the status bar
268 SUIT_Desktop* aDesktop = getApp()->desktop();
269 if ( aDesktop && aDesktop->statusBar() ) {
270 aDesktop->statusBar()->clearMessage();
273 // clear the data model's list of copying objects
274 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
276 setMenuShown( false );
277 setToolShown( false );
279 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
281 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
283 myActiveOperationMap.clear();
284 return LightApp_Module::deactivateModule( theStudy );
287 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
290 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
291 #ifndef DISABLE_PYCONSOLE
292 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
294 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
297 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
299 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
302 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
306 HYDROGUI_DataModel* aModel = getDataModel();
308 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
309 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
310 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
311 bool anIsVTKView = theClient == SVTK_Viewer::Type();
312 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
315 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
317 bool anIsSelectedDataObjects = false;
318 bool anIsVisibleInSelection = false;
319 bool anIsHiddenInSelection = false;
321 bool anIsImage = false;
322 bool anIsImportedImage = false;
323 bool anIsImageHasRefs = false;
324 bool anIsFusedImage = false;
325 bool anIsCutImage = false;
326 bool anIsSplittedImage = false;
327 bool anIsMustObjectBeUpdated = false;
328 bool anIsPolyline = false;
329 bool anIsPolyline3D = false;
330 bool anIsProfile = false;
331 bool anIsValidProfile = false;
332 bool anAllAreProfiles = false;
333 bool anIsBathymetry = false;
334 bool anIsCalculation = false;
335 bool anIsImmersibleZone = false;
336 bool anIsVisualState = false;
337 bool anIsRegion = false;
338 bool anIsZone = false;
339 bool anIsObstacle = false;
340 bool anIsStricklerTable = false;
341 bool anIsLandCover = false;
342 bool anIsStream = false;
343 bool anIsChannel = false;
344 bool anIsDigue = false;
345 bool anIsDummyObject3D = false;
346 bool anIsGroup = false;
347 bool anIsObjectCanBeColored = false;
349 bool isStreamHasBottom = false;
351 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
352 SUIT_DataOwnerPtrList anOwners;
353 aSelectionMgr->selected( anOwners );
354 if( anIsObjectBrowser && anOwners.size()==1 )
356 QString anEntry = anOwners[0]->keyString();
357 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
359 isRoot = aStudy->isComponent( anEntry );
362 // Check the selected GEOM objects (take into account the Object Browser only)
363 if ( anIsObjectBrowser ) {
364 QList<GEOM::shape_type> anObstacleTypes =
365 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
366 QList<GEOM::shape_type> aPolylineTypes =
367 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
369 bool isCanBeImportedAsObstacle =
370 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
371 bool isCanBeImportedAsPolyline =
372 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
374 // Add import as obstacle action
375 if ( isCanBeImportedAsObstacle ) {
376 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
378 // Add import as polyline action
379 if ( isCanBeImportedAsPolyline ) {
380 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
383 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
384 theMenu->addSeparator();
388 // check the selected data model objects
389 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
390 int aNbOfSelectedProfiles = 0;
391 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
393 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
394 if( !anObject.IsNull() )
396 anIsSelectedDataObjects = true;
398 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
399 anIsVisibleInSelection |= aVisibility;
400 anIsHiddenInSelection |= !aVisibility;
402 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
404 anIsMustObjectBeUpdated = true;
407 ObjectKind anObjectKind = anObject->GetKind();
408 if( anObjectKind == KIND_IMAGE )
411 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
412 if( !anImage.IsNull() )
414 anIsImportedImage = anImage->HasLocalPoints();
415 anIsImageHasRefs = anImage->HasReferences();
416 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
418 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
420 QString anOperatorName = anOperator->name();
421 if( anOperatorName == ImageComposer_FuseOperator::Type() )
422 anIsFusedImage = true;
423 else if( anOperatorName == ImageComposer_CutOperator::Type() )
425 else if( anOperatorName == ImageComposer_CropOperator::Type() )
426 anIsSplittedImage = true;
431 else if( anObjectKind == KIND_POLYLINEXY )
433 else if( anObjectKind == KIND_POLYLINE )
434 anIsPolyline3D = true;
435 else if( anObjectKind == KIND_PROFILE )
438 aNbOfSelectedProfiles++;
440 Handle(HYDROData_Profile) aProfile =
441 Handle(HYDROData_Profile)::DownCast( anObject );
442 if( !aProfile.IsNull() && aProfile->IsValid() ) {
443 anIsValidProfile = true;
446 else if( anObjectKind == KIND_CALCULATION )
447 anIsCalculation = true;
448 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
449 anIsImmersibleZone = true;
450 else if( anObjectKind == KIND_VISUAL_STATE )
451 anIsVisualState = true;
452 else if( anObjectKind == KIND_REGION )
454 else if( anObjectKind == KIND_ZONE )
456 else if( anObjectKind == KIND_BATHYMETRY )
457 anIsBathymetry = true;
458 else if( anObjectKind == KIND_OBSTACLE )
460 else if( anObjectKind == KIND_STRICKLER_TABLE )
461 anIsStricklerTable = true;
462 else if( anObjectKind == KIND_LAND_COVER )
463 anIsLandCover = true;
464 else if( anObjectKind == KIND_STREAM )
467 Handle(HYDROData_Stream) aStream =
468 Handle(HYDROData_Stream)::DownCast( anObject );
469 if ( !aStream.IsNull() )
470 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
472 else if( anObjectKind == KIND_CHANNEL )
474 else if( anObjectKind == KIND_DIGUE )
476 else if( anObjectKind == KIND_DUMMY_3D )
477 anIsDummyObject3D = true;
478 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
482 if ( !anIsObjectCanBeColored )
483 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
486 // Check if all selected objects are profiles
487 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
488 ( aNbOfSelectedProfiles == aSeq.Length() );
490 // check the selected partitions
491 if( !anIsSelectedDataObjects && anIsObjectBrowser )
493 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
494 if( aSelectedPartition != KIND_UNKNOWN )
496 switch( aSelectedPartition )
499 theMenu->addAction( action( ImportImageId ) );
501 case KIND_BATHYMETRY:
502 theMenu->addAction( action( ImportBathymetryId ) );
504 case KIND_ARTIFICIAL_OBJECT:
505 theMenu->addAction( action( CreateChannelId ) );
506 theMenu->addAction( action( CreateDigueId ) );
508 case KIND_NATURAL_OBJECT:
509 theMenu->addAction( action( CreateImmersibleZoneId ) );
510 theMenu->addAction( action( CreateStreamId ) );
513 theMenu->addAction( action( ImportObstacleFromFileId ) );
514 theMenu->addAction( action( CreateBoxId ) );
515 theMenu->addAction( action( CreateCylinderId ) );
517 case KIND_STRICKLER_TABLE:
518 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
520 case KIND_LAND_COVER:
521 theMenu->addAction( action( CreateLandCoverId ) );
523 case KIND_CALCULATION:
524 theMenu->addAction( action( CreateCalculationId ) );
526 case KIND_POLYLINEXY:
527 theMenu->addAction( action( ImportPolylineId ) );
528 theMenu->addAction( action( CreatePolylineId ) );
531 theMenu->addAction( action( CreatePolyline3DId ) );
534 theMenu->addAction( action( CreateProfileId ) );
535 theMenu->addAction( action( ImportProfilesId ) );
536 theMenu->addAction( action( AllGeoreferencementId ) );
538 case KIND_VISUAL_STATE:
539 theMenu->addAction( action( SaveVisualStateId ) );
542 theMenu->addSeparator();
546 if( anIsSelectedDataObjects )
548 if ( anIsMustObjectBeUpdated )
550 theMenu->addAction( action( UpdateObjectId ) );
551 theMenu->addSeparator();
555 theMenu->addAction( action( ForcedUpdateObjectId ) );
556 theMenu->addSeparator();
560 if( aSeq.Length() == 1 )
564 if( anIsImportedImage )
565 theMenu->addAction( action( EditImportedImageId ) );
566 else if( anIsImageHasRefs )
569 theMenu->addAction( action( EditFusedImageId ) );
570 else if( anIsCutImage )
571 theMenu->addAction( action( EditCutImageId ) );
572 else if( anIsSplittedImage )
573 theMenu->addAction( action( EditSplittedImageId ) );
576 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
577 theMenu->addAction( action( ExportImageId ) );
578 theMenu->addSeparator();
580 if( anIsImageHasRefs )
582 theMenu->addAction( action( RemoveImageRefsId ) );
583 theMenu->addSeparator();
586 theMenu->addAction( action( FuseImagesId ) );
587 theMenu->addAction( action( CutImagesId ) );
588 theMenu->addAction( action( SplitImageId ) );
589 theMenu->addSeparator();
590 theMenu->addAction( action( RecognizeContoursId ) );
591 theMenu->addSeparator();
593 else if( anIsBathymetry )
595 theMenu->addAction( action( EditImportedBathymetryId ) );
596 theMenu->addAction( action( BathymetryBoundsId ) );
597 theMenu->addSeparator();
599 else if( anIsPolyline )
601 theMenu->addAction( action( EditPolylineId ) );
602 theMenu->addSeparator();
603 theMenu->addAction( action( SplitPolylinesId ) );
604 theMenu->addAction( action( MergePolylinesId ) );
605 theMenu->addSeparator();
607 else if( anIsPolyline3D )
609 theMenu->addAction( action( EditPolyline3DId ) );
610 theMenu->addSeparator();
612 else if( anIsProfile )
614 theMenu->addAction( action( EditProfileId ) );
615 theMenu->addAction( action( SelectedGeoreferencementId ) );
616 theMenu->addSeparator();
618 else if( anIsCalculation )
620 theMenu->addAction( action( EditCalculationId ) );
621 theMenu->addAction( action( ExportCalculationId ) );
622 theMenu->addSeparator();
624 else if( anIsImmersibleZone )
626 theMenu->addAction( action( EditImmersibleZoneId ) );
627 theMenu->addSeparator();
629 else if( anIsStream )
631 theMenu->addAction( action( EditStreamId ) );
632 if ( action( RiverBottomContextId ) )
634 theMenu->addAction( action( RiverBottomContextId ) );
635 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
637 theMenu->addAction( action( ProfileInterpolateId ) );
638 theMenu->addSeparator();
640 else if( anIsChannel )
642 theMenu->addAction( action( EditChannelId ) );
643 theMenu->addSeparator();
647 theMenu->addAction( action( EditDigueId ) );
648 theMenu->addSeparator();
650 else if( anIsObstacle )
652 theMenu->addAction( action( TranslateObstacleId ) );
653 theMenu->addSeparator();
655 else if( anIsStricklerTable )
657 theMenu->addAction( action( EditStricklerTableId ) );
658 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
659 theMenu->addAction( action( DuplicateStricklerTableId ) );
660 theMenu->addSeparator();
662 Handle(HYDROData_StricklerTable) aTable =
663 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
664 QString aCurrentTable =
665 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
666 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
668 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER ).isEmpty() ) {
669 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
670 theMenu->addSeparator();
673 else if( anIsLandCover )
675 theMenu->addAction( action( EditLandCoverId ) );
676 theMenu->addSeparator();
678 else if( anIsVisualState && anIsObjectBrowser )
680 theMenu->addAction( action( SaveVisualStateId ) );
681 theMenu->addAction( action( LoadVisualStateId ) );
682 theMenu->addSeparator();
685 // Add set color action for geometrical objects
686 if ( anIsObjectCanBeColored )
688 theMenu->addAction( action( SetColorId ) );
689 theMenu->addSeparator();
691 } else if ( anAllAreProfiles ) {
692 theMenu->addAction( action( SelectedGeoreferencementId ) );
693 theMenu->addSeparator();
696 bool anIsPoly = anIsPolyline || anIsPolyline3D;
697 if ((anIsPoly && !anIsLandCover) || (!anIsPoly && anIsLandCover))
698 theMenu->addAction( action( ExportToShapeFileID ) );
701 QAction* aCopyAction = action( CopyId );
702 if( aCopyAction && aCopyAction->isEnabled() ) {
703 theMenu->addAction( action( CopyId ) );
704 theMenu->addSeparator();
708 if( !anIsDummyObject3D )
709 theMenu->addAction( action( DeleteId ) );
711 theMenu->addSeparator();
713 if( anIsImage || anIsPolyline || anIsPolyline3D ||
714 anIsImmersibleZone || anIsZone || anIsRegion ||
715 anIsBathymetry || anIsObstacle || anIsStream ||
716 anIsChannel || anIsDigue || anIsDummyObject3D ||
717 anIsValidProfile || anIsGroup || anIsLandCover )
719 if( anIsHiddenInSelection )
720 theMenu->addAction( action( ShowId ) );
721 theMenu->addAction( action( ShowOnlyId ) );
722 if( anIsVisibleInSelection )
723 theMenu->addAction( action( HideId ) );
724 theMenu->addSeparator();
730 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
731 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
732 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
733 theMenu->addAction( action( DeleteId ) );
735 theMenu->addSeparator();
736 theMenu->addAction( action( SetZLevelId ) );
737 theMenu->addSeparator();
739 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
740 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
741 theMenu->addSeparator();
745 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
747 theMenu->addAction( action( ShowAllId ) );
748 theMenu->addAction( action( HideAllId ) );
749 theMenu->addSeparator();
752 if ( anIsOCCView || anIsVTKView )
754 theMenu->addSeparator();
755 theMenu->addAction( action( CopyViewerPositionId ) );
759 theMenu->addAction( action( EditLocalCSId ) );
761 if( anIsObjectBrowser && anOwners.size()==1 )
763 if( aSeq.Size() > 0 )
765 Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
766 if( !anObject.IsNull() )
768 theMenu->addSeparator();
769 theMenu->addAction( action( SubmersibleId ) );
770 action( SubmersibleId )->setCheckable( true );
771 action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
777 void HYDROGUI_Module::createPreferences()
779 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
780 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
782 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
783 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
785 // Set property cursor type
786 QList<QVariant> aCursorTypeIndicesList;
787 QList<QVariant> aCursorTypeIconsList;
789 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
790 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
791 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
792 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
793 aCursorTypeIndicesList << i;
794 aCursorTypeIconsList << pixmap;
797 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
798 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
800 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
801 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
802 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
804 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
805 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
806 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
807 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
808 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
809 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
810 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
813 QCursor HYDROGUI_Module::getPrefEditCursor() const
815 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
816 if ( aCursorType >= Qt::BlankCursor)
818 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
822 void HYDROGUI_Module::update( const int flags )
824 if ( !isUpdateEnabled() )
827 QApplication::setOverrideCursor( Qt::WaitCursor );
829 // To prevent calling this method recursively
830 // from one of the methods called below
831 setUpdateEnabled( false );
833 // store selected objects
834 QStringList aSelectedEntries = storeSelection();
836 bool aDoFitAll = flags & UF_FitAll;
839 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
840 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
843 if( ( flags & UF_Viewer ) )
844 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
846 if( ( flags & UF_OCCViewer ) )
847 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
849 if( ( flags & UF_VTKViewer ) )
850 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
852 if( ( flags & UF_Model ) && getDataModel() && getApp() )
854 getDataModel()->update( getStudyId() );
856 // Temporary workaround to prevent breaking
857 // the selection in the object browser.
858 // Note: processEvents() should be called after updateGV(),
859 // otherwise the application crashes from time to time.
860 //RKV: qApp->processEvents();
861 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
862 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
863 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
864 if ( isResizeOnExpandItem && anObjectBrowser ) {
865 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
867 getApp()->updateObjectBrowser( true );
868 if ( isResizeOnExpandItem && anObjectBrowser ) {
869 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
873 // Object browser is currently updated by using UF_Model flag
874 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
875 getApp()->updateObjectBrowser( true );
877 if( ( flags & UF_Controls ) && getApp() )
878 getApp()->updateActions();
880 // restore selected objects
881 restoreSelection( aSelectedEntries );
883 setUpdateEnabled( true );
885 QApplication::restoreOverrideCursor();
888 void HYDROGUI_Module::updateCommandsStatus()
890 LightApp_Module::updateCommandsStatus();
892 updateUndoRedoControls();
894 action( CopyId )->setEnabled( getDataModel()->canCopy() );
895 action( PasteId )->setEnabled( getDataModel()->canPaste() );
898 void HYDROGUI_Module::selectionChanged()
900 LightApp_Module::selectionChanged();
901 updateCommandsStatus();
904 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
906 return (HYDROGUI_DataModel*)dataModel();
909 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
914 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
916 return myOCCDisplayer;
919 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
921 return myVTKDisplayer;
924 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
926 if( myViewManagerMap.contains( theId ) )
928 return myViewManagerMap[ theId ].first;
933 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
935 if( myViewManagerMap.contains( theId ) )
937 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
938 GraphicsView_ViewManager* aViewManager =
939 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
941 return aViewManager->getViewer();
946 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
948 if( myViewManagerMap.contains( theId ) )
950 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
951 OCCViewer_ViewManager* aViewManager =
952 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
954 return aViewManager->getOCCViewer();
959 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
961 if( myViewManagerMap.contains( theId ) )
963 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
964 SVTK_ViewManager* aViewManager =
965 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
967 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
972 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
974 ViewManagerMapIterator anIter( myViewManagerMap );
975 while( anIter.hasNext() )
977 int anId = anIter.next().key();
978 const ViewManagerInfo& anInfo = anIter.value();
979 if( anInfo.first == theViewManager )
985 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
987 int anId = getViewManagerId( theViewManager );
990 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
991 return anInfo.second;
996 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
997 const ViewManagerRole theRole )
999 int anId = getViewManagerId( theViewManager );
1002 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1003 anInfo.second = theRole;
1007 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1008 const Handle(HYDROData_Entity)& theObject ) const
1010 if( theObject.IsNull() )
1016 foreach( int aViewId, myObjectStateMap.keys() )
1018 if( isObjectVisible( aViewId, theObject ) )
1024 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1025 if( anIter1 != myObjectStateMap.end() )
1027 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1028 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1030 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1031 if( anIter2 != aEntry2ObjectStateMap.end() )
1033 const ObjectState& anObjectState = anIter2.value();
1034 return anObjectState.Visibility;
1040 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1041 const Handle(HYDROData_Entity)& theObject,
1042 const bool theState )
1044 if( !theObject.IsNull() )
1046 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1047 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1049 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1050 anObjectState.Visibility = theState;
1052 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1055 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1056 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1057 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1058 if ( visState != Qtx::UnpresentableState )
1059 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1062 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1063 setLandCoversScalarMapModeOff( theViewId );
1064 } else if ( theObject->GetKind() == KIND_LAND_COVER && theState ) {
1065 getOCCDisplayer()->SetToUpdateColorScale();
1070 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1071 const bool theState )
1073 if( !theObject.IsNull() )
1075 // Process OCC shapes
1076 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1077 while( aShapesMapIter != myShapesMap.end() )
1079 const ListOfShapes& aShapesList = aShapesMapIter.value();
1080 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1082 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1084 aShape->setIsToUpdate( theState );
1089 // Process VTK shapes
1090 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1091 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1093 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1094 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1096 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1098 aShape->setIsToUpdate( theState );
1106 /////////////////// OCC SHAPES PROCESSING
1107 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1108 ObjectKind theKind ) const
1110 QList<HYDROGUI_Shape*> aResult;
1112 if ( myShapesMap.contains( theViewId ) )
1114 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1115 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1117 if( aShape && aShape->getObject()->GetKind()==theKind )
1118 aResult.append( aShape );
1124 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1125 const Handle(HYDROData_Entity)& theObject ) const
1127 HYDROGUI_Shape* aResShape = NULL;
1128 if( theObject.IsNull() )
1131 if ( myShapesMap.contains( theViewId ) )
1133 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1134 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1136 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1147 void HYDROGUI_Module::setObjectShape( const int theViewId,
1148 const Handle(HYDROData_Entity)& theObject,
1149 HYDROGUI_Shape* theShape )
1151 if( theObject.IsNull() )
1154 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1155 aViewShapes.append( theShape );
1158 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1159 const Handle(HYDROData_Entity)& theObject )
1161 if ( !myShapesMap.contains( theViewId ) )
1164 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1165 Handle(HYDROData_Entity) anObject;
1166 for ( int i = 0; i < aViewShapes.length(); )
1168 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1169 anObject = aShape->getObject();
1170 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1173 aViewShapes.removeAt( i );
1181 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1183 if ( !myShapesMap.contains( theViewId ) )
1186 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1187 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1189 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1194 myShapesMap.remove( theViewId );
1196 /////////////////// END OF OCC SHAPES PROCESSING
1198 /////////////////// VTKPrs PROCESSING
1199 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1200 const Handle(HYDROData_Entity)& theObject ) const
1202 HYDROGUI_VTKPrs* aResShape = NULL;
1203 if( theObject.IsNull() )
1206 if ( myVTKPrsMap.contains( theViewId ) )
1208 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1209 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1211 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1222 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1223 const Handle(HYDROData_Entity)& theObject,
1224 HYDROGUI_VTKPrs* theShape )
1226 if( theObject.IsNull() )
1229 if( theShape && theShape->needScalarBar() )
1231 // Compute the new global Z range from the added presentation and the old global Z range.
1232 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1233 double* aRange = theShape->getInternalZRange();
1234 bool anIsUpdate = false;
1235 if ( aRange[0] < aGlobalRange[0] )
1237 aGlobalRange[0] = aRange[0];
1240 if ( aRange[1] > aGlobalRange[1] )
1242 aGlobalRange[1] = aRange[1];
1248 updateVTKZRange( theViewId, aGlobalRange );
1252 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1253 aViewShapes.append( theShape );
1256 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1257 const QString& theEntry )
1259 if ( !myVTKPrsMap.contains( theViewId ) )
1262 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1263 Handle(HYDROData_Entity) anObject;
1265 for ( int i = 0; i < aViewShapes.length(); )
1267 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1268 anObject = aShape->getObject();
1269 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1270 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1273 aViewShapes.removeAt( i );
1280 // Invalidate global Z range
1281 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1282 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1285 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1286 const Handle(HYDROData_Entity)& theObject )
1288 if ( !myVTKPrsMap.contains( theViewId ) )
1291 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1292 Handle(HYDROData_Entity) anObject;
1293 for ( int i = 0; i < aViewShapes.length(); )
1295 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1296 anObject = aShape->getObject();
1297 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1300 aViewShapes.removeAt( i );
1307 // Invalidate global Z range
1308 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1309 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1312 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1314 if ( !myVTKPrsMap.contains( theViewId ) )
1317 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1318 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1320 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1325 myVTKPrsMap.remove( theViewId );
1328 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1330 if ( myVTKPrsMap.contains( theViewId ) )
1332 // For the given viewer id update all VTK presentations ...
1333 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1334 HYDROGUI_VTKPrs* aShape;
1335 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1337 aShape = aViewShapes.at( i );
1338 if ( aShape && aShape->needScalarBar() )
1340 aShape->setZRange( theRange );
1344 // ... and update the global color legend scalar bar.
1345 getVTKDisplayer()->SetZRange( theViewId, theRange );
1347 /////////////////// END OF VTKPrs PROCESSING
1349 CAM_DataModel* HYDROGUI_Module::createDataModel()
1351 return new HYDROGUI_DataModel( this );
1354 void HYDROGUI_Module::customEvent( QEvent* e )
1356 int aType = e->type();
1357 if ( aType == NewViewEvent )
1359 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1360 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1362 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1364 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1365 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1367 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1369 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1370 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1372 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1373 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1374 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1376 //ouv: temporarily commented
1377 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1380 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1381 update( UF_Viewer );
1383 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1389 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1391 QEvent::Type aType = theEvent->type();
1392 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1394 if( aType == QEvent::Show )
1396 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1397 e->setData( theObj );
1398 QApplication::postEvent( this, e );
1399 theObj->removeEventFilter( this );
1402 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1404 if( aType == QEvent::Leave )
1406 SUIT_Desktop* aDesktop = getApp()->desktop();
1407 if ( aDesktop && aDesktop->statusBar() ) {
1408 aDesktop->statusBar()->clearMessage();
1412 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1414 if( aType == QEvent::Leave )
1416 SUIT_Desktop* aDesktop = getApp()->desktop();
1417 if ( aDesktop && aDesktop->statusBar() ) {
1418 aDesktop->statusBar()->clearMessage();
1423 return LightApp_Module::eventFilter( theObj, theEvent );
1426 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1428 LightApp_Module::onViewManagerAdded( theViewManager );
1430 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1432 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1433 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1435 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1437 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1438 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1439 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1440 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1442 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1444 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1445 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1446 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1447 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1450 createSelector( theViewManager ); // replace the default selector
1452 ViewManagerInfo anInfo( theViewManager, VMR_General );
1453 myViewManagerMap.insert( ViewManagerId++, anInfo );
1456 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1458 LightApp_Module::onViewManagerRemoved( theViewManager );
1460 createSelector( theViewManager ); // replace the default selector
1462 int anId = getViewManagerId( theViewManager );
1465 OCCViewer_ViewManager* anOCCViewManager =
1466 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1467 if ( anOCCViewManager )
1469 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1470 if ( anOCCViewer ) {
1471 int aViewerId = (size_t)anOCCViewer;
1472 removeViewShapes( aViewerId );
1473 setLandCoversScalarMapModeOff( aViewerId );
1477 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1479 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1482 getVTKDisplayer()->EraseScalarBar( anId, true );
1483 removeViewShapes( (size_t)aVTKViewer );
1487 myViewManagerMap.remove( anId );
1491 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1493 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1495 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1497 aViewFrame->installEventFilter( this );
1499 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1501 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1502 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1505 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1507 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1509 aViewFrame->onTopView();
1511 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1513 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1515 aViewPort->installEventFilter( this );
1519 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1521 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1523 aViewFrame->installEventFilter( this );
1528 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1530 /* ouv: currently unused
1531 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1533 SUIT_ViewManager* aViewManager = 0;
1535 QObject* aParent = aViewPort;
1536 while( aParent = aParent->parent() )
1538 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1540 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1542 aViewManager = aViewer->getViewManager();
1551 double aMouseX = theEvent->scenePos().x();
1552 double aMouseY = theEvent->scenePos().y();
1554 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1555 if( aRole == VMR_General )
1557 int aXDeg = 0, aYDeg = 0;
1558 int aXMin = 0, aYMin = 0;
1559 double aXSec = 0, aYSec = 0;
1560 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1561 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1563 QString aDegSymbol( QChar( 0x00B0 ) );
1564 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1565 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1567 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1569 else if( aRole == VMR_TransformImage )
1570 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1575 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1576 const bool theIsInit,
1577 const bool theIsForced,
1578 const bool theDoFitAll )
1580 QList<int> aViewManagerIdList;
1582 // currently, all views are updated
1583 ViewManagerMapIterator anIter( myViewManagerMap );
1584 while( anIter.hasNext() )
1586 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1588 if ( theDisplayer->IsApplicable( aViewManager ) )
1590 int anId = anIter.key();
1591 aViewManagerIdList.append( anId );
1595 QListIterator<int> anIdIter( aViewManagerIdList );
1596 while( anIdIter.hasNext() )
1598 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1602 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1604 if( !theViewManager )
1607 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1608 if( !aSelectionMgr )
1611 QString aViewType = theViewManager->getType();
1612 if( aViewType != GraphicsView_Viewer::Type() &&
1613 aViewType != OCCViewer_Viewer::Type())
1616 QList<SUIT_Selector*> aSelectorList;
1617 aSelectionMgr->selectors( aViewType, aSelectorList );
1619 // disable all alien selectors
1620 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1621 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1623 SUIT_Selector* aSelector = *anIter;
1624 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1625 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1626 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1627 aSelector->setEnabled( false );
1630 if ( aViewType == GraphicsView_Viewer::Type() )
1632 GraphicsView_ViewManager* aViewManager =
1633 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1635 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1637 else if ( aViewType == OCCViewer_Viewer::Type() )
1639 OCCViewer_ViewManager* aViewManager =
1640 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1642 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1646 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1648 bool aPrevState = myIsUpdateEnabled;
1649 myIsUpdateEnabled = theState;
1653 bool HYDROGUI_Module::isUpdateEnabled() const
1655 return myIsUpdateEnabled;
1658 QStringList HYDROGUI_Module::storeSelection() const
1660 QStringList anEntryList;
1661 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1663 SUIT_DataOwnerPtrList aList( true );
1664 aSelectionMgr->selected( aList );
1666 SUIT_DataOwnerPtrList::iterator anIter;
1667 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1669 const LightApp_DataOwner* anOwner =
1670 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1672 anEntryList.append( anOwner->entry() );
1678 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1680 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1682 SUIT_DataOwnerPtrList aList( true );
1683 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1684 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1685 aSelectionMgr->setSelected( aList );
1689 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1692 bool doShow = false;
1693 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1695 aDisplayer->SaveCursorViewPosition( theViewWindow );
1696 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1700 // Show the coordinates in the status bar
1701 SUIT_Desktop* aDesktop = getApp()->desktop();
1702 if ( aDesktop && aDesktop->statusBar() )
1704 gp_Pnt aWPnt( X, Y, Z );
1705 int aStudyId = application()->activeStudy()->id();
1706 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1707 double WX = aWPnt.X(), WY = aWPnt.Y();
1709 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1710 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1711 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1712 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1713 QString aMsg = tr( "COORDINATES_INFO" );
1714 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1715 aDesktop->statusBar()->showMessage( aMsg );
1721 * Returns stack of active operations;
1723 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1725 return myActiveOperationMap;
1729 * Returns the module active operation. If the active operation is show/hide,
1730 * the method returns the previous operation if it is.
1732 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1734 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1736 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1738 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1740 aVIt.previous(); // skip the top show/hide operation
1741 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1748 * \brief Virtual public slot
1750 * This method is called after the object inserted into data view to update their visibility state
1751 * This is default implementation
1753 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1755 if ( !isActiveModule() )
1758 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1760 // change visibility of object
1761 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1764 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1766 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1767 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1768 if ( visState == Qtx::UnpresentableState )
1771 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1772 treeModel->setVisibilityState( id, visState );
1774 bool vis = visState == Qtx::ShownState;
1775 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1778 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1780 update( UF_OCCViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1783 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1785 Handle(HYDROData_StricklerTable) aTable;
1787 if ( myLandCoverColoringMap.contains( theViewId ) ) {
1788 aTable = myLandCoverColoringMap.value( theViewId );
1794 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1795 const Handle(HYDROData_StricklerTable)& theTable )
1797 if ( !theTable.IsNull() ) {
1798 myLandCoverColoringMap.insert( theViewId, theTable );
1802 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
1804 myLandCoverColoringMap.remove( theViewId );
1807 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
1809 return myLandCoverColoringMap.contains( theViewId );
1812 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
1814 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
1818 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
1819 Handle(HYDROData_StricklerTable) aTable =
1820 Handle(HYDROData_StricklerTable)::DownCast( theObject );
1821 QList<int> aViewIds;
1822 QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
1823 while ( anIter.hasNext() ) {
1824 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
1825 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {