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 anIsLandCoverMap = 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( HYDROData_Entity::Geom_All ) )
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_MAP )
463 anIsLandCoverMap = 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_MAP:
521 theMenu->addAction( action( CreateLandCoverMapId ) );
522 theMenu->addAction( action( ImportLandCoverMapId ) );
524 case KIND_CALCULATION:
525 theMenu->addAction( action( CreateCalculationId ) );
527 case KIND_POLYLINEXY:
528 theMenu->addAction( action( ImportPolylineId ) );
529 theMenu->addAction( action( CreatePolylineId ) );
532 theMenu->addAction( action( CreatePolyline3DId ) );
535 theMenu->addAction( action( CreateProfileId ) );
536 theMenu->addAction( action( ImportProfilesId ) );
537 theMenu->addAction( action( AllGeoreferencementId ) );
539 case KIND_VISUAL_STATE:
540 theMenu->addAction( action( SaveVisualStateId ) );
543 theMenu->addSeparator();
547 if( anIsSelectedDataObjects )
549 if ( anIsMustObjectBeUpdated )
551 theMenu->addAction( action( UpdateObjectId ) );
552 theMenu->addSeparator();
556 theMenu->addAction( action( ForcedUpdateObjectId ) );
557 theMenu->addSeparator();
561 if( aSeq.Length() == 1 )
565 if( anIsImportedImage )
566 theMenu->addAction( action( EditImportedImageId ) );
567 else if( anIsImageHasRefs )
570 theMenu->addAction( action( EditFusedImageId ) );
571 else if( anIsCutImage )
572 theMenu->addAction( action( EditCutImageId ) );
573 else if( anIsSplittedImage )
574 theMenu->addAction( action( EditSplittedImageId ) );
577 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
578 theMenu->addAction( action( ExportImageId ) );
579 theMenu->addSeparator();
581 if( anIsImageHasRefs )
583 theMenu->addAction( action( RemoveImageRefsId ) );
584 theMenu->addSeparator();
587 theMenu->addAction( action( FuseImagesId ) );
588 theMenu->addAction( action( CutImagesId ) );
589 theMenu->addAction( action( SplitImageId ) );
590 theMenu->addSeparator();
591 theMenu->addAction( action( RecognizeContoursId ) );
592 theMenu->addSeparator();
594 else if( anIsBathymetry )
596 theMenu->addAction( action( EditImportedBathymetryId ) );
597 theMenu->addAction( action( BathymetryBoundsId ) );
598 theMenu->addSeparator();
600 else if( anIsPolyline )
602 theMenu->addAction( action( EditPolylineId ) );
603 theMenu->addSeparator();
604 theMenu->addAction( action( SplitPolylinesId ) );
605 theMenu->addAction( action( MergePolylinesId ) );
606 theMenu->addSeparator();
608 else if( anIsPolyline3D )
610 theMenu->addAction( action( EditPolyline3DId ) );
611 theMenu->addSeparator();
613 else if( anIsProfile )
615 theMenu->addAction( action( EditProfileId ) );
616 theMenu->addAction( action( SelectedGeoreferencementId ) );
617 theMenu->addSeparator();
619 else if( anIsCalculation )
621 theMenu->addAction( action( EditCalculationId ) );
622 theMenu->addAction( action( ExportCalculationId ) );
623 theMenu->addSeparator();
625 else if( anIsImmersibleZone )
627 theMenu->addAction( action( EditImmersibleZoneId ) );
628 theMenu->addSeparator();
630 else if( anIsStream )
632 theMenu->addAction( action( EditStreamId ) );
633 if ( action( RiverBottomContextId ) )
635 theMenu->addAction( action( RiverBottomContextId ) );
636 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
638 theMenu->addAction( action( ProfileInterpolateId ) );
639 theMenu->addSeparator();
641 else if( anIsChannel )
643 theMenu->addAction( action( EditChannelId ) );
644 theMenu->addSeparator();
648 theMenu->addAction( action( EditDigueId ) );
649 theMenu->addSeparator();
651 else if( anIsObstacle )
653 theMenu->addAction( action( TranslateObstacleId ) );
654 theMenu->addSeparator();
656 else if( anIsStricklerTable )
658 theMenu->addAction( action( EditStricklerTableId ) );
659 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
660 theMenu->addAction( action( DuplicateStricklerTableId ) );
661 theMenu->addSeparator();
663 Handle(HYDROData_StricklerTable) aTable =
664 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
665 QString aCurrentTable =
666 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
667 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
669 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
670 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
671 theMenu->addSeparator();
674 else if( anIsLandCoverMap )
676 theMenu->addAction( action( AddLandCoverId ) );
677 theMenu->addAction( action( RemoveLandCoverId ) );
678 theMenu->addSeparator();
679 theMenu->addAction( action( SplitLandCoverId ) );
680 theMenu->addAction( action( MergeLandCoverId ) );
681 theMenu->addAction( action( ChangeLandCoverTypeId ) );
682 theMenu->addSeparator();
684 theMenu->addAction( action( ExportToShapeFileID ) );
686 else if( anIsVisualState && anIsObjectBrowser )
688 theMenu->addAction( action( SaveVisualStateId ) );
689 theMenu->addAction( action( LoadVisualStateId ) );
690 theMenu->addSeparator();
693 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
695 theMenu->addAction( action( PolylineExtractionId ) );
696 theMenu->addSeparator();
699 // Add set color action for geometrical objects
700 if ( anIsObjectCanBeColored )
702 theMenu->addAction( action( SetColorId ) );
703 if ( anIsLandCoverMap )
704 theMenu->addAction( action( SetTransparencyId ) );
705 theMenu->addSeparator();
707 } else if ( anAllAreProfiles ) {
708 theMenu->addAction( action( SelectedGeoreferencementId ) );
709 theMenu->addSeparator();
712 bool anIsPoly = anIsPolyline || anIsPolyline3D;
713 if (anIsPoly && !anIsLandCoverMap)
714 theMenu->addAction( action( ExportToShapeFileID ) );
717 QAction* aCopyAction = action( CopyId );
718 if( aCopyAction && aCopyAction->isEnabled() ) {
719 theMenu->addAction( action( CopyId ) );
720 theMenu->addSeparator();
724 if( !anIsDummyObject3D )
725 theMenu->addAction( action( DeleteId ) );
727 theMenu->addSeparator();
729 if( anIsImage || anIsPolyline || anIsPolyline3D ||
730 anIsImmersibleZone || anIsZone || anIsRegion ||
731 anIsBathymetry || anIsObstacle || anIsStream ||
732 anIsChannel || anIsDigue || anIsDummyObject3D ||
733 anIsValidProfile || anIsGroup || anIsLandCoverMap )
735 if( anIsHiddenInSelection )
736 theMenu->addAction( action( ShowId ) );
737 theMenu->addAction( action( ShowOnlyId ) );
738 if( anIsVisibleInSelection )
739 theMenu->addAction( action( HideId ) );
740 theMenu->addSeparator();
746 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
747 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
748 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
749 theMenu->addAction( action( DeleteId ) );
751 theMenu->addSeparator();
752 theMenu->addAction( action( SetZLevelId ) );
753 theMenu->addSeparator();
755 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
756 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
757 theMenu->addSeparator();
761 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
763 theMenu->addAction( action( ShowAllId ) );
764 theMenu->addAction( action( HideAllId ) );
765 theMenu->addSeparator();
768 if ( anIsOCCView || anIsVTKView )
770 theMenu->addSeparator();
771 theMenu->addAction( action( CopyViewerPositionId ) );
775 theMenu->addAction( action( EditLocalCSId ) );
777 if( anIsObjectBrowser && anOwners.size()==1 )
779 if( aSeq.Size() > 0 )
781 Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
782 if( !anObject.IsNull() )
784 theMenu->addSeparator();
785 theMenu->addAction( action( SubmersibleId ) );
786 action( SubmersibleId )->setCheckable( true );
787 action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
793 void HYDROGUI_Module::createPreferences()
795 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
796 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
798 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
799 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
801 // Set property cursor type
802 QList<QVariant> aCursorTypeIndicesList;
803 QList<QVariant> aCursorTypeIconsList;
805 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
806 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
807 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
808 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
809 aCursorTypeIndicesList << i;
810 aCursorTypeIconsList << pixmap;
813 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
814 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
816 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
817 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
818 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
820 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
821 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
822 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
823 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
824 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
825 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
826 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
829 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
831 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
833 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
834 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
835 if ( resMgr && !aDoc.IsNull() )
836 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
839 LightApp_Module::preferencesChanged( theSection, thePref );
842 QCursor HYDROGUI_Module::getPrefEditCursor() const
844 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
845 if ( aCursorType >= Qt::BlankCursor)
847 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
851 void HYDROGUI_Module::update( const int flags )
853 if ( !isUpdateEnabled() )
856 QApplication::setOverrideCursor( Qt::WaitCursor );
858 // To prevent calling this method recursively
859 // from one of the methods called below
860 setUpdateEnabled( false );
862 // store selected objects
863 QStringList aSelectedEntries = storeSelection();
865 bool aDoFitAll = flags & UF_FitAll;
868 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
869 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
872 if( ( flags & UF_Viewer ) )
873 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
875 if( ( flags & UF_OCCViewer ) )
876 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
878 if( ( flags & UF_VTKViewer ) )
879 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
881 if( ( flags & UF_Model ) && getDataModel() && getApp() )
883 getDataModel()->update( getStudyId() );
885 // Temporary workaround to prevent breaking
886 // the selection in the object browser.
887 // Note: processEvents() should be called after updateGV(),
888 // otherwise the application crashes from time to time.
889 //RKV: qApp->processEvents();
890 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
891 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
892 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
893 if ( isResizeOnExpandItem && anObjectBrowser ) {
894 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
896 getApp()->updateObjectBrowser( true );
897 if ( isResizeOnExpandItem && anObjectBrowser ) {
898 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
902 // Object browser is currently updated by using UF_Model flag
903 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
904 getApp()->updateObjectBrowser( true );
906 if( ( flags & UF_Controls ) && getApp() )
907 getApp()->updateActions();
909 // restore selected objects
910 restoreSelection( aSelectedEntries );
912 setUpdateEnabled( true );
914 QApplication::restoreOverrideCursor();
917 void HYDROGUI_Module::updateCommandsStatus()
919 LightApp_Module::updateCommandsStatus();
921 updateUndoRedoControls();
923 action( CopyId )->setEnabled( getDataModel()->canCopy() );
924 action( PasteId )->setEnabled( getDataModel()->canPaste() );
927 void HYDROGUI_Module::selectionChanged()
929 LightApp_Module::selectionChanged();
930 updateCommandsStatus();
933 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
935 return (HYDROGUI_DataModel*)dataModel();
938 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
943 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
945 return myOCCDisplayer;
948 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
950 return myVTKDisplayer;
953 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
955 if( myViewManagerMap.contains( theId ) )
957 return myViewManagerMap[ theId ].first;
962 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
964 if( myViewManagerMap.contains( theId ) )
966 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
967 GraphicsView_ViewManager* aViewManager =
968 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
970 return aViewManager->getViewer();
975 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
977 if( myViewManagerMap.contains( theId ) )
979 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
980 OCCViewer_ViewManager* aViewManager =
981 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
983 return aViewManager->getOCCViewer();
988 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
990 if( myViewManagerMap.contains( theId ) )
992 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
993 SVTK_ViewManager* aViewManager =
994 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
996 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1001 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1003 ViewManagerMapIterator anIter( myViewManagerMap );
1004 while( anIter.hasNext() )
1006 int anId = anIter.next().key();
1007 const ViewManagerInfo& anInfo = anIter.value();
1008 if( anInfo.first == theViewManager )
1014 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1016 int anId = getViewManagerId( theViewManager );
1019 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1020 return anInfo.second;
1025 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1026 const ViewManagerRole theRole )
1028 int anId = getViewManagerId( theViewManager );
1031 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1032 anInfo.second = theRole;
1036 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1037 const Handle(HYDROData_Entity)& theObject ) const
1039 if( theObject.IsNull() )
1045 foreach( int aViewId, myObjectStateMap.keys() )
1047 if( isObjectVisible( aViewId, theObject ) )
1053 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1054 if( anIter1 != myObjectStateMap.end() )
1056 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1057 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1059 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1060 if( anIter2 != aEntry2ObjectStateMap.end() )
1062 const ObjectState& anObjectState = anIter2.value();
1063 return anObjectState.Visibility;
1069 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1070 const Handle(HYDROData_Entity)& theObject,
1071 const bool theState )
1073 if( !theObject.IsNull() )
1075 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1076 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1078 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1079 anObjectState.Visibility = theState;
1081 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1084 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1085 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1086 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1087 if ( visState != Qtx::UnpresentableState )
1088 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1091 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1092 setLandCoversScalarMapModeOff( theViewId );
1093 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1094 getOCCDisplayer()->SetToUpdateColorScale();
1099 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1100 const bool theState )
1102 if( !theObject.IsNull() )
1104 // Process OCC shapes
1105 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1106 while( aShapesMapIter != myShapesMap.end() )
1108 const ListOfShapes& aShapesList = aShapesMapIter.value();
1109 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1111 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1113 aShape->setIsToUpdate( theState );
1118 // Process VTK shapes
1119 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1120 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1122 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1123 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1125 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1127 aShape->setIsToUpdate( theState );
1135 /////////////////// OCC SHAPES PROCESSING
1136 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1137 ObjectKind theKind ) const
1139 QList<HYDROGUI_Shape*> aResult;
1141 if ( myShapesMap.contains( theViewId ) )
1143 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1144 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1146 if( aShape && aShape->getObject()->GetKind()==theKind )
1147 aResult.append( aShape );
1153 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1154 const Handle(HYDROData_Entity)& theObject ) const
1156 HYDROGUI_Shape* aResShape = NULL;
1157 if( theObject.IsNull() )
1160 if ( myShapesMap.contains( theViewId ) )
1162 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1163 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1165 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1176 void HYDROGUI_Module::setObjectShape( const int theViewId,
1177 const Handle(HYDROData_Entity)& theObject,
1178 HYDROGUI_Shape* theShape )
1180 if( theObject.IsNull() )
1183 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1184 aViewShapes.append( theShape );
1187 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1188 const Handle(HYDROData_Entity)& theObject )
1190 if ( !myShapesMap.contains( theViewId ) )
1193 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1194 Handle(HYDROData_Entity) anObject;
1195 for ( int i = 0; i < aViewShapes.length(); )
1197 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1198 anObject = aShape->getObject();
1199 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1202 aViewShapes.removeAt( i );
1210 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1212 if ( !myShapesMap.contains( theViewId ) )
1215 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1216 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1218 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1223 myShapesMap.remove( theViewId );
1225 /////////////////// END OF OCC SHAPES PROCESSING
1227 /////////////////// VTKPrs PROCESSING
1228 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1229 const Handle(HYDROData_Entity)& theObject ) const
1231 HYDROGUI_VTKPrs* aResShape = NULL;
1232 if( theObject.IsNull() )
1235 if ( myVTKPrsMap.contains( theViewId ) )
1237 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1238 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1240 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1251 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1252 const Handle(HYDROData_Entity)& theObject,
1253 HYDROGUI_VTKPrs* theShape )
1255 if( theObject.IsNull() )
1258 if( theShape && theShape->needScalarBar() )
1260 // Compute the new global Z range from the added presentation and the old global Z range.
1261 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1262 double* aRange = theShape->getInternalZRange();
1263 bool anIsUpdate = false;
1264 if ( aRange[0] < aGlobalRange[0] )
1266 aGlobalRange[0] = aRange[0];
1269 if ( aRange[1] > aGlobalRange[1] )
1271 aGlobalRange[1] = aRange[1];
1277 updateVTKZRange( theViewId, aGlobalRange );
1281 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1282 aViewShapes.append( theShape );
1285 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1286 const QString& theEntry )
1288 if ( !myVTKPrsMap.contains( theViewId ) )
1291 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1292 Handle(HYDROData_Entity) anObject;
1294 for ( int i = 0; i < aViewShapes.length(); )
1296 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1297 anObject = aShape->getObject();
1298 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1299 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1302 aViewShapes.removeAt( i );
1309 // Invalidate global Z range
1310 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1311 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1314 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1315 const Handle(HYDROData_Entity)& theObject )
1317 if ( !myVTKPrsMap.contains( theViewId ) )
1320 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1321 Handle(HYDROData_Entity) anObject;
1322 for ( int i = 0; i < aViewShapes.length(); )
1324 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1325 anObject = aShape->getObject();
1326 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1329 aViewShapes.removeAt( i );
1336 // Invalidate global Z range
1337 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1338 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1341 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1343 if ( !myVTKPrsMap.contains( theViewId ) )
1346 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1347 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1349 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1354 myVTKPrsMap.remove( theViewId );
1357 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1359 if ( myVTKPrsMap.contains( theViewId ) )
1361 // For the given viewer id update all VTK presentations ...
1362 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1363 HYDROGUI_VTKPrs* aShape;
1364 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1366 aShape = aViewShapes.at( i );
1367 if ( aShape && aShape->needScalarBar() )
1369 aShape->setZRange( theRange );
1373 // ... and update the global color legend scalar bar.
1374 getVTKDisplayer()->SetZRange( theViewId, theRange );
1376 /////////////////// END OF VTKPrs PROCESSING
1378 void HYDROGUI_Module::clearCache()
1380 myObjectStateMap.clear();
1383 CAM_DataModel* HYDROGUI_Module::createDataModel()
1385 return new HYDROGUI_DataModel( this );
1388 void HYDROGUI_Module::customEvent( QEvent* e )
1390 int aType = e->type();
1391 if ( aType == NewViewEvent )
1393 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1394 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1396 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1398 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1399 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1401 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1403 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1404 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1406 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1407 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1408 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1410 //ouv: temporarily commented
1411 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1414 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1415 update( UF_Viewer );
1417 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1423 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1425 QEvent::Type aType = theEvent->type();
1426 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1428 if( aType == QEvent::Show )
1430 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1431 e->setData( theObj );
1432 QApplication::postEvent( this, e );
1433 theObj->removeEventFilter( this );
1436 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1438 if( aType == QEvent::Leave )
1440 SUIT_Desktop* aDesktop = getApp()->desktop();
1441 if ( aDesktop && aDesktop->statusBar() ) {
1442 aDesktop->statusBar()->clearMessage();
1446 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1448 if( aType == QEvent::Leave )
1450 SUIT_Desktop* aDesktop = getApp()->desktop();
1451 if ( aDesktop && aDesktop->statusBar() ) {
1452 aDesktop->statusBar()->clearMessage();
1457 return LightApp_Module::eventFilter( theObj, theEvent );
1460 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1462 LightApp_Module::onViewManagerAdded( theViewManager );
1464 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1466 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1467 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1469 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1471 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1472 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1473 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1474 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1476 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1478 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1479 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1480 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1481 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1484 createSelector( theViewManager ); // replace the default selector
1486 ViewManagerInfo anInfo( theViewManager, VMR_General );
1487 myViewManagerMap.insert( ViewManagerId++, anInfo );
1490 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1492 LightApp_Module::onViewManagerRemoved( theViewManager );
1494 createSelector( theViewManager ); // replace the default selector
1496 int anId = getViewManagerId( theViewManager );
1499 OCCViewer_ViewManager* anOCCViewManager =
1500 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1501 if ( anOCCViewManager )
1503 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1504 if ( anOCCViewer ) {
1505 int aViewerId = (size_t)anOCCViewer;
1506 removeViewShapes( aViewerId );
1507 setLandCoversScalarMapModeOff( aViewerId );
1511 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1513 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1516 getVTKDisplayer()->EraseScalarBar( anId, true );
1517 removeViewShapes( (size_t)aVTKViewer );
1521 myViewManagerMap.remove( anId );
1525 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1527 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1529 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1531 aViewFrame->installEventFilter( this );
1533 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1535 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1536 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1539 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1541 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1543 aViewFrame->onTopView();
1545 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1547 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1549 aViewPort->installEventFilter( this );
1553 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1555 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1557 aViewFrame->installEventFilter( this );
1562 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1564 /* ouv: currently unused
1565 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1567 SUIT_ViewManager* aViewManager = 0;
1569 QObject* aParent = aViewPort;
1570 while( aParent = aParent->parent() )
1572 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1574 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1576 aViewManager = aViewer->getViewManager();
1585 double aMouseX = theEvent->scenePos().x();
1586 double aMouseY = theEvent->scenePos().y();
1588 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1589 if( aRole == VMR_General )
1591 int aXDeg = 0, aYDeg = 0;
1592 int aXMin = 0, aYMin = 0;
1593 double aXSec = 0, aYSec = 0;
1594 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1595 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1597 QString aDegSymbol( QChar( 0x00B0 ) );
1598 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1599 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1601 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1603 else if( aRole == VMR_TransformImage )
1604 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1609 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1610 const bool theIsInit,
1611 const bool theIsForced,
1612 const bool theDoFitAll )
1614 QList<int> aViewManagerIdList;
1616 // currently, all views are updated
1617 ViewManagerMapIterator anIter( myViewManagerMap );
1618 while( anIter.hasNext() )
1620 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1622 if ( theDisplayer->IsApplicable( aViewManager ) )
1624 int anId = anIter.key();
1625 aViewManagerIdList.append( anId );
1629 QListIterator<int> anIdIter( aViewManagerIdList );
1630 while( anIdIter.hasNext() )
1632 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1636 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1638 if( !theViewManager )
1641 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1642 if( !aSelectionMgr )
1645 QString aViewType = theViewManager->getType();
1646 if( aViewType != GraphicsView_Viewer::Type() &&
1647 aViewType != OCCViewer_Viewer::Type())
1650 QList<SUIT_Selector*> aSelectorList;
1651 aSelectionMgr->selectors( aViewType, aSelectorList );
1653 // disable all alien selectors
1654 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1655 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1657 SUIT_Selector* aSelector = *anIter;
1658 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1659 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1660 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1661 aSelector->setEnabled( false );
1664 if ( aViewType == GraphicsView_Viewer::Type() )
1666 GraphicsView_ViewManager* aViewManager =
1667 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1669 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1671 else if ( aViewType == OCCViewer_Viewer::Type() )
1673 OCCViewer_ViewManager* aViewManager =
1674 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1676 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1680 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1682 bool aPrevState = myIsUpdateEnabled;
1683 myIsUpdateEnabled = theState;
1687 bool HYDROGUI_Module::isUpdateEnabled() const
1689 return myIsUpdateEnabled;
1692 QStringList HYDROGUI_Module::storeSelection() const
1694 QStringList anEntryList;
1695 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1697 SUIT_DataOwnerPtrList aList( true );
1698 aSelectionMgr->selected( aList );
1700 SUIT_DataOwnerPtrList::iterator anIter;
1701 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1703 const LightApp_DataOwner* anOwner =
1704 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1706 anEntryList.append( anOwner->entry() );
1712 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1714 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1716 SUIT_DataOwnerPtrList aList( true );
1717 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1718 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1719 aSelectionMgr->setSelected( aList );
1723 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1726 bool doShow = false;
1727 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1729 aDisplayer->SaveCursorViewPosition( theViewWindow );
1730 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1734 // Show the coordinates in the status bar
1735 SUIT_Desktop* aDesktop = getApp()->desktop();
1736 if ( aDesktop && aDesktop->statusBar() )
1738 gp_Pnt aWPnt( X, Y, Z );
1739 int aStudyId = application()->activeStudy()->id();
1740 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1741 double WX = aWPnt.X(), WY = aWPnt.Y();
1743 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1744 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1745 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1746 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1747 QString aMsg = tr( "COORDINATES_INFO" );
1748 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1749 aDesktop->statusBar()->showMessage( aMsg );
1755 * Returns stack of active operations;
1757 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1759 return myActiveOperationMap;
1763 * Returns the module active operation. If the active operation is show/hide,
1764 * the method returns the previous operation if it is.
1766 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1768 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1770 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1772 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1774 aVIt.previous(); // skip the top show/hide operation
1775 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1782 * \brief Virtual public slot
1784 * This method is called after the object inserted into data view to update their visibility state
1785 * This is default implementation
1787 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1789 if ( !isActiveModule() )
1792 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1794 // change visibility of object
1795 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1798 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1800 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1801 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1802 if ( visState == Qtx::UnpresentableState )
1805 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1806 treeModel->setVisibilityState( id, visState );
1808 bool vis = visState == Qtx::ShownState;
1809 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1812 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1814 update( UF_OCCViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1817 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1819 Handle(HYDROData_StricklerTable) aTable;
1821 if ( myLandCoverColoringMap.contains( theViewId ) ) {
1822 aTable = myLandCoverColoringMap.value( theViewId );
1828 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1829 const Handle(HYDROData_StricklerTable)& theTable )
1831 if ( !theTable.IsNull() ) {
1832 myLandCoverColoringMap.insert( theViewId, theTable );
1836 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
1838 myLandCoverColoringMap.remove( theViewId );
1841 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
1843 return myLandCoverColoringMap.contains( theViewId );
1846 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
1848 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
1852 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
1853 Handle(HYDROData_StricklerTable) aTable =
1854 Handle(HYDROData_StricklerTable)::DownCast( theObject );
1855 QList<int> aViewIds;
1856 QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
1857 while ( anIter.hasNext() ) {
1858 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
1859 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {