1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_DataModel.h"
23 #include "HYDROGUI_DataObject.h"
24 #include "HYDROGUI_Displayer.h"
25 #include "HYDROGUI_GVSelector.h"
26 #include "HYDROGUI_InputPanel.h"
27 #include "HYDROGUI_ObjSelector.h"
28 #include "HYDROGUI_OCCDisplayer.h"
29 #include "HYDROGUI_OCCSelector.h"
30 #include "HYDROGUI_Operations.h"
31 #include "HYDROGUI_PrsImage.h"
32 #include "HYDROGUI_Tool.h"
33 #include "HYDROGUI_UpdateFlags.h"
34 #include "HYDROGUI_Shape.h"
35 #include "HYDROGUI_VTKPrs.h"
36 #include "HYDROGUI_VTKPrsDisplayer.h"
37 #include "HYDROGUI_AbstractDisplayer.h"
38 #include "HYDROGUI_PolylineOp.h"
39 #include "HYDROGUI_SetColorOp.h"
40 #include "HYDROGUI_ImportGeomObjectOp.h"
41 #include "HYDROGUI_ShowHideOp.h"
43 #include <HYDROData_Tool.h>
44 #include <HYDROData_Image.h>
45 #include <HYDROData_Stream.h>
46 #include <HYDROData_Profile.h>
47 #include <HYDROData_Lambert93.h>
48 #include <HYDROData_Polyline3D.h>
50 #include <HYDROData_OperationsFactory.h>
52 #include <CurveCreator_Utils.hxx>
54 #include <GraphicsView_ViewFrame.h>
55 #include <GraphicsView_ViewManager.h>
56 #include <GraphicsView_ViewPort.h>
57 #include <GraphicsView_Viewer.h>
59 #include <ImageComposer_CutOperator.h>
60 #include <ImageComposer_CropOperator.h>
61 #include <ImageComposer_FuseOperator.h>
63 #include <LightApp_Application.h>
64 #include <LightApp_DataOwner.h>
65 #include <LightApp_GVSelector.h>
66 #include <LightApp_SelectionMgr.h>
67 #include <LightApp_UpdateFlags.h>
69 #include <SalomeApp_Study.h>
71 #include <OCCViewer_ViewFrame.h>
72 #include <OCCViewer_ViewManager.h>
73 #include <OCCViewer_ViewModel.h>
75 #include <SALOME_Event.h>
77 #include <SUIT_DataBrowser.h>
78 #include <SUIT_DataObject.h>
79 #include <SUIT_ViewManager.h>
80 #include <SUIT_ResourceMgr.h>
81 #include <SUIT_Desktop.h>
82 #include <SUIT_Study.h>
83 #include <SUIT_Session.h>
85 #include <SVTK_ViewManager.h>
86 #include <SVTK_ViewModel.h>
87 #include <SVTK_ViewWindow.h>
88 #include <SVTK_Selector.h>
90 #include <OCCViewer_ViewPort3d.h>
92 #include <GEOMUtils.hxx>
93 #include <GeometryGUI.h>
95 #include <SALOMEDS_wrap.hxx>
98 #include <QApplication>
99 #include <QGraphicsSceneMouseEvent>
101 #include <QMouseEvent>
102 #include <QStatusBar>
105 static int ViewManagerId = 0;
107 extern "C" HYDRO_EXPORT CAM_Module* createModule()
109 return new HYDROGUI_Module();
112 extern "C" HYDRO_EXPORT char* getModuleVersion()
114 return (char*)HYDRO_VERSION;
117 HYDROGUI_Module::HYDROGUI_Module()
118 : LightApp_Module( "HYDRO" ),
121 myIsUpdateEnabled( true )
125 HYDROGUI_Module::~HYDROGUI_Module()
129 int HYDROGUI_Module::getStudyId() const
131 LightApp_Application* anApp = getApp();
132 return anApp ? anApp->activeStudy()->id() : 0;
135 void HYDROGUI_Module::initialize( CAM_Application* theApp )
137 LightApp_Module::initialize( theApp );
140 createUndoRedoActions();
145 setMenuShown( false );
146 setToolShown( false );
148 myDisplayer = new HYDROGUI_Displayer( this );
149 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
150 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
153 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
155 bool aRes = LightApp_Module::activateModule( theStudy );
157 LightApp_Application* anApp = getApp();
158 SUIT_Desktop* aDesktop = anApp->desktop();
160 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
162 setMenuShown( true );
163 setToolShown( true );
165 #ifndef DISABLE_PYCONSOLE
166 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
167 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
170 // Remove defunct view managers from the map.
171 // It's essential to do this before "update( UF_All )" call!
172 QList<int> anObsoleteIds;
173 ViewManagerList anAllViewManagers = anApp->viewManagers();
174 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
175 ViewManagerMapIterator anIter( myViewManagerMap );
176 while( anIter.hasNext() ) {
177 int anId = anIter.next().key();
178 const ViewManagerInfo& anInfo = anIter.value();
180 aHydroViewManagers << anInfo.first;
182 if ( !anAllViewManagers.contains( anInfo.first ) ) {
183 anObsoleteIds << anId;
186 foreach ( const int anId, anObsoleteIds ) {
187 myViewManagerMap.remove( anId );
188 myObjectStateMap.remove( anId );
189 myShapesMap.remove( anId );
190 myVTKPrsMap.remove( anId );
192 // Replace the default selector for all view managers.
193 // Add view managers created outside of HYDRO module to the map.
194 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
195 createSelector( aViewManager ); // replace the default selector
196 if ( !aHydroViewManagers.contains( aViewManager ) ) {
197 ViewManagerInfo anInfo( aViewManager, VMR_General );
198 myViewManagerMap.insert( ViewManagerId++, anInfo );
204 updateCommandsStatus();
206 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
208 ViewManagerList anOCCViewManagers;
209 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
210 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
211 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
212 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
213 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() ) {
214 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
215 if ( aViewFrame && aViewFrame->getViewPort() ) {
216 aViewFrame->getViewPort()->installEventFilter( this );
222 SalomeApp_Study* aStudy =
223 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
225 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
226 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
227 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
228 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
229 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
230 if( !GEOM_var->_is_nil() ) {
231 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
236 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
237 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
238 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
243 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
246 ViewManagerMapIterator anIter( myViewManagerMap );
247 while( anIter.hasNext() )
248 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
249 getApp()->removeViewManager( aViewManager );
250 myViewManagerMap.clear();
253 ViewManagerList anOCCViewManagers;
254 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
255 foreach ( const SUIT_ViewManager* aViewManager, anOCCViewManagers ) {
256 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
257 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
261 myObjectStateMap.clear();
266 // clear the status bar
267 SUIT_Desktop* aDesktop = getApp()->desktop();
268 if ( aDesktop && aDesktop->statusBar() ) {
269 aDesktop->statusBar()->clearMessage();
272 // clear the data model's list of copying objects
273 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
275 setMenuShown( false );
276 setToolShown( false );
278 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
280 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
282 myActiveOperationMap.clear();
283 return LightApp_Module::deactivateModule( theStudy );
286 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
289 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
290 #ifndef DISABLE_PYCONSOLE
291 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
293 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
296 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
298 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
301 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
305 HYDROGUI_DataModel* aModel = getDataModel();
307 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
308 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
309 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
310 bool anIsVTKView = theClient == SVTK_Viewer::Type();
311 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
314 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
316 bool anIsSelectedDataObjects = false;
317 bool anIsVisibleInSelection = false;
318 bool anIsHiddenInSelection = false;
320 bool anIsImage = false;
321 bool anIsImportedImage = false;
322 bool anIsImageHasRefs = false;
323 bool anIsFusedImage = false;
324 bool anIsCutImage = false;
325 bool anIsSplittedImage = false;
326 bool anIsMustObjectBeUpdated = false;
327 bool anIsPolyline = false;
328 bool anIsPolyline3D = false;
329 bool anIsProfile = false;
330 bool anIsValidProfile = false;
331 bool anAllAreProfiles = false;
332 bool anIsBathymetry = false;
333 bool anIsCalculation = false;
334 bool anIsImmersibleZone = false;
335 bool anIsVisualState = false;
336 bool anIsRegion = false;
337 bool anIsZone = false;
338 bool anIsObstacle = false;
339 bool anIsStricklerTable = false;
340 bool anIsStream = false;
341 bool anIsChannel = false;
342 bool anIsDigue = false;
343 bool anIsDummyObject3D = false;
344 bool anIsGroup = false;
345 bool anIsObjectCanBeColored = false;
347 bool isStreamHasBottom = false;
349 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
350 SUIT_DataOwnerPtrList anOwners;
351 aSelectionMgr->selected( anOwners );
352 if( anIsObjectBrowser && anOwners.size()==1 )
354 QString anEntry = anOwners[0]->keyString();
355 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
357 isRoot = aStudy->isComponent( anEntry );
360 // Check the selected GEOM objects (take into account the Object Browser only)
361 if ( anIsObjectBrowser ) {
362 QList<GEOM::shape_type> anObstacleTypes =
363 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
364 QList<GEOM::shape_type> aPolylineTypes =
365 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
367 bool isCanBeImportedAsObstacle =
368 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
369 bool isCanBeImportedAsPolyline =
370 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
372 // Add import as obstacle action
373 if ( isCanBeImportedAsObstacle ) {
374 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
376 // Add import as polyline action
377 if ( isCanBeImportedAsPolyline ) {
378 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
381 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
382 theMenu->addSeparator();
386 // check the selected data model objects
387 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
388 int aNbOfSelectedProfiles = 0;
389 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
391 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
392 if( !anObject.IsNull() )
394 anIsSelectedDataObjects = true;
396 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
397 anIsVisibleInSelection |= aVisibility;
398 anIsHiddenInSelection |= !aVisibility;
400 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated() )
402 anIsMustObjectBeUpdated = true;
405 ObjectKind anObjectKind = anObject->GetKind();
406 if( anObjectKind == KIND_IMAGE )
409 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
410 if( !anImage.IsNull() )
412 anIsImportedImage = anImage->HasLocalPoints();
413 anIsImageHasRefs = anImage->HasReferences();
414 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
416 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
418 QString anOperatorName = anOperator->name();
419 if( anOperatorName == ImageComposer_FuseOperator::Type() )
420 anIsFusedImage = true;
421 else if( anOperatorName == ImageComposer_CutOperator::Type() )
423 else if( anOperatorName == ImageComposer_CropOperator::Type() )
424 anIsSplittedImage = true;
429 else if( anObjectKind == KIND_POLYLINEXY )
431 else if( anObjectKind == KIND_POLYLINE )
432 anIsPolyline3D = true;
433 else if( anObjectKind == KIND_PROFILE )
436 aNbOfSelectedProfiles++;
438 Handle(HYDROData_Profile) aProfile =
439 Handle(HYDROData_Profile)::DownCast( anObject );
440 if( !aProfile.IsNull() && aProfile->IsValid() ) {
441 anIsValidProfile = true;
444 else if( anObjectKind == KIND_CALCULATION )
445 anIsCalculation = true;
446 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
447 anIsImmersibleZone = true;
448 else if( anObjectKind == KIND_VISUAL_STATE )
449 anIsVisualState = true;
450 else if( anObjectKind == KIND_REGION )
452 else if( anObjectKind == KIND_ZONE )
454 else if( anObjectKind == KIND_BATHYMETRY )
455 anIsBathymetry = true;
456 else if( anObjectKind == KIND_OBSTACLE )
458 else if( anObjectKind == KIND_STRICKLER_TABLE )
459 anIsStricklerTable = true;
460 else if( anObjectKind == KIND_STREAM )
463 Handle(HYDROData_Stream) aStream =
464 Handle(HYDROData_Stream)::DownCast( anObject );
465 if ( !aStream.IsNull() )
466 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
468 else if( anObjectKind == KIND_CHANNEL )
470 else if( anObjectKind == KIND_DIGUE )
472 else if( anObjectKind == KIND_DUMMY_3D )
473 anIsDummyObject3D = true;
474 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLITTED_GROUP )
478 if ( !anIsObjectCanBeColored )
479 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject );
482 // Check if all selected objects are profiles
483 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
484 ( aNbOfSelectedProfiles == aSeq.Length() );
486 // check the selected partitions
487 if( !anIsSelectedDataObjects && anIsObjectBrowser )
489 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
490 if( aSelectedPartition != KIND_UNKNOWN )
492 switch( aSelectedPartition )
495 theMenu->addAction( action( ImportImageId ) );
497 case KIND_BATHYMETRY:
498 theMenu->addAction( action( ImportBathymetryId ) );
500 case KIND_ARTIFICIAL_OBJECT:
501 theMenu->addAction( action( CreateChannelId ) );
502 theMenu->addAction( action( CreateDigueId ) );
504 case KIND_NATURAL_OBJECT:
505 theMenu->addAction( action( CreateImmersibleZoneId ) );
506 theMenu->addAction( action( CreateStreamId ) );
509 theMenu->addAction( action( ImportObstacleFromFileId ) );
510 theMenu->addAction( action( CreateBoxId ) );
511 theMenu->addAction( action( CreateCylinderId ) );
513 case KIND_STRICKLER_TABLE:
514 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
516 case KIND_CALCULATION:
517 theMenu->addAction( action( CreateCalculationId ) );
519 case KIND_POLYLINEXY:
520 theMenu->addAction( action( CreatePolylineId ) );
523 theMenu->addAction( action( CreatePolyline3DId ) );
526 theMenu->addAction( action( CreateProfileId ) );
527 theMenu->addAction( action( ImportProfilesId ) );
528 theMenu->addAction( action( AllGeoreferencementId ) );
530 case KIND_VISUAL_STATE:
531 theMenu->addAction( action( SaveVisualStateId ) );
534 theMenu->addSeparator();
538 if( anIsSelectedDataObjects )
540 if ( anIsMustObjectBeUpdated )
542 theMenu->addAction( action( UpdateObjectId ) );
543 theMenu->addSeparator();
547 theMenu->addAction( action( ForcedUpdateObjectId ) );
548 theMenu->addSeparator();
552 if( aSeq.Length() == 1 )
556 if( anIsImportedImage )
557 theMenu->addAction( action( EditImportedImageId ) );
558 else if( anIsImageHasRefs )
561 theMenu->addAction( action( EditFusedImageId ) );
562 else if( anIsCutImage )
563 theMenu->addAction( action( EditCutImageId ) );
564 else if( anIsSplittedImage )
565 theMenu->addAction( action( EditSplittedImageId ) );
568 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
569 theMenu->addAction( action( ExportImageId ) );
570 theMenu->addSeparator();
572 if( anIsImageHasRefs )
574 theMenu->addAction( action( RemoveImageRefsId ) );
575 theMenu->addSeparator();
578 theMenu->addAction( action( FuseImagesId ) );
579 theMenu->addAction( action( CutImagesId ) );
580 theMenu->addAction( action( SplitImageId ) );
581 theMenu->addSeparator();
583 else if( anIsBathymetry )
585 theMenu->addAction( action( EditImportedBathymetryId ) );
586 theMenu->addAction( action( BathymetryBoundsId ) );
587 theMenu->addSeparator();
589 else if( anIsPolyline )
591 theMenu->addAction( action( EditPolylineId ) );
592 theMenu->addSeparator();
594 else if( anIsPolyline3D )
596 theMenu->addAction( action( EditPolyline3DId ) );
597 theMenu->addSeparator();
599 else if( anIsProfile )
601 theMenu->addAction( action( EditProfileId ) );
602 theMenu->addAction( action( SelectedGeoreferencementId ) );
603 theMenu->addSeparator();
605 else if( anIsCalculation )
607 theMenu->addAction( action( EditCalculationId ) );
608 theMenu->addAction( action( ExportCalculationId ) );
609 theMenu->addSeparator();
611 else if( anIsImmersibleZone )
613 theMenu->addAction( action( EditImmersibleZoneId ) );
614 theMenu->addSeparator();
616 else if( anIsStream )
618 theMenu->addAction( action( EditStreamId ) );
619 if ( action( RiverBottomContextId ) )
621 theMenu->addAction( action( RiverBottomContextId ) );
622 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
624 theMenu->addAction( action( ProfileInterpolateId ) );
625 theMenu->addSeparator();
627 else if( anIsChannel )
629 theMenu->addAction( action( EditChannelId ) );
630 theMenu->addSeparator();
634 theMenu->addAction( action( EditDigueId ) );
635 theMenu->addSeparator();
637 else if( anIsObstacle )
639 theMenu->addAction( action( TranslateObstacleId ) );
640 theMenu->addSeparator();
642 else if( anIsStricklerTable )
644 theMenu->addAction( action( EditStricklerTableId ) );
645 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
646 theMenu->addSeparator();
648 else if( anIsVisualState && anIsObjectBrowser )
650 theMenu->addAction( action( SaveVisualStateId ) );
651 theMenu->addAction( action( LoadVisualStateId ) );
652 theMenu->addSeparator();
655 // Add set color action for geometrical objects
656 if ( anIsObjectCanBeColored )
658 theMenu->addAction( action( SetColorId ) );
659 theMenu->addSeparator();
661 } else if ( anAllAreProfiles ) {
662 theMenu->addAction( action( SelectedGeoreferencementId ) );
663 theMenu->addSeparator();
667 QAction* aCopyAction = action( CopyId );
668 if( aCopyAction && aCopyAction->isEnabled() ) {
669 theMenu->addAction( action( CopyId ) );
670 theMenu->addSeparator();
674 if( !anIsDummyObject3D )
675 theMenu->addAction( action( DeleteId ) );
677 theMenu->addSeparator();
679 if( anIsImage || anIsPolyline || anIsPolyline3D ||
680 anIsImmersibleZone || anIsZone || anIsRegion ||
681 anIsBathymetry || anIsObstacle || anIsStream ||
682 anIsChannel || anIsDigue || anIsDummyObject3D ||
683 anIsValidProfile || anIsGroup )
685 if( anIsHiddenInSelection )
686 theMenu->addAction( action( ShowId ) );
687 theMenu->addAction( action( ShowOnlyId ) );
688 if( anIsVisibleInSelection )
689 theMenu->addAction( action( HideId ) );
690 theMenu->addSeparator();
696 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
697 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
698 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
699 theMenu->addAction( action( DeleteId ) );
701 theMenu->addSeparator();
702 theMenu->addAction( action( SetZLevelId ) );
703 theMenu->addSeparator();
706 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
708 theMenu->addAction( action( ShowAllId ) );
709 theMenu->addAction( action( HideAllId ) );
710 theMenu->addSeparator();
713 if ( anIsOCCView || anIsVTKView )
715 theMenu->addSeparator();
716 theMenu->addAction( action( CopyViewerPositionId ) );
720 theMenu->addAction( action( EditLocalCSId ) );
722 if( anIsObjectBrowser && anOwners.size()==1 )
724 if( aSeq.Size() > 0 )
726 Handle( HYDROData_Object ) anObject = Handle( HYDROData_Object )::DownCast( aSeq.First() );
727 if( !anObject.IsNull() )
729 theMenu->addSeparator();
730 theMenu->addAction( action( SubmersibleId ) );
731 action( SubmersibleId )->setCheckable( true );
732 action( SubmersibleId )->setChecked( anObject->IsSubmersible() );
738 void HYDROGUI_Module::createPreferences()
740 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
741 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
743 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
744 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
746 // Set property cursor type
747 QList<QVariant> aCursorTypeIndicesList;
748 QList<QVariant> aCursorTypeIconsList;
750 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
751 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
752 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
753 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
754 aCursorTypeIndicesList << i;
755 aCursorTypeIconsList << pixmap;
758 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
759 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
761 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
762 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
763 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
766 QCursor HYDROGUI_Module::getPrefEditCursor() const
768 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
769 if ( aCursorType >= Qt::BlankCursor)
771 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
775 void HYDROGUI_Module::update( const int flags )
777 if ( !isUpdateEnabled() )
780 QApplication::setOverrideCursor( Qt::WaitCursor );
782 // To prevent calling this method recursively
783 // from one of the methods called below
784 setUpdateEnabled( false );
786 // store selected objects
787 QStringList aSelectedEntries = storeSelection();
789 bool aDoFitAll = flags & UF_FitAll;
792 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
793 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
796 if( ( flags & UF_Viewer ) )
797 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
799 if( ( flags & UF_OCCViewer ) )
800 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
802 if( ( flags & UF_VTKViewer ) )
803 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
805 if( ( flags & UF_Model ) && getDataModel() && getApp() )
807 getDataModel()->update( getStudyId() );
809 // Temporary workaround to prevent breaking
810 // the selection in the object browser.
811 // Note: processEvents() should be called after updateGV(),
812 // otherwise the application crashes from time to time.
813 //RKV: qApp->processEvents();
814 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
815 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
816 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
817 if ( isResizeOnExpandItem && anObjectBrowser ) {
818 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
820 getApp()->updateObjectBrowser( true );
821 if ( isResizeOnExpandItem && anObjectBrowser ) {
822 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
826 // Object browser is currently updated by using UF_Model flag
827 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
828 getApp()->updateObjectBrowser( true );
830 if( ( flags & UF_Controls ) && getApp() )
831 getApp()->updateActions();
833 // restore selected objects
834 restoreSelection( aSelectedEntries );
836 setUpdateEnabled( true );
838 QApplication::restoreOverrideCursor();
841 void HYDROGUI_Module::updateCommandsStatus()
843 LightApp_Module::updateCommandsStatus();
845 updateUndoRedoControls();
847 action( CopyId )->setEnabled( getDataModel()->canCopy() );
848 action( PasteId )->setEnabled( getDataModel()->canPaste() );
851 void HYDROGUI_Module::selectionChanged()
853 LightApp_Module::selectionChanged();
854 updateCommandsStatus();
857 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
859 return (HYDROGUI_DataModel*)dataModel();
862 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
867 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
869 return myOCCDisplayer;
872 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
874 return myVTKDisplayer;
877 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
879 if( myViewManagerMap.contains( theId ) )
881 return myViewManagerMap[ theId ].first;
886 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
888 if( myViewManagerMap.contains( theId ) )
890 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
891 GraphicsView_ViewManager* aViewManager =
892 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
894 return aViewManager->getViewer();
899 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
901 if( myViewManagerMap.contains( theId ) )
903 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
904 OCCViewer_ViewManager* aViewManager =
905 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
907 return aViewManager->getOCCViewer();
912 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
914 if( myViewManagerMap.contains( theId ) )
916 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
917 SVTK_ViewManager* aViewManager =
918 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
920 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
925 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
927 ViewManagerMapIterator anIter( myViewManagerMap );
928 while( anIter.hasNext() )
930 int anId = anIter.next().key();
931 const ViewManagerInfo& anInfo = anIter.value();
932 if( anInfo.first == theViewManager )
938 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
940 int anId = getViewManagerId( theViewManager );
943 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
944 return anInfo.second;
949 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
950 const ViewManagerRole theRole )
952 int anId = getViewManagerId( theViewManager );
955 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
956 anInfo.second = theRole;
960 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
961 const Handle(HYDROData_Entity)& theObject ) const
963 if( theObject.IsNull() )
969 foreach( int aViewId, myObjectStateMap.keys() )
971 if( isObjectVisible( aViewId, theObject ) )
977 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
978 if( anIter1 != myObjectStateMap.end() )
980 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
981 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
983 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
984 if( anIter2 != aEntry2ObjectStateMap.end() )
986 const ObjectState& anObjectState = anIter2.value();
987 return anObjectState.Visibility;
993 void HYDROGUI_Module::setObjectVisible( const int theViewId,
994 const Handle(HYDROData_Entity)& theObject,
995 const bool theState )
997 if( !theObject.IsNull() )
999 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ];
1000 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1002 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1003 anObjectState.Visibility = theState;
1005 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1008 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1009 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1010 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1011 if ( visState != Qtx::UnpresentableState )
1012 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1017 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1018 const bool theState )
1020 if( !theObject.IsNull() )
1022 // Process OCC shapes
1023 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1024 while( aShapesMapIter != myShapesMap.end() )
1026 const ListOfShapes& aShapesList = aShapesMapIter.value();
1027 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1029 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1031 aShape->setIsToUpdate( theState );
1036 // Process VTK shapes
1037 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1038 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1040 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1041 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1043 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1045 aShape->setIsToUpdate( theState );
1053 /////////////////// OCC SHAPES PROCESSING
1054 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const int theViewId,
1055 ObjectKind theKind ) const
1057 QList<HYDROGUI_Shape*> aResult;
1059 if ( myShapesMap.contains( theViewId ) )
1061 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1062 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1064 if( aShape && aShape->getObject()->GetKind()==theKind )
1065 aResult.append( aShape );
1071 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
1072 const Handle(HYDROData_Entity)& theObject ) const
1074 HYDROGUI_Shape* aResShape = NULL;
1075 if( theObject.IsNull() )
1078 if ( myShapesMap.contains( theViewId ) )
1080 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1081 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1083 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1094 void HYDROGUI_Module::setObjectShape( const int theViewId,
1095 const Handle(HYDROData_Entity)& theObject,
1096 HYDROGUI_Shape* theShape )
1098 if( theObject.IsNull() )
1101 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1102 aViewShapes.append( theShape );
1105 void HYDROGUI_Module::removeObjectShape( const int theViewId,
1106 const Handle(HYDROData_Entity)& theObject )
1108 if ( !myShapesMap.contains( theViewId ) )
1111 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1112 Handle(HYDROData_Entity) anObject;
1113 for ( int i = 0; i < aViewShapes.length(); )
1115 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1116 anObject = aShape->getObject();
1117 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1120 aViewShapes.removeAt( i );
1128 void HYDROGUI_Module::removeViewShapes( const int theViewId )
1130 if ( !myShapesMap.contains( theViewId ) )
1133 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1134 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1136 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1141 myShapesMap.remove( theViewId );
1143 /////////////////// END OF OCC SHAPES PROCESSING
1145 /////////////////// VTKPrs PROCESSING
1146 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
1147 const Handle(HYDROData_Entity)& theObject ) const
1149 HYDROGUI_VTKPrs* aResShape = NULL;
1150 if( theObject.IsNull() )
1153 if ( myVTKPrsMap.contains( theViewId ) )
1155 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1156 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1158 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1169 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
1170 const Handle(HYDROData_Entity)& theObject,
1171 HYDROGUI_VTKPrs* theShape )
1173 if( theObject.IsNull() )
1176 if( theShape && theShape->needScalarBar() )
1178 // Compute the new global Z range from the added presentation and the old global Z range.
1179 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1180 double* aRange = theShape->getInternalZRange();
1181 bool anIsUpdate = false;
1182 if ( aRange[0] < aGlobalRange[0] )
1184 aGlobalRange[0] = aRange[0];
1187 if ( aRange[1] > aGlobalRange[1] )
1189 aGlobalRange[1] = aRange[1];
1195 updateVTKZRange( theViewId, aGlobalRange );
1199 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1200 aViewShapes.append( theShape );
1203 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1204 const QString& theEntry )
1206 if ( !myVTKPrsMap.contains( theViewId ) )
1209 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1210 Handle(HYDROData_Entity) anObject;
1212 for ( int i = 0; i < aViewShapes.length(); )
1214 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1215 anObject = aShape->getObject();
1216 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1217 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1220 aViewShapes.removeAt( i );
1227 // Invalidate global Z range
1228 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1229 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1232 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
1233 const Handle(HYDROData_Entity)& theObject )
1235 if ( !myVTKPrsMap.contains( theViewId ) )
1238 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1239 Handle(HYDROData_Entity) anObject;
1240 for ( int i = 0; i < aViewShapes.length(); )
1242 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1243 anObject = aShape->getObject();
1244 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1247 aViewShapes.removeAt( i );
1254 // Invalidate global Z range
1255 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1256 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1259 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
1261 if ( !myVTKPrsMap.contains( theViewId ) )
1264 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1265 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1267 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1272 myVTKPrsMap.remove( theViewId );
1275 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
1277 if ( myVTKPrsMap.contains( theViewId ) )
1279 // For the given viewer id update all VTK presentations ...
1280 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1281 HYDROGUI_VTKPrs* aShape;
1282 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1284 aShape = aViewShapes.at( i );
1285 if ( aShape && aShape->needScalarBar() )
1287 aShape->setZRange( theRange );
1291 // ... and update the global color legend scalar bar.
1292 getVTKDisplayer()->SetZRange( theViewId, theRange );
1294 /////////////////// END OF VTKPrs PROCESSING
1296 CAM_DataModel* HYDROGUI_Module::createDataModel()
1298 return new HYDROGUI_DataModel( this );
1301 void HYDROGUI_Module::customEvent( QEvent* e )
1303 int aType = e->type();
1304 if ( aType == NewViewEvent )
1306 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1307 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1309 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1311 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1312 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1314 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1316 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1317 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1319 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1320 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1321 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1323 //ouv: temporarily commented
1324 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1327 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1328 update( UF_Viewer );
1330 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1336 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1338 QEvent::Type aType = theEvent->type();
1339 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1341 if( aType == QEvent::Show )
1343 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1344 e->setData( theObj );
1345 QApplication::postEvent( this, e );
1346 theObj->removeEventFilter( this );
1349 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1351 if( aType == QEvent::Leave )
1353 SUIT_Desktop* aDesktop = getApp()->desktop();
1354 if ( aDesktop && aDesktop->statusBar() ) {
1355 aDesktop->statusBar()->clearMessage();
1359 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1361 if( aType == QEvent::Leave )
1363 SUIT_Desktop* aDesktop = getApp()->desktop();
1364 if ( aDesktop && aDesktop->statusBar() ) {
1365 aDesktop->statusBar()->clearMessage();
1370 return LightApp_Module::eventFilter( theObj, theEvent );
1373 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1375 LightApp_Module::onViewManagerAdded( theViewManager );
1377 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1379 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1380 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1382 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1384 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1385 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1386 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1387 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1389 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1391 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1392 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1393 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1394 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1397 createSelector( theViewManager ); // replace the default selector
1399 ViewManagerInfo anInfo( theViewManager, VMR_General );
1400 myViewManagerMap.insert( ViewManagerId++, anInfo );
1403 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1405 LightApp_Module::onViewManagerRemoved( theViewManager );
1407 createSelector( theViewManager ); // replace the default selector
1409 int anId = getViewManagerId( theViewManager );
1412 OCCViewer_ViewManager* anOCCViewManager =
1413 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1414 if ( anOCCViewManager )
1416 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1418 removeViewShapes( (size_t)anOCCViewer );
1421 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1423 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1426 getVTKDisplayer()->EraseScalarBar( anId, true );
1427 removeViewShapes( (size_t)aVTKViewer );
1431 myViewManagerMap.remove( anId );
1435 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1437 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1439 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1441 aViewFrame->installEventFilter( this );
1443 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1445 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1446 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1449 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1451 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1453 aViewFrame->onTopView();
1455 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1457 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1459 aViewPort->installEventFilter( this );
1463 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1465 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1467 aViewFrame->installEventFilter( this );
1472 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1474 /* ouv: currently unused
1475 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1477 SUIT_ViewManager* aViewManager = 0;
1479 QObject* aParent = aViewPort;
1480 while( aParent = aParent->parent() )
1482 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1484 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1486 aViewManager = aViewer->getViewManager();
1495 double aMouseX = theEvent->scenePos().x();
1496 double aMouseY = theEvent->scenePos().y();
1498 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1499 if( aRole == VMR_General )
1501 int aXDeg = 0, aYDeg = 0;
1502 int aXMin = 0, aYMin = 0;
1503 double aXSec = 0, aYSec = 0;
1504 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1505 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1507 QString aDegSymbol( QChar( 0x00B0 ) );
1508 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1509 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1511 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1513 else if( aRole == VMR_TransformImage )
1514 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1519 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1520 const bool theIsInit,
1521 const bool theIsForced,
1522 const bool theDoFitAll )
1524 QList<int> aViewManagerIdList;
1526 // currently, all views are updated
1527 ViewManagerMapIterator anIter( myViewManagerMap );
1528 while( anIter.hasNext() )
1530 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1532 if ( theDisplayer->IsApplicable( aViewManager ) )
1534 int anId = anIter.key();
1535 aViewManagerIdList.append( anId );
1539 QListIterator<int> anIdIter( aViewManagerIdList );
1540 while( anIdIter.hasNext() )
1542 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1546 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1548 if( !theViewManager )
1551 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1552 if( !aSelectionMgr )
1555 QString aViewType = theViewManager->getType();
1556 if( aViewType != GraphicsView_Viewer::Type() &&
1557 aViewType != OCCViewer_Viewer::Type())
1560 QList<SUIT_Selector*> aSelectorList;
1561 aSelectionMgr->selectors( aViewType, aSelectorList );
1563 // disable all alien selectors
1564 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1565 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1567 SUIT_Selector* aSelector = *anIter;
1568 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1569 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1570 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1571 aSelector->setEnabled( false );
1574 if ( aViewType == GraphicsView_Viewer::Type() )
1576 GraphicsView_ViewManager* aViewManager =
1577 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1579 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1581 else if ( aViewType == OCCViewer_Viewer::Type() )
1583 OCCViewer_ViewManager* aViewManager =
1584 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1586 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1590 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1592 bool aPrevState = myIsUpdateEnabled;
1593 myIsUpdateEnabled = theState;
1597 bool HYDROGUI_Module::isUpdateEnabled() const
1599 return myIsUpdateEnabled;
1602 QStringList HYDROGUI_Module::storeSelection() const
1604 QStringList anEntryList;
1605 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1607 SUIT_DataOwnerPtrList aList( true );
1608 aSelectionMgr->selected( aList );
1610 SUIT_DataOwnerPtrList::iterator anIter;
1611 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1613 const LightApp_DataOwner* anOwner =
1614 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1616 anEntryList.append( anOwner->entry() );
1622 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1624 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1626 SUIT_DataOwnerPtrList aList( true );
1627 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1628 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1629 aSelectionMgr->setSelected( aList );
1633 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
1636 bool doShow = false;
1637 HYDROGUI_Displayer* aDisplayer = getDisplayer();
1639 aDisplayer->SaveCursorViewPosition( theViewWindow );
1640 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
1644 // Show the coordinates in the status bar
1645 SUIT_Desktop* aDesktop = getApp()->desktop();
1646 if ( aDesktop && aDesktop->statusBar() )
1648 gp_Pnt aWPnt( X, Y, Z );
1649 int aStudyId = application()->activeStudy()->id();
1650 HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false );
1651 double WX = aWPnt.X(), WY = aWPnt.Y();
1653 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
1654 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
1655 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
1656 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
1657 QString aMsg = tr( "COORDINATES_INFO" );
1658 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
1659 aDesktop->statusBar()->showMessage( aMsg );
1665 * Returns stack of active operations;
1667 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
1669 return myActiveOperationMap;
1673 * Returns the module active operation. If the active operation is show/hide,
1674 * the method returns the previous operation if it is.
1676 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
1678 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
1680 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
1682 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
1684 aVIt.previous(); // skip the top show/hide operation
1685 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
1692 * \brief Virtual public slot
1694 * This method is called after the object inserted into data view to update their visibility state
1695 * This is default implementation
1697 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
1699 if ( !isActiveModule() )
1702 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
1704 // change visibility of object
1705 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
1708 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1710 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
1711 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1712 if ( visState == Qtx::UnpresentableState )
1715 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
1716 treeModel->setVisibilityState( id, visState );
1718 bool vis = visState == Qtx::ShownState;
1719 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
1722 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
1724 update( UF_OCCViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );