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();
613 } else if ( anAllAreProfiles ) {
614 theMenu->addAction( action( SelectedGeoreferencementId ) );
615 theMenu->addSeparator();
619 QAction* aCopyAction = action( CopyId );
620 if( aCopyAction && aCopyAction->isEnabled() ) {
621 theMenu->addAction( action( CopyId ) );
622 theMenu->addSeparator();
626 if( !anIsDummyObject3D )
627 theMenu->addAction( action( DeleteId ) );
629 theMenu->addSeparator();
631 if( anIsImage || anIsPolyline || anIsPolyline3D ||
632 anIsImmersibleZone || anIsZone || anIsRegion ||
633 anIsBathymetry || anIsObstacle || anIsStream ||
634 anIsChannel || anIsDigue || anIsDummyObject3D ||
635 anIsValidProfile || anIsGroup )
637 if( anIsHiddenInSelection )
638 theMenu->addAction( action( ShowId ) );
639 theMenu->addAction( action( ShowOnlyId ) );
640 if( anIsVisibleInSelection )
641 theMenu->addAction( action( HideId ) );
642 theMenu->addSeparator();
648 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
649 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
650 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
651 theMenu->addAction( action( DeleteId ) );
654 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
656 theMenu->addAction( action( ShowAllId ) );
657 theMenu->addAction( action( HideAllId ) );
658 theMenu->addSeparator();
661 theMenu->addSeparator();
662 theMenu->addAction( action( CopyViewerPositionId ) );
666 void HYDROGUI_Module::update( const int flags )
668 if( !isUpdateEnabled() )
671 QApplication::setOverrideCursor( Qt::WaitCursor );
673 // To prevent calling this method recursively
674 // from one of the methods called below
675 setUpdateEnabled( false );
677 // store selected objects
678 QStringList aSelectedEntries = storeSelection();
680 bool aDoFitAll = flags & UF_FitAll;
681 if( ( flags & UF_Viewer ) )
682 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
684 if( ( flags & UF_OCCViewer ) )
685 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
687 if( ( flags & UF_VTKViewer ) )
688 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
690 if( ( flags & UF_Model ) && getDataModel() && getApp() )
692 getDataModel()->update( getStudyId() );
694 // Temporary workaround to prevent breaking
695 // the selection in the object browser.
696 // Note: processEvents() should be called after updateGV(),
697 // otherwise the application crashes from time to time.
698 //RKV: qApp->processEvents();
699 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
700 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
701 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
702 if ( isResizeOnExpandItem && anObjectBrowser ) {
703 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
705 getApp()->updateObjectBrowser( true );
706 if ( isResizeOnExpandItem && anObjectBrowser ) {
707 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
711 // Object browser is currently updated by using UF_Model flag
712 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
713 getApp()->updateObjectBrowser( true );
715 if( ( flags & UF_Controls ) && getApp() )
716 getApp()->updateActions();
718 // restore selected objects
719 restoreSelection( aSelectedEntries );
721 setUpdateEnabled( true );
723 QApplication::restoreOverrideCursor();
726 void HYDROGUI_Module::updateCommandsStatus()
728 LightApp_Module::updateCommandsStatus();
730 updateUndoRedoControls();
732 action( CopyId )->setEnabled( getDataModel()->canCopy() );
733 action( PasteId )->setEnabled( getDataModel()->canPaste() );
736 void HYDROGUI_Module::selectionChanged()
738 LightApp_Module::selectionChanged();
739 updateCommandsStatus();
742 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
744 return (HYDROGUI_DataModel*)dataModel();
747 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
752 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
754 return myOCCDisplayer;
757 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
759 return myVTKDisplayer;
762 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
764 if( myViewManagerMap.contains( theId ) )
766 return myViewManagerMap[ theId ].first;
771 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
773 if( myViewManagerMap.contains( theId ) )
775 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
776 GraphicsView_ViewManager* aViewManager =
777 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
779 return aViewManager->getViewer();
784 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
786 if( myViewManagerMap.contains( theId ) )
788 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
789 OCCViewer_ViewManager* aViewManager =
790 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
792 return aViewManager->getOCCViewer();
797 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
799 if( myViewManagerMap.contains( theId ) )
801 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
802 SVTK_ViewManager* aViewManager =
803 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
805 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
810 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
812 ViewManagerMapIterator anIter( myViewManagerMap );
813 while( anIter.hasNext() )
815 int anId = anIter.next().key();
816 const ViewManagerInfo& anInfo = anIter.value();
817 if( anInfo.first == theViewManager )
823 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
825 int anId = getViewManagerId( theViewManager );
828 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
829 return anInfo.second;
834 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
835 const ViewManagerRole theRole )
837 int anId = getViewManagerId( theViewManager );
840 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
841 anInfo.second = theRole;
845 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
846 const Handle(HYDROData_Entity)& theObject ) const
848 if( theObject.IsNull() )
851 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
852 if( anIter1 != myObjectStateMap.end() )
854 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
855 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
857 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
858 if( anIter2 != aEntry2ObjectStateMap.end() )
860 const ObjectState& anObjectState = anIter2.value();
861 return anObjectState.Visibility;
867 void HYDROGUI_Module::setObjectVisible( const int theViewId,
868 const Handle(HYDROData_Entity)& theObject,
869 const bool theState )
871 if( !theObject.IsNull() )
873 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
874 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
876 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
877 anObjectState.Visibility = theState;
879 // Remember the display order ( needed for Z layers assignment only )
880 QStringList& anObjectEntries = myObjectDisplayOrderMap[ theViewId ];
881 anObjectEntries.removeAll( anEntry );
883 anObjectEntries.append( anEntry );
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 Handle(HYDROData_Entity)& theObject )
1060 if ( !myVTKPrsMap.contains( theViewId ) )
1063 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1064 Handle(HYDROData_Entity) anObject;
1065 for ( int i = 0; i < aViewShapes.length(); )
1067 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1068 anObject = aShape->getObject();
1069 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1072 aViewShapes.removeAt( i );
1079 // Invalidate global Z range
1080 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1081 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1084 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1086 if ( !myVTKPrsMap.contains( theViewId ) )
1089 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1090 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1092 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1097 myVTKPrsMap.remove( theViewId );
1100 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1102 if ( myVTKPrsMap.contains( theViewId ) )
1104 // For the given viewer id update all VTK presentations ...
1105 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1106 HYDROGUI_VTKPrs* aShape;
1107 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1109 aShape = aViewShapes.at( i );
1110 if ( aShape && aShape->needScalarBar() )
1112 aShape->setZRange( theRange );
1116 // ... and update the global color legend scalar bar.
1117 getVTKDisplayer()->SetZRange( theViewId, theRange );
1119 /////////////////// END OF VTKPrs PROCESSING
1121 CAM_DataModel* HYDROGUI_Module::createDataModel()
1123 return new HYDROGUI_DataModel( this );
1126 void HYDROGUI_Module::customEvent( QEvent* e )
1128 int aType = e->type();
1129 if ( aType == NewViewEvent )
1131 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1132 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1134 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1136 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1137 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1139 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1141 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1142 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1144 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1145 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1146 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1148 //ouv: temporarily commented
1149 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1152 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1153 update( UF_Viewer );
1155 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1161 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1163 QEvent::Type aType = theEvent->type();
1164 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1166 if( aType == QEvent::Show )
1168 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1169 e->setData( theObj );
1170 QApplication::postEvent( this, e );
1171 theObj->removeEventFilter( this );
1174 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1176 if( aType == QEvent::Leave )
1178 SUIT_Desktop* aDesktop = getApp()->desktop();
1179 if ( aDesktop && aDesktop->statusBar() ) {
1180 aDesktop->statusBar()->clearMessage();
1184 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1186 if( aType == QEvent::Leave )
1188 SUIT_Desktop* aDesktop = getApp()->desktop();
1189 if ( aDesktop && aDesktop->statusBar() ) {
1190 aDesktop->statusBar()->clearMessage();
1195 return LightApp_Module::eventFilter( theObj, theEvent );
1198 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1200 LightApp_Module::onViewManagerAdded( theViewManager );
1202 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1204 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1205 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1207 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1209 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1210 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1211 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1212 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1214 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1216 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1217 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1218 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1219 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1222 createSelector( theViewManager ); // replace the default selector
1224 ViewManagerInfo anInfo( theViewManager, VMR_General );
1225 myViewManagerMap.insert( ViewManagerId++, anInfo );
1228 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1230 LightApp_Module::onViewManagerRemoved( theViewManager );
1232 createSelector( theViewManager ); // replace the default selector
1234 int anId = getViewManagerId( theViewManager );
1237 OCCViewer_ViewManager* anOCCViewManager =
1238 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1239 if ( anOCCViewManager )
1241 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1243 removeViewShapes( (size_t)anOCCViewer );
1246 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1248 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1251 getVTKDisplayer()->EraseScalarBar( anId, true );
1252 removeViewShapes( (size_t)aVTKViewer );
1256 myViewManagerMap.remove( anId );
1260 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1262 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1264 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1266 aViewFrame->installEventFilter( this );
1268 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1270 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1271 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1274 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1276 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1278 aViewFrame->onTopView();
1280 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1282 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1284 aViewPort->installEventFilter( this );
1288 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1290 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1292 aViewFrame->installEventFilter( this );
1297 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1299 /* ouv: currently unused
1300 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1302 SUIT_ViewManager* aViewManager = 0;
1304 QObject* aParent = aViewPort;
1305 while( aParent = aParent->parent() )
1307 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1309 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1311 aViewManager = aViewer->getViewManager();
1320 double aMouseX = theEvent->scenePos().x();
1321 double aMouseY = theEvent->scenePos().y();
1323 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1324 if( aRole == VMR_General )
1326 int aXDeg = 0, aYDeg = 0;
1327 int aXMin = 0, aYMin = 0;
1328 double aXSec = 0, aYSec = 0;
1329 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1330 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1332 QString aDegSymbol( QChar( 0x00B0 ) );
1333 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1334 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1336 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1338 else if( aRole == VMR_TransformImage )
1339 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1344 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1345 const bool theIsInit,
1346 const bool theIsForced,
1347 const bool theDoFitAll )
1349 QList<int> aViewManagerIdList;
1351 // currently, all views are updated
1352 ViewManagerMapIterator anIter( myViewManagerMap );
1353 while( anIter.hasNext() )
1355 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1357 if ( theDisplayer->IsApplicable( aViewManager ) )
1359 int anId = anIter.key();
1360 aViewManagerIdList.append( anId );
1364 QListIterator<int> anIdIter( aViewManagerIdList );
1365 while( anIdIter.hasNext() )
1367 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1371 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1373 if( !theViewManager )
1376 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1377 if( !aSelectionMgr )
1380 QString aViewType = theViewManager->getType();
1381 if( aViewType != GraphicsView_Viewer::Type() &&
1382 aViewType != OCCViewer_Viewer::Type())
1385 QList<SUIT_Selector*> aSelectorList;
1386 aSelectionMgr->selectors( aViewType, aSelectorList );
1388 // disable all alien selectors
1389 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1390 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1392 SUIT_Selector* aSelector = *anIter;
1393 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1394 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1395 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1396 aSelector->setEnabled( false );
1399 if ( aViewType == GraphicsView_Viewer::Type() )
1401 GraphicsView_ViewManager* aViewManager =
1402 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1404 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1406 else if ( aViewType == OCCViewer_Viewer::Type() )
1408 OCCViewer_ViewManager* aViewManager =
1409 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1411 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1415 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1417 bool aPrevState = myIsUpdateEnabled;
1418 myIsUpdateEnabled = theState;
1422 bool HYDROGUI_Module::isUpdateEnabled() const
1424 return myIsUpdateEnabled;
1427 QStringList HYDROGUI_Module::storeSelection() const
1429 QStringList anEntryList;
1430 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1432 SUIT_DataOwnerPtrList aList( true );
1433 aSelectionMgr->selected( aList );
1435 SUIT_DataOwnerPtrList::iterator anIter;
1436 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1438 const LightApp_DataOwner* anOwner =
1439 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1441 anEntryList.append( anOwner->entry() );
1447 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1449 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1451 SUIT_DataOwnerPtrList aList( true );
1452 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1453 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1454 aSelectionMgr->setSelected( aList );
1458 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1460 OCCViewer_ViewWindow* anOCCViewWindow =
1461 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1462 bool doShow = false;
1464 if ( anOCCViewWindow ) {
1465 // Get the selected point coordinates
1466 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1471 aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1472 aViewPort->getView() );
1477 SVTK_ViewWindow* aViewWindow =
1478 dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
1479 if ( aViewWindow ) {
1480 vtkRenderer* aRen = aViewWindow->getRenderer();
1483 vtkCamera* aCamera = aRen->GetActiveCamera();
1484 double* aNormal = aCamera->GetViewPlaneNormal();
1485 int event_x, event_y;
1486 vtkRenderWindowInteractor* anInteractor = aViewWindow->getInteractor();
1489 anInteractor->GetLastEventPosition(event_x, event_y);
1490 // Use a WorldPicker to get current coords
1491 myPicker->Pick( event_x, event_y, 0, aRen );
1492 double* aCoords = myPicker->GetPickPosition();
1493 /////////////////////// Use the same algorithm as for OCC
1495 double aXp, aYp, aZp;
1503 Standard_Real aPrec = LOCAL_SELECTION_TOLERANCE;
1504 if ( fabs( Vz ) > aPrec ) {
1510 else { // Vz = 0 - the eyed plane is orthogonal to Z plane - XOZ, or YOZ
1511 aXp = aYp = aZp = 0;
1512 if ( fabs( Vy ) < aPrec ) // Vy = 0 - the YOZ plane
1514 else if ( fabs( Vx ) < aPrec ) // Vx = 0 - the XOZ plane
1517 /////////////////////////
1527 // Show the coordinates in the status bar
1528 SUIT_Desktop* aDesktop = getApp()->desktop();
1529 if ( aDesktop && aDesktop->statusBar() ) {
1530 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1531 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1532 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );
1538 * Get the object display order. Needed for Z layers assignment only.
1540 int HYDROGUI_Module::getObjectDisplayOrder(
1541 const int theViewId, const Handle(HYDROData_Entity)& theObject) const
1543 if( theObject.IsNull() )
1546 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1547 QStringList anObjectEntries = myObjectDisplayOrderMap.value( theViewId );
1549 return anObjectEntries.indexOf( anEntry );