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_Tool2.h"
34 #include "HYDROGUI_UpdateFlags.h"
35 #include "HYDROGUI_Shape.h"
36 #include "HYDROGUI_VTKPrs.h"
37 #include "HYDROGUI_VTKPrsDisplayer.h"
38 #include "HYDROGUI_AbstractDisplayer.h"
39 #include "HYDROGUI_PolylineOp.h"
40 #include "HYDROGUI_SetColorOp.h"
41 #include "HYDROGUI_ImportGeomObjectOp.h"
42 #include "HYDROGUI_ShowHideOp.h"
43 #include "HYDROGUI_Overview.h"
45 #include <HYDROData_Tool.h>
46 #include <HYDROData_Image.h>
47 #include <HYDROData_Stream.h>
48 #include <HYDROData_Profile.h>
49 #include <HYDROData_Lambert93.h>
50 #include <HYDROData_Polyline3D.h>
51 #include <HYDROData_StricklerTable.h>
52 #include <HYDROData_ArtificialObject.h>
53 #include <HYDROData_NaturalObject.h>
55 #include <HYDROData_OperationsFactory.h>
57 #include <CurveCreator_Utils.hxx>
59 #include <GraphicsView_ViewFrame.h>
60 #include <GraphicsView_ViewManager.h>
61 #include <GraphicsView_ViewPort.h>
62 #include <GraphicsView_Viewer.h>
64 #include <ImageComposer_CutOperator.h>
65 #include <ImageComposer_CropOperator.h>
66 #include <ImageComposer_FuseOperator.h>
68 #include <LightApp_Application.h>
69 #include <LightApp_DataOwner.h>
70 #include <LightApp_GVSelector.h>
71 #include <LightApp_SelectionMgr.h>
72 #include <LightApp_UpdateFlags.h>
74 #include <SalomeApp_Study.h>
76 #include <OCCViewer_ViewFrame.h>
77 #include <OCCViewer_ViewManager.h>
78 #include <OCCViewer_ViewModel.h>
80 #include <SALOME_Event.h>
82 #include <SUIT_DataBrowser.h>
83 #include <SUIT_DataObject.h>
84 #include <SUIT_ViewManager.h>
85 #include <SUIT_ResourceMgr.h>
86 #include <SUIT_Desktop.h>
87 #include <SUIT_Study.h>
88 #include <SUIT_Session.h>
90 #include <SVTK_ViewManager.h>
91 #include <SVTK_ViewModel.h>
92 #include <SVTK_ViewWindow.h>
93 #include <SVTK_Selector.h>
95 #include <OCCViewer_ViewPort3d.h>
97 #include <GEOMUtils.hxx>
98 #include <GeometryGUI.h>
100 #include <SALOMEDS_wrap.hxx>
103 #include <QApplication>
104 #include <QGraphicsSceneMouseEvent>
106 #include <QMouseEvent>
107 #include <QStatusBar>
110 static int ViewManagerId = 0;
112 extern "C" HYDRO_EXPORT CAM_Module* createModule()
114 return new HYDROGUI_Module();
117 extern "C" HYDRO_EXPORT char* getModuleVersion()
119 return (char*)HYDRO_VERSION;
122 HYDROGUI_Module::HYDROGUI_Module()
123 : LightApp_Module( "HYDRO" ),
126 myIsUpdateEnabled( true ),
131 HYDROGUI_Module::~HYDROGUI_Module()
135 int HYDROGUI_Module::getStudyId() const
137 LightApp_Application* anApp = getApp();
138 return anApp ? anApp->activeStudy()->id() : 0;
141 void HYDROGUI_Module::initialize( CAM_Application* theApp )
143 LightApp_Module::initialize( theApp );
146 createUndoRedoActions();
151 setMenuShown( false );
152 setToolShown( false );
154 myDisplayer = new HYDROGUI_Displayer( this );
155 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
156 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
159 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
161 bool aRes = LightApp_Module::activateModule( theStudy );
163 LightApp_Application* anApp = getApp();
164 SUIT_Desktop* aDesktop = anApp->desktop();
166 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
168 setMenuShown( true );
169 setToolShown( true );
171 #ifndef DISABLE_PYCONSOLE
172 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
173 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
176 // Remove defunct view managers from the map.
177 // It's essential to do this before "update( UF_All )" call!
178 QList<int> anObsoleteIds;
179 ViewManagerList anAllViewManagers = anApp->viewManagers();
180 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
181 ViewManagerMapIterator anIter( myViewManagerMap );
182 while( anIter.hasNext() ) {
183 int anId = anIter.next().key();
184 const ViewManagerInfo& anInfo = anIter.value();
186 aHydroViewManagers << anInfo.first;
188 if ( !anAllViewManagers.contains( anInfo.first ) ) {
189 anObsoleteIds << anId;
192 foreach ( const int anId, anObsoleteIds ) {
193 myViewManagerMap.remove( anId );
194 myObjectStateMap.remove( anId );
195 myShapesMap.remove( anId );
196 myVTKPrsMap.remove( anId );
198 // Replace the default selector for all view managers.
199 // Add view managers created outside of HYDRO module to the map.
200 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
201 createSelector( aViewManager ); // replace the default selector
202 if ( !aHydroViewManagers.contains( aViewManager ) ) {
203 ViewManagerInfo anInfo( aViewManager, VMR_General );
204 myViewManagerMap.insert( ViewManagerId++, anInfo );
210 updateCommandsStatus();
212 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
214 ViewManagerList anOCCViewManagers;
215 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
217 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers )
219 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
220 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
221 connect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
222 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
224 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() )
226 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
227 if ( aViewFrame && aViewFrame->getViewPort() )
229 aViewFrame->getViewPort()->installEventFilter( this );
235 SalomeApp_Study* aStudy =
236 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
238 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
239 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
240 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
241 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
242 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
243 if( !GEOM_var->_is_nil() ) {
244 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
249 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
250 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
251 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
256 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
259 ViewManagerMapIterator anIter( myViewManagerMap );
260 while( anIter.hasNext() )
261 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
262 getApp()->removeViewManager( aViewManager );
263 myViewManagerMap.clear();
266 ViewManagerList anOCCViewManagers;
267 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
268 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
269 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
270 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
274 myObjectStateMap.clear();
279 // clear the status bar
280 SUIT_Desktop* aDesktop = getApp()->desktop();
281 if ( aDesktop && aDesktop->statusBar() ) {
282 aDesktop->statusBar()->clearMessage();
285 // clear the data model's list of copying objects
286 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
288 setMenuShown( false );
289 setToolShown( false );
291 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
293 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
295 myActiveOperationMap.clear();
296 return LightApp_Module::deactivateModule( theStudy );
299 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
301 static bool inWindows = false;
306 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
307 #ifndef DISABLE_PYCONSOLE
308 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
310 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
311 theMap.insert( OverviewWindow, Qt::LeftDockWidgetArea );
314 LightApp_Application* app = getApp();
315 if( app && app->getWindow( OverviewWindow )==0 )
317 const_cast<HYDROGUI_Module*>( this )->myOverview =
318 new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() );
319 app->insertDockWindow( OverviewWindow, myOverview );
320 app->placeDockWindow( OverviewWindow, Qt::LeftDockWidgetArea );
325 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
327 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
330 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
334 HYDROGUI_DataModel* aModel = getDataModel();
336 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
337 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
338 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
339 bool anIsVTKView = theClient == SVTK_Viewer::Type();
340 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
343 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
345 bool anIsSelectedDataObjects = false;
346 bool anIsVisibleInSelection = false;
347 bool anIsHiddenInSelection = false;
349 bool anIsImage = false;
350 bool anIsImportedImage = false;
351 bool anIsImageHasRefs = false;
352 bool anIsFusedImage = false;
353 bool anIsCutImage = false;
354 bool anIsSplitImage = false;
355 bool anIsMustObjectBeUpdated = false;
356 bool anIsPolyline = false;
357 bool anIsPolyline3D = false;
358 bool anIsProfile = false;
359 bool anIsValidProfile = false;
360 bool anAllAreProfiles = false;
361 bool anIsBathymetry = false;
362 bool anIsCalculation = false;
363 bool anIsImmersibleZone = false;
364 bool anIsVisualState = false;
365 bool anIsRegion = false;
366 bool anIsZone = false;
367 bool anIsObstacle = false;
368 bool anIsStricklerTable = false;
369 bool anIsLandCoverMap = false;
370 bool anIsStream = false;
371 bool anIsChannel = false;
372 bool anIsDigue = false;
373 bool anIsDummyObject3D = false;
374 bool anIsGroup = false;
375 bool anIsObjectCanBeColored = false;
377 bool isStreamHasBottom = false;
379 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
380 SUIT_DataOwnerPtrList anOwners;
381 aSelectionMgr->selected( anOwners );
382 if( anIsObjectBrowser && anOwners.size()==1 )
384 QString anEntry = anOwners[0]->keyString();
385 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
387 isRoot = aStudy->isComponent( anEntry );
390 // Check the selected GEOM objects (take into account the Object Browser only)
391 if ( anIsObjectBrowser ) {
392 QList<GEOM::shape_type> anObstacleTypes =
393 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
394 QList<GEOM::shape_type> aPolylineTypes =
395 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
397 bool isCanBeImportedAsObstacle =
398 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
399 bool isCanBeImportedAsPolyline =
400 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
402 // Add import as obstacle action
403 if ( isCanBeImportedAsObstacle ) {
404 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
406 // Add import as polyline action
407 if ( isCanBeImportedAsPolyline ) {
408 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
411 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
412 theMenu->addSeparator();
416 // check the selected data model objects
417 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
418 int aNbOfSelectedProfiles = 0;
419 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
421 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
422 if( !anObject.IsNull() )
424 anIsSelectedDataObjects = true;
426 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
427 anIsVisibleInSelection |= aVisibility;
428 anIsHiddenInSelection |= !aVisibility;
430 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
432 anIsMustObjectBeUpdated = true;
435 ObjectKind anObjectKind = anObject->GetKind();
436 if( anObjectKind == KIND_IMAGE )
439 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
440 if( !anImage.IsNull() )
442 anIsImportedImage = anImage->HasLocalPoints();
443 anIsImageHasRefs = anImage->HasReferences();
444 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
446 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
448 QString anOperatorName = anOperator->name();
449 if( anOperatorName == ImageComposer_FuseOperator::Type() )
450 anIsFusedImage = true;
451 else if( anOperatorName == ImageComposer_CutOperator::Type() )
453 else if( anOperatorName == ImageComposer_CropOperator::Type() )
454 anIsSplitImage = true;
459 else if( anObjectKind == KIND_POLYLINEXY )
461 else if( anObjectKind == KIND_POLYLINE )
462 anIsPolyline3D = true;
463 else if( anObjectKind == KIND_PROFILE )
466 aNbOfSelectedProfiles++;
468 Handle(HYDROData_Profile) aProfile =
469 Handle(HYDROData_Profile)::DownCast( anObject );
470 if( !aProfile.IsNull() && aProfile->IsValid() ) {
471 anIsValidProfile = true;
474 else if( anObjectKind == KIND_CALCULATION )
475 anIsCalculation = true;
476 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
477 anIsImmersibleZone = true;
478 else if( anObjectKind == KIND_VISUAL_STATE )
479 anIsVisualState = true;
480 else if( anObjectKind == KIND_REGION )
482 else if( anObjectKind == KIND_ZONE )
484 else if( anObjectKind == KIND_BATHYMETRY )
485 anIsBathymetry = true;
486 else if( anObjectKind == KIND_OBSTACLE )
488 else if( anObjectKind == KIND_STRICKLER_TABLE )
489 anIsStricklerTable = true;
490 else if( anObjectKind == KIND_LAND_COVER_MAP )
491 anIsLandCoverMap = true;
492 else if( anObjectKind == KIND_STREAM )
495 Handle(HYDROData_Stream) aStream =
496 Handle(HYDROData_Stream)::DownCast( anObject );
497 if ( !aStream.IsNull() )
498 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
500 else if( anObjectKind == KIND_CHANNEL )
502 else if( anObjectKind == KIND_DIGUE )
504 else if( anObjectKind == KIND_DUMMY_3D )
505 anIsDummyObject3D = true;
506 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLIT_GROUP )
510 if ( !anIsObjectCanBeColored )
511 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
514 // Check if all selected objects are profiles
515 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
516 ( aNbOfSelectedProfiles == aSeq.Length() );
518 // check the selected partitions
519 if( !anIsSelectedDataObjects && anIsObjectBrowser )
521 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
522 if( aSelectedPartition != KIND_UNKNOWN )
524 switch( aSelectedPartition )
527 theMenu->addAction( action( ImportImageId ) );
529 case KIND_BATHYMETRY:
530 theMenu->addAction( action( ImportBathymetryId ) );
532 case KIND_ARTIFICIAL_OBJECT:
533 theMenu->addAction( action( CreateChannelId ) );
534 theMenu->addAction( action( CreateDigueId ) );
536 case KIND_NATURAL_OBJECT:
537 theMenu->addAction( action( CreateImmersibleZoneId ) );
538 theMenu->addAction( action( CreateStreamId ) );
541 theMenu->addAction( action( ImportObstacleFromFileId ) );
542 theMenu->addAction( action( CreateBoxId ) );
543 theMenu->addAction( action( CreateCylinderId ) );
545 case KIND_STRICKLER_TABLE:
546 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
548 case KIND_LAND_COVER_MAP:
549 theMenu->addAction( action( CreateLandCoverMapId ) );
550 theMenu->addAction( action( ImportLandCoverMapId ) );
552 case KIND_CALCULATION:
553 theMenu->addAction( action( CreateCalculationId ) );
555 case KIND_POLYLINEXY:
556 theMenu->addAction( action( ImportPolylineId ) );
557 theMenu->addAction( action( CreatePolylineId ) );
560 theMenu->addAction( action( CreatePolyline3DId ) );
563 theMenu->addAction( action( CreateProfileId ) );
564 theMenu->addAction( action( ImportProfilesId ) );
565 theMenu->addAction( action( AllGeoreferencementId ) );
567 case KIND_VISUAL_STATE:
568 theMenu->addAction( action( SaveVisualStateId ) );
571 theMenu->addSeparator();
575 if( anIsSelectedDataObjects )
577 if ( anIsMustObjectBeUpdated )
579 theMenu->addAction( action( UpdateObjectId ) );
580 theMenu->addSeparator();
584 theMenu->addAction( action( ForcedUpdateObjectId ) );
585 theMenu->addSeparator();
589 if( aSeq.Length() == 1 )
593 if( anIsImportedImage )
594 theMenu->addAction( action( EditImportedImageId ) );
595 else if( anIsImageHasRefs )
598 theMenu->addAction( action( EditFusedImageId ) );
599 else if( anIsCutImage )
600 theMenu->addAction( action( EditCutImageId ) );
601 else if( anIsSplitImage )
602 theMenu->addAction( action( EditSplitImageId ) );
605 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
606 theMenu->addAction( action( ExportImageId ) );
607 theMenu->addSeparator();
609 if( anIsImageHasRefs )
611 theMenu->addAction( action( RemoveImageRefsId ) );
612 theMenu->addSeparator();
615 theMenu->addAction( action( FuseImagesId ) );
616 theMenu->addAction( action( CutImagesId ) );
617 theMenu->addAction( action( SplitImageId ) );
618 theMenu->addSeparator();
619 theMenu->addAction( action( RecognizeContoursId ) );
620 theMenu->addSeparator();
622 else if( anIsBathymetry )
624 theMenu->addAction( action( EditImportedBathymetryId ) );
625 theMenu->addAction( action( BathymetryBoundsId ) );
626 theMenu->addSeparator();
628 else if( anIsPolyline )
630 theMenu->addAction( action( EditPolylineId ) );
631 theMenu->addSeparator();
632 theMenu->addAction( action( SplitPolylinesId ) );
633 theMenu->addAction( action( MergePolylinesId ) );
634 theMenu->addSeparator();
636 else if( anIsPolyline3D )
638 theMenu->addAction( action( EditPolyline3DId ) );
639 theMenu->addSeparator();
641 else if( anIsProfile )
643 theMenu->addAction( action( EditProfileId ) );
644 theMenu->addAction( action( SelectedGeoreferencementId ) );
645 theMenu->addSeparator();
647 else if( anIsCalculation )
649 theMenu->addAction( action( EditCalculationId ) );
650 theMenu->addAction( action( ExportCalculationId ) );
651 theMenu->addSeparator();
653 else if( anIsImmersibleZone )
655 theMenu->addAction( action( EditImmersibleZoneId ) );
656 theMenu->addSeparator();
658 else if( anIsStream )
660 theMenu->addAction( action( EditStreamId ) );
661 if ( action( RiverBottomContextId ) )
663 theMenu->addAction( action( RiverBottomContextId ) );
664 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
666 theMenu->addAction( action( ProfileInterpolateId ) );
667 theMenu->addSeparator();
669 else if( anIsChannel )
671 theMenu->addAction( action( EditChannelId ) );
672 theMenu->addSeparator();
676 theMenu->addAction( action( EditDigueId ) );
677 theMenu->addSeparator();
679 else if( anIsObstacle )
681 theMenu->addAction( action( TranslateObstacleId ) );
682 theMenu->addSeparator();
684 else if( anIsStricklerTable )
686 theMenu->addAction( action( EditStricklerTableId ) );
687 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
688 theMenu->addAction( action( DuplicateStricklerTableId ) );
689 theMenu->addSeparator();
691 Handle(HYDROData_StricklerTable) aTable =
692 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
693 QString aCurrentTable =
694 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
695 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
697 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
698 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
699 theMenu->addSeparator();
702 else if( anIsLandCoverMap )
704 theMenu->addAction( action( AddLandCoverId ) );
705 theMenu->addAction( action( RemoveLandCoverId ) );
706 theMenu->addSeparator();
707 theMenu->addAction( action( SplitLandCoverId ) );
708 theMenu->addAction( action( MergeLandCoverId ) );
709 theMenu->addAction( action( ChangeLandCoverTypeId ) );
710 theMenu->addSeparator();
712 theMenu->addAction( action( ExportToShapeFileID ) );
713 theMenu->addSeparator();
715 else if( anIsVisualState && anIsObjectBrowser )
717 theMenu->addAction( action( SaveVisualStateId ) );
718 theMenu->addAction( action( LoadVisualStateId ) );
719 theMenu->addSeparator();
722 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
724 theMenu->addAction( action( PolylineExtractionId ) );
725 theMenu->addSeparator();
728 // Add set color action for geometrical objects
729 if ( anIsObjectCanBeColored )
731 theMenu->addAction( action( SetColorId ) );
732 theMenu->addSeparator();
735 // Add transparency action for land cover map objects
736 if ( anIsLandCoverMap )
738 theMenu->addAction( action( SetTransparencyId ) );
739 theMenu->addSeparator();
741 } else if ( anAllAreProfiles ) {
742 theMenu->addAction( action( SelectedGeoreferencementId ) );
743 theMenu->addSeparator();
746 bool isPoly = anIsPolyline || anIsPolyline3D;
747 if (isPoly && !anIsLandCoverMap)
748 theMenu->addAction( action( ExportToShapeFileID ) );
751 QAction* aCopyAction = action( CopyId );
752 if( aCopyAction && aCopyAction->isEnabled() ) {
753 theMenu->addAction( action( CopyId ) );
754 theMenu->addSeparator();
758 if( !anIsDummyObject3D )
759 theMenu->addAction( action( DeleteId ) );
761 theMenu->addSeparator();
763 if( anIsImage || anIsPolyline || anIsPolyline3D ||
764 anIsImmersibleZone || anIsZone || anIsRegion ||
765 anIsBathymetry || anIsObstacle || anIsStream ||
766 anIsChannel || anIsDigue || anIsDummyObject3D ||
767 anIsValidProfile || anIsGroup || anIsLandCoverMap )
769 if( anIsHiddenInSelection )
770 theMenu->addAction( action( ShowId ) );
771 theMenu->addAction( action( ShowOnlyId ) );
772 if( anIsVisibleInSelection )
773 theMenu->addAction( action( HideId ) );
774 theMenu->addSeparator();
780 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
781 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
782 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
783 theMenu->addAction( action( DeleteId ) );
785 theMenu->addSeparator();
786 theMenu->addAction( action( SetZLevelId ) );
787 theMenu->addSeparator();
789 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
790 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
791 theMenu->addSeparator();
795 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
797 theMenu->addAction( action( ShowAllId ) );
798 theMenu->addAction( action( HideAllId ) );
799 theMenu->addSeparator();
802 if ( anIsOCCView || anIsVTKView )
804 theMenu->addSeparator();
805 theMenu->addAction( action( CopyViewerPositionId ) );
809 theMenu->addAction( action( EditLocalCSId ) );
811 if( anIsObjectBrowser && anOwners.size()==1 )
813 if( aSeq.Size() > 0 )
815 Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
816 Handle(HYDROData_Object) anObject;
817 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
818 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
820 if (!anAObject.IsNull())
821 anObject = anAObject;
822 if (!aNObject.IsNull())
825 if( !anObject.IsNull() )
827 theMenu->addSeparator();
828 bool IsSubmersible = anObject->IsSubmersible();
831 theMenu->addAction( action( SubmersibleId ) );
832 action( SubmersibleId )->setCheckable(true);
833 action( SubmersibleId )->setChecked(true);
837 theMenu->addAction( action( UnSubmersibleId ) );
838 action( UnSubmersibleId )->setCheckable(true);
839 action( UnSubmersibleId )->setChecked(true);
845 theMenu->addSeparator();
846 QAction* a = action( ShowHideArrows );
847 a->setText( arrowsVisible() ? tr( "HIDE_ARROWS" ) : tr( "SHOW_ARROWS" ) );
848 theMenu->addAction( a );
851 void HYDROGUI_Module::createPreferences()
853 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
854 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
856 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
857 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
859 // Set property cursor type
860 QList<QVariant> aCursorTypeIndicesList;
861 QList<QVariant> aCursorTypeIconsList;
863 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
864 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
865 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
866 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
867 aCursorTypeIndicesList << i;
868 aCursorTypeIconsList << pixmap;
871 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
872 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
874 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
875 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
876 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
878 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
879 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
880 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
881 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
882 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
883 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
884 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
886 int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
887 int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
888 LightApp_Preferences::Selector, "polyline", "arrow_type" );
890 QList<QVariant> arrow_types;
891 arrow_types.append( tr( "No" ) );
892 arrow_types.append( tr( "Triangle" ) );
893 arrow_types.append( tr( "Cone" ) );
894 setPreferenceProperty( polylineArrow, "strings", arrow_types );
896 QList<QVariant> indices;
900 setPreferenceProperty( polylineArrow, "indexes", indices );
901 setPreferenceProperty( polylineArrow, "ids", indices );
903 int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
904 LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
907 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
909 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
910 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
913 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
914 if ( resMgr && !aDoc.IsNull() )
915 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
917 else if( theSection == "polyline" )
923 resMgr->value( "polyline", "arrow_type", aType );
924 resMgr->value( "polyline", "arrow_size", aSize );
927 ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
928 for( ; it!=last; it++ )
930 int aViewerId = it.key();
931 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
933 getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
937 LightApp_Module::preferencesChanged( theSection, thePref );
940 QCursor HYDROGUI_Module::getPrefEditCursor() const
942 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
943 if ( aCursorType >= Qt::BlankCursor)
945 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
949 void HYDROGUI_Module::update( const int flags )
951 if ( !isUpdateEnabled() )
954 QApplication::setOverrideCursor( Qt::WaitCursor );
956 // To prevent calling this method recursively
957 // from one of the methods called below
958 setUpdateEnabled( false );
960 // store selected objects
961 QStringList aSelectedEntries = storeSelection();
963 bool aDoFitAll = flags & UF_FitAll;
966 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
967 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
970 if( ( flags & UF_Viewer ) )
971 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
973 if( ( flags & UF_OCCViewer ) )
974 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
976 if( ( flags & UF_VTKViewer ) )
977 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
979 if( ( flags & UF_Model ) && getDataModel() && getApp() )
981 getDataModel()->update( getStudyId() );
983 // Temporary workaround to prevent breaking
984 // the selection in the object browser.
985 // Note: processEvents() should be called after updateGV(),
986 // otherwise the application crashes from time to time.
987 //RKV: qApp->processEvents();
988 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
989 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
990 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
991 if ( isResizeOnExpandItem && anObjectBrowser ) {
992 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
994 getApp()->updateObjectBrowser( true );
995 if ( isResizeOnExpandItem && anObjectBrowser ) {
996 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
1000 // Object browser is currently updated by using UF_Model flag
1001 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
1002 getApp()->updateObjectBrowser( true );
1004 if( ( flags & UF_Controls ) && getApp() )
1005 getApp()->updateActions();
1007 // restore selected objects
1008 restoreSelection( aSelectedEntries );
1010 setUpdateEnabled( true );
1012 QApplication::restoreOverrideCursor();
1015 void HYDROGUI_Module::updateCommandsStatus()
1017 LightApp_Module::updateCommandsStatus();
1019 updateUndoRedoControls();
1021 action( CopyId )->setEnabled( getDataModel()->canCopy() );
1022 action( PasteId )->setEnabled( getDataModel()->canPaste() );
1025 void HYDROGUI_Module::selectionChanged()
1027 LightApp_Module::selectionChanged();
1028 updateCommandsStatus();
1031 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1033 return (HYDROGUI_DataModel*)dataModel();
1036 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1041 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1043 return myOCCDisplayer;
1046 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1048 return myVTKDisplayer;
1051 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
1053 if( myViewManagerMap.contains( theId ) )
1055 return myViewManagerMap[ theId ].first;
1060 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
1062 if( myViewManagerMap.contains( theId ) )
1064 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1065 GraphicsView_ViewManager* aViewManager =
1066 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1068 return aViewManager->getViewer();
1073 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
1075 if( myViewManagerMap.contains( theId ) )
1077 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1078 OCCViewer_ViewManager* aViewManager =
1079 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1081 return aViewManager->getOCCViewer();
1086 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
1088 if( myViewManagerMap.contains( theId ) )
1090 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1091 SVTK_ViewManager* aViewManager =
1092 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1094 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1099 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1101 ViewManagerMapIterator anIter( myViewManagerMap );
1102 while( anIter.hasNext() )
1104 int anId = anIter.next().key();
1105 const ViewManagerInfo& anInfo = anIter.value();
1106 if( anInfo.first == theViewManager )
1112 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1114 int anId = getViewManagerId( theViewManager );
1117 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1118 return anInfo.second;
1123 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1124 const ViewManagerRole theRole )
1126 int anId = getViewManagerId( theViewManager );
1129 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1130 anInfo.second = theRole;
1134 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1135 const Handle(HYDROData_Entity)& theObject ) const
1137 if( theObject.IsNull() )
1143 foreach( int aViewId, myObjectStateMap.keys() )
1145 if( isObjectVisible( aViewId, theObject ) )
1151 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1152 if( anIter1 != myObjectStateMap.end() )
1154 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1155 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1157 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1158 if( anIter2 != aEntry2ObjectStateMap.end() )
1160 const ObjectState& anObjectState = anIter2.value();
1161 return anObjectState.Visibility;
1167 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1168 const Handle(HYDROData_Entity)& theObject,
1169 const bool theState )
1171 if( !theObject.IsNull() )
1173 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1174 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1176 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1177 anObjectState.Visibility = theState;
1179 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1182 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1185 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1186 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1187 if ( visState != Qtx::UnpresentableState )
1188 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1192 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1193 setLandCoversScalarMapModeOff( theViewId );
1194 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1195 getOCCDisplayer()->SetToUpdateColorScale();
1200 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1201 const bool theState )
1203 if( !theObject.IsNull() )
1205 // Process OCC shapes
1206 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1207 while( aShapesMapIter != myShapesMap.end() )
1209 const ListOfShapes& aShapesList = aShapesMapIter.value();
1210 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1212 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1214 aShape->setIsToUpdate( theState );
1219 // Process VTK shapes
1220 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1221 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1223 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1224 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1226 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1228 aShape->setIsToUpdate( theState );
1236 /////////////////// OCC SHAPES PROCESSING
1237 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1238 ObjectKind theKind ) const
1240 QList<HYDROGUI_Shape*> aResult;
1242 if ( myShapesMap.contains( theViewId ) )
1244 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1245 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1247 if( aShape && aShape->getObject()->GetKind()==theKind )
1248 aResult.append( aShape );
1254 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1255 const Handle(HYDROData_Entity)& theObject ) const
1257 HYDROGUI_Shape* aResShape = NULL;
1258 if( theObject.IsNull() )
1261 if ( myShapesMap.contains( theViewId ) )
1263 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1264 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1266 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1277 void HYDROGUI_Module::setObjectShape( const int theViewId,
1278 const Handle(HYDROData_Entity)& theObject,
1279 HYDROGUI_Shape* theShape )
1281 if( theObject.IsNull() )
1284 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1285 aViewShapes.append( theShape );
1288 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1289 const Handle(HYDROData_Entity)& theObject )
1291 if ( !myShapesMap.contains( theViewId ) )
1294 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1295 Handle(HYDROData_Entity) anObject;
1296 for ( int i = 0; i < aViewShapes.length(); )
1298 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1299 anObject = aShape->getObject();
1300 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1303 aViewShapes.removeAt( i );
1311 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1313 if ( !myShapesMap.contains( theViewId ) )
1316 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1317 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1319 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1324 myShapesMap.remove( theViewId );
1326 /////////////////// END OF OCC SHAPES PROCESSING
1328 /////////////////// VTKPrs PROCESSING
1329 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1330 const Handle(HYDROData_Entity)& theObject ) const
1332 HYDROGUI_VTKPrs* aResShape = NULL;
1333 if( theObject.IsNull() )
1336 if ( myVTKPrsMap.contains( theViewId ) )
1338 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1339 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1341 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1352 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1353 const Handle(HYDROData_Entity)& theObject,
1354 HYDROGUI_VTKPrs* theShape )
1356 if( theObject.IsNull() )
1359 if( theShape && theShape->needScalarBar() )
1361 // Compute the new global Z range from the added presentation and the old global Z range.
1362 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1363 double* aRange = theShape->getInternalZRange();
1364 bool anIsUpdate = false;
1365 if ( aRange[0] < aGlobalRange[0] )
1367 aGlobalRange[0] = aRange[0];
1370 if ( aRange[1] > aGlobalRange[1] )
1372 aGlobalRange[1] = aRange[1];
1378 updateVTKZRange( theViewId, aGlobalRange );
1382 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1383 aViewShapes.append( theShape );
1386 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1387 const QString& theEntry )
1389 if ( !myVTKPrsMap.contains( theViewId ) )
1392 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1393 Handle(HYDROData_Entity) anObject;
1395 for ( int i = 0; i < aViewShapes.length(); )
1397 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1398 anObject = aShape->getObject();
1399 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1400 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1403 aViewShapes.removeAt( i );
1410 // Invalidate global Z range
1411 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1412 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1415 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1416 const Handle(HYDROData_Entity)& theObject )
1418 if ( !myVTKPrsMap.contains( theViewId ) )
1421 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1422 Handle(HYDROData_Entity) anObject;
1423 for ( int i = 0; i < aViewShapes.length(); )
1425 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1426 anObject = aShape->getObject();
1427 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1430 aViewShapes.removeAt( i );
1437 // Invalidate global Z range
1438 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1439 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1442 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1444 if ( !myVTKPrsMap.contains( theViewId ) )
1447 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1448 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1450 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1455 myVTKPrsMap.remove( theViewId );
1458 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1460 if ( myVTKPrsMap.contains( theViewId ) )
1462 // For the given viewer id update all VTK presentations ...
1463 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1464 HYDROGUI_VTKPrs* aShape;
1465 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1467 aShape = aViewShapes.at( i );
1468 if ( aShape && aShape->needScalarBar() )
1470 aShape->setZRange( theRange );
1474 // ... and update the global color legend scalar bar.
1475 getVTKDisplayer()->SetZRange( theViewId, theRange );
1477 /////////////////// END OF VTKPrs PROCESSING
1479 void HYDROGUI_Module::clearCache()
1481 myObjectStateMap.clear();
1484 CAM_DataModel* HYDROGUI_Module::createDataModel()
1486 return new HYDROGUI_DataModel( this );
1489 void HYDROGUI_Module::customEvent( QEvent* e )
1491 int aType = e->type();
1492 if ( aType == NewViewEvent )
1494 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1495 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1497 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1499 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1500 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1502 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1504 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1505 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1507 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1508 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1509 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1511 //ouv: temporarily commented
1512 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1515 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1516 update( UF_Viewer );
1518 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1524 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1526 QEvent::Type aType = theEvent->type();
1527 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1529 if( aType == QEvent::Show )
1531 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1532 e->setData( theObj );
1533 QApplication::postEvent( this, e );
1534 theObj->removeEventFilter( this );
1537 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1539 if( aType == QEvent::Leave )
1541 SUIT_Desktop* aDesktop = getApp()->desktop();
1542 if ( aDesktop && aDesktop->statusBar() ) {
1543 aDesktop->statusBar()->clearMessage();
1547 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1549 if( aType == QEvent::Leave )
1551 SUIT_Desktop* aDesktop = getApp()->desktop();
1552 if ( aDesktop && aDesktop->statusBar() ) {
1553 aDesktop->statusBar()->clearMessage();
1558 return LightApp_Module::eventFilter( theObj, theEvent );
1561 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1563 LightApp_Module::onViewManagerAdded( theViewManager );
1565 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1567 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1568 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1570 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1572 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1573 mgr->setChainedOperations( true );//TODO: via preferences
1575 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1576 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1577 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1578 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1579 connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
1580 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1582 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1584 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1585 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1586 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1587 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1590 createSelector( theViewManager ); // replace the default selector
1592 ViewManagerInfo anInfo( theViewManager, VMR_General );
1593 myViewManagerMap.insert( ViewManagerId++, anInfo );
1596 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1598 LightApp_Module::onViewManagerRemoved( theViewManager );
1600 createSelector( theViewManager ); // replace the default selector
1602 int anId = getViewManagerId( theViewManager );
1605 OCCViewer_ViewManager* anOCCViewManager =
1606 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1607 if ( anOCCViewManager )
1609 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1610 if ( anOCCViewer ) {
1611 int aViewerId = (size_t)anOCCViewer;
1612 removeViewShapes( aViewerId );
1613 setLandCoversScalarMapModeOff( aViewerId );
1617 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1619 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1622 getVTKDisplayer()->EraseScalarBar( anId, true );
1623 removeViewShapes( (size_t)aVTKViewer );
1627 myViewManagerMap.remove( anId );
1631 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1633 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1635 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1637 aViewFrame->installEventFilter( this );
1639 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1640 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1642 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1643 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1646 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1648 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1650 aViewFrame->onTopView();
1652 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1654 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1656 aViewPort->installEventFilter( this );
1660 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1662 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1664 aViewFrame->installEventFilter( this );
1669 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1671 /* ouv: currently unused
1672 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1674 SUIT_ViewManager* aViewManager = 0;
1676 QObject* aParent = aViewPort;
1677 while( aParent = aParent->parent() )
1679 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1681 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1683 aViewManager = aViewer->getViewManager();
1692 double aMouseX = theEvent->scenePos().x();
1693 double aMouseY = theEvent->scenePos().y();
1695 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1696 if( aRole == VMR_General )
1698 int aXDeg = 0, aYDeg = 0;
1699 int aXMin = 0, aYMin = 0;
1700 double aXSec = 0, aYSec = 0;
1701 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1702 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1704 QString aDegSymbol( QChar( 0x00B0 ) );
1705 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1706 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1708 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1710 else if( aRole == VMR_TransformImage )
1711 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1716 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1717 const bool theIsInit,
1718 const bool theIsForced,
1719 const bool theDoFitAll )
1721 QList<int> aViewManagerIdList;
1723 // currently, all views are updated
1724 ViewManagerMapIterator anIter( myViewManagerMap );
1725 while( anIter.hasNext() )
1727 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1729 if ( theDisplayer->IsApplicable( aViewManager ) )
1731 int anId = anIter.key();
1732 aViewManagerIdList.append( anId );
1736 QListIterator<int> anIdIter( aViewManagerIdList );
1737 while( anIdIter.hasNext() )
1739 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1743 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1745 if( !theViewManager )
1748 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1749 if( !aSelectionMgr )
1752 QString aViewType = theViewManager->getType();
1753 if( aViewType != GraphicsView_Viewer::Type() &&
1754 aViewType != OCCViewer_Viewer::Type())
1757 QList<SUIT_Selector*> aSelectorList;
1758 aSelectionMgr->selectors( aViewType, aSelectorList );
1760 // disable all alien selectors
1761 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1762 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1764 SUIT_Selector* aSelector = *anIter;
1765 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1766 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1767 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1768 aSelector->setEnabled( false );
1771 if ( aViewType == GraphicsView_Viewer::Type() )
1773 GraphicsView_ViewManager* aViewManager =
1774 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1776 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1778 else if ( aViewType == OCCViewer_Viewer::Type() )
1780 OCCViewer_ViewManager* aViewManager =
1781 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1783 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1787 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1789 bool aPrevState = myIsUpdateEnabled;
1790 myIsUpdateEnabled = theState;
1794 bool HYDROGUI_Module::isUpdateEnabled() const
1796 return myIsUpdateEnabled;
1799 QStringList HYDROGUI_Module::storeSelection() const
1801 QStringList anEntryList;
1802 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1804 SUIT_DataOwnerPtrList aList( true );
1805 aSelectionMgr->selected( aList );
1807 SUIT_DataOwnerPtrList::iterator anIter;
1808 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1810 const LightApp_DataOwner* anOwner =
1811 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1813 anEntryList.append( anOwner->entry() );
1819 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1821 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1823 SUIT_DataOwnerPtrList aList( true );
1824 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1825 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1826 aSelectionMgr->setSelected( aList );
1830 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1833 bool doShow = false;
1834 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1836 aDisplayer->SaveCursorViewPosition( theViewWindow );
1837 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1841 // Show the coordinates in the status bar
1842 SUIT_Desktop* aDesktop = getApp()->desktop();
1843 if ( aDesktop && aDesktop->statusBar() )
1845 gp_Pnt aWPnt( X, Y, Z );
1846 int aStudyId = application()->activeStudy()->id();
1847 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1848 double WX = aWPnt.X(), WY = aWPnt.Y();
1850 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1851 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1852 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1853 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1854 QString aMsg = tr( "COORDINATES_INFO" );
1855 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1856 aDesktop->statusBar()->showMessage( aMsg );
1862 * Returns stack of active operations;
1864 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1866 return myActiveOperationMap;
1870 * Returns the module active operation. If the active operation is show/hide,
1871 * the method returns the previous operation if it is.
1873 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1875 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1877 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1879 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1881 aVIt.previous(); // skip the top show/hide operation
1882 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1889 * \brief Virtual public slot
1891 * This method is called after the object inserted into data view to update their visibility state
1892 * This is default implementation
1894 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1896 if ( !isActiveModule() )
1899 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1901 // change visibility of object
1902 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1905 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1907 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1908 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1909 if ( visState == Qtx::UnpresentableState )
1912 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1913 treeModel->setVisibilityState( id, visState );
1915 bool vis = visState == Qtx::ShownState;
1916 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1919 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1921 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1924 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1926 Handle(HYDROData_StricklerTable) aTable;
1928 if ( myLandCoverColoringMap.contains( theViewId ) ) {
1929 aTable = myLandCoverColoringMap.value( theViewId );
1935 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1936 const Handle(HYDROData_StricklerTable)& theTable )
1938 if ( !theTable.IsNull() ) {
1939 myLandCoverColoringMap.insert( theViewId, theTable );
1943 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
1945 myLandCoverColoringMap.remove( theViewId );
1948 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
1950 return myLandCoverColoringMap.contains( theViewId );
1953 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
1955 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
1959 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
1960 Handle(HYDROData_StricklerTable) aTable =
1961 Handle(HYDROData_StricklerTable)::DownCast( theObject );
1962 QList<int> aViewIds;
1963 QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
1964 while ( anIter.hasNext() ) {
1965 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
1966 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
1973 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
1978 SUIT_ViewWindow* wnd = theMgr->getActiveView();
1979 OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
1983 myOverview->setMainView( occwnd );