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"
46 #include <HYDROData_Image.h>
47 #include <HYDROData_Profile.h>
48 #include <HYDROData_Lambert93.h>
49 #include <HYDROData_Tool.h>
51 #include <HYDROData_OperationsFactory.h>
53 #include <CurveCreator_Utils.h>
55 #include <GraphicsView_ViewFrame.h>
56 #include <GraphicsView_ViewManager.h>
57 #include <GraphicsView_ViewPort.h>
58 #include <GraphicsView_Viewer.h>
60 #include <ImageComposer_CutOperator.h>
61 #include <ImageComposer_CropOperator.h>
62 #include <ImageComposer_FuseOperator.h>
64 #include <LightApp_Application.h>
65 #include <LightApp_DataOwner.h>
66 #include <LightApp_GVSelector.h>
67 #include <LightApp_SelectionMgr.h>
68 #include <LightApp_UpdateFlags.h>
70 #include <SalomeApp_Study.h>
72 #include <OCCViewer_ViewFrame.h>
73 #include <OCCViewer_ViewManager.h>
74 #include <OCCViewer_ViewModel.h>
76 #include <SALOME_Event.h>
78 #include <SUIT_DataBrowser.h>
79 #include <SUIT_Desktop.h>
80 #include <SUIT_Study.h>
81 #include <SUIT_ViewManager.h>
82 #include <SUIT_ResourceMgr.h>
84 #include <SVTK_ViewManager.h>
85 #include <SVTK_ViewModel.h>
86 #include <SVTK_ViewWindow.h>
87 #include <SVTK_Selector.h>
88 #include <vtkRenderWindowInteractor.h>
89 #include <vtkRenderer.h>
90 #include <vtkWorldPointPicker.h>
91 #include <vtkCamera.h>
93 #include <OCCViewer_ViewPort3d.h>
95 #include <GEOMUtils.hxx>
96 #include <GeometryGUI.h>
98 #include <SALOMEDS_wrap.hxx>
101 #include <QApplication>
102 #include <QGraphicsSceneMouseEvent>
104 #include <QMouseEvent>
105 #include <QStatusBar>
107 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
109 static int ViewManagerId = 0;
111 extern "C" HYDRO_EXPORT CAM_Module* createModule()
113 return new HYDROGUI_Module();
116 extern "C" HYDRO_EXPORT char* getModuleVersion()
118 return (char*)HYDRO_VERSION;
121 HYDROGUI_Module::HYDROGUI_Module()
122 : LightApp_Module( "HYDRO" ),
125 myIsUpdateEnabled( true )
129 HYDROGUI_Module::~HYDROGUI_Module()
133 int HYDROGUI_Module::getStudyId() const
135 LightApp_Application* anApp = getApp();
136 return anApp ? anApp->activeStudy()->id() : 0;
139 void HYDROGUI_Module::initialize( CAM_Application* theApp )
141 LightApp_Module::initialize( theApp );
144 createUndoRedoActions();
149 setMenuShown( false );
150 setToolShown( false );
152 myDisplayer = new HYDROGUI_Displayer( this );
153 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
154 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
157 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
159 bool aRes = LightApp_Module::activateModule( theStudy );
161 LightApp_Application* anApp = getApp();
162 SUIT_Desktop* aDesktop = anApp->desktop();
164 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
166 setMenuShown( true );
167 setToolShown( true );
169 #ifndef DISABLE_PYCONSOLE
170 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
171 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
174 // Remove defunct view managers from the map.
175 // It's essential to do this before "update( UF_All )" call!
176 QList<int> anObsoleteIds;
177 ViewManagerList anAllViewManagers = anApp->viewManagers();
178 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
179 ViewManagerMapIterator anIter( myViewManagerMap );
180 while( anIter.hasNext() ) {
181 int anId = anIter.next().key();
182 const ViewManagerInfo& anInfo = anIter.value();
184 aHydroViewManagers << anInfo.first;
186 if ( !anAllViewManagers.contains( anInfo.first ) ) {
187 anObsoleteIds << anId;
190 foreach ( const int anId, anObsoleteIds ) {
191 myViewManagerMap.remove( anId );
192 myObjectStateMap.remove( anId );
193 myObjectDisplayOrderMap.remove( anId );
194 myShapesMap.remove( anId );
195 myVTKPrsMap.remove( anId );
197 // Replace the default selector for all view managers.
198 // Add view managers created outside of HYDRO module to the map.
199 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
200 createSelector( aViewManager ); // replace the default selector
201 if ( !aHydroViewManagers.contains( aViewManager ) ) {
202 ViewManagerInfo anInfo( aViewManager, VMR_General );
203 myViewManagerMap.insert( ViewManagerId++, anInfo );
209 updateCommandsStatus();
211 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
213 ViewManagerList anOCCViewManagers;
214 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
215 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
216 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
217 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
218 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
219 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
220 if ( aViewFrame && aViewFrame->getViewPort() ) {
221 aViewFrame->getViewPort()->installEventFilter( this );
227 SalomeApp_Study* aStudy =
228 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
230 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
231 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
232 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
233 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
234 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
235 if( !GEOM_var->_is_nil() ) {
236 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
244 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
247 ViewManagerMapIterator anIter( myViewManagerMap );
248 while( anIter.hasNext() )
249 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
250 getApp()->removeViewManager( aViewManager );
251 myViewManagerMap.clear();
254 ViewManagerList anOCCViewManagers;
255 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
256 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
257 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
258 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
262 myObjectStateMap.clear();
267 // clear the data model's list of copying objects
268 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
270 setMenuShown( false );
271 setToolShown( false );
273 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
275 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
277 return LightApp_Module::deactivateModule( theStudy );
280 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
283 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
284 #ifndef DISABLE_PYCONSOLE
285 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
287 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
290 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
292 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
295 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
299 HYDROGUI_DataModel* aModel = getDataModel();
301 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
302 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
303 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
304 bool anIsVTKView = theClient == SVTK_Viewer::Type();
305 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
308 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
310 bool anIsSelectedDataObjects = false;
311 bool anIsVisibleInSelection = false;
312 bool anIsHiddenInSelection = false;
314 bool anIsImage = false;
315 bool anIsImportedImage = false;
316 bool anIsImageHasRefs = false;
317 bool anIsFusedImage = false;
318 bool anIsCutImage = false;
319 bool anIsSplittedImage = false;
320 bool anIsMustObjectBeUpdated = false;
321 bool anIsPolyline = false;
322 bool anIsPolyline3D = false;
323 bool anIsProfile = false;
324 bool anIsValidProfile = false;
325 bool anAllAreProfiles = false;
326 bool anIsBathymetry = false;
327 bool anIsCalculation = false;
328 bool anIsImmersibleZone = false;
329 bool anIsVisualState = false;
330 bool anIsRegion = false;
331 bool anIsZone = false;
332 bool anIsObstacle = false;
333 bool anIsStream = false;
334 bool anIsChannel = false;
335 bool anIsDigue = false;
336 bool anIsDummyObject3D = false;
337 bool anIsGroup = false;
338 bool anIsObjectCanBeColored = false;
340 // Check the selected GEOM objects (take into account the Object Browser only)
341 if ( anIsObjectBrowser ) {
342 QList<GEOM::shape_type> anObstacleTypes =
343 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
344 QList<GEOM::shape_type> aPolylineTypes =
345 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
347 bool isCanBeImportedAsObstacle =
348 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
349 bool isCanBeImportedAsPolyline =
350 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
352 // Add import as obstacle action
353 if ( isCanBeImportedAsObstacle ) {
354 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
356 // Add import as polyline action
357 if ( isCanBeImportedAsPolyline ) {
358 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
361 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
362 theMenu->addSeparator();
366 // check the selected data model objects
367 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
368 int aNbOfSelectedProfiles = 0;
369 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
371 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
372 if( !anObject.IsNull() )
374 anIsSelectedDataObjects = true;
376 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
377 anIsVisibleInSelection |= aVisibility;
378 anIsHiddenInSelection |= !aVisibility;
380 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
382 anIsMustObjectBeUpdated = true;
385 ObjectKind anObjectKind = anObject->GetKind();
386 if( anObjectKind == KIND_IMAGE )
389 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
390 if( !anImage.IsNull() )
392 anIsImportedImage = anImage->HasLocalPoints();
393 anIsImageHasRefs = anImage->HasReferences();
394 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
396 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
398 QString anOperatorName = anOperator->name();
399 if( anOperatorName == ImageComposer_FuseOperator::Type() )
400 anIsFusedImage = true;
401 else if( anOperatorName == ImageComposer_CutOperator::Type() )
403 else if( anOperatorName == ImageComposer_CropOperator::Type() )
404 anIsSplittedImage = true;
409 else if( anObjectKind == KIND_POLYLINEXY )
411 else if( anObjectKind == KIND_POLYLINE )
412 anIsPolyline3D = true;
413 else if( anObjectKind == KIND_PROFILE )
416 aNbOfSelectedProfiles++;
418 Handle(HYDROData_Profile) aProfile =
419 Handle(HYDROData_Profile)::DownCast( anObject );
420 if( !aProfile.IsNull() && aProfile->IsValid() ) {
421 anIsValidProfile = true;
424 else if( anObjectKind == KIND_CALCULATION )
425 anIsCalculation = true;
426 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
427 anIsImmersibleZone = true;
428 else if( anObjectKind == KIND_VISUAL_STATE )
429 anIsVisualState = true;
430 else if( anObjectKind == KIND_REGION )
432 else if( anObjectKind == KIND_ZONE )
434 else if( anObjectKind == KIND_BATHYMETRY )
435 anIsBathymetry = true;
436 else if( anObjectKind == KIND_OBSTACLE )
438 else if( anObjectKind == KIND_STREAM )
440 else if( anObjectKind == KIND_CHANNEL )
442 else if( anObjectKind == KIND_DIGUE )
444 else if( anObjectKind == KIND_DUMMY_3D )
445 anIsDummyObject3D = true;
446 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
450 if ( !anIsObjectCanBeColored )
451 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
454 // Check if all selected objects are profiles
455 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
456 ( aNbOfSelectedProfiles == aSeq.Length() );
458 // check the selected partitions
459 if( !anIsSelectedDataObjects && anIsObjectBrowser )
461 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
462 if( aSelectedPartition != KIND_UNKNOWN )
464 switch( aSelectedPartition )
467 theMenu->addAction( action( ImportImageId ) );
469 case KIND_BATHYMETRY:
470 theMenu->addAction( action( ImportBathymetryId ) );
472 case KIND_ARTIFICIAL_OBJECT:
473 theMenu->addAction( action( CreateChannelId ) );
474 theMenu->addAction( action( CreateDigueId ) );
476 case KIND_NATURAL_OBJECT:
477 theMenu->addAction( action( CreateImmersibleZoneId ) );
478 theMenu->addAction( action( CreateStreamId ) );
481 theMenu->addAction( action( ImportObstacleFromFileId ) );
482 theMenu->addAction( action( CreateBoxId ) );
483 theMenu->addAction( action( CreateCylinderId ) );
485 case KIND_CALCULATION:
486 theMenu->addAction( action( CreateCalculationId ) );
488 case KIND_POLYLINEXY:
489 theMenu->addAction( action( CreatePolylineId ) );
492 theMenu->addAction( action( CreatePolyline3DId ) );
495 theMenu->addAction( action( CreateProfileId ) );
496 theMenu->addAction( action( ImportProfilesId ) );
497 theMenu->addAction( action( AllGeoreferencementId ) );
499 case KIND_VISUAL_STATE:
500 theMenu->addAction( action( SaveVisualStateId ) );
503 theMenu->addSeparator();
507 if( anIsSelectedDataObjects )
509 if ( anIsMustObjectBeUpdated )
511 theMenu->addAction( action( UpdateObjectId ) );
512 theMenu->addSeparator();
516 theMenu->addAction( action( ForcedUpdateObjectId ) );
517 theMenu->addSeparator();
521 if( aSeq.Length() == 1 )
525 if( anIsImportedImage )
526 theMenu->addAction( action( EditImportedImageId ) );
527 else if( anIsImageHasRefs )
530 theMenu->addAction( action( EditFusedImageId ) );
531 else if( anIsCutImage )
532 theMenu->addAction( action( EditCutImageId ) );
533 else if( anIsSplittedImage )
534 theMenu->addAction( action( EditSplittedImageId ) );
537 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
538 theMenu->addAction( action( ExportImageId ) );
539 theMenu->addSeparator();
541 if( anIsImageHasRefs )
543 theMenu->addAction( action( RemoveImageRefsId ) );
544 theMenu->addSeparator();
547 theMenu->addAction( action( FuseImagesId ) );
548 theMenu->addAction( action( CutImagesId ) );
549 theMenu->addAction( action( SplitImageId ) );
550 theMenu->addSeparator();
552 else if( anIsBathymetry )
554 theMenu->addAction( action( EditImportedBathymetryId ) );
555 theMenu->addAction( action( BathymetryBoundsId ) );
556 theMenu->addSeparator();
558 else if( anIsPolyline )
560 theMenu->addAction( action( EditPolylineId ) );
561 theMenu->addSeparator();
563 else if( anIsPolyline3D )
565 theMenu->addAction( action( EditPolyline3DId ) );
566 theMenu->addSeparator();
568 else if( anIsProfile )
570 theMenu->addAction( action( EditProfileId ) );
571 theMenu->addAction( action( SelectedGeoreferencementId ) );
572 theMenu->addSeparator();
574 else if( anIsCalculation )
576 theMenu->addAction( action( EditCalculationId ) );
577 theMenu->addAction( action( ExportCalculationId ) );
578 theMenu->addSeparator();
580 else if( anIsImmersibleZone )
582 theMenu->addAction( action( EditImmersibleZoneId ) );
583 theMenu->addSeparator();
585 else if( anIsStream )
587 theMenu->addAction( action( EditStreamId ) );
588 theMenu->addSeparator();
590 else if( anIsChannel )
592 theMenu->addAction( action( EditChannelId ) );
593 theMenu->addSeparator();
597 theMenu->addAction( action( EditDigueId ) );
598 theMenu->addSeparator();
600 else if( anIsVisualState && anIsObjectBrowser )
602 theMenu->addAction( action( SaveVisualStateId ) );
603 theMenu->addAction( action( LoadVisualStateId ) );
604 theMenu->addSeparator();
607 // Add set color action for geometrical objects
608 if ( anIsObjectCanBeColored )
610 theMenu->addAction( action( SetColorId ) );
611 theMenu->addSeparator();
615 if( aModel->canCopy() ) {
616 theMenu->addAction( action( CopyId ) );
617 theMenu->addSeparator();
619 } else if ( anAllAreProfiles ) {
620 theMenu->addAction( action( SelectedGeoreferencementId ) );
621 theMenu->addSeparator();
624 if( !anIsDummyObject3D )
625 theMenu->addAction( action( DeleteId ) );
626 theMenu->addSeparator();
628 if( anIsImage || anIsPolyline || anIsPolyline3D ||
629 anIsImmersibleZone || anIsZone || anIsRegion ||
630 anIsBathymetry || anIsObstacle || anIsStream ||
631 anIsChannel || anIsDigue || anIsDummyObject3D ||
632 anIsValidProfile || anIsGroup )
634 if( anIsHiddenInSelection )
635 theMenu->addAction( action( ShowId ) );
636 theMenu->addAction( action( ShowOnlyId ) );
637 if( anIsVisibleInSelection )
638 theMenu->addAction( action( HideId ) );
639 theMenu->addSeparator();
645 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
646 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
647 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
648 theMenu->addAction( action( DeleteId ) );
651 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
653 theMenu->addAction( action( ShowAllId ) );
654 theMenu->addAction( action( HideAllId ) );
655 theMenu->addSeparator();
658 theMenu->addSeparator();
659 theMenu->addAction( action( CopyViewerPositionId ) );
663 void HYDROGUI_Module::update( const int flags )
665 if( !isUpdateEnabled() )
668 QApplication::setOverrideCursor( Qt::WaitCursor );
670 // To prevent calling this method recursively
671 // from one of the methods called below
672 setUpdateEnabled( false );
674 // store selected objects
675 QStringList aSelectedEntries = storeSelection();
677 bool aDoFitAll = flags & UF_FitAll;
678 if( ( flags & UF_Viewer ) )
679 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
681 if( ( flags & UF_OCCViewer ) )
682 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
684 if( ( flags & UF_VTKViewer ) )
685 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
687 if( ( flags & UF_Model ) && getDataModel() && getApp() )
689 getDataModel()->update( getStudyId() );
691 // Temporary workaround to prevent breaking
692 // the selection in the object browser.
693 // Note: processEvents() should be called after updateGV(),
694 // otherwise the application crashes from time to time.
695 //RKV: qApp->processEvents();
696 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
697 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
698 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
699 if ( isResizeOnExpandItem && anObjectBrowser ) {
700 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
702 getApp()->updateObjectBrowser( true );
703 if ( isResizeOnExpandItem && anObjectBrowser ) {
704 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
708 // Object browser is currently updated by using UF_Model flag
709 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
710 getApp()->updateObjectBrowser( true );
712 if( ( flags & UF_Controls ) && getApp() )
713 getApp()->updateActions();
715 // restore selected objects
716 restoreSelection( aSelectedEntries );
718 setUpdateEnabled( true );
720 QApplication::restoreOverrideCursor();
723 void HYDROGUI_Module::updateCommandsStatus()
725 LightApp_Module::updateCommandsStatus();
727 updateUndoRedoControls();
729 action( CopyId )->setEnabled( getDataModel()->canCopy() );
730 action( PasteId )->setEnabled( getDataModel()->canPaste() );
733 void HYDROGUI_Module::selectionChanged()
735 LightApp_Module::selectionChanged();
736 updateCommandsStatus();
739 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
741 return (HYDROGUI_DataModel*)dataModel();
744 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
749 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
751 return myOCCDisplayer;
754 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
756 return myVTKDisplayer;
759 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
761 if( myViewManagerMap.contains( theId ) )
763 return myViewManagerMap[ theId ].first;
768 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
770 if( myViewManagerMap.contains( theId ) )
772 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
773 GraphicsView_ViewManager* aViewManager =
774 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
776 return aViewManager->getViewer();
781 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
783 if( myViewManagerMap.contains( theId ) )
785 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
786 OCCViewer_ViewManager* aViewManager =
787 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
789 return aViewManager->getOCCViewer();
794 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
796 if( myViewManagerMap.contains( theId ) )
798 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
799 SVTK_ViewManager* aViewManager =
800 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
802 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
807 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
809 ViewManagerMapIterator anIter( myViewManagerMap );
810 while( anIter.hasNext() )
812 int anId = anIter.next().key();
813 const ViewManagerInfo& anInfo = anIter.value();
814 if( anInfo.first == theViewManager )
820 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
822 int anId = getViewManagerId( theViewManager );
825 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
826 return anInfo.second;
831 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
832 const ViewManagerRole theRole )
834 int anId = getViewManagerId( theViewManager );
837 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
838 anInfo.second = theRole;
842 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
843 const Handle(HYDROData_Entity)& theObject ) const
845 if( theObject.IsNull() )
848 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
849 if( anIter1 != myObjectStateMap.end() )
851 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
852 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
854 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
855 if( anIter2 != aEntry2ObjectStateMap.end() )
857 const ObjectState& anObjectState = anIter2.value();
858 return anObjectState.Visibility;
864 void HYDROGUI_Module::setObjectVisible( const int theViewId,
865 const Handle(HYDROData_Entity)& theObject,
866 const bool theState )
868 if( !theObject.IsNull() )
870 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
871 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
873 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
874 anObjectState.Visibility = theState;
876 // Remember the display order ( needed for Z layers assignment only )
877 QStringList& anObjectEntries = myObjectDisplayOrderMap[ theViewId ];
878 anObjectEntries.removeAll( anEntry );
880 anObjectEntries.append( anEntry );
885 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
886 const bool theState )
888 if( !theObject.IsNull() )
890 // Process OCC shapes
891 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
892 while( aShapesMapIter != myShapesMap.end() )
894 const ListOfShapes& aShapesList = aShapesMapIter.value();
895 foreach ( HYDROGUI_Shape* aShape, aShapesList )
897 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
899 aShape->setIsToUpdate( theState );
904 // Process VTK shapes
905 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
906 while( aVTKPrsMapIter != myVTKPrsMap.end() )
908 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
909 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
911 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
913 aShape->setIsToUpdate( theState );
921 /////////////////// OCC SHAPES PROCESSING
922 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
923 const Handle(HYDROData_Entity)& theObject ) const
925 HYDROGUI_Shape* aResShape = NULL;
926 if( theObject.IsNull() )
929 if ( myShapesMap.contains( theViewId ) )
931 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
932 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
934 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
945 void HYDROGUI_Module::setObjectShape( const int theViewId,
946 const Handle(HYDROData_Entity)& theObject,
947 HYDROGUI_Shape* theShape )
949 if( theObject.IsNull() )
952 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
953 aViewShapes.append( theShape );
956 void HYDROGUI_Module::removeObjectShape( const int theViewId,
957 const Handle(HYDROData_Entity)& theObject )
959 if ( !myShapesMap.contains( theViewId ) )
962 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
963 Handle(HYDROData_Entity) anObject;
964 for ( int i = 0; i < aViewShapes.length(); )
966 HYDROGUI_Shape* aShape = aViewShapes.at( i );
967 anObject = aShape->getObject();
968 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
971 aViewShapes.removeAt( i );
979 void HYDROGUI_Module::removeViewShapes( const int theViewId )
981 if ( !myShapesMap.contains( theViewId ) )
984 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
985 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
987 HYDROGUI_Shape* aShape = aViewShapes.at( i );
992 myShapesMap.remove( theViewId );
994 /////////////////// END OF OCC SHAPES PROCESSING
996 /////////////////// VTKPrs PROCESSING
997 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
998 const Handle(HYDROData_Entity)& theObject ) const
1000 HYDROGUI_VTKPrs* aResShape = NULL;
1001 if( theObject.IsNull() )
1004 if ( myVTKPrsMap.contains( theViewId ) )
1006 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1007 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1009 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1020 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1021 const Handle(HYDROData_Entity)& theObject,
1022 HYDROGUI_VTKPrs* theShape )
1024 if( theObject.IsNull() )
1027 if( theShape && theShape->needScalarBar() )
1029 // Compute the new global Z range from the added presentation and the old global Z range.
1030 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1031 double* aRange = theShape->getInternalZRange();
1032 bool anIsUpdate = false;
1033 if ( aRange[0] < aGlobalRange[0] )
1035 aGlobalRange[0] = aRange[0];
1038 if ( aRange[1] > aGlobalRange[1] )
1040 aGlobalRange[1] = aRange[1];
1046 updateVTKZRange( theViewId, aGlobalRange );
1050 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1051 aViewShapes.append( theShape );
1054 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1055 const Handle(HYDROData_Entity)& theObject )
1057 if ( !myVTKPrsMap.contains( theViewId ) )
1060 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1061 Handle(HYDROData_Entity) anObject;
1062 for ( int i = 0; i < aViewShapes.length(); )
1064 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1065 anObject = aShape->getObject();
1066 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1069 aViewShapes.removeAt( i );
1076 // Invalidate global Z range
1077 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1078 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1081 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1083 if ( !myVTKPrsMap.contains( theViewId ) )
1086 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1087 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1089 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1094 myVTKPrsMap.remove( theViewId );
1097 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1099 if ( myVTKPrsMap.contains( theViewId ) )
1101 // For the given viewer id update all VTK presentations ...
1102 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1103 HYDROGUI_VTKPrs* aShape;
1104 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1106 aShape = aViewShapes.at( i );
1107 if ( aShape && aShape->needScalarBar() )
1109 aShape->setZRange( theRange );
1113 // ... and update the global color legend scalar bar.
1114 getVTKDisplayer()->SetZRange( theViewId, theRange );
1116 /////////////////// END OF VTKPrs PROCESSING
1118 CAM_DataModel* HYDROGUI_Module::createDataModel()
1120 return new HYDROGUI_DataModel( this );
1123 void HYDROGUI_Module::customEvent( QEvent* e )
1125 int aType = e->type();
1126 if ( aType == NewViewEvent )
1128 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1129 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1131 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1133 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1134 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1136 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1138 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1139 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1141 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1142 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1143 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1145 //ouv: temporarily commented
1146 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1149 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1150 update( UF_Viewer );
1152 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1158 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1160 QEvent::Type aType = theEvent->type();
1161 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1163 if( aType == QEvent::Show )
1165 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1166 e->setData( theObj );
1167 QApplication::postEvent( this, e );
1168 theObj->removeEventFilter( this );
1171 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1173 if( aType == QEvent::Leave )
1175 SUIT_Desktop* aDesktop = getApp()->desktop();
1176 if ( aDesktop && aDesktop->statusBar() ) {
1177 aDesktop->statusBar()->clearMessage();
1181 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1183 if( aType == QEvent::Leave )
1185 SUIT_Desktop* aDesktop = getApp()->desktop();
1186 if ( aDesktop && aDesktop->statusBar() ) {
1187 aDesktop->statusBar()->clearMessage();
1192 return LightApp_Module::eventFilter( theObj, theEvent );
1195 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1197 LightApp_Module::onViewManagerAdded( theViewManager );
1199 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1201 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1202 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1204 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1206 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1207 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1208 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1209 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1211 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1213 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1214 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1215 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1216 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1219 createSelector( theViewManager ); // replace the default selector
1221 ViewManagerInfo anInfo( theViewManager, VMR_General );
1222 myViewManagerMap.insert( ViewManagerId++, anInfo );
1225 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1227 LightApp_Module::onViewManagerRemoved( theViewManager );
1229 createSelector( theViewManager ); // replace the default selector
1231 int anId = getViewManagerId( theViewManager );
1234 OCCViewer_ViewManager* anOCCViewManager =
1235 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1236 if ( anOCCViewManager )
1238 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1240 removeViewShapes( (size_t)anOCCViewer );
1243 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1245 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1248 getVTKDisplayer()->EraseScalarBar( anId, true );
1249 removeViewShapes( (size_t)aVTKViewer );
1253 myViewManagerMap.remove( anId );
1257 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1259 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1261 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1263 aViewFrame->installEventFilter( this );
1265 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1267 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1268 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1271 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1273 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1275 aViewFrame->onTopView();
1277 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1279 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1281 aViewPort->installEventFilter( this );
1285 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1287 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1289 aViewFrame->installEventFilter( this );
1294 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1296 /* ouv: currently unused
1297 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1299 SUIT_ViewManager* aViewManager = 0;
1301 QObject* aParent = aViewPort;
1302 while( aParent = aParent->parent() )
1304 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1306 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1308 aViewManager = aViewer->getViewManager();
1317 double aMouseX = theEvent->scenePos().x();
1318 double aMouseY = theEvent->scenePos().y();
1320 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1321 if( aRole == VMR_General )
1323 int aXDeg = 0, aYDeg = 0;
1324 int aXMin = 0, aYMin = 0;
1325 double aXSec = 0, aYSec = 0;
1326 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1327 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1329 QString aDegSymbol( QChar( 0x00B0 ) );
1330 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1331 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1333 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1335 else if( aRole == VMR_TransformImage )
1336 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1341 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1342 const bool theIsInit,
1343 const bool theIsForced,
1344 const bool theDoFitAll )
1346 QList<int> aViewManagerIdList;
1348 // currently, all views are updated
1349 ViewManagerMapIterator anIter( myViewManagerMap );
1350 while( anIter.hasNext() )
1352 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1354 if ( theDisplayer->IsApplicable( aViewManager ) )
1356 int anId = anIter.key();
1357 aViewManagerIdList.append( anId );
1361 QListIterator<int> anIdIter( aViewManagerIdList );
1362 while( anIdIter.hasNext() )
1364 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1368 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1370 if( !theViewManager )
1373 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1374 if( !aSelectionMgr )
1377 QString aViewType = theViewManager->getType();
1378 if( aViewType != GraphicsView_Viewer::Type() &&
1379 aViewType != OCCViewer_Viewer::Type())
1382 QList<SUIT_Selector*> aSelectorList;
1383 aSelectionMgr->selectors( aViewType, aSelectorList );
1385 // disable all alien selectors
1386 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1387 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1389 SUIT_Selector* aSelector = *anIter;
1390 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1391 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1392 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1393 aSelector->setEnabled( false );
1396 if ( aViewType == GraphicsView_Viewer::Type() )
1398 GraphicsView_ViewManager* aViewManager =
1399 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1401 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1403 else if ( aViewType == OCCViewer_Viewer::Type() )
1405 OCCViewer_ViewManager* aViewManager =
1406 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1408 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1412 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1414 bool aPrevState = myIsUpdateEnabled;
1415 myIsUpdateEnabled = theState;
1419 bool HYDROGUI_Module::isUpdateEnabled() const
1421 return myIsUpdateEnabled;
1424 QStringList HYDROGUI_Module::storeSelection() const
1426 QStringList anEntryList;
1427 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1429 SUIT_DataOwnerPtrList aList( true );
1430 aSelectionMgr->selected( aList );
1432 SUIT_DataOwnerPtrList::iterator anIter;
1433 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1435 const LightApp_DataOwner* anOwner =
1436 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1438 anEntryList.append( anOwner->entry() );
1444 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1446 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1448 SUIT_DataOwnerPtrList aList( true );
1449 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1450 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1451 aSelectionMgr->setSelected( aList );
1455 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1457 OCCViewer_ViewWindow* anOCCViewWindow =
1458 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1459 bool doShow = false;
1461 if ( anOCCViewWindow ) {
1462 // Get the selected point coordinates
1463 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1468 aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1469 aViewPort->getView() );
1474 SVTK_ViewWindow* aViewWindow =
1475 dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
1476 if ( aViewWindow ) {
1477 vtkRenderer* aRen = aViewWindow->getRenderer();
1480 vtkCamera* aCamera = aRen->GetActiveCamera();
1481 double* aNormal = aCamera->GetViewPlaneNormal();
1482 int event_x, event_y;
1483 vtkRenderWindowInteractor* anInteractor = aViewWindow->getInteractor();
1486 anInteractor->GetLastEventPosition(event_x, event_y);
1487 // Use a WorldPicker to get current coords
1488 myPicker->Pick( event_x, event_y, 0, aRen );
1489 double* aCoords = myPicker->GetPickPosition();
1490 /////////////////////// Use the same algorithm as for OCC
1492 double aXp, aYp, aZp;
1500 Standard_Real aPrec = LOCAL_SELECTION_TOLERANCE;
1501 if ( fabs( Vz ) > aPrec ) {
1507 else { // Vz = 0 - the eyed plane is orthogonal to Z plane - XOZ, or YOZ
1508 aXp = aYp = aZp = 0;
1509 if ( fabs( Vy ) < aPrec ) // Vy = 0 - the YOZ plane
1511 else if ( fabs( Vx ) < aPrec ) // Vx = 0 - the XOZ plane
1514 /////////////////////////
1524 // Show the coordinates in the status bar
1525 SUIT_Desktop* aDesktop = getApp()->desktop();
1526 if ( aDesktop && aDesktop->statusBar() ) {
1527 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1528 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1529 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );
1535 * Get the object display order. Needed for Z layers assignment only.
1537 int HYDROGUI_Module::getObjectDisplayOrder(
1538 const int theViewId, const Handle(HYDROData_Entity)& theObject) const
1540 if( theObject.IsNull() )
1543 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1544 QStringList anObjectEntries = myObjectDisplayOrderMap.value( theViewId );
1546 return anObjectEntries.indexOf( anEntry );