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 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 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
941 ObjectKind theKind ) const
943 QList<HYDROGUI_Shape*> aResult;
945 if ( myShapesMap.contains( theViewId ) )
947 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
948 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
950 if( aShape && aShape->getObject()->GetKind()==theKind )
951 aResult.append( aShape );
957 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
958 const Handle(HYDROData_Entity)& theObject ) const
960 HYDROGUI_Shape* aResShape = NULL;
961 if( theObject.IsNull() )
964 if ( myShapesMap.contains( theViewId ) )
966 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
967 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
969 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
980 void HYDROGUI_Module::setObjectShape( const int theViewId,
981 const Handle(HYDROData_Entity)& theObject,
982 HYDROGUI_Shape* theShape )
984 if( theObject.IsNull() )
987 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
988 aViewShapes.append( theShape );
991 void HYDROGUI_Module::removeObjectShape( const int theViewId,
992 const Handle(HYDROData_Entity)& theObject )
994 if ( !myShapesMap.contains( theViewId ) )
997 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
998 Handle(HYDROData_Entity) anObject;
999 for ( int i = 0; i < aViewShapes.length(); )
1001 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1002 anObject = aShape->getObject();
1003 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1006 aViewShapes.removeAt( i );
1014 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1016 if ( !myShapesMap.contains( theViewId ) )
1019 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1020 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1022 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1027 myShapesMap.remove( theViewId );
1029 /////////////////// END OF OCC SHAPES PROCESSING
1031 /////////////////// VTKPrs PROCESSING
1032 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1033 const Handle(HYDROData_Entity)& theObject ) const
1035 HYDROGUI_VTKPrs* aResShape = NULL;
1036 if( theObject.IsNull() )
1039 if ( myVTKPrsMap.contains( theViewId ) )
1041 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1042 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1044 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1055 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1056 const Handle(HYDROData_Entity)& theObject,
1057 HYDROGUI_VTKPrs* theShape )
1059 if( theObject.IsNull() )
1062 if( theShape && theShape->needScalarBar() )
1064 // Compute the new global Z range from the added presentation and the old global Z range.
1065 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1066 double* aRange = theShape->getInternalZRange();
1067 bool anIsUpdate = false;
1068 if ( aRange[0] < aGlobalRange[0] )
1070 aGlobalRange[0] = aRange[0];
1073 if ( aRange[1] > aGlobalRange[1] )
1075 aGlobalRange[1] = aRange[1];
1081 updateVTKZRange( theViewId, aGlobalRange );
1085 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1086 aViewShapes.append( theShape );
1089 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1090 const QString& theEntry )
1092 if ( !myVTKPrsMap.contains( theViewId ) )
1095 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1096 Handle(HYDROData_Entity) anObject;
1098 for ( int i = 0; i < aViewShapes.length(); )
1100 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1101 anObject = aShape->getObject();
1102 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1103 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1106 aViewShapes.removeAt( i );
1113 // Invalidate global Z range
1114 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1115 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1118 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1119 const Handle(HYDROData_Entity)& theObject )
1121 if ( !myVTKPrsMap.contains( theViewId ) )
1124 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1125 Handle(HYDROData_Entity) anObject;
1126 for ( int i = 0; i < aViewShapes.length(); )
1128 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1129 anObject = aShape->getObject();
1130 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1133 aViewShapes.removeAt( i );
1140 // Invalidate global Z range
1141 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1142 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1145 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1147 if ( !myVTKPrsMap.contains( theViewId ) )
1150 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1151 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1153 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1158 myVTKPrsMap.remove( theViewId );
1161 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1163 if ( myVTKPrsMap.contains( theViewId ) )
1165 // For the given viewer id update all VTK presentations ...
1166 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1167 HYDROGUI_VTKPrs* aShape;
1168 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1170 aShape = aViewShapes.at( i );
1171 if ( aShape && aShape->needScalarBar() )
1173 aShape->setZRange( theRange );
1177 // ... and update the global color legend scalar bar.
1178 getVTKDisplayer()->SetZRange( theViewId, theRange );
1180 /////////////////// END OF VTKPrs PROCESSING
1182 CAM_DataModel* HYDROGUI_Module::createDataModel()
1184 return new HYDROGUI_DataModel( this );
1187 void HYDROGUI_Module::customEvent( QEvent* e )
1189 int aType = e->type();
1190 if ( aType == NewViewEvent )
1192 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1193 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1195 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1197 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1198 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1200 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1202 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1203 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1205 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1206 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1207 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1209 //ouv: temporarily commented
1210 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1213 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1214 update( UF_Viewer );
1216 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1222 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1224 QEvent::Type aType = theEvent->type();
1225 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1227 if( aType == QEvent::Show )
1229 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1230 e->setData( theObj );
1231 QApplication::postEvent( this, e );
1232 theObj->removeEventFilter( this );
1235 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1237 if( aType == QEvent::Leave )
1239 SUIT_Desktop* aDesktop = getApp()->desktop();
1240 if ( aDesktop && aDesktop->statusBar() ) {
1241 aDesktop->statusBar()->clearMessage();
1245 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1247 if( aType == QEvent::Leave )
1249 SUIT_Desktop* aDesktop = getApp()->desktop();
1250 if ( aDesktop && aDesktop->statusBar() ) {
1251 aDesktop->statusBar()->clearMessage();
1256 return LightApp_Module::eventFilter( theObj, theEvent );
1259 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1261 LightApp_Module::onViewManagerAdded( theViewManager );
1263 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1265 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1266 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1268 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1270 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1271 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1272 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1273 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1275 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1277 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1278 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1279 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1280 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1283 createSelector( theViewManager ); // replace the default selector
1285 ViewManagerInfo anInfo( theViewManager, VMR_General );
1286 myViewManagerMap.insert( ViewManagerId++, anInfo );
1289 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1291 LightApp_Module::onViewManagerRemoved( theViewManager );
1293 createSelector( theViewManager ); // replace the default selector
1295 int anId = getViewManagerId( theViewManager );
1298 OCCViewer_ViewManager* anOCCViewManager =
1299 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1300 if ( anOCCViewManager )
1302 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1304 removeViewShapes( (size_t)anOCCViewer );
1307 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1309 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1312 getVTKDisplayer()->EraseScalarBar( anId, true );
1313 removeViewShapes( (size_t)aVTKViewer );
1317 myViewManagerMap.remove( anId );
1321 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1323 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1325 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1327 aViewFrame->installEventFilter( this );
1329 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1331 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1332 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1335 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1337 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1339 aViewFrame->onTopView();
1341 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1343 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1345 aViewPort->installEventFilter( this );
1349 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1351 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1353 aViewFrame->installEventFilter( this );
1358 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1360 /* ouv: currently unused
1361 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1363 SUIT_ViewManager* aViewManager = 0;
1365 QObject* aParent = aViewPort;
1366 while( aParent = aParent->parent() )
1368 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1370 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1372 aViewManager = aViewer->getViewManager();
1381 double aMouseX = theEvent->scenePos().x();
1382 double aMouseY = theEvent->scenePos().y();
1384 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1385 if( aRole == VMR_General )
1387 int aXDeg = 0, aYDeg = 0;
1388 int aXMin = 0, aYMin = 0;
1389 double aXSec = 0, aYSec = 0;
1390 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1391 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1393 QString aDegSymbol( QChar( 0x00B0 ) );
1394 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1395 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1397 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1399 else if( aRole == VMR_TransformImage )
1400 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1405 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1406 const bool theIsInit,
1407 const bool theIsForced,
1408 const bool theDoFitAll )
1410 QList<int> aViewManagerIdList;
1412 // currently, all views are updated
1413 ViewManagerMapIterator anIter( myViewManagerMap );
1414 while( anIter.hasNext() )
1416 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1418 if ( theDisplayer->IsApplicable( aViewManager ) )
1420 int anId = anIter.key();
1421 aViewManagerIdList.append( anId );
1425 QListIterator<int> anIdIter( aViewManagerIdList );
1426 while( anIdIter.hasNext() )
1428 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1432 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1434 if( !theViewManager )
1437 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1438 if( !aSelectionMgr )
1441 QString aViewType = theViewManager->getType();
1442 if( aViewType != GraphicsView_Viewer::Type() &&
1443 aViewType != OCCViewer_Viewer::Type())
1446 QList<SUIT_Selector*> aSelectorList;
1447 aSelectionMgr->selectors( aViewType, aSelectorList );
1449 // disable all alien selectors
1450 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1451 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1453 SUIT_Selector* aSelector = *anIter;
1454 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1455 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1456 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1457 aSelector->setEnabled( false );
1460 if ( aViewType == GraphicsView_Viewer::Type() )
1462 GraphicsView_ViewManager* aViewManager =
1463 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1465 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1467 else if ( aViewType == OCCViewer_Viewer::Type() )
1469 OCCViewer_ViewManager* aViewManager =
1470 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1472 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1476 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1478 bool aPrevState = myIsUpdateEnabled;
1479 myIsUpdateEnabled = theState;
1483 bool HYDROGUI_Module::isUpdateEnabled() const
1485 return myIsUpdateEnabled;
1488 QStringList HYDROGUI_Module::storeSelection() const
1490 QStringList anEntryList;
1491 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1493 SUIT_DataOwnerPtrList aList( true );
1494 aSelectionMgr->selected( aList );
1496 SUIT_DataOwnerPtrList::iterator anIter;
1497 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1499 const LightApp_DataOwner* anOwner =
1500 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1502 anEntryList.append( anOwner->entry() );
1508 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1510 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1512 SUIT_DataOwnerPtrList aList( true );
1513 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1514 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1515 aSelectionMgr->setSelected( aList );
1519 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1522 bool doShow = false;
1523 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1525 aDisplayer->SaveCursorViewPosition( theViewWindow );
1526 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1530 // Show the coordinates in the status bar
1531 SUIT_Desktop* aDesktop = getApp()->desktop();
1532 if ( aDesktop && aDesktop->statusBar() )
1534 gp_Pnt aWPnt( X, Y, Z );
1535 int aStudyId = application()->activeStudy()->id();
1536 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1537 double WX = aWPnt.X(), WY = aWPnt.Y();
1539 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1540 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1541 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1542 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1543 QString aMsg = tr( "COORDINATES_INFO" );
1544 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1545 aDesktop->statusBar()->showMessage( aMsg );
1551 * Returns stack of active operations;
1553 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1555 return myActiveOperationMap;
1559 * Returns the module active operation. If the active operation is show/hide,
1560 * the method returns the previous operation if it is.
1562 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1564 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1566 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1568 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1570 aVIt.previous(); // skip the top show/hide operation
1571 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;