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();
297 myViewManagerMap.clear();
299 return LightApp_Module::deactivateModule( theStudy );
302 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
304 static bool inWindows = false;
309 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
310 #ifndef DISABLE_PYCONSOLE
311 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
313 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
314 theMap.insert( OverviewWindow, Qt::LeftDockWidgetArea );
317 LightApp_Application* app = getApp();
318 if( app && app->getWindow( OverviewWindow )==0 )
320 const_cast<HYDROGUI_Module*>( this )->myOverview =
321 new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() );
322 app->insertDockWindow( OverviewWindow, myOverview );
323 app->placeDockWindow( OverviewWindow, Qt::LeftDockWidgetArea );
328 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
330 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
333 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
337 HYDROGUI_DataModel* aModel = getDataModel();
339 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
340 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
341 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
342 bool anIsVTKView = theClient == SVTK_Viewer::Type();
343 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
346 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
348 bool anIsSelectedDataObjects = false;
349 bool anIsVisibleInSelection = false;
350 bool anIsHiddenInSelection = false;
352 bool anIsImage = false;
353 bool anIsImportedImage = false;
354 bool anIsImageHasRefs = false;
355 bool anIsFusedImage = false;
356 bool anIsCutImage = false;
357 bool anIsSplitImage = false;
358 bool anIsMustObjectBeUpdated = false;
359 bool anIsPolyline = false;
360 bool anIsPolyline3D = false;
361 bool anIsProfile = false;
362 bool anIsValidProfile = false;
363 bool anAllAreProfiles = false;
364 bool anIsBathymetry = false;
365 bool anIsCalculation = false;
366 bool anIsImmersibleZone = false;
367 bool anIsVisualState = false;
368 bool anIsRegion = false;
369 bool anIsZone = false;
370 bool anIsObstacle = false;
371 bool anIsStricklerTable = false;
372 bool anIsLandCoverMap = false;
373 bool anIsStream = false;
374 bool anIsChannel = false;
375 bool anIsDigue = false;
376 bool anIsDummyObject3D = false;
377 bool anIsGroup = false;
378 bool anIsObjectCanBeColored = false;
380 bool isStreamHasBottom = false;
382 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
383 SUIT_DataOwnerPtrList anOwners;
384 aSelectionMgr->selected( anOwners );
385 if( anIsObjectBrowser && anOwners.size()==1 )
387 QString anEntry = anOwners[0]->keyString();
388 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
390 isRoot = aStudy->isComponent( anEntry );
393 // Check the selected GEOM objects (take into account the Object Browser only)
394 if ( anIsObjectBrowser ) {
395 QList<GEOM::shape_type> anObstacleTypes =
396 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
397 QList<GEOM::shape_type> aPolylineTypes =
398 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
400 bool isCanBeImportedAsObstacle =
401 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
402 bool isCanBeImportedAsPolyline =
403 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
405 // Add import as obstacle action
406 if ( isCanBeImportedAsObstacle ) {
407 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
409 // Add import as polyline action
410 if ( isCanBeImportedAsPolyline ) {
411 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
414 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
415 theMenu->addSeparator();
419 // check the selected data model objects
420 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
421 int aNbOfSelectedProfiles = 0;
422 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
424 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
425 if( !anObject.IsNull() )
427 anIsSelectedDataObjects = true;
429 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
430 anIsVisibleInSelection |= aVisibility;
431 anIsHiddenInSelection |= !aVisibility;
433 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
435 anIsMustObjectBeUpdated = true;
438 ObjectKind anObjectKind = anObject->GetKind();
439 if( anObjectKind == KIND_IMAGE )
442 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
443 if( !anImage.IsNull() )
445 anIsImportedImage = anImage->HasLocalPoints();
446 anIsImageHasRefs = anImage->HasReferences();
447 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
449 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
451 QString anOperatorName = anOperator->name();
452 if( anOperatorName == ImageComposer_FuseOperator::Type() )
453 anIsFusedImage = true;
454 else if( anOperatorName == ImageComposer_CutOperator::Type() )
456 else if( anOperatorName == ImageComposer_CropOperator::Type() )
457 anIsSplitImage = true;
462 else if( anObjectKind == KIND_POLYLINEXY )
464 else if( anObjectKind == KIND_POLYLINE )
465 anIsPolyline3D = true;
466 else if( anObjectKind == KIND_PROFILE )
469 aNbOfSelectedProfiles++;
471 Handle(HYDROData_Profile) aProfile =
472 Handle(HYDROData_Profile)::DownCast( anObject );
473 if( !aProfile.IsNull() && aProfile->IsValid() ) {
474 anIsValidProfile = true;
477 else if( anObjectKind == KIND_CALCULATION )
478 anIsCalculation = true;
479 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
480 anIsImmersibleZone = true;
481 else if( anObjectKind == KIND_VISUAL_STATE )
482 anIsVisualState = true;
483 else if( anObjectKind == KIND_REGION )
485 else if( anObjectKind == KIND_ZONE )
487 else if( anObjectKind == KIND_BATHYMETRY )
488 anIsBathymetry = true;
489 else if( anObjectKind == KIND_OBSTACLE )
491 else if( anObjectKind == KIND_STRICKLER_TABLE )
492 anIsStricklerTable = true;
493 else if( anObjectKind == KIND_LAND_COVER_MAP )
494 anIsLandCoverMap = true;
495 else if( anObjectKind == KIND_STREAM )
498 Handle(HYDROData_Stream) aStream =
499 Handle(HYDROData_Stream)::DownCast( anObject );
500 if ( !aStream.IsNull() )
501 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
503 else if( anObjectKind == KIND_CHANNEL )
505 else if( anObjectKind == KIND_DIGUE )
507 else if( anObjectKind == KIND_DUMMY_3D )
508 anIsDummyObject3D = true;
509 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLIT_GROUP )
513 if ( !anIsObjectCanBeColored )
514 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
517 // Check if all selected objects are profiles
518 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
519 ( aNbOfSelectedProfiles == aSeq.Length() );
521 // check the selected partitions
522 if( !anIsSelectedDataObjects && anIsObjectBrowser )
524 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
525 if( aSelectedPartition != KIND_UNKNOWN )
527 switch( aSelectedPartition )
530 theMenu->addAction( action( ImportImageId ) );
532 case KIND_BATHYMETRY:
533 theMenu->addAction( action( ImportBathymetryId ) );
535 case KIND_ARTIFICIAL_OBJECT:
536 theMenu->addAction( action( CreateChannelId ) );
537 theMenu->addAction( action( CreateDigueId ) );
539 case KIND_NATURAL_OBJECT:
540 theMenu->addAction( action( CreateImmersibleZoneId ) );
541 theMenu->addAction( action( CreateStreamId ) );
544 theMenu->addAction( action( ImportObstacleFromFileId ) );
545 theMenu->addAction( action( CreateBoxId ) );
546 theMenu->addAction( action( CreateCylinderId ) );
548 case KIND_STRICKLER_TABLE:
549 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
551 case KIND_LAND_COVER_MAP:
552 theMenu->addAction( action( CreateLandCoverMapId ) );
553 theMenu->addAction( action( ImportLandCoverMapId ) );
555 case KIND_CALCULATION:
556 theMenu->addAction( action( CreateCalculationId ) );
558 case KIND_POLYLINEXY:
559 theMenu->addAction( action( ImportPolylineId ) );
560 theMenu->addAction( action( CreatePolylineId ) );
563 theMenu->addAction( action( CreatePolyline3DId ) );
566 theMenu->addAction( action( CreateProfileId ) );
567 theMenu->addAction( action( ImportProfilesId ) );
568 theMenu->addAction( action( AllGeoreferencementId ) );
570 case KIND_VISUAL_STATE:
571 theMenu->addAction( action( SaveVisualStateId ) );
574 theMenu->addSeparator();
578 Handle(HYDROData_CalculationCase) aCalcCase;
580 HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
581 if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
582 theMenu->addAction( action( RegenerateRegionColorsId ) );
586 if( anIsSelectedDataObjects )
588 if ( anIsMustObjectBeUpdated )
590 theMenu->addAction( action( UpdateObjectId ) );
591 theMenu->addSeparator();
595 theMenu->addAction( action( ForcedUpdateObjectId ) );
596 theMenu->addSeparator();
600 if( aSeq.Length() == 1 )
604 if( anIsImportedImage )
605 theMenu->addAction( action( EditImportedImageId ) );
606 else if( anIsImageHasRefs )
609 theMenu->addAction( action( EditFusedImageId ) );
610 else if( anIsCutImage )
611 theMenu->addAction( action( EditCutImageId ) );
612 else if( anIsSplitImage )
613 theMenu->addAction( action( EditSplitImageId ) );
616 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
617 theMenu->addAction( action( ExportImageId ) );
618 theMenu->addSeparator();
620 if( anIsImageHasRefs )
622 theMenu->addAction( action( RemoveImageRefsId ) );
623 theMenu->addSeparator();
626 theMenu->addAction( action( FuseImagesId ) );
627 theMenu->addAction( action( CutImagesId ) );
628 theMenu->addAction( action( SplitImageId ) );
629 theMenu->addSeparator();
630 theMenu->addAction( action( RecognizeContoursId ) );
631 theMenu->addSeparator();
633 else if( anIsBathymetry )
635 theMenu->addAction( action( EditImportedBathymetryId ) );
636 theMenu->addAction( action( BathymetryBoundsId ) );
637 theMenu->addSeparator();
639 else if( anIsPolyline )
641 theMenu->addAction( action( EditPolylineId ) );
642 theMenu->addSeparator();
643 theMenu->addAction( action( SplitPolylinesId ) );
644 theMenu->addAction( action( MergePolylinesId ) );
645 theMenu->addSeparator();
647 else if( anIsPolyline3D )
649 theMenu->addAction( action( EditPolyline3DId ) );
650 theMenu->addSeparator();
652 else if( anIsProfile )
654 theMenu->addAction( action( EditProfileId ) );
655 theMenu->addAction( action( SelectedGeoreferencementId ) );
656 theMenu->addSeparator();
658 else if( anIsCalculation )
660 theMenu->addAction( action( EditCalculationId ) );
661 theMenu->addAction( action( ExportCalculationId ) );
662 theMenu->addSeparator();
664 else if( anIsImmersibleZone )
666 theMenu->addAction( action( EditImmersibleZoneId ) );
667 theMenu->addSeparator();
669 else if( anIsStream )
671 theMenu->addAction( action( EditStreamId ) );
672 if ( action( RiverBottomContextId ) )
674 theMenu->addAction( action( RiverBottomContextId ) );
675 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
677 theMenu->addAction( action( ProfileInterpolateId ) );
678 theMenu->addSeparator();
680 else if( anIsChannel )
682 theMenu->addAction( action( EditChannelId ) );
683 theMenu->addSeparator();
687 theMenu->addAction( action( EditDigueId ) );
688 theMenu->addSeparator();
690 else if( anIsObstacle )
692 theMenu->addAction( action( TranslateObstacleId ) );
693 theMenu->addSeparator();
695 else if( anIsStricklerTable )
697 theMenu->addAction( action( EditStricklerTableId ) );
698 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
699 theMenu->addAction( action( DuplicateStricklerTableId ) );
700 theMenu->addSeparator();
702 Handle(HYDROData_StricklerTable) aTable =
703 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
704 QString aCurrentTable =
705 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
706 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
708 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
709 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
710 theMenu->addSeparator();
713 else if( anIsLandCoverMap )
715 theMenu->addAction( action( AddLandCoverId ) );
716 theMenu->addAction( action( RemoveLandCoverId ) );
717 theMenu->addSeparator();
718 theMenu->addAction( action( SplitLandCoverId ) );
719 theMenu->addAction( action( MergeLandCoverId ) );
720 theMenu->addAction( action( ChangeLandCoverTypeId ) );
721 theMenu->addSeparator();
723 theMenu->addAction( action( ExportToShapeFileID ) );
724 theMenu->addSeparator();
726 else if( anIsVisualState && anIsObjectBrowser )
728 theMenu->addAction( action( SaveVisualStateId ) );
729 theMenu->addAction( action( LoadVisualStateId ) );
730 theMenu->addSeparator();
733 theMenu->addAction( action( ZoneSetColorId ) );
735 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
737 theMenu->addAction( action( PolylineExtractionId ) );
738 theMenu->addSeparator();
741 // Add set color action for geometrical objects
742 if ( anIsObjectCanBeColored )
744 theMenu->addAction( action( SetColorId ) );
745 theMenu->addSeparator();
748 // Add transparency action for land cover map objects
749 if ( anIsLandCoverMap )
751 theMenu->addAction( action( SetTransparencyId ) );
752 theMenu->addSeparator();
755 else if ( anAllAreProfiles )
757 theMenu->addAction( action( EditProfileId ) );
758 theMenu->addAction( action( SelectedGeoreferencementId ) );
759 theMenu->addSeparator();
762 bool isPoly = anIsPolyline || anIsPolyline3D;
763 if (isPoly && !anIsLandCoverMap)
764 theMenu->addAction( action( ExportToShapeFileID ) );
767 QAction* aCopyAction = action( CopyId );
768 if( aCopyAction && aCopyAction->isEnabled() ) {
769 theMenu->addAction( action( CopyId ) );
770 theMenu->addSeparator();
774 if( !anIsDummyObject3D )
775 theMenu->addAction( action( DeleteId ) );
777 theMenu->addSeparator();
779 if( anIsImage || anIsPolyline || anIsPolyline3D ||
780 anIsImmersibleZone || anIsZone || anIsRegion ||
781 anIsBathymetry || anIsObstacle || anIsStream ||
782 anIsChannel || anIsDigue || anIsDummyObject3D ||
783 anIsValidProfile || anIsGroup || anIsLandCoverMap )
785 if( anIsHiddenInSelection )
786 theMenu->addAction( action( ShowId ) );
787 theMenu->addAction( action( ShowOnlyId ) );
788 if( anIsVisibleInSelection )
789 theMenu->addAction( action( HideId ) );
790 theMenu->addSeparator();
796 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
797 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
798 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
799 theMenu->addAction( action( DeleteId ) );
801 theMenu->addSeparator();
802 theMenu->addAction( action( SetZLevelId ) );
803 theMenu->addSeparator();
805 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
806 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
807 theMenu->addSeparator();
811 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
813 theMenu->addAction( action( ShowAllId ) );
814 theMenu->addAction( action( HideAllId ) );
815 theMenu->addSeparator();
818 if ( anIsOCCView || anIsVTKView )
820 theMenu->addSeparator();
821 theMenu->addAction( action( CopyViewerPositionId ) );
825 theMenu->addAction( action( EditLocalCSId ) );
827 if( anIsObjectBrowser && anOwners.size()==1 )
829 if( aSeq.Size() > 0 )
831 Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
832 Handle(HYDROData_Object) anObject;
833 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
834 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
836 if (!anAObject.IsNull())
837 anObject = anAObject;
838 if (!aNObject.IsNull())
841 if( !anObject.IsNull() )
843 theMenu->addSeparator();
844 bool IsSubmersible = anObject->IsSubmersible();
847 theMenu->addAction( action( SubmersibleId ) );
848 action( SubmersibleId )->setCheckable(true);
849 action( SubmersibleId )->setChecked(true);
853 theMenu->addAction( action( UnSubmersibleId ) );
854 action( UnSubmersibleId )->setCheckable(true);
855 action( UnSubmersibleId )->setChecked(true);
861 theMenu->addSeparator();
862 QAction* a = action( ShowHideArrows );
863 a->setText( arrowsVisible() ? tr( "HIDE_ARROWS" ) : tr( "SHOW_ARROWS" ) );
864 theMenu->addAction( a );
867 void HYDROGUI_Module::createPreferences()
869 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
870 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
872 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
873 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
875 // Set property cursor type
876 QList<QVariant> aCursorTypeIndicesList;
877 QList<QVariant> aCursorTypeIconsList;
879 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
880 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
881 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
882 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
883 aCursorTypeIndicesList << i;
884 aCursorTypeIconsList << pixmap;
887 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
888 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
890 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
891 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
892 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
894 addPreference( tr( "PREF_VIEWER_AUTOMATIC_ZOOM" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "automatic_zoom" );
896 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
897 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
898 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
899 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
900 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
901 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
902 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
904 int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
905 int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
906 LightApp_Preferences::Selector, "polyline", "arrow_type" );
908 QList<QVariant> arrow_types;
909 arrow_types.append( tr( "No" ) );
910 arrow_types.append( tr( "Triangle" ) );
911 arrow_types.append( tr( "Cone" ) );
912 setPreferenceProperty( polylineArrow, "strings", arrow_types );
914 QList<QVariant> indices;
918 setPreferenceProperty( polylineArrow, "indexes", indices );
919 setPreferenceProperty( polylineArrow, "ids", indices );
921 int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
922 LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
925 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
927 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
928 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
931 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
932 if ( resMgr && !aDoc.IsNull() )
933 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
935 else if( theSection == "polyline" )
941 resMgr->value( "polyline", "arrow_type", aType );
942 resMgr->value( "polyline", "arrow_size", aSize );
945 ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
946 for( ; it!=last; it++ )
948 int aViewerId = it.key();
949 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
951 getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
954 else if (theSection == "HYDRO" && thePref == "automatic_zoom")
956 bool anAutoZoom = resMgr->booleanValue( "HYDRO", "automatic_zoom" );
957 ViewManagerList aViewManagers = getApp()->viewManagers();
958 foreach (SUIT_ViewManager* aVMgr, aViewManagers)
962 QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
963 foreach (SUIT_ViewWindow* aView, aViews)
967 OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
970 anOCCViewFrame->setAutomaticZoom(anAutoZoom);
971 for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
973 OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
975 aV->setAutomaticZoom(anAutoZoom);
978 OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
980 anOCCViewWindow->setAutomaticZoom(true);
987 LightApp_Module::preferencesChanged( theSection, thePref );
990 QCursor HYDROGUI_Module::getPrefEditCursor() const
992 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
993 if ( aCursorType >= Qt::BlankCursor)
995 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
999 void HYDROGUI_Module::update( const int flags )
1001 if ( !isUpdateEnabled() )
1004 QApplication::setOverrideCursor( Qt::WaitCursor );
1006 // To prevent calling this method recursively
1007 // from one of the methods called below
1008 setUpdateEnabled( false );
1010 // store selected objects
1011 QStringList aSelectedEntries = storeSelection();
1013 bool aDoFitAll = flags & UF_FitAll;
1016 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1017 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
1020 if( ( flags & UF_Viewer ) )
1021 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
1023 if( ( flags & UF_OCCViewer ) )
1024 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
1026 if( ( flags & UF_VTKViewer ) )
1027 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
1029 if( ( flags & UF_Model ) && getDataModel() && getApp() )
1031 getDataModel()->update( getStudyId() );
1033 // Temporary workaround to prevent breaking
1034 // the selection in the object browser.
1035 // Note: processEvents() should be called after updateGV(),
1036 // otherwise the application crashes from time to time.
1037 //RKV: qApp->processEvents();
1038 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1039 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
1040 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
1041 if ( isResizeOnExpandItem && anObjectBrowser ) {
1042 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
1044 getApp()->updateObjectBrowser( true );
1045 if ( isResizeOnExpandItem && anObjectBrowser ) {
1046 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
1050 // Object browser is currently updated by using UF_Model flag
1051 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
1052 getApp()->updateObjectBrowser( true );
1054 if( ( flags & UF_Controls ) && getApp() )
1055 getApp()->updateActions();
1057 // restore selected objects
1058 restoreSelection( aSelectedEntries );
1060 setUpdateEnabled( true );
1062 QApplication::restoreOverrideCursor();
1065 void HYDROGUI_Module::updateCommandsStatus()
1067 LightApp_Module::updateCommandsStatus();
1069 updateUndoRedoControls();
1071 action( CopyId )->setEnabled( getDataModel()->canCopy() );
1072 action( PasteId )->setEnabled( getDataModel()->canPaste() );
1075 void HYDROGUI_Module::selectionChanged()
1077 LightApp_Module::selectionChanged();
1078 updateCommandsStatus();
1081 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1083 return (HYDROGUI_DataModel*)dataModel();
1086 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1091 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1093 return myOCCDisplayer;
1096 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1098 return myVTKDisplayer;
1101 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
1103 if( myViewManagerMap.contains( theId ) )
1105 return myViewManagerMap[ theId ].first;
1110 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
1112 if( myViewManagerMap.contains( theId ) )
1114 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1115 GraphicsView_ViewManager* aViewManager =
1116 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1118 return aViewManager->getViewer();
1123 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
1125 if( myViewManagerMap.contains( theId ) )
1127 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1128 OCCViewer_ViewManager* aViewManager =
1129 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1131 return aViewManager->getOCCViewer();
1136 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
1138 if( myViewManagerMap.contains( theId ) )
1140 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1141 SVTK_ViewManager* aViewManager =
1142 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1144 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1149 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1151 ViewManagerMapIterator anIter( myViewManagerMap );
1152 while( anIter.hasNext() )
1154 int anId = anIter.next().key();
1155 const ViewManagerInfo& anInfo = anIter.value();
1156 if( anInfo.first == theViewManager )
1162 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1164 int anId = getViewManagerId( theViewManager );
1167 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1168 return anInfo.second;
1173 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1174 const ViewManagerRole theRole )
1176 int anId = getViewManagerId( theViewManager );
1179 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1180 anInfo.second = theRole;
1184 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1185 const Handle(HYDROData_Entity)& theObject ) const
1187 if( theObject.IsNull() )
1193 foreach( int aViewId, myObjectStateMap.keys() )
1195 if( isObjectVisible( aViewId, theObject ) )
1201 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1202 if( anIter1 != myObjectStateMap.end() )
1204 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1205 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1207 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1208 if( anIter2 != aEntry2ObjectStateMap.end() )
1210 const ObjectState& anObjectState = anIter2.value();
1211 return anObjectState.Visibility;
1217 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1218 const Handle(HYDROData_Entity)& theObject,
1219 const bool theState )
1221 if( !theObject.IsNull() )
1223 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1224 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1226 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1227 anObjectState.Visibility = theState;
1229 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1232 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1235 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1236 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1237 if ( visState != Qtx::UnpresentableState )
1238 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1242 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1243 setLandCoversScalarMapModeOff( theViewId );
1244 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1245 getOCCDisplayer()->SetToUpdateColorScale();
1250 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1251 const bool theState )
1253 if( !theObject.IsNull() )
1255 // Process OCC shapes
1256 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1257 while( aShapesMapIter != myShapesMap.end() )
1259 const ListOfShapes& aShapesList = aShapesMapIter.value();
1260 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1262 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1264 aShape->setIsToUpdate( theState );
1269 // Process VTK shapes
1270 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1271 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1273 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1274 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1276 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1278 aShape->setIsToUpdate( theState );
1286 /////////////////// OCC SHAPES PROCESSING
1287 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1288 ObjectKind theKind ) const
1290 QList<HYDROGUI_Shape*> aResult;
1292 if ( myShapesMap.contains( theViewId ) )
1294 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1295 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1297 if( aShape && aShape->getObject()->GetKind()==theKind )
1298 aResult.append( aShape );
1304 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1305 const Handle(HYDROData_Entity)& theObject ) const
1307 HYDROGUI_Shape* aResShape = NULL;
1308 if( theObject.IsNull() )
1311 if ( myShapesMap.contains( theViewId ) )
1313 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1314 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1316 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1327 void HYDROGUI_Module::setObjectShape( const int theViewId,
1328 const Handle(HYDROData_Entity)& theObject,
1329 HYDROGUI_Shape* theShape )
1331 if( theObject.IsNull() )
1334 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1335 aViewShapes.append( theShape );
1338 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1339 const Handle(HYDROData_Entity)& theObject )
1341 if ( !myShapesMap.contains( theViewId ) )
1344 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1345 Handle(HYDROData_Entity) anObject;
1346 for ( int i = 0; i < aViewShapes.length(); )
1348 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1349 anObject = aShape->getObject();
1350 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1353 aViewShapes.removeAt( i );
1361 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1363 if ( !myShapesMap.contains( theViewId ) )
1366 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1367 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1369 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1374 myShapesMap.remove( theViewId );
1376 /////////////////// END OF OCC SHAPES PROCESSING
1378 /////////////////// VTKPrs PROCESSING
1379 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1380 const Handle(HYDROData_Entity)& theObject ) const
1382 HYDROGUI_VTKPrs* aResShape = NULL;
1383 if( theObject.IsNull() )
1386 if ( myVTKPrsMap.contains( theViewId ) )
1388 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1389 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1391 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1402 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1403 const Handle(HYDROData_Entity)& theObject,
1404 HYDROGUI_VTKPrs* theShape )
1406 if( theObject.IsNull() )
1409 if( theShape && theShape->needScalarBar() )
1411 // Compute the new global Z range from the added presentation and the old global Z range.
1412 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1413 double* aRange = theShape->getInternalZRange();
1414 bool anIsUpdate = false;
1415 if ( aRange[0] < aGlobalRange[0] )
1417 aGlobalRange[0] = aRange[0];
1420 if ( aRange[1] > aGlobalRange[1] )
1422 aGlobalRange[1] = aRange[1];
1428 updateVTKZRange( theViewId, aGlobalRange );
1432 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1433 aViewShapes.append( theShape );
1436 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1437 const QString& theEntry )
1439 if ( !myVTKPrsMap.contains( theViewId ) )
1442 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1443 Handle(HYDROData_Entity) anObject;
1445 for ( int i = 0; i < aViewShapes.length(); )
1447 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1448 anObject = aShape->getObject();
1449 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1450 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1453 aViewShapes.removeAt( i );
1460 // Invalidate global Z range
1461 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1462 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1465 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1466 const Handle(HYDROData_Entity)& theObject )
1468 if ( !myVTKPrsMap.contains( theViewId ) )
1471 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1472 Handle(HYDROData_Entity) anObject;
1473 for ( int i = 0; i < aViewShapes.length(); )
1475 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1476 anObject = aShape->getObject();
1477 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1480 aViewShapes.removeAt( i );
1487 // Invalidate global Z range
1488 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1489 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1492 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1494 if ( !myVTKPrsMap.contains( theViewId ) )
1497 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1498 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1500 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1505 myVTKPrsMap.remove( theViewId );
1508 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1510 if ( myVTKPrsMap.contains( theViewId ) )
1512 // For the given viewer id update all VTK presentations ...
1513 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1514 HYDROGUI_VTKPrs* aShape;
1515 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1517 aShape = aViewShapes.at( i );
1518 if ( aShape && aShape->needScalarBar() )
1520 aShape->setZRange( theRange );
1524 // ... and update the global color legend scalar bar.
1525 getVTKDisplayer()->SetZRange( theViewId, theRange );
1527 /////////////////// END OF VTKPrs PROCESSING
1529 void HYDROGUI_Module::clearCache()
1531 myObjectStateMap.clear();
1534 CAM_DataModel* HYDROGUI_Module::createDataModel()
1536 return new HYDROGUI_DataModel( this );
1539 void HYDROGUI_Module::customEvent( QEvent* e )
1541 int aType = e->type();
1542 if ( aType == NewViewEvent )
1544 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1545 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1547 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1549 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1550 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1552 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1554 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1555 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1557 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1558 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1559 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1561 //ouv: temporarily commented
1562 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1565 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1566 update( UF_Viewer );
1568 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1574 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1576 QEvent::Type aType = theEvent->type();
1577 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1579 if( aType == QEvent::Show )
1581 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1582 e->setData( theObj );
1583 QApplication::postEvent( this, e );
1584 theObj->removeEventFilter( this );
1587 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1589 if( aType == QEvent::Leave )
1591 SUIT_Desktop* aDesktop = getApp()->desktop();
1592 if ( aDesktop && aDesktop->statusBar() ) {
1593 aDesktop->statusBar()->clearMessage();
1597 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1599 if( aType == QEvent::Leave )
1601 SUIT_Desktop* aDesktop = getApp()->desktop();
1602 if ( aDesktop && aDesktop->statusBar() ) {
1603 aDesktop->statusBar()->clearMessage();
1608 return LightApp_Module::eventFilter( theObj, theEvent );
1611 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1613 LightApp_Module::onViewManagerAdded( theViewManager );
1615 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1617 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1618 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1620 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1622 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1623 mgr->setChainedOperations( true );//TODO: via preferences
1625 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1626 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1627 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1628 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1629 connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
1630 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1632 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1634 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1635 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1636 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1637 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1640 createSelector( theViewManager ); // replace the default selector
1642 ViewManagerInfo anInfo( theViewManager, VMR_General );
1643 myViewManagerMap.insert( ViewManagerId++, anInfo );
1646 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1648 LightApp_Module::onViewManagerRemoved( theViewManager );
1650 createSelector( theViewManager ); // replace the default selector
1652 int anId = getViewManagerId( theViewManager );
1655 OCCViewer_ViewManager* anOCCViewManager =
1656 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1657 if ( anOCCViewManager )
1659 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1660 if ( anOCCViewer ) {
1661 int aViewerId = (size_t)anOCCViewer;
1662 removeViewShapes( aViewerId );
1663 setLandCoversScalarMapModeOff( aViewerId );
1667 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1669 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1672 getVTKDisplayer()->EraseScalarBar( anId, true );
1673 removeViewShapes( (size_t)aVTKViewer );
1677 myViewManagerMap.remove( anId );
1681 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1683 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1685 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1687 aViewFrame->installEventFilter( this );
1689 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1690 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1692 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1693 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1696 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1698 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1700 aViewFrame->onTopView();
1702 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1704 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1706 aViewPort->installEventFilter( this );
1710 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1712 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1714 aViewFrame->installEventFilter( this );
1719 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1721 /* ouv: currently unused
1722 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1724 SUIT_ViewManager* aViewManager = 0;
1726 QObject* aParent = aViewPort;
1727 while( aParent = aParent->parent() )
1729 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1731 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1733 aViewManager = aViewer->getViewManager();
1742 double aMouseX = theEvent->scenePos().x();
1743 double aMouseY = theEvent->scenePos().y();
1745 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1746 if( aRole == VMR_General )
1748 int aXDeg = 0, aYDeg = 0;
1749 int aXMin = 0, aYMin = 0;
1750 double aXSec = 0, aYSec = 0;
1751 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1752 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1754 QString aDegSymbol( QChar( 0x00B0 ) );
1755 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1756 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1758 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1760 else if( aRole == VMR_TransformImage )
1761 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1766 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1767 const bool theIsInit,
1768 const bool theIsForced,
1769 const bool theDoFitAll )
1771 QList<int> aViewManagerIdList;
1773 // currently, all views are updated
1774 ViewManagerMapIterator anIter( myViewManagerMap );
1775 while( anIter.hasNext() )
1777 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1779 if ( theDisplayer->IsApplicable( aViewManager ) )
1781 int anId = anIter.key();
1782 aViewManagerIdList.append( anId );
1786 QListIterator<int> anIdIter( aViewManagerIdList );
1787 while( anIdIter.hasNext() )
1789 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1790 myOverview->setTopView();
1794 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1796 if( !theViewManager )
1799 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1800 if( !aSelectionMgr )
1803 QString aViewType = theViewManager->getType();
1804 if( aViewType != GraphicsView_Viewer::Type() &&
1805 aViewType != OCCViewer_Viewer::Type())
1808 QList<SUIT_Selector*> aSelectorList;
1809 aSelectionMgr->selectors( aViewType, aSelectorList );
1811 // disable all alien selectors
1812 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1813 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1815 SUIT_Selector* aSelector = *anIter;
1816 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1817 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1818 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1819 aSelector->setEnabled( false );
1822 if ( aViewType == GraphicsView_Viewer::Type() )
1824 GraphicsView_ViewManager* aViewManager =
1825 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1827 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1829 else if ( aViewType == OCCViewer_Viewer::Type() )
1831 OCCViewer_ViewManager* aViewManager =
1832 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1834 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1838 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1840 bool aPrevState = myIsUpdateEnabled;
1841 myIsUpdateEnabled = theState;
1845 bool HYDROGUI_Module::isUpdateEnabled() const
1847 return myIsUpdateEnabled;
1850 QStringList HYDROGUI_Module::storeSelection() const
1852 QStringList anEntryList;
1853 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1855 SUIT_DataOwnerPtrList aList( true );
1856 aSelectionMgr->selected( aList );
1858 SUIT_DataOwnerPtrList::iterator anIter;
1859 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1861 const LightApp_DataOwner* anOwner =
1862 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1864 anEntryList.append( anOwner->entry() );
1870 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1872 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1874 SUIT_DataOwnerPtrList aList( true );
1875 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1876 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1877 aSelectionMgr->setSelected( aList );
1881 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1884 bool doShow = false;
1885 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1887 aDisplayer->SaveCursorViewPosition( theViewWindow );
1888 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1892 // Show the coordinates in the status bar
1893 SUIT_Desktop* aDesktop = getApp()->desktop();
1894 if ( aDesktop && aDesktop->statusBar() )
1896 gp_Pnt aWPnt( X, Y, Z );
1897 int aStudyId = application()->activeStudy()->id();
1898 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1899 double WX = aWPnt.X(), WY = aWPnt.Y();
1901 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1902 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1903 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1904 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1905 QString aMsg = tr( "COORDINATES_INFO" );
1906 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1907 aDesktop->statusBar()->showMessage( aMsg );
1913 * Returns stack of active operations;
1915 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1917 return myActiveOperationMap;
1921 * Returns the module active operation. If the active operation is show/hide,
1922 * the method returns the previous operation if it is.
1924 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1926 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1928 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1930 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1932 aVIt.previous(); // skip the top show/hide operation
1933 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1940 * \brief Virtual public slot
1942 * This method is called after the object inserted into data view to update their visibility state
1943 * This is default implementation
1945 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1947 if ( !isActiveModule() )
1950 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1952 // change visibility of object
1953 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1956 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1958 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1959 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1960 if ( visState == Qtx::UnpresentableState )
1963 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1964 treeModel->setVisibilityState( id, visState );
1966 bool vis = visState == Qtx::ShownState;
1967 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1970 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1972 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1975 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1977 Handle(HYDROData_StricklerTable) aTable;
1979 if ( myLandCoverColoringMap.contains( theViewId ) ) {
1980 aTable = myLandCoverColoringMap.value( theViewId );
1986 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1987 const Handle(HYDROData_StricklerTable)& theTable )
1989 if ( !theTable.IsNull() ) {
1990 myLandCoverColoringMap.insert( theViewId, theTable );
1994 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
1996 myLandCoverColoringMap.remove( theViewId );
1999 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
2001 return myLandCoverColoringMap.contains( theViewId );
2004 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
2006 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
2010 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
2011 Handle(HYDROData_StricklerTable) aTable =
2012 Handle(HYDROData_StricklerTable)::DownCast( theObject );
2013 QList<int> aViewIds;
2014 QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
2015 while ( anIter.hasNext() ) {
2016 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
2017 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
2024 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
2029 SUIT_ViewWindow* wnd = theMgr->getActiveView();
2030 OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
2034 myOverview->setMainView( occwnd );