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>
53 #include <HYDROData_OperationsFactory.h>
55 #include <CurveCreator_Utils.hxx>
57 #include <GraphicsView_ViewFrame.h>
58 #include <GraphicsView_ViewManager.h>
59 #include <GraphicsView_ViewPort.h>
60 #include <GraphicsView_Viewer.h>
62 #include <ImageComposer_CutOperator.h>
63 #include <ImageComposer_CropOperator.h>
64 #include <ImageComposer_FuseOperator.h>
66 #include <LightApp_Application.h>
67 #include <LightApp_DataOwner.h>
68 #include <LightApp_GVSelector.h>
69 #include <LightApp_SelectionMgr.h>
70 #include <LightApp_UpdateFlags.h>
72 #include <SalomeApp_Study.h>
74 #include <OCCViewer_ViewFrame.h>
75 #include <OCCViewer_ViewManager.h>
76 #include <OCCViewer_ViewModel.h>
78 #include <SALOME_Event.h>
80 #include <SUIT_DataBrowser.h>
81 #include <SUIT_DataObject.h>
82 #include <SUIT_ViewManager.h>
83 #include <SUIT_ResourceMgr.h>
84 #include <SUIT_Desktop.h>
85 #include <SUIT_Study.h>
86 #include <SUIT_Session.h>
88 #include <SVTK_ViewManager.h>
89 #include <SVTK_ViewModel.h>
90 #include <SVTK_ViewWindow.h>
91 #include <SVTK_Selector.h>
93 #include <OCCViewer_ViewPort3d.h>
95 #include <GEOMUtils.hxx>
96 #include <GeometryGUI.h>
98 #include <SALOMEDS_wrap.hxx>
101 #include <QApplication>
102 #include <QGraphicsSceneMouseEvent>
104 #include <QMouseEvent>
105 #include <QStatusBar>
108 static int ViewManagerId = 0;
110 extern "C" HYDRO_EXPORT CAM_Module* createModule()
112 return new HYDROGUI_Module();
115 extern "C" HYDRO_EXPORT char* getModuleVersion()
117 return (char*)HYDRO_VERSION;
120 HYDROGUI_Module::HYDROGUI_Module()
121 : LightApp_Module( "HYDRO" ),
124 myIsUpdateEnabled( true ),
129 HYDROGUI_Module::~HYDROGUI_Module()
133 int HYDROGUI_Module::getStudyId() const
135 LightApp_Application* anApp = getApp();
136 return anApp ? anApp->activeStudy()->id() : 0;
139 void HYDROGUI_Module::initialize( CAM_Application* theApp )
141 LightApp_Module::initialize( theApp );
144 createUndoRedoActions();
149 setMenuShown( false );
150 setToolShown( false );
152 myDisplayer = new HYDROGUI_Displayer( this );
153 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
154 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
157 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
159 bool aRes = LightApp_Module::activateModule( theStudy );
161 LightApp_Application* anApp = getApp();
162 SUIT_Desktop* aDesktop = anApp->desktop();
164 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
166 setMenuShown( true );
167 setToolShown( true );
169 #ifndef DISABLE_PYCONSOLE
170 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
171 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
174 // Remove defunct view managers from the map.
175 // It's essential to do this before "update( UF_All )" call!
176 QList<int> anObsoleteIds;
177 ViewManagerList anAllViewManagers = anApp->viewManagers();
178 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
179 ViewManagerMapIterator anIter( myViewManagerMap );
180 while( anIter.hasNext() ) {
181 int anId = anIter.next().key();
182 const ViewManagerInfo& anInfo = anIter.value();
184 aHydroViewManagers << anInfo.first;
186 if ( !anAllViewManagers.contains( anInfo.first ) ) {
187 anObsoleteIds << anId;
190 foreach ( const int anId, anObsoleteIds ) {
191 myViewManagerMap.remove( anId );
192 myObjectStateMap.remove( anId );
193 myShapesMap.remove( anId );
194 myVTKPrsMap.remove( anId );
196 // Replace the default selector for all view managers.
197 // Add view managers created outside of HYDRO module to the map.
198 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
199 createSelector( aViewManager ); // replace the default selector
200 if ( !aHydroViewManagers.contains( aViewManager ) ) {
201 ViewManagerInfo anInfo( aViewManager, VMR_General );
202 myViewManagerMap.insert( ViewManagerId++, anInfo );
208 updateCommandsStatus();
210 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
212 ViewManagerList anOCCViewManagers;
213 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
215 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers )
217 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
218 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
219 connect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
220 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
222 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() )
224 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
225 if ( aViewFrame && aViewFrame->getViewPort() )
227 aViewFrame->getViewPort()->installEventFilter( this );
233 SalomeApp_Study* aStudy =
234 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
236 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
237 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
238 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
239 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
240 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
241 if( !GEOM_var->_is_nil() ) {
242 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
247 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
248 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
249 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
254 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
257 ViewManagerMapIterator anIter( myViewManagerMap );
258 while( anIter.hasNext() )
259 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
260 getApp()->removeViewManager( aViewManager );
261 myViewManagerMap.clear();
264 ViewManagerList anOCCViewManagers;
265 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
266 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
267 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
268 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
272 myObjectStateMap.clear();
277 // clear the status bar
278 SUIT_Desktop* aDesktop = getApp()->desktop();
279 if ( aDesktop && aDesktop->statusBar() ) {
280 aDesktop->statusBar()->clearMessage();
283 // clear the data model's list of copying objects
284 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
286 setMenuShown( false );
287 setToolShown( false );
289 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
291 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
293 myActiveOperationMap.clear();
294 return LightApp_Module::deactivateModule( theStudy );
297 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
299 static bool inWindows = false;
304 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
305 #ifndef DISABLE_PYCONSOLE
306 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
308 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
309 theMap.insert( OverviewWindow, Qt::LeftDockWidgetArea );
312 LightApp_Application* app = getApp();
313 if( app && app->getWindow( OverviewWindow )==0 )
315 const_cast<HYDROGUI_Module*>( this )->myOverview =
316 new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() );
317 myOverview->setGeometry( 0, 0, 320, 240 );
318 app->insertDockWindow( OverviewWindow, myOverview );
323 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
325 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
328 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
332 HYDROGUI_DataModel* aModel = getDataModel();
334 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
335 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
336 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
337 bool anIsVTKView = theClient == SVTK_Viewer::Type();
338 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
341 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
343 bool anIsSelectedDataObjects = false;
344 bool anIsVisibleInSelection = false;
345 bool anIsHiddenInSelection = false;
347 bool anIsImage = false;
348 bool anIsImportedImage = false;
349 bool anIsImageHasRefs = false;
350 bool anIsFusedImage = false;
351 bool anIsCutImage = false;
352 bool anIsSplitImage = false;
353 bool anIsMustObjectBeUpdated = false;
354 bool anIsPolyline = false;
355 bool anIsPolyline3D = false;
356 bool anIsProfile = false;
357 bool anIsValidProfile = false;
358 bool anAllAreProfiles = false;
359 bool anIsBathymetry = false;
360 bool anIsCalculation = false;
361 bool anIsImmersibleZone = false;
362 bool anIsVisualState = false;
363 bool anIsRegion = false;
364 bool anIsZone = false;
365 bool anIsObstacle = false;
366 bool anIsStricklerTable = false;
367 bool anIsLandCoverMap = false;
368 bool anIsStream = false;
369 bool anIsChannel = false;
370 bool anIsDigue = false;
371 bool anIsDummyObject3D = false;
372 bool anIsGroup = false;
373 bool anIsObjectCanBeColored = false;
375 bool isStreamHasBottom = false;
377 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
378 SUIT_DataOwnerPtrList anOwners;
379 aSelectionMgr->selected( anOwners );
380 if( anIsObjectBrowser && anOwners.size()==1 )
382 QString anEntry = anOwners[0]->keyString();
383 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
385 isRoot = aStudy->isComponent( anEntry );
388 // Check the selected GEOM objects (take into account the Object Browser only)
389 if ( anIsObjectBrowser ) {
390 QList<GEOM::shape_type> anObstacleTypes =
391 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
392 QList<GEOM::shape_type> aPolylineTypes =
393 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
395 bool isCanBeImportedAsObstacle =
396 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
397 bool isCanBeImportedAsPolyline =
398 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
400 // Add import as obstacle action
401 if ( isCanBeImportedAsObstacle ) {
402 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
404 // Add import as polyline action
405 if ( isCanBeImportedAsPolyline ) {
406 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
409 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
410 theMenu->addSeparator();
414 // check the selected data model objects
415 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
416 int aNbOfSelectedProfiles = 0;
417 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
419 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
420 if( !anObject.IsNull() )
422 anIsSelectedDataObjects = true;
424 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
425 anIsVisibleInSelection |= aVisibility;
426 anIsHiddenInSelection |= !aVisibility;
428 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
430 anIsMustObjectBeUpdated = true;
433 ObjectKind anObjectKind = anObject->GetKind();
434 if( anObjectKind == KIND_IMAGE )
437 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
438 if( !anImage.IsNull() )
440 anIsImportedImage = anImage->HasLocalPoints();
441 anIsImageHasRefs = anImage->HasReferences();
442 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
444 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
446 QString anOperatorName = anOperator->name();
447 if( anOperatorName == ImageComposer_FuseOperator::Type() )
448 anIsFusedImage = true;
449 else if( anOperatorName == ImageComposer_CutOperator::Type() )
451 else if( anOperatorName == ImageComposer_CropOperator::Type() )
452 anIsSplitImage = true;
457 else if( anObjectKind == KIND_POLYLINEXY )
459 else if( anObjectKind == KIND_POLYLINE )
460 anIsPolyline3D = true;
461 else if( anObjectKind == KIND_PROFILE )
464 aNbOfSelectedProfiles++;
466 Handle(HYDROData_Profile) aProfile =
467 Handle(HYDROData_Profile)::DownCast( anObject );
468 if( !aProfile.IsNull() && aProfile->IsValid() ) {
469 anIsValidProfile = true;
472 else if( anObjectKind == KIND_CALCULATION )
473 anIsCalculation = true;
474 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
475 anIsImmersibleZone = true;
476 else if( anObjectKind == KIND_VISUAL_STATE )
477 anIsVisualState = true;
478 else if( anObjectKind == KIND_REGION )
480 else if( anObjectKind == KIND_ZONE )
482 else if( anObjectKind == KIND_BATHYMETRY )
483 anIsBathymetry = true;
484 else if( anObjectKind == KIND_OBSTACLE )
486 else if( anObjectKind == KIND_STRICKLER_TABLE )
487 anIsStricklerTable = true;
488 else if( anObjectKind == KIND_LAND_COVER_MAP )
489 anIsLandCoverMap = true;
490 else if( anObjectKind == KIND_STREAM )
493 Handle(HYDROData_Stream) aStream =
494 Handle(HYDROData_Stream)::DownCast( anObject );
495 if ( !aStream.IsNull() )
496 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
498 else if( anObjectKind == KIND_CHANNEL )
500 else if( anObjectKind == KIND_DIGUE )
502 else if( anObjectKind == KIND_DUMMY_3D )
503 anIsDummyObject3D = true;
504 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLIT_GROUP )
508 if ( !anIsObjectCanBeColored )
509 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
512 // Check if all selected objects are profiles
513 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
514 ( aNbOfSelectedProfiles == aSeq.Length() );
516 // check the selected partitions
517 if( !anIsSelectedDataObjects && anIsObjectBrowser )
519 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
520 if( aSelectedPartition != KIND_UNKNOWN )
522 switch( aSelectedPartition )
525 theMenu->addAction( action( ImportImageId ) );
527 case KIND_BATHYMETRY:
528 theMenu->addAction( action( ImportBathymetryId ) );
530 case KIND_ARTIFICIAL_OBJECT:
531 theMenu->addAction( action( CreateChannelId ) );
532 theMenu->addAction( action( CreateDigueId ) );
534 case KIND_NATURAL_OBJECT:
535 theMenu->addAction( action( CreateImmersibleZoneId ) );
536 theMenu->addAction( action( CreateStreamId ) );
539 theMenu->addAction( action( ImportObstacleFromFileId ) );
540 theMenu->addAction( action( CreateBoxId ) );
541 theMenu->addAction( action( CreateCylinderId ) );
543 case KIND_STRICKLER_TABLE:
544 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
546 case KIND_LAND_COVER_MAP:
547 theMenu->addAction( action( CreateLandCoverMapId ) );
548 theMenu->addAction( action( ImportLandCoverMapId ) );
550 case KIND_CALCULATION:
551 theMenu->addAction( action( CreateCalculationId ) );
553 case KIND_POLYLINEXY:
554 theMenu->addAction( action( ImportPolylineId ) );
555 theMenu->addAction( action( CreatePolylineId ) );
558 theMenu->addAction( action( CreatePolyline3DId ) );
561 theMenu->addAction( action( CreateProfileId ) );
562 theMenu->addAction( action( ImportProfilesId ) );
563 theMenu->addAction( action( AllGeoreferencementId ) );
565 case KIND_VISUAL_STATE:
566 theMenu->addAction( action( SaveVisualStateId ) );
569 theMenu->addSeparator();
573 Handle(HYDROData_CalculationCase) aCalcCase;
575 HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
576 if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
577 theMenu->addAction( action( RegenerateRegionColorsId ) );
581 if( anIsSelectedDataObjects )
583 if ( anIsMustObjectBeUpdated )
585 theMenu->addAction( action( UpdateObjectId ) );
586 theMenu->addSeparator();
590 theMenu->addAction( action( ForcedUpdateObjectId ) );
591 theMenu->addSeparator();
595 if( aSeq.Length() == 1 )
599 if( anIsImportedImage )
600 theMenu->addAction( action( EditImportedImageId ) );
601 else if( anIsImageHasRefs )
604 theMenu->addAction( action( EditFusedImageId ) );
605 else if( anIsCutImage )
606 theMenu->addAction( action( EditCutImageId ) );
607 else if( anIsSplitImage )
608 theMenu->addAction( action( EditSplitImageId ) );
611 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
612 theMenu->addAction( action( ExportImageId ) );
613 theMenu->addSeparator();
615 if( anIsImageHasRefs )
617 theMenu->addAction( action( RemoveImageRefsId ) );
618 theMenu->addSeparator();
621 theMenu->addAction( action( FuseImagesId ) );
622 theMenu->addAction( action( CutImagesId ) );
623 theMenu->addAction( action( SplitImageId ) );
624 theMenu->addSeparator();
625 theMenu->addAction( action( RecognizeContoursId ) );
626 theMenu->addSeparator();
628 else if( anIsBathymetry )
630 theMenu->addAction( action( EditImportedBathymetryId ) );
631 theMenu->addAction( action( BathymetryBoundsId ) );
632 theMenu->addSeparator();
634 else if( anIsPolyline )
636 theMenu->addAction( action( EditPolylineId ) );
637 theMenu->addSeparator();
638 theMenu->addAction( action( SplitPolylinesId ) );
639 theMenu->addAction( action( MergePolylinesId ) );
640 theMenu->addSeparator();
642 else if( anIsPolyline3D )
644 theMenu->addAction( action( EditPolyline3DId ) );
645 theMenu->addSeparator();
647 else if( anIsProfile )
649 theMenu->addAction( action( EditProfileId ) );
650 theMenu->addAction( action( SelectedGeoreferencementId ) );
651 theMenu->addSeparator();
653 else if( anIsCalculation )
655 theMenu->addAction( action( EditCalculationId ) );
656 theMenu->addAction( action( ExportCalculationId ) );
657 theMenu->addSeparator();
659 else if( anIsImmersibleZone )
661 theMenu->addAction( action( EditImmersibleZoneId ) );
662 theMenu->addSeparator();
664 else if( anIsStream )
666 theMenu->addAction( action( EditStreamId ) );
667 if ( action( RiverBottomContextId ) )
669 theMenu->addAction( action( RiverBottomContextId ) );
670 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
672 theMenu->addAction( action( ProfileInterpolateId ) );
673 theMenu->addSeparator();
675 else if( anIsChannel )
677 theMenu->addAction( action( EditChannelId ) );
678 theMenu->addSeparator();
682 theMenu->addAction( action( EditDigueId ) );
683 theMenu->addSeparator();
685 else if( anIsObstacle )
687 theMenu->addAction( action( TranslateObstacleId ) );
688 theMenu->addSeparator();
690 else if( anIsStricklerTable )
692 theMenu->addAction( action( EditStricklerTableId ) );
693 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
694 theMenu->addAction( action( DuplicateStricklerTableId ) );
695 theMenu->addSeparator();
697 Handle(HYDROData_StricklerTable) aTable =
698 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
699 QString aCurrentTable =
700 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
701 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
703 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
704 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
705 theMenu->addSeparator();
708 else if( anIsLandCoverMap )
710 theMenu->addAction( action( AddLandCoverId ) );
711 theMenu->addAction( action( RemoveLandCoverId ) );
712 theMenu->addSeparator();
713 theMenu->addAction( action( SplitLandCoverId ) );
714 theMenu->addAction( action( MergeLandCoverId ) );
715 theMenu->addAction( action( ChangeLandCoverTypeId ) );
716 theMenu->addSeparator();
718 theMenu->addAction( action( ExportToShapeFileID ) );
719 theMenu->addSeparator();
721 else if( anIsVisualState && anIsObjectBrowser )
723 theMenu->addAction( action( SaveVisualStateId ) );
724 theMenu->addAction( action( LoadVisualStateId ) );
725 theMenu->addSeparator();
728 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
730 theMenu->addAction( action( PolylineExtractionId ) );
731 theMenu->addSeparator();
734 // Add set color action for geometrical objects
735 if ( anIsObjectCanBeColored )
737 theMenu->addAction( action( SetColorId ) );
738 theMenu->addSeparator();
741 // Add transparency action for land cover map objects
742 if ( anIsLandCoverMap )
744 theMenu->addAction( action( SetTransparencyId ) );
745 theMenu->addSeparator();
747 } else if ( anAllAreProfiles ) {
748 theMenu->addAction( action( SelectedGeoreferencementId ) );
749 theMenu->addSeparator();
752 bool anIsPoly = anIsPolyline || anIsPolyline3D;
753 if (anIsPoly && !anIsLandCoverMap)
754 theMenu->addAction( action( ExportToShapeFileID ) );
757 QAction* aCopyAction = action( CopyId );
758 if( aCopyAction && aCopyAction->isEnabled() ) {
759 theMenu->addAction( action( CopyId ) );
760 theMenu->addSeparator();
764 if( !anIsDummyObject3D )
765 theMenu->addAction( action( DeleteId ) );
767 theMenu->addSeparator();
769 if( anIsImage || anIsPolyline || anIsPolyline3D ||
770 anIsImmersibleZone || anIsZone || anIsRegion ||
771 anIsBathymetry || anIsObstacle || anIsStream ||
772 anIsChannel || anIsDigue || anIsDummyObject3D ||
773 anIsValidProfile || anIsGroup || anIsLandCoverMap )
775 if( anIsHiddenInSelection )
776 theMenu->addAction( action( ShowId ) );
777 theMenu->addAction( action( ShowOnlyId ) );
778 if( anIsVisibleInSelection )
779 theMenu->addAction( action( HideId ) );
780 theMenu->addSeparator();
786 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
787 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
788 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
789 theMenu->addAction( action( DeleteId ) );
791 theMenu->addSeparator();
792 theMenu->addAction( action( SetZLevelId ) );
793 theMenu->addSeparator();
795 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
796 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
797 theMenu->addSeparator();
801 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
803 theMenu->addAction( action( ShowAllId ) );
804 theMenu->addAction( action( HideAllId ) );
805 theMenu->addSeparator();
808 if ( anIsOCCView || anIsVTKView )
810 theMenu->addSeparator();
811 theMenu->addAction( action( CopyViewerPositionId ) );
815 theMenu->addAction( action( EditLocalCSId ) );
817 if( anIsObjectBrowser && anOwners.size()==1 )
819 if( aSeq.Size() > 0 )
821 Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
822 if( !anObject.IsNull() )
824 theMenu->addSeparator();
825 theMenu->addAction( action( SubmersibleId ) );
826 action( SubmersibleId )->setCheckable( true );
827 action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
833 void HYDROGUI_Module::createPreferences()
835 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
836 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
838 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
839 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
841 // Set property cursor type
842 QList<QVariant> aCursorTypeIndicesList;
843 QList<QVariant> aCursorTypeIconsList;
845 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
846 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
847 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
848 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
849 aCursorTypeIndicesList << i;
850 aCursorTypeIconsList << pixmap;
853 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
854 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
856 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
857 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
858 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
860 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
861 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
862 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
863 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
864 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
865 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
866 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
868 int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
869 int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
870 LightApp_Preferences::Selector, "polyline", "arrow_type" );
872 QList<QVariant> arrow_types;
873 arrow_types.append( tr( "No" ) );
874 arrow_types.append( tr( "Triangle" ) );
875 arrow_types.append( tr( "Cone" ) );
876 setPreferenceProperty( polylineArrow, "strings", arrow_types );
878 QList<QVariant> indices;
882 setPreferenceProperty( polylineArrow, "indexes", indices );
883 setPreferenceProperty( polylineArrow, "ids", indices );
885 int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
886 LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
889 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
891 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
892 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
895 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
896 if ( resMgr && !aDoc.IsNull() )
897 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
899 else if( theSection == "polyline" )
905 resMgr->value( "polyline", "arrow_type", aType );
906 resMgr->value( "polyline", "arrow_size", aSize );
909 ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
910 for( ; it!=last; it++ )
912 int aViewerId = it.key();
913 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
915 getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
919 LightApp_Module::preferencesChanged( theSection, thePref );
922 QCursor HYDROGUI_Module::getPrefEditCursor() const
924 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
925 if ( aCursorType >= Qt::BlankCursor)
927 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
931 void HYDROGUI_Module::update( const int flags )
933 if ( !isUpdateEnabled() )
936 QApplication::setOverrideCursor( Qt::WaitCursor );
938 // To prevent calling this method recursively
939 // from one of the methods called below
940 setUpdateEnabled( false );
942 // store selected objects
943 QStringList aSelectedEntries = storeSelection();
945 bool aDoFitAll = flags & UF_FitAll;
948 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
949 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
952 if( ( flags & UF_Viewer ) )
953 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
955 if( ( flags & UF_OCCViewer ) )
956 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
958 if( ( flags & UF_VTKViewer ) )
959 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
961 if( ( flags & UF_Model ) && getDataModel() && getApp() )
963 getDataModel()->update( getStudyId() );
965 // Temporary workaround to prevent breaking
966 // the selection in the object browser.
967 // Note: processEvents() should be called after updateGV(),
968 // otherwise the application crashes from time to time.
969 //RKV: qApp->processEvents();
970 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
971 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
972 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
973 if ( isResizeOnExpandItem && anObjectBrowser ) {
974 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
976 getApp()->updateObjectBrowser( true );
977 if ( isResizeOnExpandItem && anObjectBrowser ) {
978 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
982 // Object browser is currently updated by using UF_Model flag
983 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
984 getApp()->updateObjectBrowser( true );
986 if( ( flags & UF_Controls ) && getApp() )
987 getApp()->updateActions();
989 // restore selected objects
990 restoreSelection( aSelectedEntries );
992 setUpdateEnabled( true );
994 QApplication::restoreOverrideCursor();
997 void HYDROGUI_Module::updateCommandsStatus()
999 LightApp_Module::updateCommandsStatus();
1001 updateUndoRedoControls();
1003 action( CopyId )->setEnabled( getDataModel()->canCopy() );
1004 action( PasteId )->setEnabled( getDataModel()->canPaste() );
1007 void HYDROGUI_Module::selectionChanged()
1009 LightApp_Module::selectionChanged();
1010 updateCommandsStatus();
1013 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1015 return (HYDROGUI_DataModel*)dataModel();
1018 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1023 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1025 return myOCCDisplayer;
1028 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1030 return myVTKDisplayer;
1033 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
1035 if( myViewManagerMap.contains( theId ) )
1037 return myViewManagerMap[ theId ].first;
1042 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
1044 if( myViewManagerMap.contains( theId ) )
1046 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1047 GraphicsView_ViewManager* aViewManager =
1048 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1050 return aViewManager->getViewer();
1055 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
1057 if( myViewManagerMap.contains( theId ) )
1059 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1060 OCCViewer_ViewManager* aViewManager =
1061 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1063 return aViewManager->getOCCViewer();
1068 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
1070 if( myViewManagerMap.contains( theId ) )
1072 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1073 SVTK_ViewManager* aViewManager =
1074 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1076 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1081 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1083 ViewManagerMapIterator anIter( myViewManagerMap );
1084 while( anIter.hasNext() )
1086 int anId = anIter.next().key();
1087 const ViewManagerInfo& anInfo = anIter.value();
1088 if( anInfo.first == theViewManager )
1094 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1096 int anId = getViewManagerId( theViewManager );
1099 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1100 return anInfo.second;
1105 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1106 const ViewManagerRole theRole )
1108 int anId = getViewManagerId( theViewManager );
1111 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1112 anInfo.second = theRole;
1116 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1117 const Handle(HYDROData_Entity)& theObject ) const
1119 if( theObject.IsNull() )
1125 foreach( int aViewId, myObjectStateMap.keys() )
1127 if( isObjectVisible( aViewId, theObject ) )
1133 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1134 if( anIter1 != myObjectStateMap.end() )
1136 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1137 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1139 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1140 if( anIter2 != aEntry2ObjectStateMap.end() )
1142 const ObjectState& anObjectState = anIter2.value();
1143 return anObjectState.Visibility;
1149 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1150 const Handle(HYDROData_Entity)& theObject,
1151 const bool theState )
1153 if( !theObject.IsNull() )
1155 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1156 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1158 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1159 anObjectState.Visibility = theState;
1161 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1164 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1167 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1168 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1169 if ( visState != Qtx::UnpresentableState )
1170 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1174 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1175 setLandCoversScalarMapModeOff( theViewId );
1176 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1177 getOCCDisplayer()->SetToUpdateColorScale();
1182 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1183 const bool theState )
1185 if( !theObject.IsNull() )
1187 // Process OCC shapes
1188 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1189 while( aShapesMapIter != myShapesMap.end() )
1191 const ListOfShapes& aShapesList = aShapesMapIter.value();
1192 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1194 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1196 aShape->setIsToUpdate( theState );
1201 // Process VTK shapes
1202 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1203 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1205 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1206 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1208 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1210 aShape->setIsToUpdate( theState );
1218 /////////////////// OCC SHAPES PROCESSING
1219 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1220 ObjectKind theKind ) const
1222 QList<HYDROGUI_Shape*> aResult;
1224 if ( myShapesMap.contains( theViewId ) )
1226 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1227 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1229 if( aShape && aShape->getObject()->GetKind()==theKind )
1230 aResult.append( aShape );
1236 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1237 const Handle(HYDROData_Entity)& theObject ) const
1239 HYDROGUI_Shape* aResShape = NULL;
1240 if( theObject.IsNull() )
1243 if ( myShapesMap.contains( theViewId ) )
1245 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1246 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1248 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1259 void HYDROGUI_Module::setObjectShape( const int theViewId,
1260 const Handle(HYDROData_Entity)& theObject,
1261 HYDROGUI_Shape* theShape )
1263 if( theObject.IsNull() )
1266 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1267 aViewShapes.append( theShape );
1270 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1271 const Handle(HYDROData_Entity)& theObject )
1273 if ( !myShapesMap.contains( theViewId ) )
1276 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1277 Handle(HYDROData_Entity) anObject;
1278 for ( int i = 0; i < aViewShapes.length(); )
1280 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1281 anObject = aShape->getObject();
1282 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1285 aViewShapes.removeAt( i );
1293 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1295 if ( !myShapesMap.contains( theViewId ) )
1298 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1299 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1301 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1306 myShapesMap.remove( theViewId );
1308 /////////////////// END OF OCC SHAPES PROCESSING
1310 /////////////////// VTKPrs PROCESSING
1311 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1312 const Handle(HYDROData_Entity)& theObject ) const
1314 HYDROGUI_VTKPrs* aResShape = NULL;
1315 if( theObject.IsNull() )
1318 if ( myVTKPrsMap.contains( theViewId ) )
1320 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1321 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1323 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1334 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1335 const Handle(HYDROData_Entity)& theObject,
1336 HYDROGUI_VTKPrs* theShape )
1338 if( theObject.IsNull() )
1341 if( theShape && theShape->needScalarBar() )
1343 // Compute the new global Z range from the added presentation and the old global Z range.
1344 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1345 double* aRange = theShape->getInternalZRange();
1346 bool anIsUpdate = false;
1347 if ( aRange[0] < aGlobalRange[0] )
1349 aGlobalRange[0] = aRange[0];
1352 if ( aRange[1] > aGlobalRange[1] )
1354 aGlobalRange[1] = aRange[1];
1360 updateVTKZRange( theViewId, aGlobalRange );
1364 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1365 aViewShapes.append( theShape );
1368 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1369 const QString& theEntry )
1371 if ( !myVTKPrsMap.contains( theViewId ) )
1374 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1375 Handle(HYDROData_Entity) anObject;
1377 for ( int i = 0; i < aViewShapes.length(); )
1379 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1380 anObject = aShape->getObject();
1381 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1382 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1385 aViewShapes.removeAt( i );
1392 // Invalidate global Z range
1393 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1394 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1397 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1398 const Handle(HYDROData_Entity)& theObject )
1400 if ( !myVTKPrsMap.contains( theViewId ) )
1403 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1404 Handle(HYDROData_Entity) anObject;
1405 for ( int i = 0; i < aViewShapes.length(); )
1407 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1408 anObject = aShape->getObject();
1409 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1412 aViewShapes.removeAt( i );
1419 // Invalidate global Z range
1420 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1421 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1424 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1426 if ( !myVTKPrsMap.contains( theViewId ) )
1429 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1430 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1432 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1437 myVTKPrsMap.remove( theViewId );
1440 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1442 if ( myVTKPrsMap.contains( theViewId ) )
1444 // For the given viewer id update all VTK presentations ...
1445 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1446 HYDROGUI_VTKPrs* aShape;
1447 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1449 aShape = aViewShapes.at( i );
1450 if ( aShape && aShape->needScalarBar() )
1452 aShape->setZRange( theRange );
1456 // ... and update the global color legend scalar bar.
1457 getVTKDisplayer()->SetZRange( theViewId, theRange );
1459 /////////////////// END OF VTKPrs PROCESSING
1461 void HYDROGUI_Module::clearCache()
1463 myObjectStateMap.clear();
1466 CAM_DataModel* HYDROGUI_Module::createDataModel()
1468 return new HYDROGUI_DataModel( this );
1471 void HYDROGUI_Module::customEvent( QEvent* e )
1473 int aType = e->type();
1474 if ( aType == NewViewEvent )
1476 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1477 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1479 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1481 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1482 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1484 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1486 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1487 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1489 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1490 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1491 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1493 //ouv: temporarily commented
1494 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1497 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1498 update( UF_Viewer );
1500 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1506 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1508 QEvent::Type aType = theEvent->type();
1509 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1511 if( aType == QEvent::Show )
1513 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1514 e->setData( theObj );
1515 QApplication::postEvent( this, e );
1516 theObj->removeEventFilter( this );
1519 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1521 if( aType == QEvent::Leave )
1523 SUIT_Desktop* aDesktop = getApp()->desktop();
1524 if ( aDesktop && aDesktop->statusBar() ) {
1525 aDesktop->statusBar()->clearMessage();
1529 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1531 if( aType == QEvent::Leave )
1533 SUIT_Desktop* aDesktop = getApp()->desktop();
1534 if ( aDesktop && aDesktop->statusBar() ) {
1535 aDesktop->statusBar()->clearMessage();
1540 return LightApp_Module::eventFilter( theObj, theEvent );
1543 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1545 LightApp_Module::onViewManagerAdded( theViewManager );
1547 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1549 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1550 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1552 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1554 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1555 mgr->setChainedOperations( true );//TODO: via preferences
1557 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1558 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1559 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1560 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1561 connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
1562 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1564 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1566 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1567 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1568 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1569 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1572 createSelector( theViewManager ); // replace the default selector
1574 ViewManagerInfo anInfo( theViewManager, VMR_General );
1575 myViewManagerMap.insert( ViewManagerId++, anInfo );
1578 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1580 LightApp_Module::onViewManagerRemoved( theViewManager );
1582 createSelector( theViewManager ); // replace the default selector
1584 int anId = getViewManagerId( theViewManager );
1587 OCCViewer_ViewManager* anOCCViewManager =
1588 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1589 if ( anOCCViewManager )
1591 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1592 if ( anOCCViewer ) {
1593 int aViewerId = (size_t)anOCCViewer;
1594 removeViewShapes( aViewerId );
1595 setLandCoversScalarMapModeOff( aViewerId );
1599 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1601 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1604 getVTKDisplayer()->EraseScalarBar( anId, true );
1605 removeViewShapes( (size_t)aVTKViewer );
1609 myViewManagerMap.remove( anId );
1613 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1615 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1617 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1619 aViewFrame->installEventFilter( this );
1621 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1622 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1624 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1625 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1628 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1630 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1632 aViewFrame->onTopView();
1634 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1636 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1638 aViewPort->installEventFilter( this );
1642 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1644 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1646 aViewFrame->installEventFilter( this );
1651 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1653 /* ouv: currently unused
1654 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1656 SUIT_ViewManager* aViewManager = 0;
1658 QObject* aParent = aViewPort;
1659 while( aParent = aParent->parent() )
1661 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1663 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1665 aViewManager = aViewer->getViewManager();
1674 double aMouseX = theEvent->scenePos().x();
1675 double aMouseY = theEvent->scenePos().y();
1677 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1678 if( aRole == VMR_General )
1680 int aXDeg = 0, aYDeg = 0;
1681 int aXMin = 0, aYMin = 0;
1682 double aXSec = 0, aYSec = 0;
1683 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1684 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1686 QString aDegSymbol( QChar( 0x00B0 ) );
1687 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1688 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1690 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1692 else if( aRole == VMR_TransformImage )
1693 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1698 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1699 const bool theIsInit,
1700 const bool theIsForced,
1701 const bool theDoFitAll )
1703 QList<int> aViewManagerIdList;
1705 // currently, all views are updated
1706 ViewManagerMapIterator anIter( myViewManagerMap );
1707 while( anIter.hasNext() )
1709 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1711 if ( theDisplayer->IsApplicable( aViewManager ) )
1713 int anId = anIter.key();
1714 aViewManagerIdList.append( anId );
1718 QListIterator<int> anIdIter( aViewManagerIdList );
1719 while( anIdIter.hasNext() )
1721 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1725 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1727 if( !theViewManager )
1730 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1731 if( !aSelectionMgr )
1734 QString aViewType = theViewManager->getType();
1735 if( aViewType != GraphicsView_Viewer::Type() &&
1736 aViewType != OCCViewer_Viewer::Type())
1739 QList<SUIT_Selector*> aSelectorList;
1740 aSelectionMgr->selectors( aViewType, aSelectorList );
1742 // disable all alien selectors
1743 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1744 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1746 SUIT_Selector* aSelector = *anIter;
1747 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1748 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1749 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1750 aSelector->setEnabled( false );
1753 if ( aViewType == GraphicsView_Viewer::Type() )
1755 GraphicsView_ViewManager* aViewManager =
1756 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1758 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1760 else if ( aViewType == OCCViewer_Viewer::Type() )
1762 OCCViewer_ViewManager* aViewManager =
1763 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1765 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1769 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1771 bool aPrevState = myIsUpdateEnabled;
1772 myIsUpdateEnabled = theState;
1776 bool HYDROGUI_Module::isUpdateEnabled() const
1778 return myIsUpdateEnabled;
1781 QStringList HYDROGUI_Module::storeSelection() const
1783 QStringList anEntryList;
1784 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1786 SUIT_DataOwnerPtrList aList( true );
1787 aSelectionMgr->selected( aList );
1789 SUIT_DataOwnerPtrList::iterator anIter;
1790 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1792 const LightApp_DataOwner* anOwner =
1793 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1795 anEntryList.append( anOwner->entry() );
1801 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1803 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1805 SUIT_DataOwnerPtrList aList( true );
1806 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1807 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1808 aSelectionMgr->setSelected( aList );
1812 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1815 bool doShow = false;
1816 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1818 aDisplayer->SaveCursorViewPosition( theViewWindow );
1819 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1823 // Show the coordinates in the status bar
1824 SUIT_Desktop* aDesktop = getApp()->desktop();
1825 if ( aDesktop && aDesktop->statusBar() )
1827 gp_Pnt aWPnt( X, Y, Z );
1828 int aStudyId = application()->activeStudy()->id();
1829 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1830 double WX = aWPnt.X(), WY = aWPnt.Y();
1832 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1833 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1834 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1835 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1836 QString aMsg = tr( "COORDINATES_INFO" );
1837 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1838 aDesktop->statusBar()->showMessage( aMsg );
1844 * Returns stack of active operations;
1846 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1848 return myActiveOperationMap;
1852 * Returns the module active operation. If the active operation is show/hide,
1853 * the method returns the previous operation if it is.
1855 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1857 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1859 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1861 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1863 aVIt.previous(); // skip the top show/hide operation
1864 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1871 * \brief Virtual public slot
1873 * This method is called after the object inserted into data view to update their visibility state
1874 * This is default implementation
1876 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1878 if ( !isActiveModule() )
1881 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1883 // change visibility of object
1884 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1887 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1889 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1890 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1891 if ( visState == Qtx::UnpresentableState )
1894 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1895 treeModel->setVisibilityState( id, visState );
1897 bool vis = visState == Qtx::ShownState;
1898 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1901 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1903 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1906 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1908 Handle(HYDROData_StricklerTable) aTable;
1910 if ( myLandCoverColoringMap.contains( theViewId ) ) {
1911 aTable = myLandCoverColoringMap.value( theViewId );
1917 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1918 const Handle(HYDROData_StricklerTable)& theTable )
1920 if ( !theTable.IsNull() ) {
1921 myLandCoverColoringMap.insert( theViewId, theTable );
1925 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
1927 myLandCoverColoringMap.remove( theViewId );
1930 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
1932 return myLandCoverColoringMap.contains( theViewId );
1935 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
1937 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
1941 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
1942 Handle(HYDROData_StricklerTable) aTable =
1943 Handle(HYDROData_StricklerTable)::DownCast( theObject );
1944 QList<int> aViewIds;
1945 QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
1946 while ( anIter.hasNext() ) {
1947 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
1948 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
1955 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
1960 SUIT_ViewWindow* wnd = theMgr->getActiveView();
1961 OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
1965 myOverview->setMainView( occwnd );