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( RiverBottom ) )
613 theMenu->addAction( action( RiverBottom ) );
614 action( RiverBottom )->setEnabled( !isStreamHasBottom );
616 theMenu->addSeparator();
618 else if( anIsChannel )
620 theMenu->addAction( action( EditChannelId ) );
621 theMenu->addSeparator();
625 theMenu->addAction( action( EditDigueId ) );
626 theMenu->addSeparator();
628 else if( anIsObstacle )
630 theMenu->addAction( action( TranslateObstacleId ) );
631 theMenu->addSeparator();
633 else if( anIsVisualState && anIsObjectBrowser )
635 theMenu->addAction( action( SaveVisualStateId ) );
636 theMenu->addAction( action( LoadVisualStateId ) );
637 theMenu->addSeparator();
640 // Add set color action for geometrical objects
641 if ( anIsObjectCanBeColored )
643 theMenu->addAction( action( SetColorId ) );
644 theMenu->addSeparator();
646 } else if ( anAllAreProfiles ) {
647 theMenu->addAction( action( SelectedGeoreferencementId ) );
648 theMenu->addSeparator();
652 QAction* aCopyAction = action( CopyId );
653 if( aCopyAction && aCopyAction->isEnabled() ) {
654 theMenu->addAction( action( CopyId ) );
655 theMenu->addSeparator();
659 if( !anIsDummyObject3D )
660 theMenu->addAction( action( DeleteId ) );
662 theMenu->addSeparator();
664 if( anIsImage || anIsPolyline || anIsPolyline3D ||
665 anIsImmersibleZone || anIsZone || anIsRegion ||
666 anIsBathymetry || anIsObstacle || anIsStream ||
667 anIsChannel || anIsDigue || anIsDummyObject3D ||
668 anIsValidProfile || anIsGroup )
670 if( anIsHiddenInSelection )
671 theMenu->addAction( action( ShowId ) );
672 theMenu->addAction( action( ShowOnlyId ) );
673 if( anIsVisibleInSelection )
674 theMenu->addAction( action( HideId ) );
675 theMenu->addSeparator();
681 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
682 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
683 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
684 theMenu->addAction( action( DeleteId ) );
686 theMenu->addSeparator();
687 theMenu->addAction( action( SetZLevelId ) );
688 theMenu->addSeparator();
691 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
693 theMenu->addAction( action( ShowAllId ) );
694 theMenu->addAction( action( HideAllId ) );
695 theMenu->addSeparator();
698 if ( anIsOCCView || anIsVTKView )
700 theMenu->addSeparator();
701 theMenu->addAction( action( CopyViewerPositionId ) );
705 theMenu->addAction( action( EditLocalCSId ) );
708 void HYDROGUI_Module::update( const int flags )
710 if( !isUpdateEnabled() )
713 QApplication::setOverrideCursor( Qt::WaitCursor );
715 // To prevent calling this method recursively
716 // from one of the methods called below
717 setUpdateEnabled( false );
719 // store selected objects
720 QStringList aSelectedEntries = storeSelection();
722 bool aDoFitAll = flags & UF_FitAll;
723 if( ( flags & UF_Viewer ) )
724 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
726 if( ( flags & UF_OCCViewer ) )
727 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
729 if( ( flags & UF_VTKViewer ) )
730 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
732 if( ( flags & UF_Model ) && getDataModel() && getApp() )
734 getDataModel()->update( getStudyId() );
736 // Temporary workaround to prevent breaking
737 // the selection in the object browser.
738 // Note: processEvents() should be called after updateGV(),
739 // otherwise the application crashes from time to time.
740 //RKV: qApp->processEvents();
741 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
742 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
743 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
744 if ( isResizeOnExpandItem && anObjectBrowser ) {
745 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
747 getApp()->updateObjectBrowser( true );
748 if ( isResizeOnExpandItem && anObjectBrowser ) {
749 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
753 // Object browser is currently updated by using UF_Model flag
754 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
755 getApp()->updateObjectBrowser( true );
757 if( ( flags & UF_Controls ) && getApp() )
758 getApp()->updateActions();
760 // restore selected objects
761 restoreSelection( aSelectedEntries );
763 setUpdateEnabled( true );
765 QApplication::restoreOverrideCursor();
768 void HYDROGUI_Module::updateCommandsStatus()
770 LightApp_Module::updateCommandsStatus();
772 updateUndoRedoControls();
774 action( CopyId )->setEnabled( getDataModel()->canCopy() );
775 action( PasteId )->setEnabled( getDataModel()->canPaste() );
778 void HYDROGUI_Module::selectionChanged()
780 LightApp_Module::selectionChanged();
781 updateCommandsStatus();
784 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
786 return (HYDROGUI_DataModel*)dataModel();
789 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
794 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
796 return myOCCDisplayer;
799 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
801 return myVTKDisplayer;
804 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
806 if( myViewManagerMap.contains( theId ) )
808 return myViewManagerMap[ theId ].first;
813 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
815 if( myViewManagerMap.contains( theId ) )
817 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
818 GraphicsView_ViewManager* aViewManager =
819 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
821 return aViewManager->getViewer();
826 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
828 if( myViewManagerMap.contains( theId ) )
830 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
831 OCCViewer_ViewManager* aViewManager =
832 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
834 return aViewManager->getOCCViewer();
839 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
841 if( myViewManagerMap.contains( theId ) )
843 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
844 SVTK_ViewManager* aViewManager =
845 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
847 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
852 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
854 ViewManagerMapIterator anIter( myViewManagerMap );
855 while( anIter.hasNext() )
857 int anId = anIter.next().key();
858 const ViewManagerInfo& anInfo = anIter.value();
859 if( anInfo.first == theViewManager )
865 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
867 int anId = getViewManagerId( theViewManager );
870 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
871 return anInfo.second;
876 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
877 const ViewManagerRole theRole )
879 int anId = getViewManagerId( theViewManager );
882 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
883 anInfo.second = theRole;
887 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
888 const Handle(HYDROData_Entity)& theObject ) const
890 if( theObject.IsNull() )
893 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
894 if( anIter1 != myObjectStateMap.end() )
896 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
897 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
899 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
900 if( anIter2 != aEntry2ObjectStateMap.end() )
902 const ObjectState& anObjectState = anIter2.value();
903 return anObjectState.Visibility;
909 void HYDROGUI_Module::setObjectVisible( const int theViewId,
910 const Handle(HYDROData_Entity)& theObject,
911 const bool theState )
913 if( !theObject.IsNull() )
915 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
916 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
918 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
919 anObjectState.Visibility = theState;
923 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
924 const bool theState )
926 if( !theObject.IsNull() )
928 // Process OCC shapes
929 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
930 while( aShapesMapIter != myShapesMap.end() )
932 const ListOfShapes& aShapesList = aShapesMapIter.value();
933 foreach ( HYDROGUI_Shape* aShape, aShapesList )
935 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
937 aShape->setIsToUpdate( theState );
942 // Process VTK shapes
943 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
944 while( aVTKPrsMapIter != myVTKPrsMap.end() )
946 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
947 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
949 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
951 aShape->setIsToUpdate( theState );
959 /////////////////// OCC SHAPES PROCESSING
960 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
961 ObjectKind theKind ) const
963 QList<HYDROGUI_Shape*> aResult;
965 if ( myShapesMap.contains( theViewId ) )
967 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
968 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
970 if( aShape && aShape->getObject()->GetKind()==theKind )
971 aResult.append( aShape );
977 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
978 const Handle(HYDROData_Entity)& theObject ) const
980 HYDROGUI_Shape* aResShape = NULL;
981 if( theObject.IsNull() )
984 if ( myShapesMap.contains( theViewId ) )
986 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
987 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
989 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1000 void HYDROGUI_Module::setObjectShape( const int theViewId,
1001 const Handle(HYDROData_Entity)& theObject,
1002 HYDROGUI_Shape* theShape )
1004 if( theObject.IsNull() )
1007 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1008 aViewShapes.append( theShape );
1011 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1012 const Handle(HYDROData_Entity)& theObject )
1014 if ( !myShapesMap.contains( theViewId ) )
1017 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1018 Handle(HYDROData_Entity) anObject;
1019 for ( int i = 0; i < aViewShapes.length(); )
1021 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1022 anObject = aShape->getObject();
1023 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1026 aViewShapes.removeAt( i );
1034 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1036 if ( !myShapesMap.contains( theViewId ) )
1039 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1040 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1042 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1047 myShapesMap.remove( theViewId );
1049 /////////////////// END OF OCC SHAPES PROCESSING
1051 /////////////////// VTKPrs PROCESSING
1052 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1053 const Handle(HYDROData_Entity)& theObject ) const
1055 HYDROGUI_VTKPrs* aResShape = NULL;
1056 if( theObject.IsNull() )
1059 if ( myVTKPrsMap.contains( theViewId ) )
1061 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1062 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1064 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1075 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1076 const Handle(HYDROData_Entity)& theObject,
1077 HYDROGUI_VTKPrs* theShape )
1079 if( theObject.IsNull() )
1082 if( theShape && theShape->needScalarBar() )
1084 // Compute the new global Z range from the added presentation and the old global Z range.
1085 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1086 double* aRange = theShape->getInternalZRange();
1087 bool anIsUpdate = false;
1088 if ( aRange[0] < aGlobalRange[0] )
1090 aGlobalRange[0] = aRange[0];
1093 if ( aRange[1] > aGlobalRange[1] )
1095 aGlobalRange[1] = aRange[1];
1101 updateVTKZRange( theViewId, aGlobalRange );
1105 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1106 aViewShapes.append( theShape );
1109 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1110 const QString& theEntry )
1112 if ( !myVTKPrsMap.contains( theViewId ) )
1115 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1116 Handle(HYDROData_Entity) anObject;
1118 for ( int i = 0; i < aViewShapes.length(); )
1120 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1121 anObject = aShape->getObject();
1122 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1123 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1126 aViewShapes.removeAt( i );
1133 // Invalidate global Z range
1134 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1135 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1138 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1139 const Handle(HYDROData_Entity)& theObject )
1141 if ( !myVTKPrsMap.contains( theViewId ) )
1144 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1145 Handle(HYDROData_Entity) anObject;
1146 for ( int i = 0; i < aViewShapes.length(); )
1148 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1149 anObject = aShape->getObject();
1150 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1153 aViewShapes.removeAt( i );
1160 // Invalidate global Z range
1161 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1162 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1165 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1167 if ( !myVTKPrsMap.contains( theViewId ) )
1170 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1171 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1173 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1178 myVTKPrsMap.remove( theViewId );
1181 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1183 if ( myVTKPrsMap.contains( theViewId ) )
1185 // For the given viewer id update all VTK presentations ...
1186 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1187 HYDROGUI_VTKPrs* aShape;
1188 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1190 aShape = aViewShapes.at( i );
1191 if ( aShape && aShape->needScalarBar() )
1193 aShape->setZRange( theRange );
1197 // ... and update the global color legend scalar bar.
1198 getVTKDisplayer()->SetZRange( theViewId, theRange );
1200 /////////////////// END OF VTKPrs PROCESSING
1202 CAM_DataModel* HYDROGUI_Module::createDataModel()
1204 return new HYDROGUI_DataModel( this );
1207 void HYDROGUI_Module::customEvent( QEvent* e )
1209 int aType = e->type();
1210 if ( aType == NewViewEvent )
1212 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1213 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1215 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1217 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1218 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1220 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1222 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1223 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1225 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1226 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1227 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1229 //ouv: temporarily commented
1230 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1233 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1234 update( UF_Viewer );
1236 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1242 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1244 QEvent::Type aType = theEvent->type();
1245 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1247 if( aType == QEvent::Show )
1249 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1250 e->setData( theObj );
1251 QApplication::postEvent( this, e );
1252 theObj->removeEventFilter( this );
1255 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1257 if( aType == QEvent::Leave )
1259 SUIT_Desktop* aDesktop = getApp()->desktop();
1260 if ( aDesktop && aDesktop->statusBar() ) {
1261 aDesktop->statusBar()->clearMessage();
1265 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1267 if( aType == QEvent::Leave )
1269 SUIT_Desktop* aDesktop = getApp()->desktop();
1270 if ( aDesktop && aDesktop->statusBar() ) {
1271 aDesktop->statusBar()->clearMessage();
1276 return LightApp_Module::eventFilter( theObj, theEvent );
1279 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1281 LightApp_Module::onViewManagerAdded( theViewManager );
1283 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1285 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1286 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1288 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1290 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1291 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1292 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1293 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1295 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1297 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1298 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1299 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1300 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1303 createSelector( theViewManager ); // replace the default selector
1305 ViewManagerInfo anInfo( theViewManager, VMR_General );
1306 myViewManagerMap.insert( ViewManagerId++, anInfo );
1309 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1311 LightApp_Module::onViewManagerRemoved( theViewManager );
1313 createSelector( theViewManager ); // replace the default selector
1315 int anId = getViewManagerId( theViewManager );
1318 OCCViewer_ViewManager* anOCCViewManager =
1319 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1320 if ( anOCCViewManager )
1322 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1324 removeViewShapes( (size_t)anOCCViewer );
1327 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1329 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1332 getVTKDisplayer()->EraseScalarBar( anId, true );
1333 removeViewShapes( (size_t)aVTKViewer );
1337 myViewManagerMap.remove( anId );
1341 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1343 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1345 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1347 aViewFrame->installEventFilter( this );
1349 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1351 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1352 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1355 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1357 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1359 aViewFrame->onTopView();
1361 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1363 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1365 aViewPort->installEventFilter( this );
1369 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1371 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1373 aViewFrame->installEventFilter( this );
1378 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1380 /* ouv: currently unused
1381 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1383 SUIT_ViewManager* aViewManager = 0;
1385 QObject* aParent = aViewPort;
1386 while( aParent = aParent->parent() )
1388 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1390 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1392 aViewManager = aViewer->getViewManager();
1401 double aMouseX = theEvent->scenePos().x();
1402 double aMouseY = theEvent->scenePos().y();
1404 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1405 if( aRole == VMR_General )
1407 int aXDeg = 0, aYDeg = 0;
1408 int aXMin = 0, aYMin = 0;
1409 double aXSec = 0, aYSec = 0;
1410 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1411 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1413 QString aDegSymbol( QChar( 0x00B0 ) );
1414 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1415 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1417 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1419 else if( aRole == VMR_TransformImage )
1420 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1425 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1426 const bool theIsInit,
1427 const bool theIsForced,
1428 const bool theDoFitAll )
1430 QList<int> aViewManagerIdList;
1432 // currently, all views are updated
1433 ViewManagerMapIterator anIter( myViewManagerMap );
1434 while( anIter.hasNext() )
1436 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1438 if ( theDisplayer->IsApplicable( aViewManager ) )
1440 int anId = anIter.key();
1441 aViewManagerIdList.append( anId );
1445 QListIterator<int> anIdIter( aViewManagerIdList );
1446 while( anIdIter.hasNext() )
1448 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1452 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1454 if( !theViewManager )
1457 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1458 if( !aSelectionMgr )
1461 QString aViewType = theViewManager->getType();
1462 if( aViewType != GraphicsView_Viewer::Type() &&
1463 aViewType != OCCViewer_Viewer::Type())
1466 QList<SUIT_Selector*> aSelectorList;
1467 aSelectionMgr->selectors( aViewType, aSelectorList );
1469 // disable all alien selectors
1470 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1471 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1473 SUIT_Selector* aSelector = *anIter;
1474 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1475 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1476 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1477 aSelector->setEnabled( false );
1480 if ( aViewType == GraphicsView_Viewer::Type() )
1482 GraphicsView_ViewManager* aViewManager =
1483 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1485 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1487 else if ( aViewType == OCCViewer_Viewer::Type() )
1489 OCCViewer_ViewManager* aViewManager =
1490 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1492 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1496 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1498 bool aPrevState = myIsUpdateEnabled;
1499 myIsUpdateEnabled = theState;
1503 bool HYDROGUI_Module::isUpdateEnabled() const
1505 return myIsUpdateEnabled;
1508 QStringList HYDROGUI_Module::storeSelection() const
1510 QStringList anEntryList;
1511 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1513 SUIT_DataOwnerPtrList aList( true );
1514 aSelectionMgr->selected( aList );
1516 SUIT_DataOwnerPtrList::iterator anIter;
1517 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1519 const LightApp_DataOwner* anOwner =
1520 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1522 anEntryList.append( anOwner->entry() );
1528 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1530 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1532 SUIT_DataOwnerPtrList aList( true );
1533 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1534 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1535 aSelectionMgr->setSelected( aList );
1539 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1542 bool doShow = false;
1543 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1545 aDisplayer->SaveCursorViewPosition( theViewWindow );
1546 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1550 // Show the coordinates in the status bar
1551 SUIT_Desktop* aDesktop = getApp()->desktop();
1552 if ( aDesktop && aDesktop->statusBar() )
1554 gp_Pnt aWPnt( X, Y, Z );
1555 int aStudyId = application()->activeStudy()->id();
1556 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1557 double WX = aWPnt.X(), WY = aWPnt.Y();
1559 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1560 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1561 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1562 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1563 QString aMsg = tr( "COORDINATES_INFO" );
1564 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1565 aDesktop->statusBar()->showMessage( aMsg );
1571 * Returns stack of active operations;
1573 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1575 return myActiveOperationMap;
1579 * Returns the module active operation. If the active operation is show/hide,
1580 * the method returns the previous operation if it is.
1582 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1584 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1586 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1588 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1590 aVIt.previous(); // skip the top show/hide operation
1591 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;