1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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"
45 #include "HYDROGUI_ShowHideOp.h"
47 #include <HYDROData_Tool.h>
48 #include <HYDROData_Image.h>
49 #include <HYDROData_Stream.h>
50 #include <HYDROData_Profile.h>
51 #include <HYDROData_Lambert93.h>
52 #include <HYDROData_Polyline3D.h>
54 #include <HYDROData_OperationsFactory.h>
56 #include <CurveCreator_Utils.hxx>
58 #include <GraphicsView_ViewFrame.h>
59 #include <GraphicsView_ViewManager.h>
60 #include <GraphicsView_ViewPort.h>
61 #include <GraphicsView_Viewer.h>
63 #include <ImageComposer_CutOperator.h>
64 #include <ImageComposer_CropOperator.h>
65 #include <ImageComposer_FuseOperator.h>
67 #include <LightApp_Application.h>
68 #include <LightApp_DataOwner.h>
69 #include <LightApp_GVSelector.h>
70 #include <LightApp_SelectionMgr.h>
71 #include <LightApp_UpdateFlags.h>
73 #include <SalomeApp_Study.h>
75 #include <OCCViewer_ViewFrame.h>
76 #include <OCCViewer_ViewManager.h>
77 #include <OCCViewer_ViewModel.h>
79 #include <SALOME_Event.h>
81 #include <SUIT_DataBrowser.h>
82 #include <SUIT_Desktop.h>
83 #include <SUIT_Study.h>
84 #include <SUIT_ViewManager.h>
85 #include <SUIT_ResourceMgr.h>
87 #include <SVTK_ViewManager.h>
88 #include <SVTK_ViewModel.h>
89 #include <SVTK_ViewWindow.h>
90 #include <SVTK_Selector.h>
92 #include <OCCViewer_ViewPort3d.h>
94 #include <GEOMUtils.hxx>
95 #include <GeometryGUI.h>
97 #include <SALOMEDS_wrap.hxx>
100 #include <QApplication>
101 #include <QGraphicsSceneMouseEvent>
103 #include <QMouseEvent>
104 #include <QStatusBar>
107 static int ViewManagerId = 0;
109 extern "C" HYDRO_EXPORT CAM_Module* createModule()
111 return new HYDROGUI_Module();
114 extern "C" HYDRO_EXPORT char* getModuleVersion()
116 return (char*)HYDRO_VERSION;
119 HYDROGUI_Module::HYDROGUI_Module()
120 : LightApp_Module( "HYDRO" ),
123 myIsUpdateEnabled( true )
127 HYDROGUI_Module::~HYDROGUI_Module()
131 int HYDROGUI_Module::getStudyId() const
133 LightApp_Application* anApp = getApp();
134 return anApp ? anApp->activeStudy()->id() : 0;
137 void HYDROGUI_Module::initialize( CAM_Application* theApp )
139 LightApp_Module::initialize( theApp );
142 createUndoRedoActions();
147 setMenuShown( false );
148 setToolShown( false );
150 myDisplayer = new HYDROGUI_Displayer( this );
151 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
152 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
155 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
157 bool aRes = LightApp_Module::activateModule( theStudy );
159 LightApp_Application* anApp = getApp();
160 SUIT_Desktop* aDesktop = anApp->desktop();
162 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
164 setMenuShown( true );
165 setToolShown( true );
167 #ifndef DISABLE_PYCONSOLE
168 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
169 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
172 // Remove defunct view managers from the map.
173 // It's essential to do this before "update( UF_All )" call!
174 QList<int> anObsoleteIds;
175 ViewManagerList anAllViewManagers = anApp->viewManagers();
176 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
177 ViewManagerMapIterator anIter( myViewManagerMap );
178 while( anIter.hasNext() ) {
179 int anId = anIter.next().key();
180 const ViewManagerInfo& anInfo = anIter.value();
182 aHydroViewManagers << anInfo.first;
184 if ( !anAllViewManagers.contains( anInfo.first ) ) {
185 anObsoleteIds << anId;
188 foreach ( const int anId, anObsoleteIds ) {
189 myViewManagerMap.remove( anId );
190 myObjectStateMap.remove( anId );
191 myShapesMap.remove( anId );
192 myVTKPrsMap.remove( anId );
194 // Replace the default selector for all view managers.
195 // Add view managers created outside of HYDRO module to the map.
196 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
197 createSelector( aViewManager ); // replace the default selector
198 if ( !aHydroViewManagers.contains( aViewManager ) ) {
199 ViewManagerInfo anInfo( aViewManager, VMR_General );
200 myViewManagerMap.insert( ViewManagerId++, anInfo );
206 updateCommandsStatus();
208 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
210 ViewManagerList anOCCViewManagers;
211 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
212 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
213 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
214 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
215 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
216 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
217 if ( aViewFrame && aViewFrame->getViewPort() ) {
218 aViewFrame->getViewPort()->installEventFilter( this );
224 SalomeApp_Study* aStudy =
225 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
227 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
228 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
229 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
230 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
231 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
232 if( !GEOM_var->_is_nil() ) {
233 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
241 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
244 ViewManagerMapIterator anIter( myViewManagerMap );
245 while( anIter.hasNext() )
246 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
247 getApp()->removeViewManager( aViewManager );
248 myViewManagerMap.clear();
251 ViewManagerList anOCCViewManagers;
252 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
253 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
254 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
255 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
259 myObjectStateMap.clear();
264 // clear the status bar
265 SUIT_Desktop* aDesktop = getApp()->desktop();
266 if ( aDesktop && aDesktop->statusBar() ) {
267 aDesktop->statusBar()->clearMessage();
270 // clear the data model's list of copying objects
271 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
273 setMenuShown( false );
274 setToolShown( false );
276 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
278 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
280 myActiveOperationMap.clear();
281 return LightApp_Module::deactivateModule( theStudy );
284 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
287 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
288 #ifndef DISABLE_PYCONSOLE
289 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
291 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
294 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
296 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
299 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
303 HYDROGUI_DataModel* aModel = getDataModel();
305 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
306 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
307 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
308 bool anIsVTKView = theClient == SVTK_Viewer::Type();
309 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
312 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
314 bool anIsSelectedDataObjects = false;
315 bool anIsVisibleInSelection = false;
316 bool anIsHiddenInSelection = false;
318 bool anIsImage = false;
319 bool anIsImportedImage = false;
320 bool anIsImageHasRefs = false;
321 bool anIsFusedImage = false;
322 bool anIsCutImage = false;
323 bool anIsSplittedImage = false;
324 bool anIsMustObjectBeUpdated = false;
325 bool anIsPolyline = false;
326 bool anIsPolyline3D = false;
327 bool anIsProfile = false;
328 bool anIsValidProfile = false;
329 bool anAllAreProfiles = false;
330 bool anIsBathymetry = false;
331 bool anIsCalculation = false;
332 bool anIsImmersibleZone = false;
333 bool anIsVisualState = false;
334 bool anIsRegion = false;
335 bool anIsZone = false;
336 bool anIsObstacle = false;
337 bool anIsStream = false;
338 bool anIsChannel = false;
339 bool anIsDigue = false;
340 bool anIsDummyObject3D = false;
341 bool anIsGroup = false;
342 bool anIsObjectCanBeColored = false;
344 bool isStreamHasBottom = false;
346 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
347 SUIT_DataOwnerPtrList anOwners;
348 aSelectionMgr->selected( anOwners );
349 if( anIsObjectBrowser && anOwners.size()==1 )
351 QString anEntry = anOwners[0]->keyString();
352 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
354 isRoot = aStudy->isComponent( anEntry );
357 // Check the selected GEOM objects (take into account the Object Browser only)
358 if ( anIsObjectBrowser ) {
359 QList<GEOM::shape_type> anObstacleTypes =
360 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
361 QList<GEOM::shape_type> aPolylineTypes =
362 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
364 bool isCanBeImportedAsObstacle =
365 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
366 bool isCanBeImportedAsPolyline =
367 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
369 // Add import as obstacle action
370 if ( isCanBeImportedAsObstacle ) {
371 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
373 // Add import as polyline action
374 if ( isCanBeImportedAsPolyline ) {
375 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
378 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
379 theMenu->addSeparator();
383 // check the selected data model objects
384 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
385 int aNbOfSelectedProfiles = 0;
386 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
388 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
389 if( !anObject.IsNull() )
391 anIsSelectedDataObjects = true;
393 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
394 anIsVisibleInSelection |= aVisibility;
395 anIsHiddenInSelection |= !aVisibility;
397 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
399 anIsMustObjectBeUpdated = true;
402 ObjectKind anObjectKind = anObject->GetKind();
403 if( anObjectKind == KIND_IMAGE )
406 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
407 if( !anImage.IsNull() )
409 anIsImportedImage = anImage->HasLocalPoints();
410 anIsImageHasRefs = anImage->HasReferences();
411 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
413 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
415 QString anOperatorName = anOperator->name();
416 if( anOperatorName == ImageComposer_FuseOperator::Type() )
417 anIsFusedImage = true;
418 else if( anOperatorName == ImageComposer_CutOperator::Type() )
420 else if( anOperatorName == ImageComposer_CropOperator::Type() )
421 anIsSplittedImage = true;
426 else if( anObjectKind == KIND_POLYLINEXY )
428 else if( anObjectKind == KIND_POLYLINE )
429 anIsPolyline3D = true;
430 else if( anObjectKind == KIND_PROFILE )
433 aNbOfSelectedProfiles++;
435 Handle(HYDROData_Profile) aProfile =
436 Handle(HYDROData_Profile)::DownCast( anObject );
437 if( !aProfile.IsNull() && aProfile->IsValid() ) {
438 anIsValidProfile = true;
441 else if( anObjectKind == KIND_CALCULATION )
442 anIsCalculation = true;
443 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
444 anIsImmersibleZone = true;
445 else if( anObjectKind == KIND_VISUAL_STATE )
446 anIsVisualState = true;
447 else if( anObjectKind == KIND_REGION )
449 else if( anObjectKind == KIND_ZONE )
451 else if( anObjectKind == KIND_BATHYMETRY )
452 anIsBathymetry = true;
453 else if( anObjectKind == KIND_OBSTACLE )
455 else if( anObjectKind == KIND_STREAM )
458 Handle(HYDROData_Stream) aStream =
459 Handle(HYDROData_Stream)::DownCast( anObject );
460 if ( !aStream.IsNull() )
461 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
463 else if( anObjectKind == KIND_CHANNEL )
465 else if( anObjectKind == KIND_DIGUE )
467 else if( anObjectKind == KIND_DUMMY_3D )
468 anIsDummyObject3D = true;
469 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
473 if ( !anIsObjectCanBeColored )
474 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
477 // Check if all selected objects are profiles
478 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
479 ( aNbOfSelectedProfiles == aSeq.Length() );
481 // check the selected partitions
482 if( !anIsSelectedDataObjects && anIsObjectBrowser )
484 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
485 if( aSelectedPartition != KIND_UNKNOWN )
487 switch( aSelectedPartition )
490 theMenu->addAction( action( ImportImageId ) );
492 case KIND_BATHYMETRY:
493 theMenu->addAction( action( ImportBathymetryId ) );
495 case KIND_ARTIFICIAL_OBJECT:
496 theMenu->addAction( action( CreateChannelId ) );
497 theMenu->addAction( action( CreateDigueId ) );
499 case KIND_NATURAL_OBJECT:
500 theMenu->addAction( action( CreateImmersibleZoneId ) );
501 theMenu->addAction( action( CreateStreamId ) );
504 theMenu->addAction( action( ImportObstacleFromFileId ) );
505 theMenu->addAction( action( CreateBoxId ) );
506 theMenu->addAction( action( CreateCylinderId ) );
508 case KIND_CALCULATION:
509 theMenu->addAction( action( CreateCalculationId ) );
511 case KIND_POLYLINEXY:
512 theMenu->addAction( action( CreatePolylineId ) );
515 theMenu->addAction( action( CreatePolyline3DId ) );
518 theMenu->addAction( action( CreateProfileId ) );
519 theMenu->addAction( action( ImportProfilesId ) );
520 theMenu->addAction( action( AllGeoreferencementId ) );
522 case KIND_VISUAL_STATE:
523 theMenu->addAction( action( SaveVisualStateId ) );
526 theMenu->addSeparator();
530 if( anIsSelectedDataObjects )
532 if ( anIsMustObjectBeUpdated )
534 theMenu->addAction( action( UpdateObjectId ) );
535 theMenu->addSeparator();
539 theMenu->addAction( action( ForcedUpdateObjectId ) );
540 theMenu->addSeparator();
544 if( aSeq.Length() == 1 )
548 if( anIsImportedImage )
549 theMenu->addAction( action( EditImportedImageId ) );
550 else if( anIsImageHasRefs )
553 theMenu->addAction( action( EditFusedImageId ) );
554 else if( anIsCutImage )
555 theMenu->addAction( action( EditCutImageId ) );
556 else if( anIsSplittedImage )
557 theMenu->addAction( action( EditSplittedImageId ) );
560 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
561 theMenu->addAction( action( ExportImageId ) );
562 theMenu->addSeparator();
564 if( anIsImageHasRefs )
566 theMenu->addAction( action( RemoveImageRefsId ) );
567 theMenu->addSeparator();
570 theMenu->addAction( action( FuseImagesId ) );
571 theMenu->addAction( action( CutImagesId ) );
572 theMenu->addAction( action( SplitImageId ) );
573 theMenu->addSeparator();
575 else if( anIsBathymetry )
577 theMenu->addAction( action( EditImportedBathymetryId ) );
578 theMenu->addAction( action( BathymetryBoundsId ) );
579 theMenu->addSeparator();
581 else if( anIsPolyline )
583 theMenu->addAction( action( EditPolylineId ) );
584 theMenu->addSeparator();
586 else if( anIsPolyline3D )
588 theMenu->addAction( action( EditPolyline3DId ) );
589 theMenu->addSeparator();
591 else if( anIsProfile )
593 theMenu->addAction( action( EditProfileId ) );
594 theMenu->addAction( action( SelectedGeoreferencementId ) );
595 theMenu->addSeparator();
597 else if( anIsCalculation )
599 theMenu->addAction( action( EditCalculationId ) );
600 theMenu->addAction( action( ExportCalculationId ) );
601 theMenu->addSeparator();
603 else if( anIsImmersibleZone )
605 theMenu->addAction( action( EditImmersibleZoneId ) );
606 theMenu->addSeparator();
608 else if( anIsStream )
610 theMenu->addAction( action( EditStreamId ) );
611 if ( action( RiverBottomContextId ) )
613 theMenu->addAction( action( RiverBottomContextId ) );
614 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
616 theMenu->addAction( action( ProfileInterpolateId ) );
617 theMenu->addSeparator();
619 else if( anIsChannel )
621 theMenu->addAction( action( EditChannelId ) );
622 theMenu->addSeparator();
626 theMenu->addAction( action( EditDigueId ) );
627 theMenu->addSeparator();
629 else if( anIsObstacle )
631 theMenu->addAction( action( TranslateObstacleId ) );
632 theMenu->addSeparator();
634 else if( anIsVisualState && anIsObjectBrowser )
636 theMenu->addAction( action( SaveVisualStateId ) );
637 theMenu->addAction( action( LoadVisualStateId ) );
638 theMenu->addSeparator();
641 // Add set color action for geometrical objects
642 if ( anIsObjectCanBeColored )
644 theMenu->addAction( action( SetColorId ) );
645 theMenu->addSeparator();
647 } else if ( anAllAreProfiles ) {
648 theMenu->addAction( action( SelectedGeoreferencementId ) );
649 theMenu->addSeparator();
653 QAction* aCopyAction = action( CopyId );
654 if( aCopyAction && aCopyAction->isEnabled() ) {
655 theMenu->addAction( action( CopyId ) );
656 theMenu->addSeparator();
660 if( !anIsDummyObject3D )
661 theMenu->addAction( action( DeleteId ) );
663 theMenu->addSeparator();
665 if( anIsImage || anIsPolyline || anIsPolyline3D ||
666 anIsImmersibleZone || anIsZone || anIsRegion ||
667 anIsBathymetry || anIsObstacle || anIsStream ||
668 anIsChannel || anIsDigue || anIsDummyObject3D ||
669 anIsValidProfile || anIsGroup )
671 if( anIsHiddenInSelection )
672 theMenu->addAction( action( ShowId ) );
673 theMenu->addAction( action( ShowOnlyId ) );
674 if( anIsVisibleInSelection )
675 theMenu->addAction( action( HideId ) );
676 theMenu->addSeparator();
682 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
683 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
684 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
685 theMenu->addAction( action( DeleteId ) );
687 theMenu->addSeparator();
688 theMenu->addAction( action( SetZLevelId ) );
689 theMenu->addSeparator();
692 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
694 theMenu->addAction( action( ShowAllId ) );
695 theMenu->addAction( action( HideAllId ) );
696 theMenu->addSeparator();
699 if ( anIsOCCView || anIsVTKView )
701 theMenu->addSeparator();
702 theMenu->addAction( action( CopyViewerPositionId ) );
706 theMenu->addAction( action( EditLocalCSId ) );
709 void HYDROGUI_Module::update( const int flags )
711 if( !isUpdateEnabled() )
714 QApplication::setOverrideCursor( Qt::WaitCursor );
716 // To prevent calling this method recursively
717 // from one of the methods called below
718 setUpdateEnabled( false );
720 // store selected objects
721 QStringList aSelectedEntries = storeSelection();
723 bool aDoFitAll = flags & UF_FitAll;
724 if( ( flags & UF_Viewer ) )
725 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
727 if( ( flags & UF_OCCViewer ) )
728 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
730 if( ( flags & UF_VTKViewer ) )
731 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
733 if( ( flags & UF_Model ) && getDataModel() && getApp() )
735 getDataModel()->update( getStudyId() );
737 // Temporary workaround to prevent breaking
738 // the selection in the object browser.
739 // Note: processEvents() should be called after updateGV(),
740 // otherwise the application crashes from time to time.
741 //RKV: qApp->processEvents();
742 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
743 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
744 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
745 if ( isResizeOnExpandItem && anObjectBrowser ) {
746 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
748 getApp()->updateObjectBrowser( true );
749 if ( isResizeOnExpandItem && anObjectBrowser ) {
750 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
754 // Object browser is currently updated by using UF_Model flag
755 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
756 getApp()->updateObjectBrowser( true );
758 if( ( flags & UF_Controls ) && getApp() )
759 getApp()->updateActions();
761 // restore selected objects
762 restoreSelection( aSelectedEntries );
764 setUpdateEnabled( true );
766 QApplication::restoreOverrideCursor();
769 void HYDROGUI_Module::updateCommandsStatus()
771 LightApp_Module::updateCommandsStatus();
773 updateUndoRedoControls();
775 action( CopyId )->setEnabled( getDataModel()->canCopy() );
776 action( PasteId )->setEnabled( getDataModel()->canPaste() );
779 void HYDROGUI_Module::selectionChanged()
781 LightApp_Module::selectionChanged();
782 updateCommandsStatus();
785 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
787 return (HYDROGUI_DataModel*)dataModel();
790 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
795 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
797 return myOCCDisplayer;
800 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
802 return myVTKDisplayer;
805 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
807 if( myViewManagerMap.contains( theId ) )
809 return myViewManagerMap[ theId ].first;
814 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
816 if( myViewManagerMap.contains( theId ) )
818 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
819 GraphicsView_ViewManager* aViewManager =
820 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
822 return aViewManager->getViewer();
827 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
829 if( myViewManagerMap.contains( theId ) )
831 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
832 OCCViewer_ViewManager* aViewManager =
833 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
835 return aViewManager->getOCCViewer();
840 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
842 if( myViewManagerMap.contains( theId ) )
844 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
845 SVTK_ViewManager* aViewManager =
846 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
848 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
853 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
855 ViewManagerMapIterator anIter( myViewManagerMap );
856 while( anIter.hasNext() )
858 int anId = anIter.next().key();
859 const ViewManagerInfo& anInfo = anIter.value();
860 if( anInfo.first == theViewManager )
866 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
868 int anId = getViewManagerId( theViewManager );
871 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
872 return anInfo.second;
877 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
878 const ViewManagerRole theRole )
880 int anId = getViewManagerId( theViewManager );
883 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
884 anInfo.second = theRole;
888 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
889 const Handle(HYDROData_Entity)& theObject ) const
891 if( theObject.IsNull() )
894 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
895 if( anIter1 != myObjectStateMap.end() )
897 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
898 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
900 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
901 if( anIter2 != aEntry2ObjectStateMap.end() )
903 const ObjectState& anObjectState = anIter2.value();
904 return anObjectState.Visibility;
910 void HYDROGUI_Module::setObjectVisible( const int theViewId,
911 const Handle(HYDROData_Entity)& theObject,
912 const bool theState )
914 if( !theObject.IsNull() )
916 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
917 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
919 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
920 anObjectState.Visibility = theState;
924 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
925 const bool theState )
927 if( !theObject.IsNull() )
929 // Process OCC shapes
930 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
931 while( aShapesMapIter != myShapesMap.end() )
933 const ListOfShapes& aShapesList = aShapesMapIter.value();
934 foreach ( HYDROGUI_Shape* aShape, aShapesList )
936 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
938 aShape->setIsToUpdate( theState );
943 // Process VTK shapes
944 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
945 while( aVTKPrsMapIter != myVTKPrsMap.end() )
947 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
948 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
950 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
952 aShape->setIsToUpdate( theState );
960 /////////////////// OCC SHAPES PROCESSING
961 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
962 ObjectKind theKind ) const
964 QList<HYDROGUI_Shape*> aResult;
966 if ( myShapesMap.contains( theViewId ) )
968 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
969 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
971 if( aShape && aShape->getObject()->GetKind()==theKind )
972 aResult.append( aShape );
978 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
979 const Handle(HYDROData_Entity)& theObject ) const
981 HYDROGUI_Shape* aResShape = NULL;
982 if( theObject.IsNull() )
985 if ( myShapesMap.contains( theViewId ) )
987 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
988 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
990 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1001 void HYDROGUI_Module::setObjectShape( const int theViewId,
1002 const Handle(HYDROData_Entity)& theObject,
1003 HYDROGUI_Shape* theShape )
1005 if( theObject.IsNull() )
1008 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1009 aViewShapes.append( theShape );
1012 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1013 const Handle(HYDROData_Entity)& theObject )
1015 if ( !myShapesMap.contains( theViewId ) )
1018 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1019 Handle(HYDROData_Entity) anObject;
1020 for ( int i = 0; i < aViewShapes.length(); )
1022 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1023 anObject = aShape->getObject();
1024 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1027 aViewShapes.removeAt( i );
1035 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1037 if ( !myShapesMap.contains( theViewId ) )
1040 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1041 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1043 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1048 myShapesMap.remove( theViewId );
1050 /////////////////// END OF OCC SHAPES PROCESSING
1052 /////////////////// VTKPrs PROCESSING
1053 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1054 const Handle(HYDROData_Entity)& theObject ) const
1056 HYDROGUI_VTKPrs* aResShape = NULL;
1057 if( theObject.IsNull() )
1060 if ( myVTKPrsMap.contains( theViewId ) )
1062 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1063 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1065 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1076 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1077 const Handle(HYDROData_Entity)& theObject,
1078 HYDROGUI_VTKPrs* theShape )
1080 if( theObject.IsNull() )
1083 if( theShape && theShape->needScalarBar() )
1085 // Compute the new global Z range from the added presentation and the old global Z range.
1086 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1087 double* aRange = theShape->getInternalZRange();
1088 bool anIsUpdate = false;
1089 if ( aRange[0] < aGlobalRange[0] )
1091 aGlobalRange[0] = aRange[0];
1094 if ( aRange[1] > aGlobalRange[1] )
1096 aGlobalRange[1] = aRange[1];
1102 updateVTKZRange( theViewId, aGlobalRange );
1106 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1107 aViewShapes.append( theShape );
1110 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1111 const QString& theEntry )
1113 if ( !myVTKPrsMap.contains( theViewId ) )
1116 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1117 Handle(HYDROData_Entity) anObject;
1119 for ( int i = 0; i < aViewShapes.length(); )
1121 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1122 anObject = aShape->getObject();
1123 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1124 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1127 aViewShapes.removeAt( i );
1134 // Invalidate global Z range
1135 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1136 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1139 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1140 const Handle(HYDROData_Entity)& theObject )
1142 if ( !myVTKPrsMap.contains( theViewId ) )
1145 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1146 Handle(HYDROData_Entity) anObject;
1147 for ( int i = 0; i < aViewShapes.length(); )
1149 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1150 anObject = aShape->getObject();
1151 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1154 aViewShapes.removeAt( i );
1161 // Invalidate global Z range
1162 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1163 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1166 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1168 if ( !myVTKPrsMap.contains( theViewId ) )
1171 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1172 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1174 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1179 myVTKPrsMap.remove( theViewId );
1182 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1184 if ( myVTKPrsMap.contains( theViewId ) )
1186 // For the given viewer id update all VTK presentations ...
1187 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1188 HYDROGUI_VTKPrs* aShape;
1189 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1191 aShape = aViewShapes.at( i );
1192 if ( aShape && aShape->needScalarBar() )
1194 aShape->setZRange( theRange );
1198 // ... and update the global color legend scalar bar.
1199 getVTKDisplayer()->SetZRange( theViewId, theRange );
1201 /////////////////// END OF VTKPrs PROCESSING
1203 CAM_DataModel* HYDROGUI_Module::createDataModel()
1205 return new HYDROGUI_DataModel( this );
1208 void HYDROGUI_Module::customEvent( QEvent* e )
1210 int aType = e->type();
1211 if ( aType == NewViewEvent )
1213 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1214 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1216 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1218 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1219 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1221 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1223 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1224 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1226 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1227 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1228 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1230 //ouv: temporarily commented
1231 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1234 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1235 update( UF_Viewer );
1237 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1243 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1245 QEvent::Type aType = theEvent->type();
1246 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1248 if( aType == QEvent::Show )
1250 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1251 e->setData( theObj );
1252 QApplication::postEvent( this, e );
1253 theObj->removeEventFilter( this );
1256 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1258 if( aType == QEvent::Leave )
1260 SUIT_Desktop* aDesktop = getApp()->desktop();
1261 if ( aDesktop && aDesktop->statusBar() ) {
1262 aDesktop->statusBar()->clearMessage();
1266 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1268 if( aType == QEvent::Leave )
1270 SUIT_Desktop* aDesktop = getApp()->desktop();
1271 if ( aDesktop && aDesktop->statusBar() ) {
1272 aDesktop->statusBar()->clearMessage();
1277 return LightApp_Module::eventFilter( theObj, theEvent );
1280 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1282 LightApp_Module::onViewManagerAdded( theViewManager );
1284 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1286 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1287 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1289 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1291 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1292 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1293 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1294 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1296 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1298 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1299 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1300 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1301 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1304 createSelector( theViewManager ); // replace the default selector
1306 ViewManagerInfo anInfo( theViewManager, VMR_General );
1307 myViewManagerMap.insert( ViewManagerId++, anInfo );
1310 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1312 LightApp_Module::onViewManagerRemoved( theViewManager );
1314 createSelector( theViewManager ); // replace the default selector
1316 int anId = getViewManagerId( theViewManager );
1319 OCCViewer_ViewManager* anOCCViewManager =
1320 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1321 if ( anOCCViewManager )
1323 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1325 removeViewShapes( (size_t)anOCCViewer );
1328 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1330 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1333 getVTKDisplayer()->EraseScalarBar( anId, true );
1334 removeViewShapes( (size_t)aVTKViewer );
1338 myViewManagerMap.remove( anId );
1342 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1344 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1346 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1348 aViewFrame->installEventFilter( this );
1350 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1352 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1353 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1356 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1358 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1360 aViewFrame->onTopView();
1362 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1364 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1366 aViewPort->installEventFilter( this );
1370 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1372 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1374 aViewFrame->installEventFilter( this );
1379 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1381 /* ouv: currently unused
1382 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1384 SUIT_ViewManager* aViewManager = 0;
1386 QObject* aParent = aViewPort;
1387 while( aParent = aParent->parent() )
1389 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1391 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1393 aViewManager = aViewer->getViewManager();
1402 double aMouseX = theEvent->scenePos().x();
1403 double aMouseY = theEvent->scenePos().y();
1405 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1406 if( aRole == VMR_General )
1408 int aXDeg = 0, aYDeg = 0;
1409 int aXMin = 0, aYMin = 0;
1410 double aXSec = 0, aYSec = 0;
1411 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1412 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1414 QString aDegSymbol( QChar( 0x00B0 ) );
1415 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1416 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1418 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1420 else if( aRole == VMR_TransformImage )
1421 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1426 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1427 const bool theIsInit,
1428 const bool theIsForced,
1429 const bool theDoFitAll )
1431 QList<int> aViewManagerIdList;
1433 // currently, all views are updated
1434 ViewManagerMapIterator anIter( myViewManagerMap );
1435 while( anIter.hasNext() )
1437 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1439 if ( theDisplayer->IsApplicable( aViewManager ) )
1441 int anId = anIter.key();
1442 aViewManagerIdList.append( anId );
1446 QListIterator<int> anIdIter( aViewManagerIdList );
1447 while( anIdIter.hasNext() )
1449 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1453 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1455 if( !theViewManager )
1458 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1459 if( !aSelectionMgr )
1462 QString aViewType = theViewManager->getType();
1463 if( aViewType != GraphicsView_Viewer::Type() &&
1464 aViewType != OCCViewer_Viewer::Type())
1467 QList<SUIT_Selector*> aSelectorList;
1468 aSelectionMgr->selectors( aViewType, aSelectorList );
1470 // disable all alien selectors
1471 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1472 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1474 SUIT_Selector* aSelector = *anIter;
1475 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1476 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1477 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1478 aSelector->setEnabled( false );
1481 if ( aViewType == GraphicsView_Viewer::Type() )
1483 GraphicsView_ViewManager* aViewManager =
1484 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1486 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1488 else if ( aViewType == OCCViewer_Viewer::Type() )
1490 OCCViewer_ViewManager* aViewManager =
1491 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1493 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1497 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1499 bool aPrevState = myIsUpdateEnabled;
1500 myIsUpdateEnabled = theState;
1504 bool HYDROGUI_Module::isUpdateEnabled() const
1506 return myIsUpdateEnabled;
1509 QStringList HYDROGUI_Module::storeSelection() const
1511 QStringList anEntryList;
1512 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1514 SUIT_DataOwnerPtrList aList( true );
1515 aSelectionMgr->selected( aList );
1517 SUIT_DataOwnerPtrList::iterator anIter;
1518 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1520 const LightApp_DataOwner* anOwner =
1521 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1523 anEntryList.append( anOwner->entry() );
1529 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1531 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1533 SUIT_DataOwnerPtrList aList( true );
1534 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1535 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1536 aSelectionMgr->setSelected( aList );
1540 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1543 bool doShow = false;
1544 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1546 aDisplayer->SaveCursorViewPosition( theViewWindow );
1547 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1551 // Show the coordinates in the status bar
1552 SUIT_Desktop* aDesktop = getApp()->desktop();
1553 if ( aDesktop && aDesktop->statusBar() )
1555 gp_Pnt aWPnt( X, Y, Z );
1556 int aStudyId = application()->activeStudy()->id();
1557 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1558 double WX = aWPnt.X(), WY = aWPnt.Y();
1560 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1561 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1562 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1563 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1564 QString aMsg = tr( "COORDINATES_INFO" );
1565 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1566 aDesktop->statusBar()->showMessage( aMsg );
1572 * Returns stack of active operations;
1574 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1576 return myActiveOperationMap;
1580 * Returns the module active operation. If the active operation is show/hide,
1581 * the method returns the previous operation if it is.
1583 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1585 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1587 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1589 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1591 aVIt.previous(); // skip the top show/hide operation
1592 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;