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"
44 #include <HYDROData_Tool.h>
45 #include <HYDROData_Image.h>
46 #include <HYDROData_Stream.h>
47 #include <HYDROData_Profile.h>
48 #include <HYDROData_Lambert93.h>
49 #include <HYDROData_Polyline3D.h>
50 #include <HYDROData_StricklerTable.h>
52 #include <HYDROData_OperationsFactory.h>
54 #include <CurveCreator_Utils.hxx>
56 #include <GraphicsView_ViewFrame.h>
57 #include <GraphicsView_ViewManager.h>
58 #include <GraphicsView_ViewPort.h>
59 #include <GraphicsView_Viewer.h>
61 #include <ImageComposer_CutOperator.h>
62 #include <ImageComposer_CropOperator.h>
63 #include <ImageComposer_FuseOperator.h>
65 #include <LightApp_Application.h>
66 #include <LightApp_DataOwner.h>
67 #include <LightApp_GVSelector.h>
68 #include <LightApp_SelectionMgr.h>
69 #include <LightApp_UpdateFlags.h>
71 #include <SalomeApp_Study.h>
73 #include <OCCViewer_ViewFrame.h>
74 #include <OCCViewer_ViewManager.h>
75 #include <OCCViewer_ViewModel.h>
77 #include <SALOME_Event.h>
79 #include <SUIT_DataBrowser.h>
80 #include <SUIT_DataObject.h>
81 #include <SUIT_ViewManager.h>
82 #include <SUIT_ResourceMgr.h>
83 #include <SUIT_Desktop.h>
84 #include <SUIT_Study.h>
85 #include <SUIT_Session.h>
87 #include <SVTK_ViewManager.h>
88 #include <SVTK_ViewModel.h>
89 #include <SVTK_ViewWindow.h>
90 #include <SVTK_Selector.h>
92 #include <OCCViewer_ViewPort3d.h>
94 #include <GEOMUtils.hxx>
95 #include <GeometryGUI.h>
97 #include <SALOMEDS_wrap.hxx>
100 #include <QApplication>
101 #include <QGraphicsSceneMouseEvent>
103 #include <QMouseEvent>
104 #include <QStatusBar>
107 static int ViewManagerId = 0;
109 extern "C" HYDRO_EXPORT CAM_Module* createModule()
111 return new HYDROGUI_Module();
114 extern "C" HYDRO_EXPORT char* getModuleVersion()
116 return (char*)HYDRO_VERSION;
119 HYDROGUI_Module::HYDROGUI_Module()
120 : LightApp_Module( "HYDRO" ),
123 myIsUpdateEnabled( true )
127 HYDROGUI_Module::~HYDROGUI_Module()
131 int HYDROGUI_Module::getStudyId() const
133 LightApp_Application* anApp = getApp();
134 return anApp ? anApp->activeStudy()->id() : 0;
137 void HYDROGUI_Module::initialize( CAM_Application* theApp )
139 LightApp_Module::initialize( theApp );
142 createUndoRedoActions();
147 setMenuShown( false );
148 setToolShown( false );
150 myDisplayer = new HYDROGUI_Displayer( this );
151 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
152 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
155 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
157 bool aRes = LightApp_Module::activateModule( theStudy );
159 LightApp_Application* anApp = getApp();
160 SUIT_Desktop* aDesktop = anApp->desktop();
162 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
164 setMenuShown( true );
165 setToolShown( true );
167 #ifndef DISABLE_PYCONSOLE
168 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
169 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
172 // Remove defunct view managers from the map.
173 // It's essential to do this before "update( UF_All )" call!
174 QList<int> anObsoleteIds;
175 ViewManagerList anAllViewManagers = anApp->viewManagers();
176 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
177 ViewManagerMapIterator anIter( myViewManagerMap );
178 while( anIter.hasNext() ) {
179 int anId = anIter.next().key();
180 const ViewManagerInfo& anInfo = anIter.value();
182 aHydroViewManagers << anInfo.first;
184 if ( !anAllViewManagers.contains( anInfo.first ) ) {
185 anObsoleteIds << anId;
188 foreach ( const int anId, anObsoleteIds ) {
189 myViewManagerMap.remove( anId );
190 myObjectStateMap.remove( anId );
191 myShapesMap.remove( anId );
192 myVTKPrsMap.remove( anId );
194 // Replace the default selector for all view managers.
195 // Add view managers created outside of HYDRO module to the map.
196 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
197 createSelector( aViewManager ); // replace the default selector
198 if ( !aHydroViewManagers.contains( aViewManager ) ) {
199 ViewManagerInfo anInfo( aViewManager, VMR_General );
200 myViewManagerMap.insert( ViewManagerId++, anInfo );
206 updateCommandsStatus();
208 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
210 ViewManagerList anOCCViewManagers;
211 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
212 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
213 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
214 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
215 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
216 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
217 if ( aViewFrame && aViewFrame->getViewPort() ) {
218 aViewFrame->getViewPort()->installEventFilter( this );
224 SalomeApp_Study* aStudy =
225 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
227 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
228 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
229 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
230 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
231 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
232 if( !GEOM_var->_is_nil() ) {
233 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
238 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
239 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
240 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
245 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
248 ViewManagerMapIterator anIter( myViewManagerMap );
249 while( anIter.hasNext() )
250 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
251 getApp()->removeViewManager( aViewManager );
252 myViewManagerMap.clear();
255 ViewManagerList anOCCViewManagers;
256 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
257 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
258 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
259 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
263 myObjectStateMap.clear();
268 // clear the status bar
269 SUIT_Desktop* aDesktop = getApp()->desktop();
270 if ( aDesktop && aDesktop->statusBar() ) {
271 aDesktop->statusBar()->clearMessage();
274 // clear the data model's list of copying objects
275 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
277 setMenuShown( false );
278 setToolShown( false );
280 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
282 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
284 myActiveOperationMap.clear();
285 return LightApp_Module::deactivateModule( theStudy );
288 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
291 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
292 #ifndef DISABLE_PYCONSOLE
293 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
295 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
298 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
300 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
303 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
307 HYDROGUI_DataModel* aModel = getDataModel();
309 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
310 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
311 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
312 bool anIsVTKView = theClient == SVTK_Viewer::Type();
313 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
316 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
318 bool anIsSelectedDataObjects = false;
319 bool anIsVisibleInSelection = false;
320 bool anIsHiddenInSelection = false;
322 bool anIsImage = false;
323 bool anIsImportedImage = false;
324 bool anIsImageHasRefs = false;
325 bool anIsFusedImage = false;
326 bool anIsCutImage = false;
327 bool anIsSplitImage = false;
328 bool anIsMustObjectBeUpdated = false;
329 bool anIsPolyline = false;
330 bool anIsPolyline3D = false;
331 bool anIsProfile = false;
332 bool anIsValidProfile = false;
333 bool anAllAreProfiles = false;
334 bool anIsBathymetry = false;
335 bool anIsCalculation = false;
336 bool anIsImmersibleZone = false;
337 bool anIsVisualState = false;
338 bool anIsRegion = false;
339 bool anIsZone = false;
340 bool anIsObstacle = false;
341 bool anIsStricklerTable = false;
342 bool anIsLandCoverMap = false;
343 bool anIsStream = false;
344 bool anIsChannel = false;
345 bool anIsDigue = false;
346 bool anIsDummyObject3D = false;
347 bool anIsGroup = false;
348 bool anIsObjectCanBeColored = false;
350 bool isStreamHasBottom = false;
352 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
353 SUIT_DataOwnerPtrList anOwners;
354 aSelectionMgr->selected( anOwners );
355 if( anIsObjectBrowser && anOwners.size()==1 )
357 QString anEntry = anOwners[0]->keyString();
358 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
360 isRoot = aStudy->isComponent( anEntry );
363 // Check the selected GEOM objects (take into account the Object Browser only)
364 if ( anIsObjectBrowser ) {
365 QList<GEOM::shape_type> anObstacleTypes =
366 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
367 QList<GEOM::shape_type> aPolylineTypes =
368 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
370 bool isCanBeImportedAsObstacle =
371 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
372 bool isCanBeImportedAsPolyline =
373 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
375 // Add import as obstacle action
376 if ( isCanBeImportedAsObstacle ) {
377 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
379 // Add import as polyline action
380 if ( isCanBeImportedAsPolyline ) {
381 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
384 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
385 theMenu->addSeparator();
389 // check the selected data model objects
390 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
391 int aNbOfSelectedProfiles = 0;
392 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
394 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
395 if( !anObject.IsNull() )
397 anIsSelectedDataObjects = true;
399 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
400 anIsVisibleInSelection |= aVisibility;
401 anIsHiddenInSelection |= !aVisibility;
403 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
405 anIsMustObjectBeUpdated = true;
408 ObjectKind anObjectKind = anObject->GetKind();
409 if( anObjectKind == KIND_IMAGE )
412 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
413 if( !anImage.IsNull() )
415 anIsImportedImage = anImage->HasLocalPoints();
416 anIsImageHasRefs = anImage->HasReferences();
417 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
419 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
421 QString anOperatorName = anOperator->name();
422 if( anOperatorName == ImageComposer_FuseOperator::Type() )
423 anIsFusedImage = true;
424 else if( anOperatorName == ImageComposer_CutOperator::Type() )
426 else if( anOperatorName == ImageComposer_CropOperator::Type() )
427 anIsSplitImage = true;
432 else if( anObjectKind == KIND_POLYLINEXY )
434 else if( anObjectKind == KIND_POLYLINE )
435 anIsPolyline3D = true;
436 else if( anObjectKind == KIND_PROFILE )
439 aNbOfSelectedProfiles++;
441 Handle(HYDROData_Profile) aProfile =
442 Handle(HYDROData_Profile)::DownCast( anObject );
443 if( !aProfile.IsNull() && aProfile->IsValid() ) {
444 anIsValidProfile = true;
447 else if( anObjectKind == KIND_CALCULATION )
448 anIsCalculation = true;
449 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
450 anIsImmersibleZone = true;
451 else if( anObjectKind == KIND_VISUAL_STATE )
452 anIsVisualState = true;
453 else if( anObjectKind == KIND_REGION )
455 else if( anObjectKind == KIND_ZONE )
457 else if( anObjectKind == KIND_BATHYMETRY )
458 anIsBathymetry = true;
459 else if( anObjectKind == KIND_OBSTACLE )
461 else if( anObjectKind == KIND_STRICKLER_TABLE )
462 anIsStricklerTable = true;
463 else if( anObjectKind == KIND_LAND_COVER_MAP )
464 anIsLandCoverMap = true;
465 else if( anObjectKind == KIND_STREAM )
468 Handle(HYDROData_Stream) aStream =
469 Handle(HYDROData_Stream)::DownCast( anObject );
470 if ( !aStream.IsNull() )
471 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
473 else if( anObjectKind == KIND_CHANNEL )
475 else if( anObjectKind == KIND_DIGUE )
477 else if( anObjectKind == KIND_DUMMY_3D )
478 anIsDummyObject3D = true;
479 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLIT_GROUP )
483 if ( !anIsObjectCanBeColored )
484 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
487 // Check if all selected objects are profiles
488 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
489 ( aNbOfSelectedProfiles == aSeq.Length() );
491 // check the selected partitions
492 if( !anIsSelectedDataObjects && anIsObjectBrowser )
494 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
495 if( aSelectedPartition != KIND_UNKNOWN )
497 switch( aSelectedPartition )
500 theMenu->addAction( action( ImportImageId ) );
502 case KIND_BATHYMETRY:
503 theMenu->addAction( action( ImportBathymetryId ) );
505 case KIND_ARTIFICIAL_OBJECT:
506 theMenu->addAction( action( CreateChannelId ) );
507 theMenu->addAction( action( CreateDigueId ) );
509 case KIND_NATURAL_OBJECT:
510 theMenu->addAction( action( CreateImmersibleZoneId ) );
511 theMenu->addAction( action( CreateStreamId ) );
514 theMenu->addAction( action( ImportObstacleFromFileId ) );
515 theMenu->addAction( action( CreateBoxId ) );
516 theMenu->addAction( action( CreateCylinderId ) );
518 case KIND_STRICKLER_TABLE:
519 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
521 case KIND_LAND_COVER_MAP:
522 theMenu->addAction( action( CreateLandCoverMapId ) );
523 theMenu->addAction( action( ImportLandCoverMapId ) );
525 case KIND_CALCULATION:
526 theMenu->addAction( action( CreateCalculationId ) );
528 case KIND_POLYLINEXY:
529 theMenu->addAction( action( ImportPolylineId ) );
530 theMenu->addAction( action( CreatePolylineId ) );
533 theMenu->addAction( action( CreatePolyline3DId ) );
536 theMenu->addAction( action( CreateProfileId ) );
537 theMenu->addAction( action( ImportProfilesId ) );
538 theMenu->addAction( action( AllGeoreferencementId ) );
540 case KIND_VISUAL_STATE:
541 theMenu->addAction( action( SaveVisualStateId ) );
544 theMenu->addSeparator();
548 if( anIsSelectedDataObjects )
550 if ( anIsMustObjectBeUpdated )
552 theMenu->addAction( action( UpdateObjectId ) );
553 theMenu->addSeparator();
557 theMenu->addAction( action( ForcedUpdateObjectId ) );
558 theMenu->addSeparator();
562 if( aSeq.Length() == 1 )
566 if( anIsImportedImage )
567 theMenu->addAction( action( EditImportedImageId ) );
568 else if( anIsImageHasRefs )
571 theMenu->addAction( action( EditFusedImageId ) );
572 else if( anIsCutImage )
573 theMenu->addAction( action( EditCutImageId ) );
574 else if( anIsSplitImage )
575 theMenu->addAction( action( EditSplitImageId ) );
578 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
579 theMenu->addAction( action( ExportImageId ) );
580 theMenu->addSeparator();
582 if( anIsImageHasRefs )
584 theMenu->addAction( action( RemoveImageRefsId ) );
585 theMenu->addSeparator();
588 theMenu->addAction( action( FuseImagesId ) );
589 theMenu->addAction( action( CutImagesId ) );
590 theMenu->addAction( action( SplitImageId ) );
591 theMenu->addSeparator();
592 theMenu->addAction( action( RecognizeContoursId ) );
593 theMenu->addSeparator();
595 else if( anIsBathymetry )
597 theMenu->addAction( action( EditImportedBathymetryId ) );
598 theMenu->addAction( action( BathymetryBoundsId ) );
599 theMenu->addSeparator();
601 else if( anIsPolyline )
603 theMenu->addAction( action( EditPolylineId ) );
604 theMenu->addSeparator();
605 theMenu->addAction( action( SplitPolylinesId ) );
606 theMenu->addAction( action( MergePolylinesId ) );
607 theMenu->addSeparator();
609 else if( anIsPolyline3D )
611 theMenu->addAction( action( EditPolyline3DId ) );
612 theMenu->addSeparator();
614 else if( anIsProfile )
616 theMenu->addAction( action( EditProfileId ) );
617 theMenu->addAction( action( SelectedGeoreferencementId ) );
618 theMenu->addSeparator();
620 else if( anIsCalculation )
622 theMenu->addAction( action( EditCalculationId ) );
623 theMenu->addAction( action( ExportCalculationId ) );
624 theMenu->addSeparator();
626 else if( anIsImmersibleZone )
628 theMenu->addAction( action( EditImmersibleZoneId ) );
629 theMenu->addSeparator();
631 else if( anIsStream )
633 theMenu->addAction( action( EditStreamId ) );
634 if ( action( RiverBottomContextId ) )
636 theMenu->addAction( action( RiverBottomContextId ) );
637 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
639 theMenu->addAction( action( ProfileInterpolateId ) );
640 theMenu->addSeparator();
642 else if( anIsChannel )
644 theMenu->addAction( action( EditChannelId ) );
645 theMenu->addSeparator();
649 theMenu->addAction( action( EditDigueId ) );
650 theMenu->addSeparator();
652 else if( anIsObstacle )
654 theMenu->addAction( action( TranslateObstacleId ) );
655 theMenu->addSeparator();
657 else if( anIsStricklerTable )
659 theMenu->addAction( action( EditStricklerTableId ) );
660 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
661 theMenu->addAction( action( DuplicateStricklerTableId ) );
662 theMenu->addSeparator();
664 Handle(HYDROData_StricklerTable) aTable =
665 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
666 QString aCurrentTable =
667 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
668 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
670 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
671 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
672 theMenu->addSeparator();
675 else if( anIsLandCoverMap )
677 theMenu->addAction( action( AddLandCoverId ) );
678 theMenu->addAction( action( RemoveLandCoverId ) );
679 theMenu->addSeparator();
680 theMenu->addAction( action( SplitLandCoverId ) );
681 theMenu->addAction( action( MergeLandCoverId ) );
682 theMenu->addAction( action( ChangeLandCoverTypeId ) );
683 theMenu->addSeparator();
685 theMenu->addAction( action( ExportToShapeFileID ) );
686 theMenu->addSeparator();
688 else if( anIsVisualState && anIsObjectBrowser )
690 theMenu->addAction( action( SaveVisualStateId ) );
691 theMenu->addAction( action( LoadVisualStateId ) );
692 theMenu->addSeparator();
695 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
697 theMenu->addAction( action( PolylineExtractionId ) );
698 theMenu->addSeparator();
701 // Add set color action for geometrical objects
702 if ( anIsObjectCanBeColored )
704 theMenu->addAction( action( SetColorId ) );
705 theMenu->addSeparator();
708 // Add transparency action for land cover map objects
709 if ( anIsLandCoverMap )
711 theMenu->addAction( action( SetTransparencyId ) );
712 theMenu->addSeparator();
714 } else if ( anAllAreProfiles ) {
715 theMenu->addAction( action( SelectedGeoreferencementId ) );
716 theMenu->addSeparator();
719 bool anIsPoly = anIsPolyline || anIsPolyline3D;
720 if (anIsPoly && !anIsLandCoverMap)
721 theMenu->addAction( action( ExportToShapeFileID ) );
724 QAction* aCopyAction = action( CopyId );
725 if( aCopyAction && aCopyAction->isEnabled() ) {
726 theMenu->addAction( action( CopyId ) );
727 theMenu->addSeparator();
731 if( !anIsDummyObject3D )
732 theMenu->addAction( action( DeleteId ) );
734 theMenu->addSeparator();
736 if( anIsImage || anIsPolyline || anIsPolyline3D ||
737 anIsImmersibleZone || anIsZone || anIsRegion ||
738 anIsBathymetry || anIsObstacle || anIsStream ||
739 anIsChannel || anIsDigue || anIsDummyObject3D ||
740 anIsValidProfile || anIsGroup || anIsLandCoverMap )
742 if( anIsHiddenInSelection )
743 theMenu->addAction( action( ShowId ) );
744 theMenu->addAction( action( ShowOnlyId ) );
745 if( anIsVisibleInSelection )
746 theMenu->addAction( action( HideId ) );
747 theMenu->addSeparator();
753 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
754 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
755 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
756 theMenu->addAction( action( DeleteId ) );
758 theMenu->addSeparator();
759 theMenu->addAction( action( SetZLevelId ) );
760 theMenu->addSeparator();
762 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
763 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
764 theMenu->addSeparator();
768 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
770 theMenu->addAction( action( ShowAllId ) );
771 theMenu->addAction( action( HideAllId ) );
772 theMenu->addSeparator();
775 if ( anIsOCCView || anIsVTKView )
777 theMenu->addSeparator();
778 theMenu->addAction( action( CopyViewerPositionId ) );
782 theMenu->addAction( action( EditLocalCSId ) );
784 if( anIsObjectBrowser && anOwners.size()==1 )
786 if( aSeq.Size() > 0 )
788 Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
789 if( !anObject.IsNull() )
791 theMenu->addSeparator();
792 theMenu->addAction( action( SubmersibleId ) );
793 action( SubmersibleId )->setCheckable( true );
794 action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
800 void HYDROGUI_Module::createPreferences()
802 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
803 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
805 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
806 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
808 // Set property cursor type
809 QList<QVariant> aCursorTypeIndicesList;
810 QList<QVariant> aCursorTypeIconsList;
812 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
813 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
814 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
815 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
816 aCursorTypeIndicesList << i;
817 aCursorTypeIconsList << pixmap;
820 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
821 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
823 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
824 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
825 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
827 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
828 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
829 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
830 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
831 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
832 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
833 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
835 int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
836 int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
837 LightApp_Preferences::Selector, "polyline", "arrow_type" );
839 QList<QVariant> arrow_types;
840 arrow_types.append( tr( "No" ) );
841 arrow_types.append( tr( "Triangle" ) );
842 arrow_types.append( tr( "Cone" ) );
843 setPreferenceProperty( polylineArrow, "strings", arrow_types );
845 QList<QVariant> indices;
849 setPreferenceProperty( polylineArrow, "indexes", indices );
850 setPreferenceProperty( polylineArrow, "ids", indices );
852 int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
853 LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
856 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
858 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
859 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
862 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
863 if ( resMgr && !aDoc.IsNull() )
864 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
866 else if( theSection == "polyline" )
872 resMgr->value( "polyline", "arrow_type", aType );
873 resMgr->value( "polyline", "arrow_size", aSize );
876 ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
877 for( ; it!=last; it++ )
879 int aViewerId = it.key();
880 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
882 getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
886 LightApp_Module::preferencesChanged( theSection, thePref );
889 QCursor HYDROGUI_Module::getPrefEditCursor() const
891 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
892 if ( aCursorType >= Qt::BlankCursor)
894 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
898 void HYDROGUI_Module::update( const int flags )
900 if ( !isUpdateEnabled() )
903 QApplication::setOverrideCursor( Qt::WaitCursor );
905 // To prevent calling this method recursively
906 // from one of the methods called below
907 setUpdateEnabled( false );
909 // store selected objects
910 QStringList aSelectedEntries = storeSelection();
912 bool aDoFitAll = flags & UF_FitAll;
915 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
916 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
919 if( ( flags & UF_Viewer ) )
920 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
922 if( ( flags & UF_OCCViewer ) )
923 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
925 if( ( flags & UF_VTKViewer ) )
926 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
928 if( ( flags & UF_Model ) && getDataModel() && getApp() )
930 getDataModel()->update( getStudyId() );
932 // Temporary workaround to prevent breaking
933 // the selection in the object browser.
934 // Note: processEvents() should be called after updateGV(),
935 // otherwise the application crashes from time to time.
936 //RKV: qApp->processEvents();
937 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
938 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
939 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
940 if ( isResizeOnExpandItem && anObjectBrowser ) {
941 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
943 getApp()->updateObjectBrowser( true );
944 if ( isResizeOnExpandItem && anObjectBrowser ) {
945 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
949 // Object browser is currently updated by using UF_Model flag
950 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
951 getApp()->updateObjectBrowser( true );
953 if( ( flags & UF_Controls ) && getApp() )
954 getApp()->updateActions();
956 // restore selected objects
957 restoreSelection( aSelectedEntries );
959 setUpdateEnabled( true );
961 QApplication::restoreOverrideCursor();
964 void HYDROGUI_Module::updateCommandsStatus()
966 LightApp_Module::updateCommandsStatus();
968 updateUndoRedoControls();
970 action( CopyId )->setEnabled( getDataModel()->canCopy() );
971 action( PasteId )->setEnabled( getDataModel()->canPaste() );
974 void HYDROGUI_Module::selectionChanged()
976 LightApp_Module::selectionChanged();
977 updateCommandsStatus();
980 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
982 return (HYDROGUI_DataModel*)dataModel();
985 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
990 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
992 return myOCCDisplayer;
995 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
997 return myVTKDisplayer;
1000 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
1002 if( myViewManagerMap.contains( theId ) )
1004 return myViewManagerMap[ theId ].first;
1009 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
1011 if( myViewManagerMap.contains( theId ) )
1013 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1014 GraphicsView_ViewManager* aViewManager =
1015 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1017 return aViewManager->getViewer();
1022 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
1024 if( myViewManagerMap.contains( theId ) )
1026 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1027 OCCViewer_ViewManager* aViewManager =
1028 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1030 return aViewManager->getOCCViewer();
1035 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
1037 if( myViewManagerMap.contains( theId ) )
1039 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1040 SVTK_ViewManager* aViewManager =
1041 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1043 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1048 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1050 ViewManagerMapIterator anIter( myViewManagerMap );
1051 while( anIter.hasNext() )
1053 int anId = anIter.next().key();
1054 const ViewManagerInfo& anInfo = anIter.value();
1055 if( anInfo.first == theViewManager )
1061 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1063 int anId = getViewManagerId( theViewManager );
1066 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1067 return anInfo.second;
1072 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1073 const ViewManagerRole theRole )
1075 int anId = getViewManagerId( theViewManager );
1078 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1079 anInfo.second = theRole;
1083 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
1084 const Handle(HYDROData_Entity)& theObject ) const
1086 if( theObject.IsNull() )
1092 foreach( int aViewId, myObjectStateMap.keys() )
1094 if( isObjectVisible( aViewId, theObject ) )
1100 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1101 if( anIter1 != myObjectStateMap.end() )
1103 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1104 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1106 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1107 if( anIter2 != aEntry2ObjectStateMap.end() )
1109 const ObjectState& anObjectState = anIter2.value();
1110 return anObjectState.Visibility;
1116 void HYDROGUI_Module::setObjectVisible( const int theViewId,
1117 const Handle(HYDROData_Entity)& theObject,
1118 const bool theState )
1120 if( !theObject.IsNull() )
1122 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1123 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1125 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1126 anObjectState.Visibility = theState;
1128 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1131 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1134 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1135 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1136 if ( visState != Qtx::UnpresentableState )
1137 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1141 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1142 setLandCoversScalarMapModeOff( theViewId );
1143 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1144 getOCCDisplayer()->SetToUpdateColorScale();
1149 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1150 const bool theState )
1152 if( !theObject.IsNull() )
1154 // Process OCC shapes
1155 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1156 while( aShapesMapIter != myShapesMap.end() )
1158 const ListOfShapes& aShapesList = aShapesMapIter.value();
1159 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1161 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1163 aShape->setIsToUpdate( theState );
1168 // Process VTK shapes
1169 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1170 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1172 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1173 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1175 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1177 aShape->setIsToUpdate( theState );
1185 /////////////////// OCC SHAPES PROCESSING
1186 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1187 ObjectKind theKind ) const
1189 QList<HYDROGUI_Shape*> aResult;
1191 if ( myShapesMap.contains( theViewId ) )
1193 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1194 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1196 if( aShape && aShape->getObject()->GetKind()==theKind )
1197 aResult.append( aShape );
1203 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1204 const Handle(HYDROData_Entity)& theObject ) const
1206 HYDROGUI_Shape* aResShape = NULL;
1207 if( theObject.IsNull() )
1210 if ( myShapesMap.contains( theViewId ) )
1212 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1213 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1215 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1226 void HYDROGUI_Module::setObjectShape( const int theViewId,
1227 const Handle(HYDROData_Entity)& theObject,
1228 HYDROGUI_Shape* theShape )
1230 if( theObject.IsNull() )
1233 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1234 aViewShapes.append( theShape );
1237 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1238 const Handle(HYDROData_Entity)& theObject )
1240 if ( !myShapesMap.contains( theViewId ) )
1243 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1244 Handle(HYDROData_Entity) anObject;
1245 for ( int i = 0; i < aViewShapes.length(); )
1247 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1248 anObject = aShape->getObject();
1249 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1252 aViewShapes.removeAt( i );
1260 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1262 if ( !myShapesMap.contains( theViewId ) )
1265 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1266 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1268 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1273 myShapesMap.remove( theViewId );
1275 /////////////////// END OF OCC SHAPES PROCESSING
1277 /////////////////// VTKPrs PROCESSING
1278 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1279 const Handle(HYDROData_Entity)& theObject ) const
1281 HYDROGUI_VTKPrs* aResShape = NULL;
1282 if( theObject.IsNull() )
1285 if ( myVTKPrsMap.contains( theViewId ) )
1287 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1288 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1290 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1301 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1302 const Handle(HYDROData_Entity)& theObject,
1303 HYDROGUI_VTKPrs* theShape )
1305 if( theObject.IsNull() )
1308 if( theShape && theShape->needScalarBar() )
1310 // Compute the new global Z range from the added presentation and the old global Z range.
1311 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1312 double* aRange = theShape->getInternalZRange();
1313 bool anIsUpdate = false;
1314 if ( aRange[0] < aGlobalRange[0] )
1316 aGlobalRange[0] = aRange[0];
1319 if ( aRange[1] > aGlobalRange[1] )
1321 aGlobalRange[1] = aRange[1];
1327 updateVTKZRange( theViewId, aGlobalRange );
1331 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1332 aViewShapes.append( theShape );
1335 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1336 const QString& theEntry )
1338 if ( !myVTKPrsMap.contains( theViewId ) )
1341 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1342 Handle(HYDROData_Entity) anObject;
1344 for ( int i = 0; i < aViewShapes.length(); )
1346 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1347 anObject = aShape->getObject();
1348 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1349 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1352 aViewShapes.removeAt( i );
1359 // Invalidate global Z range
1360 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1361 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1364 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1365 const Handle(HYDROData_Entity)& theObject )
1367 if ( !myVTKPrsMap.contains( theViewId ) )
1370 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1371 Handle(HYDROData_Entity) anObject;
1372 for ( int i = 0; i < aViewShapes.length(); )
1374 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1375 anObject = aShape->getObject();
1376 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1379 aViewShapes.removeAt( i );
1386 // Invalidate global Z range
1387 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1388 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1391 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1393 if ( !myVTKPrsMap.contains( theViewId ) )
1396 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1397 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1399 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1404 myVTKPrsMap.remove( theViewId );
1407 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1409 if ( myVTKPrsMap.contains( theViewId ) )
1411 // For the given viewer id update all VTK presentations ...
1412 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1413 HYDROGUI_VTKPrs* aShape;
1414 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1416 aShape = aViewShapes.at( i );
1417 if ( aShape && aShape->needScalarBar() )
1419 aShape->setZRange( theRange );
1423 // ... and update the global color legend scalar bar.
1424 getVTKDisplayer()->SetZRange( theViewId, theRange );
1426 /////////////////// END OF VTKPrs PROCESSING
1428 void HYDROGUI_Module::clearCache()
1430 myObjectStateMap.clear();
1433 CAM_DataModel* HYDROGUI_Module::createDataModel()
1435 return new HYDROGUI_DataModel( this );
1438 void HYDROGUI_Module::customEvent( QEvent* e )
1440 int aType = e->type();
1441 if ( aType == NewViewEvent )
1443 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1444 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1446 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1448 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1449 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1451 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1453 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1454 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1456 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1457 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1458 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1460 //ouv: temporarily commented
1461 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1464 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1465 update( UF_Viewer );
1467 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1473 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1475 QEvent::Type aType = theEvent->type();
1476 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1478 if( aType == QEvent::Show )
1480 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1481 e->setData( theObj );
1482 QApplication::postEvent( this, e );
1483 theObj->removeEventFilter( this );
1486 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1488 if( aType == QEvent::Leave )
1490 SUIT_Desktop* aDesktop = getApp()->desktop();
1491 if ( aDesktop && aDesktop->statusBar() ) {
1492 aDesktop->statusBar()->clearMessage();
1496 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1498 if( aType == QEvent::Leave )
1500 SUIT_Desktop* aDesktop = getApp()->desktop();
1501 if ( aDesktop && aDesktop->statusBar() ) {
1502 aDesktop->statusBar()->clearMessage();
1507 return LightApp_Module::eventFilter( theObj, theEvent );
1510 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1512 LightApp_Module::onViewManagerAdded( theViewManager );
1514 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1516 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1517 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1519 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1521 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1522 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1523 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1524 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1526 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1528 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1529 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1530 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1531 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1534 createSelector( theViewManager ); // replace the default selector
1536 ViewManagerInfo anInfo( theViewManager, VMR_General );
1537 myViewManagerMap.insert( ViewManagerId++, anInfo );
1540 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1542 LightApp_Module::onViewManagerRemoved( theViewManager );
1544 createSelector( theViewManager ); // replace the default selector
1546 int anId = getViewManagerId( theViewManager );
1549 OCCViewer_ViewManager* anOCCViewManager =
1550 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1551 if ( anOCCViewManager )
1553 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1554 if ( anOCCViewer ) {
1555 int aViewerId = (size_t)anOCCViewer;
1556 removeViewShapes( aViewerId );
1557 setLandCoversScalarMapModeOff( aViewerId );
1561 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1563 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1566 getVTKDisplayer()->EraseScalarBar( anId, true );
1567 removeViewShapes( (size_t)aVTKViewer );
1571 myViewManagerMap.remove( anId );
1575 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1577 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1579 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1581 aViewFrame->installEventFilter( this );
1583 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1584 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1586 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1587 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1590 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1592 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1594 aViewFrame->onTopView();
1596 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1598 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1600 aViewPort->installEventFilter( this );
1604 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1606 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1608 aViewFrame->installEventFilter( this );
1613 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1615 /* ouv: currently unused
1616 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1618 SUIT_ViewManager* aViewManager = 0;
1620 QObject* aParent = aViewPort;
1621 while( aParent = aParent->parent() )
1623 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1625 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1627 aViewManager = aViewer->getViewManager();
1636 double aMouseX = theEvent->scenePos().x();
1637 double aMouseY = theEvent->scenePos().y();
1639 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1640 if( aRole == VMR_General )
1642 int aXDeg = 0, aYDeg = 0;
1643 int aXMin = 0, aYMin = 0;
1644 double aXSec = 0, aYSec = 0;
1645 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1646 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1648 QString aDegSymbol( QChar( 0x00B0 ) );
1649 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1650 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1652 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1654 else if( aRole == VMR_TransformImage )
1655 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1660 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1661 const bool theIsInit,
1662 const bool theIsForced,
1663 const bool theDoFitAll )
1665 QList<int> aViewManagerIdList;
1667 // currently, all views are updated
1668 ViewManagerMapIterator anIter( myViewManagerMap );
1669 while( anIter.hasNext() )
1671 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1673 if ( theDisplayer->IsApplicable( aViewManager ) )
1675 int anId = anIter.key();
1676 aViewManagerIdList.append( anId );
1680 QListIterator<int> anIdIter( aViewManagerIdList );
1681 while( anIdIter.hasNext() )
1683 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1687 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1689 if( !theViewManager )
1692 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1693 if( !aSelectionMgr )
1696 QString aViewType = theViewManager->getType();
1697 if( aViewType != GraphicsView_Viewer::Type() &&
1698 aViewType != OCCViewer_Viewer::Type())
1701 QList<SUIT_Selector*> aSelectorList;
1702 aSelectionMgr->selectors( aViewType, aSelectorList );
1704 // disable all alien selectors
1705 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1706 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1708 SUIT_Selector* aSelector = *anIter;
1709 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1710 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1711 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1712 aSelector->setEnabled( false );
1715 if ( aViewType == GraphicsView_Viewer::Type() )
1717 GraphicsView_ViewManager* aViewManager =
1718 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1720 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1722 else if ( aViewType == OCCViewer_Viewer::Type() )
1724 OCCViewer_ViewManager* aViewManager =
1725 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1727 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1731 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1733 bool aPrevState = myIsUpdateEnabled;
1734 myIsUpdateEnabled = theState;
1738 bool HYDROGUI_Module::isUpdateEnabled() const
1740 return myIsUpdateEnabled;
1743 QStringList HYDROGUI_Module::storeSelection() const
1745 QStringList anEntryList;
1746 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1748 SUIT_DataOwnerPtrList aList( true );
1749 aSelectionMgr->selected( aList );
1751 SUIT_DataOwnerPtrList::iterator anIter;
1752 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1754 const LightApp_DataOwner* anOwner =
1755 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1757 anEntryList.append( anOwner->entry() );
1763 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1765 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1767 SUIT_DataOwnerPtrList aList( true );
1768 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1769 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1770 aSelectionMgr->setSelected( aList );
1774 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1777 bool doShow = false;
1778 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1780 aDisplayer->SaveCursorViewPosition( theViewWindow );
1781 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1785 // Show the coordinates in the status bar
1786 SUIT_Desktop* aDesktop = getApp()->desktop();
1787 if ( aDesktop && aDesktop->statusBar() )
1789 gp_Pnt aWPnt( X, Y, Z );
1790 int aStudyId = application()->activeStudy()->id();
1791 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1792 double WX = aWPnt.X(), WY = aWPnt.Y();
1794 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1795 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1796 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1797 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1798 QString aMsg = tr( "COORDINATES_INFO" );
1799 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1800 aDesktop->statusBar()->showMessage( aMsg );
1806 * Returns stack of active operations;
1808 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1810 return myActiveOperationMap;
1814 * Returns the module active operation. If the active operation is show/hide,
1815 * the method returns the previous operation if it is.
1817 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1819 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1821 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1823 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1825 aVIt.previous(); // skip the top show/hide operation
1826 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1833 * \brief Virtual public slot
1835 * This method is called after the object inserted into data view to update their visibility state
1836 * This is default implementation
1838 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1840 if ( !isActiveModule() )
1843 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1845 // change visibility of object
1846 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1849 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1851 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1852 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1853 if ( visState == Qtx::UnpresentableState )
1856 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1857 treeModel->setVisibilityState( id, visState );
1859 bool vis = visState == Qtx::ShownState;
1860 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1863 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1865 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
1868 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const int theViewId ) const
1870 Handle(HYDROData_StricklerTable) aTable;
1872 if ( myLandCoverColoringMap.contains( theViewId ) ) {
1873 aTable = myLandCoverColoringMap.value( theViewId );
1879 void HYDROGUI_Module::setLandCoverColoringTable( const int theViewId,
1880 const Handle(HYDROData_StricklerTable)& theTable )
1882 if ( !theTable.IsNull() ) {
1883 myLandCoverColoringMap.insert( theViewId, theTable );
1887 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const int theViewId )
1889 myLandCoverColoringMap.remove( theViewId );
1892 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const int theViewId ) const
1894 return myLandCoverColoringMap.contains( theViewId );
1897 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
1899 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
1903 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
1904 Handle(HYDROData_StricklerTable) aTable =
1905 Handle(HYDROData_StricklerTable)::DownCast( theObject );
1906 QList<int> aViewIds;
1907 QMutableMapIterator<int, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
1908 while ( anIter.hasNext() ) {
1909 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
1910 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {