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_DataObject.h>
83 #include <SUIT_ViewManager.h>
84 #include <SUIT_ResourceMgr.h>
85 #include <SUIT_Desktop.h>
86 #include <SUIT_Study.h>
87 #include <SUIT_Session.h>
89 #include <SVTK_ViewManager.h>
90 #include <SVTK_ViewModel.h>
91 #include <SVTK_ViewWindow.h>
92 #include <SVTK_Selector.h>
94 #include <OCCViewer_ViewPort3d.h>
96 #include <GEOMUtils.hxx>
97 #include <GeometryGUI.h>
99 #include <SALOMEDS_wrap.hxx>
102 #include <QApplication>
103 #include <QGraphicsSceneMouseEvent>
105 #include <QMouseEvent>
106 #include <QStatusBar>
109 static int ViewManagerId = 0;
111 extern "C" HYDRO_EXPORT CAM_Module* createModule()
113 return new HYDROGUI_Module();
116 extern "C" HYDRO_EXPORT char* getModuleVersion()
118 return (char*)HYDRO_VERSION;
121 HYDROGUI_Module::HYDROGUI_Module()
122 : LightApp_Module( "HYDRO" ),
125 myIsUpdateEnabled( true )
129 HYDROGUI_Module::~HYDROGUI_Module()
133 int HYDROGUI_Module::getStudyId() const
135 LightApp_Application* anApp = getApp();
136 return anApp ? anApp->activeStudy()->id() : 0;
139 void HYDROGUI_Module::initialize( CAM_Application* theApp )
141 LightApp_Module::initialize( theApp );
144 createUndoRedoActions();
149 setMenuShown( false );
150 setToolShown( false );
152 myDisplayer = new HYDROGUI_Displayer( this );
153 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
154 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
157 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
159 bool aRes = LightApp_Module::activateModule( theStudy );
161 LightApp_Application* anApp = getApp();
162 SUIT_Desktop* aDesktop = anApp->desktop();
164 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
166 setMenuShown( true );
167 setToolShown( true );
169 #ifndef DISABLE_PYCONSOLE
170 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
171 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
174 // Remove defunct view managers from the map.
175 // It's essential to do this before "update( UF_All )" call!
176 QList<int> anObsoleteIds;
177 ViewManagerList anAllViewManagers = anApp->viewManagers();
178 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
179 ViewManagerMapIterator anIter( myViewManagerMap );
180 while( anIter.hasNext() ) {
181 int anId = anIter.next().key();
182 const ViewManagerInfo& anInfo = anIter.value();
184 aHydroViewManagers << anInfo.first;
186 if ( !anAllViewManagers.contains( anInfo.first ) ) {
187 anObsoleteIds << anId;
190 foreach ( const int anId, anObsoleteIds ) {
191 myViewManagerMap.remove( anId );
192 myObjectStateMap.remove( anId );
193 myShapesMap.remove( anId );
194 myVTKPrsMap.remove( anId );
196 // Replace the default selector for all view managers.
197 // Add view managers created outside of HYDRO module to the map.
198 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
199 createSelector( aViewManager ); // replace the default selector
200 if ( !aHydroViewManagers.contains( aViewManager ) ) {
201 ViewManagerInfo anInfo( aViewManager, VMR_General );
202 myViewManagerMap.insert( ViewManagerId++, anInfo );
208 updateCommandsStatus();
210 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
212 ViewManagerList anOCCViewManagers;
213 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
214 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
215 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
216 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
217 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
218 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
219 if ( aViewFrame && aViewFrame->getViewPort() ) {
220 aViewFrame->getViewPort()->installEventFilter( this );
226 SalomeApp_Study* aStudy =
227 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
229 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
230 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
231 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
232 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
233 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
234 if( !GEOM_var->_is_nil() ) {
235 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
240 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
241 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
242 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
247 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
250 ViewManagerMapIterator anIter( myViewManagerMap );
251 while( anIter.hasNext() )
252 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
253 getApp()->removeViewManager( aViewManager );
254 myViewManagerMap.clear();
257 ViewManagerList anOCCViewManagers;
258 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
259 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
260 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
261 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
265 myObjectStateMap.clear();
270 // clear the status bar
271 SUIT_Desktop* aDesktop = getApp()->desktop();
272 if ( aDesktop && aDesktop->statusBar() ) {
273 aDesktop->statusBar()->clearMessage();
276 // clear the data model's list of copying objects
277 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
279 setMenuShown( false );
280 setToolShown( false );
282 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
284 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
286 myActiveOperationMap.clear();
287 return LightApp_Module::deactivateModule( theStudy );
290 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
293 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
294 #ifndef DISABLE_PYCONSOLE
295 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
297 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
300 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
302 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
305 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
309 HYDROGUI_DataModel* aModel = getDataModel();
311 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
312 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
313 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
314 bool anIsVTKView = theClient == SVTK_Viewer::Type();
315 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
318 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
320 bool anIsSelectedDataObjects = false;
321 bool anIsVisibleInSelection = false;
322 bool anIsHiddenInSelection = false;
324 bool anIsImage = false;
325 bool anIsImportedImage = false;
326 bool anIsImageHasRefs = false;
327 bool anIsFusedImage = false;
328 bool anIsCutImage = false;
329 bool anIsSplittedImage = false;
330 bool anIsMustObjectBeUpdated = false;
331 bool anIsPolyline = false;
332 bool anIsPolyline3D = false;
333 bool anIsProfile = false;
334 bool anIsValidProfile = false;
335 bool anAllAreProfiles = false;
336 bool anIsBathymetry = false;
337 bool anIsCalculation = false;
338 bool anIsImmersibleZone = false;
339 bool anIsVisualState = false;
340 bool anIsRegion = false;
341 bool anIsZone = false;
342 bool anIsObstacle = false;
343 bool anIsStream = false;
344 bool anIsChannel = false;
345 bool anIsDigue = false;
346 bool anIsDummyObject3D = false;
347 bool anIsGroup = false;
348 bool anIsObjectCanBeColored = false;
350 bool isStreamHasBottom = false;
352 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
353 SUIT_DataOwnerPtrList anOwners;
354 aSelectionMgr->selected( anOwners );
355 if( anIsObjectBrowser && anOwners.size()==1 )
357 QString anEntry = anOwners[0]->keyString();
358 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
360 isRoot = aStudy->isComponent( anEntry );
363 // Check the selected GEOM objects (take into account the Object Browser only)
364 if ( anIsObjectBrowser ) {
365 QList<GEOM::shape_type> anObstacleTypes =
366 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
367 QList<GEOM::shape_type> aPolylineTypes =
368 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
370 bool isCanBeImportedAsObstacle =
371 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
372 bool isCanBeImportedAsPolyline =
373 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
375 // Add import as obstacle action
376 if ( isCanBeImportedAsObstacle ) {
377 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
379 // Add import as polyline action
380 if ( isCanBeImportedAsPolyline ) {
381 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
384 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
385 theMenu->addSeparator();
389 // check the selected data model objects
390 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
391 int aNbOfSelectedProfiles = 0;
392 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
394 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
395 if( !anObject.IsNull() )
397 anIsSelectedDataObjects = true;
399 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
400 anIsVisibleInSelection |= aVisibility;
401 anIsHiddenInSelection |= !aVisibility;
403 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
405 anIsMustObjectBeUpdated = true;
408 ObjectKind anObjectKind = anObject->GetKind();
409 if( anObjectKind == KIND_IMAGE )
412 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
413 if( !anImage.IsNull() )
415 anIsImportedImage = anImage->HasLocalPoints();
416 anIsImageHasRefs = anImage->HasReferences();
417 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
419 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
421 QString anOperatorName = anOperator->name();
422 if( anOperatorName == ImageComposer_FuseOperator::Type() )
423 anIsFusedImage = true;
424 else if( anOperatorName == ImageComposer_CutOperator::Type() )
426 else if( anOperatorName == ImageComposer_CropOperator::Type() )
427 anIsSplittedImage = true;
432 else if( anObjectKind == KIND_POLYLINEXY )
434 else if( anObjectKind == KIND_POLYLINE )
435 anIsPolyline3D = true;
436 else if( anObjectKind == KIND_PROFILE )
439 aNbOfSelectedProfiles++;
441 Handle(HYDROData_Profile) aProfile =
442 Handle(HYDROData_Profile)::DownCast( anObject );
443 if( !aProfile.IsNull() && aProfile->IsValid() ) {
444 anIsValidProfile = true;
447 else if( anObjectKind == KIND_CALCULATION )
448 anIsCalculation = true;
449 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
450 anIsImmersibleZone = true;
451 else if( anObjectKind == KIND_VISUAL_STATE )
452 anIsVisualState = true;
453 else if( anObjectKind == KIND_REGION )
455 else if( anObjectKind == KIND_ZONE )
457 else if( anObjectKind == KIND_BATHYMETRY )
458 anIsBathymetry = true;
459 else if( anObjectKind == KIND_OBSTACLE )
461 else if( anObjectKind == KIND_STREAM )
464 Handle(HYDROData_Stream) aStream =
465 Handle(HYDROData_Stream)::DownCast( anObject );
466 if ( !aStream.IsNull() )
467 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
469 else if( anObjectKind == KIND_CHANNEL )
471 else if( anObjectKind == KIND_DIGUE )
473 else if( anObjectKind == KIND_DUMMY_3D )
474 anIsDummyObject3D = true;
475 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
479 if ( !anIsObjectCanBeColored )
480 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
483 // Check if all selected objects are profiles
484 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
485 ( aNbOfSelectedProfiles == aSeq.Length() );
487 // check the selected partitions
488 if( !anIsSelectedDataObjects && anIsObjectBrowser )
490 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
491 if( aSelectedPartition != KIND_UNKNOWN )
493 switch( aSelectedPartition )
496 theMenu->addAction( action( ImportImageId ) );
498 case KIND_BATHYMETRY:
499 theMenu->addAction( action( ImportBathymetryId ) );
501 case KIND_ARTIFICIAL_OBJECT:
502 theMenu->addAction( action( CreateChannelId ) );
503 theMenu->addAction( action( CreateDigueId ) );
505 case KIND_NATURAL_OBJECT:
506 theMenu->addAction( action( CreateImmersibleZoneId ) );
507 theMenu->addAction( action( CreateStreamId ) );
510 theMenu->addAction( action( ImportObstacleFromFileId ) );
511 theMenu->addAction( action( CreateBoxId ) );
512 theMenu->addAction( action( CreateCylinderId ) );
514 case KIND_CALCULATION:
515 theMenu->addAction( action( CreateCalculationId ) );
517 case KIND_POLYLINEXY:
518 theMenu->addAction( action( CreatePolylineId ) );
521 theMenu->addAction( action( CreatePolyline3DId ) );
524 theMenu->addAction( action( CreateProfileId ) );
525 theMenu->addAction( action( ImportProfilesId ) );
526 theMenu->addAction( action( AllGeoreferencementId ) );
528 case KIND_VISUAL_STATE:
529 theMenu->addAction( action( SaveVisualStateId ) );
532 theMenu->addSeparator();
536 if( anIsSelectedDataObjects )
538 if ( anIsMustObjectBeUpdated )
540 theMenu->addAction( action( UpdateObjectId ) );
541 theMenu->addSeparator();
545 theMenu->addAction( action( ForcedUpdateObjectId ) );
546 theMenu->addSeparator();
550 if( aSeq.Length() == 1 )
554 if( anIsImportedImage )
555 theMenu->addAction( action( EditImportedImageId ) );
556 else if( anIsImageHasRefs )
559 theMenu->addAction( action( EditFusedImageId ) );
560 else if( anIsCutImage )
561 theMenu->addAction( action( EditCutImageId ) );
562 else if( anIsSplittedImage )
563 theMenu->addAction( action( EditSplittedImageId ) );
566 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
567 theMenu->addAction( action( ExportImageId ) );
568 theMenu->addSeparator();
570 if( anIsImageHasRefs )
572 theMenu->addAction( action( RemoveImageRefsId ) );
573 theMenu->addSeparator();
576 theMenu->addAction( action( FuseImagesId ) );
577 theMenu->addAction( action( CutImagesId ) );
578 theMenu->addAction( action( SplitImageId ) );
579 theMenu->addSeparator();
581 else if( anIsBathymetry )
583 theMenu->addAction( action( EditImportedBathymetryId ) );
584 theMenu->addAction( action( BathymetryBoundsId ) );
585 theMenu->addSeparator();
587 else if( anIsPolyline )
589 theMenu->addAction( action( EditPolylineId ) );
590 theMenu->addSeparator();
592 else if( anIsPolyline3D )
594 theMenu->addAction( action( EditPolyline3DId ) );
595 theMenu->addSeparator();
597 else if( anIsProfile )
599 theMenu->addAction( action( EditProfileId ) );
600 theMenu->addAction( action( SelectedGeoreferencementId ) );
601 theMenu->addSeparator();
603 else if( anIsCalculation )
605 theMenu->addAction( action( EditCalculationId ) );
606 theMenu->addAction( action( ExportCalculationId ) );
607 theMenu->addSeparator();
609 else if( anIsImmersibleZone )
611 theMenu->addAction( action( EditImmersibleZoneId ) );
612 theMenu->addSeparator();
614 else if( anIsStream )
616 theMenu->addAction( action( EditStreamId ) );
617 if ( action( RiverBottomContextId ) )
619 theMenu->addAction( action( RiverBottomContextId ) );
620 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
622 theMenu->addAction( action( ProfileInterpolateId ) );
623 theMenu->addSeparator();
625 else if( anIsChannel )
627 theMenu->addAction( action( EditChannelId ) );
628 theMenu->addSeparator();
632 theMenu->addAction( action( EditDigueId ) );
633 theMenu->addSeparator();
635 else if( anIsObstacle )
637 theMenu->addAction( action( TranslateObstacleId ) );
638 theMenu->addSeparator();
640 else if( anIsVisualState && anIsObjectBrowser )
642 theMenu->addAction( action( SaveVisualStateId ) );
643 theMenu->addAction( action( LoadVisualStateId ) );
644 theMenu->addSeparator();
647 // Add set color action for geometrical objects
648 if ( anIsObjectCanBeColored )
650 theMenu->addAction( action( SetColorId ) );
651 theMenu->addSeparator();
653 } else if ( anAllAreProfiles ) {
654 theMenu->addAction( action( SelectedGeoreferencementId ) );
655 theMenu->addSeparator();
659 QAction* aCopyAction = action( CopyId );
660 if( aCopyAction && aCopyAction->isEnabled() ) {
661 theMenu->addAction( action( CopyId ) );
662 theMenu->addSeparator();
666 if( !anIsDummyObject3D )
667 theMenu->addAction( action( DeleteId ) );
669 theMenu->addSeparator();
671 if( anIsImage || anIsPolyline || anIsPolyline3D ||
672 anIsImmersibleZone || anIsZone || anIsRegion ||
673 anIsBathymetry || anIsObstacle || anIsStream ||
674 anIsChannel || anIsDigue || anIsDummyObject3D ||
675 anIsValidProfile || anIsGroup )
677 if( anIsHiddenInSelection )
678 theMenu->addAction( action( ShowId ) );
679 theMenu->addAction( action( ShowOnlyId ) );
680 if( anIsVisibleInSelection )
681 theMenu->addAction( action( HideId ) );
682 theMenu->addSeparator();
688 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
689 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
690 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
691 theMenu->addAction( action( DeleteId ) );
693 theMenu->addSeparator();
694 theMenu->addAction( action( SetZLevelId ) );
695 theMenu->addSeparator();
698 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
700 theMenu->addAction( action( ShowAllId ) );
701 theMenu->addAction( action( HideAllId ) );
702 theMenu->addSeparator();
705 if ( anIsOCCView || anIsVTKView )
707 theMenu->addSeparator();
708 theMenu->addAction( action( CopyViewerPositionId ) );
712 theMenu->addAction( action( EditLocalCSId ) );
715 void HYDROGUI_Module::createPreferences()
717 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
718 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
720 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
721 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
723 // Set property cursor type
724 QList<QVariant> aCursorTypeIndicesList;
725 QList<QVariant> aCursorTypeIconsList;
727 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
728 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
729 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
730 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
731 aCursorTypeIndicesList << i;
732 aCursorTypeIconsList << pixmap;
735 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
736 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
738 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
739 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
740 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
743 void HYDROGUI_Module::update( const int flags )
745 if ( !isUpdateEnabled() )
748 QApplication::setOverrideCursor( Qt::WaitCursor );
750 // To prevent calling this method recursively
751 // from one of the methods called below
752 setUpdateEnabled( false );
754 // store selected objects
755 QStringList aSelectedEntries = storeSelection();
757 bool aDoFitAll = flags & UF_FitAll;
760 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
761 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
764 if( ( flags & UF_Viewer ) )
765 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
767 if( ( flags & UF_OCCViewer ) )
768 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
770 if( ( flags & UF_VTKViewer ) )
771 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
773 if( ( flags & UF_Model ) && getDataModel() && getApp() )
775 getDataModel()->update( getStudyId() );
777 // Temporary workaround to prevent breaking
778 // the selection in the object browser.
779 // Note: processEvents() should be called after updateGV(),
780 // otherwise the application crashes from time to time.
781 //RKV: qApp->processEvents();
782 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
783 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
784 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
785 if ( isResizeOnExpandItem && anObjectBrowser ) {
786 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
788 getApp()->updateObjectBrowser( true );
789 if ( isResizeOnExpandItem && anObjectBrowser ) {
790 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
794 // Object browser is currently updated by using UF_Model flag
795 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
796 getApp()->updateObjectBrowser( true );
798 if( ( flags & UF_Controls ) && getApp() )
799 getApp()->updateActions();
801 // restore selected objects
802 restoreSelection( aSelectedEntries );
804 setUpdateEnabled( true );
806 QApplication::restoreOverrideCursor();
809 void HYDROGUI_Module::updateCommandsStatus()
811 LightApp_Module::updateCommandsStatus();
813 updateUndoRedoControls();
815 action( CopyId )->setEnabled( getDataModel()->canCopy() );
816 action( PasteId )->setEnabled( getDataModel()->canPaste() );
819 void HYDROGUI_Module::selectionChanged()
821 LightApp_Module::selectionChanged();
822 updateCommandsStatus();
825 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
827 return (HYDROGUI_DataModel*)dataModel();
830 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
835 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
837 return myOCCDisplayer;
840 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
842 return myVTKDisplayer;
845 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
847 if( myViewManagerMap.contains( theId ) )
849 return myViewManagerMap[ theId ].first;
854 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
856 if( myViewManagerMap.contains( theId ) )
858 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
859 GraphicsView_ViewManager* aViewManager =
860 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
862 return aViewManager->getViewer();
867 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
869 if( myViewManagerMap.contains( theId ) )
871 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
872 OCCViewer_ViewManager* aViewManager =
873 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
875 return aViewManager->getOCCViewer();
880 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
882 if( myViewManagerMap.contains( theId ) )
884 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
885 SVTK_ViewManager* aViewManager =
886 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
888 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
893 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
895 ViewManagerMapIterator anIter( myViewManagerMap );
896 while( anIter.hasNext() )
898 int anId = anIter.next().key();
899 const ViewManagerInfo& anInfo = anIter.value();
900 if( anInfo.first == theViewManager )
906 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
908 int anId = getViewManagerId( theViewManager );
911 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
912 return anInfo.second;
917 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
918 const ViewManagerRole theRole )
920 int anId = getViewManagerId( theViewManager );
923 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
924 anInfo.second = theRole;
928 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
929 const Handle(HYDROData_Entity)& theObject ) const
931 if( theObject.IsNull() )
934 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
935 if( anIter1 != myObjectStateMap.end() )
937 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
938 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
940 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
941 if( anIter2 != aEntry2ObjectStateMap.end() )
943 const ObjectState& anObjectState = anIter2.value();
944 return anObjectState.Visibility;
950 void HYDROGUI_Module::setObjectVisible( const int theViewId,
951 const Handle(HYDROData_Entity)& theObject,
952 const bool theState )
954 if( !theObject.IsNull() )
956 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
957 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
959 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
960 anObjectState.Visibility = theState;
962 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
965 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
966 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
967 Qtx::VisibilityState visState = treeModel->visibilityState( id );
968 if ( visState != Qtx::UnpresentableState )
969 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
974 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
975 const bool theState )
977 if( !theObject.IsNull() )
979 // Process OCC shapes
980 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
981 while( aShapesMapIter != myShapesMap.end() )
983 const ListOfShapes& aShapesList = aShapesMapIter.value();
984 foreach ( HYDROGUI_Shape* aShape, aShapesList )
986 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
988 aShape->setIsToUpdate( theState );
993 // Process VTK shapes
994 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
995 while( aVTKPrsMapIter != myVTKPrsMap.end() )
997 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
998 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1000 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1002 aShape->setIsToUpdate( theState );
1010 /////////////////// OCC SHAPES PROCESSING
1011 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1012 ObjectKind theKind ) const
1014 QList<HYDROGUI_Shape*> aResult;
1016 if ( myShapesMap.contains( theViewId ) )
1018 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1019 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1021 if( aShape && aShape->getObject()->GetKind()==theKind )
1022 aResult.append( aShape );
1028 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1029 const Handle(HYDROData_Entity)& theObject ) const
1031 HYDROGUI_Shape* aResShape = NULL;
1032 if( theObject.IsNull() )
1035 if ( myShapesMap.contains( theViewId ) )
1037 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1038 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1040 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1051 void HYDROGUI_Module::setObjectShape( const int theViewId,
1052 const Handle(HYDROData_Entity)& theObject,
1053 HYDROGUI_Shape* theShape )
1055 if( theObject.IsNull() )
1058 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1059 aViewShapes.append( theShape );
1062 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1063 const Handle(HYDROData_Entity)& theObject )
1065 if ( !myShapesMap.contains( theViewId ) )
1068 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1069 Handle(HYDROData_Entity) anObject;
1070 for ( int i = 0; i < aViewShapes.length(); )
1072 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1073 anObject = aShape->getObject();
1074 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1077 aViewShapes.removeAt( i );
1085 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1087 if ( !myShapesMap.contains( theViewId ) )
1090 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1091 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1093 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1098 myShapesMap.remove( theViewId );
1100 /////////////////// END OF OCC SHAPES PROCESSING
1102 /////////////////// VTKPrs PROCESSING
1103 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1104 const Handle(HYDROData_Entity)& theObject ) const
1106 HYDROGUI_VTKPrs* aResShape = NULL;
1107 if( theObject.IsNull() )
1110 if ( myVTKPrsMap.contains( theViewId ) )
1112 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1113 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1115 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1126 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1127 const Handle(HYDROData_Entity)& theObject,
1128 HYDROGUI_VTKPrs* theShape )
1130 if( theObject.IsNull() )
1133 if( theShape && theShape->needScalarBar() )
1135 // Compute the new global Z range from the added presentation and the old global Z range.
1136 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1137 double* aRange = theShape->getInternalZRange();
1138 bool anIsUpdate = false;
1139 if ( aRange[0] < aGlobalRange[0] )
1141 aGlobalRange[0] = aRange[0];
1144 if ( aRange[1] > aGlobalRange[1] )
1146 aGlobalRange[1] = aRange[1];
1152 updateVTKZRange( theViewId, aGlobalRange );
1156 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1157 aViewShapes.append( theShape );
1160 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1161 const QString& theEntry )
1163 if ( !myVTKPrsMap.contains( theViewId ) )
1166 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1167 Handle(HYDROData_Entity) anObject;
1169 for ( int i = 0; i < aViewShapes.length(); )
1171 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1172 anObject = aShape->getObject();
1173 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1174 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1177 aViewShapes.removeAt( i );
1184 // Invalidate global Z range
1185 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1186 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1189 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1190 const Handle(HYDROData_Entity)& theObject )
1192 if ( !myVTKPrsMap.contains( theViewId ) )
1195 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1196 Handle(HYDROData_Entity) anObject;
1197 for ( int i = 0; i < aViewShapes.length(); )
1199 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1200 anObject = aShape->getObject();
1201 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1204 aViewShapes.removeAt( i );
1211 // Invalidate global Z range
1212 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1213 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1216 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1218 if ( !myVTKPrsMap.contains( theViewId ) )
1221 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1222 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1224 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1229 myVTKPrsMap.remove( theViewId );
1232 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1234 if ( myVTKPrsMap.contains( theViewId ) )
1236 // For the given viewer id update all VTK presentations ...
1237 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1238 HYDROGUI_VTKPrs* aShape;
1239 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1241 aShape = aViewShapes.at( i );
1242 if ( aShape && aShape->needScalarBar() )
1244 aShape->setZRange( theRange );
1248 // ... and update the global color legend scalar bar.
1249 getVTKDisplayer()->SetZRange( theViewId, theRange );
1251 /////////////////// END OF VTKPrs PROCESSING
1253 CAM_DataModel* HYDROGUI_Module::createDataModel()
1255 return new HYDROGUI_DataModel( this );
1258 void HYDROGUI_Module::customEvent( QEvent* e )
1260 int aType = e->type();
1261 if ( aType == NewViewEvent )
1263 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1264 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1266 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1268 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1269 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1271 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1273 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1274 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1276 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1277 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1278 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1280 //ouv: temporarily commented
1281 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1284 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1285 update( UF_Viewer );
1287 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1293 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1295 QEvent::Type aType = theEvent->type();
1296 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1298 if( aType == QEvent::Show )
1300 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1301 e->setData( theObj );
1302 QApplication::postEvent( this, e );
1303 theObj->removeEventFilter( this );
1306 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1308 if( aType == QEvent::Leave )
1310 SUIT_Desktop* aDesktop = getApp()->desktop();
1311 if ( aDesktop && aDesktop->statusBar() ) {
1312 aDesktop->statusBar()->clearMessage();
1316 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1318 if( aType == QEvent::Leave )
1320 SUIT_Desktop* aDesktop = getApp()->desktop();
1321 if ( aDesktop && aDesktop->statusBar() ) {
1322 aDesktop->statusBar()->clearMessage();
1327 return LightApp_Module::eventFilter( theObj, theEvent );
1330 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1332 LightApp_Module::onViewManagerAdded( theViewManager );
1334 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1336 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1337 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1339 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1341 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1342 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1343 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1344 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1346 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1348 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1349 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1350 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1351 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1354 createSelector( theViewManager ); // replace the default selector
1356 ViewManagerInfo anInfo( theViewManager, VMR_General );
1357 myViewManagerMap.insert( ViewManagerId++, anInfo );
1360 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1362 LightApp_Module::onViewManagerRemoved( theViewManager );
1364 createSelector( theViewManager ); // replace the default selector
1366 int anId = getViewManagerId( theViewManager );
1369 OCCViewer_ViewManager* anOCCViewManager =
1370 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1371 if ( anOCCViewManager )
1373 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1375 removeViewShapes( (size_t)anOCCViewer );
1378 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1380 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1383 getVTKDisplayer()->EraseScalarBar( anId, true );
1384 removeViewShapes( (size_t)aVTKViewer );
1388 myViewManagerMap.remove( anId );
1392 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1394 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1396 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1398 aViewFrame->installEventFilter( this );
1400 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1402 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1403 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1406 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1408 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1410 aViewFrame->onTopView();
1412 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1414 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1416 aViewPort->installEventFilter( this );
1420 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1422 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1424 aViewFrame->installEventFilter( this );
1429 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1431 /* ouv: currently unused
1432 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1434 SUIT_ViewManager* aViewManager = 0;
1436 QObject* aParent = aViewPort;
1437 while( aParent = aParent->parent() )
1439 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1441 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1443 aViewManager = aViewer->getViewManager();
1452 double aMouseX = theEvent->scenePos().x();
1453 double aMouseY = theEvent->scenePos().y();
1455 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1456 if( aRole == VMR_General )
1458 int aXDeg = 0, aYDeg = 0;
1459 int aXMin = 0, aYMin = 0;
1460 double aXSec = 0, aYSec = 0;
1461 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1462 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1464 QString aDegSymbol( QChar( 0x00B0 ) );
1465 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1466 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1468 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1470 else if( aRole == VMR_TransformImage )
1471 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1476 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1477 const bool theIsInit,
1478 const bool theIsForced,
1479 const bool theDoFitAll )
1481 QList<int> aViewManagerIdList;
1483 // currently, all views are updated
1484 ViewManagerMapIterator anIter( myViewManagerMap );
1485 while( anIter.hasNext() )
1487 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1489 if ( theDisplayer->IsApplicable( aViewManager ) )
1491 int anId = anIter.key();
1492 aViewManagerIdList.append( anId );
1496 QListIterator<int> anIdIter( aViewManagerIdList );
1497 while( anIdIter.hasNext() )
1499 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1503 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1505 if( !theViewManager )
1508 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1509 if( !aSelectionMgr )
1512 QString aViewType = theViewManager->getType();
1513 if( aViewType != GraphicsView_Viewer::Type() &&
1514 aViewType != OCCViewer_Viewer::Type())
1517 QList<SUIT_Selector*> aSelectorList;
1518 aSelectionMgr->selectors( aViewType, aSelectorList );
1520 // disable all alien selectors
1521 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1522 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1524 SUIT_Selector* aSelector = *anIter;
1525 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1526 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1527 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1528 aSelector->setEnabled( false );
1531 if ( aViewType == GraphicsView_Viewer::Type() )
1533 GraphicsView_ViewManager* aViewManager =
1534 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1536 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1538 else if ( aViewType == OCCViewer_Viewer::Type() )
1540 OCCViewer_ViewManager* aViewManager =
1541 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1543 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1547 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1549 bool aPrevState = myIsUpdateEnabled;
1550 myIsUpdateEnabled = theState;
1554 bool HYDROGUI_Module::isUpdateEnabled() const
1556 return myIsUpdateEnabled;
1559 QStringList HYDROGUI_Module::storeSelection() const
1561 QStringList anEntryList;
1562 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1564 SUIT_DataOwnerPtrList aList( true );
1565 aSelectionMgr->selected( aList );
1567 SUIT_DataOwnerPtrList::iterator anIter;
1568 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1570 const LightApp_DataOwner* anOwner =
1571 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1573 anEntryList.append( anOwner->entry() );
1579 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1581 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1583 SUIT_DataOwnerPtrList aList( true );
1584 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1585 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1586 aSelectionMgr->setSelected( aList );
1590 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1593 bool doShow = false;
1594 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1596 aDisplayer->SaveCursorViewPosition( theViewWindow );
1597 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1601 // Show the coordinates in the status bar
1602 SUIT_Desktop* aDesktop = getApp()->desktop();
1603 if ( aDesktop && aDesktop->statusBar() )
1605 gp_Pnt aWPnt( X, Y, Z );
1606 int aStudyId = application()->activeStudy()->id();
1607 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1608 double WX = aWPnt.X(), WY = aWPnt.Y();
1610 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1611 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1612 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1613 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1614 QString aMsg = tr( "COORDINATES_INFO" );
1615 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1616 aDesktop->statusBar()->showMessage( aMsg );
1622 * Returns stack of active operations;
1624 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1626 return myActiveOperationMap;
1630 * Returns the module active operation. If the active operation is show/hide,
1631 * the method returns the previous operation if it is.
1633 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1635 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1637 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1639 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1641 aVIt.previous(); // skip the top show/hide operation
1642 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1649 * \brief Virtual public slot
1651 * This method is called after the object inserted into data view to update their visibility state
1652 * This is default implementation
1654 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1656 if ( !isActiveModule() )
1659 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1661 // change visibility of object
1662 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1665 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1667 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1668 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1669 if ( visState == Qtx::UnpresentableState )
1672 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1673 treeModel->setVisibilityState( id, visState );
1675 bool vis = visState == Qtx::ShownState;
1676 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1679 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1681 update( UF_OCCViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );