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 Handle(HYDROData_CalculationCase) aCalcCase;
577 HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
578 if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
579 theMenu->addAction( action( RegenerateRegionColorsId ) );
583 if( anIsSelectedDataObjects )
585 if ( anIsMustObjectBeUpdated )
587 theMenu->addAction( action( UpdateObjectId ) );
588 theMenu->addSeparator();
592 theMenu->addAction( action( ForcedUpdateObjectId ) );
593 theMenu->addSeparator();
597 if( aSeq.Length() == 1 )
601 if( anIsImportedImage )
602 theMenu->addAction( action( EditImportedImageId ) );
603 else if( anIsImageHasRefs )
606 theMenu->addAction( action( EditFusedImageId ) );
607 else if( anIsCutImage )
608 theMenu->addAction( action( EditCutImageId ) );
609 else if( anIsSplitImage )
610 theMenu->addAction( action( EditSplitImageId ) );
613 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
614 theMenu->addAction( action( ExportImageId ) );
615 theMenu->addSeparator();
617 if( anIsImageHasRefs )
619 theMenu->addAction( action( RemoveImageRefsId ) );
620 theMenu->addSeparator();
623 theMenu->addAction( action( FuseImagesId ) );
624 theMenu->addAction( action( CutImagesId ) );
625 theMenu->addAction( action( SplitImageId ) );
626 theMenu->addSeparator();
627 theMenu->addAction( action( RecognizeContoursId ) );
628 theMenu->addSeparator();
630 else if( anIsBathymetry )
632 theMenu->addAction( action( EditImportedBathymetryId ) );
633 theMenu->addAction( action( BathymetryBoundsId ) );
634 theMenu->addSeparator();
636 else if( anIsPolyline )
638 theMenu->addAction( action( EditPolylineId ) );
639 theMenu->addSeparator();
640 theMenu->addAction( action( SplitPolylinesId ) );
641 theMenu->addAction( action( MergePolylinesId ) );
642 theMenu->addSeparator();
644 else if( anIsPolyline3D )
646 theMenu->addAction( action( EditPolyline3DId ) );
647 theMenu->addSeparator();
649 else if( anIsProfile )
651 theMenu->addAction( action( EditProfileId ) );
652 theMenu->addAction( action( SelectedGeoreferencementId ) );
653 theMenu->addSeparator();
655 else if( anIsCalculation )
657 theMenu->addAction( action( EditCalculationId ) );
658 theMenu->addAction( action( ExportCalculationId ) );
659 theMenu->addSeparator();
661 else if( anIsImmersibleZone )
663 theMenu->addAction( action( EditImmersibleZoneId ) );
664 theMenu->addSeparator();
666 else if( anIsStream )
668 theMenu->addAction( action( EditStreamId ) );
669 if ( action( RiverBottomContextId ) )
671 theMenu->addAction( action( RiverBottomContextId ) );
672 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
674 theMenu->addAction( action( ProfileInterpolateId ) );
675 theMenu->addSeparator();
677 else if( anIsChannel )
679 theMenu->addAction( action( EditChannelId ) );
680 theMenu->addSeparator();
684 theMenu->addAction( action( EditDigueId ) );
685 theMenu->addSeparator();
687 else if( anIsObstacle )
689 theMenu->addAction( action( TranslateObstacleId ) );
690 theMenu->addSeparator();
692 else if( anIsStricklerTable )
694 theMenu->addAction( action( EditStricklerTableId ) );
695 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
696 theMenu->addAction( action( DuplicateStricklerTableId ) );
697 theMenu->addSeparator();
699 Handle(HYDROData_StricklerTable) aTable =
700 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
701 QString aCurrentTable =
702 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
703 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
705 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
706 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
707 theMenu->addSeparator();
710 else if( anIsLandCoverMap )
712 theMenu->addAction( action( AddLandCoverId ) );
713 theMenu->addAction( action( RemoveLandCoverId ) );
714 theMenu->addSeparator();
715 theMenu->addAction( action( SplitLandCoverId ) );
716 theMenu->addAction( action( MergeLandCoverId ) );
717 theMenu->addAction( action( ChangeLandCoverTypeId ) );
718 theMenu->addSeparator();
720 theMenu->addAction( action( ExportToShapeFileID ) );
721 theMenu->addSeparator();
723 else if( anIsVisualState && anIsObjectBrowser )
725 theMenu->addAction( action( SaveVisualStateId ) );
726 theMenu->addAction( action( LoadVisualStateId ) );
727 theMenu->addSeparator();
730 theMenu->addAction( action( ZoneSetColorId ) );
732 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
734 theMenu->addAction( action( PolylineExtractionId ) );
735 theMenu->addSeparator();
738 // Add set color action for geometrical objects
739 if ( anIsObjectCanBeColored )
741 theMenu->addAction( action( SetColorId ) );
742 theMenu->addSeparator();
745 // Add transparency action for land cover map objects
746 if ( anIsLandCoverMap )
748 theMenu->addAction( action( SetTransparencyId ) );
749 theMenu->addSeparator();
751 } else if ( anAllAreProfiles ) {
752 theMenu->addAction( action( SelectedGeoreferencementId ) );
753 theMenu->addSeparator();
756 bool isPoly = anIsPolyline || anIsPolyline3D;
757 if (isPoly && !anIsLandCoverMap)
758 theMenu->addAction( action( ExportToShapeFileID ) );
761 QAction* aCopyAction = action( CopyId );
762 if( aCopyAction && aCopyAction->isEnabled() ) {
763 theMenu->addAction( action( CopyId ) );
764 theMenu->addSeparator();
768 if( !anIsDummyObject3D )
769 theMenu->addAction( action( DeleteId ) );
771 theMenu->addSeparator();
773 if( anIsImage || anIsPolyline || anIsPolyline3D ||
774 anIsImmersibleZone || anIsZone || anIsRegion ||
775 anIsBathymetry || anIsObstacle || anIsStream ||
776 anIsChannel || anIsDigue || anIsDummyObject3D ||
777 anIsValidProfile || anIsGroup || anIsLandCoverMap )
779 if( anIsHiddenInSelection )
780 theMenu->addAction( action( ShowId ) );
781 theMenu->addAction( action( ShowOnlyId ) );
782 if( anIsVisibleInSelection )
783 theMenu->addAction( action( HideId ) );
784 theMenu->addSeparator();
790 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
791 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
792 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
793 theMenu->addAction( action( DeleteId ) );
795 theMenu->addSeparator();
796 theMenu->addAction( action( SetZLevelId ) );
797 theMenu->addSeparator();
799 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
800 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
801 theMenu->addSeparator();
805 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
807 theMenu->addAction( action( ShowAllId ) );
808 theMenu->addAction( action( HideAllId ) );
809 theMenu->addSeparator();
812 if ( anIsOCCView || anIsVTKView )
814 theMenu->addSeparator();
815 theMenu->addAction( action( CopyViewerPositionId ) );
819 theMenu->addAction( action( EditLocalCSId ) );
821 if( anIsObjectBrowser && anOwners.size()==1 )
823 if( aSeq.Size() > 0 )
825 Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
826 Handle(HYDROData_Object) anObject;
827 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
828 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
830 if (!anAObject.IsNull())
831 anObject = anAObject;
832 if (!aNObject.IsNull())
835 if( !anObject.IsNull() )
837 theMenu->addSeparator();
838 bool IsSubmersible = anObject->IsSubmersible();
841 theMenu->addAction( action( SubmersibleId ) );
842 action( SubmersibleId )->setCheckable(true);
843 action( SubmersibleId )->setChecked(true);
847 theMenu->addAction( action( UnSubmersibleId ) );
848 action( UnSubmersibleId )->setCheckable(true);
849 action( UnSubmersibleId )->setChecked(true);
855 theMenu->addSeparator();
856 QAction* a = action( ShowHideArrows );
857 a->setText( arrowsVisible() ? tr( "HIDE_ARROWS" ) : tr( "SHOW_ARROWS" ) );
858 theMenu->addAction( a );
861 void HYDROGUI_Module::createPreferences()
863 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
864 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
866 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
867 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
869 // Set property cursor type
870 QList<QVariant> aCursorTypeIndicesList;
871 QList<QVariant> aCursorTypeIconsList;
873 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
874 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
875 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
876 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
877 aCursorTypeIndicesList << i;
878 aCursorTypeIconsList << pixmap;
881 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
882 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
884 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
885 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
886 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
888 addPreference( tr( "PREF_VIEWER_AUTOMATIC_ZOOM" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "automatic_zoom" );
890 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
891 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
892 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
893 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
894 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
895 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
896 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
898 int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
899 int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
900 LightApp_Preferences::Selector, "polyline", "arrow_type" );
902 QList<QVariant> arrow_types;
903 arrow_types.append( tr( "No" ) );
904 arrow_types.append( tr( "Triangle" ) );
905 arrow_types.append( tr( "Cone" ) );
906 setPreferenceProperty( polylineArrow, "strings", arrow_types );
908 QList<QVariant> indices;
912 setPreferenceProperty( polylineArrow, "indexes", indices );
913 setPreferenceProperty( polylineArrow, "ids", indices );
915 int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
916 LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
919 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
921 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
922 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
925 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
926 if ( resMgr && !aDoc.IsNull() )
927 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
929 else if( theSection == "polyline" )
935 resMgr->value( "polyline", "arrow_type", aType );
936 resMgr->value( "polyline", "arrow_size", aSize );
939 ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
940 for( ; it!=last; it++ )
942 int aViewerId = it.key();
943 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
945 getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
948 else if (theSection == "HYDRO" && thePref == "automatic_zoom")
950 bool anAutoZoom = resMgr->booleanValue( "HYDRO", "automatic_zoom" );
951 ViewManagerList aViewManagers = getApp()->viewManagers();
952 foreach (SUIT_ViewManager* aVMgr, aViewManagers)
956 QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
957 foreach (SUIT_ViewWindow* aView, aViews)
961 OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
964 anOCCViewFrame->setAutomaticZoom(anAutoZoom);
965 for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
967 OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
969 aV->setAutomaticZoom(anAutoZoom);
972 OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
974 anOCCViewWindow->setAutomaticZoom(true);
981 LightApp_Module::preferencesChanged( theSection, thePref );
984 QCursor HYDROGUI_Module::getPrefEditCursor() const
986 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
987 if ( aCursorType >= Qt::BlankCursor)
989 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
993 void HYDROGUI_Module::update( const int flags )
995 if ( !isUpdateEnabled() )
998 QApplication::setOverrideCursor( Qt::WaitCursor );
1000 // To prevent calling this method recursively
1001 // from one of the methods called below
1002 setUpdateEnabled( false );
1004 // store selected objects
1005 QStringList aSelectedEntries = storeSelection();
1007 bool aDoFitAll = flags & UF_FitAll;
1010 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1011 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
1014 if( ( flags & UF_Viewer ) )
1015 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
1017 if( ( flags & UF_OCCViewer ) )
1018 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
1020 if( ( flags & UF_VTKViewer ) )
1021 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
1023 if( ( flags & UF_Model ) && getDataModel() && getApp() )
1025 getDataModel()->update( getStudyId() );
1027 // Temporary workaround to prevent breaking
1028 // the selection in the object browser.
1029 // Note: processEvents() should be called after updateGV(),
1030 // otherwise the application crashes from time to time.
1031 //RKV: qApp->processEvents();
1032 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1033 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
1034 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
1035 if ( isResizeOnExpandItem && anObjectBrowser ) {
1036 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
1038 getApp()->updateObjectBrowser( true );
1039 if ( isResizeOnExpandItem && anObjectBrowser ) {
1040 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
1044 // Object browser is currently updated by using UF_Model flag
1045 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
1046 getApp()->updateObjectBrowser( true );
1048 if( ( flags & UF_Controls ) && getApp() )
1049 getApp()->updateActions();
1051 // restore selected objects
1052 restoreSelection( aSelectedEntries );
1054 setUpdateEnabled( true );
1056 QApplication::restoreOverrideCursor();
1059 void HYDROGUI_Module::updateCommandsStatus()
1061 LightApp_Module::updateCommandsStatus();
1063 updateUndoRedoControls();
1065 action( CopyId )->setEnabled( getDataModel()->canCopy() );
1066 action( PasteId )->setEnabled( getDataModel()->canPaste() );
1069 void HYDROGUI_Module::selectionChanged()
1071 LightApp_Module::selectionChanged();
1072 updateCommandsStatus();
1075 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1077 return (HYDROGUI_DataModel*)dataModel();
1080 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1085 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1087 return myOCCDisplayer;
1090 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1092 return myVTKDisplayer;
1095 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
1097 if( myViewManagerMap.contains( theId ) )
1099 return myViewManagerMap[ theId ].first;
1104 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
1106 if( myViewManagerMap.contains( theId ) )
1108 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1109 GraphicsView_ViewManager* aViewManager =
1110 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1112 return aViewManager->getViewer();
1117 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
1119 if( myViewManagerMap.contains( theId ) )
1121 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1122 OCCViewer_ViewManager* aViewManager =
1123 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1125 return aViewManager->getOCCViewer();
1130 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
1132 if( myViewManagerMap.contains( theId ) )
1134 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1135 SVTK_ViewManager* aViewManager =
1136 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1138 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1143 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1145 ViewManagerMapIterator anIter( myViewManagerMap );
1146 while( anIter.hasNext() )
1148 int anId = anIter.next().key();
1149 const ViewManagerInfo& anInfo = anIter.value();
1150 if( anInfo.first == theViewManager )
1156 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1158 int anId = getViewManagerId( theViewManager );
1161 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1162 return anInfo.second;
1167 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1168 const ViewManagerRole theRole )
1170 int anId = getViewManagerId( theViewManager );
1173 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1174 anInfo.second = theRole;
1178 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1179 const Handle(HYDROData_Entity)& theObject ) const
1181 if( theObject.IsNull() )
1187 foreach( int aViewId, myObjectStateMap.keys() )
1189 if( isObjectVisible( aViewId, theObject ) )
1195 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1196 if( anIter1 != myObjectStateMap.end() )
1198 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1199 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1201 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1202 if( anIter2 != aEntry2ObjectStateMap.end() )
1204 const ObjectState& anObjectState = anIter2.value();
1205 return anObjectState.Visibility;
1211 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1212 const Handle(HYDROData_Entity)& theObject,
1213 const bool theState )
1215 if( !theObject.IsNull() )
1217 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1218 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1220 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1221 anObjectState.Visibility = theState;
1223 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1226 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1229 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1230 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1231 if ( visState != Qtx::UnpresentableState )
1232 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1236 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1237 setLandCoversScalarMapModeOff( theViewId );
1238 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1239 getOCCDisplayer()->SetToUpdateColorScale();
1244 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1245 const bool theState )
1247 if( !theObject.IsNull() )
1249 // Process OCC shapes
1250 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1251 while( aShapesMapIter != myShapesMap.end() )
1253 const ListOfShapes& aShapesList = aShapesMapIter.value();
1254 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1256 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1258 aShape->setIsToUpdate( theState );
1263 // Process VTK shapes
1264 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1265 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1267 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1268 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1270 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1272 aShape->setIsToUpdate( theState );
1280 /////////////////// OCC SHAPES PROCESSING
1281 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1282 ObjectKind theKind ) const
1284 QList<HYDROGUI_Shape*> aResult;
1286 if ( myShapesMap.contains( theViewId ) )
1288 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1289 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1291 if( aShape && aShape->getObject()->GetKind()==theKind )
1292 aResult.append( aShape );
1298 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1299 const Handle(HYDROData_Entity)& theObject ) const
1301 HYDROGUI_Shape* aResShape = NULL;
1302 if( theObject.IsNull() )
1305 if ( myShapesMap.contains( theViewId ) )
1307 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1308 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1310 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1321 void HYDROGUI_Module::setObjectShape( const int theViewId,
1322 const Handle(HYDROData_Entity)& theObject,
1323 HYDROGUI_Shape* theShape )
1325 if( theObject.IsNull() )
1328 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1329 aViewShapes.append( theShape );
1332 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1333 const Handle(HYDROData_Entity)& theObject )
1335 if ( !myShapesMap.contains( theViewId ) )
1338 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1339 Handle(HYDROData_Entity) anObject;
1340 for ( int i = 0; i < aViewShapes.length(); )
1342 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1343 anObject = aShape->getObject();
1344 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1347 aViewShapes.removeAt( i );
1355 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1357 if ( !myShapesMap.contains( theViewId ) )
1360 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1361 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1363 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1368 myShapesMap.remove( theViewId );
1370 /////////////////// END OF OCC SHAPES PROCESSING
1372 /////////////////// VTKPrs PROCESSING
1373 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1374 const Handle(HYDROData_Entity)& theObject ) const
1376 HYDROGUI_VTKPrs* aResShape = NULL;
1377 if( theObject.IsNull() )
1380 if ( myVTKPrsMap.contains( theViewId ) )
1382 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1383 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1385 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1396 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1397 const Handle(HYDROData_Entity)& theObject,
1398 HYDROGUI_VTKPrs* theShape )
1400 if( theObject.IsNull() )
1403 if( theShape && theShape->needScalarBar() )
1405 // Compute the new global Z range from the added presentation and the old global Z range.
1406 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1407 double* aRange = theShape->getInternalZRange();
1408 bool anIsUpdate = false;
1409 if ( aRange[0] < aGlobalRange[0] )
1411 aGlobalRange[0] = aRange[0];
1414 if ( aRange[1] > aGlobalRange[1] )
1416 aGlobalRange[1] = aRange[1];
1422 updateVTKZRange( theViewId, aGlobalRange );
1426 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1427 aViewShapes.append( theShape );
1430 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1431 const QString& theEntry )
1433 if ( !myVTKPrsMap.contains( theViewId ) )
1436 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1437 Handle(HYDROData_Entity) anObject;
1439 for ( int i = 0; i < aViewShapes.length(); )
1441 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1442 anObject = aShape->getObject();
1443 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1444 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1447 aViewShapes.removeAt( i );
1454 // Invalidate global Z range
1455 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1456 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1459 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1460 const Handle(HYDROData_Entity)& theObject )
1462 if ( !myVTKPrsMap.contains( theViewId ) )
1465 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1466 Handle(HYDROData_Entity) anObject;
1467 for ( int i = 0; i < aViewShapes.length(); )
1469 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1470 anObject = aShape->getObject();
1471 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1474 aViewShapes.removeAt( i );
1481 // Invalidate global Z range
1482 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1483 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1486 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1488 if ( !myVTKPrsMap.contains( theViewId ) )
1491 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1492 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1494 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1499 myVTKPrsMap.remove( theViewId );
1502 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1504 if ( myVTKPrsMap.contains( theViewId ) )
1506 // For the given viewer id update all VTK presentations ...
1507 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1508 HYDROGUI_VTKPrs* aShape;
1509 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1511 aShape = aViewShapes.at( i );
1512 if ( aShape && aShape->needScalarBar() )
1514 aShape->setZRange( theRange );
1518 // ... and update the global color legend scalar bar.
1519 getVTKDisplayer()->SetZRange( theViewId, theRange );
1521 /////////////////// END OF VTKPrs PROCESSING
1523 void HYDROGUI_Module::clearCache()
1525 myObjectStateMap.clear();
1528 CAM_DataModel* HYDROGUI_Module::createDataModel()
1530 return new HYDROGUI_DataModel( this );
1533 void HYDROGUI_Module::customEvent( QEvent* e )
1535 int aType = e->type();
1536 if ( aType == NewViewEvent )
1538 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1539 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1541 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1543 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1544 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1546 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1548 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1549 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1551 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1552 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1553 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1555 //ouv: temporarily commented
1556 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1559 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1560 update( UF_Viewer );
1562 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1568 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1570 QEvent::Type aType = theEvent->type();
1571 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1573 if( aType == QEvent::Show )
1575 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1576 e->setData( theObj );
1577 QApplication::postEvent( this, e );
1578 theObj->removeEventFilter( this );
1581 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1583 if( aType == QEvent::Leave )
1585 SUIT_Desktop* aDesktop = getApp()->desktop();
1586 if ( aDesktop && aDesktop->statusBar() ) {
1587 aDesktop->statusBar()->clearMessage();
1591 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1593 if( aType == QEvent::Leave )
1595 SUIT_Desktop* aDesktop = getApp()->desktop();
1596 if ( aDesktop && aDesktop->statusBar() ) {
1597 aDesktop->statusBar()->clearMessage();
1602 return LightApp_Module::eventFilter( theObj, theEvent );
1605 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1607 LightApp_Module::onViewManagerAdded( theViewManager );
1609 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1611 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1612 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1614 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1616 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1617 mgr->setChainedOperations( true );//TODO: via preferences
1619 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1620 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1621 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1622 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1623 connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
1624 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1626 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1628 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1629 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1630 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1631 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1634 createSelector( theViewManager ); // replace the default selector
1636 ViewManagerInfo anInfo( theViewManager, VMR_General );
1637 myViewManagerMap.insert( ViewManagerId++, anInfo );
1640 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1642 LightApp_Module::onViewManagerRemoved( theViewManager );
1644 createSelector( theViewManager ); // replace the default selector
1646 int anId = getViewManagerId( theViewManager );
1649 OCCViewer_ViewManager* anOCCViewManager =
1650 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1651 if ( anOCCViewManager )
1653 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1654 if ( anOCCViewer ) {
1655 int aViewerId = (size_t)anOCCViewer;
1656 removeViewShapes( aViewerId );
1657 setLandCoversScalarMapModeOff( aViewerId );
1661 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1663 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1666 getVTKDisplayer()->EraseScalarBar( anId, true );
1667 removeViewShapes( (size_t)aVTKViewer );
1671 myViewManagerMap.remove( anId );
1675 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1677 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1679 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1681 aViewFrame->installEventFilter( this );
1683 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1684 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1686 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1687 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1690 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1692 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1694 aViewFrame->onTopView();
1696 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1698 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1700 aViewPort->installEventFilter( this );
1704 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1706 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1708 aViewFrame->installEventFilter( this );
1713 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1715 /* ouv: currently unused
1716 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1718 SUIT_ViewManager* aViewManager = 0;
1720 QObject* aParent = aViewPort;
1721 while( aParent = aParent->parent() )
1723 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1725 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1727 aViewManager = aViewer->getViewManager();
1736 double aMouseX = theEvent->scenePos().x();
1737 double aMouseY = theEvent->scenePos().y();
1739 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1740 if( aRole == VMR_General )
1742 int aXDeg = 0, aYDeg = 0;
1743 int aXMin = 0, aYMin = 0;
1744 double aXSec = 0, aYSec = 0;
1745 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1746 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1748 QString aDegSymbol( QChar( 0x00B0 ) );
1749 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1750 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1752 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1754 else if( aRole == VMR_TransformImage )
1755 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1760 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1761 const bool theIsInit,
1762 const bool theIsForced,
1763 const bool theDoFitAll )
1765 QList<int> aViewManagerIdList;
1767 // currently, all views are updated
1768 ViewManagerMapIterator anIter( myViewManagerMap );
1769 while( anIter.hasNext() )
1771 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1773 if ( theDisplayer->IsApplicable( aViewManager ) )
1775 int anId = anIter.key();
1776 aViewManagerIdList.append( anId );
1780 QListIterator<int> anIdIter( aViewManagerIdList );
1781 while( anIdIter.hasNext() )
1783 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1784 myOverview->setTopView();
1788 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1790 if( !theViewManager )
1793 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1794 if( !aSelectionMgr )
1797 QString aViewType = theViewManager->getType();
1798 if( aViewType != GraphicsView_Viewer::Type() &&
1799 aViewType != OCCViewer_Viewer::Type())
1802 QList<SUIT_Selector*> aSelectorList;
1803 aSelectionMgr->selectors( aViewType, aSelectorList );
1805 // disable all alien selectors
1806 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1807 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1809 SUIT_Selector* aSelector = *anIter;
1810 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1811 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1812 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1813 aSelector->setEnabled( false );
1816 if ( aViewType == GraphicsView_Viewer::Type() )
1818 GraphicsView_ViewManager* aViewManager =
1819 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1821 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1823 else if ( aViewType == OCCViewer_Viewer::Type() )
1825 OCCViewer_ViewManager* aViewManager =
1826 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1828 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1832 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1834 bool aPrevState = myIsUpdateEnabled;
1835 myIsUpdateEnabled = theState;
1839 bool HYDROGUI_Module::isUpdateEnabled() const
1841 return myIsUpdateEnabled;
1844 QStringList HYDROGUI_Module::storeSelection() const
1846 QStringList anEntryList;
1847 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1849 SUIT_DataOwnerPtrList aList( true );
1850 aSelectionMgr->selected( aList );
1852 SUIT_DataOwnerPtrList::iterator anIter;
1853 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1855 const LightApp_DataOwner* anOwner =
1856 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1858 anEntryList.append( anOwner->entry() );
1864 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1866 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1868 SUIT_DataOwnerPtrList aList( true );
1869 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1870 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1871 aSelectionMgr->setSelected( aList );
1875 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1878 bool doShow = false;
1879 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1881 aDisplayer->SaveCursorViewPosition( theViewWindow );
1882 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1886 // Show the coordinates in the status bar
1887 SUIT_Desktop* aDesktop = getApp()->desktop();
1888 if ( aDesktop && aDesktop->statusBar() )
1890 gp_Pnt aWPnt( X, Y, Z );
1891 int aStudyId = application()->activeStudy()->id();
1892 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1893 double WX = aWPnt.X(), WY = aWPnt.Y();
1895 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1896 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1897 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1898 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1899 QString aMsg = tr( "COORDINATES_INFO" );
1900 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1901 aDesktop->statusBar()->showMessage( aMsg );
1907 * Returns stack of active operations;
1909 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1911 return myActiveOperationMap;
1915 * Returns the module active operation. If the active operation is show/hide,
1916 * the method returns the previous operation if it is.
1918 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1920 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1922 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1924 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1926 aVIt.previous(); // skip the top show/hide operation
1927 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1934 * \brief Virtual public slot
1936 * This method is called after the object inserted into data view to update their visibility state
1937 * This is default implementation
1939 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1941 if ( !isActiveModule() )
1944 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1946 // change visibility of object
1947 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1950 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1952 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1953 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1954 if ( visState == Qtx::UnpresentableState )
1957 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1958 treeModel->setVisibilityState( id, visState );
1960 bool vis = visState == Qtx::ShownState;
1961 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1964 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1966 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1969 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1971 Handle(HYDROData_StricklerTable) aTable;
1973 if ( myLandCoverColoringMap.contains( theViewId ) ) {
1974 aTable = myLandCoverColoringMap.value( theViewId );
1980 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1981 const Handle(HYDROData_StricklerTable)& theTable )
1983 if ( !theTable.IsNull() ) {
1984 myLandCoverColoringMap.insert( theViewId, theTable );
1988 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
1990 myLandCoverColoringMap.remove( theViewId );
1993 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
1995 return myLandCoverColoringMap.contains( theViewId );
1998 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
2000 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
2004 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
2005 Handle(HYDROData_StricklerTable) aTable =
2006 Handle(HYDROData_StricklerTable)::DownCast( theObject );
2007 QList<int> aViewIds;
2008 QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
2009 while ( anIter.hasNext() ) {
2010 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
2011 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
2018 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
2023 SUIT_ViewWindow* wnd = theMgr->getActiveView();
2024 OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
2028 myOverview->setMainView( occwnd );