1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_DataModel.h"
23 #include "HYDROGUI_DataObject.h"
24 #include "HYDROGUI_Displayer.h"
25 #include "HYDROGUI_GVSelector.h"
26 #include "HYDROGUI_InputPanel.h"
27 #include "HYDROGUI_ObjSelector.h"
28 #include "HYDROGUI_OCCDisplayer.h"
29 #include "HYDROGUI_OCCSelector.h"
30 #include "HYDROGUI_Operations.h"
31 #include "HYDROGUI_PrsImage.h"
32 #include "HYDROGUI_Tool.h"
33 #include "HYDROGUI_UpdateFlags.h"
34 #include "HYDROGUI_Shape.h"
35 #include "HYDROGUI_VTKPrs.h"
36 #include "HYDROGUI_VTKPrsDisplayer.h"
37 #include "HYDROGUI_AbstractDisplayer.h"
38 #include "HYDROGUI_PolylineOp.h"
39 #include "HYDROGUI_SetColorOp.h"
40 #include "HYDROGUI_ImportGeomObjectOp.h"
41 #include "HYDROGUI_ShowHideOp.h"
43 #include <HYDROData_Tool.h>
44 #include <HYDROData_Image.h>
45 #include <HYDROData_Stream.h>
46 #include <HYDROData_Profile.h>
47 #include <HYDROData_Lambert93.h>
48 #include <HYDROData_Polyline3D.h>
50 #include <HYDROData_OperationsFactory.h>
52 #include <CurveCreator_Utils.hxx>
54 #include <GraphicsView_ViewFrame.h>
55 #include <GraphicsView_ViewManager.h>
56 #include <GraphicsView_ViewPort.h>
57 #include <GraphicsView_Viewer.h>
59 #include <ImageComposer_CutOperator.h>
60 #include <ImageComposer_CropOperator.h>
61 #include <ImageComposer_FuseOperator.h>
63 #include <LightApp_Application.h>
64 #include <LightApp_DataOwner.h>
65 #include <LightApp_GVSelector.h>
66 #include <LightApp_SelectionMgr.h>
67 #include <LightApp_UpdateFlags.h>
69 #include <SalomeApp_Study.h>
71 #include <OCCViewer_ViewFrame.h>
72 #include <OCCViewer_ViewManager.h>
73 #include <OCCViewer_ViewModel.h>
75 #include <SALOME_Event.h>
77 #include <SUIT_DataBrowser.h>
78 #include <SUIT_Desktop.h>
79 #include <SUIT_Study.h>
80 #include <SUIT_ViewManager.h>
81 #include <SUIT_ResourceMgr.h>
83 #include <SVTK_ViewManager.h>
84 #include <SVTK_ViewModel.h>
85 #include <SVTK_ViewWindow.h>
86 #include <SVTK_Selector.h>
88 #include <OCCViewer_ViewPort3d.h>
90 #include <GEOMUtils.hxx>
91 #include <GeometryGUI.h>
93 #include <SALOMEDS_wrap.hxx>
96 #include <QApplication>
97 #include <QGraphicsSceneMouseEvent>
99 #include <QMouseEvent>
100 #include <QStatusBar>
103 static int ViewManagerId = 0;
105 extern "C" HYDRO_EXPORT CAM_Module* createModule()
107 return new HYDROGUI_Module();
110 extern "C" HYDRO_EXPORT char* getModuleVersion()
112 return (char*)HYDRO_VERSION;
115 HYDROGUI_Module::HYDROGUI_Module()
116 : LightApp_Module( "HYDRO" ),
119 myIsUpdateEnabled( true )
123 HYDROGUI_Module::~HYDROGUI_Module()
127 int HYDROGUI_Module::getStudyId() const
129 LightApp_Application* anApp = getApp();
130 return anApp ? anApp->activeStudy()->id() : 0;
133 void HYDROGUI_Module::initialize( CAM_Application* theApp )
135 LightApp_Module::initialize( theApp );
138 createUndoRedoActions();
143 setMenuShown( false );
144 setToolShown( false );
146 myDisplayer = new HYDROGUI_Displayer( this );
147 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
148 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
151 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
153 bool aRes = LightApp_Module::activateModule( theStudy );
155 LightApp_Application* anApp = getApp();
156 SUIT_Desktop* aDesktop = anApp->desktop();
158 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
160 setMenuShown( true );
161 setToolShown( true );
163 #ifndef DISABLE_PYCONSOLE
164 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
165 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
168 // Remove defunct view managers from the map.
169 // It's essential to do this before "update( UF_All )" call!
170 QList<int> anObsoleteIds;
171 ViewManagerList anAllViewManagers = anApp->viewManagers();
172 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
173 ViewManagerMapIterator anIter( myViewManagerMap );
174 while( anIter.hasNext() ) {
175 int anId = anIter.next().key();
176 const ViewManagerInfo& anInfo = anIter.value();
178 aHydroViewManagers << anInfo.first;
180 if ( !anAllViewManagers.contains( anInfo.first ) ) {
181 anObsoleteIds << anId;
184 foreach ( const int anId, anObsoleteIds ) {
185 myViewManagerMap.remove( anId );
186 myObjectStateMap.remove( anId );
187 myShapesMap.remove( anId );
188 myVTKPrsMap.remove( anId );
190 // Replace the default selector for all view managers.
191 // Add view managers created outside of HYDRO module to the map.
192 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
193 createSelector( aViewManager ); // replace the default selector
194 if ( !aHydroViewManagers.contains( aViewManager ) ) {
195 ViewManagerInfo anInfo( aViewManager, VMR_General );
196 myViewManagerMap.insert( ViewManagerId++, anInfo );
202 updateCommandsStatus();
204 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
206 ViewManagerList anOCCViewManagers;
207 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
208 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
209 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
210 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
211 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
212 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
213 if ( aViewFrame && aViewFrame->getViewPort() ) {
214 aViewFrame->getViewPort()->installEventFilter( this );
220 SalomeApp_Study* aStudy =
221 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
223 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
224 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
225 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
226 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
227 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
228 if( !GEOM_var->_is_nil() ) {
229 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
237 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
240 ViewManagerMapIterator anIter( myViewManagerMap );
241 while( anIter.hasNext() )
242 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
243 getApp()->removeViewManager( aViewManager );
244 myViewManagerMap.clear();
247 ViewManagerList anOCCViewManagers;
248 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
249 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
250 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
251 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
255 myObjectStateMap.clear();
260 // clear the status bar
261 SUIT_Desktop* aDesktop = getApp()->desktop();
262 if ( aDesktop && aDesktop->statusBar() ) {
263 aDesktop->statusBar()->clearMessage();
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 myActiveOperationMap.clear();
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 bool isStreamHasBottom = false;
342 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
343 SUIT_DataOwnerPtrList anOwners;
344 aSelectionMgr->selected( anOwners );
345 if( anIsObjectBrowser && anOwners.size()==1 )
347 QString anEntry = anOwners[0]->keyString();
348 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
350 isRoot = aStudy->isComponent( anEntry );
353 // Check the selected GEOM objects (take into account the Object Browser only)
354 if ( anIsObjectBrowser ) {
355 QList<GEOM::shape_type> anObstacleTypes =
356 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
357 QList<GEOM::shape_type> aPolylineTypes =
358 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
360 bool isCanBeImportedAsObstacle =
361 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
362 bool isCanBeImportedAsPolyline =
363 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
365 // Add import as obstacle action
366 if ( isCanBeImportedAsObstacle ) {
367 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
369 // Add import as polyline action
370 if ( isCanBeImportedAsPolyline ) {
371 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
374 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
375 theMenu->addSeparator();
379 // check the selected data model objects
380 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
381 int aNbOfSelectedProfiles = 0;
382 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
384 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
385 if( !anObject.IsNull() )
387 anIsSelectedDataObjects = true;
389 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
390 anIsVisibleInSelection |= aVisibility;
391 anIsHiddenInSelection |= !aVisibility;
393 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
395 anIsMustObjectBeUpdated = true;
398 ObjectKind anObjectKind = anObject->GetKind();
399 if( anObjectKind == KIND_IMAGE )
402 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
403 if( !anImage.IsNull() )
405 anIsImportedImage = anImage->HasLocalPoints();
406 anIsImageHasRefs = anImage->HasReferences();
407 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
409 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
411 QString anOperatorName = anOperator->name();
412 if( anOperatorName == ImageComposer_FuseOperator::Type() )
413 anIsFusedImage = true;
414 else if( anOperatorName == ImageComposer_CutOperator::Type() )
416 else if( anOperatorName == ImageComposer_CropOperator::Type() )
417 anIsSplittedImage = true;
422 else if( anObjectKind == KIND_POLYLINEXY )
424 else if( anObjectKind == KIND_POLYLINE )
425 anIsPolyline3D = true;
426 else if( anObjectKind == KIND_PROFILE )
429 aNbOfSelectedProfiles++;
431 Handle(HYDROData_Profile) aProfile =
432 Handle(HYDROData_Profile)::DownCast( anObject );
433 if( !aProfile.IsNull() && aProfile->IsValid() ) {
434 anIsValidProfile = true;
437 else if( anObjectKind == KIND_CALCULATION )
438 anIsCalculation = true;
439 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
440 anIsImmersibleZone = true;
441 else if( anObjectKind == KIND_VISUAL_STATE )
442 anIsVisualState = true;
443 else if( anObjectKind == KIND_REGION )
445 else if( anObjectKind == KIND_ZONE )
447 else if( anObjectKind == KIND_BATHYMETRY )
448 anIsBathymetry = true;
449 else if( anObjectKind == KIND_OBSTACLE )
451 else if( anObjectKind == KIND_STREAM )
454 Handle(HYDROData_Stream) aStream =
455 Handle(HYDROData_Stream)::DownCast( anObject );
456 if ( !aStream.IsNull() )
457 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
459 else if( anObjectKind == KIND_CHANNEL )
461 else if( anObjectKind == KIND_DIGUE )
463 else if( anObjectKind == KIND_DUMMY_3D )
464 anIsDummyObject3D = true;
465 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
469 if ( !anIsObjectCanBeColored )
470 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
473 // Check if all selected objects are profiles
474 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
475 ( aNbOfSelectedProfiles == aSeq.Length() );
477 // check the selected partitions
478 if( !anIsSelectedDataObjects && anIsObjectBrowser )
480 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
481 if( aSelectedPartition != KIND_UNKNOWN )
483 switch( aSelectedPartition )
486 theMenu->addAction( action( ImportImageId ) );
488 case KIND_BATHYMETRY:
489 theMenu->addAction( action( ImportBathymetryId ) );
491 case KIND_ARTIFICIAL_OBJECT:
492 theMenu->addAction( action( CreateChannelId ) );
493 theMenu->addAction( action( CreateDigueId ) );
495 case KIND_NATURAL_OBJECT:
496 theMenu->addAction( action( CreateImmersibleZoneId ) );
497 theMenu->addAction( action( CreateStreamId ) );
500 theMenu->addAction( action( ImportObstacleFromFileId ) );
501 theMenu->addAction( action( CreateBoxId ) );
502 theMenu->addAction( action( CreateCylinderId ) );
504 case KIND_CALCULATION:
505 theMenu->addAction( action( CreateCalculationId ) );
507 case KIND_POLYLINEXY:
508 theMenu->addAction( action( CreatePolylineId ) );
511 theMenu->addAction( action( CreatePolyline3DId ) );
514 theMenu->addAction( action( CreateProfileId ) );
515 theMenu->addAction( action( ImportProfilesId ) );
516 theMenu->addAction( action( AllGeoreferencementId ) );
518 case KIND_VISUAL_STATE:
519 theMenu->addAction( action( SaveVisualStateId ) );
522 theMenu->addSeparator();
526 if( anIsSelectedDataObjects )
528 if ( anIsMustObjectBeUpdated )
530 theMenu->addAction( action( UpdateObjectId ) );
531 theMenu->addSeparator();
535 theMenu->addAction( action( ForcedUpdateObjectId ) );
536 theMenu->addSeparator();
540 if( aSeq.Length() == 1 )
544 if( anIsImportedImage )
545 theMenu->addAction( action( EditImportedImageId ) );
546 else if( anIsImageHasRefs )
549 theMenu->addAction( action( EditFusedImageId ) );
550 else if( anIsCutImage )
551 theMenu->addAction( action( EditCutImageId ) );
552 else if( anIsSplittedImage )
553 theMenu->addAction( action( EditSplittedImageId ) );
556 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
557 theMenu->addAction( action( ExportImageId ) );
558 theMenu->addSeparator();
560 if( anIsImageHasRefs )
562 theMenu->addAction( action( RemoveImageRefsId ) );
563 theMenu->addSeparator();
566 theMenu->addAction( action( FuseImagesId ) );
567 theMenu->addAction( action( CutImagesId ) );
568 theMenu->addAction( action( SplitImageId ) );
569 theMenu->addSeparator();
571 else if( anIsBathymetry )
573 theMenu->addAction( action( EditImportedBathymetryId ) );
574 theMenu->addAction( action( BathymetryBoundsId ) );
575 theMenu->addSeparator();
577 else if( anIsPolyline )
579 theMenu->addAction( action( EditPolylineId ) );
580 theMenu->addSeparator();
582 else if( anIsPolyline3D )
584 theMenu->addAction( action( EditPolyline3DId ) );
585 theMenu->addSeparator();
587 else if( anIsProfile )
589 theMenu->addAction( action( EditProfileId ) );
590 theMenu->addAction( action( SelectedGeoreferencementId ) );
591 theMenu->addSeparator();
593 else if( anIsCalculation )
595 theMenu->addAction( action( EditCalculationId ) );
596 theMenu->addAction( action( ExportCalculationId ) );
597 theMenu->addSeparator();
599 else if( anIsImmersibleZone )
601 theMenu->addAction( action( EditImmersibleZoneId ) );
602 theMenu->addSeparator();
604 else if( anIsStream )
606 theMenu->addAction( action( EditStreamId ) );
607 if ( action( RiverBottomContextId ) )
609 theMenu->addAction( action( RiverBottomContextId ) );
610 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
612 theMenu->addAction( action( ProfileInterpolateId ) );
613 theMenu->addSeparator();
615 else if( anIsChannel )
617 theMenu->addAction( action( EditChannelId ) );
618 theMenu->addSeparator();
622 theMenu->addAction( action( EditDigueId ) );
623 theMenu->addSeparator();
625 else if( anIsObstacle )
627 theMenu->addAction( action( TranslateObstacleId ) );
628 theMenu->addSeparator();
630 else if( anIsVisualState && anIsObjectBrowser )
632 theMenu->addAction( action( SaveVisualStateId ) );
633 theMenu->addAction( action( LoadVisualStateId ) );
634 theMenu->addSeparator();
637 // Add set color action for geometrical objects
638 if ( anIsObjectCanBeColored )
640 theMenu->addAction( action( SetColorId ) );
641 theMenu->addSeparator();
643 } else if ( anAllAreProfiles ) {
644 theMenu->addAction( action( SelectedGeoreferencementId ) );
645 theMenu->addSeparator();
649 QAction* aCopyAction = action( CopyId );
650 if( aCopyAction && aCopyAction->isEnabled() ) {
651 theMenu->addAction( action( CopyId ) );
652 theMenu->addSeparator();
656 if( !anIsDummyObject3D )
657 theMenu->addAction( action( DeleteId ) );
659 theMenu->addSeparator();
661 if( anIsImage || anIsPolyline || anIsPolyline3D ||
662 anIsImmersibleZone || anIsZone || anIsRegion ||
663 anIsBathymetry || anIsObstacle || anIsStream ||
664 anIsChannel || anIsDigue || anIsDummyObject3D ||
665 anIsValidProfile || anIsGroup )
667 if( anIsHiddenInSelection )
668 theMenu->addAction( action( ShowId ) );
669 theMenu->addAction( action( ShowOnlyId ) );
670 if( anIsVisibleInSelection )
671 theMenu->addAction( action( HideId ) );
672 theMenu->addSeparator();
678 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
679 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
680 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
681 theMenu->addAction( action( DeleteId ) );
683 theMenu->addSeparator();
684 theMenu->addAction( action( SetZLevelId ) );
685 theMenu->addSeparator();
688 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
690 theMenu->addAction( action( ShowAllId ) );
691 theMenu->addAction( action( HideAllId ) );
692 theMenu->addSeparator();
695 if ( anIsOCCView || anIsVTKView )
697 theMenu->addSeparator();
698 theMenu->addAction( action( CopyViewerPositionId ) );
702 theMenu->addAction( action( EditLocalCSId ) );
704 if( anIsObjectBrowser && anOwners.size()==1 )
706 Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
707 if( !anObject.IsNull() )
709 theMenu->addSeparator();
710 theMenu->addAction( action( SubmersibleId ) );
711 action( SubmersibleId )->setCheckable( true );
712 action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
717 void HYDROGUI_Module::update( const int flags )
719 if( !isUpdateEnabled() )
722 QApplication::setOverrideCursor( Qt::WaitCursor );
724 // To prevent calling this method recursively
725 // from one of the methods called below
726 setUpdateEnabled( false );
728 // store selected objects
729 QStringList aSelectedEntries = storeSelection();
731 bool aDoFitAll = flags & UF_FitAll;
732 if( ( flags & UF_Viewer ) )
733 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
735 if( ( flags & UF_OCCViewer ) )
736 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
738 if( ( flags & UF_VTKViewer ) )
739 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
741 if( ( flags & UF_Model ) && getDataModel() && getApp() )
743 getDataModel()->update( getStudyId() );
745 // Temporary workaround to prevent breaking
746 // the selection in the object browser.
747 // Note: processEvents() should be called after updateGV(),
748 // otherwise the application crashes from time to time.
749 //RKV: qApp->processEvents();
750 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
751 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
752 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
753 if ( isResizeOnExpandItem && anObjectBrowser ) {
754 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
756 getApp()->updateObjectBrowser( true );
757 if ( isResizeOnExpandItem && anObjectBrowser ) {
758 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
762 // Object browser is currently updated by using UF_Model flag
763 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
764 getApp()->updateObjectBrowser( true );
766 if( ( flags & UF_Controls ) && getApp() )
767 getApp()->updateActions();
769 // restore selected objects
770 restoreSelection( aSelectedEntries );
772 setUpdateEnabled( true );
774 QApplication::restoreOverrideCursor();
777 void HYDROGUI_Module::updateCommandsStatus()
779 LightApp_Module::updateCommandsStatus();
781 updateUndoRedoControls();
783 action( CopyId )->setEnabled( getDataModel()->canCopy() );
784 action( PasteId )->setEnabled( getDataModel()->canPaste() );
787 void HYDROGUI_Module::selectionChanged()
789 LightApp_Module::selectionChanged();
790 updateCommandsStatus();
793 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
795 return (HYDROGUI_DataModel*)dataModel();
798 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
803 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
805 return myOCCDisplayer;
808 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
810 return myVTKDisplayer;
813 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
815 if( myViewManagerMap.contains( theId ) )
817 return myViewManagerMap[ theId ].first;
822 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
824 if( myViewManagerMap.contains( theId ) )
826 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
827 GraphicsView_ViewManager* aViewManager =
828 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
830 return aViewManager->getViewer();
835 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
837 if( myViewManagerMap.contains( theId ) )
839 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
840 OCCViewer_ViewManager* aViewManager =
841 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
843 return aViewManager->getOCCViewer();
848 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
850 if( myViewManagerMap.contains( theId ) )
852 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
853 SVTK_ViewManager* aViewManager =
854 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
856 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
861 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
863 ViewManagerMapIterator anIter( myViewManagerMap );
864 while( anIter.hasNext() )
866 int anId = anIter.next().key();
867 const ViewManagerInfo& anInfo = anIter.value();
868 if( anInfo.first == theViewManager )
874 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
876 int anId = getViewManagerId( theViewManager );
879 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
880 return anInfo.second;
885 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
886 const ViewManagerRole theRole )
888 int anId = getViewManagerId( theViewManager );
891 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
892 anInfo.second = theRole;
896 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
897 const Handle(HYDROData_Entity)& theObject ) const
899 if( theObject.IsNull() )
902 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
903 if( anIter1 != myObjectStateMap.end() )
905 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
906 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
908 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
909 if( anIter2 != aEntry2ObjectStateMap.end() )
911 const ObjectState& anObjectState = anIter2.value();
912 return anObjectState.Visibility;
918 void HYDROGUI_Module::setObjectVisible( const int theViewId,
919 const Handle(HYDROData_Entity)& theObject,
920 const bool theState )
922 if( !theObject.IsNull() )
924 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
925 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
927 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
928 anObjectState.Visibility = theState;
932 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
933 const bool theState )
935 if( !theObject.IsNull() )
937 // Process OCC shapes
938 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
939 while( aShapesMapIter != myShapesMap.end() )
941 const ListOfShapes& aShapesList = aShapesMapIter.value();
942 foreach ( HYDROGUI_Shape* aShape, aShapesList )
944 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
946 aShape->setIsToUpdate( theState );
951 // Process VTK shapes
952 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
953 while( aVTKPrsMapIter != myVTKPrsMap.end() )
955 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
956 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
958 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
960 aShape->setIsToUpdate( theState );
968 /////////////////// OCC SHAPES PROCESSING
969 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
970 ObjectKind theKind ) const
972 QList<HYDROGUI_Shape*> aResult;
974 if ( myShapesMap.contains( theViewId ) )
976 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
977 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
979 if( aShape && aShape->getObject()->GetKind()==theKind )
980 aResult.append( aShape );
986 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
987 const Handle(HYDROData_Entity)& theObject ) const
989 HYDROGUI_Shape* aResShape = NULL;
990 if( theObject.IsNull() )
993 if ( myShapesMap.contains( theViewId ) )
995 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
996 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
998 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1009 void HYDROGUI_Module::setObjectShape( const int theViewId,
1010 const Handle(HYDROData_Entity)& theObject,
1011 HYDROGUI_Shape* theShape )
1013 if( theObject.IsNull() )
1016 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1017 aViewShapes.append( theShape );
1020 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1021 const Handle(HYDROData_Entity)& theObject )
1023 if ( !myShapesMap.contains( theViewId ) )
1026 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1027 Handle(HYDROData_Entity) anObject;
1028 for ( int i = 0; i < aViewShapes.length(); )
1030 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1031 anObject = aShape->getObject();
1032 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1035 aViewShapes.removeAt( i );
1043 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1045 if ( !myShapesMap.contains( theViewId ) )
1048 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1049 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1051 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1056 myShapesMap.remove( theViewId );
1058 /////////////////// END OF OCC SHAPES PROCESSING
1060 /////////////////// VTKPrs PROCESSING
1061 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1062 const Handle(HYDROData_Entity)& theObject ) const
1064 HYDROGUI_VTKPrs* aResShape = NULL;
1065 if( theObject.IsNull() )
1068 if ( myVTKPrsMap.contains( theViewId ) )
1070 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1071 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1073 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1084 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1085 const Handle(HYDROData_Entity)& theObject,
1086 HYDROGUI_VTKPrs* theShape )
1088 if( theObject.IsNull() )
1091 if( theShape && theShape->needScalarBar() )
1093 // Compute the new global Z range from the added presentation and the old global Z range.
1094 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1095 double* aRange = theShape->getInternalZRange();
1096 bool anIsUpdate = false;
1097 if ( aRange[0] < aGlobalRange[0] )
1099 aGlobalRange[0] = aRange[0];
1102 if ( aRange[1] > aGlobalRange[1] )
1104 aGlobalRange[1] = aRange[1];
1110 updateVTKZRange( theViewId, aGlobalRange );
1114 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1115 aViewShapes.append( theShape );
1118 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1119 const QString& theEntry )
1121 if ( !myVTKPrsMap.contains( theViewId ) )
1124 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1125 Handle(HYDROData_Entity) anObject;
1127 for ( int i = 0; i < aViewShapes.length(); )
1129 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1130 anObject = aShape->getObject();
1131 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1132 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1135 aViewShapes.removeAt( i );
1142 // Invalidate global Z range
1143 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1144 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1147 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1148 const Handle(HYDROData_Entity)& theObject )
1150 if ( !myVTKPrsMap.contains( theViewId ) )
1153 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1154 Handle(HYDROData_Entity) anObject;
1155 for ( int i = 0; i < aViewShapes.length(); )
1157 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1158 anObject = aShape->getObject();
1159 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1162 aViewShapes.removeAt( i );
1169 // Invalidate global Z range
1170 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1171 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1174 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1176 if ( !myVTKPrsMap.contains( theViewId ) )
1179 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1180 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1182 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1187 myVTKPrsMap.remove( theViewId );
1190 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1192 if ( myVTKPrsMap.contains( theViewId ) )
1194 // For the given viewer id update all VTK presentations ...
1195 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1196 HYDROGUI_VTKPrs* aShape;
1197 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1199 aShape = aViewShapes.at( i );
1200 if ( aShape && aShape->needScalarBar() )
1202 aShape->setZRange( theRange );
1206 // ... and update the global color legend scalar bar.
1207 getVTKDisplayer()->SetZRange( theViewId, theRange );
1209 /////////////////// END OF VTKPrs PROCESSING
1211 CAM_DataModel* HYDROGUI_Module::createDataModel()
1213 return new HYDROGUI_DataModel( this );
1216 void HYDROGUI_Module::customEvent( QEvent* e )
1218 int aType = e->type();
1219 if ( aType == NewViewEvent )
1221 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1222 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1224 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1226 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1227 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1229 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1231 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1232 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1234 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1235 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1236 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1238 //ouv: temporarily commented
1239 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1242 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1243 update( UF_Viewer );
1245 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1251 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1253 QEvent::Type aType = theEvent->type();
1254 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1256 if( aType == QEvent::Show )
1258 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1259 e->setData( theObj );
1260 QApplication::postEvent( this, e );
1261 theObj->removeEventFilter( this );
1264 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1266 if( aType == QEvent::Leave )
1268 SUIT_Desktop* aDesktop = getApp()->desktop();
1269 if ( aDesktop && aDesktop->statusBar() ) {
1270 aDesktop->statusBar()->clearMessage();
1274 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1276 if( aType == QEvent::Leave )
1278 SUIT_Desktop* aDesktop = getApp()->desktop();
1279 if ( aDesktop && aDesktop->statusBar() ) {
1280 aDesktop->statusBar()->clearMessage();
1285 return LightApp_Module::eventFilter( theObj, theEvent );
1288 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1290 LightApp_Module::onViewManagerAdded( theViewManager );
1292 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1294 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1295 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1297 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1299 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1300 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1301 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1302 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1304 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1306 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1307 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1308 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1309 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1312 createSelector( theViewManager ); // replace the default selector
1314 ViewManagerInfo anInfo( theViewManager, VMR_General );
1315 myViewManagerMap.insert( ViewManagerId++, anInfo );
1318 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1320 LightApp_Module::onViewManagerRemoved( theViewManager );
1322 createSelector( theViewManager ); // replace the default selector
1324 int anId = getViewManagerId( theViewManager );
1327 OCCViewer_ViewManager* anOCCViewManager =
1328 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1329 if ( anOCCViewManager )
1331 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1333 removeViewShapes( (size_t)anOCCViewer );
1336 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1338 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1341 getVTKDisplayer()->EraseScalarBar( anId, true );
1342 removeViewShapes( (size_t)aVTKViewer );
1346 myViewManagerMap.remove( anId );
1350 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1352 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1354 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1356 aViewFrame->installEventFilter( this );
1358 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1360 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1361 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1364 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1366 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1368 aViewFrame->onTopView();
1370 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1372 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1374 aViewPort->installEventFilter( this );
1378 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1380 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1382 aViewFrame->installEventFilter( this );
1387 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1389 /* ouv: currently unused
1390 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1392 SUIT_ViewManager* aViewManager = 0;
1394 QObject* aParent = aViewPort;
1395 while( aParent = aParent->parent() )
1397 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1399 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1401 aViewManager = aViewer->getViewManager();
1410 double aMouseX = theEvent->scenePos().x();
1411 double aMouseY = theEvent->scenePos().y();
1413 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1414 if( aRole == VMR_General )
1416 int aXDeg = 0, aYDeg = 0;
1417 int aXMin = 0, aYMin = 0;
1418 double aXSec = 0, aYSec = 0;
1419 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1420 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1422 QString aDegSymbol( QChar( 0x00B0 ) );
1423 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1424 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1426 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1428 else if( aRole == VMR_TransformImage )
1429 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1434 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1435 const bool theIsInit,
1436 const bool theIsForced,
1437 const bool theDoFitAll )
1439 QList<int> aViewManagerIdList;
1441 // currently, all views are updated
1442 ViewManagerMapIterator anIter( myViewManagerMap );
1443 while( anIter.hasNext() )
1445 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1447 if ( theDisplayer->IsApplicable( aViewManager ) )
1449 int anId = anIter.key();
1450 aViewManagerIdList.append( anId );
1454 QListIterator<int> anIdIter( aViewManagerIdList );
1455 while( anIdIter.hasNext() )
1457 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1461 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1463 if( !theViewManager )
1466 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1467 if( !aSelectionMgr )
1470 QString aViewType = theViewManager->getType();
1471 if( aViewType != GraphicsView_Viewer::Type() &&
1472 aViewType != OCCViewer_Viewer::Type())
1475 QList<SUIT_Selector*> aSelectorList;
1476 aSelectionMgr->selectors( aViewType, aSelectorList );
1478 // disable all alien selectors
1479 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1480 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1482 SUIT_Selector* aSelector = *anIter;
1483 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1484 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1485 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1486 aSelector->setEnabled( false );
1489 if ( aViewType == GraphicsView_Viewer::Type() )
1491 GraphicsView_ViewManager* aViewManager =
1492 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1494 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1496 else if ( aViewType == OCCViewer_Viewer::Type() )
1498 OCCViewer_ViewManager* aViewManager =
1499 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1501 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1505 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1507 bool aPrevState = myIsUpdateEnabled;
1508 myIsUpdateEnabled = theState;
1512 bool HYDROGUI_Module::isUpdateEnabled() const
1514 return myIsUpdateEnabled;
1517 QStringList HYDROGUI_Module::storeSelection() const
1519 QStringList anEntryList;
1520 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1522 SUIT_DataOwnerPtrList aList( true );
1523 aSelectionMgr->selected( aList );
1525 SUIT_DataOwnerPtrList::iterator anIter;
1526 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1528 const LightApp_DataOwner* anOwner =
1529 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1531 anEntryList.append( anOwner->entry() );
1537 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1539 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1541 SUIT_DataOwnerPtrList aList( true );
1542 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1543 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1544 aSelectionMgr->setSelected( aList );
1548 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1551 bool doShow = false;
1552 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1554 aDisplayer->SaveCursorViewPosition( theViewWindow );
1555 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1559 // Show the coordinates in the status bar
1560 SUIT_Desktop* aDesktop = getApp()->desktop();
1561 if ( aDesktop && aDesktop->statusBar() )
1563 gp_Pnt aWPnt( X, Y, Z );
1564 int aStudyId = application()->activeStudy()->id();
1565 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1566 double WX = aWPnt.X(), WY = aWPnt.Y();
1568 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1569 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1570 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1571 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1572 QString aMsg = tr( "COORDINATES_INFO" );
1573 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1574 aDesktop->statusBar()->showMessage( aMsg );
1580 * Returns stack of active operations;
1582 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1584 return myActiveOperationMap;
1588 * Returns the module active operation. If the active operation is show/hide,
1589 * the method returns the previous operation if it is.
1591 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1593 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1595 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1597 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1599 aVIt.previous(); // skip the top show/hide operation
1600 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;