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.hxx>
56 #include <GraphicsView_ViewFrame.h>
57 #include <GraphicsView_ViewManager.h>
58 #include <GraphicsView_ViewPort.h>
59 #include <GraphicsView_Viewer.h>
61 #include <ImageComposer_CutOperator.h>
62 #include <ImageComposer_CropOperator.h>
63 #include <ImageComposer_FuseOperator.h>
65 #include <LightApp_Application.h>
66 #include <LightApp_DataOwner.h>
67 #include <LightApp_GVSelector.h>
68 #include <LightApp_SelectionMgr.h>
69 #include <LightApp_UpdateFlags.h>
71 #include <SalomeApp_Study.h>
73 #include <OCCViewer_ViewFrame.h>
74 #include <OCCViewer_ViewManager.h>
75 #include <OCCViewer_ViewModel.h>
77 #include <SALOME_Event.h>
79 #include <SUIT_DataBrowser.h>
80 #include <SUIT_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 status bar
263 SUIT_Desktop* aDesktop = getApp()->desktop();
264 if ( aDesktop && aDesktop->statusBar() ) {
265 aDesktop->statusBar()->clearMessage();
268 // clear the data model's list of copying objects
269 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
271 setMenuShown( false );
272 setToolShown( false );
274 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
276 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
278 myActiveOperationMap.clear();
279 return LightApp_Module::deactivateModule( theStudy );
282 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
285 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
286 #ifndef DISABLE_PYCONSOLE
287 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
289 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
292 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
294 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
297 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
301 HYDROGUI_DataModel* aModel = getDataModel();
303 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
304 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
305 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
306 bool anIsVTKView = theClient == SVTK_Viewer::Type();
307 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
310 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
312 bool anIsSelectedDataObjects = false;
313 bool anIsVisibleInSelection = false;
314 bool anIsHiddenInSelection = false;
316 bool anIsImage = false;
317 bool anIsImportedImage = false;
318 bool anIsImageHasRefs = false;
319 bool anIsFusedImage = false;
320 bool anIsCutImage = false;
321 bool anIsSplittedImage = false;
322 bool anIsMustObjectBeUpdated = false;
323 bool anIsPolyline = false;
324 bool anIsPolyline3D = false;
325 bool anIsProfile = false;
326 bool anIsValidProfile = false;
327 bool anAllAreProfiles = false;
328 bool anIsBathymetry = false;
329 bool anIsCalculation = false;
330 bool anIsImmersibleZone = false;
331 bool anIsVisualState = false;
332 bool anIsRegion = false;
333 bool anIsZone = false;
334 bool anIsObstacle = false;
335 bool anIsStream = false;
336 bool anIsChannel = false;
337 bool anIsDigue = false;
338 bool anIsDummyObject3D = false;
339 bool anIsGroup = false;
340 bool anIsObjectCanBeColored = false;
343 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
344 SUIT_DataOwnerPtrList anOwners;
345 aSelectionMgr->selected( anOwners );
346 if( anIsObjectBrowser && anOwners.size()==1 )
348 QString anEntry = anOwners[0]->keyString();
349 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
351 isRoot = aStudy->isComponent( anEntry );
354 // Check the selected GEOM objects (take into account the Object Browser only)
355 if ( anIsObjectBrowser ) {
356 QList<GEOM::shape_type> anObstacleTypes =
357 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
358 QList<GEOM::shape_type> aPolylineTypes =
359 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
361 bool isCanBeImportedAsObstacle =
362 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
363 bool isCanBeImportedAsPolyline =
364 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
366 // Add import as obstacle action
367 if ( isCanBeImportedAsObstacle ) {
368 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
370 // Add import as polyline action
371 if ( isCanBeImportedAsPolyline ) {
372 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
375 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
376 theMenu->addSeparator();
380 // check the selected data model objects
381 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
382 int aNbOfSelectedProfiles = 0;
383 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
385 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
386 if( !anObject.IsNull() )
388 anIsSelectedDataObjects = true;
390 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
391 anIsVisibleInSelection |= aVisibility;
392 anIsHiddenInSelection |= !aVisibility;
394 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
396 anIsMustObjectBeUpdated = true;
399 ObjectKind anObjectKind = anObject->GetKind();
400 if( anObjectKind == KIND_IMAGE )
403 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
404 if( !anImage.IsNull() )
406 anIsImportedImage = anImage->HasLocalPoints();
407 anIsImageHasRefs = anImage->HasReferences();
408 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
410 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
412 QString anOperatorName = anOperator->name();
413 if( anOperatorName == ImageComposer_FuseOperator::Type() )
414 anIsFusedImage = true;
415 else if( anOperatorName == ImageComposer_CutOperator::Type() )
417 else if( anOperatorName == ImageComposer_CropOperator::Type() )
418 anIsSplittedImage = true;
423 else if( anObjectKind == KIND_POLYLINEXY )
425 else if( anObjectKind == KIND_POLYLINE )
426 anIsPolyline3D = true;
427 else if( anObjectKind == KIND_PROFILE )
430 aNbOfSelectedProfiles++;
432 Handle(HYDROData_Profile) aProfile =
433 Handle(HYDROData_Profile)::DownCast( anObject );
434 if( !aProfile.IsNull() && aProfile->IsValid() ) {
435 anIsValidProfile = true;
438 else if( anObjectKind == KIND_CALCULATION )
439 anIsCalculation = true;
440 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
441 anIsImmersibleZone = true;
442 else if( anObjectKind == KIND_VISUAL_STATE )
443 anIsVisualState = true;
444 else if( anObjectKind == KIND_REGION )
446 else if( anObjectKind == KIND_ZONE )
448 else if( anObjectKind == KIND_BATHYMETRY )
449 anIsBathymetry = true;
450 else if( anObjectKind == KIND_OBSTACLE )
452 else if( anObjectKind == KIND_STREAM )
454 else if( anObjectKind == KIND_CHANNEL )
456 else if( anObjectKind == KIND_DIGUE )
458 else if( anObjectKind == KIND_DUMMY_3D )
459 anIsDummyObject3D = true;
460 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
464 if ( !anIsObjectCanBeColored )
465 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
468 // Check if all selected objects are profiles
469 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
470 ( aNbOfSelectedProfiles == aSeq.Length() );
472 // check the selected partitions
473 if( !anIsSelectedDataObjects && anIsObjectBrowser )
475 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
476 if( aSelectedPartition != KIND_UNKNOWN )
478 switch( aSelectedPartition )
481 theMenu->addAction( action( ImportImageId ) );
483 case KIND_BATHYMETRY:
484 theMenu->addAction( action( ImportBathymetryId ) );
486 case KIND_ARTIFICIAL_OBJECT:
487 theMenu->addAction( action( CreateChannelId ) );
488 theMenu->addAction( action( CreateDigueId ) );
490 case KIND_NATURAL_OBJECT:
491 theMenu->addAction( action( CreateImmersibleZoneId ) );
492 theMenu->addAction( action( CreateStreamId ) );
495 theMenu->addAction( action( ImportObstacleFromFileId ) );
496 theMenu->addAction( action( CreateBoxId ) );
497 theMenu->addAction( action( CreateCylinderId ) );
499 case KIND_CALCULATION:
500 theMenu->addAction( action( CreateCalculationId ) );
502 case KIND_POLYLINEXY:
503 theMenu->addAction( action( CreatePolylineId ) );
506 theMenu->addAction( action( CreatePolyline3DId ) );
509 theMenu->addAction( action( CreateProfileId ) );
510 theMenu->addAction( action( ImportProfilesId ) );
511 theMenu->addAction( action( AllGeoreferencementId ) );
513 case KIND_VISUAL_STATE:
514 theMenu->addAction( action( SaveVisualStateId ) );
517 theMenu->addSeparator();
521 if( anIsSelectedDataObjects )
523 if ( anIsMustObjectBeUpdated )
525 theMenu->addAction( action( UpdateObjectId ) );
526 theMenu->addSeparator();
530 theMenu->addAction( action( ForcedUpdateObjectId ) );
531 theMenu->addSeparator();
535 if( aSeq.Length() == 1 )
539 if( anIsImportedImage )
540 theMenu->addAction( action( EditImportedImageId ) );
541 else if( anIsImageHasRefs )
544 theMenu->addAction( action( EditFusedImageId ) );
545 else if( anIsCutImage )
546 theMenu->addAction( action( EditCutImageId ) );
547 else if( anIsSplittedImage )
548 theMenu->addAction( action( EditSplittedImageId ) );
551 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
552 theMenu->addAction( action( ExportImageId ) );
553 theMenu->addSeparator();
555 if( anIsImageHasRefs )
557 theMenu->addAction( action( RemoveImageRefsId ) );
558 theMenu->addSeparator();
561 theMenu->addAction( action( FuseImagesId ) );
562 theMenu->addAction( action( CutImagesId ) );
563 theMenu->addAction( action( SplitImageId ) );
564 theMenu->addSeparator();
566 else if( anIsBathymetry )
568 theMenu->addAction( action( EditImportedBathymetryId ) );
569 theMenu->addAction( action( BathymetryBoundsId ) );
570 theMenu->addSeparator();
572 else if( anIsPolyline )
574 theMenu->addAction( action( EditPolylineId ) );
575 theMenu->addSeparator();
577 else if( anIsPolyline3D )
579 theMenu->addAction( action( EditPolyline3DId ) );
580 theMenu->addSeparator();
582 else if( anIsProfile )
584 theMenu->addAction( action( EditProfileId ) );
585 theMenu->addAction( action( SelectedGeoreferencementId ) );
586 theMenu->addSeparator();
588 else if( anIsCalculation )
590 theMenu->addAction( action( EditCalculationId ) );
591 theMenu->addAction( action( ExportCalculationId ) );
592 theMenu->addSeparator();
594 else if( anIsImmersibleZone )
596 theMenu->addAction( action( EditImmersibleZoneId ) );
597 theMenu->addSeparator();
599 else if( anIsStream )
601 theMenu->addAction( action( EditStreamId ) );
602 theMenu->addSeparator();
604 else if( anIsChannel )
606 theMenu->addAction( action( EditChannelId ) );
607 theMenu->addSeparator();
611 theMenu->addAction( action( EditDigueId ) );
612 theMenu->addSeparator();
614 else if( anIsObstacle )
616 theMenu->addAction( action( TranslateObstacleId ) );
617 theMenu->addSeparator();
619 else if( anIsVisualState && anIsObjectBrowser )
621 theMenu->addAction( action( SaveVisualStateId ) );
622 theMenu->addAction( action( LoadVisualStateId ) );
623 theMenu->addSeparator();
626 // Add set color action for geometrical objects
627 if ( anIsObjectCanBeColored )
629 theMenu->addAction( action( SetColorId ) );
630 theMenu->addSeparator();
632 } else if ( anAllAreProfiles ) {
633 theMenu->addAction( action( SelectedGeoreferencementId ) );
634 theMenu->addSeparator();
638 QAction* aCopyAction = action( CopyId );
639 if( aCopyAction && aCopyAction->isEnabled() ) {
640 theMenu->addAction( action( CopyId ) );
641 theMenu->addSeparator();
645 if( !anIsDummyObject3D )
646 theMenu->addAction( action( DeleteId ) );
648 theMenu->addSeparator();
650 if( anIsImage || anIsPolyline || anIsPolyline3D ||
651 anIsImmersibleZone || anIsZone || anIsRegion ||
652 anIsBathymetry || anIsObstacle || anIsStream ||
653 anIsChannel || anIsDigue || anIsDummyObject3D ||
654 anIsValidProfile || anIsGroup )
656 if( anIsHiddenInSelection )
657 theMenu->addAction( action( ShowId ) );
658 theMenu->addAction( action( ShowOnlyId ) );
659 if( anIsVisibleInSelection )
660 theMenu->addAction( action( HideId ) );
661 theMenu->addSeparator();
667 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
668 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
669 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
670 theMenu->addAction( action( DeleteId ) );
672 theMenu->addSeparator();
673 theMenu->addAction( action( SetZLevelId ) );
674 theMenu->addSeparator();
677 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
679 theMenu->addAction( action( ShowAllId ) );
680 theMenu->addAction( action( HideAllId ) );
681 theMenu->addSeparator();
684 if ( anIsOCCView || anIsVTKView )
686 theMenu->addSeparator();
687 theMenu->addAction( action( CopyViewerPositionId ) );
691 theMenu->addAction( action( EditLocalCSId ) );
694 void HYDROGUI_Module::update( const int flags )
696 if( !isUpdateEnabled() )
699 QApplication::setOverrideCursor( Qt::WaitCursor );
701 // To prevent calling this method recursively
702 // from one of the methods called below
703 setUpdateEnabled( false );
705 // store selected objects
706 QStringList aSelectedEntries = storeSelection();
708 bool aDoFitAll = flags & UF_FitAll;
709 if( ( flags & UF_Viewer ) )
710 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
712 if( ( flags & UF_OCCViewer ) )
713 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
715 if( ( flags & UF_VTKViewer ) )
716 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
718 if( ( flags & UF_Model ) && getDataModel() && getApp() )
720 getDataModel()->update( getStudyId() );
722 // Temporary workaround to prevent breaking
723 // the selection in the object browser.
724 // Note: processEvents() should be called after updateGV(),
725 // otherwise the application crashes from time to time.
726 //RKV: qApp->processEvents();
727 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
728 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
729 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
730 if ( isResizeOnExpandItem && anObjectBrowser ) {
731 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
733 getApp()->updateObjectBrowser( true );
734 if ( isResizeOnExpandItem && anObjectBrowser ) {
735 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
739 // Object browser is currently updated by using UF_Model flag
740 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
741 getApp()->updateObjectBrowser( true );
743 if( ( flags & UF_Controls ) && getApp() )
744 getApp()->updateActions();
746 // restore selected objects
747 restoreSelection( aSelectedEntries );
749 setUpdateEnabled( true );
751 QApplication::restoreOverrideCursor();
754 void HYDROGUI_Module::updateCommandsStatus()
756 LightApp_Module::updateCommandsStatus();
758 updateUndoRedoControls();
760 action( CopyId )->setEnabled( getDataModel()->canCopy() );
761 action( PasteId )->setEnabled( getDataModel()->canPaste() );
764 void HYDROGUI_Module::selectionChanged()
766 LightApp_Module::selectionChanged();
767 updateCommandsStatus();
770 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
772 return (HYDROGUI_DataModel*)dataModel();
775 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
780 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
782 return myOCCDisplayer;
785 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
787 return myVTKDisplayer;
790 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
792 if( myViewManagerMap.contains( theId ) )
794 return myViewManagerMap[ theId ].first;
799 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
801 if( myViewManagerMap.contains( theId ) )
803 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
804 GraphicsView_ViewManager* aViewManager =
805 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
807 return aViewManager->getViewer();
812 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
814 if( myViewManagerMap.contains( theId ) )
816 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
817 OCCViewer_ViewManager* aViewManager =
818 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
820 return aViewManager->getOCCViewer();
825 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
827 if( myViewManagerMap.contains( theId ) )
829 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
830 SVTK_ViewManager* aViewManager =
831 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
833 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
838 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
840 ViewManagerMapIterator anIter( myViewManagerMap );
841 while( anIter.hasNext() )
843 int anId = anIter.next().key();
844 const ViewManagerInfo& anInfo = anIter.value();
845 if( anInfo.first == theViewManager )
851 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
853 int anId = getViewManagerId( theViewManager );
856 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
857 return anInfo.second;
862 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
863 const ViewManagerRole theRole )
865 int anId = getViewManagerId( theViewManager );
868 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
869 anInfo.second = theRole;
873 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
874 const Handle(HYDROData_Entity)& theObject ) const
876 if( theObject.IsNull() )
879 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
880 if( anIter1 != myObjectStateMap.end() )
882 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
883 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
885 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
886 if( anIter2 != aEntry2ObjectStateMap.end() )
888 const ObjectState& anObjectState = anIter2.value();
889 return anObjectState.Visibility;
895 void HYDROGUI_Module::setObjectVisible( const int theViewId,
896 const Handle(HYDROData_Entity)& theObject,
897 const bool theState )
899 if( !theObject.IsNull() )
901 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
902 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
904 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
905 anObjectState.Visibility = theState;
909 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
910 const bool theState )
912 if( !theObject.IsNull() )
914 // Process OCC shapes
915 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
916 while( aShapesMapIter != myShapesMap.end() )
918 const ListOfShapes& aShapesList = aShapesMapIter.value();
919 foreach ( HYDROGUI_Shape* aShape, aShapesList )
921 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
923 aShape->setIsToUpdate( theState );
928 // Process VTK shapes
929 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
930 while( aVTKPrsMapIter != myVTKPrsMap.end() )
932 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
933 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
935 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
937 aShape->setIsToUpdate( theState );
945 /////////////////// OCC SHAPES PROCESSING
946 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
947 ObjectKind theKind ) const
949 QList<HYDROGUI_Shape*> aResult;
951 if ( myShapesMap.contains( theViewId ) )
953 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
954 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
956 if( aShape && aShape->getObject()->GetKind()==theKind )
957 aResult.append( aShape );
963 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
964 const Handle(HYDROData_Entity)& theObject ) const
966 HYDROGUI_Shape* aResShape = NULL;
967 if( theObject.IsNull() )
970 if ( myShapesMap.contains( theViewId ) )
972 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
973 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
975 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
986 void HYDROGUI_Module::setObjectShape( const int theViewId,
987 const Handle(HYDROData_Entity)& theObject,
988 HYDROGUI_Shape* theShape )
990 if( theObject.IsNull() )
993 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
994 aViewShapes.append( theShape );
997 void HYDROGUI_Module::removeObjectShape( const int theViewId,
998 const Handle(HYDROData_Entity)& theObject )
1000 if ( !myShapesMap.contains( theViewId ) )
1003 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1004 Handle(HYDROData_Entity) anObject;
1005 for ( int i = 0; i < aViewShapes.length(); )
1007 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1008 anObject = aShape->getObject();
1009 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1012 aViewShapes.removeAt( i );
1020 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1022 if ( !myShapesMap.contains( theViewId ) )
1025 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1026 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1028 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1033 myShapesMap.remove( theViewId );
1035 /////////////////// END OF OCC SHAPES PROCESSING
1037 /////////////////// VTKPrs PROCESSING
1038 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1039 const Handle(HYDROData_Entity)& theObject ) const
1041 HYDROGUI_VTKPrs* aResShape = NULL;
1042 if( theObject.IsNull() )
1045 if ( myVTKPrsMap.contains( theViewId ) )
1047 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1048 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1050 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1061 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1062 const Handle(HYDROData_Entity)& theObject,
1063 HYDROGUI_VTKPrs* theShape )
1065 if( theObject.IsNull() )
1068 if( theShape && theShape->needScalarBar() )
1070 // Compute the new global Z range from the added presentation and the old global Z range.
1071 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1072 double* aRange = theShape->getInternalZRange();
1073 bool anIsUpdate = false;
1074 if ( aRange[0] < aGlobalRange[0] )
1076 aGlobalRange[0] = aRange[0];
1079 if ( aRange[1] > aGlobalRange[1] )
1081 aGlobalRange[1] = aRange[1];
1087 updateVTKZRange( theViewId, aGlobalRange );
1091 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1092 aViewShapes.append( theShape );
1095 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1096 const QString& theEntry )
1098 if ( !myVTKPrsMap.contains( theViewId ) )
1101 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1102 Handle(HYDROData_Entity) anObject;
1104 for ( int i = 0; i < aViewShapes.length(); )
1106 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1107 anObject = aShape->getObject();
1108 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1109 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1112 aViewShapes.removeAt( i );
1119 // Invalidate global Z range
1120 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1121 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1124 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1125 const Handle(HYDROData_Entity)& theObject )
1127 if ( !myVTKPrsMap.contains( theViewId ) )
1130 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1131 Handle(HYDROData_Entity) anObject;
1132 for ( int i = 0; i < aViewShapes.length(); )
1134 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1135 anObject = aShape->getObject();
1136 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1139 aViewShapes.removeAt( i );
1146 // Invalidate global Z range
1147 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1148 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1151 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1153 if ( !myVTKPrsMap.contains( theViewId ) )
1156 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1157 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1159 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1164 myVTKPrsMap.remove( theViewId );
1167 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1169 if ( myVTKPrsMap.contains( theViewId ) )
1171 // For the given viewer id update all VTK presentations ...
1172 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1173 HYDROGUI_VTKPrs* aShape;
1174 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1176 aShape = aViewShapes.at( i );
1177 if ( aShape && aShape->needScalarBar() )
1179 aShape->setZRange( theRange );
1183 // ... and update the global color legend scalar bar.
1184 getVTKDisplayer()->SetZRange( theViewId, theRange );
1186 /////////////////// END OF VTKPrs PROCESSING
1188 CAM_DataModel* HYDROGUI_Module::createDataModel()
1190 return new HYDROGUI_DataModel( this );
1193 void HYDROGUI_Module::customEvent( QEvent* e )
1195 int aType = e->type();
1196 if ( aType == NewViewEvent )
1198 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1199 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1201 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1203 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1204 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1206 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1208 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1209 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1211 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1212 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1213 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1215 //ouv: temporarily commented
1216 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1219 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1220 update( UF_Viewer );
1222 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1228 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1230 QEvent::Type aType = theEvent->type();
1231 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1233 if( aType == QEvent::Show )
1235 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1236 e->setData( theObj );
1237 QApplication::postEvent( this, e );
1238 theObj->removeEventFilter( this );
1241 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1243 if( aType == QEvent::Leave )
1245 SUIT_Desktop* aDesktop = getApp()->desktop();
1246 if ( aDesktop && aDesktop->statusBar() ) {
1247 aDesktop->statusBar()->clearMessage();
1251 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1253 if( aType == QEvent::Leave )
1255 SUIT_Desktop* aDesktop = getApp()->desktop();
1256 if ( aDesktop && aDesktop->statusBar() ) {
1257 aDesktop->statusBar()->clearMessage();
1262 return LightApp_Module::eventFilter( theObj, theEvent );
1265 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1267 LightApp_Module::onViewManagerAdded( theViewManager );
1269 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1271 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1272 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1274 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1276 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1277 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1278 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1279 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1281 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1283 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1284 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1285 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1286 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1289 createSelector( theViewManager ); // replace the default selector
1291 ViewManagerInfo anInfo( theViewManager, VMR_General );
1292 myViewManagerMap.insert( ViewManagerId++, anInfo );
1295 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1297 LightApp_Module::onViewManagerRemoved( theViewManager );
1299 createSelector( theViewManager ); // replace the default selector
1301 int anId = getViewManagerId( theViewManager );
1304 OCCViewer_ViewManager* anOCCViewManager =
1305 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1306 if ( anOCCViewManager )
1308 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1310 removeViewShapes( (size_t)anOCCViewer );
1313 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1315 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1318 getVTKDisplayer()->EraseScalarBar( anId, true );
1319 removeViewShapes( (size_t)aVTKViewer );
1323 myViewManagerMap.remove( anId );
1327 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1329 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1331 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1333 aViewFrame->installEventFilter( this );
1335 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1337 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1338 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1341 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1343 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1345 aViewFrame->onTopView();
1347 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1349 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1351 aViewPort->installEventFilter( this );
1355 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1357 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1359 aViewFrame->installEventFilter( this );
1364 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1366 /* ouv: currently unused
1367 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1369 SUIT_ViewManager* aViewManager = 0;
1371 QObject* aParent = aViewPort;
1372 while( aParent = aParent->parent() )
1374 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1376 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1378 aViewManager = aViewer->getViewManager();
1387 double aMouseX = theEvent->scenePos().x();
1388 double aMouseY = theEvent->scenePos().y();
1390 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1391 if( aRole == VMR_General )
1393 int aXDeg = 0, aYDeg = 0;
1394 int aXMin = 0, aYMin = 0;
1395 double aXSec = 0, aYSec = 0;
1396 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1397 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1399 QString aDegSymbol( QChar( 0x00B0 ) );
1400 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1401 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1403 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1405 else if( aRole == VMR_TransformImage )
1406 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1411 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1412 const bool theIsInit,
1413 const bool theIsForced,
1414 const bool theDoFitAll )
1416 QList<int> aViewManagerIdList;
1418 // currently, all views are updated
1419 ViewManagerMapIterator anIter( myViewManagerMap );
1420 while( anIter.hasNext() )
1422 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1424 if ( theDisplayer->IsApplicable( aViewManager ) )
1426 int anId = anIter.key();
1427 aViewManagerIdList.append( anId );
1431 QListIterator<int> anIdIter( aViewManagerIdList );
1432 while( anIdIter.hasNext() )
1434 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1438 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1440 if( !theViewManager )
1443 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1444 if( !aSelectionMgr )
1447 QString aViewType = theViewManager->getType();
1448 if( aViewType != GraphicsView_Viewer::Type() &&
1449 aViewType != OCCViewer_Viewer::Type())
1452 QList<SUIT_Selector*> aSelectorList;
1453 aSelectionMgr->selectors( aViewType, aSelectorList );
1455 // disable all alien selectors
1456 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1457 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1459 SUIT_Selector* aSelector = *anIter;
1460 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1461 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1462 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1463 aSelector->setEnabled( false );
1466 if ( aViewType == GraphicsView_Viewer::Type() )
1468 GraphicsView_ViewManager* aViewManager =
1469 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1471 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1473 else if ( aViewType == OCCViewer_Viewer::Type() )
1475 OCCViewer_ViewManager* aViewManager =
1476 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1478 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1482 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1484 bool aPrevState = myIsUpdateEnabled;
1485 myIsUpdateEnabled = theState;
1489 bool HYDROGUI_Module::isUpdateEnabled() const
1491 return myIsUpdateEnabled;
1494 QStringList HYDROGUI_Module::storeSelection() const
1496 QStringList anEntryList;
1497 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1499 SUIT_DataOwnerPtrList aList( true );
1500 aSelectionMgr->selected( aList );
1502 SUIT_DataOwnerPtrList::iterator anIter;
1503 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1505 const LightApp_DataOwner* anOwner =
1506 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1508 anEntryList.append( anOwner->entry() );
1514 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1516 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1518 SUIT_DataOwnerPtrList aList( true );
1519 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1520 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1521 aSelectionMgr->setSelected( aList );
1525 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1528 bool doShow = false;
1529 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1531 aDisplayer->SaveCursorViewPosition( theViewWindow );
1532 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1536 // Show the coordinates in the status bar
1537 SUIT_Desktop* aDesktop = getApp()->desktop();
1538 if ( aDesktop && aDesktop->statusBar() )
1540 gp_Pnt aWPnt( X, Y, Z );
1541 int aStudyId = application()->activeStudy()->id();
1542 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1543 double WX = aWPnt.X(), WY = aWPnt.Y();
1545 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1546 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1547 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1548 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1549 QString aMsg = tr( "COORDINATES_INFO" );
1550 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1551 aDesktop->statusBar()->showMessage( aMsg );
1557 * Returns stack of active operations;
1559 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1561 return myActiveOperationMap;
1565 * Returns the module active operation. If the active operation is show/hide,
1566 * the method returns the previous operation if it is.
1568 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1570 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1572 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1574 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1576 aVIt.previous(); // skip the top show/hide operation
1577 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;