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 <OCCViewer_ViewFrame.h>
68 #include <OCCViewer_ViewManager.h>
69 #include <OCCViewer_ViewModel.h>
71 #include <SALOME_Event.h>
73 #include <SUIT_DataBrowser.h>
74 #include <SUIT_Desktop.h>
75 #include <SUIT_Study.h>
76 #include <SUIT_ViewManager.h>
78 #include <SVTK_ViewManager.h>
79 #include <SVTK_ViewModel.h>
80 #include <SVTK_Selector.h>
82 #include <OCCViewer_ViewPort3d.h>
84 #include <GEOMUtils.hxx>
87 #include <QApplication>
88 #include <QGraphicsSceneMouseEvent>
90 #include <QMouseEvent>
93 static int ViewManagerId = 0;
95 extern "C" HYDRO_EXPORT CAM_Module* createModule()
97 return new HYDROGUI_Module();
100 extern "C" HYDRO_EXPORT char* getModuleVersion()
102 return (char*)HYDRO_VERSION;
105 HYDROGUI_Module::HYDROGUI_Module()
106 : LightApp_Module( "HYDRO" ),
109 myIsUpdateEnabled( true )
113 HYDROGUI_Module::~HYDROGUI_Module()
117 int HYDROGUI_Module::getStudyId() const
119 LightApp_Application* anApp = getApp();
120 return anApp ? anApp->activeStudy()->id() : 0;
123 void HYDROGUI_Module::initialize( CAM_Application* theApp )
125 LightApp_Module::initialize( theApp );
128 createUndoRedoActions();
133 setMenuShown( false );
134 setToolShown( false );
136 myDisplayer = new HYDROGUI_Displayer( this );
137 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
138 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
141 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
143 bool aRes = LightApp_Module::activateModule( theStudy );
145 LightApp_Application* anApp = getApp();
146 SUIT_Desktop* aDesktop = anApp->desktop();
148 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
150 setMenuShown( true );
151 setToolShown( true );
153 #ifndef DISABLE_PYCONSOLE
154 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
155 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
158 // Remove defunct view managers from the map.
159 // It's essential to do this before "update( UF_All )" call!
160 QList<int> anObsoleteIds;
161 ViewManagerList anAllViewManagers = anApp->viewManagers();
162 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
163 ViewManagerMapIterator anIter( myViewManagerMap );
164 while( anIter.hasNext() ) {
165 int anId = anIter.next().key();
166 const ViewManagerInfo& anInfo = anIter.value();
168 aHydroViewManagers << anInfo.first;
170 if ( !anAllViewManagers.contains( anInfo.first ) ) {
171 anObsoleteIds << anId;
174 foreach ( const int anId, anObsoleteIds ) {
175 myViewManagerMap.remove( anId );
176 myObjectStateMap.remove( anId );
177 myShapesMap.remove( anId );
178 myVTKPrsMap.remove( anId );
180 // Replace the default selector for all view managers.
181 // Add view managers created outside of HYDRO module to the map.
182 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
183 createSelector( aViewManager ); // replace the default selector
184 if ( !aHydroViewManagers.contains( aViewManager ) ) {
185 ViewManagerInfo anInfo( aViewManager, VMR_General );
186 myViewManagerMap.insert( ViewManagerId++, anInfo );
192 updateCommandsStatus();
194 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
196 ViewManagerList anOCCViewManagers;
197 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
198 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
199 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
200 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
201 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
202 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
203 if ( aViewFrame && aViewFrame->getViewPort() ) {
204 aViewFrame->getViewPort()->installEventFilter( this );
212 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
215 ViewManagerMapIterator anIter( myViewManagerMap );
216 while( anIter.hasNext() )
217 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
218 getApp()->removeViewManager( aViewManager );
219 myViewManagerMap.clear();
222 ViewManagerList anOCCViewManagers;
223 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
224 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
225 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
226 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
230 myObjectStateMap.clear();
235 // clear the data model's list of copying objects
236 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
238 setMenuShown( false );
239 setToolShown( false );
241 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
243 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
245 return LightApp_Module::deactivateModule( theStudy );
248 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
251 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
252 #ifndef DISABLE_PYCONSOLE
253 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
255 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
258 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
260 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
263 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
267 HYDROGUI_DataModel* aModel = getDataModel();
269 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
270 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
271 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
272 bool anIsVTKView = theClient == SVTK_Viewer::Type();
273 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
276 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
278 bool anIsSelectedDataObjects = false;
279 bool anIsVisibleInSelection = false;
280 bool anIsHiddenInSelection = false;
282 bool anIsImage = false;
283 bool anIsImportedImage = false;
284 bool anIsImageHasRefs = false;
285 bool anIsFusedImage = false;
286 bool anIsCutImage = false;
287 bool anIsSplittedImage = false;
288 bool anIsMustObjectBeUpdated = false;
289 bool anIsPolyline = false;
290 bool anIsPolyline3D = false;
291 bool anIsProfile = false;
292 bool anIsValidProfile = false;
293 bool anAllAreProfiles = false;
294 bool anIsBathymetry = false;
295 bool anIsCalculation = false;
296 bool anIsImmersibleZone = false;
297 bool anIsVisualState = false;
298 bool anIsRegion = false;
299 bool anIsZone = false;
300 bool anIsObstacle = false;
301 bool anIsStream = false;
302 bool anIsChannel = false;
303 bool anIsDigue = false;
304 bool anIsDummyObject3D = false;
305 bool anIsGroup = false;
306 bool anIsObjectCanBeColored = false;
308 // Check the selected GEOM objects (take into account the Object Browser only)
309 if ( anIsObjectBrowser ) {
310 QList<GEOM::shape_type> anObstacleTypes =
311 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
312 QList<GEOM::shape_type> aPolylineTypes =
313 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
315 bool isCanBeImportedAsObstacle =
316 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
317 bool isCanBeImportedAsPolyline =
318 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
320 // Add import as obstacle action
321 if ( isCanBeImportedAsObstacle ) {
322 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
324 // Add import as polyline action
325 if ( isCanBeImportedAsPolyline ) {
326 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
329 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
330 theMenu->addSeparator();
334 // check the selected data model objects
335 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
336 int aNbOfSelectedProfiles = 0;
337 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
339 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
340 if( !anObject.IsNull() )
342 anIsSelectedDataObjects = true;
344 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
345 anIsVisibleInSelection |= aVisibility;
346 anIsHiddenInSelection |= !aVisibility;
348 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
350 anIsMustObjectBeUpdated = true;
353 ObjectKind anObjectKind = anObject->GetKind();
354 if( anObjectKind == KIND_IMAGE )
357 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
358 if( !anImage.IsNull() )
360 anIsImportedImage = anImage->HasLocalPoints();
361 anIsImageHasRefs = anImage->HasReferences();
362 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
364 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
366 QString anOperatorName = anOperator->name();
367 if( anOperatorName == ImageComposer_FuseOperator::Type() )
368 anIsFusedImage = true;
369 else if( anOperatorName == ImageComposer_CutOperator::Type() )
371 else if( anOperatorName == ImageComposer_CropOperator::Type() )
372 anIsSplittedImage = true;
377 else if( anObjectKind == KIND_POLYLINEXY )
379 else if( anObjectKind == KIND_POLYLINE )
380 anIsPolyline3D = true;
381 else if( anObjectKind == KIND_PROFILE )
384 aNbOfSelectedProfiles++;
386 Handle(HYDROData_Profile) aProfile =
387 Handle(HYDROData_Profile)::DownCast( anObject );
388 if( !aProfile.IsNull() && aProfile->IsValid() ) {
389 anIsValidProfile = true;
392 else if( anObjectKind == KIND_CALCULATION )
393 anIsCalculation = true;
394 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
395 anIsImmersibleZone = true;
396 else if( anObjectKind == KIND_VISUAL_STATE )
397 anIsVisualState = true;
398 else if( anObjectKind == KIND_REGION )
400 else if( anObjectKind == KIND_ZONE )
402 else if( anObjectKind == KIND_BATHYMETRY )
403 anIsBathymetry = true;
404 else if( anObjectKind == KIND_OBSTACLE )
406 else if( anObjectKind == KIND_STREAM )
408 else if( anObjectKind == KIND_CHANNEL )
410 else if( anObjectKind == KIND_DIGUE )
412 else if( anObjectKind == KIND_DUMMY_3D )
413 anIsDummyObject3D = true;
414 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
418 if ( !anIsObjectCanBeColored )
419 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
422 // Check if all selected objects are profiles
423 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
424 ( aNbOfSelectedProfiles == aSeq.Length() );
426 // check the selected partitions
427 if( !anIsSelectedDataObjects && anIsObjectBrowser )
429 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
430 if( aSelectedPartition != KIND_UNKNOWN )
432 switch( aSelectedPartition )
435 theMenu->addAction( action( ImportImageId ) );
437 case KIND_BATHYMETRY:
438 theMenu->addAction( action( ImportBathymetryId ) );
440 case KIND_ARTIFICIAL_OBJECT:
441 theMenu->addAction( action( CreateChannelId ) );
442 theMenu->addAction( action( CreateDigueId ) );
444 case KIND_NATURAL_OBJECT:
445 theMenu->addAction( action( CreateImmersibleZoneId ) );
446 theMenu->addAction( action( CreateStreamId ) );
449 theMenu->addAction( action( ImportObstacleFromFileId ) );
450 theMenu->addAction( action( CreateBoxId ) );
451 theMenu->addAction( action( CreateCylinderId ) );
453 case KIND_CALCULATION:
454 theMenu->addAction( action( CreateCalculationId ) );
456 case KIND_POLYLINEXY:
457 theMenu->addAction( action( CreatePolylineId ) );
460 theMenu->addAction( action( CreatePolyline3DId ) );
463 theMenu->addAction( action( CreateProfileId ) );
464 theMenu->addAction( action( ImportProfilesId ) );
465 theMenu->addAction( action( AllGeoreferencementId ) );
467 case KIND_VISUAL_STATE:
468 theMenu->addAction( action( SaveVisualStateId ) );
471 theMenu->addSeparator();
475 if( anIsSelectedDataObjects )
477 if ( anIsMustObjectBeUpdated )
479 theMenu->addAction( action( UpdateObjectId ) );
480 theMenu->addSeparator();
483 if( aSeq.Length() == 1 )
487 if( anIsImportedImage )
488 theMenu->addAction( action( EditImportedImageId ) );
489 else if( anIsImageHasRefs )
492 theMenu->addAction( action( EditFusedImageId ) );
493 else if( anIsCutImage )
494 theMenu->addAction( action( EditCutImageId ) );
495 else if( anIsSplittedImage )
496 theMenu->addAction( action( EditSplittedImageId ) );
499 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
500 theMenu->addAction( action( ExportImageId ) );
501 theMenu->addSeparator();
503 if( anIsImageHasRefs )
505 theMenu->addAction( action( RemoveImageRefsId ) );
506 theMenu->addSeparator();
509 theMenu->addAction( action( FuseImagesId ) );
510 theMenu->addAction( action( CutImagesId ) );
511 theMenu->addAction( action( SplitImageId ) );
512 theMenu->addSeparator();
514 else if( anIsBathymetry )
516 theMenu->addAction( action( EditImportedBathymetryId ) );
517 theMenu->addSeparator();
519 else if( anIsPolyline )
521 theMenu->addAction( action( EditPolylineId ) );
522 theMenu->addSeparator();
524 else if( anIsPolyline3D )
526 theMenu->addAction( action( EditPolyline3DId ) );
527 theMenu->addSeparator();
529 else if( anIsProfile )
531 theMenu->addAction( action( EditProfileId ) );
532 theMenu->addAction( action( SelectedGeoreferencementId ) );
533 theMenu->addSeparator();
535 else if( anIsCalculation )
537 theMenu->addAction( action( EditCalculationId ) );
538 theMenu->addAction( action( ExportCalculationId ) );
539 theMenu->addSeparator();
541 else if( anIsImmersibleZone )
543 theMenu->addAction( action( EditImmersibleZoneId ) );
544 theMenu->addSeparator();
546 else if( anIsStream )
548 theMenu->addAction( action( EditStreamId ) );
549 theMenu->addSeparator();
551 else if( anIsChannel )
553 theMenu->addAction( action( EditChannelId ) );
554 theMenu->addSeparator();
558 theMenu->addAction( action( EditDigueId ) );
559 theMenu->addSeparator();
561 else if( anIsVisualState && anIsObjectBrowser )
563 theMenu->addAction( action( SaveVisualStateId ) );
564 theMenu->addAction( action( LoadVisualStateId ) );
565 theMenu->addSeparator();
568 // Add set color action for geometrical objects
569 if ( anIsObjectCanBeColored )
571 theMenu->addAction( action( SetColorId ) );
572 theMenu->addSeparator();
574 } else if ( anAllAreProfiles ) {
575 theMenu->addAction( action( SelectedGeoreferencementId ) );
576 theMenu->addSeparator();
579 if( !anIsDummyObject3D )
580 theMenu->addAction( action( DeleteId ) );
581 theMenu->addSeparator();
583 if( anIsImage || anIsPolyline || anIsPolyline3D ||
584 anIsImmersibleZone || anIsZone || anIsRegion ||
585 anIsBathymetry || anIsObstacle || anIsStream ||
586 anIsChannel || anIsDigue || anIsDummyObject3D ||
587 anIsValidProfile || anIsGroup )
589 if( anIsHiddenInSelection )
590 theMenu->addAction( action( ShowId ) );
591 theMenu->addAction( action( ShowOnlyId ) );
592 if( anIsVisibleInSelection )
593 theMenu->addAction( action( HideId ) );
594 theMenu->addSeparator();
600 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
601 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
602 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
603 theMenu->addAction( action( DeleteId ) );
606 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
608 theMenu->addAction( action( ShowAllId ) );
609 theMenu->addAction( action( HideAllId ) );
610 theMenu->addSeparator();
614 void HYDROGUI_Module::update( const int flags )
616 if( !isUpdateEnabled() )
619 QApplication::setOverrideCursor( Qt::WaitCursor );
621 // To prevent calling this method recursively
622 // from one of the methods called below
623 setUpdateEnabled( false );
625 // store selected objects
626 QStringList aSelectedEntries = storeSelection();
628 bool aDoFitAll = flags & UF_FitAll;
629 if( ( flags & UF_Viewer ) )
630 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
632 if( ( flags & UF_OCCViewer ) )
633 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
635 if( ( flags & UF_VTKViewer ) )
636 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
638 if( ( flags & UF_Model ) && getDataModel() && getApp() )
640 getDataModel()->update( getStudyId() );
642 // Temporary workaround to prevent breaking
643 // the selection in the object browser.
644 // Note: processEvents() should be called after updateGV(),
645 // otherwise the application crashes from time to time.
646 //RKV: qApp->processEvents();
647 getApp()->updateObjectBrowser( true );
650 // Object browser is currently updated by using UF_Model flag
651 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
652 getApp()->updateObjectBrowser( true );
654 if( ( flags & UF_Controls ) && getApp() )
655 getApp()->updateActions();
657 // restore selected objects
658 restoreSelection( aSelectedEntries );
660 setUpdateEnabled( true );
662 QApplication::restoreOverrideCursor();
665 void HYDROGUI_Module::updateCommandsStatus()
667 LightApp_Module::updateCommandsStatus();
669 updateUndoRedoControls();
671 action( CopyId )->setEnabled( getDataModel()->canCopy() );
672 action( PasteId )->setEnabled( getDataModel()->canPaste() );
675 void HYDROGUI_Module::selectionChanged()
677 LightApp_Module::selectionChanged();
678 updateCommandsStatus();
681 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
683 return (HYDROGUI_DataModel*)dataModel();
686 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
691 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
693 return myOCCDisplayer;
696 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
698 return myVTKDisplayer;
701 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
703 if( myViewManagerMap.contains( theId ) )
705 return myViewManagerMap[ theId ].first;
710 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
712 if( myViewManagerMap.contains( theId ) )
714 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
715 GraphicsView_ViewManager* aViewManager =
716 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
718 return aViewManager->getViewer();
723 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
725 if( myViewManagerMap.contains( theId ) )
727 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
728 OCCViewer_ViewManager* aViewManager =
729 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
731 return aViewManager->getOCCViewer();
736 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
738 if( myViewManagerMap.contains( theId ) )
740 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
741 SVTK_ViewManager* aViewManager =
742 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
744 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
749 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
751 ViewManagerMapIterator anIter( myViewManagerMap );
752 while( anIter.hasNext() )
754 int anId = anIter.next().key();
755 const ViewManagerInfo& anInfo = anIter.value();
756 if( anInfo.first == theViewManager )
762 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
764 int anId = getViewManagerId( theViewManager );
767 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
768 return anInfo.second;
773 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
774 const ViewManagerRole theRole )
776 int anId = getViewManagerId( theViewManager );
779 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
780 anInfo.second = theRole;
784 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
785 const Handle(HYDROData_Entity)& theObject ) const
787 if( theObject.IsNull() )
790 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
791 if( anIter1 != myObjectStateMap.end() )
793 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
794 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
795 if( anIter2 != aName2ObjectStateMap.end() )
797 const ObjectState& anObjectState = anIter2.value();
798 return anObjectState.Visibility;
804 void HYDROGUI_Module::setObjectVisible( const int theViewId,
805 const Handle(HYDROData_Entity)& theObject,
806 const bool theState )
808 if( !theObject.IsNull() )
810 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
811 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
812 anObjectState.Visibility = theState;
816 /////////////////// OCC SHAPES PROCESSING
817 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
818 const Handle(HYDROData_Entity)& theObject ) const
820 HYDROGUI_Shape* aResShape = NULL;
821 if( theObject.IsNull() )
824 if ( myShapesMap.contains( theViewId ) )
826 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
827 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
829 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
840 void HYDROGUI_Module::setObjectShape( const int theViewId,
841 const Handle(HYDROData_Entity)& theObject,
842 HYDROGUI_Shape* theShape )
844 if( theObject.IsNull() )
847 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
848 aViewShapes.append( theShape );
851 void HYDROGUI_Module::removeObjectShape( const int theViewId,
852 const Handle(HYDROData_Entity)& theObject )
854 if ( !myShapesMap.contains( theViewId ) )
857 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
858 Handle(HYDROData_Entity) anObject;
859 for ( int i = 0; i < aViewShapes.length(); )
861 HYDROGUI_Shape* aShape = aViewShapes.at( i );
862 anObject = aShape->getObject();
863 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
866 aViewShapes.removeAt( i );
874 void HYDROGUI_Module::removeViewShapes( const int theViewId )
876 if ( !myShapesMap.contains( theViewId ) )
879 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
880 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
882 HYDROGUI_Shape* aShape = aViewShapes.at( i );
887 myShapesMap.remove( theViewId );
889 /////////////////// END OF OCC SHAPES PROCESSING
891 /////////////////// VTKPrs PROCESSING
892 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
893 const Handle(HYDROData_Entity)& theObject ) const
895 HYDROGUI_VTKPrs* aResShape = NULL;
896 if( theObject.IsNull() )
899 if ( myVTKPrsMap.contains( theViewId ) )
901 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
902 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
904 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
915 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
916 const Handle(HYDROData_Entity)& theObject,
917 HYDROGUI_VTKPrs* theShape )
919 if( theObject.IsNull() )
922 if( theShape && theShape->needScalarBar() )
924 // Compute the new global Z range from the added presentation and the old global Z range.
925 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
926 double* aRange = theShape->getInternalZRange();
927 bool anIsUpdate = false;
928 if ( aRange[0] < aGlobalRange[0] )
930 aGlobalRange[0] = aRange[0];
933 if ( aRange[1] > aGlobalRange[1] )
935 aGlobalRange[1] = aRange[1];
941 updateVTKZRange( theViewId, aGlobalRange );
945 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
946 aViewShapes.append( theShape );
949 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
950 const Handle(HYDROData_Entity)& theObject )
952 if ( !myVTKPrsMap.contains( theViewId ) )
955 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
956 Handle(HYDROData_Entity) anObject;
957 for ( int i = 0; i < aViewShapes.length(); )
959 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
960 anObject = aShape->getObject();
961 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
964 aViewShapes.removeAt( i );
971 // Invalidate global Z range
972 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
973 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
976 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
978 if ( !myVTKPrsMap.contains( theViewId ) )
981 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
982 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
984 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
989 myVTKPrsMap.remove( theViewId );
992 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
994 if ( myVTKPrsMap.contains( theViewId ) )
996 // For the given viewer id update all VTK presentations ...
997 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
998 HYDROGUI_VTKPrs* aShape;
999 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1001 aShape = aViewShapes.at( i );
1002 if ( aShape && aShape->needScalarBar() )
1004 aShape->setZRange( theRange );
1008 // ... and update the global color legend scalar bar.
1009 getVTKDisplayer()->SetZRange( theViewId, theRange );
1011 /////////////////// END OF VTKPrs PROCESSING
1013 CAM_DataModel* HYDROGUI_Module::createDataModel()
1015 return new HYDROGUI_DataModel( this );
1018 void HYDROGUI_Module::customEvent( QEvent* e )
1020 int aType = e->type();
1021 if ( aType == NewViewEvent )
1023 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1024 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1026 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1028 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1029 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1031 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1033 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1034 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1036 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1037 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1038 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1040 //ouv: temporarily commented
1041 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1044 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1045 update( UF_Viewer );
1047 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1053 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1055 QEvent::Type aType = theEvent->type();
1056 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1058 if( aType == QEvent::Show )
1060 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1061 e->setData( theObj );
1062 QApplication::postEvent( this, e );
1063 theObj->removeEventFilter( this );
1066 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1068 if( aType == QEvent::Leave )
1070 SUIT_Desktop* aDesktop = getApp()->desktop();
1071 if ( aDesktop && aDesktop->statusBar() ) {
1072 aDesktop->statusBar()->clearMessage();
1077 return LightApp_Module::eventFilter( theObj, theEvent );
1080 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1082 LightApp_Module::onViewManagerAdded( theViewManager );
1084 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1086 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1087 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1089 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1091 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1092 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1093 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1094 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1097 createSelector( theViewManager ); // replace the default selector
1099 ViewManagerInfo anInfo( theViewManager, VMR_General );
1100 myViewManagerMap.insert( ViewManagerId++, anInfo );
1103 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1105 LightApp_Module::onViewManagerRemoved( theViewManager );
1107 createSelector( theViewManager ); // replace the default selector
1109 int anId = getViewManagerId( theViewManager );
1112 OCCViewer_ViewManager* anOCCViewManager =
1113 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1114 if ( anOCCViewManager )
1116 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1118 removeViewShapes( (size_t)anOCCViewer );
1121 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1123 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1126 getVTKDisplayer()->EraseScalarBar( anId, true );
1127 removeViewShapes( (size_t)aVTKViewer );
1131 myViewManagerMap.remove( anId );
1135 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1137 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1139 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1141 aViewFrame->installEventFilter( this );
1143 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1145 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1146 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1149 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1151 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1153 aViewFrame->onTopView();
1155 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1157 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1159 aViewPort->installEventFilter( this );
1165 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1167 /* ouv: currently unused
1168 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1170 SUIT_ViewManager* aViewManager = 0;
1172 QObject* aParent = aViewPort;
1173 while( aParent = aParent->parent() )
1175 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1177 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1179 aViewManager = aViewer->getViewManager();
1188 double aMouseX = theEvent->scenePos().x();
1189 double aMouseY = theEvent->scenePos().y();
1191 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1192 if( aRole == VMR_General )
1194 int aXDeg = 0, aYDeg = 0;
1195 int aXMin = 0, aYMin = 0;
1196 double aXSec = 0, aYSec = 0;
1197 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1198 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1200 QString aDegSymbol( QChar( 0x00B0 ) );
1201 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1202 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1204 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1206 else if( aRole == VMR_TransformImage )
1207 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1212 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1213 const bool theIsInit,
1214 const bool theIsForced,
1215 const bool theDoFitAll )
1217 QList<int> aViewManagerIdList;
1219 // currently, all views are updated
1220 ViewManagerMapIterator anIter( myViewManagerMap );
1221 while( anIter.hasNext() )
1223 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1225 if ( theDisplayer->IsApplicable( aViewManager ) )
1227 int anId = anIter.key();
1228 aViewManagerIdList.append( anId );
1232 QListIterator<int> anIdIter( aViewManagerIdList );
1233 while( anIdIter.hasNext() )
1235 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1239 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1241 if( !theViewManager )
1244 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1245 if( !aSelectionMgr )
1248 QString aViewType = theViewManager->getType();
1249 if( aViewType != GraphicsView_Viewer::Type() &&
1250 aViewType != OCCViewer_Viewer::Type())
1253 QList<SUIT_Selector*> aSelectorList;
1254 aSelectionMgr->selectors( aViewType, aSelectorList );
1256 // disable all alien selectors
1257 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1258 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1260 SUIT_Selector* aSelector = *anIter;
1261 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1262 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1263 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1264 aSelector->setEnabled( false );
1267 if ( aViewType == GraphicsView_Viewer::Type() )
1269 GraphicsView_ViewManager* aViewManager =
1270 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1272 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1274 else if ( aViewType == OCCViewer_Viewer::Type() )
1276 OCCViewer_ViewManager* aViewManager =
1277 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1279 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1283 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1285 bool aPrevState = myIsUpdateEnabled;
1286 myIsUpdateEnabled = theState;
1290 bool HYDROGUI_Module::isUpdateEnabled() const
1292 return myIsUpdateEnabled;
1295 QStringList HYDROGUI_Module::storeSelection() const
1297 QStringList anEntryList;
1298 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1300 SUIT_DataOwnerPtrList aList( true );
1301 aSelectionMgr->selected( aList );
1303 SUIT_DataOwnerPtrList::iterator anIter;
1304 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1306 const LightApp_DataOwner* anOwner =
1307 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1309 anEntryList.append( anOwner->entry() );
1315 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1317 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1319 SUIT_DataOwnerPtrList aList( true );
1320 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1321 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1322 aSelectionMgr->setSelected( aList );
1326 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1328 OCCViewer_ViewWindow* anOCCViewWindow =
1329 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1330 if ( !anOCCViewWindow ) {
1334 // Get the selected point coordinates
1335 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1340 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1341 aViewPort->getView() );
1343 // Show the coordinates in the status bar
1344 SUIT_Desktop* aDesktop = getApp()->desktop();
1345 if ( aDesktop && aDesktop->statusBar() ) {
1346 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1347 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1348 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );