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_DataObject.h>
79 #include <SUIT_ViewManager.h>
80 #include <SUIT_ResourceMgr.h>
81 #include <SUIT_Desktop.h>
82 #include <SUIT_Study.h>
83 #include <SUIT_Session.h>
85 #include <SVTK_ViewManager.h>
86 #include <SVTK_ViewModel.h>
87 #include <SVTK_ViewWindow.h>
88 #include <SVTK_Selector.h>
90 #include <OCCViewer_ViewPort3d.h>
92 #include <GEOMUtils.hxx>
93 #include <GeometryGUI.h>
95 #include <SALOMEDS_wrap.hxx>
98 #include <QApplication>
99 #include <QGraphicsSceneMouseEvent>
101 #include <QMouseEvent>
102 #include <QStatusBar>
105 static int ViewManagerId = 0;
107 extern "C" HYDRO_EXPORT CAM_Module* createModule()
109 return new HYDROGUI_Module();
112 extern "C" HYDRO_EXPORT char* getModuleVersion()
114 return (char*)HYDRO_VERSION;
117 HYDROGUI_Module::HYDROGUI_Module()
118 : LightApp_Module( "HYDRO" ),
121 myIsUpdateEnabled( true )
125 HYDROGUI_Module::~HYDROGUI_Module()
129 int HYDROGUI_Module::getStudyId() const
131 LightApp_Application* anApp = getApp();
132 return anApp ? anApp->activeStudy()->id() : 0;
135 void HYDROGUI_Module::initialize( CAM_Application* theApp )
137 LightApp_Module::initialize( theApp );
140 createUndoRedoActions();
145 setMenuShown( false );
146 setToolShown( false );
148 myDisplayer = new HYDROGUI_Displayer( this );
149 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
150 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
153 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
155 bool aRes = LightApp_Module::activateModule( theStudy );
157 LightApp_Application* anApp = getApp();
158 SUIT_Desktop* aDesktop = anApp->desktop();
160 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
162 setMenuShown( true );
163 setToolShown( true );
165 #ifndef DISABLE_PYCONSOLE
166 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
167 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
170 // Remove defunct view managers from the map.
171 // It's essential to do this before "update( UF_All )" call!
172 QList<int> anObsoleteIds;
173 ViewManagerList anAllViewManagers = anApp->viewManagers();
174 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
175 ViewManagerMapIterator anIter( myViewManagerMap );
176 while( anIter.hasNext() ) {
177 int anId = anIter.next().key();
178 const ViewManagerInfo& anInfo = anIter.value();
180 aHydroViewManagers << anInfo.first;
182 if ( !anAllViewManagers.contains( anInfo.first ) ) {
183 anObsoleteIds << anId;
186 foreach ( const int anId, anObsoleteIds ) {
187 myViewManagerMap.remove( anId );
188 myObjectStateMap.remove( anId );
189 myShapesMap.remove( anId );
190 myVTKPrsMap.remove( anId );
192 // Replace the default selector for all view managers.
193 // Add view managers created outside of HYDRO module to the map.
194 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
195 createSelector( aViewManager ); // replace the default selector
196 if ( !aHydroViewManagers.contains( aViewManager ) ) {
197 ViewManagerInfo anInfo( aViewManager, VMR_General );
198 myViewManagerMap.insert( ViewManagerId++, anInfo );
204 updateCommandsStatus();
206 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
208 ViewManagerList anOCCViewManagers;
209 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
210 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
211 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
212 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
213 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
214 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
215 if ( aViewFrame && aViewFrame->getViewPort() ) {
216 aViewFrame->getViewPort()->installEventFilter( this );
222 SalomeApp_Study* aStudy =
223 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
225 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
226 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
227 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
228 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
229 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
230 if( !GEOM_var->_is_nil() ) {
231 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
236 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
237 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
238 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
243 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
246 ViewManagerMapIterator anIter( myViewManagerMap );
247 while( anIter.hasNext() )
248 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
249 getApp()->removeViewManager( aViewManager );
250 myViewManagerMap.clear();
253 ViewManagerList anOCCViewManagers;
254 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
255 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
256 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
257 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
261 myObjectStateMap.clear();
266 // clear the status bar
267 SUIT_Desktop* aDesktop = getApp()->desktop();
268 if ( aDesktop && aDesktop->statusBar() ) {
269 aDesktop->statusBar()->clearMessage();
272 // clear the data model's list of copying objects
273 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
275 setMenuShown( false );
276 setToolShown( false );
278 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
280 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
282 myActiveOperationMap.clear();
283 return LightApp_Module::deactivateModule( theStudy );
286 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
289 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
290 #ifndef DISABLE_PYCONSOLE
291 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
293 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
296 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
298 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
301 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
305 HYDROGUI_DataModel* aModel = getDataModel();
307 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
308 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
309 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
310 bool anIsVTKView = theClient == SVTK_Viewer::Type();
311 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
314 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
316 bool anIsSelectedDataObjects = false;
317 bool anIsVisibleInSelection = false;
318 bool anIsHiddenInSelection = false;
320 bool anIsImage = false;
321 bool anIsImportedImage = false;
322 bool anIsImageHasRefs = false;
323 bool anIsFusedImage = false;
324 bool anIsCutImage = false;
325 bool anIsSplittedImage = false;
326 bool anIsMustObjectBeUpdated = false;
327 bool anIsPolyline = false;
328 bool anIsPolyline3D = false;
329 bool anIsProfile = false;
330 bool anIsValidProfile = false;
331 bool anAllAreProfiles = false;
332 bool anIsBathymetry = false;
333 bool anIsCalculation = false;
334 bool anIsImmersibleZone = false;
335 bool anIsVisualState = false;
336 bool anIsRegion = false;
337 bool anIsZone = false;
338 bool anIsObstacle = false;
339 bool anIsStream = false;
340 bool anIsChannel = false;
341 bool anIsDigue = false;
342 bool anIsDummyObject3D = false;
343 bool anIsGroup = false;
344 bool anIsObjectCanBeColored = false;
346 bool isStreamHasBottom = false;
348 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
349 SUIT_DataOwnerPtrList anOwners;
350 aSelectionMgr->selected( anOwners );
351 if( anIsObjectBrowser && anOwners.size()==1 )
353 QString anEntry = anOwners[0]->keyString();
354 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
356 isRoot = aStudy->isComponent( anEntry );
359 // Check the selected GEOM objects (take into account the Object Browser only)
360 if ( anIsObjectBrowser ) {
361 QList<GEOM::shape_type> anObstacleTypes =
362 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
363 QList<GEOM::shape_type> aPolylineTypes =
364 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
366 bool isCanBeImportedAsObstacle =
367 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
368 bool isCanBeImportedAsPolyline =
369 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
371 // Add import as obstacle action
372 if ( isCanBeImportedAsObstacle ) {
373 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
375 // Add import as polyline action
376 if ( isCanBeImportedAsPolyline ) {
377 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
380 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
381 theMenu->addSeparator();
385 // check the selected data model objects
386 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
387 int aNbOfSelectedProfiles = 0;
388 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
390 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
391 if( !anObject.IsNull() )
393 anIsSelectedDataObjects = true;
395 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
396 anIsVisibleInSelection |= aVisibility;
397 anIsHiddenInSelection |= !aVisibility;
399 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
401 anIsMustObjectBeUpdated = true;
404 ObjectKind anObjectKind = anObject->GetKind();
405 if( anObjectKind == KIND_IMAGE )
408 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
409 if( !anImage.IsNull() )
411 anIsImportedImage = anImage->HasLocalPoints();
412 anIsImageHasRefs = anImage->HasReferences();
413 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
415 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
417 QString anOperatorName = anOperator->name();
418 if( anOperatorName == ImageComposer_FuseOperator::Type() )
419 anIsFusedImage = true;
420 else if( anOperatorName == ImageComposer_CutOperator::Type() )
422 else if( anOperatorName == ImageComposer_CropOperator::Type() )
423 anIsSplittedImage = true;
428 else if( anObjectKind == KIND_POLYLINEXY )
430 else if( anObjectKind == KIND_POLYLINE )
431 anIsPolyline3D = true;
432 else if( anObjectKind == KIND_PROFILE )
435 aNbOfSelectedProfiles++;
437 Handle(HYDROData_Profile) aProfile =
438 Handle(HYDROData_Profile)::DownCast( anObject );
439 if( !aProfile.IsNull() && aProfile->IsValid() ) {
440 anIsValidProfile = true;
443 else if( anObjectKind == KIND_CALCULATION )
444 anIsCalculation = true;
445 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
446 anIsImmersibleZone = true;
447 else if( anObjectKind == KIND_VISUAL_STATE )
448 anIsVisualState = true;
449 else if( anObjectKind == KIND_REGION )
451 else if( anObjectKind == KIND_ZONE )
453 else if( anObjectKind == KIND_BATHYMETRY )
454 anIsBathymetry = true;
455 else if( anObjectKind == KIND_OBSTACLE )
457 else if( anObjectKind == KIND_STREAM )
460 Handle(HYDROData_Stream) aStream =
461 Handle(HYDROData_Stream)::DownCast( anObject );
462 if ( !aStream.IsNull() )
463 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
465 else if( anObjectKind == KIND_CHANNEL )
467 else if( anObjectKind == KIND_DIGUE )
469 else if( anObjectKind == KIND_DUMMY_3D )
470 anIsDummyObject3D = true;
471 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
475 if ( !anIsObjectCanBeColored )
476 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
479 // Check if all selected objects are profiles
480 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
481 ( aNbOfSelectedProfiles == aSeq.Length() );
483 // check the selected partitions
484 if( !anIsSelectedDataObjects && anIsObjectBrowser )
486 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
487 if( aSelectedPartition != KIND_UNKNOWN )
489 switch( aSelectedPartition )
492 theMenu->addAction( action( ImportImageId ) );
494 case KIND_BATHYMETRY:
495 theMenu->addAction( action( ImportBathymetryId ) );
497 case KIND_ARTIFICIAL_OBJECT:
498 theMenu->addAction( action( CreateChannelId ) );
499 theMenu->addAction( action( CreateDigueId ) );
501 case KIND_NATURAL_OBJECT:
502 theMenu->addAction( action( CreateImmersibleZoneId ) );
503 theMenu->addAction( action( CreateStreamId ) );
506 theMenu->addAction( action( ImportObstacleFromFileId ) );
507 theMenu->addAction( action( CreateBoxId ) );
508 theMenu->addAction( action( CreateCylinderId ) );
510 case KIND_CALCULATION:
511 theMenu->addAction( action( CreateCalculationId ) );
513 case KIND_POLYLINEXY:
514 theMenu->addAction( action( CreatePolylineId ) );
517 theMenu->addAction( action( CreatePolyline3DId ) );
520 theMenu->addAction( action( CreateProfileId ) );
521 theMenu->addAction( action( ImportProfilesId ) );
522 theMenu->addAction( action( AllGeoreferencementId ) );
524 case KIND_VISUAL_STATE:
525 theMenu->addAction( action( SaveVisualStateId ) );
528 theMenu->addSeparator();
532 if( anIsSelectedDataObjects )
534 if ( anIsMustObjectBeUpdated )
536 theMenu->addAction( action( UpdateObjectId ) );
537 theMenu->addSeparator();
541 theMenu->addAction( action( ForcedUpdateObjectId ) );
542 theMenu->addSeparator();
546 if( aSeq.Length() == 1 )
550 if( anIsImportedImage )
551 theMenu->addAction( action( EditImportedImageId ) );
552 else if( anIsImageHasRefs )
555 theMenu->addAction( action( EditFusedImageId ) );
556 else if( anIsCutImage )
557 theMenu->addAction( action( EditCutImageId ) );
558 else if( anIsSplittedImage )
559 theMenu->addAction( action( EditSplittedImageId ) );
562 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
563 theMenu->addAction( action( ExportImageId ) );
564 theMenu->addSeparator();
566 if( anIsImageHasRefs )
568 theMenu->addAction( action( RemoveImageRefsId ) );
569 theMenu->addSeparator();
572 theMenu->addAction( action( FuseImagesId ) );
573 theMenu->addAction( action( CutImagesId ) );
574 theMenu->addAction( action( SplitImageId ) );
575 theMenu->addSeparator();
577 else if( anIsBathymetry )
579 theMenu->addAction( action( EditImportedBathymetryId ) );
580 theMenu->addAction( action( BathymetryBoundsId ) );
581 theMenu->addSeparator();
583 else if( anIsPolyline )
585 theMenu->addAction( action( EditPolylineId ) );
586 theMenu->addSeparator();
588 else if( anIsPolyline3D )
590 theMenu->addAction( action( EditPolyline3DId ) );
591 theMenu->addSeparator();
593 else if( anIsProfile )
595 theMenu->addAction( action( EditProfileId ) );
596 theMenu->addAction( action( SelectedGeoreferencementId ) );
597 theMenu->addSeparator();
599 else if( anIsCalculation )
601 theMenu->addAction( action( EditCalculationId ) );
602 theMenu->addAction( action( ExportCalculationId ) );
603 theMenu->addSeparator();
605 else if( anIsImmersibleZone )
607 theMenu->addAction( action( EditImmersibleZoneId ) );
608 theMenu->addSeparator();
610 else if( anIsStream )
612 theMenu->addAction( action( EditStreamId ) );
613 if ( action( RiverBottomContextId ) )
615 theMenu->addAction( action( RiverBottomContextId ) );
616 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
618 theMenu->addAction( action( ProfileInterpolateId ) );
619 theMenu->addSeparator();
621 else if( anIsChannel )
623 theMenu->addAction( action( EditChannelId ) );
624 theMenu->addSeparator();
628 theMenu->addAction( action( EditDigueId ) );
629 theMenu->addSeparator();
631 else if( anIsObstacle )
633 theMenu->addAction( action( TranslateObstacleId ) );
634 theMenu->addSeparator();
636 else if( anIsVisualState && anIsObjectBrowser )
638 theMenu->addAction( action( SaveVisualStateId ) );
639 theMenu->addAction( action( LoadVisualStateId ) );
640 theMenu->addSeparator();
643 // Add set color action for geometrical objects
644 if ( anIsObjectCanBeColored )
646 theMenu->addAction( action( SetColorId ) );
647 theMenu->addSeparator();
649 } else if ( anAllAreProfiles ) {
650 theMenu->addAction( action( SelectedGeoreferencementId ) );
651 theMenu->addSeparator();
654 if (anIsPolyline || anIsPolyline3D)
655 theMenu->addAction( action( ExportPolylineId ) );
658 QAction* aCopyAction = action( CopyId );
659 if( aCopyAction && aCopyAction->isEnabled() ) {
660 theMenu->addAction( action( CopyId ) );
661 theMenu->addSeparator();
665 if( !anIsDummyObject3D )
666 theMenu->addAction( action( DeleteId ) );
668 theMenu->addSeparator();
670 if( anIsImage || anIsPolyline || anIsPolyline3D ||
671 anIsImmersibleZone || anIsZone || anIsRegion ||
672 anIsBathymetry || anIsObstacle || anIsStream ||
673 anIsChannel || anIsDigue || anIsDummyObject3D ||
674 anIsValidProfile || anIsGroup )
676 if( anIsHiddenInSelection )
677 theMenu->addAction( action( ShowId ) );
678 theMenu->addAction( action( ShowOnlyId ) );
679 if( anIsVisibleInSelection )
680 theMenu->addAction( action( HideId ) );
681 theMenu->addSeparator();
687 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
688 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
689 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
690 theMenu->addAction( action( DeleteId ) );
692 theMenu->addSeparator();
693 theMenu->addAction( action( SetZLevelId ) );
694 theMenu->addSeparator();
697 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
699 theMenu->addAction( action( ShowAllId ) );
700 theMenu->addAction( action( HideAllId ) );
701 theMenu->addSeparator();
704 if ( anIsOCCView || anIsVTKView )
706 theMenu->addSeparator();
707 theMenu->addAction( action( CopyViewerPositionId ) );
711 theMenu->addAction( action( EditLocalCSId ) );
713 if( anIsObjectBrowser && anOwners.size()==1 )
715 if( aSeq.Size() > 0 )
717 Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
718 if( !anObject.IsNull() )
720 theMenu->addSeparator();
721 theMenu->addAction( action( SubmersibleId ) );
722 action( SubmersibleId )->setCheckable( true );
723 action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
729 void HYDROGUI_Module::createPreferences()
731 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
732 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
734 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
735 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
737 // Set property cursor type
738 QList<QVariant> aCursorTypeIndicesList;
739 QList<QVariant> aCursorTypeIconsList;
741 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
742 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
743 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
744 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
745 aCursorTypeIndicesList << i;
746 aCursorTypeIconsList << pixmap;
749 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
750 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
752 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
753 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
754 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
757 QCursor HYDROGUI_Module::getPrefEditCursor() const
759 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
760 if ( aCursorType >= Qt::BlankCursor)
762 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
766 void HYDROGUI_Module::update( const int flags )
768 if ( !isUpdateEnabled() )
771 QApplication::setOverrideCursor( Qt::WaitCursor );
773 // To prevent calling this method recursively
774 // from one of the methods called below
775 setUpdateEnabled( false );
777 // store selected objects
778 QStringList aSelectedEntries = storeSelection();
780 bool aDoFitAll = flags & UF_FitAll;
783 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
784 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
787 if( ( flags & UF_Viewer ) )
788 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
790 if( ( flags & UF_OCCViewer ) )
791 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
793 if( ( flags & UF_VTKViewer ) )
794 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
796 if( ( flags & UF_Model ) && getDataModel() && getApp() )
798 getDataModel()->update( getStudyId() );
800 // Temporary workaround to prevent breaking
801 // the selection in the object browser.
802 // Note: processEvents() should be called after updateGV(),
803 // otherwise the application crashes from time to time.
804 //RKV: qApp->processEvents();
805 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
806 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
807 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
808 if ( isResizeOnExpandItem && anObjectBrowser ) {
809 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
811 getApp()->updateObjectBrowser( true );
812 if ( isResizeOnExpandItem && anObjectBrowser ) {
813 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
817 // Object browser is currently updated by using UF_Model flag
818 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
819 getApp()->updateObjectBrowser( true );
821 if( ( flags & UF_Controls ) && getApp() )
822 getApp()->updateActions();
824 // restore selected objects
825 restoreSelection( aSelectedEntries );
827 setUpdateEnabled( true );
829 QApplication::restoreOverrideCursor();
832 void HYDROGUI_Module::updateCommandsStatus()
834 LightApp_Module::updateCommandsStatus();
836 updateUndoRedoControls();
838 action( CopyId )->setEnabled( getDataModel()->canCopy() );
839 action( PasteId )->setEnabled( getDataModel()->canPaste() );
842 void HYDROGUI_Module::selectionChanged()
844 LightApp_Module::selectionChanged();
845 updateCommandsStatus();
848 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
850 return (HYDROGUI_DataModel*)dataModel();
853 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
858 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
860 return myOCCDisplayer;
863 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
865 return myVTKDisplayer;
868 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
870 if( myViewManagerMap.contains( theId ) )
872 return myViewManagerMap[ theId ].first;
877 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
879 if( myViewManagerMap.contains( theId ) )
881 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
882 GraphicsView_ViewManager* aViewManager =
883 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
885 return aViewManager->getViewer();
890 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
892 if( myViewManagerMap.contains( theId ) )
894 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
895 OCCViewer_ViewManager* aViewManager =
896 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
898 return aViewManager->getOCCViewer();
903 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
905 if( myViewManagerMap.contains( theId ) )
907 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
908 SVTK_ViewManager* aViewManager =
909 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
911 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
916 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
918 ViewManagerMapIterator anIter( myViewManagerMap );
919 while( anIter.hasNext() )
921 int anId = anIter.next().key();
922 const ViewManagerInfo& anInfo = anIter.value();
923 if( anInfo.first == theViewManager )
929 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
931 int anId = getViewManagerId( theViewManager );
934 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
935 return anInfo.second;
940 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
941 const ViewManagerRole theRole )
943 int anId = getViewManagerId( theViewManager );
946 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
947 anInfo.second = theRole;
951 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
952 const Handle(HYDROData_Entity)& theObject ) const
954 if( theObject.IsNull() )
960 foreach( int aViewId, myObjectStateMap.keys() )
962 if( isObjectVisible( aViewId, theObject ) )
968 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
969 if( anIter1 != myObjectStateMap.end() )
971 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
972 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
974 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
975 if( anIter2 != aEntry2ObjectStateMap.end() )
977 const ObjectState& anObjectState = anIter2.value();
978 return anObjectState.Visibility;
984 void HYDROGUI_Module::setObjectVisible( const int theViewId,
985 const Handle(HYDROData_Entity)& theObject,
986 const bool theState )
988 if( !theObject.IsNull() )
990 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
991 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
993 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
994 anObjectState.Visibility = theState;
996 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
999 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1000 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1001 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1002 if ( visState != Qtx::UnpresentableState )
1003 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1008 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1009 const bool theState )
1011 if( !theObject.IsNull() )
1013 // Process OCC shapes
1014 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1015 while( aShapesMapIter != myShapesMap.end() )
1017 const ListOfShapes& aShapesList = aShapesMapIter.value();
1018 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1020 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1022 aShape->setIsToUpdate( theState );
1027 // Process VTK shapes
1028 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1029 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1031 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1032 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1034 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1036 aShape->setIsToUpdate( theState );
1044 /////////////////// OCC SHAPES PROCESSING
1045 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1046 ObjectKind theKind ) const
1048 QList<HYDROGUI_Shape*> aResult;
1050 if ( myShapesMap.contains( theViewId ) )
1052 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1053 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1055 if( aShape && aShape->getObject()->GetKind()==theKind )
1056 aResult.append( aShape );
1062 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1063 const Handle(HYDROData_Entity)& theObject ) const
1065 HYDROGUI_Shape* aResShape = NULL;
1066 if( theObject.IsNull() )
1069 if ( myShapesMap.contains( theViewId ) )
1071 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1072 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1074 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1085 void HYDROGUI_Module::setObjectShape( const int theViewId,
1086 const Handle(HYDROData_Entity)& theObject,
1087 HYDROGUI_Shape* theShape )
1089 if( theObject.IsNull() )
1092 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1093 aViewShapes.append( theShape );
1096 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1097 const Handle(HYDROData_Entity)& theObject )
1099 if ( !myShapesMap.contains( theViewId ) )
1102 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1103 Handle(HYDROData_Entity) anObject;
1104 for ( int i = 0; i < aViewShapes.length(); )
1106 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1107 anObject = aShape->getObject();
1108 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1111 aViewShapes.removeAt( i );
1119 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1121 if ( !myShapesMap.contains( theViewId ) )
1124 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1125 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1127 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1132 myShapesMap.remove( theViewId );
1134 /////////////////// END OF OCC SHAPES PROCESSING
1136 /////////////////// VTKPrs PROCESSING
1137 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1138 const Handle(HYDROData_Entity)& theObject ) const
1140 HYDROGUI_VTKPrs* aResShape = NULL;
1141 if( theObject.IsNull() )
1144 if ( myVTKPrsMap.contains( theViewId ) )
1146 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1147 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1149 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1160 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1161 const Handle(HYDROData_Entity)& theObject,
1162 HYDROGUI_VTKPrs* theShape )
1164 if( theObject.IsNull() )
1167 if( theShape && theShape->needScalarBar() )
1169 // Compute the new global Z range from the added presentation and the old global Z range.
1170 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1171 double* aRange = theShape->getInternalZRange();
1172 bool anIsUpdate = false;
1173 if ( aRange[0] < aGlobalRange[0] )
1175 aGlobalRange[0] = aRange[0];
1178 if ( aRange[1] > aGlobalRange[1] )
1180 aGlobalRange[1] = aRange[1];
1186 updateVTKZRange( theViewId, aGlobalRange );
1190 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1191 aViewShapes.append( theShape );
1194 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1195 const QString& theEntry )
1197 if ( !myVTKPrsMap.contains( theViewId ) )
1200 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1201 Handle(HYDROData_Entity) anObject;
1203 for ( int i = 0; i < aViewShapes.length(); )
1205 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1206 anObject = aShape->getObject();
1207 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1208 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1211 aViewShapes.removeAt( i );
1218 // Invalidate global Z range
1219 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1220 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1223 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1224 const Handle(HYDROData_Entity)& theObject )
1226 if ( !myVTKPrsMap.contains( theViewId ) )
1229 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1230 Handle(HYDROData_Entity) anObject;
1231 for ( int i = 0; i < aViewShapes.length(); )
1233 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1234 anObject = aShape->getObject();
1235 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1238 aViewShapes.removeAt( i );
1245 // Invalidate global Z range
1246 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1247 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1250 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1252 if ( !myVTKPrsMap.contains( theViewId ) )
1255 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1256 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1258 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1263 myVTKPrsMap.remove( theViewId );
1266 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1268 if ( myVTKPrsMap.contains( theViewId ) )
1270 // For the given viewer id update all VTK presentations ...
1271 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1272 HYDROGUI_VTKPrs* aShape;
1273 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1275 aShape = aViewShapes.at( i );
1276 if ( aShape && aShape->needScalarBar() )
1278 aShape->setZRange( theRange );
1282 // ... and update the global color legend scalar bar.
1283 getVTKDisplayer()->SetZRange( theViewId, theRange );
1285 /////////////////// END OF VTKPrs PROCESSING
1287 CAM_DataModel* HYDROGUI_Module::createDataModel()
1289 return new HYDROGUI_DataModel( this );
1292 void HYDROGUI_Module::customEvent( QEvent* e )
1294 int aType = e->type();
1295 if ( aType == NewViewEvent )
1297 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1298 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1300 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1302 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1303 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1305 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1307 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1308 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1310 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1311 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1312 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1314 //ouv: temporarily commented
1315 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1318 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1319 update( UF_Viewer );
1321 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1327 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1329 QEvent::Type aType = theEvent->type();
1330 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1332 if( aType == QEvent::Show )
1334 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1335 e->setData( theObj );
1336 QApplication::postEvent( this, e );
1337 theObj->removeEventFilter( this );
1340 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1342 if( aType == QEvent::Leave )
1344 SUIT_Desktop* aDesktop = getApp()->desktop();
1345 if ( aDesktop && aDesktop->statusBar() ) {
1346 aDesktop->statusBar()->clearMessage();
1350 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1352 if( aType == QEvent::Leave )
1354 SUIT_Desktop* aDesktop = getApp()->desktop();
1355 if ( aDesktop && aDesktop->statusBar() ) {
1356 aDesktop->statusBar()->clearMessage();
1361 return LightApp_Module::eventFilter( theObj, theEvent );
1364 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1366 LightApp_Module::onViewManagerAdded( theViewManager );
1368 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1370 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1371 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1373 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1375 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1376 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1377 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1378 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1380 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1382 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1383 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1384 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1385 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1388 createSelector( theViewManager ); // replace the default selector
1390 ViewManagerInfo anInfo( theViewManager, VMR_General );
1391 myViewManagerMap.insert( ViewManagerId++, anInfo );
1394 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1396 LightApp_Module::onViewManagerRemoved( theViewManager );
1398 createSelector( theViewManager ); // replace the default selector
1400 int anId = getViewManagerId( theViewManager );
1403 OCCViewer_ViewManager* anOCCViewManager =
1404 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1405 if ( anOCCViewManager )
1407 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1409 removeViewShapes( (size_t)anOCCViewer );
1412 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1414 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1417 getVTKDisplayer()->EraseScalarBar( anId, true );
1418 removeViewShapes( (size_t)aVTKViewer );
1422 myViewManagerMap.remove( anId );
1426 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1428 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1430 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1432 aViewFrame->installEventFilter( this );
1434 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1436 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1437 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1440 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1442 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1444 aViewFrame->onTopView();
1446 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1448 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1450 aViewPort->installEventFilter( this );
1454 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1456 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1458 aViewFrame->installEventFilter( this );
1463 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1465 /* ouv: currently unused
1466 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1468 SUIT_ViewManager* aViewManager = 0;
1470 QObject* aParent = aViewPort;
1471 while( aParent = aParent->parent() )
1473 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1475 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1477 aViewManager = aViewer->getViewManager();
1486 double aMouseX = theEvent->scenePos().x();
1487 double aMouseY = theEvent->scenePos().y();
1489 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1490 if( aRole == VMR_General )
1492 int aXDeg = 0, aYDeg = 0;
1493 int aXMin = 0, aYMin = 0;
1494 double aXSec = 0, aYSec = 0;
1495 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1496 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1498 QString aDegSymbol( QChar( 0x00B0 ) );
1499 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1500 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1502 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1504 else if( aRole == VMR_TransformImage )
1505 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1510 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1511 const bool theIsInit,
1512 const bool theIsForced,
1513 const bool theDoFitAll )
1515 QList<int> aViewManagerIdList;
1517 // currently, all views are updated
1518 ViewManagerMapIterator anIter( myViewManagerMap );
1519 while( anIter.hasNext() )
1521 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1523 if ( theDisplayer->IsApplicable( aViewManager ) )
1525 int anId = anIter.key();
1526 aViewManagerIdList.append( anId );
1530 QListIterator<int> anIdIter( aViewManagerIdList );
1531 while( anIdIter.hasNext() )
1533 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1537 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1539 if( !theViewManager )
1542 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1543 if( !aSelectionMgr )
1546 QString aViewType = theViewManager->getType();
1547 if( aViewType != GraphicsView_Viewer::Type() &&
1548 aViewType != OCCViewer_Viewer::Type())
1551 QList<SUIT_Selector*> aSelectorList;
1552 aSelectionMgr->selectors( aViewType, aSelectorList );
1554 // disable all alien selectors
1555 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1556 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1558 SUIT_Selector* aSelector = *anIter;
1559 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1560 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1561 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1562 aSelector->setEnabled( false );
1565 if ( aViewType == GraphicsView_Viewer::Type() )
1567 GraphicsView_ViewManager* aViewManager =
1568 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1570 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1572 else if ( aViewType == OCCViewer_Viewer::Type() )
1574 OCCViewer_ViewManager* aViewManager =
1575 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1577 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1581 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1583 bool aPrevState = myIsUpdateEnabled;
1584 myIsUpdateEnabled = theState;
1588 bool HYDROGUI_Module::isUpdateEnabled() const
1590 return myIsUpdateEnabled;
1593 QStringList HYDROGUI_Module::storeSelection() const
1595 QStringList anEntryList;
1596 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1598 SUIT_DataOwnerPtrList aList( true );
1599 aSelectionMgr->selected( aList );
1601 SUIT_DataOwnerPtrList::iterator anIter;
1602 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1604 const LightApp_DataOwner* anOwner =
1605 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1607 anEntryList.append( anOwner->entry() );
1613 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1615 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1617 SUIT_DataOwnerPtrList aList( true );
1618 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1619 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1620 aSelectionMgr->setSelected( aList );
1624 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1627 bool doShow = false;
1628 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1630 aDisplayer->SaveCursorViewPosition( theViewWindow );
1631 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1635 // Show the coordinates in the status bar
1636 SUIT_Desktop* aDesktop = getApp()->desktop();
1637 if ( aDesktop && aDesktop->statusBar() )
1639 gp_Pnt aWPnt( X, Y, Z );
1640 int aStudyId = application()->activeStudy()->id();
1641 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1642 double WX = aWPnt.X(), WY = aWPnt.Y();
1644 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1645 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1646 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1647 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1648 QString aMsg = tr( "COORDINATES_INFO" );
1649 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1650 aDesktop->statusBar()->showMessage( aMsg );
1656 * Returns stack of active operations;
1658 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1660 return myActiveOperationMap;
1664 * Returns the module active operation. If the active operation is show/hide,
1665 * the method returns the previous operation if it is.
1667 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1669 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1671 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1673 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1675 aVIt.previous(); // skip the top show/hide operation
1676 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1683 * \brief Virtual public slot
1685 * This method is called after the object inserted into data view to update their visibility state
1686 * This is default implementation
1688 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1690 if ( !isActiveModule() )
1693 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1695 // change visibility of object
1696 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1699 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1701 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1702 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1703 if ( visState == Qtx::UnpresentableState )
1706 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1707 treeModel->setVisibilityState( id, visState );
1709 bool vis = visState == Qtx::ShownState;
1710 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1713 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1715 update( UF_OCCViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );