1 // Copyright (C) 2007-2013 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.
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_Displayer.h"
28 #include "HYDROGUI_GVSelector.h"
29 #include "HYDROGUI_InputPanel.h"
30 #include "HYDROGUI_ObjSelector.h"
31 #include "HYDROGUI_OCCDisplayer.h"
32 #include "HYDROGUI_OCCSelector.h"
33 #include "HYDROGUI_Operations.h"
34 #include "HYDROGUI_PrsImage.h"
35 #include "HYDROGUI_Tool.h"
36 #include "HYDROGUI_UpdateFlags.h"
37 #include "HYDROGUI_Shape.h"
38 #include "HYDROGUI_VTKPrs.h"
39 #include "HYDROGUI_VTKPrsDisplayer.h"
40 #include "HYDROGUI_AbstractDisplayer.h"
41 #include "HYDROGUI_PolylineOp.h"
42 #include "HYDROGUI_SetColorOp.h"
43 #include "HYDROGUI_ImportGeomObjectOp.h"
45 #include <HYDROData_Image.h>
46 #include <HYDROData_Profile.h>
47 #include <HYDROData_Lambert93.h>
48 #include <HYDROData_Tool.h>
50 #include <HYDROData_OperationsFactory.h>
52 #include <GraphicsView_ViewFrame.h>
53 #include <GraphicsView_ViewManager.h>
54 #include <GraphicsView_ViewPort.h>
55 #include <GraphicsView_Viewer.h>
57 #include <ImageComposer_CutOperator.h>
58 #include <ImageComposer_CropOperator.h>
59 #include <ImageComposer_FuseOperator.h>
61 #include <LightApp_Application.h>
62 #include <LightApp_DataOwner.h>
63 #include <LightApp_GVSelector.h>
64 #include <LightApp_SelectionMgr.h>
65 #include <LightApp_UpdateFlags.h>
67 #include <SalomeApp_Study.h>
69 #include <OCCViewer_ViewFrame.h>
70 #include <OCCViewer_ViewManager.h>
71 #include <OCCViewer_ViewModel.h>
73 #include <SALOME_Event.h>
75 #include <SUIT_DataBrowser.h>
76 #include <SUIT_Desktop.h>
77 #include <SUIT_Study.h>
78 #include <SUIT_ViewManager.h>
80 #include <SVTK_ViewManager.h>
81 #include <SVTK_ViewModel.h>
82 #include <SVTK_Selector.h>
84 #include <OCCViewer_ViewPort3d.h>
86 #include <GEOMUtils.hxx>
87 #include <GeometryGUI.h>
89 #include <SALOMEDS_wrap.hxx>
92 #include <QApplication>
93 #include <QGraphicsSceneMouseEvent>
95 #include <QMouseEvent>
98 static int ViewManagerId = 0;
100 extern "C" HYDRO_EXPORT CAM_Module* createModule()
102 return new HYDROGUI_Module();
105 extern "C" HYDRO_EXPORT char* getModuleVersion()
107 return (char*)HYDRO_VERSION;
110 HYDROGUI_Module::HYDROGUI_Module()
111 : LightApp_Module( "HYDRO" ),
114 myIsUpdateEnabled( true )
118 HYDROGUI_Module::~HYDROGUI_Module()
122 int HYDROGUI_Module::getStudyId() const
124 LightApp_Application* anApp = getApp();
125 return anApp ? anApp->activeStudy()->id() : 0;
128 void HYDROGUI_Module::initialize( CAM_Application* theApp )
130 LightApp_Module::initialize( theApp );
133 createUndoRedoActions();
138 setMenuShown( false );
139 setToolShown( false );
141 myDisplayer = new HYDROGUI_Displayer( this );
142 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
143 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
146 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
148 bool aRes = LightApp_Module::activateModule( theStudy );
150 LightApp_Application* anApp = getApp();
151 SUIT_Desktop* aDesktop = anApp->desktop();
153 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
155 setMenuShown( true );
156 setToolShown( true );
158 #ifndef DISABLE_PYCONSOLE
159 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
160 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
163 // Remove defunct view managers from the map.
164 // It's essential to do this before "update( UF_All )" call!
165 QList<int> anObsoleteIds;
166 ViewManagerList anAllViewManagers = anApp->viewManagers();
167 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
168 ViewManagerMapIterator anIter( myViewManagerMap );
169 while( anIter.hasNext() ) {
170 int anId = anIter.next().key();
171 const ViewManagerInfo& anInfo = anIter.value();
173 aHydroViewManagers << anInfo.first;
175 if ( !anAllViewManagers.contains( anInfo.first ) ) {
176 anObsoleteIds << anId;
179 foreach ( const int anId, anObsoleteIds ) {
180 myViewManagerMap.remove( anId );
181 myObjectStateMap.remove( anId );
182 myShapesMap.remove( anId );
183 myVTKPrsMap.remove( anId );
185 // Replace the default selector for all view managers.
186 // Add view managers created outside of HYDRO module to the map.
187 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
188 createSelector( aViewManager ); // replace the default selector
189 if ( !aHydroViewManagers.contains( aViewManager ) ) {
190 ViewManagerInfo anInfo( aViewManager, VMR_General );
191 myViewManagerMap.insert( ViewManagerId++, anInfo );
197 updateCommandsStatus();
199 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
201 ViewManagerList anOCCViewManagers;
202 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
203 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
204 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
205 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
206 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
207 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
208 if ( aViewFrame && aViewFrame->getViewPort() ) {
209 aViewFrame->getViewPort()->installEventFilter( this );
215 SalomeApp_Study* aStudy =
216 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
218 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
219 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
220 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
221 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
222 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
223 if( !GEOM_var->_is_nil() ) {
224 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
232 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
235 ViewManagerMapIterator anIter( myViewManagerMap );
236 while( anIter.hasNext() )
237 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
238 getApp()->removeViewManager( aViewManager );
239 myViewManagerMap.clear();
242 ViewManagerList anOCCViewManagers;
243 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
244 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
245 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
246 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
250 myObjectStateMap.clear();
255 // clear the data model's list of copying objects
256 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
258 setMenuShown( false );
259 setToolShown( false );
261 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
263 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
265 return LightApp_Module::deactivateModule( theStudy );
268 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
271 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
272 #ifndef DISABLE_PYCONSOLE
273 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
275 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
278 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
280 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
283 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
287 HYDROGUI_DataModel* aModel = getDataModel();
289 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
290 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
291 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
292 bool anIsVTKView = theClient == SVTK_Viewer::Type();
293 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
296 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
298 bool anIsSelectedDataObjects = false;
299 bool anIsVisibleInSelection = false;
300 bool anIsHiddenInSelection = false;
302 bool anIsImage = false;
303 bool anIsImportedImage = false;
304 bool anIsImageHasRefs = false;
305 bool anIsFusedImage = false;
306 bool anIsCutImage = false;
307 bool anIsSplittedImage = false;
308 bool anIsMustObjectBeUpdated = false;
309 bool anIsPolyline = false;
310 bool anIsPolyline3D = false;
311 bool anIsProfile = false;
312 bool anIsValidProfile = false;
313 bool anAllAreProfiles = false;
314 bool anIsBathymetry = false;
315 bool anIsCalculation = false;
316 bool anIsImmersibleZone = false;
317 bool anIsVisualState = false;
318 bool anIsRegion = false;
319 bool anIsZone = false;
320 bool anIsObstacle = false;
321 bool anIsStream = false;
322 bool anIsChannel = false;
323 bool anIsDigue = false;
324 bool anIsDummyObject3D = false;
325 bool anIsGroup = false;
326 bool anIsObjectCanBeColored = false;
328 // Check the selected GEOM objects (take into account the Object Browser only)
329 if ( anIsObjectBrowser ) {
330 QList<GEOM::shape_type> anObstacleTypes =
331 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
332 QList<GEOM::shape_type> aPolylineTypes =
333 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
335 bool isCanBeImportedAsObstacle =
336 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
337 bool isCanBeImportedAsPolyline =
338 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
340 // Add import as obstacle action
341 if ( isCanBeImportedAsObstacle ) {
342 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
344 // Add import as polyline action
345 if ( isCanBeImportedAsPolyline ) {
346 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
349 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
350 theMenu->addSeparator();
354 // check the selected data model objects
355 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
356 int aNbOfSelectedProfiles = 0;
357 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
359 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
360 if( !anObject.IsNull() )
362 anIsSelectedDataObjects = true;
364 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
365 anIsVisibleInSelection |= aVisibility;
366 anIsHiddenInSelection |= !aVisibility;
368 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
370 anIsMustObjectBeUpdated = true;
373 ObjectKind anObjectKind = anObject->GetKind();
374 if( anObjectKind == KIND_IMAGE )
377 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
378 if( !anImage.IsNull() )
380 anIsImportedImage = anImage->HasLocalPoints();
381 anIsImageHasRefs = anImage->HasReferences();
382 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
384 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
386 QString anOperatorName = anOperator->name();
387 if( anOperatorName == ImageComposer_FuseOperator::Type() )
388 anIsFusedImage = true;
389 else if( anOperatorName == ImageComposer_CutOperator::Type() )
391 else if( anOperatorName == ImageComposer_CropOperator::Type() )
392 anIsSplittedImage = true;
397 else if( anObjectKind == KIND_POLYLINEXY )
399 else if( anObjectKind == KIND_POLYLINE )
400 anIsPolyline3D = true;
401 else if( anObjectKind == KIND_PROFILE )
404 aNbOfSelectedProfiles++;
406 Handle(HYDROData_Profile) aProfile =
407 Handle(HYDROData_Profile)::DownCast( anObject );
408 if( !aProfile.IsNull() && aProfile->IsValid() ) {
409 anIsValidProfile = true;
412 else if( anObjectKind == KIND_CALCULATION )
413 anIsCalculation = true;
414 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
415 anIsImmersibleZone = true;
416 else if( anObjectKind == KIND_VISUAL_STATE )
417 anIsVisualState = true;
418 else if( anObjectKind == KIND_REGION )
420 else if( anObjectKind == KIND_ZONE )
422 else if( anObjectKind == KIND_BATHYMETRY )
423 anIsBathymetry = true;
424 else if( anObjectKind == KIND_OBSTACLE )
426 else if( anObjectKind == KIND_STREAM )
428 else if( anObjectKind == KIND_CHANNEL )
430 else if( anObjectKind == KIND_DIGUE )
432 else if( anObjectKind == KIND_DUMMY_3D )
433 anIsDummyObject3D = true;
434 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
438 if ( !anIsObjectCanBeColored )
439 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
442 // Check if all selected objects are profiles
443 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
444 ( aNbOfSelectedProfiles == aSeq.Length() );
446 // check the selected partitions
447 if( !anIsSelectedDataObjects && anIsObjectBrowser )
449 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
450 if( aSelectedPartition != KIND_UNKNOWN )
452 switch( aSelectedPartition )
455 theMenu->addAction( action( ImportImageId ) );
457 case KIND_BATHYMETRY:
458 theMenu->addAction( action( ImportBathymetryId ) );
460 case KIND_ARTIFICIAL_OBJECT:
461 theMenu->addAction( action( CreateChannelId ) );
462 theMenu->addAction( action( CreateDigueId ) );
464 case KIND_NATURAL_OBJECT:
465 theMenu->addAction( action( CreateImmersibleZoneId ) );
466 theMenu->addAction( action( CreateStreamId ) );
469 theMenu->addAction( action( ImportObstacleFromFileId ) );
470 theMenu->addAction( action( CreateBoxId ) );
471 theMenu->addAction( action( CreateCylinderId ) );
473 case KIND_CALCULATION:
474 theMenu->addAction( action( CreateCalculationId ) );
476 case KIND_POLYLINEXY:
477 theMenu->addAction( action( CreatePolylineId ) );
480 theMenu->addAction( action( CreatePolyline3DId ) );
483 theMenu->addAction( action( CreateProfileId ) );
484 theMenu->addAction( action( ImportProfilesId ) );
485 theMenu->addAction( action( AllGeoreferencementId ) );
487 case KIND_VISUAL_STATE:
488 theMenu->addAction( action( SaveVisualStateId ) );
491 theMenu->addSeparator();
495 if( anIsSelectedDataObjects )
497 if ( anIsMustObjectBeUpdated )
499 theMenu->addAction( action( UpdateObjectId ) );
500 theMenu->addSeparator();
504 theMenu->addAction( action( ForcedUpdateObjectId ) );
505 theMenu->addSeparator();
509 if( aSeq.Length() == 1 )
513 if( anIsImportedImage )
514 theMenu->addAction( action( EditImportedImageId ) );
515 else if( anIsImageHasRefs )
518 theMenu->addAction( action( EditFusedImageId ) );
519 else if( anIsCutImage )
520 theMenu->addAction( action( EditCutImageId ) );
521 else if( anIsSplittedImage )
522 theMenu->addAction( action( EditSplittedImageId ) );
525 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
526 theMenu->addAction( action( ExportImageId ) );
527 theMenu->addSeparator();
529 if( anIsImageHasRefs )
531 theMenu->addAction( action( RemoveImageRefsId ) );
532 theMenu->addSeparator();
535 theMenu->addAction( action( FuseImagesId ) );
536 theMenu->addAction( action( CutImagesId ) );
537 theMenu->addAction( action( SplitImageId ) );
538 theMenu->addSeparator();
540 else if( anIsBathymetry )
542 theMenu->addAction( action( EditImportedBathymetryId ) );
543 theMenu->addAction( action( BathymetryBoundsId ) );
544 theMenu->addSeparator();
546 else if( anIsPolyline )
548 theMenu->addAction( action( EditPolylineId ) );
549 theMenu->addSeparator();
551 else if( anIsPolyline3D )
553 theMenu->addAction( action( EditPolyline3DId ) );
554 theMenu->addSeparator();
556 else if( anIsProfile )
558 theMenu->addAction( action( EditProfileId ) );
559 theMenu->addAction( action( SelectedGeoreferencementId ) );
560 theMenu->addSeparator();
562 else if( anIsCalculation )
564 theMenu->addAction( action( EditCalculationId ) );
565 theMenu->addAction( action( ExportCalculationId ) );
566 theMenu->addSeparator();
568 else if( anIsImmersibleZone )
570 theMenu->addAction( action( EditImmersibleZoneId ) );
571 theMenu->addSeparator();
573 else if( anIsStream )
575 theMenu->addAction( action( EditStreamId ) );
576 theMenu->addSeparator();
578 else if( anIsChannel )
580 theMenu->addAction( action( EditChannelId ) );
581 theMenu->addSeparator();
585 theMenu->addAction( action( EditDigueId ) );
586 theMenu->addSeparator();
588 else if( anIsVisualState && anIsObjectBrowser )
590 theMenu->addAction( action( SaveVisualStateId ) );
591 theMenu->addAction( action( LoadVisualStateId ) );
592 theMenu->addSeparator();
595 // Add set color action for geometrical objects
596 if ( anIsObjectCanBeColored )
598 theMenu->addAction( action( SetColorId ) );
599 theMenu->addSeparator();
601 } else if ( anAllAreProfiles ) {
602 theMenu->addAction( action( SelectedGeoreferencementId ) );
603 theMenu->addSeparator();
606 if( !anIsDummyObject3D )
607 theMenu->addAction( action( DeleteId ) );
608 theMenu->addSeparator();
610 if( anIsImage || anIsPolyline || anIsPolyline3D ||
611 anIsImmersibleZone || anIsZone || anIsRegion ||
612 anIsBathymetry || anIsObstacle || anIsStream ||
613 anIsChannel || anIsDigue || anIsDummyObject3D ||
614 anIsValidProfile || anIsGroup )
616 if( anIsHiddenInSelection )
617 theMenu->addAction( action( ShowId ) );
618 theMenu->addAction( action( ShowOnlyId ) );
619 if( anIsVisibleInSelection )
620 theMenu->addAction( action( HideId ) );
621 theMenu->addSeparator();
627 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
628 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
629 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
630 theMenu->addAction( action( DeleteId ) );
633 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
635 theMenu->addAction( action( ShowAllId ) );
636 theMenu->addAction( action( HideAllId ) );
637 theMenu->addSeparator();
641 void HYDROGUI_Module::update( const int flags )
643 if( !isUpdateEnabled() )
646 QApplication::setOverrideCursor( Qt::WaitCursor );
648 // To prevent calling this method recursively
649 // from one of the methods called below
650 setUpdateEnabled( false );
652 // store selected objects
653 QStringList aSelectedEntries = storeSelection();
655 bool aDoFitAll = flags & UF_FitAll;
656 if( ( flags & UF_Viewer ) )
657 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
659 if( ( flags & UF_OCCViewer ) )
660 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
662 if( ( flags & UF_VTKViewer ) )
663 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
665 if( ( flags & UF_Model ) && getDataModel() && getApp() )
667 getDataModel()->update( getStudyId() );
669 // Temporary workaround to prevent breaking
670 // the selection in the object browser.
671 // Note: processEvents() should be called after updateGV(),
672 // otherwise the application crashes from time to time.
673 //RKV: qApp->processEvents();
674 getApp()->updateObjectBrowser( true );
677 // Object browser is currently updated by using UF_Model flag
678 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
679 getApp()->updateObjectBrowser( true );
681 if( ( flags & UF_Controls ) && getApp() )
682 getApp()->updateActions();
684 // restore selected objects
685 restoreSelection( aSelectedEntries );
687 setUpdateEnabled( true );
689 QApplication::restoreOverrideCursor();
692 void HYDROGUI_Module::updateCommandsStatus()
694 LightApp_Module::updateCommandsStatus();
696 updateUndoRedoControls();
698 action( CopyId )->setEnabled( getDataModel()->canCopy() );
699 action( PasteId )->setEnabled( getDataModel()->canPaste() );
702 void HYDROGUI_Module::selectionChanged()
704 LightApp_Module::selectionChanged();
705 updateCommandsStatus();
708 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
710 return (HYDROGUI_DataModel*)dataModel();
713 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
718 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
720 return myOCCDisplayer;
723 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
725 return myVTKDisplayer;
728 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
730 if( myViewManagerMap.contains( theId ) )
732 return myViewManagerMap[ theId ].first;
737 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
739 if( myViewManagerMap.contains( theId ) )
741 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
742 GraphicsView_ViewManager* aViewManager =
743 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
745 return aViewManager->getViewer();
750 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
752 if( myViewManagerMap.contains( theId ) )
754 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
755 OCCViewer_ViewManager* aViewManager =
756 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
758 return aViewManager->getOCCViewer();
763 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
765 if( myViewManagerMap.contains( theId ) )
767 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
768 SVTK_ViewManager* aViewManager =
769 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
771 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
776 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
778 ViewManagerMapIterator anIter( myViewManagerMap );
779 while( anIter.hasNext() )
781 int anId = anIter.next().key();
782 const ViewManagerInfo& anInfo = anIter.value();
783 if( anInfo.first == theViewManager )
789 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
791 int anId = getViewManagerId( theViewManager );
794 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
795 return anInfo.second;
800 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
801 const ViewManagerRole theRole )
803 int anId = getViewManagerId( theViewManager );
806 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
807 anInfo.second = theRole;
811 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
812 const Handle(HYDROData_Entity)& theObject ) const
814 if( theObject.IsNull() )
817 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
818 if( anIter1 != myObjectStateMap.end() )
820 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
821 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
822 if( anIter2 != aName2ObjectStateMap.end() )
824 const ObjectState& anObjectState = anIter2.value();
825 return anObjectState.Visibility;
831 void HYDROGUI_Module::setObjectVisible( const int theViewId,
832 const Handle(HYDROData_Entity)& theObject,
833 const bool theState )
835 if( !theObject.IsNull() )
837 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
838 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
839 anObjectState.Visibility = theState;
843 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
844 const bool theState )
846 if( !theObject.IsNull() )
848 // Process OCC shapes
849 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
850 while( aShapesMapIter != myShapesMap.end() )
852 const ListOfShapes& aShapesList = aShapesMapIter.value();
853 foreach ( HYDROGUI_Shape* aShape, aShapesList )
855 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
857 aShape->setIsToUpdate( theState );
862 // Process VTK shapes
863 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
864 while( aVTKPrsMapIter != myVTKPrsMap.end() )
866 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
867 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
869 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
871 aShape->setIsToUpdate( theState );
879 /////////////////// OCC SHAPES PROCESSING
880 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
881 const Handle(HYDROData_Entity)& theObject ) const
883 HYDROGUI_Shape* aResShape = NULL;
884 if( theObject.IsNull() )
887 if ( myShapesMap.contains( theViewId ) )
889 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
890 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
892 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
903 void HYDROGUI_Module::setObjectShape( const int theViewId,
904 const Handle(HYDROData_Entity)& theObject,
905 HYDROGUI_Shape* theShape )
907 if( theObject.IsNull() )
910 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
911 aViewShapes.append( theShape );
914 void HYDROGUI_Module::removeObjectShape( const int theViewId,
915 const Handle(HYDROData_Entity)& theObject )
917 if ( !myShapesMap.contains( theViewId ) )
920 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
921 Handle(HYDROData_Entity) anObject;
922 for ( int i = 0; i < aViewShapes.length(); )
924 HYDROGUI_Shape* aShape = aViewShapes.at( i );
925 anObject = aShape->getObject();
926 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
929 aViewShapes.removeAt( i );
937 void HYDROGUI_Module::removeViewShapes( const int theViewId )
939 if ( !myShapesMap.contains( theViewId ) )
942 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
943 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
945 HYDROGUI_Shape* aShape = aViewShapes.at( i );
950 myShapesMap.remove( theViewId );
952 /////////////////// END OF OCC SHAPES PROCESSING
954 /////////////////// VTKPrs PROCESSING
955 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
956 const Handle(HYDROData_Entity)& theObject ) const
958 HYDROGUI_VTKPrs* aResShape = NULL;
959 if( theObject.IsNull() )
962 if ( myVTKPrsMap.contains( theViewId ) )
964 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
965 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
967 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
978 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
979 const Handle(HYDROData_Entity)& theObject,
980 HYDROGUI_VTKPrs* theShape )
982 if( theObject.IsNull() )
985 if( theShape && theShape->needScalarBar() )
987 // Compute the new global Z range from the added presentation and the old global Z range.
988 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
989 double* aRange = theShape->getInternalZRange();
990 bool anIsUpdate = false;
991 if ( aRange[0] < aGlobalRange[0] )
993 aGlobalRange[0] = aRange[0];
996 if ( aRange[1] > aGlobalRange[1] )
998 aGlobalRange[1] = aRange[1];
1004 updateVTKZRange( theViewId, aGlobalRange );
1008 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1009 aViewShapes.append( theShape );
1012 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1013 const Handle(HYDROData_Entity)& theObject )
1015 if ( !myVTKPrsMap.contains( theViewId ) )
1018 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1019 Handle(HYDROData_Entity) anObject;
1020 for ( int i = 0; i < aViewShapes.length(); )
1022 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1023 anObject = aShape->getObject();
1024 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1027 aViewShapes.removeAt( i );
1034 // Invalidate global Z range
1035 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1036 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1039 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1041 if ( !myVTKPrsMap.contains( theViewId ) )
1044 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1045 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1047 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1052 myVTKPrsMap.remove( theViewId );
1055 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1057 if ( myVTKPrsMap.contains( theViewId ) )
1059 // For the given viewer id update all VTK presentations ...
1060 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1061 HYDROGUI_VTKPrs* aShape;
1062 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1064 aShape = aViewShapes.at( i );
1065 if ( aShape && aShape->needScalarBar() )
1067 aShape->setZRange( theRange );
1071 // ... and update the global color legend scalar bar.
1072 getVTKDisplayer()->SetZRange( theViewId, theRange );
1074 /////////////////// END OF VTKPrs PROCESSING
1076 CAM_DataModel* HYDROGUI_Module::createDataModel()
1078 return new HYDROGUI_DataModel( this );
1081 void HYDROGUI_Module::customEvent( QEvent* e )
1083 int aType = e->type();
1084 if ( aType == NewViewEvent )
1086 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1087 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1089 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1091 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1092 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1094 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1096 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1097 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1099 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1100 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1101 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1103 //ouv: temporarily commented
1104 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1107 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1108 update( UF_Viewer );
1110 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1116 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1118 QEvent::Type aType = theEvent->type();
1119 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1121 if( aType == QEvent::Show )
1123 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1124 e->setData( theObj );
1125 QApplication::postEvent( this, e );
1126 theObj->removeEventFilter( this );
1129 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1131 if( aType == QEvent::Leave )
1133 SUIT_Desktop* aDesktop = getApp()->desktop();
1134 if ( aDesktop && aDesktop->statusBar() ) {
1135 aDesktop->statusBar()->clearMessage();
1140 return LightApp_Module::eventFilter( theObj, theEvent );
1143 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1145 LightApp_Module::onViewManagerAdded( theViewManager );
1147 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1149 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1150 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1152 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1154 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1155 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1156 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1157 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1160 createSelector( theViewManager ); // replace the default selector
1162 ViewManagerInfo anInfo( theViewManager, VMR_General );
1163 myViewManagerMap.insert( ViewManagerId++, anInfo );
1166 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1168 LightApp_Module::onViewManagerRemoved( theViewManager );
1170 createSelector( theViewManager ); // replace the default selector
1172 int anId = getViewManagerId( theViewManager );
1175 OCCViewer_ViewManager* anOCCViewManager =
1176 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1177 if ( anOCCViewManager )
1179 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1181 removeViewShapes( (size_t)anOCCViewer );
1184 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1186 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1189 getVTKDisplayer()->EraseScalarBar( anId, true );
1190 removeViewShapes( (size_t)aVTKViewer );
1194 myViewManagerMap.remove( anId );
1198 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1200 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1202 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1204 aViewFrame->installEventFilter( this );
1206 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1208 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1209 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1212 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1214 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1216 aViewFrame->onTopView();
1218 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1220 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1222 aViewPort->installEventFilter( this );
1228 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1230 /* ouv: currently unused
1231 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1233 SUIT_ViewManager* aViewManager = 0;
1235 QObject* aParent = aViewPort;
1236 while( aParent = aParent->parent() )
1238 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1240 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1242 aViewManager = aViewer->getViewManager();
1251 double aMouseX = theEvent->scenePos().x();
1252 double aMouseY = theEvent->scenePos().y();
1254 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1255 if( aRole == VMR_General )
1257 int aXDeg = 0, aYDeg = 0;
1258 int aXMin = 0, aYMin = 0;
1259 double aXSec = 0, aYSec = 0;
1260 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1261 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1263 QString aDegSymbol( QChar( 0x00B0 ) );
1264 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1265 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1267 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1269 else if( aRole == VMR_TransformImage )
1270 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1275 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1276 const bool theIsInit,
1277 const bool theIsForced,
1278 const bool theDoFitAll )
1280 QList<int> aViewManagerIdList;
1282 // currently, all views are updated
1283 ViewManagerMapIterator anIter( myViewManagerMap );
1284 while( anIter.hasNext() )
1286 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1288 if ( theDisplayer->IsApplicable( aViewManager ) )
1290 int anId = anIter.key();
1291 aViewManagerIdList.append( anId );
1295 QListIterator<int> anIdIter( aViewManagerIdList );
1296 while( anIdIter.hasNext() )
1298 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1302 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1304 if( !theViewManager )
1307 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1308 if( !aSelectionMgr )
1311 QString aViewType = theViewManager->getType();
1312 if( aViewType != GraphicsView_Viewer::Type() &&
1313 aViewType != OCCViewer_Viewer::Type())
1316 QList<SUIT_Selector*> aSelectorList;
1317 aSelectionMgr->selectors( aViewType, aSelectorList );
1319 // disable all alien selectors
1320 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1321 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1323 SUIT_Selector* aSelector = *anIter;
1324 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1325 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1326 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1327 aSelector->setEnabled( false );
1330 if ( aViewType == GraphicsView_Viewer::Type() )
1332 GraphicsView_ViewManager* aViewManager =
1333 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1335 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1337 else if ( aViewType == OCCViewer_Viewer::Type() )
1339 OCCViewer_ViewManager* aViewManager =
1340 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1342 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1346 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1348 bool aPrevState = myIsUpdateEnabled;
1349 myIsUpdateEnabled = theState;
1353 bool HYDROGUI_Module::isUpdateEnabled() const
1355 return myIsUpdateEnabled;
1358 QStringList HYDROGUI_Module::storeSelection() const
1360 QStringList anEntryList;
1361 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1363 SUIT_DataOwnerPtrList aList( true );
1364 aSelectionMgr->selected( aList );
1366 SUIT_DataOwnerPtrList::iterator anIter;
1367 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1369 const LightApp_DataOwner* anOwner =
1370 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1372 anEntryList.append( anOwner->entry() );
1378 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1380 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1382 SUIT_DataOwnerPtrList aList( true );
1383 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1384 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1385 aSelectionMgr->setSelected( aList );
1389 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1391 OCCViewer_ViewWindow* anOCCViewWindow =
1392 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1393 if ( !anOCCViewWindow ) {
1397 // Get the selected point coordinates
1398 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1403 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1404 aViewPort->getView() );
1406 // Show the coordinates in the status bar
1407 SUIT_Desktop* aDesktop = getApp()->desktop();
1408 if ( aDesktop && aDesktop->statusBar() ) {
1409 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1410 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1411 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );