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;
336 // Check the selected GEOM objects (take into account the Object Browser only)
337 if ( anIsObjectBrowser ) {
338 QList<GEOM::shape_type> anObstacleTypes =
339 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
340 QList<GEOM::shape_type> aPolylineTypes =
341 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
343 bool isCanBeImportedAsObstacle =
344 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
345 bool isCanBeImportedAsPolyline =
346 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
348 // Add import as obstacle action
349 if ( isCanBeImportedAsObstacle ) {
350 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
352 // Add import as polyline action
353 if ( isCanBeImportedAsPolyline ) {
354 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
357 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
358 theMenu->addSeparator();
362 // check the selected data model objects
363 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
364 int aNbOfSelectedProfiles = 0;
365 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
367 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
368 if( !anObject.IsNull() )
370 anIsSelectedDataObjects = true;
372 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
373 anIsVisibleInSelection |= aVisibility;
374 anIsHiddenInSelection |= !aVisibility;
376 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
378 anIsMustObjectBeUpdated = true;
381 ObjectKind anObjectKind = anObject->GetKind();
382 if( anObjectKind == KIND_IMAGE )
385 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
386 if( !anImage.IsNull() )
388 anIsImportedImage = anImage->HasLocalPoints();
389 anIsImageHasRefs = anImage->HasReferences();
390 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
392 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
394 QString anOperatorName = anOperator->name();
395 if( anOperatorName == ImageComposer_FuseOperator::Type() )
396 anIsFusedImage = true;
397 else if( anOperatorName == ImageComposer_CutOperator::Type() )
399 else if( anOperatorName == ImageComposer_CropOperator::Type() )
400 anIsSplittedImage = true;
405 else if( anObjectKind == KIND_POLYLINEXY )
407 else if( anObjectKind == KIND_POLYLINE )
408 anIsPolyline3D = true;
409 else if( anObjectKind == KIND_PROFILE )
412 aNbOfSelectedProfiles++;
414 Handle(HYDROData_Profile) aProfile =
415 Handle(HYDROData_Profile)::DownCast( anObject );
416 if( !aProfile.IsNull() && aProfile->IsValid() ) {
417 anIsValidProfile = true;
420 else if( anObjectKind == KIND_CALCULATION )
421 anIsCalculation = true;
422 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
423 anIsImmersibleZone = true;
424 else if( anObjectKind == KIND_VISUAL_STATE )
425 anIsVisualState = true;
426 else if( anObjectKind == KIND_REGION )
428 else if( anObjectKind == KIND_ZONE )
430 else if( anObjectKind == KIND_BATHYMETRY )
431 anIsBathymetry = true;
432 else if( anObjectKind == KIND_OBSTACLE )
434 else if( anObjectKind == KIND_STREAM )
436 else if( anObjectKind == KIND_CHANNEL )
438 else if( anObjectKind == KIND_DIGUE )
440 else if( anObjectKind == KIND_DUMMY_3D )
441 anIsDummyObject3D = true;
442 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
446 if ( !anIsObjectCanBeColored )
447 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
450 // Check if all selected objects are profiles
451 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
452 ( aNbOfSelectedProfiles == aSeq.Length() );
454 // check the selected partitions
455 if( !anIsSelectedDataObjects && anIsObjectBrowser )
457 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
458 if( aSelectedPartition != KIND_UNKNOWN )
460 switch( aSelectedPartition )
463 theMenu->addAction( action( ImportImageId ) );
465 case KIND_BATHYMETRY:
466 theMenu->addAction( action( ImportBathymetryId ) );
468 case KIND_ARTIFICIAL_OBJECT:
469 theMenu->addAction( action( CreateChannelId ) );
470 theMenu->addAction( action( CreateDigueId ) );
472 case KIND_NATURAL_OBJECT:
473 theMenu->addAction( action( CreateImmersibleZoneId ) );
474 theMenu->addAction( action( CreateStreamId ) );
477 theMenu->addAction( action( ImportObstacleFromFileId ) );
478 theMenu->addAction( action( CreateBoxId ) );
479 theMenu->addAction( action( CreateCylinderId ) );
481 case KIND_CALCULATION:
482 theMenu->addAction( action( CreateCalculationId ) );
484 case KIND_POLYLINEXY:
485 theMenu->addAction( action( CreatePolylineId ) );
488 theMenu->addAction( action( CreatePolyline3DId ) );
491 theMenu->addAction( action( CreateProfileId ) );
492 theMenu->addAction( action( ImportProfilesId ) );
493 theMenu->addAction( action( AllGeoreferencementId ) );
495 case KIND_VISUAL_STATE:
496 theMenu->addAction( action( SaveVisualStateId ) );
499 theMenu->addSeparator();
503 if( anIsSelectedDataObjects )
505 if ( anIsMustObjectBeUpdated )
507 theMenu->addAction( action( UpdateObjectId ) );
508 theMenu->addSeparator();
512 theMenu->addAction( action( ForcedUpdateObjectId ) );
513 theMenu->addSeparator();
517 if( aSeq.Length() == 1 )
521 if( anIsImportedImage )
522 theMenu->addAction( action( EditImportedImageId ) );
523 else if( anIsImageHasRefs )
526 theMenu->addAction( action( EditFusedImageId ) );
527 else if( anIsCutImage )
528 theMenu->addAction( action( EditCutImageId ) );
529 else if( anIsSplittedImage )
530 theMenu->addAction( action( EditSplittedImageId ) );
533 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
534 theMenu->addAction( action( ExportImageId ) );
535 theMenu->addSeparator();
537 if( anIsImageHasRefs )
539 theMenu->addAction( action( RemoveImageRefsId ) );
540 theMenu->addSeparator();
543 theMenu->addAction( action( FuseImagesId ) );
544 theMenu->addAction( action( CutImagesId ) );
545 theMenu->addAction( action( SplitImageId ) );
546 theMenu->addSeparator();
548 else if( anIsBathymetry )
550 theMenu->addAction( action( EditImportedBathymetryId ) );
551 theMenu->addAction( action( BathymetryBoundsId ) );
552 theMenu->addSeparator();
554 else if( anIsPolyline )
556 theMenu->addAction( action( EditPolylineId ) );
557 theMenu->addSeparator();
559 else if( anIsPolyline3D )
561 theMenu->addAction( action( EditPolyline3DId ) );
562 theMenu->addSeparator();
564 else if( anIsProfile )
566 theMenu->addAction( action( EditProfileId ) );
567 theMenu->addAction( action( SelectedGeoreferencementId ) );
568 theMenu->addSeparator();
570 else if( anIsCalculation )
572 theMenu->addAction( action( EditCalculationId ) );
573 theMenu->addAction( action( ExportCalculationId ) );
574 theMenu->addSeparator();
576 else if( anIsImmersibleZone )
578 theMenu->addAction( action( EditImmersibleZoneId ) );
579 theMenu->addSeparator();
581 else if( anIsStream )
583 theMenu->addAction( action( EditStreamId ) );
584 theMenu->addSeparator();
586 else if( anIsChannel )
588 theMenu->addAction( action( EditChannelId ) );
589 theMenu->addSeparator();
593 theMenu->addAction( action( EditDigueId ) );
594 theMenu->addSeparator();
596 else if( anIsObstacle )
598 theMenu->addAction( action( TranslateObstacleId ) );
599 theMenu->addSeparator();
601 else if( anIsVisualState && anIsObjectBrowser )
603 theMenu->addAction( action( SaveVisualStateId ) );
604 theMenu->addAction( action( LoadVisualStateId ) );
605 theMenu->addSeparator();
608 // Add set color action for geometrical objects
609 if ( anIsObjectCanBeColored )
611 theMenu->addAction( action( SetColorId ) );
612 theMenu->addSeparator();
614 } else if ( anAllAreProfiles ) {
615 theMenu->addAction( action( SelectedGeoreferencementId ) );
616 theMenu->addSeparator();
620 QAction* aCopyAction = action( CopyId );
621 if( aCopyAction && aCopyAction->isEnabled() ) {
622 theMenu->addAction( action( CopyId ) );
623 theMenu->addSeparator();
627 if( !anIsDummyObject3D )
628 theMenu->addAction( action( DeleteId ) );
630 theMenu->addSeparator();
632 if( anIsImage || anIsPolyline || anIsPolyline3D ||
633 anIsImmersibleZone || anIsZone || anIsRegion ||
634 anIsBathymetry || anIsObstacle || anIsStream ||
635 anIsChannel || anIsDigue || anIsDummyObject3D ||
636 anIsValidProfile || anIsGroup )
638 if( anIsHiddenInSelection )
639 theMenu->addAction( action( ShowId ) );
640 theMenu->addAction( action( ShowOnlyId ) );
641 if( anIsVisibleInSelection )
642 theMenu->addAction( action( HideId ) );
643 theMenu->addSeparator();
649 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
650 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
651 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
652 theMenu->addAction( action( DeleteId ) );
654 theMenu->addSeparator();
655 theMenu->addAction( action( SetZLevelId ) );
656 theMenu->addSeparator();
659 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
661 theMenu->addAction( action( ShowAllId ) );
662 theMenu->addAction( action( HideAllId ) );
663 theMenu->addSeparator();
666 if ( anIsOCCView || anIsVTKView )
668 theMenu->addSeparator();
669 theMenu->addAction( action( CopyViewerPositionId ) );
673 void HYDROGUI_Module::update( const int flags )
675 if( !isUpdateEnabled() )
678 QApplication::setOverrideCursor( Qt::WaitCursor );
680 // To prevent calling this method recursively
681 // from one of the methods called below
682 setUpdateEnabled( false );
684 // store selected objects
685 QStringList aSelectedEntries = storeSelection();
687 bool aDoFitAll = flags & UF_FitAll;
688 if( ( flags & UF_Viewer ) )
689 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
691 if( ( flags & UF_OCCViewer ) )
692 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
694 if( ( flags & UF_VTKViewer ) )
695 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
697 if( ( flags & UF_Model ) && getDataModel() && getApp() )
699 getDataModel()->update( getStudyId() );
701 // Temporary workaround to prevent breaking
702 // the selection in the object browser.
703 // Note: processEvents() should be called after updateGV(),
704 // otherwise the application crashes from time to time.
705 //RKV: qApp->processEvents();
706 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
707 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
708 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
709 if ( isResizeOnExpandItem && anObjectBrowser ) {
710 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
712 getApp()->updateObjectBrowser( true );
713 if ( isResizeOnExpandItem && anObjectBrowser ) {
714 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
718 // Object browser is currently updated by using UF_Model flag
719 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
720 getApp()->updateObjectBrowser( true );
722 if( ( flags & UF_Controls ) && getApp() )
723 getApp()->updateActions();
725 // restore selected objects
726 restoreSelection( aSelectedEntries );
728 setUpdateEnabled( true );
730 QApplication::restoreOverrideCursor();
733 void HYDROGUI_Module::updateCommandsStatus()
735 LightApp_Module::updateCommandsStatus();
737 updateUndoRedoControls();
739 action( CopyId )->setEnabled( getDataModel()->canCopy() );
740 action( PasteId )->setEnabled( getDataModel()->canPaste() );
743 void HYDROGUI_Module::selectionChanged()
745 LightApp_Module::selectionChanged();
746 updateCommandsStatus();
749 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
751 return (HYDROGUI_DataModel*)dataModel();
754 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
759 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
761 return myOCCDisplayer;
764 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
766 return myVTKDisplayer;
769 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
771 if( myViewManagerMap.contains( theId ) )
773 return myViewManagerMap[ theId ].first;
778 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
780 if( myViewManagerMap.contains( theId ) )
782 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
783 GraphicsView_ViewManager* aViewManager =
784 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
786 return aViewManager->getViewer();
791 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
793 if( myViewManagerMap.contains( theId ) )
795 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
796 OCCViewer_ViewManager* aViewManager =
797 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
799 return aViewManager->getOCCViewer();
804 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
806 if( myViewManagerMap.contains( theId ) )
808 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
809 SVTK_ViewManager* aViewManager =
810 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
812 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
817 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
819 ViewManagerMapIterator anIter( myViewManagerMap );
820 while( anIter.hasNext() )
822 int anId = anIter.next().key();
823 const ViewManagerInfo& anInfo = anIter.value();
824 if( anInfo.first == theViewManager )
830 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
832 int anId = getViewManagerId( theViewManager );
835 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
836 return anInfo.second;
841 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
842 const ViewManagerRole theRole )
844 int anId = getViewManagerId( theViewManager );
847 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
848 anInfo.second = theRole;
852 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
853 const Handle(HYDROData_Entity)& theObject ) const
855 if( theObject.IsNull() )
858 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
859 if( anIter1 != myObjectStateMap.end() )
861 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
862 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
864 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
865 if( anIter2 != aEntry2ObjectStateMap.end() )
867 const ObjectState& anObjectState = anIter2.value();
868 return anObjectState.Visibility;
874 void HYDROGUI_Module::setObjectVisible( const int theViewId,
875 const Handle(HYDROData_Entity)& theObject,
876 const bool theState )
878 if( !theObject.IsNull() )
880 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
881 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
883 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
884 anObjectState.Visibility = theState;
888 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
889 const bool theState )
891 if( !theObject.IsNull() )
893 // Process OCC shapes
894 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
895 while( aShapesMapIter != myShapesMap.end() )
897 const ListOfShapes& aShapesList = aShapesMapIter.value();
898 foreach ( HYDROGUI_Shape* aShape, aShapesList )
900 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
902 aShape->setIsToUpdate( theState );
907 // Process VTK shapes
908 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
909 while( aVTKPrsMapIter != myVTKPrsMap.end() )
911 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
912 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
914 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
916 aShape->setIsToUpdate( theState );
924 /////////////////// OCC SHAPES PROCESSING
925 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
926 const Handle(HYDROData_Entity)& theObject ) const
928 HYDROGUI_Shape* aResShape = NULL;
929 if( theObject.IsNull() )
932 if ( myShapesMap.contains( theViewId ) )
934 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
935 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
937 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
948 void HYDROGUI_Module::setObjectShape( const int theViewId,
949 const Handle(HYDROData_Entity)& theObject,
950 HYDROGUI_Shape* theShape )
952 if( theObject.IsNull() )
955 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
956 aViewShapes.append( theShape );
959 void HYDROGUI_Module::removeObjectShape( const int theViewId,
960 const Handle(HYDROData_Entity)& theObject )
962 if ( !myShapesMap.contains( theViewId ) )
965 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
966 Handle(HYDROData_Entity) anObject;
967 for ( int i = 0; i < aViewShapes.length(); )
969 HYDROGUI_Shape* aShape = aViewShapes.at( i );
970 anObject = aShape->getObject();
971 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
974 aViewShapes.removeAt( i );
982 void HYDROGUI_Module::removeViewShapes( const int theViewId )
984 if ( !myShapesMap.contains( theViewId ) )
987 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
988 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
990 HYDROGUI_Shape* aShape = aViewShapes.at( i );
995 myShapesMap.remove( theViewId );
997 /////////////////// END OF OCC SHAPES PROCESSING
999 /////////////////// VTKPrs PROCESSING
1000 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1001 const Handle(HYDROData_Entity)& theObject ) const
1003 HYDROGUI_VTKPrs* aResShape = NULL;
1004 if( theObject.IsNull() )
1007 if ( myVTKPrsMap.contains( theViewId ) )
1009 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1010 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1012 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1023 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1024 const Handle(HYDROData_Entity)& theObject,
1025 HYDROGUI_VTKPrs* theShape )
1027 if( theObject.IsNull() )
1030 if( theShape && theShape->needScalarBar() )
1032 // Compute the new global Z range from the added presentation and the old global Z range.
1033 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1034 double* aRange = theShape->getInternalZRange();
1035 bool anIsUpdate = false;
1036 if ( aRange[0] < aGlobalRange[0] )
1038 aGlobalRange[0] = aRange[0];
1041 if ( aRange[1] > aGlobalRange[1] )
1043 aGlobalRange[1] = aRange[1];
1049 updateVTKZRange( theViewId, aGlobalRange );
1053 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1054 aViewShapes.append( theShape );
1057 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1058 const QString& theEntry )
1060 if ( !myVTKPrsMap.contains( theViewId ) )
1063 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1064 Handle(HYDROData_Entity) anObject;
1066 for ( int i = 0; i < aViewShapes.length(); )
1068 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1069 anObject = aShape->getObject();
1070 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1071 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1074 aViewShapes.removeAt( i );
1081 // Invalidate global Z range
1082 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1083 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1086 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1087 const Handle(HYDROData_Entity)& theObject )
1089 if ( !myVTKPrsMap.contains( theViewId ) )
1092 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1093 Handle(HYDROData_Entity) anObject;
1094 for ( int i = 0; i < aViewShapes.length(); )
1096 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1097 anObject = aShape->getObject();
1098 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1101 aViewShapes.removeAt( i );
1108 // Invalidate global Z range
1109 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1110 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1113 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1115 if ( !myVTKPrsMap.contains( theViewId ) )
1118 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1119 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1121 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1126 myVTKPrsMap.remove( theViewId );
1129 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1131 if ( myVTKPrsMap.contains( theViewId ) )
1133 // For the given viewer id update all VTK presentations ...
1134 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1135 HYDROGUI_VTKPrs* aShape;
1136 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1138 aShape = aViewShapes.at( i );
1139 if ( aShape && aShape->needScalarBar() )
1141 aShape->setZRange( theRange );
1145 // ... and update the global color legend scalar bar.
1146 getVTKDisplayer()->SetZRange( theViewId, theRange );
1148 /////////////////// END OF VTKPrs PROCESSING
1150 CAM_DataModel* HYDROGUI_Module::createDataModel()
1152 return new HYDROGUI_DataModel( this );
1155 void HYDROGUI_Module::customEvent( QEvent* e )
1157 int aType = e->type();
1158 if ( aType == NewViewEvent )
1160 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1161 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1163 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1165 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1166 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1168 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1170 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1171 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1173 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1174 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1175 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1177 //ouv: temporarily commented
1178 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1181 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1182 update( UF_Viewer );
1184 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1190 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1192 QEvent::Type aType = theEvent->type();
1193 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1195 if( aType == QEvent::Show )
1197 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1198 e->setData( theObj );
1199 QApplication::postEvent( this, e );
1200 theObj->removeEventFilter( this );
1203 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1205 if( aType == QEvent::Leave )
1207 SUIT_Desktop* aDesktop = getApp()->desktop();
1208 if ( aDesktop && aDesktop->statusBar() ) {
1209 aDesktop->statusBar()->clearMessage();
1213 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1215 if( aType == QEvent::Leave )
1217 SUIT_Desktop* aDesktop = getApp()->desktop();
1218 if ( aDesktop && aDesktop->statusBar() ) {
1219 aDesktop->statusBar()->clearMessage();
1224 return LightApp_Module::eventFilter( theObj, theEvent );
1227 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1229 LightApp_Module::onViewManagerAdded( theViewManager );
1231 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1233 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1234 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1236 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1238 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1239 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1240 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1241 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1243 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1245 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1246 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1247 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1248 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1251 createSelector( theViewManager ); // replace the default selector
1253 ViewManagerInfo anInfo( theViewManager, VMR_General );
1254 myViewManagerMap.insert( ViewManagerId++, anInfo );
1257 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1259 LightApp_Module::onViewManagerRemoved( theViewManager );
1261 createSelector( theViewManager ); // replace the default selector
1263 int anId = getViewManagerId( theViewManager );
1266 OCCViewer_ViewManager* anOCCViewManager =
1267 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1268 if ( anOCCViewManager )
1270 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1272 removeViewShapes( (size_t)anOCCViewer );
1275 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1277 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1280 getVTKDisplayer()->EraseScalarBar( anId, true );
1281 removeViewShapes( (size_t)aVTKViewer );
1285 myViewManagerMap.remove( anId );
1289 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1291 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1293 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1295 aViewFrame->installEventFilter( this );
1297 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1299 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1300 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1303 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1305 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1307 aViewFrame->onTopView();
1309 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1311 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1313 aViewPort->installEventFilter( this );
1317 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1319 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1321 aViewFrame->installEventFilter( this );
1326 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1328 /* ouv: currently unused
1329 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1331 SUIT_ViewManager* aViewManager = 0;
1333 QObject* aParent = aViewPort;
1334 while( aParent = aParent->parent() )
1336 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1338 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1340 aViewManager = aViewer->getViewManager();
1349 double aMouseX = theEvent->scenePos().x();
1350 double aMouseY = theEvent->scenePos().y();
1352 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1353 if( aRole == VMR_General )
1355 int aXDeg = 0, aYDeg = 0;
1356 int aXMin = 0, aYMin = 0;
1357 double aXSec = 0, aYSec = 0;
1358 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1359 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1361 QString aDegSymbol( QChar( 0x00B0 ) );
1362 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1363 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1365 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1367 else if( aRole == VMR_TransformImage )
1368 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1373 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1374 const bool theIsInit,
1375 const bool theIsForced,
1376 const bool theDoFitAll )
1378 QList<int> aViewManagerIdList;
1380 // currently, all views are updated
1381 ViewManagerMapIterator anIter( myViewManagerMap );
1382 while( anIter.hasNext() )
1384 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1386 if ( theDisplayer->IsApplicable( aViewManager ) )
1388 int anId = anIter.key();
1389 aViewManagerIdList.append( anId );
1393 QListIterator<int> anIdIter( aViewManagerIdList );
1394 while( anIdIter.hasNext() )
1396 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1400 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1402 if( !theViewManager )
1405 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1406 if( !aSelectionMgr )
1409 QString aViewType = theViewManager->getType();
1410 if( aViewType != GraphicsView_Viewer::Type() &&
1411 aViewType != OCCViewer_Viewer::Type())
1414 QList<SUIT_Selector*> aSelectorList;
1415 aSelectionMgr->selectors( aViewType, aSelectorList );
1417 // disable all alien selectors
1418 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1419 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1421 SUIT_Selector* aSelector = *anIter;
1422 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1423 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1424 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1425 aSelector->setEnabled( false );
1428 if ( aViewType == GraphicsView_Viewer::Type() )
1430 GraphicsView_ViewManager* aViewManager =
1431 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1433 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1435 else if ( aViewType == OCCViewer_Viewer::Type() )
1437 OCCViewer_ViewManager* aViewManager =
1438 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1440 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1444 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1446 bool aPrevState = myIsUpdateEnabled;
1447 myIsUpdateEnabled = theState;
1451 bool HYDROGUI_Module::isUpdateEnabled() const
1453 return myIsUpdateEnabled;
1456 QStringList HYDROGUI_Module::storeSelection() const
1458 QStringList anEntryList;
1459 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1461 SUIT_DataOwnerPtrList aList( true );
1462 aSelectionMgr->selected( aList );
1464 SUIT_DataOwnerPtrList::iterator anIter;
1465 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1467 const LightApp_DataOwner* anOwner =
1468 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1470 anEntryList.append( anOwner->entry() );
1476 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1478 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1480 SUIT_DataOwnerPtrList aList( true );
1481 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1482 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1483 aSelectionMgr->setSelected( aList );
1487 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1490 bool doShow = false;
1491 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1493 aDisplayer->SaveCursorViewPosition( theViewWindow );
1494 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, aX, aY, aZ );
1498 // Show the coordinates in the status bar
1499 SUIT_Desktop* aDesktop = getApp()->desktop();
1500 if ( aDesktop && aDesktop->statusBar() ) {
1501 QString aXStr = HYDROGUI_Tool::GetCoordinateString( aX );
1502 QString anYStr = HYDROGUI_Tool::GetCoordinateString( aY );
1503 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aXStr ).arg( anYStr ) );
1509 * Returns stack of active operations;
1511 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1513 return myActiveOperationMap;
1517 * Returns the module active operation. If the active operation is show/hide,
1518 * the method returns the previous operation if it is.
1520 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1522 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1524 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1526 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1528 aVIt.previous(); // skip the top show/hide operation
1529 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;