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 myShapesMap.remove( anId );
194 myVTKPrsMap.remove( anId );
196 // Replace the default selector for all view managers.
197 // Add view managers created outside of HYDRO module to the map.
198 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
199 createSelector( aViewManager ); // replace the default selector
200 if ( !aHydroViewManagers.contains( aViewManager ) ) {
201 ViewManagerInfo anInfo( aViewManager, VMR_General );
202 myViewManagerMap.insert( ViewManagerId++, anInfo );
208 updateCommandsStatus();
210 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
212 ViewManagerList anOCCViewManagers;
213 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
214 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
215 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
216 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
217 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
218 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
219 if ( aViewFrame && aViewFrame->getViewPort() ) {
220 aViewFrame->getViewPort()->installEventFilter( this );
226 SalomeApp_Study* aStudy =
227 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
229 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
230 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
231 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
232 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
233 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
234 if( !GEOM_var->_is_nil() ) {
235 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
243 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
246 ViewManagerMapIterator anIter( myViewManagerMap );
247 while( anIter.hasNext() )
248 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
249 getApp()->removeViewManager( aViewManager );
250 myViewManagerMap.clear();
253 ViewManagerList anOCCViewManagers;
254 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
255 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
256 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
257 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
261 myObjectStateMap.clear();
266 // clear the data model's list of copying objects
267 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
269 setMenuShown( false );
270 setToolShown( false );
272 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
274 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
276 return LightApp_Module::deactivateModule( theStudy );
279 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
282 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
283 #ifndef DISABLE_PYCONSOLE
284 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
286 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
289 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
291 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
294 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
298 HYDROGUI_DataModel* aModel = getDataModel();
300 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
301 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
302 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
303 bool anIsVTKView = theClient == SVTK_Viewer::Type();
304 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
307 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
309 bool anIsSelectedDataObjects = false;
310 bool anIsVisibleInSelection = false;
311 bool anIsHiddenInSelection = false;
313 bool anIsImage = false;
314 bool anIsImportedImage = false;
315 bool anIsImageHasRefs = false;
316 bool anIsFusedImage = false;
317 bool anIsCutImage = false;
318 bool anIsSplittedImage = false;
319 bool anIsMustObjectBeUpdated = false;
320 bool anIsPolyline = false;
321 bool anIsPolyline3D = false;
322 bool anIsProfile = false;
323 bool anIsValidProfile = false;
324 bool anAllAreProfiles = false;
325 bool anIsBathymetry = false;
326 bool anIsCalculation = false;
327 bool anIsImmersibleZone = false;
328 bool anIsVisualState = false;
329 bool anIsRegion = false;
330 bool anIsZone = false;
331 bool anIsObstacle = false;
332 bool anIsStream = false;
333 bool anIsChannel = false;
334 bool anIsDigue = false;
335 bool anIsDummyObject3D = false;
336 bool anIsGroup = false;
337 bool anIsObjectCanBeColored = false;
339 // Check the selected GEOM objects (take into account the Object Browser only)
340 if ( anIsObjectBrowser ) {
341 QList<GEOM::shape_type> anObstacleTypes =
342 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
343 QList<GEOM::shape_type> aPolylineTypes =
344 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
346 bool isCanBeImportedAsObstacle =
347 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
348 bool isCanBeImportedAsPolyline =
349 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
351 // Add import as obstacle action
352 if ( isCanBeImportedAsObstacle ) {
353 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
355 // Add import as polyline action
356 if ( isCanBeImportedAsPolyline ) {
357 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
360 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
361 theMenu->addSeparator();
365 // check the selected data model objects
366 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
367 int aNbOfSelectedProfiles = 0;
368 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
370 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
371 if( !anObject.IsNull() )
373 anIsSelectedDataObjects = true;
375 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
376 anIsVisibleInSelection |= aVisibility;
377 anIsHiddenInSelection |= !aVisibility;
379 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
381 anIsMustObjectBeUpdated = true;
384 ObjectKind anObjectKind = anObject->GetKind();
385 if( anObjectKind == KIND_IMAGE )
388 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
389 if( !anImage.IsNull() )
391 anIsImportedImage = anImage->HasLocalPoints();
392 anIsImageHasRefs = anImage->HasReferences();
393 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
395 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
397 QString anOperatorName = anOperator->name();
398 if( anOperatorName == ImageComposer_FuseOperator::Type() )
399 anIsFusedImage = true;
400 else if( anOperatorName == ImageComposer_CutOperator::Type() )
402 else if( anOperatorName == ImageComposer_CropOperator::Type() )
403 anIsSplittedImage = true;
408 else if( anObjectKind == KIND_POLYLINEXY )
410 else if( anObjectKind == KIND_POLYLINE )
411 anIsPolyline3D = true;
412 else if( anObjectKind == KIND_PROFILE )
415 aNbOfSelectedProfiles++;
417 Handle(HYDROData_Profile) aProfile =
418 Handle(HYDROData_Profile)::DownCast( anObject );
419 if( !aProfile.IsNull() && aProfile->IsValid() ) {
420 anIsValidProfile = true;
423 else if( anObjectKind == KIND_CALCULATION )
424 anIsCalculation = true;
425 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
426 anIsImmersibleZone = true;
427 else if( anObjectKind == KIND_VISUAL_STATE )
428 anIsVisualState = true;
429 else if( anObjectKind == KIND_REGION )
431 else if( anObjectKind == KIND_ZONE )
433 else if( anObjectKind == KIND_BATHYMETRY )
434 anIsBathymetry = true;
435 else if( anObjectKind == KIND_OBSTACLE )
437 else if( anObjectKind == KIND_STREAM )
439 else if( anObjectKind == KIND_CHANNEL )
441 else if( anObjectKind == KIND_DIGUE )
443 else if( anObjectKind == KIND_DUMMY_3D )
444 anIsDummyObject3D = true;
445 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
449 if ( !anIsObjectCanBeColored )
450 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
453 // Check if all selected objects are profiles
454 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
455 ( aNbOfSelectedProfiles == aSeq.Length() );
457 // check the selected partitions
458 if( !anIsSelectedDataObjects && anIsObjectBrowser )
460 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
461 if( aSelectedPartition != KIND_UNKNOWN )
463 switch( aSelectedPartition )
466 theMenu->addAction( action( ImportImageId ) );
468 case KIND_BATHYMETRY:
469 theMenu->addAction( action( ImportBathymetryId ) );
471 case KIND_ARTIFICIAL_OBJECT:
472 theMenu->addAction( action( CreateChannelId ) );
473 theMenu->addAction( action( CreateDigueId ) );
475 case KIND_NATURAL_OBJECT:
476 theMenu->addAction( action( CreateImmersibleZoneId ) );
477 theMenu->addAction( action( CreateStreamId ) );
480 theMenu->addAction( action( ImportObstacleFromFileId ) );
481 theMenu->addAction( action( CreateBoxId ) );
482 theMenu->addAction( action( CreateCylinderId ) );
484 case KIND_CALCULATION:
485 theMenu->addAction( action( CreateCalculationId ) );
487 case KIND_POLYLINEXY:
488 theMenu->addAction( action( CreatePolylineId ) );
491 theMenu->addAction( action( CreatePolyline3DId ) );
494 theMenu->addAction( action( CreateProfileId ) );
495 theMenu->addAction( action( ImportProfilesId ) );
496 theMenu->addAction( action( AllGeoreferencementId ) );
498 case KIND_VISUAL_STATE:
499 theMenu->addAction( action( SaveVisualStateId ) );
502 theMenu->addSeparator();
506 if( anIsSelectedDataObjects )
508 if ( anIsMustObjectBeUpdated )
510 theMenu->addAction( action( UpdateObjectId ) );
511 theMenu->addSeparator();
515 theMenu->addAction( action( ForcedUpdateObjectId ) );
516 theMenu->addSeparator();
520 if( aSeq.Length() == 1 )
524 if( anIsImportedImage )
525 theMenu->addAction( action( EditImportedImageId ) );
526 else if( anIsImageHasRefs )
529 theMenu->addAction( action( EditFusedImageId ) );
530 else if( anIsCutImage )
531 theMenu->addAction( action( EditCutImageId ) );
532 else if( anIsSplittedImage )
533 theMenu->addAction( action( EditSplittedImageId ) );
536 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
537 theMenu->addAction( action( ExportImageId ) );
538 theMenu->addSeparator();
540 if( anIsImageHasRefs )
542 theMenu->addAction( action( RemoveImageRefsId ) );
543 theMenu->addSeparator();
546 theMenu->addAction( action( FuseImagesId ) );
547 theMenu->addAction( action( CutImagesId ) );
548 theMenu->addAction( action( SplitImageId ) );
549 theMenu->addSeparator();
551 else if( anIsBathymetry )
553 theMenu->addAction( action( EditImportedBathymetryId ) );
554 theMenu->addAction( action( BathymetryBoundsId ) );
555 theMenu->addSeparator();
557 else if( anIsPolyline )
559 theMenu->addAction( action( EditPolylineId ) );
560 theMenu->addSeparator();
562 else if( anIsPolyline3D )
564 theMenu->addAction( action( EditPolyline3DId ) );
565 theMenu->addSeparator();
567 else if( anIsProfile )
569 theMenu->addAction( action( EditProfileId ) );
570 theMenu->addAction( action( SelectedGeoreferencementId ) );
571 theMenu->addSeparator();
573 else if( anIsCalculation )
575 theMenu->addAction( action( EditCalculationId ) );
576 theMenu->addAction( action( ExportCalculationId ) );
577 theMenu->addSeparator();
579 else if( anIsImmersibleZone )
581 theMenu->addAction( action( EditImmersibleZoneId ) );
582 theMenu->addSeparator();
584 else if( anIsStream )
586 theMenu->addAction( action( EditStreamId ) );
587 theMenu->addSeparator();
589 else if( anIsChannel )
591 theMenu->addAction( action( EditChannelId ) );
592 theMenu->addSeparator();
596 theMenu->addAction( action( EditDigueId ) );
597 theMenu->addSeparator();
599 else if( anIsVisualState && anIsObjectBrowser )
601 theMenu->addAction( action( SaveVisualStateId ) );
602 theMenu->addAction( action( LoadVisualStateId ) );
603 theMenu->addSeparator();
606 // Add set color action for geometrical objects
607 if ( anIsObjectCanBeColored )
609 theMenu->addAction( action( SetColorId ) );
610 theMenu->addSeparator();
614 if( aModel->canCopy() ) {
615 theMenu->addAction( action( CopyId ) );
616 theMenu->addSeparator();
618 } else if ( anAllAreProfiles ) {
619 theMenu->addAction( action( SelectedGeoreferencementId ) );
620 theMenu->addSeparator();
623 if( !anIsDummyObject3D )
624 theMenu->addAction( action( DeleteId ) );
625 theMenu->addSeparator();
627 if( anIsImage || anIsPolyline || anIsPolyline3D ||
628 anIsImmersibleZone || anIsZone || anIsRegion ||
629 anIsBathymetry || anIsObstacle || anIsStream ||
630 anIsChannel || anIsDigue || anIsDummyObject3D ||
631 anIsValidProfile || anIsGroup )
633 if( anIsHiddenInSelection )
634 theMenu->addAction( action( ShowId ) );
635 theMenu->addAction( action( ShowOnlyId ) );
636 if( anIsVisibleInSelection )
637 theMenu->addAction( action( HideId ) );
638 theMenu->addSeparator();
644 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
645 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
646 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
647 theMenu->addAction( action( DeleteId ) );
650 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
652 theMenu->addAction( action( ShowAllId ) );
653 theMenu->addAction( action( HideAllId ) );
654 theMenu->addSeparator();
658 void HYDROGUI_Module::update( const int flags )
660 if( !isUpdateEnabled() )
663 QApplication::setOverrideCursor( Qt::WaitCursor );
665 // To prevent calling this method recursively
666 // from one of the methods called below
667 setUpdateEnabled( false );
669 // store selected objects
670 QStringList aSelectedEntries = storeSelection();
672 bool aDoFitAll = flags & UF_FitAll;
673 if( ( flags & UF_Viewer ) )
674 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
676 if( ( flags & UF_OCCViewer ) )
677 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
679 if( ( flags & UF_VTKViewer ) )
680 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
682 if( ( flags & UF_Model ) && getDataModel() && getApp() )
684 getDataModel()->update( getStudyId() );
686 // Temporary workaround to prevent breaking
687 // the selection in the object browser.
688 // Note: processEvents() should be called after updateGV(),
689 // otherwise the application crashes from time to time.
690 //RKV: qApp->processEvents();
691 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
692 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
693 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
694 if ( isResizeOnExpandItem && anObjectBrowser ) {
695 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
697 getApp()->updateObjectBrowser( true );
698 if ( isResizeOnExpandItem && anObjectBrowser ) {
699 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
703 // Object browser is currently updated by using UF_Model flag
704 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
705 getApp()->updateObjectBrowser( true );
707 if( ( flags & UF_Controls ) && getApp() )
708 getApp()->updateActions();
710 // restore selected objects
711 restoreSelection( aSelectedEntries );
713 setUpdateEnabled( true );
715 QApplication::restoreOverrideCursor();
718 void HYDROGUI_Module::updateCommandsStatus()
720 LightApp_Module::updateCommandsStatus();
722 updateUndoRedoControls();
724 action( CopyId )->setEnabled( getDataModel()->canCopy() );
725 action( PasteId )->setEnabled( getDataModel()->canPaste() );
728 void HYDROGUI_Module::selectionChanged()
730 LightApp_Module::selectionChanged();
731 updateCommandsStatus();
734 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
736 return (HYDROGUI_DataModel*)dataModel();
739 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
744 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
746 return myOCCDisplayer;
749 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
751 return myVTKDisplayer;
754 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
756 if( myViewManagerMap.contains( theId ) )
758 return myViewManagerMap[ theId ].first;
763 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
765 if( myViewManagerMap.contains( theId ) )
767 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
768 GraphicsView_ViewManager* aViewManager =
769 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
771 return aViewManager->getViewer();
776 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
778 if( myViewManagerMap.contains( theId ) )
780 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
781 OCCViewer_ViewManager* aViewManager =
782 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
784 return aViewManager->getOCCViewer();
789 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
791 if( myViewManagerMap.contains( theId ) )
793 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
794 SVTK_ViewManager* aViewManager =
795 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
797 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
802 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
804 ViewManagerMapIterator anIter( myViewManagerMap );
805 while( anIter.hasNext() )
807 int anId = anIter.next().key();
808 const ViewManagerInfo& anInfo = anIter.value();
809 if( anInfo.first == theViewManager )
815 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
817 int anId = getViewManagerId( theViewManager );
820 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
821 return anInfo.second;
826 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
827 const ViewManagerRole theRole )
829 int anId = getViewManagerId( theViewManager );
832 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
833 anInfo.second = theRole;
837 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
838 const Handle(HYDROData_Entity)& theObject ) const
840 if( theObject.IsNull() )
843 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
844 if( anIter1 != myObjectStateMap.end() )
846 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
847 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
849 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
850 if( anIter2 != aEntry2ObjectStateMap.end() )
852 const ObjectState& anObjectState = anIter2.value();
853 return anObjectState.Visibility;
859 void HYDROGUI_Module::setObjectVisible( const int theViewId,
860 const Handle(HYDROData_Entity)& theObject,
861 const bool theState )
863 if( !theObject.IsNull() )
865 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
866 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
868 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
869 anObjectState.Visibility = theState;
873 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
874 const bool theState )
876 if( !theObject.IsNull() )
878 // Process OCC shapes
879 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
880 while( aShapesMapIter != myShapesMap.end() )
882 const ListOfShapes& aShapesList = aShapesMapIter.value();
883 foreach ( HYDROGUI_Shape* aShape, aShapesList )
885 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
887 aShape->setIsToUpdate( theState );
892 // Process VTK shapes
893 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
894 while( aVTKPrsMapIter != myVTKPrsMap.end() )
896 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
897 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
899 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
901 aShape->setIsToUpdate( theState );
909 /////////////////// OCC SHAPES PROCESSING
910 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
911 const Handle(HYDROData_Entity)& theObject ) const
913 HYDROGUI_Shape* aResShape = NULL;
914 if( theObject.IsNull() )
917 if ( myShapesMap.contains( theViewId ) )
919 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
920 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
922 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
933 void HYDROGUI_Module::setObjectShape( const int theViewId,
934 const Handle(HYDROData_Entity)& theObject,
935 HYDROGUI_Shape* theShape )
937 if( theObject.IsNull() )
940 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
941 aViewShapes.append( theShape );
944 void HYDROGUI_Module::removeObjectShape( const int theViewId,
945 const Handle(HYDROData_Entity)& theObject )
947 if ( !myShapesMap.contains( theViewId ) )
950 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
951 Handle(HYDROData_Entity) anObject;
952 for ( int i = 0; i < aViewShapes.length(); )
954 HYDROGUI_Shape* aShape = aViewShapes.at( i );
955 anObject = aShape->getObject();
956 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
959 aViewShapes.removeAt( i );
967 void HYDROGUI_Module::removeViewShapes( const int theViewId )
969 if ( !myShapesMap.contains( theViewId ) )
972 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
973 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
975 HYDROGUI_Shape* aShape = aViewShapes.at( i );
980 myShapesMap.remove( theViewId );
982 /////////////////// END OF OCC SHAPES PROCESSING
984 /////////////////// VTKPrs PROCESSING
985 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
986 const Handle(HYDROData_Entity)& theObject ) const
988 HYDROGUI_VTKPrs* aResShape = NULL;
989 if( theObject.IsNull() )
992 if ( myVTKPrsMap.contains( theViewId ) )
994 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
995 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
997 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1008 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1009 const Handle(HYDROData_Entity)& theObject,
1010 HYDROGUI_VTKPrs* theShape )
1012 if( theObject.IsNull() )
1015 if( theShape && theShape->needScalarBar() )
1017 // Compute the new global Z range from the added presentation and the old global Z range.
1018 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1019 double* aRange = theShape->getInternalZRange();
1020 bool anIsUpdate = false;
1021 if ( aRange[0] < aGlobalRange[0] )
1023 aGlobalRange[0] = aRange[0];
1026 if ( aRange[1] > aGlobalRange[1] )
1028 aGlobalRange[1] = aRange[1];
1034 updateVTKZRange( theViewId, aGlobalRange );
1038 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1039 aViewShapes.append( theShape );
1042 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1043 const Handle(HYDROData_Entity)& theObject )
1045 if ( !myVTKPrsMap.contains( theViewId ) )
1048 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1049 Handle(HYDROData_Entity) anObject;
1050 for ( int i = 0; i < aViewShapes.length(); )
1052 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1053 anObject = aShape->getObject();
1054 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1057 aViewShapes.removeAt( i );
1064 // Invalidate global Z range
1065 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1066 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1069 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1071 if ( !myVTKPrsMap.contains( theViewId ) )
1074 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1075 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1077 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1082 myVTKPrsMap.remove( theViewId );
1085 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1087 if ( myVTKPrsMap.contains( theViewId ) )
1089 // For the given viewer id update all VTK presentations ...
1090 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1091 HYDROGUI_VTKPrs* aShape;
1092 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1094 aShape = aViewShapes.at( i );
1095 if ( aShape && aShape->needScalarBar() )
1097 aShape->setZRange( theRange );
1101 // ... and update the global color legend scalar bar.
1102 getVTKDisplayer()->SetZRange( theViewId, theRange );
1104 /////////////////// END OF VTKPrs PROCESSING
1106 CAM_DataModel* HYDROGUI_Module::createDataModel()
1108 return new HYDROGUI_DataModel( this );
1111 void HYDROGUI_Module::customEvent( QEvent* e )
1113 int aType = e->type();
1114 if ( aType == NewViewEvent )
1116 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1117 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1119 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1121 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1122 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1124 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1126 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1127 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1129 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1130 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1131 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1133 //ouv: temporarily commented
1134 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1137 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1138 update( UF_Viewer );
1140 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1146 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1148 QEvent::Type aType = theEvent->type();
1149 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1151 if( aType == QEvent::Show )
1153 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1154 e->setData( theObj );
1155 QApplication::postEvent( this, e );
1156 theObj->removeEventFilter( this );
1159 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1161 if( aType == QEvent::Leave )
1163 SUIT_Desktop* aDesktop = getApp()->desktop();
1164 if ( aDesktop && aDesktop->statusBar() ) {
1165 aDesktop->statusBar()->clearMessage();
1169 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1171 if( aType == QEvent::Leave )
1173 SUIT_Desktop* aDesktop = getApp()->desktop();
1174 if ( aDesktop && aDesktop->statusBar() ) {
1175 aDesktop->statusBar()->clearMessage();
1180 return LightApp_Module::eventFilter( theObj, theEvent );
1183 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1185 LightApp_Module::onViewManagerAdded( theViewManager );
1187 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1189 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1190 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1192 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1194 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1195 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1196 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1197 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1199 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1201 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1202 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1203 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1204 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1207 createSelector( theViewManager ); // replace the default selector
1209 ViewManagerInfo anInfo( theViewManager, VMR_General );
1210 myViewManagerMap.insert( ViewManagerId++, anInfo );
1213 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1215 LightApp_Module::onViewManagerRemoved( theViewManager );
1217 createSelector( theViewManager ); // replace the default selector
1219 int anId = getViewManagerId( theViewManager );
1222 OCCViewer_ViewManager* anOCCViewManager =
1223 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1224 if ( anOCCViewManager )
1226 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1228 removeViewShapes( (size_t)anOCCViewer );
1231 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1233 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1236 getVTKDisplayer()->EraseScalarBar( anId, true );
1237 removeViewShapes( (size_t)aVTKViewer );
1241 myViewManagerMap.remove( anId );
1245 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1247 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1249 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1251 aViewFrame->installEventFilter( this );
1253 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1255 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1256 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1259 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1261 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1263 aViewFrame->onTopView();
1265 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1267 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1269 aViewPort->installEventFilter( this );
1273 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1275 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1277 aViewFrame->installEventFilter( this );
1282 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1284 /* ouv: currently unused
1285 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1287 SUIT_ViewManager* aViewManager = 0;
1289 QObject* aParent = aViewPort;
1290 while( aParent = aParent->parent() )
1292 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1294 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1296 aViewManager = aViewer->getViewManager();
1305 double aMouseX = theEvent->scenePos().x();
1306 double aMouseY = theEvent->scenePos().y();
1308 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1309 if( aRole == VMR_General )
1311 int aXDeg = 0, aYDeg = 0;
1312 int aXMin = 0, aYMin = 0;
1313 double aXSec = 0, aYSec = 0;
1314 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1315 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1317 QString aDegSymbol( QChar( 0x00B0 ) );
1318 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1319 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1321 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1323 else if( aRole == VMR_TransformImage )
1324 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1329 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1330 const bool theIsInit,
1331 const bool theIsForced,
1332 const bool theDoFitAll )
1334 QList<int> aViewManagerIdList;
1336 // currently, all views are updated
1337 ViewManagerMapIterator anIter( myViewManagerMap );
1338 while( anIter.hasNext() )
1340 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1342 if ( theDisplayer->IsApplicable( aViewManager ) )
1344 int anId = anIter.key();
1345 aViewManagerIdList.append( anId );
1349 QListIterator<int> anIdIter( aViewManagerIdList );
1350 while( anIdIter.hasNext() )
1352 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1356 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1358 if( !theViewManager )
1361 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1362 if( !aSelectionMgr )
1365 QString aViewType = theViewManager->getType();
1366 if( aViewType != GraphicsView_Viewer::Type() &&
1367 aViewType != OCCViewer_Viewer::Type())
1370 QList<SUIT_Selector*> aSelectorList;
1371 aSelectionMgr->selectors( aViewType, aSelectorList );
1373 // disable all alien selectors
1374 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1375 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1377 SUIT_Selector* aSelector = *anIter;
1378 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1379 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1380 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1381 aSelector->setEnabled( false );
1384 if ( aViewType == GraphicsView_Viewer::Type() )
1386 GraphicsView_ViewManager* aViewManager =
1387 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1389 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1391 else if ( aViewType == OCCViewer_Viewer::Type() )
1393 OCCViewer_ViewManager* aViewManager =
1394 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1396 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1400 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1402 bool aPrevState = myIsUpdateEnabled;
1403 myIsUpdateEnabled = theState;
1407 bool HYDROGUI_Module::isUpdateEnabled() const
1409 return myIsUpdateEnabled;
1412 QStringList HYDROGUI_Module::storeSelection() const
1414 QStringList anEntryList;
1415 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1417 SUIT_DataOwnerPtrList aList( true );
1418 aSelectionMgr->selected( aList );
1420 SUIT_DataOwnerPtrList::iterator anIter;
1421 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1423 const LightApp_DataOwner* anOwner =
1424 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1426 anEntryList.append( anOwner->entry() );
1432 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1434 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1436 SUIT_DataOwnerPtrList aList( true );
1437 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1438 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1439 aSelectionMgr->setSelected( aList );
1443 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1445 OCCViewer_ViewWindow* anOCCViewWindow =
1446 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1447 bool doShow = false;
1449 if ( anOCCViewWindow ) {
1450 // Get the selected point coordinates
1451 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1456 aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1457 aViewPort->getView() );
1462 SVTK_ViewWindow* aViewWindow =
1463 dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
1464 if ( aViewWindow ) {
1465 vtkRenderer* aRen = aViewWindow->getRenderer();
1468 vtkCamera* aCamera = aRen->GetActiveCamera();
1469 double* aNormal = aCamera->GetViewPlaneNormal();
1470 int event_x, event_y;
1471 vtkRenderWindowInteractor* anInteractor = aViewWindow->getInteractor();
1474 anInteractor->GetLastEventPosition(event_x, event_y);
1475 // Use a WorldPicker to get current coords
1476 myPicker->Pick( event_x, event_y, 0, aRen );
1477 double* aCoords = myPicker->GetPickPosition();
1478 /////////////////////// Use the same algorithm as for OCC
1480 double aXp, aYp, aZp;
1488 Standard_Real aPrec = LOCAL_SELECTION_TOLERANCE;
1489 if ( fabs( Vz ) > aPrec ) {
1495 else { // Vz = 0 - the eyed plane is orthogonal to Z plane - XOZ, or YOZ
1496 aXp = aYp = aZp = 0;
1497 if ( fabs( Vy ) < aPrec ) // Vy = 0 - the YOZ plane
1499 else if ( fabs( Vx ) < aPrec ) // Vx = 0 - the XOZ plane
1502 /////////////////////////
1512 // Show the coordinates in the status bar
1513 SUIT_Desktop* aDesktop = getApp()->desktop();
1514 if ( aDesktop && aDesktop->statusBar() ) {
1515 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1516 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1517 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );