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 ( 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 OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
226 occ_mgr->setChainedOperations( true );//TODO: via preferences
229 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() )
231 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
232 if ( aViewFrame && aViewFrame->getViewPort() )
234 aViewFrame->getViewPort()->installEventFilter( this );
240 SalomeApp_Study* aStudy =
241 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
243 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
244 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
245 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
246 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
247 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
248 if( !GEOM_var->_is_nil() ) {
249 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
254 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
255 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
256 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
261 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
264 ViewManagerMapIterator anIter( myViewManagerMap );
265 while( anIter.hasNext() )
266 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
267 getApp()->removeViewManager( aViewManager );
268 myViewManagerMap.clear();
271 ViewManagerList anOCCViewManagers;
272 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
273 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
274 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
275 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
279 myObjectStateMap.clear();
284 // clear the status bar
285 SUIT_Desktop* aDesktop = getApp()->desktop();
286 if ( aDesktop && aDesktop->statusBar() ) {
287 aDesktop->statusBar()->clearMessage();
290 // clear the data model's list of copying objects
291 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
293 setMenuShown( false );
294 setToolShown( false );
296 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
298 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
300 myActiveOperationMap.clear();
302 myViewManagerMap.clear();
304 return LightApp_Module::deactivateModule( theStudy );
307 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
309 static bool inWindows = false;
314 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
315 #ifndef DISABLE_PYCONSOLE
316 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
318 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
319 theMap.insert( OverviewWindow, Qt::LeftDockWidgetArea );
322 LightApp_Application* app = getApp();
323 if( app && app->getWindow( OverviewWindow )==0 )
325 const_cast<HYDROGUI_Module*>( this )->myOverview =
326 new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() );
327 app->insertDockWindow( OverviewWindow, myOverview );
328 app->placeDockWindow( OverviewWindow, Qt::LeftDockWidgetArea );
333 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
335 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
338 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
342 HYDROGUI_DataModel* aModel = getDataModel();
344 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
345 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
346 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
347 bool anIsVTKView = theClient == SVTK_Viewer::Type();
348 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
351 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
353 bool anIsSelectedDataObjects = false;
354 bool anIsVisibleInSelection = false;
355 bool anIsHiddenInSelection = false;
357 bool anIsImage = false;
358 bool anIsImportedImage = false;
359 bool anIsImageHasRefs = false;
360 bool anIsFusedImage = false;
361 bool anIsCutImage = false;
362 bool anIsSplitImage = false;
363 bool anIsMustObjectBeUpdated = false;
364 bool anIsPolyline = false;
365 bool anIsPolyline3D = false;
366 bool anIsProfile = false;
367 bool anIsValidProfile = false;
368 bool anAllAreProfiles = false;
369 bool anIsBathymetry = false;
370 bool anIsCalculation = false;
371 bool anIsImmersibleZone = false;
372 bool anIsVisualState = false;
373 bool anIsRegion = false;
374 bool anIsZone = false;
375 bool anIsObstacle = false;
376 bool anIsStricklerTable = false;
377 bool anIsLandCoverMap = false;
378 bool anIsStream = false;
379 bool anIsChannel = false;
380 bool anIsDigue = false;
381 bool anIsDummyObject3D = false;
382 bool anIsGroup = false;
383 bool anIsObjectCanBeColored = false;
385 bool isStreamHasBottom = false;
387 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
388 SUIT_DataOwnerPtrList anOwners;
389 aSelectionMgr->selected( anOwners );
390 if( anIsObjectBrowser && anOwners.size()==1 )
392 QString anEntry = anOwners[0]->keyString();
393 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
395 isRoot = aStudy->isComponent( anEntry );
398 // Check the selected GEOM objects (take into account the Object Browser only)
399 if ( anIsObjectBrowser ) {
400 QList<GEOM::shape_type> anObstacleTypes =
401 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
402 QList<GEOM::shape_type> aPolylineTypes =
403 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
405 bool isCanBeImportedAsObstacle =
406 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
407 bool isCanBeImportedAsPolyline =
408 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
410 // Add import as obstacle action
411 if ( isCanBeImportedAsObstacle ) {
412 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
414 // Add import as polyline action
415 if ( isCanBeImportedAsPolyline ) {
416 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
419 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
420 theMenu->addSeparator();
424 // check the selected data model objects
425 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
426 int aNbOfSelectedProfiles = 0;
427 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
429 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
430 if( !anObject.IsNull() )
432 anIsSelectedDataObjects = true;
434 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
435 anIsVisibleInSelection |= aVisibility;
436 anIsHiddenInSelection |= !aVisibility;
438 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
440 anIsMustObjectBeUpdated = true;
443 ObjectKind anObjectKind = anObject->GetKind();
444 if( anObjectKind == KIND_IMAGE )
447 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
448 if( !anImage.IsNull() )
450 anIsImportedImage = anImage->HasLocalPoints();
451 anIsImageHasRefs = anImage->HasReferences();
452 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
454 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
456 QString anOperatorName = anOperator->name();
457 if( anOperatorName == ImageComposer_FuseOperator::Type() )
458 anIsFusedImage = true;
459 else if( anOperatorName == ImageComposer_CutOperator::Type() )
461 else if( anOperatorName == ImageComposer_CropOperator::Type() )
462 anIsSplitImage = true;
467 else if( anObjectKind == KIND_POLYLINEXY )
469 else if( anObjectKind == KIND_POLYLINE )
470 anIsPolyline3D = true;
471 else if( anObjectKind == KIND_PROFILE )
474 aNbOfSelectedProfiles++;
476 Handle(HYDROData_Profile) aProfile =
477 Handle(HYDROData_Profile)::DownCast( anObject );
478 if( !aProfile.IsNull() && aProfile->IsValid() ) {
479 anIsValidProfile = true;
482 else if( anObjectKind == KIND_CALCULATION )
483 anIsCalculation = true;
484 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
485 anIsImmersibleZone = true;
486 else if( anObjectKind == KIND_VISUAL_STATE )
487 anIsVisualState = true;
488 else if( anObjectKind == KIND_REGION )
490 else if( anObjectKind == KIND_ZONE )
492 else if( anObjectKind == KIND_BATHYMETRY )
493 anIsBathymetry = true;
494 else if( anObjectKind == KIND_OBSTACLE )
496 else if( anObjectKind == KIND_STRICKLER_TABLE )
497 anIsStricklerTable = true;
498 else if( anObjectKind == KIND_LAND_COVER_MAP )
499 anIsLandCoverMap = true;
500 else if( anObjectKind == KIND_STREAM )
503 Handle(HYDROData_Stream) aStream =
504 Handle(HYDROData_Stream)::DownCast( anObject );
505 if ( !aStream.IsNull() )
506 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
508 else if( anObjectKind == KIND_CHANNEL )
510 else if( anObjectKind == KIND_DIGUE )
512 else if( anObjectKind == KIND_DUMMY_3D )
513 anIsDummyObject3D = true;
514 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLIT_GROUP )
518 if ( !anIsObjectCanBeColored )
519 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
522 // Check if all selected objects are profiles
523 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
524 ( aNbOfSelectedProfiles == aSeq.Length() );
526 // check the selected partitions
527 if( !anIsSelectedDataObjects && anIsObjectBrowser )
529 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
530 if( aSelectedPartition != KIND_UNKNOWN )
532 switch( aSelectedPartition )
535 theMenu->addAction( action( ImportImageId ) );
537 case KIND_BATHYMETRY:
538 theMenu->addAction( action( ImportBathymetryId ) );
540 case KIND_ARTIFICIAL_OBJECT:
541 theMenu->addAction( action( CreateChannelId ) );
542 theMenu->addAction( action( CreateDigueId ) );
544 case KIND_NATURAL_OBJECT:
545 theMenu->addAction( action( CreateImmersibleZoneId ) );
546 theMenu->addAction( action( CreateStreamId ) );
549 theMenu->addAction( action( ImportObstacleFromFileId ) );
550 theMenu->addAction( action( CreateBoxId ) );
551 theMenu->addAction( action( CreateCylinderId ) );
553 case KIND_STRICKLER_TABLE:
554 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
556 case KIND_LAND_COVER_MAP:
557 theMenu->addAction( action( CreateLandCoverMapId ) );
558 theMenu->addAction( action( ImportLandCoverMapId ) );
560 case KIND_CALCULATION:
561 theMenu->addAction( action( CreateCalculationId ) );
563 case KIND_POLYLINEXY:
564 theMenu->addAction( action( ImportPolylineId ) );
565 theMenu->addAction( action( CreatePolylineId ) );
568 theMenu->addAction( action( CreatePolyline3DId ) );
571 theMenu->addAction( action( CreateProfileId ) );
572 theMenu->addAction( action( ImportProfilesId ) );
573 theMenu->addAction( action( AllGeoreferencementId ) );
575 case KIND_VISUAL_STATE:
576 theMenu->addAction( action( SaveVisualStateId ) );
579 theMenu->addSeparator();
583 Handle(HYDROData_CalculationCase) aCalcCase;
585 HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
586 if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
587 theMenu->addAction( action( RegenerateRegionColorsId ) );
591 if( anIsSelectedDataObjects )
593 if ( anIsMustObjectBeUpdated )
595 theMenu->addAction( action( UpdateObjectId ) );
596 theMenu->addSeparator();
600 theMenu->addAction( action( ForcedUpdateObjectId ) );
601 theMenu->addSeparator();
605 if( aSeq.Length() == 1 )
609 if( anIsImportedImage )
610 theMenu->addAction( action( EditImportedImageId ) );
611 else if( anIsImageHasRefs )
614 theMenu->addAction( action( EditFusedImageId ) );
615 else if( anIsCutImage )
616 theMenu->addAction( action( EditCutImageId ) );
617 else if( anIsSplitImage )
618 theMenu->addAction( action( EditSplitImageId ) );
621 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
622 theMenu->addAction( action( ExportImageId ) );
623 theMenu->addSeparator();
625 if( anIsImageHasRefs )
627 theMenu->addAction( action( RemoveImageRefsId ) );
628 theMenu->addSeparator();
631 theMenu->addAction( action( FuseImagesId ) );
632 theMenu->addAction( action( CutImagesId ) );
633 theMenu->addAction( action( SplitImageId ) );
634 theMenu->addSeparator();
635 theMenu->addAction( action( RecognizeContoursId ) );
636 theMenu->addSeparator();
638 else if( anIsBathymetry )
640 theMenu->addAction( action( EditImportedBathymetryId ) );
641 theMenu->addAction( action( BathymetryBoundsId ) );
642 theMenu->addSeparator();
644 else if( anIsPolyline )
646 theMenu->addAction( action( EditPolylineId ) );
647 theMenu->addSeparator();
648 theMenu->addAction( action( SplitPolylinesId ) );
649 theMenu->addAction( action( MergePolylinesId ) );
650 theMenu->addSeparator();
652 else if( anIsPolyline3D )
654 theMenu->addAction( action( EditPolyline3DId ) );
655 theMenu->addSeparator();
657 else if( anIsProfile )
659 theMenu->addAction( action( EditProfileId ) );
660 theMenu->addAction( action( SelectedGeoreferencementId ) );
661 theMenu->addSeparator();
663 else if( anIsCalculation )
665 theMenu->addAction( action( EditCalculationId ) );
666 theMenu->addAction( action( ExportCalculationId ) );
667 theMenu->addSeparator();
669 else if( anIsImmersibleZone )
671 theMenu->addAction( action( EditImmersibleZoneId ) );
672 theMenu->addSeparator();
674 else if( anIsStream )
676 theMenu->addAction( action( EditStreamId ) );
677 if ( action( RiverBottomContextId ) )
679 theMenu->addAction( action( RiverBottomContextId ) );
680 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
682 theMenu->addAction( action( ProfileInterpolateId ) );
683 theMenu->addSeparator();
685 else if( anIsChannel )
687 theMenu->addAction( action( EditChannelId ) );
688 theMenu->addSeparator();
692 theMenu->addAction( action( EditDigueId ) );
693 theMenu->addSeparator();
695 else if( anIsObstacle )
697 theMenu->addAction( action( TranslateObstacleId ) );
698 theMenu->addSeparator();
700 else if( anIsStricklerTable )
702 theMenu->addAction( action( EditStricklerTableId ) );
703 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
704 theMenu->addAction( action( DuplicateStricklerTableId ) );
705 theMenu->addSeparator();
707 Handle(HYDROData_StricklerTable) aTable =
708 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
709 QString aCurrentTable =
710 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
711 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
713 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
714 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
715 theMenu->addSeparator();
718 else if( anIsLandCoverMap )
720 theMenu->addAction( action( AddLandCoverId ) );
721 theMenu->addAction( action( RemoveLandCoverId ) );
722 theMenu->addSeparator();
723 theMenu->addAction( action( SplitLandCoverId ) );
724 theMenu->addAction( action( MergeLandCoverId ) );
725 theMenu->addAction( action( ChangeLandCoverTypeId ) );
726 theMenu->addSeparator();
728 theMenu->addAction( action( ExportToShapeFileID ) );
729 theMenu->addSeparator();
731 else if( anIsVisualState && anIsObjectBrowser )
733 theMenu->addAction( action( SaveVisualStateId ) );
734 theMenu->addAction( action( LoadVisualStateId ) );
735 theMenu->addSeparator();
738 theMenu->addAction( action( ZoneSetColorId ) );
740 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
742 theMenu->addAction( action( PolylineExtractionId ) );
743 theMenu->addSeparator();
746 // Add set color action for geometrical objects
747 if ( anIsObjectCanBeColored )
749 theMenu->addAction( action( SetColorId ) );
750 theMenu->addSeparator();
753 // Add transparency action for land cover map objects
754 if ( anIsLandCoverMap )
756 theMenu->addAction( action( SetTransparencyId ) );
757 theMenu->addSeparator();
760 else if ( anAllAreProfiles )
762 theMenu->addAction( action( EditProfileId ) );
763 theMenu->addAction( action( SelectedGeoreferencementId ) );
764 theMenu->addSeparator();
767 bool isPoly = anIsPolyline || anIsPolyline3D;
768 if (isPoly && !anIsLandCoverMap)
769 theMenu->addAction( action( ExportToShapeFileID ) );
772 QAction* aCopyAction = action( CopyId );
773 if( aCopyAction && aCopyAction->isEnabled() ) {
774 theMenu->addAction( action( CopyId ) );
775 theMenu->addSeparator();
779 if( !anIsDummyObject3D )
780 theMenu->addAction( action( DeleteId ) );
782 theMenu->addSeparator();
784 if( anIsImage || anIsPolyline || anIsPolyline3D ||
785 anIsImmersibleZone || anIsZone || anIsRegion ||
786 anIsBathymetry || anIsObstacle || anIsStream ||
787 anIsChannel || anIsDigue || anIsDummyObject3D ||
788 anIsValidProfile || anIsGroup || anIsLandCoverMap )
790 if( anIsHiddenInSelection )
791 theMenu->addAction( action( ShowId ) );
792 theMenu->addAction( action( ShowOnlyId ) );
793 if( anIsVisibleInSelection )
794 theMenu->addAction( action( HideId ) );
795 theMenu->addSeparator();
801 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
802 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
803 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
804 theMenu->addAction( action( DeleteId ) );
806 theMenu->addSeparator();
807 theMenu->addAction( action( SetZLevelId ) );
808 theMenu->addSeparator();
810 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
811 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
812 theMenu->addSeparator();
816 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
818 theMenu->addAction( action( ShowAllId ) );
819 theMenu->addAction( action( HideAllId ) );
820 theMenu->addSeparator();
823 if ( anIsOCCView || anIsVTKView )
825 theMenu->addSeparator();
826 theMenu->addAction( action( CopyViewerPositionId ) );
830 theMenu->addAction( action( EditLocalCSId ) );
832 if( anIsObjectBrowser && anOwners.size()==1 )
834 if( aSeq.Size() > 0 )
836 Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
837 Handle(HYDROData_Object) anObject;
838 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
839 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
841 if (!anAObject.IsNull())
842 anObject = anAObject;
843 if (!aNObject.IsNull())
846 if( !anObject.IsNull() )
848 theMenu->addSeparator();
849 bool IsSubmersible = anObject->IsSubmersible();
852 theMenu->addAction( action( SubmersibleId ) );
853 action( SubmersibleId )->setCheckable(true);
854 action( SubmersibleId )->setChecked(true);
858 theMenu->addAction( action( UnSubmersibleId ) );
859 action( UnSubmersibleId )->setCheckable(true);
860 action( UnSubmersibleId )->setChecked(true);
866 theMenu->addSeparator();
867 QAction* a = action( ShowHideArrows );
868 a->setText( arrowsVisible() ? tr( "HIDE_ARROWS" ) : tr( "SHOW_ARROWS" ) );
869 theMenu->addAction( a );
872 void HYDROGUI_Module::createPreferences()
874 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
875 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
877 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
878 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
880 // Set property cursor type
881 QList<QVariant> aCursorTypeIndicesList;
882 QList<QVariant> aCursorTypeIconsList;
884 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
885 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
886 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
887 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
888 aCursorTypeIndicesList << i;
889 aCursorTypeIconsList << pixmap;
892 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
893 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
895 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
896 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
897 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
899 addPreference( tr( "PREF_VIEWER_AUTOMATIC_ZOOM" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "automatic_zoom" );
901 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
902 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
903 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
904 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
905 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
906 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
907 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
909 int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
910 int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
911 LightApp_Preferences::Selector, "polyline", "arrow_type" );
913 QList<QVariant> arrow_types;
914 arrow_types.append( tr( "No" ) );
915 arrow_types.append( tr( "Triangle" ) );
916 arrow_types.append( tr( "Cone" ) );
917 setPreferenceProperty( polylineArrow, "strings", arrow_types );
919 QList<QVariant> indices;
923 setPreferenceProperty( polylineArrow, "indexes", indices );
924 setPreferenceProperty( polylineArrow, "ids", indices );
926 int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
927 LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
930 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
932 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
933 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
936 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
937 if ( resMgr && !aDoc.IsNull() )
938 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
940 else if( theSection == "polyline" )
946 resMgr->value( "polyline", "arrow_type", aType );
947 resMgr->value( "polyline", "arrow_size", aSize );
950 ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
951 for( ; it!=last; it++ )
953 int aViewerId = it.key();
954 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
956 getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
959 else if (theSection == "HYDRO" && thePref == "automatic_zoom")
961 bool anAutoZoom = resMgr->booleanValue( "HYDRO", "automatic_zoom" );
962 ViewManagerList aViewManagers = getApp()->viewManagers();
963 foreach (SUIT_ViewManager* aVMgr, aViewManagers)
967 QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
968 foreach (SUIT_ViewWindow* aView, aViews)
972 OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
975 anOCCViewFrame->setAutomaticZoom(anAutoZoom);
976 for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
978 OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
980 aV->setAutomaticZoom(anAutoZoom);
983 OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
985 anOCCViewWindow->setAutomaticZoom(true);
992 LightApp_Module::preferencesChanged( theSection, thePref );
995 QCursor HYDROGUI_Module::getPrefEditCursor() const
997 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
998 if ( aCursorType >= Qt::BlankCursor)
1000 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
1004 void HYDROGUI_Module::update( const int flags )
1006 if ( !isUpdateEnabled() )
1009 QApplication::setOverrideCursor( Qt::WaitCursor );
1011 // To prevent calling this method recursively
1012 // from one of the methods called below
1013 setUpdateEnabled( false );
1015 // store selected objects
1016 QStringList aSelectedEntries = storeSelection();
1018 bool aDoFitAll = flags & UF_FitAll;
1021 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1022 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
1025 if( ( flags & UF_Viewer ) )
1026 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
1028 if( ( flags & UF_OCCViewer ) )
1029 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
1031 if( ( flags & UF_VTKViewer ) )
1032 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
1034 if( ( flags & UF_Model ) && getDataModel() && getApp() )
1036 getDataModel()->update( getStudyId() );
1038 // Temporary workaround to prevent breaking
1039 // the selection in the object browser.
1040 // Note: processEvents() should be called after updateGV(),
1041 // otherwise the application crashes from time to time.
1042 //RKV: qApp->processEvents();
1043 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1044 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
1045 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
1046 if ( isResizeOnExpandItem && anObjectBrowser ) {
1047 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
1049 getApp()->updateObjectBrowser( true );
1050 if ( isResizeOnExpandItem && anObjectBrowser ) {
1051 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
1055 // Object browser is currently updated by using UF_Model flag
1056 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
1057 getApp()->updateObjectBrowser( true );
1059 if( ( flags & UF_Controls ) && getApp() )
1060 getApp()->updateActions();
1062 // restore selected objects
1063 restoreSelection( aSelectedEntries );
1065 setUpdateEnabled( true );
1067 QApplication::restoreOverrideCursor();
1070 void HYDROGUI_Module::updateCommandsStatus()
1072 LightApp_Module::updateCommandsStatus();
1074 updateUndoRedoControls();
1076 action( CopyId )->setEnabled( getDataModel()->canCopy() );
1077 action( PasteId )->setEnabled( getDataModel()->canPaste() );
1080 void HYDROGUI_Module::selectionChanged()
1082 LightApp_Module::selectionChanged();
1083 updateCommandsStatus();
1086 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1088 return (HYDROGUI_DataModel*)dataModel();
1091 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1096 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1098 return myOCCDisplayer;
1101 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1103 return myVTKDisplayer;
1106 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
1108 if( myViewManagerMap.contains( theId ) )
1110 return myViewManagerMap[ theId ].first;
1115 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
1117 if( myViewManagerMap.contains( theId ) )
1119 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1120 GraphicsView_ViewManager* aViewManager =
1121 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1123 return aViewManager->getViewer();
1128 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
1130 if( myViewManagerMap.contains( theId ) )
1132 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1133 OCCViewer_ViewManager* aViewManager =
1134 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1136 return aViewManager->getOCCViewer();
1141 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
1143 if( myViewManagerMap.contains( theId ) )
1145 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1146 SVTK_ViewManager* aViewManager =
1147 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1149 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1154 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1156 ViewManagerMapIterator anIter( myViewManagerMap );
1157 while( anIter.hasNext() )
1159 int anId = anIter.next().key();
1160 const ViewManagerInfo& anInfo = anIter.value();
1161 if( anInfo.first == theViewManager )
1167 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1169 int anId = getViewManagerId( theViewManager );
1172 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1173 return anInfo.second;
1178 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1179 const ViewManagerRole theRole )
1181 int anId = getViewManagerId( theViewManager );
1184 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1185 anInfo.second = theRole;
1189 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1190 const Handle(HYDROData_Entity)& theObject ) const
1192 if( theObject.IsNull() )
1198 foreach( int aViewId, myObjectStateMap.keys() )
1200 if( isObjectVisible( aViewId, theObject ) )
1206 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1207 if( anIter1 != myObjectStateMap.end() )
1209 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1210 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1212 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1213 if( anIter2 != aEntry2ObjectStateMap.end() )
1215 const ObjectState& anObjectState = anIter2.value();
1216 return anObjectState.Visibility;
1222 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1223 const Handle(HYDROData_Entity)& theObject,
1224 const bool theState )
1226 if( !theObject.IsNull() )
1228 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1229 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1231 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1232 anObjectState.Visibility = theState;
1234 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1237 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1240 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1241 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1242 if ( visState != Qtx::UnpresentableState )
1243 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1247 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1248 setLandCoversScalarMapModeOff( theViewId );
1249 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1250 getOCCDisplayer()->SetToUpdateColorScale();
1255 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1256 const bool theState )
1258 if( !theObject.IsNull() )
1260 // Process OCC shapes
1261 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1262 while( aShapesMapIter != myShapesMap.end() )
1264 const ListOfShapes& aShapesList = aShapesMapIter.value();
1265 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1267 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1269 aShape->setIsToUpdate( theState );
1274 // Process VTK shapes
1275 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1276 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1278 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1279 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1281 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1283 aShape->setIsToUpdate( theState );
1291 /////////////////// OCC SHAPES PROCESSING
1292 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1293 ObjectKind theKind ) const
1295 QList<HYDROGUI_Shape*> aResult;
1297 if ( myShapesMap.contains( theViewId ) )
1299 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1300 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1302 if( aShape && aShape->getObject()->GetKind()==theKind )
1303 aResult.append( aShape );
1309 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1310 const Handle(HYDROData_Entity)& theObject ) const
1312 HYDROGUI_Shape* aResShape = NULL;
1313 if( theObject.IsNull() )
1316 if ( myShapesMap.contains( theViewId ) )
1318 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1319 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1321 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1332 void HYDROGUI_Module::setObjectShape( const int theViewId,
1333 const Handle(HYDROData_Entity)& theObject,
1334 HYDROGUI_Shape* theShape )
1336 if( theObject.IsNull() )
1339 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1340 aViewShapes.append( theShape );
1343 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1344 const Handle(HYDROData_Entity)& theObject )
1346 if ( !myShapesMap.contains( theViewId ) )
1349 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1350 Handle(HYDROData_Entity) anObject;
1351 for ( int i = 0; i < aViewShapes.length(); )
1353 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1354 anObject = aShape->getObject();
1355 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1358 aViewShapes.removeAt( i );
1366 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1368 if ( !myShapesMap.contains( theViewId ) )
1371 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1372 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1374 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1379 myShapesMap.remove( theViewId );
1381 /////////////////// END OF OCC SHAPES PROCESSING
1383 /////////////////// VTKPrs PROCESSING
1384 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1385 const Handle(HYDROData_Entity)& theObject ) const
1387 HYDROGUI_VTKPrs* aResShape = NULL;
1388 if( theObject.IsNull() )
1391 if ( myVTKPrsMap.contains( theViewId ) )
1393 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1394 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1396 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1407 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1408 const Handle(HYDROData_Entity)& theObject,
1409 HYDROGUI_VTKPrs* theShape )
1411 if( theObject.IsNull() )
1414 if( theShape && theShape->needScalarBar() )
1416 // Compute the new global Z range from the added presentation and the old global Z range.
1417 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1418 double* aRange = theShape->getInternalZRange();
1419 bool anIsUpdate = false;
1420 if ( aRange[0] < aGlobalRange[0] )
1422 aGlobalRange[0] = aRange[0];
1425 if ( aRange[1] > aGlobalRange[1] )
1427 aGlobalRange[1] = aRange[1];
1433 updateVTKZRange( theViewId, aGlobalRange );
1437 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1438 aViewShapes.append( theShape );
1441 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1442 const QString& theEntry )
1444 if ( !myVTKPrsMap.contains( theViewId ) )
1447 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1448 Handle(HYDROData_Entity) anObject;
1450 for ( int i = 0; i < aViewShapes.length(); )
1452 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1453 anObject = aShape->getObject();
1454 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1455 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1458 aViewShapes.removeAt( i );
1465 // Invalidate global Z range
1466 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1467 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1470 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1471 const Handle(HYDROData_Entity)& theObject )
1473 if ( !myVTKPrsMap.contains( theViewId ) )
1476 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1477 Handle(HYDROData_Entity) anObject;
1478 for ( int i = 0; i < aViewShapes.length(); )
1480 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1481 anObject = aShape->getObject();
1482 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1485 aViewShapes.removeAt( i );
1492 // Invalidate global Z range
1493 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1494 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1497 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1499 if ( !myVTKPrsMap.contains( theViewId ) )
1502 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1503 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1505 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1510 myVTKPrsMap.remove( theViewId );
1513 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1515 if ( myVTKPrsMap.contains( theViewId ) )
1517 // For the given viewer id update all VTK presentations ...
1518 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1519 HYDROGUI_VTKPrs* aShape;
1520 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1522 aShape = aViewShapes.at( i );
1523 if ( aShape && aShape->needScalarBar() )
1525 aShape->setZRange( theRange );
1529 // ... and update the global color legend scalar bar.
1530 getVTKDisplayer()->SetZRange( theViewId, theRange );
1532 /////////////////// END OF VTKPrs PROCESSING
1534 void HYDROGUI_Module::clearCache()
1536 myObjectStateMap.clear();
1539 CAM_DataModel* HYDROGUI_Module::createDataModel()
1541 return new HYDROGUI_DataModel( this );
1544 void HYDROGUI_Module::customEvent( QEvent* e )
1546 int aType = e->type();
1547 if ( aType == NewViewEvent )
1549 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1550 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1552 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1554 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1555 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1557 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1559 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1560 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1562 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1563 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1564 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1566 //ouv: temporarily commented
1567 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1570 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1571 update( UF_Viewer );
1573 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1579 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1581 QEvent::Type aType = theEvent->type();
1582 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1584 if( aType == QEvent::Show )
1586 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1587 e->setData( theObj );
1588 QApplication::postEvent( this, e );
1589 theObj->removeEventFilter( this );
1592 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1594 if( aType == QEvent::Leave )
1596 SUIT_Desktop* aDesktop = getApp()->desktop();
1597 if ( aDesktop && aDesktop->statusBar() ) {
1598 aDesktop->statusBar()->clearMessage();
1602 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1604 if( aType == QEvent::Leave )
1606 SUIT_Desktop* aDesktop = getApp()->desktop();
1607 if ( aDesktop && aDesktop->statusBar() ) {
1608 aDesktop->statusBar()->clearMessage();
1613 return LightApp_Module::eventFilter( theObj, theEvent );
1616 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1618 LightApp_Module::onViewManagerAdded( theViewManager );
1620 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1622 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1623 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1625 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1627 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1628 mgr->setChainedOperations( true );//TODO: via preferences
1630 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1631 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1632 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1633 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1634 connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
1635 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1637 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1639 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1640 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1641 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1642 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1645 createSelector( theViewManager ); // replace the default selector
1647 ViewManagerInfo anInfo( theViewManager, VMR_General );
1648 myViewManagerMap.insert( ViewManagerId++, anInfo );
1651 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1653 LightApp_Module::onViewManagerRemoved( theViewManager );
1655 createSelector( theViewManager ); // replace the default selector
1657 int anId = getViewManagerId( theViewManager );
1660 OCCViewer_ViewManager* anOCCViewManager =
1661 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1662 if ( anOCCViewManager )
1664 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1665 if ( anOCCViewer ) {
1666 int aViewerId = (size_t)anOCCViewer;
1667 removeViewShapes( aViewerId );
1668 setLandCoversScalarMapModeOff( aViewerId );
1672 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1674 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1677 getVTKDisplayer()->EraseScalarBar( anId, true );
1678 removeViewShapes( (size_t)aVTKViewer );
1682 myViewManagerMap.remove( anId );
1686 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1688 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1690 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1692 aViewFrame->installEventFilter( this );
1694 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1695 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1697 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1698 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1701 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1703 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1705 aViewFrame->onTopView();
1707 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1709 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1711 aViewPort->installEventFilter( this );
1715 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1717 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1719 aViewFrame->installEventFilter( this );
1724 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1726 /* ouv: currently unused
1727 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1729 SUIT_ViewManager* aViewManager = 0;
1731 QObject* aParent = aViewPort;
1732 while( aParent = aParent->parent() )
1734 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1736 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1738 aViewManager = aViewer->getViewManager();
1747 double aMouseX = theEvent->scenePos().x();
1748 double aMouseY = theEvent->scenePos().y();
1750 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1751 if( aRole == VMR_General )
1753 int aXDeg = 0, aYDeg = 0;
1754 int aXMin = 0, aYMin = 0;
1755 double aXSec = 0, aYSec = 0;
1756 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1757 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1759 QString aDegSymbol( QChar( 0x00B0 ) );
1760 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1761 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1763 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1765 else if( aRole == VMR_TransformImage )
1766 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1771 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1772 const bool theIsInit,
1773 const bool theIsForced,
1774 const bool theDoFitAll )
1776 QList<int> aViewManagerIdList;
1778 // currently, all views are updated
1779 ViewManagerMapIterator anIter( myViewManagerMap );
1780 while( anIter.hasNext() )
1782 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1784 if ( theDisplayer->IsApplicable( aViewManager ) )
1786 int anId = anIter.key();
1787 aViewManagerIdList.append( anId );
1791 QListIterator<int> anIdIter( aViewManagerIdList );
1792 while( anIdIter.hasNext() )
1794 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1795 myOverview->setTopView();
1799 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1801 if( !theViewManager )
1804 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1805 if( !aSelectionMgr )
1808 QString aViewType = theViewManager->getType();
1809 if( aViewType != GraphicsView_Viewer::Type() &&
1810 aViewType != OCCViewer_Viewer::Type())
1813 QList<SUIT_Selector*> aSelectorList;
1814 aSelectionMgr->selectors( aViewType, aSelectorList );
1816 // disable all alien selectors
1817 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1818 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1820 SUIT_Selector* aSelector = *anIter;
1821 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1822 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1823 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1824 aSelector->setEnabled( false );
1827 if ( aViewType == GraphicsView_Viewer::Type() )
1829 GraphicsView_ViewManager* aViewManager =
1830 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1832 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1834 else if ( aViewType == OCCViewer_Viewer::Type() )
1836 OCCViewer_ViewManager* aViewManager =
1837 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1839 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1843 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1845 bool aPrevState = myIsUpdateEnabled;
1846 myIsUpdateEnabled = theState;
1850 bool HYDROGUI_Module::isUpdateEnabled() const
1852 return myIsUpdateEnabled;
1855 QStringList HYDROGUI_Module::storeSelection() const
1857 QStringList anEntryList;
1858 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1860 SUIT_DataOwnerPtrList aList( true );
1861 aSelectionMgr->selected( aList );
1863 SUIT_DataOwnerPtrList::iterator anIter;
1864 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1866 const LightApp_DataOwner* anOwner =
1867 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1869 anEntryList.append( anOwner->entry() );
1875 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1877 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1879 SUIT_DataOwnerPtrList aList( true );
1880 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1881 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1882 aSelectionMgr->setSelected( aList );
1886 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1889 bool doShow = false;
1890 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1892 aDisplayer->SaveCursorViewPosition( theViewWindow );
1893 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1897 // Show the coordinates in the status bar
1898 SUIT_Desktop* aDesktop = getApp()->desktop();
1899 if ( aDesktop && aDesktop->statusBar() )
1901 gp_Pnt aWPnt( X, Y, Z );
1902 int aStudyId = application()->activeStudy()->id();
1903 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1904 double WX = aWPnt.X(), WY = aWPnt.Y();
1906 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1907 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1908 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1909 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1910 QString aMsg = tr( "COORDINATES_INFO" );
1911 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1912 aDesktop->statusBar()->showMessage( aMsg );
1918 * Returns stack of active operations;
1920 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1922 return myActiveOperationMap;
1926 * Returns the module active operation. If the active operation is show/hide,
1927 * the method returns the previous operation if it is.
1929 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1931 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1933 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1935 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1937 aVIt.previous(); // skip the top show/hide operation
1938 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1945 * \brief Virtual public slot
1947 * This method is called after the object inserted into data view to update their visibility state
1948 * This is default implementation
1950 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1952 if ( !isActiveModule() )
1955 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1957 // change visibility of object
1958 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1961 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1963 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1964 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1965 if ( visState == Qtx::UnpresentableState )
1968 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1969 treeModel->setVisibilityState( id, visState );
1971 bool vis = visState == Qtx::ShownState;
1972 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1975 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1977 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1980 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1982 Handle(HYDROData_StricklerTable) aTable;
1984 if ( myLandCoverColoringMap.contains( theViewId ) ) {
1985 aTable = myLandCoverColoringMap.value( theViewId );
1991 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1992 const Handle(HYDROData_StricklerTable)& theTable )
1994 if ( !theTable.IsNull() ) {
1995 myLandCoverColoringMap.insert( theViewId, theTable );
1999 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
2001 myLandCoverColoringMap.remove( theViewId );
2004 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
2006 return myLandCoverColoringMap.contains( theViewId );
2009 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
2011 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
2015 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
2016 Handle(HYDROData_StricklerTable) aTable =
2017 Handle(HYDROData_StricklerTable)::DownCast( theObject );
2018 QList<int> aViewIds;
2019 QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
2020 while ( anIter.hasNext() ) {
2021 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
2022 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
2029 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
2034 SUIT_ViewWindow* wnd = theMgr->getActiveView();
2035 OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
2039 myOverview->setMainView( occwnd );