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();
503 if( aSeq.Length() == 1 )
507 if( anIsImportedImage )
508 theMenu->addAction( action( EditImportedImageId ) );
509 else if( anIsImageHasRefs )
512 theMenu->addAction( action( EditFusedImageId ) );
513 else if( anIsCutImage )
514 theMenu->addAction( action( EditCutImageId ) );
515 else if( anIsSplittedImage )
516 theMenu->addAction( action( EditSplittedImageId ) );
519 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
520 theMenu->addAction( action( ExportImageId ) );
521 theMenu->addSeparator();
523 if( anIsImageHasRefs )
525 theMenu->addAction( action( RemoveImageRefsId ) );
526 theMenu->addSeparator();
529 theMenu->addAction( action( FuseImagesId ) );
530 theMenu->addAction( action( CutImagesId ) );
531 theMenu->addAction( action( SplitImageId ) );
532 theMenu->addSeparator();
534 else if( anIsBathymetry )
536 theMenu->addAction( action( EditImportedBathymetryId ) );
537 theMenu->addAction( action( BathymetryBoundsId ) );
538 theMenu->addSeparator();
540 else if( anIsPolyline )
542 theMenu->addAction( action( EditPolylineId ) );
543 theMenu->addSeparator();
545 else if( anIsPolyline3D )
547 theMenu->addAction( action( EditPolyline3DId ) );
548 theMenu->addSeparator();
550 else if( anIsProfile )
552 theMenu->addAction( action( EditProfileId ) );
553 theMenu->addAction( action( SelectedGeoreferencementId ) );
554 theMenu->addSeparator();
556 else if( anIsCalculation )
558 theMenu->addAction( action( EditCalculationId ) );
559 theMenu->addAction( action( ExportCalculationId ) );
560 theMenu->addSeparator();
562 else if( anIsImmersibleZone )
564 theMenu->addAction( action( EditImmersibleZoneId ) );
565 theMenu->addSeparator();
567 else if( anIsStream )
569 theMenu->addAction( action( EditStreamId ) );
570 theMenu->addSeparator();
572 else if( anIsChannel )
574 theMenu->addAction( action( EditChannelId ) );
575 theMenu->addSeparator();
579 theMenu->addAction( action( EditDigueId ) );
580 theMenu->addSeparator();
582 else if( anIsVisualState && anIsObjectBrowser )
584 theMenu->addAction( action( SaveVisualStateId ) );
585 theMenu->addAction( action( LoadVisualStateId ) );
586 theMenu->addSeparator();
589 // Add set color action for geometrical objects
590 if ( anIsObjectCanBeColored )
592 theMenu->addAction( action( SetColorId ) );
593 theMenu->addSeparator();
595 } else if ( anAllAreProfiles ) {
596 theMenu->addAction( action( SelectedGeoreferencementId ) );
597 theMenu->addSeparator();
600 if( !anIsDummyObject3D )
601 theMenu->addAction( action( DeleteId ) );
602 theMenu->addSeparator();
604 if( anIsImage || anIsPolyline || anIsPolyline3D ||
605 anIsImmersibleZone || anIsZone || anIsRegion ||
606 anIsBathymetry || anIsObstacle || anIsStream ||
607 anIsChannel || anIsDigue || anIsDummyObject3D ||
608 anIsValidProfile || anIsGroup )
610 if( anIsHiddenInSelection )
611 theMenu->addAction( action( ShowId ) );
612 theMenu->addAction( action( ShowOnlyId ) );
613 if( anIsVisibleInSelection )
614 theMenu->addAction( action( HideId ) );
615 theMenu->addSeparator();
621 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
622 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
623 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
624 theMenu->addAction( action( DeleteId ) );
627 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
629 theMenu->addAction( action( ShowAllId ) );
630 theMenu->addAction( action( HideAllId ) );
631 theMenu->addSeparator();
635 void HYDROGUI_Module::update( const int flags )
637 if( !isUpdateEnabled() )
640 QApplication::setOverrideCursor( Qt::WaitCursor );
642 // To prevent calling this method recursively
643 // from one of the methods called below
644 setUpdateEnabled( false );
646 // store selected objects
647 QStringList aSelectedEntries = storeSelection();
649 bool aDoFitAll = flags & UF_FitAll;
650 if( ( flags & UF_Viewer ) )
651 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
653 if( ( flags & UF_OCCViewer ) )
654 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
656 if( ( flags & UF_VTKViewer ) )
657 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
659 if( ( flags & UF_Model ) && getDataModel() && getApp() )
661 getDataModel()->update( getStudyId() );
663 // Temporary workaround to prevent breaking
664 // the selection in the object browser.
665 // Note: processEvents() should be called after updateGV(),
666 // otherwise the application crashes from time to time.
667 //RKV: qApp->processEvents();
668 getApp()->updateObjectBrowser( true );
671 // Object browser is currently updated by using UF_Model flag
672 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
673 getApp()->updateObjectBrowser( true );
675 if( ( flags & UF_Controls ) && getApp() )
676 getApp()->updateActions();
678 // restore selected objects
679 restoreSelection( aSelectedEntries );
681 setUpdateEnabled( true );
683 QApplication::restoreOverrideCursor();
686 void HYDROGUI_Module::updateCommandsStatus()
688 LightApp_Module::updateCommandsStatus();
690 updateUndoRedoControls();
692 action( CopyId )->setEnabled( getDataModel()->canCopy() );
693 action( PasteId )->setEnabled( getDataModel()->canPaste() );
696 void HYDROGUI_Module::selectionChanged()
698 LightApp_Module::selectionChanged();
699 updateCommandsStatus();
702 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
704 return (HYDROGUI_DataModel*)dataModel();
707 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
712 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
714 return myOCCDisplayer;
717 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
719 return myVTKDisplayer;
722 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
724 if( myViewManagerMap.contains( theId ) )
726 return myViewManagerMap[ theId ].first;
731 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
733 if( myViewManagerMap.contains( theId ) )
735 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
736 GraphicsView_ViewManager* aViewManager =
737 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
739 return aViewManager->getViewer();
744 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
746 if( myViewManagerMap.contains( theId ) )
748 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
749 OCCViewer_ViewManager* aViewManager =
750 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
752 return aViewManager->getOCCViewer();
757 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
759 if( myViewManagerMap.contains( theId ) )
761 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
762 SVTK_ViewManager* aViewManager =
763 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
765 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
770 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
772 ViewManagerMapIterator anIter( myViewManagerMap );
773 while( anIter.hasNext() )
775 int anId = anIter.next().key();
776 const ViewManagerInfo& anInfo = anIter.value();
777 if( anInfo.first == theViewManager )
783 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
785 int anId = getViewManagerId( theViewManager );
788 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
789 return anInfo.second;
794 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
795 const ViewManagerRole theRole )
797 int anId = getViewManagerId( theViewManager );
800 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
801 anInfo.second = theRole;
805 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
806 const Handle(HYDROData_Entity)& theObject ) const
808 if( theObject.IsNull() )
811 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
812 if( anIter1 != myObjectStateMap.end() )
814 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
815 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
816 if( anIter2 != aName2ObjectStateMap.end() )
818 const ObjectState& anObjectState = anIter2.value();
819 return anObjectState.Visibility;
825 void HYDROGUI_Module::setObjectVisible( const int theViewId,
826 const Handle(HYDROData_Entity)& theObject,
827 const bool theState )
829 if( !theObject.IsNull() )
831 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
832 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
833 anObjectState.Visibility = theState;
837 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
838 const bool theState )
840 if( !theObject.IsNull() )
842 // Process OCC shapes
843 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
844 while( aShapesMapIter != myShapesMap.end() )
846 const ListOfShapes& aShapesList = aShapesMapIter.value();
847 foreach ( HYDROGUI_Shape* aShape, aShapesList )
849 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
851 aShape->setIsToUpdate( theState );
856 // Process VTK shapes
857 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
858 while( aVTKPrsMapIter != myVTKPrsMap.end() )
860 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
861 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
863 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
865 aShape->setIsToUpdate( theState );
873 /////////////////// OCC SHAPES PROCESSING
874 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
875 const Handle(HYDROData_Entity)& theObject ) const
877 HYDROGUI_Shape* aResShape = NULL;
878 if( theObject.IsNull() )
881 if ( myShapesMap.contains( theViewId ) )
883 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
884 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
886 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
897 void HYDROGUI_Module::setObjectShape( const int theViewId,
898 const Handle(HYDROData_Entity)& theObject,
899 HYDROGUI_Shape* theShape )
901 if( theObject.IsNull() )
904 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
905 aViewShapes.append( theShape );
908 void HYDROGUI_Module::removeObjectShape( const int theViewId,
909 const Handle(HYDROData_Entity)& theObject )
911 if ( !myShapesMap.contains( theViewId ) )
914 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
915 Handle(HYDROData_Entity) anObject;
916 for ( int i = 0; i < aViewShapes.length(); )
918 HYDROGUI_Shape* aShape = aViewShapes.at( i );
919 anObject = aShape->getObject();
920 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
923 aViewShapes.removeAt( i );
931 void HYDROGUI_Module::removeViewShapes( const int theViewId )
933 if ( !myShapesMap.contains( theViewId ) )
936 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
937 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
939 HYDROGUI_Shape* aShape = aViewShapes.at( i );
944 myShapesMap.remove( theViewId );
946 /////////////////// END OF OCC SHAPES PROCESSING
948 /////////////////// VTKPrs PROCESSING
949 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
950 const Handle(HYDROData_Entity)& theObject ) const
952 HYDROGUI_VTKPrs* aResShape = NULL;
953 if( theObject.IsNull() )
956 if ( myVTKPrsMap.contains( theViewId ) )
958 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
959 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
961 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
972 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
973 const Handle(HYDROData_Entity)& theObject,
974 HYDROGUI_VTKPrs* theShape )
976 if( theObject.IsNull() )
979 if( theShape && theShape->needScalarBar() )
981 // Compute the new global Z range from the added presentation and the old global Z range.
982 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
983 double* aRange = theShape->getInternalZRange();
984 bool anIsUpdate = false;
985 if ( aRange[0] < aGlobalRange[0] )
987 aGlobalRange[0] = aRange[0];
990 if ( aRange[1] > aGlobalRange[1] )
992 aGlobalRange[1] = aRange[1];
998 updateVTKZRange( theViewId, aGlobalRange );
1002 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1003 aViewShapes.append( theShape );
1006 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1007 const Handle(HYDROData_Entity)& theObject )
1009 if ( !myVTKPrsMap.contains( theViewId ) )
1012 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1013 Handle(HYDROData_Entity) anObject;
1014 for ( int i = 0; i < aViewShapes.length(); )
1016 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1017 anObject = aShape->getObject();
1018 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1021 aViewShapes.removeAt( i );
1028 // Invalidate global Z range
1029 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1030 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1033 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1035 if ( !myVTKPrsMap.contains( theViewId ) )
1038 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1039 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1041 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1046 myVTKPrsMap.remove( theViewId );
1049 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1051 if ( myVTKPrsMap.contains( theViewId ) )
1053 // For the given viewer id update all VTK presentations ...
1054 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1055 HYDROGUI_VTKPrs* aShape;
1056 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1058 aShape = aViewShapes.at( i );
1059 if ( aShape && aShape->needScalarBar() )
1061 aShape->setZRange( theRange );
1065 // ... and update the global color legend scalar bar.
1066 getVTKDisplayer()->SetZRange( theViewId, theRange );
1068 /////////////////// END OF VTKPrs PROCESSING
1070 CAM_DataModel* HYDROGUI_Module::createDataModel()
1072 return new HYDROGUI_DataModel( this );
1075 void HYDROGUI_Module::customEvent( QEvent* e )
1077 int aType = e->type();
1078 if ( aType == NewViewEvent )
1080 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1081 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1083 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1085 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1086 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1088 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1090 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1091 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1093 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1094 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1095 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1097 //ouv: temporarily commented
1098 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1101 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1102 update( UF_Viewer );
1104 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1110 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1112 QEvent::Type aType = theEvent->type();
1113 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1115 if( aType == QEvent::Show )
1117 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1118 e->setData( theObj );
1119 QApplication::postEvent( this, e );
1120 theObj->removeEventFilter( this );
1123 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1125 if( aType == QEvent::Leave )
1127 SUIT_Desktop* aDesktop = getApp()->desktop();
1128 if ( aDesktop && aDesktop->statusBar() ) {
1129 aDesktop->statusBar()->clearMessage();
1134 return LightApp_Module::eventFilter( theObj, theEvent );
1137 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1139 LightApp_Module::onViewManagerAdded( theViewManager );
1141 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1143 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1144 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1146 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1148 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1149 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1150 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1151 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1154 createSelector( theViewManager ); // replace the default selector
1156 ViewManagerInfo anInfo( theViewManager, VMR_General );
1157 myViewManagerMap.insert( ViewManagerId++, anInfo );
1160 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1162 LightApp_Module::onViewManagerRemoved( theViewManager );
1164 createSelector( theViewManager ); // replace the default selector
1166 int anId = getViewManagerId( theViewManager );
1169 OCCViewer_ViewManager* anOCCViewManager =
1170 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1171 if ( anOCCViewManager )
1173 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1175 removeViewShapes( (size_t)anOCCViewer );
1178 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1180 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1183 getVTKDisplayer()->EraseScalarBar( anId, true );
1184 removeViewShapes( (size_t)aVTKViewer );
1188 myViewManagerMap.remove( anId );
1192 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1194 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1196 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1198 aViewFrame->installEventFilter( this );
1200 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1202 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1203 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1206 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1208 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1210 aViewFrame->onTopView();
1212 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1214 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1216 aViewPort->installEventFilter( this );
1222 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1224 /* ouv: currently unused
1225 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1227 SUIT_ViewManager* aViewManager = 0;
1229 QObject* aParent = aViewPort;
1230 while( aParent = aParent->parent() )
1232 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1234 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1236 aViewManager = aViewer->getViewManager();
1245 double aMouseX = theEvent->scenePos().x();
1246 double aMouseY = theEvent->scenePos().y();
1248 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1249 if( aRole == VMR_General )
1251 int aXDeg = 0, aYDeg = 0;
1252 int aXMin = 0, aYMin = 0;
1253 double aXSec = 0, aYSec = 0;
1254 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1255 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1257 QString aDegSymbol( QChar( 0x00B0 ) );
1258 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1259 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1261 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1263 else if( aRole == VMR_TransformImage )
1264 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1269 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1270 const bool theIsInit,
1271 const bool theIsForced,
1272 const bool theDoFitAll )
1274 QList<int> aViewManagerIdList;
1276 // currently, all views are updated
1277 ViewManagerMapIterator anIter( myViewManagerMap );
1278 while( anIter.hasNext() )
1280 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1282 if ( theDisplayer->IsApplicable( aViewManager ) )
1284 int anId = anIter.key();
1285 aViewManagerIdList.append( anId );
1289 QListIterator<int> anIdIter( aViewManagerIdList );
1290 while( anIdIter.hasNext() )
1292 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1296 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1298 if( !theViewManager )
1301 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1302 if( !aSelectionMgr )
1305 QString aViewType = theViewManager->getType();
1306 if( aViewType != GraphicsView_Viewer::Type() &&
1307 aViewType != OCCViewer_Viewer::Type())
1310 QList<SUIT_Selector*> aSelectorList;
1311 aSelectionMgr->selectors( aViewType, aSelectorList );
1313 // disable all alien selectors
1314 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1315 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1317 SUIT_Selector* aSelector = *anIter;
1318 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1319 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1320 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1321 aSelector->setEnabled( false );
1324 if ( aViewType == GraphicsView_Viewer::Type() )
1326 GraphicsView_ViewManager* aViewManager =
1327 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1329 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1331 else if ( aViewType == OCCViewer_Viewer::Type() )
1333 OCCViewer_ViewManager* aViewManager =
1334 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1336 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1340 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1342 bool aPrevState = myIsUpdateEnabled;
1343 myIsUpdateEnabled = theState;
1347 bool HYDROGUI_Module::isUpdateEnabled() const
1349 return myIsUpdateEnabled;
1352 QStringList HYDROGUI_Module::storeSelection() const
1354 QStringList anEntryList;
1355 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1357 SUIT_DataOwnerPtrList aList( true );
1358 aSelectionMgr->selected( aList );
1360 SUIT_DataOwnerPtrList::iterator anIter;
1361 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1363 const LightApp_DataOwner* anOwner =
1364 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1366 anEntryList.append( anOwner->entry() );
1372 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1374 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1376 SUIT_DataOwnerPtrList aList( true );
1377 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1378 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1379 aSelectionMgr->setSelected( aList );
1383 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
1385 OCCViewer_ViewWindow* anOCCViewWindow =
1386 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
1387 if ( !anOCCViewWindow ) {
1391 // Get the selected point coordinates
1392 OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
1397 gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( theEvent->x(), theEvent->y(),
1398 aViewPort->getView() );
1400 // Show the coordinates in the status bar
1401 SUIT_Desktop* aDesktop = getApp()->desktop();
1402 if ( aDesktop && aDesktop->statusBar() ) {
1403 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X() );
1404 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y() );
1405 aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) );