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 ) );
656 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
658 theMenu->addAction( action( ShowAllId ) );
659 theMenu->addAction( action( HideAllId ) );
660 theMenu->addSeparator();
662 if ( anIsOCCView || anIsVTKView ) {
663 theMenu->addSeparator();
664 theMenu->addAction( action( CopyViewerPositionId ) );
668 void HYDROGUI_Module::update( const int flags )
670 if( !isUpdateEnabled() )
673 QApplication::setOverrideCursor( Qt::WaitCursor );
675 // To prevent calling this method recursively
676 // from one of the methods called below
677 setUpdateEnabled( false );
679 // store selected objects
680 QStringList aSelectedEntries = storeSelection();
682 bool aDoFitAll = flags & UF_FitAll;
683 if( ( flags & UF_Viewer ) )
684 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
686 if( ( flags & UF_OCCViewer ) )
687 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
689 if( ( flags & UF_VTKViewer ) )
690 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
692 if( ( flags & UF_Model ) && getDataModel() && getApp() )
694 getDataModel()->update( getStudyId() );
696 // Temporary workaround to prevent breaking
697 // the selection in the object browser.
698 // Note: processEvents() should be called after updateGV(),
699 // otherwise the application crashes from time to time.
700 //RKV: qApp->processEvents();
701 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
702 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
703 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
704 if ( isResizeOnExpandItem && anObjectBrowser ) {
705 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
707 getApp()->updateObjectBrowser( true );
708 if ( isResizeOnExpandItem && anObjectBrowser ) {
709 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
713 // Object browser is currently updated by using UF_Model flag
714 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
715 getApp()->updateObjectBrowser( true );
717 if( ( flags & UF_Controls ) && getApp() )
718 getApp()->updateActions();
720 // restore selected objects
721 restoreSelection( aSelectedEntries );
723 setUpdateEnabled( true );
725 QApplication::restoreOverrideCursor();
728 void HYDROGUI_Module::updateCommandsStatus()
730 LightApp_Module::updateCommandsStatus();
732 updateUndoRedoControls();
734 action( CopyId )->setEnabled( getDataModel()->canCopy() );
735 action( PasteId )->setEnabled( getDataModel()->canPaste() );
738 void HYDROGUI_Module::selectionChanged()
740 LightApp_Module::selectionChanged();
741 updateCommandsStatus();
744 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
746 return (HYDROGUI_DataModel*)dataModel();
749 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
754 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
756 return myOCCDisplayer;
759 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
761 return myVTKDisplayer;
764 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
766 if( myViewManagerMap.contains( theId ) )
768 return myViewManagerMap[ theId ].first;
773 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
775 if( myViewManagerMap.contains( theId ) )
777 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
778 GraphicsView_ViewManager* aViewManager =
779 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
781 return aViewManager->getViewer();
786 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
788 if( myViewManagerMap.contains( theId ) )
790 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
791 OCCViewer_ViewManager* aViewManager =
792 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
794 return aViewManager->getOCCViewer();
799 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
801 if( myViewManagerMap.contains( theId ) )
803 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
804 SVTK_ViewManager* aViewManager =
805 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
807 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
812 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
814 ViewManagerMapIterator anIter( myViewManagerMap );
815 while( anIter.hasNext() )
817 int anId = anIter.next().key();
818 const ViewManagerInfo& anInfo = anIter.value();
819 if( anInfo.first == theViewManager )
825 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
827 int anId = getViewManagerId( theViewManager );
830 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
831 return anInfo.second;
836 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
837 const ViewManagerRole theRole )
839 int anId = getViewManagerId( theViewManager );
842 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
843 anInfo.second = theRole;
847 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
848 const Handle(HYDROData_Entity)& theObject ) const
850 if( theObject.IsNull() )
853 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
854 if( anIter1 != myObjectStateMap.end() )
856 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
857 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
859 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
860 if( anIter2 != aEntry2ObjectStateMap.end() )
862 const ObjectState& anObjectState = anIter2.value();
863 return anObjectState.Visibility;
869 void HYDROGUI_Module::setObjectVisible( const int theViewId,
870 const Handle(HYDROData_Entity)& theObject,
871 const bool theState )
873 if( !theObject.IsNull() )
875 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
876 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
878 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
879 anObjectState.Visibility = theState;
881 // Remember the display order ( needed for Z layers assignment only )
882 QStringList& anObjectEntries = myObjectDisplayOrderMap[ theViewId ];
883 anObjectEntries.removeAll( anEntry );
885 anObjectEntries.append( anEntry );
890 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
891 const bool theState )
893 if( !theObject.IsNull() )
895 // Process OCC shapes
896 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
897 while( aShapesMapIter != myShapesMap.end() )
899 const ListOfShapes& aShapesList = aShapesMapIter.value();
900 foreach ( HYDROGUI_Shape* aShape, aShapesList )
902 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
904 aShape->setIsToUpdate( theState );
909 // Process VTK shapes
910 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
911 while( aVTKPrsMapIter != myVTKPrsMap.end() )
913 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
914 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
916 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
918 aShape->setIsToUpdate( theState );
926 /////////////////// OCC SHAPES PROCESSING
927 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
928 const Handle(HYDROData_Entity)& theObject ) const
930 HYDROGUI_Shape* aResShape = NULL;
931 if( theObject.IsNull() )
934 if ( myShapesMap.contains( theViewId ) )
936 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
937 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
939 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
950 void HYDROGUI_Module::setObjectShape( const int theViewId,
951 const Handle(HYDROData_Entity)& theObject,
952 HYDROGUI_Shape* theShape )
954 if( theObject.IsNull() )
957 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
958 aViewShapes.append( theShape );
961 void HYDROGUI_Module::removeObjectShape( const int theViewId,
962 const Handle(HYDROData_Entity)& theObject )
964 if ( !myShapesMap.contains( theViewId ) )
967 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
968 Handle(HYDROData_Entity) anObject;
969 for ( int i = 0; i < aViewShapes.length(); )
971 HYDROGUI_Shape* aShape = aViewShapes.at( i );
972 anObject = aShape->getObject();
973 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
976 aViewShapes.removeAt( i );
984 void HYDROGUI_Module::removeViewShapes( const int theViewId )
986 if ( !myShapesMap.contains( theViewId ) )
989 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
990 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
992 HYDROGUI_Shape* aShape = aViewShapes.at( i );
997 myShapesMap.remove( theViewId );
999 /////////////////// END OF OCC SHAPES PROCESSING
1001 /////////////////// VTKPrs PROCESSING
1002 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1003 const Handle(HYDROData_Entity)& theObject ) const
1005 HYDROGUI_VTKPrs* aResShape = NULL;
1006 if( theObject.IsNull() )
1009 if ( myVTKPrsMap.contains( theViewId ) )
1011 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1012 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1014 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1025 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1026 const Handle(HYDROData_Entity)& theObject,
1027 HYDROGUI_VTKPrs* theShape )
1029 if( theObject.IsNull() )
1032 if( theShape && theShape->needScalarBar() )
1034 // Compute the new global Z range from the added presentation and the old global Z range.
1035 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1036 double* aRange = theShape->getInternalZRange();
1037 bool anIsUpdate = false;
1038 if ( aRange[0] < aGlobalRange[0] )
1040 aGlobalRange[0] = aRange[0];
1043 if ( aRange[1] > aGlobalRange[1] )
1045 aGlobalRange[1] = aRange[1];
1051 updateVTKZRange( theViewId, aGlobalRange );
1055 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1056 aViewShapes.append( theShape );
1059 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1060 const QString& theEntry )
1062 if ( !myVTKPrsMap.contains( theViewId ) )
1065 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1066 Handle(HYDROData_Entity) anObject;
1068 for ( int i = 0; i < aViewShapes.length(); )
1070 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1071 anObject = aShape->getObject();
1072 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1073 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1076 aViewShapes.removeAt( i );
1083 // Invalidate global Z range
1084 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1085 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1088 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1089 const Handle(HYDROData_Entity)& theObject )
1091 if ( !myVTKPrsMap.contains( theViewId ) )
1094 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1095 Handle(HYDROData_Entity) anObject;
1096 for ( int i = 0; i < aViewShapes.length(); )
1098 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1099 anObject = aShape->getObject();
1100 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1103 aViewShapes.removeAt( i );
1110 // Invalidate global Z range
1111 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1112 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1115 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1117 if ( !myVTKPrsMap.contains( theViewId ) )
1120 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1121 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1123 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1128 myVTKPrsMap.remove( theViewId );
1131 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1133 if ( myVTKPrsMap.contains( theViewId ) )
1135 // For the given viewer id update all VTK presentations ...
1136 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1137 HYDROGUI_VTKPrs* aShape;
1138 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1140 aShape = aViewShapes.at( i );
1141 if ( aShape && aShape->needScalarBar() )
1143 aShape->setZRange( theRange );
1147 // ... and update the global color legend scalar bar.
1148 getVTKDisplayer()->SetZRange( theViewId, theRange );
1150 /////////////////// END OF VTKPrs PROCESSING
1152 CAM_DataModel* HYDROGUI_Module::createDataModel()
1154 return new HYDROGUI_DataModel( this );
1157 void HYDROGUI_Module::customEvent( QEvent* e )
1159 int aType = e->type();
1160 if ( aType == NewViewEvent )
1162 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1163 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1165 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1167 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1168 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1170 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1172 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1173 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1175 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1176 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1177 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1179 //ouv: temporarily commented
1180 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1183 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1184 update( UF_Viewer );
1186 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1192 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1194 QEvent::Type aType = theEvent->type();
1195 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1197 if( aType == QEvent::Show )
1199 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1200 e->setData( theObj );
1201 QApplication::postEvent( this, e );
1202 theObj->removeEventFilter( this );
1205 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1207 if( aType == QEvent::Leave )
1209 SUIT_Desktop* aDesktop = getApp()->desktop();
1210 if ( aDesktop && aDesktop->statusBar() ) {
1211 aDesktop->statusBar()->clearMessage();
1215 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1217 if( aType == QEvent::Leave )
1219 SUIT_Desktop* aDesktop = getApp()->desktop();
1220 if ( aDesktop && aDesktop->statusBar() ) {
1221 aDesktop->statusBar()->clearMessage();
1226 return LightApp_Module::eventFilter( theObj, theEvent );
1229 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1231 LightApp_Module::onViewManagerAdded( theViewManager );
1233 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1235 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1236 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1238 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1240 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1241 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1242 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1243 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1245 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1247 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1248 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1249 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1250 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1253 createSelector( theViewManager ); // replace the default selector
1255 ViewManagerInfo anInfo( theViewManager, VMR_General );
1256 myViewManagerMap.insert( ViewManagerId++, anInfo );
1259 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1261 LightApp_Module::onViewManagerRemoved( theViewManager );
1263 createSelector( theViewManager ); // replace the default selector
1265 int anId = getViewManagerId( theViewManager );
1268 OCCViewer_ViewManager* anOCCViewManager =
1269 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1270 if ( anOCCViewManager )
1272 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1274 removeViewShapes( (size_t)anOCCViewer );
1277 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1279 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1282 getVTKDisplayer()->EraseScalarBar( anId, true );
1283 removeViewShapes( (size_t)aVTKViewer );
1287 myViewManagerMap.remove( anId );
1291 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1293 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1295 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1297 aViewFrame->installEventFilter( this );
1299 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1301 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1302 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1305 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1307 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1309 aViewFrame->onTopView();
1311 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1313 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1315 aViewPort->installEventFilter( this );
1319 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1321 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1323 aViewFrame->installEventFilter( this );
1328 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1330 /* ouv: currently unused
1331 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1333 SUIT_ViewManager* aViewManager = 0;
1335 QObject* aParent = aViewPort;
1336 while( aParent = aParent->parent() )
1338 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1340 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1342 aViewManager = aViewer->getViewManager();
1351 double aMouseX = theEvent->scenePos().x();
1352 double aMouseY = theEvent->scenePos().y();
1354 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1355 if( aRole == VMR_General )
1357 int aXDeg = 0, aYDeg = 0;
1358 int aXMin = 0, aYMin = 0;
1359 double aXSec = 0, aYSec = 0;
1360 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1361 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1363 QString aDegSymbol( QChar( 0x00B0 ) );
1364 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1365 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1367 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1369 else if( aRole == VMR_TransformImage )
1370 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1375 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1376 const bool theIsInit,
1377 const bool theIsForced,
1378 const bool theDoFitAll )
1380 QList<int> aViewManagerIdList;
1382 // currently, all views are updated
1383 ViewManagerMapIterator anIter( myViewManagerMap );
1384 while( anIter.hasNext() )
1386 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1388 if ( theDisplayer->IsApplicable( aViewManager ) )
1390 int anId = anIter.key();
1391 aViewManagerIdList.append( anId );
1395 QListIterator<int> anIdIter( aViewManagerIdList );
1396 while( anIdIter.hasNext() )
1398 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1402 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1404 if( !theViewManager )
1407 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1408 if( !aSelectionMgr )
1411 QString aViewType = theViewManager->getType();
1412 if( aViewType != GraphicsView_Viewer::Type() &&
1413 aViewType != OCCViewer_Viewer::Type())
1416 QList<SUIT_Selector*> aSelectorList;
1417 aSelectionMgr->selectors( aViewType, aSelectorList );
1419 // disable all alien selectors
1420 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1421 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1423 SUIT_Selector* aSelector = *anIter;
1424 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1425 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1426 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1427 aSelector->setEnabled( false );
1430 if ( aViewType == GraphicsView_Viewer::Type() )
1432 GraphicsView_ViewManager* aViewManager =
1433 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1435 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1437 else if ( aViewType == OCCViewer_Viewer::Type() )
1439 OCCViewer_ViewManager* aViewManager =
1440 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1442 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1446 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1448 bool aPrevState = myIsUpdateEnabled;
1449 myIsUpdateEnabled = theState;
1453 bool HYDROGUI_Module::isUpdateEnabled() const
1455 return myIsUpdateEnabled;
1458 QStringList HYDROGUI_Module::storeSelection() const
1460 QStringList anEntryList;
1461 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1463 SUIT_DataOwnerPtrList aList( true );
1464 aSelectionMgr->selected( aList );
1466 SUIT_DataOwnerPtrList::iterator anIter;
1467 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1469 const LightApp_DataOwner* anOwner =
1470 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1472 anEntryList.append( anOwner->entry() );
1478 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1480 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1482 SUIT_DataOwnerPtrList aList( true );
1483 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1484 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1485 aSelectionMgr->setSelected( aList );
1489 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1492 bool doShow = false;
1493 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1495 aDisplayer->SaveCursorViewPosition( theViewWindow );
1496 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, aX, aY, aZ );
1500 // Show the coordinates in the status bar
1501 SUIT_Desktop* aDesktop = getApp()->desktop();
1502 if ( aDesktop && aDesktop->statusBar() ) {
1503 QString aXStr = HYDROGUI_Tool::GetCoordinateString( aX );
1504 QString anYStr = HYDROGUI_Tool::GetCoordinateString( aY );
1505 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aXStr ).arg( anYStr ) );
1511 * Get the object display order. Needed for Z layers assignment only.
1513 int HYDROGUI_Module::getObjectDisplayOrder(
1514 const int theViewId, const Handle(HYDROData_Entity)& theObject) const
1516 if( theObject.IsNull() )
1519 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1520 QStringList anObjectEntries = myObjectDisplayOrderMap.value( theViewId );
1522 return anObjectEntries.indexOf( anEntry );
1526 * Returns stack of active operations;
1528 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1530 return myActiveOperationMap;
1534 * Returns the module active operation. If the active operation is show/hide,
1535 * the method returns the previous operation if it is.
1537 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1539 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1541 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1543 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1545 aVIt.previous(); // skip the top show/hide operation
1546 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;