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 myShapesMap.remove( anId );
190 myVTKPrsMap.remove( anId );
192 // Replace the default selector for all view managers.
193 // Add view managers created outside of HYDRO module to the map.
194 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
195 createSelector( aViewManager ); // replace the default selector
196 if ( !aHydroViewManagers.contains( aViewManager ) ) {
197 ViewManagerInfo anInfo( aViewManager, VMR_General );
198 myViewManagerMap.insert( ViewManagerId++, anInfo );
204 updateCommandsStatus();
206 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
208 ViewManagerList anOCCViewManagers;
209 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
210 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
211 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
212 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
213 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
214 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
215 if ( aViewFrame && aViewFrame->getViewPort() ) {
216 aViewFrame->getViewPort()->installEventFilter( this );
222 SalomeApp_Study* aStudy =
223 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
225 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
226 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
227 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
228 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
229 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
230 if( !GEOM_var->_is_nil() ) {
231 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
239 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
242 ViewManagerMapIterator anIter( myViewManagerMap );
243 while( anIter.hasNext() )
244 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
245 getApp()->removeViewManager( aViewManager );
246 myViewManagerMap.clear();
249 ViewManagerList anOCCViewManagers;
250 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
251 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
252 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
253 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
257 myObjectStateMap.clear();
262 // clear the data model's list of copying objects
263 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
265 setMenuShown( false );
266 setToolShown( false );
268 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
270 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
272 myActiveOperationMap.clear();
273 return LightApp_Module::deactivateModule( theStudy );
276 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
279 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
280 #ifndef DISABLE_PYCONSOLE
281 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
283 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
286 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
288 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
291 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
295 HYDROGUI_DataModel* aModel = getDataModel();
297 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
298 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
299 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
300 bool anIsVTKView = theClient == SVTK_Viewer::Type();
301 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
304 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
306 bool anIsSelectedDataObjects = false;
307 bool anIsVisibleInSelection = false;
308 bool anIsHiddenInSelection = false;
310 bool anIsImage = false;
311 bool anIsImportedImage = false;
312 bool anIsImageHasRefs = false;
313 bool anIsFusedImage = false;
314 bool anIsCutImage = false;
315 bool anIsSplittedImage = false;
316 bool anIsMustObjectBeUpdated = false;
317 bool anIsPolyline = false;
318 bool anIsPolyline3D = false;
319 bool anIsProfile = false;
320 bool anIsValidProfile = false;
321 bool anAllAreProfiles = false;
322 bool anIsBathymetry = false;
323 bool anIsCalculation = false;
324 bool anIsImmersibleZone = false;
325 bool anIsVisualState = false;
326 bool anIsRegion = false;
327 bool anIsZone = false;
328 bool anIsObstacle = false;
329 bool anIsStream = false;
330 bool anIsChannel = false;
331 bool anIsDigue = false;
332 bool anIsDummyObject3D = false;
333 bool anIsGroup = false;
334 bool anIsObjectCanBeColored = false;
337 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
338 SUIT_DataOwnerPtrList anOwners;
339 aSelectionMgr->selected( anOwners );
340 if( anIsObjectBrowser && anOwners.size()==1 )
342 QString anEntry = anOwners[0]->keyString();
343 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
345 isRoot = aStudy->isComponent( anEntry );
348 // Check the selected GEOM objects (take into account the Object Browser only)
349 if ( anIsObjectBrowser ) {
350 QList<GEOM::shape_type> anObstacleTypes =
351 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
352 QList<GEOM::shape_type> aPolylineTypes =
353 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
355 bool isCanBeImportedAsObstacle =
356 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
357 bool isCanBeImportedAsPolyline =
358 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
360 // Add import as obstacle action
361 if ( isCanBeImportedAsObstacle ) {
362 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
364 // Add import as polyline action
365 if ( isCanBeImportedAsPolyline ) {
366 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
369 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
370 theMenu->addSeparator();
374 // check the selected data model objects
375 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
376 int aNbOfSelectedProfiles = 0;
377 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
379 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
380 if( !anObject.IsNull() )
382 anIsSelectedDataObjects = true;
384 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
385 anIsVisibleInSelection |= aVisibility;
386 anIsHiddenInSelection |= !aVisibility;
388 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
390 anIsMustObjectBeUpdated = true;
393 ObjectKind anObjectKind = anObject->GetKind();
394 if( anObjectKind == KIND_IMAGE )
397 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
398 if( !anImage.IsNull() )
400 anIsImportedImage = anImage->HasLocalPoints();
401 anIsImageHasRefs = anImage->HasReferences();
402 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
404 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
406 QString anOperatorName = anOperator->name();
407 if( anOperatorName == ImageComposer_FuseOperator::Type() )
408 anIsFusedImage = true;
409 else if( anOperatorName == ImageComposer_CutOperator::Type() )
411 else if( anOperatorName == ImageComposer_CropOperator::Type() )
412 anIsSplittedImage = true;
417 else if( anObjectKind == KIND_POLYLINEXY )
419 else if( anObjectKind == KIND_POLYLINE )
420 anIsPolyline3D = true;
421 else if( anObjectKind == KIND_PROFILE )
424 aNbOfSelectedProfiles++;
426 Handle(HYDROData_Profile) aProfile =
427 Handle(HYDROData_Profile)::DownCast( anObject );
428 if( !aProfile.IsNull() && aProfile->IsValid() ) {
429 anIsValidProfile = true;
432 else if( anObjectKind == KIND_CALCULATION )
433 anIsCalculation = true;
434 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
435 anIsImmersibleZone = true;
436 else if( anObjectKind == KIND_VISUAL_STATE )
437 anIsVisualState = true;
438 else if( anObjectKind == KIND_REGION )
440 else if( anObjectKind == KIND_ZONE )
442 else if( anObjectKind == KIND_BATHYMETRY )
443 anIsBathymetry = true;
444 else if( anObjectKind == KIND_OBSTACLE )
446 else if( anObjectKind == KIND_STREAM )
448 else if( anObjectKind == KIND_CHANNEL )
450 else if( anObjectKind == KIND_DIGUE )
452 else if( anObjectKind == KIND_DUMMY_3D )
453 anIsDummyObject3D = true;
454 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
458 if ( !anIsObjectCanBeColored )
459 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
462 // Check if all selected objects are profiles
463 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
464 ( aNbOfSelectedProfiles == aSeq.Length() );
466 // check the selected partitions
467 if( !anIsSelectedDataObjects && anIsObjectBrowser )
469 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
470 if( aSelectedPartition != KIND_UNKNOWN )
472 switch( aSelectedPartition )
475 theMenu->addAction( action( ImportImageId ) );
477 case KIND_BATHYMETRY:
478 theMenu->addAction( action( ImportBathymetryId ) );
480 case KIND_ARTIFICIAL_OBJECT:
481 theMenu->addAction( action( CreateChannelId ) );
482 theMenu->addAction( action( CreateDigueId ) );
484 case KIND_NATURAL_OBJECT:
485 theMenu->addAction( action( CreateImmersibleZoneId ) );
486 theMenu->addAction( action( CreateStreamId ) );
489 theMenu->addAction( action( ImportObstacleFromFileId ) );
490 theMenu->addAction( action( CreateBoxId ) );
491 theMenu->addAction( action( CreateCylinderId ) );
493 case KIND_CALCULATION:
494 theMenu->addAction( action( CreateCalculationId ) );
496 case KIND_POLYLINEXY:
497 theMenu->addAction( action( CreatePolylineId ) );
500 theMenu->addAction( action( CreatePolyline3DId ) );
503 theMenu->addAction( action( CreateProfileId ) );
504 theMenu->addAction( action( ImportProfilesId ) );
505 theMenu->addAction( action( AllGeoreferencementId ) );
507 case KIND_VISUAL_STATE:
508 theMenu->addAction( action( SaveVisualStateId ) );
511 theMenu->addSeparator();
515 if( anIsSelectedDataObjects )
517 if ( anIsMustObjectBeUpdated )
519 theMenu->addAction( action( UpdateObjectId ) );
520 theMenu->addSeparator();
524 theMenu->addAction( action( ForcedUpdateObjectId ) );
525 theMenu->addSeparator();
529 if( aSeq.Length() == 1 )
533 if( anIsImportedImage )
534 theMenu->addAction( action( EditImportedImageId ) );
535 else if( anIsImageHasRefs )
538 theMenu->addAction( action( EditFusedImageId ) );
539 else if( anIsCutImage )
540 theMenu->addAction( action( EditCutImageId ) );
541 else if( anIsSplittedImage )
542 theMenu->addAction( action( EditSplittedImageId ) );
545 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
546 theMenu->addAction( action( ExportImageId ) );
547 theMenu->addSeparator();
549 if( anIsImageHasRefs )
551 theMenu->addAction( action( RemoveImageRefsId ) );
552 theMenu->addSeparator();
555 theMenu->addAction( action( FuseImagesId ) );
556 theMenu->addAction( action( CutImagesId ) );
557 theMenu->addAction( action( SplitImageId ) );
558 theMenu->addSeparator();
560 else if( anIsBathymetry )
562 theMenu->addAction( action( EditImportedBathymetryId ) );
563 theMenu->addAction( action( BathymetryBoundsId ) );
564 theMenu->addSeparator();
566 else if( anIsPolyline )
568 theMenu->addAction( action( EditPolylineId ) );
569 theMenu->addSeparator();
571 else if( anIsPolyline3D )
573 theMenu->addAction( action( EditPolyline3DId ) );
574 theMenu->addSeparator();
576 else if( anIsProfile )
578 theMenu->addAction( action( EditProfileId ) );
579 theMenu->addAction( action( SelectedGeoreferencementId ) );
580 theMenu->addSeparator();
582 else if( anIsCalculation )
584 theMenu->addAction( action( EditCalculationId ) );
585 theMenu->addAction( action( ExportCalculationId ) );
586 theMenu->addSeparator();
588 else if( anIsImmersibleZone )
590 theMenu->addAction( action( EditImmersibleZoneId ) );
591 theMenu->addSeparator();
593 else if( anIsStream )
595 theMenu->addAction( action( EditStreamId ) );
596 theMenu->addSeparator();
598 else if( anIsChannel )
600 theMenu->addAction( action( EditChannelId ) );
601 theMenu->addSeparator();
605 theMenu->addAction( action( EditDigueId ) );
606 theMenu->addSeparator();
608 else if( anIsObstacle )
610 theMenu->addAction( action( TranslateObstacleId ) );
611 theMenu->addSeparator();
613 else if( anIsVisualState && anIsObjectBrowser )
615 theMenu->addAction( action( SaveVisualStateId ) );
616 theMenu->addAction( action( LoadVisualStateId ) );
617 theMenu->addSeparator();
620 // Add set color action for geometrical objects
621 if ( anIsObjectCanBeColored )
623 theMenu->addAction( action( SetColorId ) );
624 theMenu->addSeparator();
626 } else if ( anAllAreProfiles ) {
627 theMenu->addAction( action( SelectedGeoreferencementId ) );
628 theMenu->addSeparator();
632 QAction* aCopyAction = action( CopyId );
633 if( aCopyAction && aCopyAction->isEnabled() ) {
634 theMenu->addAction( action( CopyId ) );
635 theMenu->addSeparator();
639 if( !anIsDummyObject3D )
640 theMenu->addAction( action( DeleteId ) );
642 theMenu->addSeparator();
644 if( anIsImage || anIsPolyline || anIsPolyline3D ||
645 anIsImmersibleZone || anIsZone || anIsRegion ||
646 anIsBathymetry || anIsObstacle || anIsStream ||
647 anIsChannel || anIsDigue || anIsDummyObject3D ||
648 anIsValidProfile || anIsGroup )
650 if( anIsHiddenInSelection )
651 theMenu->addAction( action( ShowId ) );
652 theMenu->addAction( action( ShowOnlyId ) );
653 if( anIsVisibleInSelection )
654 theMenu->addAction( action( HideId ) );
655 theMenu->addSeparator();
661 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
662 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
663 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
664 theMenu->addAction( action( DeleteId ) );
666 theMenu->addSeparator();
667 theMenu->addAction( action( SetZLevelId ) );
668 theMenu->addSeparator();
671 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
673 theMenu->addAction( action( ShowAllId ) );
674 theMenu->addAction( action( HideAllId ) );
675 theMenu->addSeparator();
678 if ( anIsOCCView || anIsVTKView )
680 theMenu->addSeparator();
681 theMenu->addAction( action( CopyViewerPositionId ) );
685 theMenu->addAction( action( EditLocalCSId ) );
688 void HYDROGUI_Module::update( const int flags )
690 if( !isUpdateEnabled() )
693 QApplication::setOverrideCursor( Qt::WaitCursor );
695 // To prevent calling this method recursively
696 // from one of the methods called below
697 setUpdateEnabled( false );
699 // store selected objects
700 QStringList aSelectedEntries = storeSelection();
702 bool aDoFitAll = flags & UF_FitAll;
703 if( ( flags & UF_Viewer ) )
704 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
706 if( ( flags & UF_OCCViewer ) )
707 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
709 if( ( flags & UF_VTKViewer ) )
710 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
712 if( ( flags & UF_Model ) && getDataModel() && getApp() )
714 getDataModel()->update( getStudyId() );
716 // Temporary workaround to prevent breaking
717 // the selection in the object browser.
718 // Note: processEvents() should be called after updateGV(),
719 // otherwise the application crashes from time to time.
720 //RKV: qApp->processEvents();
721 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
722 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
723 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
724 if ( isResizeOnExpandItem && anObjectBrowser ) {
725 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
727 getApp()->updateObjectBrowser( true );
728 if ( isResizeOnExpandItem && anObjectBrowser ) {
729 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
733 // Object browser is currently updated by using UF_Model flag
734 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
735 getApp()->updateObjectBrowser( true );
737 if( ( flags & UF_Controls ) && getApp() )
738 getApp()->updateActions();
740 // restore selected objects
741 restoreSelection( aSelectedEntries );
743 setUpdateEnabled( true );
745 QApplication::restoreOverrideCursor();
748 void HYDROGUI_Module::updateCommandsStatus()
750 LightApp_Module::updateCommandsStatus();
752 updateUndoRedoControls();
754 action( CopyId )->setEnabled( getDataModel()->canCopy() );
755 action( PasteId )->setEnabled( getDataModel()->canPaste() );
758 void HYDROGUI_Module::selectionChanged()
760 LightApp_Module::selectionChanged();
761 updateCommandsStatus();
764 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
766 return (HYDROGUI_DataModel*)dataModel();
769 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
774 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
776 return myOCCDisplayer;
779 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
781 return myVTKDisplayer;
784 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
786 if( myViewManagerMap.contains( theId ) )
788 return myViewManagerMap[ theId ].first;
793 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
795 if( myViewManagerMap.contains( theId ) )
797 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
798 GraphicsView_ViewManager* aViewManager =
799 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
801 return aViewManager->getViewer();
806 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
808 if( myViewManagerMap.contains( theId ) )
810 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
811 OCCViewer_ViewManager* aViewManager =
812 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
814 return aViewManager->getOCCViewer();
819 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
821 if( myViewManagerMap.contains( theId ) )
823 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
824 SVTK_ViewManager* aViewManager =
825 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
827 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
832 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
834 ViewManagerMapIterator anIter( myViewManagerMap );
835 while( anIter.hasNext() )
837 int anId = anIter.next().key();
838 const ViewManagerInfo& anInfo = anIter.value();
839 if( anInfo.first == theViewManager )
845 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
847 int anId = getViewManagerId( theViewManager );
850 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
851 return anInfo.second;
856 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
857 const ViewManagerRole theRole )
859 int anId = getViewManagerId( theViewManager );
862 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
863 anInfo.second = theRole;
867 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
868 const Handle(HYDROData_Entity)& theObject ) const
870 if( theObject.IsNull() )
873 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
874 if( anIter1 != myObjectStateMap.end() )
876 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
877 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
879 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
880 if( anIter2 != aEntry2ObjectStateMap.end() )
882 const ObjectState& anObjectState = anIter2.value();
883 return anObjectState.Visibility;
889 void HYDROGUI_Module::setObjectVisible( const int theViewId,
890 const Handle(HYDROData_Entity)& theObject,
891 const bool theState )
893 if( !theObject.IsNull() )
895 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
896 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
898 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
899 anObjectState.Visibility = theState;
903 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
904 const bool theState )
906 if( !theObject.IsNull() )
908 // Process OCC shapes
909 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
910 while( aShapesMapIter != myShapesMap.end() )
912 const ListOfShapes& aShapesList = aShapesMapIter.value();
913 foreach ( HYDROGUI_Shape* aShape, aShapesList )
915 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
917 aShape->setIsToUpdate( theState );
922 // Process VTK shapes
923 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
924 while( aVTKPrsMapIter != myVTKPrsMap.end() )
926 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
927 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
929 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
931 aShape->setIsToUpdate( theState );
939 /////////////////// OCC SHAPES PROCESSING
940 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
941 const Handle(HYDROData_Entity)& theObject ) const
943 HYDROGUI_Shape* aResShape = NULL;
944 if( theObject.IsNull() )
947 if ( myShapesMap.contains( theViewId ) )
949 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
950 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
952 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
963 void HYDROGUI_Module::setObjectShape( const int theViewId,
964 const Handle(HYDROData_Entity)& theObject,
965 HYDROGUI_Shape* theShape )
967 if( theObject.IsNull() )
970 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
971 aViewShapes.append( theShape );
974 void HYDROGUI_Module::removeObjectShape( const int theViewId,
975 const Handle(HYDROData_Entity)& theObject )
977 if ( !myShapesMap.contains( theViewId ) )
980 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
981 Handle(HYDROData_Entity) anObject;
982 for ( int i = 0; i < aViewShapes.length(); )
984 HYDROGUI_Shape* aShape = aViewShapes.at( i );
985 anObject = aShape->getObject();
986 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
989 aViewShapes.removeAt( i );
997 void HYDROGUI_Module::removeViewShapes( const int theViewId )
999 if ( !myShapesMap.contains( theViewId ) )
1002 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1003 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1005 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1010 myShapesMap.remove( theViewId );
1012 /////////////////// END OF OCC SHAPES PROCESSING
1014 /////////////////// VTKPrs PROCESSING
1015 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1016 const Handle(HYDROData_Entity)& theObject ) const
1018 HYDROGUI_VTKPrs* aResShape = NULL;
1019 if( theObject.IsNull() )
1022 if ( myVTKPrsMap.contains( theViewId ) )
1024 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1025 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1027 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1038 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1039 const Handle(HYDROData_Entity)& theObject,
1040 HYDROGUI_VTKPrs* theShape )
1042 if( theObject.IsNull() )
1045 if( theShape && theShape->needScalarBar() )
1047 // Compute the new global Z range from the added presentation and the old global Z range.
1048 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1049 double* aRange = theShape->getInternalZRange();
1050 bool anIsUpdate = false;
1051 if ( aRange[0] < aGlobalRange[0] )
1053 aGlobalRange[0] = aRange[0];
1056 if ( aRange[1] > aGlobalRange[1] )
1058 aGlobalRange[1] = aRange[1];
1064 updateVTKZRange( theViewId, aGlobalRange );
1068 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1069 aViewShapes.append( theShape );
1072 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1073 const QString& theEntry )
1075 if ( !myVTKPrsMap.contains( theViewId ) )
1078 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1079 Handle(HYDROData_Entity) anObject;
1081 for ( int i = 0; i < aViewShapes.length(); )
1083 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1084 anObject = aShape->getObject();
1085 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1086 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1089 aViewShapes.removeAt( i );
1096 // Invalidate global Z range
1097 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1098 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1101 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1102 const Handle(HYDROData_Entity)& theObject )
1104 if ( !myVTKPrsMap.contains( theViewId ) )
1107 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1108 Handle(HYDROData_Entity) anObject;
1109 for ( int i = 0; i < aViewShapes.length(); )
1111 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1112 anObject = aShape->getObject();
1113 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1116 aViewShapes.removeAt( i );
1123 // Invalidate global Z range
1124 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1125 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1128 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1130 if ( !myVTKPrsMap.contains( theViewId ) )
1133 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1134 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1136 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1141 myVTKPrsMap.remove( theViewId );
1144 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1146 if ( myVTKPrsMap.contains( theViewId ) )
1148 // For the given viewer id update all VTK presentations ...
1149 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1150 HYDROGUI_VTKPrs* aShape;
1151 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1153 aShape = aViewShapes.at( i );
1154 if ( aShape && aShape->needScalarBar() )
1156 aShape->setZRange( theRange );
1160 // ... and update the global color legend scalar bar.
1161 getVTKDisplayer()->SetZRange( theViewId, theRange );
1163 /////////////////// END OF VTKPrs PROCESSING
1165 CAM_DataModel* HYDROGUI_Module::createDataModel()
1167 return new HYDROGUI_DataModel( this );
1170 void HYDROGUI_Module::customEvent( QEvent* e )
1172 int aType = e->type();
1173 if ( aType == NewViewEvent )
1175 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1176 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1178 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1180 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1181 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1183 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1185 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1186 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1188 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1189 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1190 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1192 //ouv: temporarily commented
1193 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1196 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1197 update( UF_Viewer );
1199 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1205 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1207 QEvent::Type aType = theEvent->type();
1208 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1210 if( aType == QEvent::Show )
1212 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1213 e->setData( theObj );
1214 QApplication::postEvent( this, e );
1215 theObj->removeEventFilter( this );
1218 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1220 if( aType == QEvent::Leave )
1222 SUIT_Desktop* aDesktop = getApp()->desktop();
1223 if ( aDesktop && aDesktop->statusBar() ) {
1224 aDesktop->statusBar()->clearMessage();
1228 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1230 if( aType == QEvent::Leave )
1232 SUIT_Desktop* aDesktop = getApp()->desktop();
1233 if ( aDesktop && aDesktop->statusBar() ) {
1234 aDesktop->statusBar()->clearMessage();
1239 return LightApp_Module::eventFilter( theObj, theEvent );
1242 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1244 LightApp_Module::onViewManagerAdded( theViewManager );
1246 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1248 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1249 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1251 else if( theViewManager->getType() == OCCViewer_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* ) ) );
1258 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1260 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1261 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1262 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1263 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1266 createSelector( theViewManager ); // replace the default selector
1268 ViewManagerInfo anInfo( theViewManager, VMR_General );
1269 myViewManagerMap.insert( ViewManagerId++, anInfo );
1272 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1274 LightApp_Module::onViewManagerRemoved( theViewManager );
1276 createSelector( theViewManager ); // replace the default selector
1278 int anId = getViewManagerId( theViewManager );
1281 OCCViewer_ViewManager* anOCCViewManager =
1282 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1283 if ( anOCCViewManager )
1285 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1287 removeViewShapes( (size_t)anOCCViewer );
1290 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1292 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1295 getVTKDisplayer()->EraseScalarBar( anId, true );
1296 removeViewShapes( (size_t)aVTKViewer );
1300 myViewManagerMap.remove( anId );
1304 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1306 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1308 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1310 aViewFrame->installEventFilter( this );
1312 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1314 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1315 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1318 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1320 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1322 aViewFrame->onTopView();
1324 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1326 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1328 aViewPort->installEventFilter( this );
1332 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1334 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1336 aViewFrame->installEventFilter( this );
1341 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1343 /* ouv: currently unused
1344 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1346 SUIT_ViewManager* aViewManager = 0;
1348 QObject* aParent = aViewPort;
1349 while( aParent = aParent->parent() )
1351 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1353 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1355 aViewManager = aViewer->getViewManager();
1364 double aMouseX = theEvent->scenePos().x();
1365 double aMouseY = theEvent->scenePos().y();
1367 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1368 if( aRole == VMR_General )
1370 int aXDeg = 0, aYDeg = 0;
1371 int aXMin = 0, aYMin = 0;
1372 double aXSec = 0, aYSec = 0;
1373 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1374 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1376 QString aDegSymbol( QChar( 0x00B0 ) );
1377 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1378 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1380 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1382 else if( aRole == VMR_TransformImage )
1383 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1388 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1389 const bool theIsInit,
1390 const bool theIsForced,
1391 const bool theDoFitAll )
1393 QList<int> aViewManagerIdList;
1395 // currently, all views are updated
1396 ViewManagerMapIterator anIter( myViewManagerMap );
1397 while( anIter.hasNext() )
1399 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1401 if ( theDisplayer->IsApplicable( aViewManager ) )
1403 int anId = anIter.key();
1404 aViewManagerIdList.append( anId );
1408 QListIterator<int> anIdIter( aViewManagerIdList );
1409 while( anIdIter.hasNext() )
1411 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1415 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1417 if( !theViewManager )
1420 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1421 if( !aSelectionMgr )
1424 QString aViewType = theViewManager->getType();
1425 if( aViewType != GraphicsView_Viewer::Type() &&
1426 aViewType != OCCViewer_Viewer::Type())
1429 QList<SUIT_Selector*> aSelectorList;
1430 aSelectionMgr->selectors( aViewType, aSelectorList );
1432 // disable all alien selectors
1433 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1434 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1436 SUIT_Selector* aSelector = *anIter;
1437 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1438 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1439 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1440 aSelector->setEnabled( false );
1443 if ( aViewType == GraphicsView_Viewer::Type() )
1445 GraphicsView_ViewManager* aViewManager =
1446 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1448 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1450 else if ( aViewType == OCCViewer_Viewer::Type() )
1452 OCCViewer_ViewManager* aViewManager =
1453 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1455 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1459 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1461 bool aPrevState = myIsUpdateEnabled;
1462 myIsUpdateEnabled = theState;
1466 bool HYDROGUI_Module::isUpdateEnabled() const
1468 return myIsUpdateEnabled;
1471 QStringList HYDROGUI_Module::storeSelection() const
1473 QStringList anEntryList;
1474 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1476 SUIT_DataOwnerPtrList aList( true );
1477 aSelectionMgr->selected( aList );
1479 SUIT_DataOwnerPtrList::iterator anIter;
1480 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1482 const LightApp_DataOwner* anOwner =
1483 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1485 anEntryList.append( anOwner->entry() );
1491 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1493 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1495 SUIT_DataOwnerPtrList aList( true );
1496 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1497 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1498 aSelectionMgr->setSelected( aList );
1502 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1505 bool doShow = false;
1506 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1508 aDisplayer->SaveCursorViewPosition( theViewWindow );
1509 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1513 // Show the coordinates in the status bar
1514 SUIT_Desktop* aDesktop = getApp()->desktop();
1515 if ( aDesktop && aDesktop->statusBar() )
1517 gp_Pnt aWPnt( X, Y, Z );
1518 int aStudyId = application()->activeStudy()->id();
1519 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1520 double WX = aWPnt.X(), WY = aWPnt.Y();
1522 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X );
1523 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y );
1524 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX );
1525 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY );
1526 QString aMsg = tr( "COORDINATES_INFO" );
1527 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1528 aDesktop->statusBar()->showMessage( aMsg );
1534 * Returns stack of active operations;
1536 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1538 return myActiveOperationMap;
1542 * Returns the module active operation. If the active operation is show/hide,
1543 * the method returns the previous operation if it is.
1545 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1547 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1549 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1551 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1553 aVIt.previous(); // skip the top show/hide operation
1554 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;