1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_DataObject.h"
28 #include "HYDROGUI_Displayer.h"
29 #include "HYDROGUI_GVSelector.h"
30 #include "HYDROGUI_InputPanel.h"
31 #include "HYDROGUI_ObjSelector.h"
32 #include "HYDROGUI_OCCDisplayer.h"
33 #include "HYDROGUI_OCCSelector.h"
34 #include "HYDROGUI_Operations.h"
35 #include "HYDROGUI_PrsImage.h"
36 #include "HYDROGUI_Tool.h"
37 #include "HYDROGUI_UpdateFlags.h"
38 #include "HYDROGUI_Shape.h"
39 #include "HYDROGUI_VTKPrs.h"
40 #include "HYDROGUI_VTKPrsDisplayer.h"
41 #include "HYDROGUI_AbstractDisplayer.h"
42 #include "HYDROGUI_PolylineOp.h"
43 #include "HYDROGUI_SetColorOp.h"
44 #include "HYDROGUI_ImportGeomObjectOp.h"
45 #include "HYDROGUI_ShowHideOp.h"
47 #include <HYDROData_Image.h>
48 #include <HYDROData_Profile.h>
49 #include <HYDROData_Lambert93.h>
50 #include <HYDROData_Tool.h>
52 #include <HYDROData_OperationsFactory.h>
54 #include <CurveCreator_Utils.h>
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_Desktop.h>
81 #include <SUIT_Study.h>
82 #include <SUIT_ViewManager.h>
83 #include <SUIT_ResourceMgr.h>
85 #include <SVTK_ViewManager.h>
86 #include <SVTK_ViewModel.h>
87 #include <SVTK_ViewWindow.h>
88 #include <SVTK_Selector.h>
90 #include <OCCViewer_ViewPort3d.h>
92 #include <GEOMUtils.hxx>
93 #include <GeometryGUI.h>
95 #include <SALOMEDS_wrap.hxx>
98 #include <QApplication>
99 #include <QGraphicsSceneMouseEvent>
101 #include <QMouseEvent>
102 #include <QStatusBar>
105 static int ViewManagerId = 0;
107 extern "C" HYDRO_EXPORT CAM_Module* createModule()
109 return new HYDROGUI_Module();
112 extern "C" HYDRO_EXPORT char* getModuleVersion()
114 return (char*)HYDRO_VERSION;
117 HYDROGUI_Module::HYDROGUI_Module()
118 : LightApp_Module( "HYDRO" ),
121 myIsUpdateEnabled( true )
125 HYDROGUI_Module::~HYDROGUI_Module()
129 int HYDROGUI_Module::getStudyId() const
131 LightApp_Application* anApp = getApp();
132 return anApp ? anApp->activeStudy()->id() : 0;
135 void HYDROGUI_Module::initialize( CAM_Application* theApp )
137 LightApp_Module::initialize( theApp );
140 createUndoRedoActions();
145 setMenuShown( false );
146 setToolShown( false );
148 myDisplayer = new HYDROGUI_Displayer( this );
149 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
150 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
153 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
155 bool aRes = LightApp_Module::activateModule( theStudy );
157 LightApp_Application* anApp = getApp();
158 SUIT_Desktop* aDesktop = anApp->desktop();
160 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
162 setMenuShown( true );
163 setToolShown( true );
165 #ifndef DISABLE_PYCONSOLE
166 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
167 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
170 // Remove defunct view managers from the map.
171 // It's essential to do this before "update( UF_All )" call!
172 QList<int> anObsoleteIds;
173 ViewManagerList anAllViewManagers = anApp->viewManagers();
174 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
175 ViewManagerMapIterator anIter( myViewManagerMap );
176 while( anIter.hasNext() ) {
177 int anId = anIter.next().key();
178 const ViewManagerInfo& anInfo = anIter.value();
180 aHydroViewManagers << anInfo.first;
182 if ( !anAllViewManagers.contains( anInfo.first ) ) {
183 anObsoleteIds << anId;
186 foreach ( const int anId, anObsoleteIds ) {
187 myViewManagerMap.remove( anId );
188 myObjectStateMap.remove( anId );
189 myObjectDisplayOrderMap.remove( anId );
190 myShapesMap.remove( anId );
191 myVTKPrsMap.remove( anId );
193 // Replace the default selector for all view managers.
194 // Add view managers created outside of HYDRO module to the map.
195 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
196 createSelector( aViewManager ); // replace the default selector
197 if ( !aHydroViewManagers.contains( aViewManager ) ) {
198 ViewManagerInfo anInfo( aViewManager, VMR_General );
199 myViewManagerMap.insert( ViewManagerId++, anInfo );
205 updateCommandsStatus();
207 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
209 ViewManagerList anOCCViewManagers;
210 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
211 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
212 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
213 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
214 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
215 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
216 if ( aViewFrame && aViewFrame->getViewPort() ) {
217 aViewFrame->getViewPort()->installEventFilter( this );
223 SalomeApp_Study* aStudy =
224 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
226 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
227 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
228 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
229 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
230 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
231 if( !GEOM_var->_is_nil() ) {
232 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
240 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
243 ViewManagerMapIterator anIter( myViewManagerMap );
244 while( anIter.hasNext() )
245 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
246 getApp()->removeViewManager( aViewManager );
247 myViewManagerMap.clear();
250 ViewManagerList anOCCViewManagers;
251 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
252 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
253 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
254 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
258 myObjectStateMap.clear();
263 // clear the data model's list of copying objects
264 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
266 setMenuShown( false );
267 setToolShown( false );
269 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
271 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
273 myActiveOperationMap.clear();
274 return LightApp_Module::deactivateModule( theStudy );
277 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
280 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
281 #ifndef DISABLE_PYCONSOLE
282 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
284 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
287 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
289 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
292 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
296 HYDROGUI_DataModel* aModel = getDataModel();
298 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
299 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
300 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
301 bool anIsVTKView = theClient == SVTK_Viewer::Type();
302 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
305 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
307 bool anIsSelectedDataObjects = false;
308 bool anIsVisibleInSelection = false;
309 bool anIsHiddenInSelection = false;
311 bool anIsImage = false;
312 bool anIsImportedImage = false;
313 bool anIsImageHasRefs = false;
314 bool anIsFusedImage = false;
315 bool anIsCutImage = false;
316 bool anIsSplittedImage = false;
317 bool anIsMustObjectBeUpdated = false;
318 bool anIsPolyline = false;
319 bool anIsPolyline3D = false;
320 bool anIsProfile = false;
321 bool anIsValidProfile = false;
322 bool anAllAreProfiles = false;
323 bool anIsBathymetry = false;
324 bool anIsCalculation = false;
325 bool anIsImmersibleZone = false;
326 bool anIsVisualState = false;
327 bool anIsRegion = false;
328 bool anIsZone = false;
329 bool anIsObstacle = false;
330 bool anIsStream = false;
331 bool anIsChannel = false;
332 bool anIsDigue = false;
333 bool anIsDummyObject3D = false;
334 bool anIsGroup = false;
335 bool anIsObjectCanBeColored = false;
337 // Check the selected GEOM objects (take into account the Object Browser only)
338 if ( anIsObjectBrowser ) {
339 QList<GEOM::shape_type> anObstacleTypes =
340 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
341 QList<GEOM::shape_type> aPolylineTypes =
342 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
344 bool isCanBeImportedAsObstacle =
345 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
346 bool isCanBeImportedAsPolyline =
347 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
349 // Add import as obstacle action
350 if ( isCanBeImportedAsObstacle ) {
351 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
353 // Add import as polyline action
354 if ( isCanBeImportedAsPolyline ) {
355 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
358 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
359 theMenu->addSeparator();
363 // check the selected data model objects
364 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
365 int aNbOfSelectedProfiles = 0;
366 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
368 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
369 if( !anObject.IsNull() )
371 anIsSelectedDataObjects = true;
373 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
374 anIsVisibleInSelection |= aVisibility;
375 anIsHiddenInSelection |= !aVisibility;
377 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
379 anIsMustObjectBeUpdated = true;
382 ObjectKind anObjectKind = anObject->GetKind();
383 if( anObjectKind == KIND_IMAGE )
386 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
387 if( !anImage.IsNull() )
389 anIsImportedImage = anImage->HasLocalPoints();
390 anIsImageHasRefs = anImage->HasReferences();
391 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
393 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
395 QString anOperatorName = anOperator->name();
396 if( anOperatorName == ImageComposer_FuseOperator::Type() )
397 anIsFusedImage = true;
398 else if( anOperatorName == ImageComposer_CutOperator::Type() )
400 else if( anOperatorName == ImageComposer_CropOperator::Type() )
401 anIsSplittedImage = true;
406 else if( anObjectKind == KIND_POLYLINEXY )
408 else if( anObjectKind == KIND_POLYLINE )
409 anIsPolyline3D = true;
410 else if( anObjectKind == KIND_PROFILE )
413 aNbOfSelectedProfiles++;
415 Handle(HYDROData_Profile) aProfile =
416 Handle(HYDROData_Profile)::DownCast( anObject );
417 if( !aProfile.IsNull() && aProfile->IsValid() ) {
418 anIsValidProfile = true;
421 else if( anObjectKind == KIND_CALCULATION )
422 anIsCalculation = true;
423 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
424 anIsImmersibleZone = true;
425 else if( anObjectKind == KIND_VISUAL_STATE )
426 anIsVisualState = true;
427 else if( anObjectKind == KIND_REGION )
429 else if( anObjectKind == KIND_ZONE )
431 else if( anObjectKind == KIND_BATHYMETRY )
432 anIsBathymetry = true;
433 else if( anObjectKind == KIND_OBSTACLE )
435 else if( anObjectKind == KIND_STREAM )
437 else if( anObjectKind == KIND_CHANNEL )
439 else if( anObjectKind == KIND_DIGUE )
441 else if( anObjectKind == KIND_DUMMY_3D )
442 anIsDummyObject3D = true;
443 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
447 if ( !anIsObjectCanBeColored )
448 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
451 // Check if all selected objects are profiles
452 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
453 ( aNbOfSelectedProfiles == aSeq.Length() );
455 // check the selected partitions
456 if( !anIsSelectedDataObjects && anIsObjectBrowser )
458 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
459 if( aSelectedPartition != KIND_UNKNOWN )
461 switch( aSelectedPartition )
464 theMenu->addAction( action( ImportImageId ) );
466 case KIND_BATHYMETRY:
467 theMenu->addAction( action( ImportBathymetryId ) );
469 case KIND_ARTIFICIAL_OBJECT:
470 theMenu->addAction( action( CreateChannelId ) );
471 theMenu->addAction( action( CreateDigueId ) );
473 case KIND_NATURAL_OBJECT:
474 theMenu->addAction( action( CreateImmersibleZoneId ) );
475 theMenu->addAction( action( CreateStreamId ) );
478 theMenu->addAction( action( ImportObstacleFromFileId ) );
479 theMenu->addAction( action( CreateBoxId ) );
480 theMenu->addAction( action( CreateCylinderId ) );
482 case KIND_CALCULATION:
483 theMenu->addAction( action( CreateCalculationId ) );
485 case KIND_POLYLINEXY:
486 theMenu->addAction( action( CreatePolylineId ) );
489 theMenu->addAction( action( CreatePolyline3DId ) );
492 theMenu->addAction( action( CreateProfileId ) );
493 theMenu->addAction( action( ImportProfilesId ) );
494 theMenu->addAction( action( AllGeoreferencementId ) );
496 case KIND_VISUAL_STATE:
497 theMenu->addAction( action( SaveVisualStateId ) );
500 theMenu->addSeparator();
504 if( anIsSelectedDataObjects )
506 if ( anIsMustObjectBeUpdated )
508 theMenu->addAction( action( UpdateObjectId ) );
509 theMenu->addSeparator();
513 theMenu->addAction( action( ForcedUpdateObjectId ) );
514 theMenu->addSeparator();
518 if( aSeq.Length() == 1 )
522 if( anIsImportedImage )
523 theMenu->addAction( action( EditImportedImageId ) );
524 else if( anIsImageHasRefs )
527 theMenu->addAction( action( EditFusedImageId ) );
528 else if( anIsCutImage )
529 theMenu->addAction( action( EditCutImageId ) );
530 else if( anIsSplittedImage )
531 theMenu->addAction( action( EditSplittedImageId ) );
534 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
535 theMenu->addAction( action( ExportImageId ) );
536 theMenu->addSeparator();
538 if( anIsImageHasRefs )
540 theMenu->addAction( action( RemoveImageRefsId ) );
541 theMenu->addSeparator();
544 theMenu->addAction( action( FuseImagesId ) );
545 theMenu->addAction( action( CutImagesId ) );
546 theMenu->addAction( action( SplitImageId ) );
547 theMenu->addSeparator();
549 else if( anIsBathymetry )
551 theMenu->addAction( action( EditImportedBathymetryId ) );
552 theMenu->addAction( action( BathymetryBoundsId ) );
553 theMenu->addSeparator();
555 else if( anIsPolyline )
557 theMenu->addAction( action( EditPolylineId ) );
558 theMenu->addSeparator();
560 else if( anIsPolyline3D )
562 theMenu->addAction( action( EditPolyline3DId ) );
563 theMenu->addSeparator();
565 else if( anIsProfile )
567 theMenu->addAction( action( EditProfileId ) );
568 theMenu->addAction( action( SelectedGeoreferencementId ) );
569 theMenu->addSeparator();
571 else if( anIsCalculation )
573 theMenu->addAction( action( EditCalculationId ) );
574 theMenu->addAction( action( ExportCalculationId ) );
575 theMenu->addSeparator();
577 else if( anIsImmersibleZone )
579 theMenu->addAction( action( EditImmersibleZoneId ) );
580 theMenu->addSeparator();
582 else if( anIsStream )
584 theMenu->addAction( action( EditStreamId ) );
585 theMenu->addSeparator();
587 else if( anIsChannel )
589 theMenu->addAction( action( EditChannelId ) );
590 theMenu->addSeparator();
594 theMenu->addAction( action( EditDigueId ) );
595 theMenu->addSeparator();
597 else if( anIsObstacle )
599 theMenu->addAction( action( TranslateObstacleId ) );
600 theMenu->addSeparator();
602 else if( anIsVisualState && anIsObjectBrowser )
604 theMenu->addAction( action( SaveVisualStateId ) );
605 theMenu->addAction( action( LoadVisualStateId ) );
606 theMenu->addSeparator();
609 // Add set color action for geometrical objects
610 if ( anIsObjectCanBeColored )
612 theMenu->addAction( action( SetColorId ) );
613 theMenu->addSeparator();
615 } else if ( anAllAreProfiles ) {
616 theMenu->addAction( action( SelectedGeoreferencementId ) );
617 theMenu->addSeparator();
621 QAction* aCopyAction = action( CopyId );
622 if( aCopyAction && aCopyAction->isEnabled() ) {
623 theMenu->addAction( action( CopyId ) );
624 theMenu->addSeparator();
628 if( !anIsDummyObject3D )
629 theMenu->addAction( action( DeleteId ) );
631 theMenu->addSeparator();
633 if( anIsImage || anIsPolyline || anIsPolyline3D ||
634 anIsImmersibleZone || anIsZone || anIsRegion ||
635 anIsBathymetry || anIsObstacle || anIsStream ||
636 anIsChannel || anIsDigue || anIsDummyObject3D ||
637 anIsValidProfile || anIsGroup )
639 if( anIsHiddenInSelection )
640 theMenu->addAction( action( ShowId ) );
641 theMenu->addAction( action( ShowOnlyId ) );
642 if( anIsVisibleInSelection )
643 theMenu->addAction( action( HideId ) );
644 theMenu->addSeparator();
650 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
651 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
652 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
653 theMenu->addAction( action( DeleteId ) );
655 theMenu->addSeparator();
656 theMenu->addAction( action( SetZLevelId ) );
657 theMenu->addSeparator();
660 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
662 theMenu->addAction( action( ShowAllId ) );
663 theMenu->addAction( action( HideAllId ) );
664 theMenu->addSeparator();
667 if ( anIsOCCView || anIsVTKView )
669 theMenu->addSeparator();
670 theMenu->addAction( action( CopyViewerPositionId ) );
674 void HYDROGUI_Module::update( const int flags )
676 if( !isUpdateEnabled() )
679 QApplication::setOverrideCursor( Qt::WaitCursor );
681 // To prevent calling this method recursively
682 // from one of the methods called below
683 setUpdateEnabled( false );
685 // store selected objects
686 QStringList aSelectedEntries = storeSelection();
688 bool aDoFitAll = flags & UF_FitAll;
689 if( ( flags & UF_Viewer ) )
690 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
692 if( ( flags & UF_OCCViewer ) )
693 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
695 if( ( flags & UF_VTKViewer ) )
696 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
698 if( ( flags & UF_Model ) && getDataModel() && getApp() )
700 getDataModel()->update( getStudyId() );
702 // Temporary workaround to prevent breaking
703 // the selection in the object browser.
704 // Note: processEvents() should be called after updateGV(),
705 // otherwise the application crashes from time to time.
706 //RKV: qApp->processEvents();
707 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
708 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
709 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
710 if ( isResizeOnExpandItem && anObjectBrowser ) {
711 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
713 getApp()->updateObjectBrowser( true );
714 if ( isResizeOnExpandItem && anObjectBrowser ) {
715 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
719 // Object browser is currently updated by using UF_Model flag
720 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
721 getApp()->updateObjectBrowser( true );
723 if( ( flags & UF_Controls ) && getApp() )
724 getApp()->updateActions();
726 // restore selected objects
727 restoreSelection( aSelectedEntries );
729 setUpdateEnabled( true );
731 QApplication::restoreOverrideCursor();
734 void HYDROGUI_Module::updateCommandsStatus()
736 LightApp_Module::updateCommandsStatus();
738 updateUndoRedoControls();
740 action( CopyId )->setEnabled( getDataModel()->canCopy() );
741 action( PasteId )->setEnabled( getDataModel()->canPaste() );
744 void HYDROGUI_Module::selectionChanged()
746 LightApp_Module::selectionChanged();
747 updateCommandsStatus();
750 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
752 return (HYDROGUI_DataModel*)dataModel();
755 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
760 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
762 return myOCCDisplayer;
765 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
767 return myVTKDisplayer;
770 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
772 if( myViewManagerMap.contains( theId ) )
774 return myViewManagerMap[ theId ].first;
779 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
781 if( myViewManagerMap.contains( theId ) )
783 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
784 GraphicsView_ViewManager* aViewManager =
785 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
787 return aViewManager->getViewer();
792 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
794 if( myViewManagerMap.contains( theId ) )
796 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
797 OCCViewer_ViewManager* aViewManager =
798 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
800 return aViewManager->getOCCViewer();
805 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
807 if( myViewManagerMap.contains( theId ) )
809 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
810 SVTK_ViewManager* aViewManager =
811 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
813 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
818 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
820 ViewManagerMapIterator anIter( myViewManagerMap );
821 while( anIter.hasNext() )
823 int anId = anIter.next().key();
824 const ViewManagerInfo& anInfo = anIter.value();
825 if( anInfo.first == theViewManager )
831 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
833 int anId = getViewManagerId( theViewManager );
836 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
837 return anInfo.second;
842 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
843 const ViewManagerRole theRole )
845 int anId = getViewManagerId( theViewManager );
848 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
849 anInfo.second = theRole;
853 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
854 const Handle(HYDROData_Entity)& theObject ) const
856 if( theObject.IsNull() )
859 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
860 if( anIter1 != myObjectStateMap.end() )
862 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
863 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
865 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
866 if( anIter2 != aEntry2ObjectStateMap.end() )
868 const ObjectState& anObjectState = anIter2.value();
869 return anObjectState.Visibility;
875 void HYDROGUI_Module::setObjectVisible( const int theViewId,
876 const Handle(HYDROData_Entity)& theObject,
877 const bool theState )
879 if( !theObject.IsNull() )
881 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
882 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
884 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
885 anObjectState.Visibility = theState;
887 // Remember the display order ( needed for Z layers assignment only )
888 QStringList& anObjectEntries = myObjectDisplayOrderMap[ theViewId ];
889 anObjectEntries.removeAll( anEntry );
891 anObjectEntries.append( anEntry );
896 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
897 const bool theState )
899 if( !theObject.IsNull() )
901 // Process OCC shapes
902 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
903 while( aShapesMapIter != myShapesMap.end() )
905 const ListOfShapes& aShapesList = aShapesMapIter.value();
906 foreach ( HYDROGUI_Shape* aShape, aShapesList )
908 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
910 aShape->setIsToUpdate( theState );
915 // Process VTK shapes
916 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
917 while( aVTKPrsMapIter != myVTKPrsMap.end() )
919 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
920 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
922 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
924 aShape->setIsToUpdate( theState );
932 /////////////////// OCC SHAPES PROCESSING
933 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
934 const Handle(HYDROData_Entity)& theObject ) const
936 HYDROGUI_Shape* aResShape = NULL;
937 if( theObject.IsNull() )
940 if ( myShapesMap.contains( theViewId ) )
942 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
943 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
945 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
956 void HYDROGUI_Module::setObjectShape( const int theViewId,
957 const Handle(HYDROData_Entity)& theObject,
958 HYDROGUI_Shape* theShape )
960 if( theObject.IsNull() )
963 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
964 aViewShapes.append( theShape );
967 void HYDROGUI_Module::removeObjectShape( const int theViewId,
968 const Handle(HYDROData_Entity)& theObject )
970 if ( !myShapesMap.contains( theViewId ) )
973 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
974 Handle(HYDROData_Entity) anObject;
975 for ( int i = 0; i < aViewShapes.length(); )
977 HYDROGUI_Shape* aShape = aViewShapes.at( i );
978 anObject = aShape->getObject();
979 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
982 aViewShapes.removeAt( i );
990 void HYDROGUI_Module::removeViewShapes( const int theViewId )
992 if ( !myShapesMap.contains( theViewId ) )
995 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
996 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
998 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1003 myShapesMap.remove( theViewId );
1005 /////////////////// END OF OCC SHAPES PROCESSING
1007 /////////////////// VTKPrs PROCESSING
1008 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1009 const Handle(HYDROData_Entity)& theObject ) const
1011 HYDROGUI_VTKPrs* aResShape = NULL;
1012 if( theObject.IsNull() )
1015 if ( myVTKPrsMap.contains( theViewId ) )
1017 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1018 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1020 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1031 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1032 const Handle(HYDROData_Entity)& theObject,
1033 HYDROGUI_VTKPrs* theShape )
1035 if( theObject.IsNull() )
1038 if( theShape && theShape->needScalarBar() )
1040 // Compute the new global Z range from the added presentation and the old global Z range.
1041 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1042 double* aRange = theShape->getInternalZRange();
1043 bool anIsUpdate = false;
1044 if ( aRange[0] < aGlobalRange[0] )
1046 aGlobalRange[0] = aRange[0];
1049 if ( aRange[1] > aGlobalRange[1] )
1051 aGlobalRange[1] = aRange[1];
1057 updateVTKZRange( theViewId, aGlobalRange );
1061 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1062 aViewShapes.append( theShape );
1065 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1066 const QString& theEntry )
1068 if ( !myVTKPrsMap.contains( theViewId ) )
1071 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1072 Handle(HYDROData_Entity) anObject;
1074 for ( int i = 0; i < aViewShapes.length(); )
1076 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1077 anObject = aShape->getObject();
1078 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1079 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1082 aViewShapes.removeAt( i );
1089 // Invalidate global Z range
1090 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1091 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1094 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1095 const Handle(HYDROData_Entity)& theObject )
1097 if ( !myVTKPrsMap.contains( theViewId ) )
1100 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1101 Handle(HYDROData_Entity) anObject;
1102 for ( int i = 0; i < aViewShapes.length(); )
1104 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1105 anObject = aShape->getObject();
1106 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1109 aViewShapes.removeAt( i );
1116 // Invalidate global Z range
1117 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1118 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1121 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1123 if ( !myVTKPrsMap.contains( theViewId ) )
1126 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1127 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1129 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1134 myVTKPrsMap.remove( theViewId );
1137 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1139 if ( myVTKPrsMap.contains( theViewId ) )
1141 // For the given viewer id update all VTK presentations ...
1142 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1143 HYDROGUI_VTKPrs* aShape;
1144 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1146 aShape = aViewShapes.at( i );
1147 if ( aShape && aShape->needScalarBar() )
1149 aShape->setZRange( theRange );
1153 // ... and update the global color legend scalar bar.
1154 getVTKDisplayer()->SetZRange( theViewId, theRange );
1156 /////////////////// END OF VTKPrs PROCESSING
1158 CAM_DataModel* HYDROGUI_Module::createDataModel()
1160 return new HYDROGUI_DataModel( this );
1163 void HYDROGUI_Module::customEvent( QEvent* e )
1165 int aType = e->type();
1166 if ( aType == NewViewEvent )
1168 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1169 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1171 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1173 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1174 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1176 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1178 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1179 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1181 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1182 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1183 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1185 //ouv: temporarily commented
1186 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1189 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1190 update( UF_Viewer );
1192 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1198 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1200 QEvent::Type aType = theEvent->type();
1201 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1203 if( aType == QEvent::Show )
1205 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1206 e->setData( theObj );
1207 QApplication::postEvent( this, e );
1208 theObj->removeEventFilter( this );
1211 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1213 if( aType == QEvent::Leave )
1215 SUIT_Desktop* aDesktop = getApp()->desktop();
1216 if ( aDesktop && aDesktop->statusBar() ) {
1217 aDesktop->statusBar()->clearMessage();
1221 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1223 if( aType == QEvent::Leave )
1225 SUIT_Desktop* aDesktop = getApp()->desktop();
1226 if ( aDesktop && aDesktop->statusBar() ) {
1227 aDesktop->statusBar()->clearMessage();
1232 return LightApp_Module::eventFilter( theObj, theEvent );
1235 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1237 LightApp_Module::onViewManagerAdded( theViewManager );
1239 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1241 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1242 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1244 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1246 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1247 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1248 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1249 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1251 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1253 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1254 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1255 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1256 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1259 createSelector( theViewManager ); // replace the default selector
1261 ViewManagerInfo anInfo( theViewManager, VMR_General );
1262 myViewManagerMap.insert( ViewManagerId++, anInfo );
1265 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1267 LightApp_Module::onViewManagerRemoved( theViewManager );
1269 createSelector( theViewManager ); // replace the default selector
1271 int anId = getViewManagerId( theViewManager );
1274 OCCViewer_ViewManager* anOCCViewManager =
1275 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1276 if ( anOCCViewManager )
1278 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1280 removeViewShapes( (size_t)anOCCViewer );
1283 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1285 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1288 getVTKDisplayer()->EraseScalarBar( anId, true );
1289 removeViewShapes( (size_t)aVTKViewer );
1293 myViewManagerMap.remove( anId );
1297 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1299 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1301 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1303 aViewFrame->installEventFilter( this );
1305 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1307 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1308 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1311 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1313 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1315 aViewFrame->onTopView();
1317 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1319 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1321 aViewPort->installEventFilter( this );
1325 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1327 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1329 aViewFrame->installEventFilter( this );
1334 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1336 /* ouv: currently unused
1337 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1339 SUIT_ViewManager* aViewManager = 0;
1341 QObject* aParent = aViewPort;
1342 while( aParent = aParent->parent() )
1344 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1346 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1348 aViewManager = aViewer->getViewManager();
1357 double aMouseX = theEvent->scenePos().x();
1358 double aMouseY = theEvent->scenePos().y();
1360 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1361 if( aRole == VMR_General )
1363 int aXDeg = 0, aYDeg = 0;
1364 int aXMin = 0, aYMin = 0;
1365 double aXSec = 0, aYSec = 0;
1366 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1367 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1369 QString aDegSymbol( QChar( 0x00B0 ) );
1370 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1371 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1373 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1375 else if( aRole == VMR_TransformImage )
1376 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1381 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1382 const bool theIsInit,
1383 const bool theIsForced,
1384 const bool theDoFitAll )
1386 QList<int> aViewManagerIdList;
1388 // currently, all views are updated
1389 ViewManagerMapIterator anIter( myViewManagerMap );
1390 while( anIter.hasNext() )
1392 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1394 if ( theDisplayer->IsApplicable( aViewManager ) )
1396 int anId = anIter.key();
1397 aViewManagerIdList.append( anId );
1401 QListIterator<int> anIdIter( aViewManagerIdList );
1402 while( anIdIter.hasNext() )
1404 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1408 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1410 if( !theViewManager )
1413 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1414 if( !aSelectionMgr )
1417 QString aViewType = theViewManager->getType();
1418 if( aViewType != GraphicsView_Viewer::Type() &&
1419 aViewType != OCCViewer_Viewer::Type())
1422 QList<SUIT_Selector*> aSelectorList;
1423 aSelectionMgr->selectors( aViewType, aSelectorList );
1425 // disable all alien selectors
1426 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1427 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1429 SUIT_Selector* aSelector = *anIter;
1430 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1431 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1432 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1433 aSelector->setEnabled( false );
1436 if ( aViewType == GraphicsView_Viewer::Type() )
1438 GraphicsView_ViewManager* aViewManager =
1439 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1441 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1443 else if ( aViewType == OCCViewer_Viewer::Type() )
1445 OCCViewer_ViewManager* aViewManager =
1446 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1448 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1452 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1454 bool aPrevState = myIsUpdateEnabled;
1455 myIsUpdateEnabled = theState;
1459 bool HYDROGUI_Module::isUpdateEnabled() const
1461 return myIsUpdateEnabled;
1464 QStringList HYDROGUI_Module::storeSelection() const
1466 QStringList anEntryList;
1467 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1469 SUIT_DataOwnerPtrList aList( true );
1470 aSelectionMgr->selected( aList );
1472 SUIT_DataOwnerPtrList::iterator anIter;
1473 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1475 const LightApp_DataOwner* anOwner =
1476 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1478 anEntryList.append( anOwner->entry() );
1484 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1486 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1488 SUIT_DataOwnerPtrList aList( true );
1489 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1490 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1491 aSelectionMgr->setSelected( aList );
1495 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1498 bool doShow = false;
1499 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1501 aDisplayer->SaveCursorViewPosition( theViewWindow );
1502 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, aX, aY, aZ );
1506 // Show the coordinates in the status bar
1507 SUIT_Desktop* aDesktop = getApp()->desktop();
1508 if ( aDesktop && aDesktop->statusBar() ) {
1509 QString aXStr = HYDROGUI_Tool::GetCoordinateString( aX );
1510 QString anYStr = HYDROGUI_Tool::GetCoordinateString( aY );
1511 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aXStr ).arg( anYStr ) );
1517 * Get the object display order. Needed for Z layers assignment only.
1519 int HYDROGUI_Module::getObjectDisplayOrder(
1520 const int theViewId, const Handle(HYDROData_Entity)& theObject) const
1522 if( theObject.IsNull() )
1525 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1526 QStringList anObjectEntries = myObjectDisplayOrderMap.value( theViewId );
1528 return anObjectEntries.indexOf( anEntry );
1532 * Returns stack of active operations;
1534 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1536 return myActiveOperationMap;
1540 * Returns the module active operation. If the active operation is show/hide,
1541 * the method returns the previous operation if it is.
1543 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1545 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1547 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1549 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1551 aVIt.previous(); // skip the top show/hide operation
1552 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;