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();
659 void HYDROGUI_Module::update( const int flags )
661 if( !isUpdateEnabled() )
664 QApplication::setOverrideCursor( Qt::WaitCursor );
666 // To prevent calling this method recursively
667 // from one of the methods called below
668 setUpdateEnabled( false );
670 // store selected objects
671 QStringList aSelectedEntries = storeSelection();
673 bool aDoFitAll = flags & UF_FitAll;
674 if( ( flags & UF_Viewer ) )
675 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
677 if( ( flags & UF_OCCViewer ) )
678 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
680 if( ( flags & UF_VTKViewer ) )
681 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
683 if( ( flags & UF_Model ) && getDataModel() && getApp() )
685 getDataModel()->update( getStudyId() );
687 // Temporary workaround to prevent breaking
688 // the selection in the object browser.
689 // Note: processEvents() should be called after updateGV(),
690 // otherwise the application crashes from time to time.
691 //RKV: qApp->processEvents();
692 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
693 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
694 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
695 if ( isResizeOnExpandItem && anObjectBrowser ) {
696 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
698 getApp()->updateObjectBrowser( true );
699 if ( isResizeOnExpandItem && anObjectBrowser ) {
700 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
704 // Object browser is currently updated by using UF_Model flag
705 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
706 getApp()->updateObjectBrowser( true );
708 if( ( flags & UF_Controls ) && getApp() )
709 getApp()->updateActions();
711 // restore selected objects
712 restoreSelection( aSelectedEntries );
714 setUpdateEnabled( true );
716 QApplication::restoreOverrideCursor();
719 void HYDROGUI_Module::updateCommandsStatus()
721 LightApp_Module::updateCommandsStatus();
723 updateUndoRedoControls();
725 action( CopyId )->setEnabled( getDataModel()->canCopy() );
726 action( PasteId )->setEnabled( getDataModel()->canPaste() );
729 void HYDROGUI_Module::selectionChanged()
731 LightApp_Module::selectionChanged();
732 updateCommandsStatus();
735 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
737 return (HYDROGUI_DataModel*)dataModel();
740 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
745 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
747 return myOCCDisplayer;
750 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
752 return myVTKDisplayer;
755 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
757 if( myViewManagerMap.contains( theId ) )
759 return myViewManagerMap[ theId ].first;
764 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
766 if( myViewManagerMap.contains( theId ) )
768 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
769 GraphicsView_ViewManager* aViewManager =
770 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
772 return aViewManager->getViewer();
777 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
779 if( myViewManagerMap.contains( theId ) )
781 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
782 OCCViewer_ViewManager* aViewManager =
783 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
785 return aViewManager->getOCCViewer();
790 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
792 if( myViewManagerMap.contains( theId ) )
794 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
795 SVTK_ViewManager* aViewManager =
796 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
798 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
803 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
805 ViewManagerMapIterator anIter( myViewManagerMap );
806 while( anIter.hasNext() )
808 int anId = anIter.next().key();
809 const ViewManagerInfo& anInfo = anIter.value();
810 if( anInfo.first == theViewManager )
816 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
818 int anId = getViewManagerId( theViewManager );
821 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
822 return anInfo.second;
827 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
828 const ViewManagerRole theRole )
830 int anId = getViewManagerId( theViewManager );
833 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
834 anInfo.second = theRole;
838 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
839 const Handle(HYDROData_Entity)& theObject ) const
841 if( theObject.IsNull() )
844 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
845 if( anIter1 != myObjectStateMap.end() )
847 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
848 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
850 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
851 if( anIter2 != aEntry2ObjectStateMap.end() )
853 const ObjectState& anObjectState = anIter2.value();
854 return anObjectState.Visibility;
860 void HYDROGUI_Module::setObjectVisible( const int theViewId,
861 const Handle(HYDROData_Entity)& theObject,
862 const bool theState )
864 if( !theObject.IsNull() )
866 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
867 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
869 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
870 anObjectState.Visibility = theState;
872 // Remember the display order ( needed for Z layers assignment only )
873 QStringList& anObjectEntries = myObjectDisplayOrderMap[ theViewId ];
874 anObjectEntries.removeAll( anEntry );
876 anObjectEntries.append( anEntry );
881 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
882 const bool theState )
884 if( !theObject.IsNull() )
886 // Process OCC shapes
887 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
888 while( aShapesMapIter != myShapesMap.end() )
890 const ListOfShapes& aShapesList = aShapesMapIter.value();
891 foreach ( HYDROGUI_Shape* aShape, aShapesList )
893 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
895 aShape->setIsToUpdate( theState );
900 // Process VTK shapes
901 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
902 while( aVTKPrsMapIter != myVTKPrsMap.end() )
904 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
905 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
907 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
909 aShape->setIsToUpdate( theState );
917 /////////////////// OCC SHAPES PROCESSING
918 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
919 const Handle(HYDROData_Entity)& theObject ) const
921 HYDROGUI_Shape* aResShape = NULL;
922 if( theObject.IsNull() )
925 if ( myShapesMap.contains( theViewId ) )
927 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
928 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
930 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
941 void HYDROGUI_Module::setObjectShape( const int theViewId,
942 const Handle(HYDROData_Entity)& theObject,
943 HYDROGUI_Shape* theShape )
945 if( theObject.IsNull() )
948 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
949 aViewShapes.append( theShape );
952 void HYDROGUI_Module::removeObjectShape( const int theViewId,
953 const Handle(HYDROData_Entity)& theObject )
955 if ( !myShapesMap.contains( theViewId ) )
958 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
959 Handle(HYDROData_Entity) anObject;
960 for ( int i = 0; i < aViewShapes.length(); )
962 HYDROGUI_Shape* aShape = aViewShapes.at( i );
963 anObject = aShape->getObject();
964 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
967 aViewShapes.removeAt( i );
975 void HYDROGUI_Module::removeViewShapes( const int theViewId )
977 if ( !myShapesMap.contains( theViewId ) )
980 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
981 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
983 HYDROGUI_Shape* aShape = aViewShapes.at( i );
988 myShapesMap.remove( theViewId );
990 /////////////////// END OF OCC SHAPES PROCESSING
992 /////////////////// VTKPrs PROCESSING
993 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
994 const Handle(HYDROData_Entity)& theObject ) const
996 HYDROGUI_VTKPrs* aResShape = NULL;
997 if( theObject.IsNull() )
1000 if ( myVTKPrsMap.contains( theViewId ) )
1002 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1003 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1005 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1016 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1017 const Handle(HYDROData_Entity)& theObject,
1018 HYDROGUI_VTKPrs* theShape )
1020 if( theObject.IsNull() )
1023 if( theShape && theShape->needScalarBar() )
1025 // Compute the new global Z range from the added presentation and the old global Z range.
1026 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1027 double* aRange = theShape->getInternalZRange();
1028 bool anIsUpdate = false;
1029 if ( aRange[0] < aGlobalRange[0] )
1031 aGlobalRange[0] = aRange[0];
1034 if ( aRange[1] > aGlobalRange[1] )
1036 aGlobalRange[1] = aRange[1];
1042 updateVTKZRange( theViewId, aGlobalRange );
1046 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1047 aViewShapes.append( theShape );
1050 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1051 const Handle(HYDROData_Entity)& theObject )
1053 if ( !myVTKPrsMap.contains( theViewId ) )
1056 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1057 Handle(HYDROData_Entity) anObject;
1058 for ( int i = 0; i < aViewShapes.length(); )
1060 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1061 anObject = aShape->getObject();
1062 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1065 aViewShapes.removeAt( i );
1072 // Invalidate global Z range
1073 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1074 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1077 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1079 if ( !myVTKPrsMap.contains( theViewId ) )
1082 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1083 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1085 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1090 myVTKPrsMap.remove( theViewId );
1093 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1095 if ( myVTKPrsMap.contains( theViewId ) )
1097 // For the given viewer id update all VTK presentations ...
1098 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1099 HYDROGUI_VTKPrs* aShape;
1100 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1102 aShape = aViewShapes.at( i );
1103 if ( aShape && aShape->needScalarBar() )
1105 aShape->setZRange( theRange );
1109 // ... and update the global color legend scalar bar.
1110 getVTKDisplayer()->SetZRange( theViewId, theRange );
1112 /////////////////// END OF VTKPrs PROCESSING
1114 CAM_DataModel* HYDROGUI_Module::createDataModel()
1116 return new HYDROGUI_DataModel( this );
1119 void HYDROGUI_Module::customEvent( QEvent* e )
1121 int aType = e->type();
1122 if ( aType == NewViewEvent )
1124 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1125 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1127 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1129 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1130 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1132 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1134 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1135 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1137 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1138 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1139 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1141 //ouv: temporarily commented
1142 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1145 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1146 update( UF_Viewer );
1148 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1154 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1156 QEvent::Type aType = theEvent->type();
1157 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1159 if( aType == QEvent::Show )
1161 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1162 e->setData( theObj );
1163 QApplication::postEvent( this, e );
1164 theObj->removeEventFilter( this );
1167 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1169 if( aType == QEvent::Leave )
1171 SUIT_Desktop* aDesktop = getApp()->desktop();
1172 if ( aDesktop && aDesktop->statusBar() ) {
1173 aDesktop->statusBar()->clearMessage();
1177 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1179 if( aType == QEvent::Leave )
1181 SUIT_Desktop* aDesktop = getApp()->desktop();
1182 if ( aDesktop && aDesktop->statusBar() ) {
1183 aDesktop->statusBar()->clearMessage();
1188 return LightApp_Module::eventFilter( theObj, theEvent );
1191 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1193 LightApp_Module::onViewManagerAdded( theViewManager );
1195 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1197 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1198 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1200 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1202 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1203 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1204 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1205 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1207 else if( theViewManager->getType() == SVTK_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* ) ) );
1215 createSelector( theViewManager ); // replace the default selector
1217 ViewManagerInfo anInfo( theViewManager, VMR_General );
1218 myViewManagerMap.insert( ViewManagerId++, anInfo );
1221 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1223 LightApp_Module::onViewManagerRemoved( theViewManager );
1225 createSelector( theViewManager ); // replace the default selector
1227 int anId = getViewManagerId( theViewManager );
1230 OCCViewer_ViewManager* anOCCViewManager =
1231 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1232 if ( anOCCViewManager )
1234 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1236 removeViewShapes( (size_t)anOCCViewer );
1239 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1241 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1244 getVTKDisplayer()->EraseScalarBar( anId, true );
1245 removeViewShapes( (size_t)aVTKViewer );
1249 myViewManagerMap.remove( anId );
1253 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1255 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1257 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1259 aViewFrame->installEventFilter( this );
1261 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1263 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1264 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1267 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1269 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1271 aViewFrame->onTopView();
1273 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1275 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1277 aViewPort->installEventFilter( this );
1281 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1283 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1285 aViewFrame->installEventFilter( this );
1290 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1292 /* ouv: currently unused
1293 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1295 SUIT_ViewManager* aViewManager = 0;
1297 QObject* aParent = aViewPort;
1298 while( aParent = aParent->parent() )
1300 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1302 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1304 aViewManager = aViewer->getViewManager();
1313 double aMouseX = theEvent->scenePos().x();
1314 double aMouseY = theEvent->scenePos().y();
1316 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1317 if( aRole == VMR_General )
1319 int aXDeg = 0, aYDeg = 0;
1320 int aXMin = 0, aYMin = 0;
1321 double aXSec = 0, aYSec = 0;
1322 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1323 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1325 QString aDegSymbol( QChar( 0x00B0 ) );
1326 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1327 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1329 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1331 else if( aRole == VMR_TransformImage )
1332 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1337 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1338 const bool theIsInit,
1339 const bool theIsForced,
1340 const bool theDoFitAll )
1342 QList<int> aViewManagerIdList;
1344 // currently, all views are updated
1345 ViewManagerMapIterator anIter( myViewManagerMap );
1346 while( anIter.hasNext() )
1348 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1350 if ( theDisplayer->IsApplicable( aViewManager ) )
1352 int anId = anIter.key();
1353 aViewManagerIdList.append( anId );
1357 QListIterator<int> anIdIter( aViewManagerIdList );
1358 while( anIdIter.hasNext() )
1360 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1364 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1366 if( !theViewManager )
1369 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1370 if( !aSelectionMgr )
1373 QString aViewType = theViewManager->getType();
1374 if( aViewType != GraphicsView_Viewer::Type() &&
1375 aViewType != OCCViewer_Viewer::Type())
1378 QList<SUIT_Selector*> aSelectorList;
1379 aSelectionMgr->selectors( aViewType, aSelectorList );
1381 // disable all alien selectors
1382 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1383 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1385 SUIT_Selector* aSelector = *anIter;
1386 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1387 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1388 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1389 aSelector->setEnabled( false );
1392 if ( aViewType == GraphicsView_Viewer::Type() )
1394 GraphicsView_ViewManager* aViewManager =
1395 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1397 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1399 else if ( aViewType == OCCViewer_Viewer::Type() )
1401 OCCViewer_ViewManager* aViewManager =
1402 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1404 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1408 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1410 bool aPrevState = myIsUpdateEnabled;
1411 myIsUpdateEnabled = theState;
1415 bool HYDROGUI_Module::isUpdateEnabled() const
1417 return myIsUpdateEnabled;
1420 QStringList HYDROGUI_Module::storeSelection() const
1422 QStringList anEntryList;
1423 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1425 SUIT_DataOwnerPtrList aList( true );
1426 aSelectionMgr->selected( aList );
1428 SUIT_DataOwnerPtrList::iterator anIter;
1429 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1431 const LightApp_DataOwner* anOwner =
1432 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1434 anEntryList.append( anOwner->entry() );
1440 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1442 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1444 SUIT_DataOwnerPtrList aList( true );
1445 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1446 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1447 aSelectionMgr->setSelected( aList );
1451 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1453 OCCViewer_ViewWindow* anOCCViewWindow =
1454 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1455 bool doShow = false;
1457 if ( anOCCViewWindow ) {
1458 // Get the selected point coordinates
1459 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1464 aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1465 aViewPort->getView() );
1470 SVTK_ViewWindow* aViewWindow =
1471 dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
1472 if ( aViewWindow ) {
1473 vtkRenderer* aRen = aViewWindow->getRenderer();
1476 vtkCamera* aCamera = aRen->GetActiveCamera();
1477 double* aNormal = aCamera->GetViewPlaneNormal();
1478 int event_x, event_y;
1479 vtkRenderWindowInteractor* anInteractor = aViewWindow->getInteractor();
1482 anInteractor->GetLastEventPosition(event_x, event_y);
1483 // Use a WorldPicker to get current coords
1484 myPicker->Pick( event_x, event_y, 0, aRen );
1485 double* aCoords = myPicker->GetPickPosition();
1486 /////////////////////// Use the same algorithm as for OCC
1488 double aXp, aYp, aZp;
1496 Standard_Real aPrec = LOCAL_SELECTION_TOLERANCE;
1497 if ( fabs( Vz ) > aPrec ) {
1503 else { // Vz = 0 - the eyed plane is orthogonal to Z plane - XOZ, or YOZ
1504 aXp = aYp = aZp = 0;
1505 if ( fabs( Vy ) < aPrec ) // Vy = 0 - the YOZ plane
1507 else if ( fabs( Vx ) < aPrec ) // Vx = 0 - the XOZ plane
1510 /////////////////////////
1520 // Show the coordinates in the status bar
1521 SUIT_Desktop* aDesktop = getApp()->desktop();
1522 if ( aDesktop && aDesktop->statusBar() ) {
1523 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1524 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1525 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );
1531 * Get the object display order. Needed for Z layers assignment only.
1533 int HYDROGUI_Module::getObjectDisplayOrder(
1534 const int theViewId, const Handle(HYDROData_Entity)& theObject) const
1536 if( theObject.IsNull() )
1539 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1540 QStringList anObjectEntries = myObjectDisplayOrderMap.value( theViewId );
1542 return anObjectEntries.indexOf( anEntry );