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
21 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_DataModel.h"
25 #include "HYDROGUI_DataObject.h"
26 #include "HYDROGUI_Displayer.h"
27 #include "HYDROGUI_GVSelector.h"
28 #include "HYDROGUI_InputPanel.h"
29 #include "HYDROGUI_ObjSelector.h"
30 #include "HYDROGUI_OCCDisplayer.h"
31 #include "HYDROGUI_OCCSelector.h"
32 #include "HYDROGUI_Operations.h"
33 #include "HYDROGUI_PrsImage.h"
34 #include "HYDROGUI_Tool.h"
35 #include "HYDROGUI_Tool2.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"
44 #include "HYDROGUI_ShowHideOp.h"
45 #include "HYDROGUI_Overview.h"
46 #include <HYDROGUI_ProfileDlg.h>
47 #include <HYDROGUI_SIProgressIndicator.h>
48 #include <HYDROGUI_ZIProgressIndicator.h>
49 #include <HYDROData_Tool.h>
50 #include <HYDROData_Image.h>
51 #include <HYDROData_Stream.h>
52 #include <HYDROData_Profile.h>
53 #include <HYDROData_Lambert93.h>
54 #include <HYDROData_Polyline3D.h>
55 #include <HYDROData_StricklerTable.h>
56 #include <HYDROData_ArtificialObject.h>
57 #include <HYDROData_NaturalObject.h>
59 #include <HYDROData_OperationsFactory.h>
61 #include <CurveCreator_Utils.hxx>
63 #include <GraphicsView_ViewFrame.h>
64 #include <GraphicsView_ViewManager.h>
65 #include <GraphicsView_ViewPort.h>
66 #include <GraphicsView_Viewer.h>
68 #include <ImageComposer_CutOperator.h>
69 #include <ImageComposer_CropOperator.h>
70 #include <ImageComposer_FuseOperator.h>
72 #include <LightApp_Application.h>
73 #include <LightApp_DataOwner.h>
74 #include <LightApp_GVSelector.h>
75 #include <LightApp_SelectionMgr.h>
76 #include <LightApp_UpdateFlags.h>
78 #include <SalomeApp_Study.h>
80 #include <OCCViewer_ViewFrame.h>
81 #include <OCCViewer_ViewManager.h>
82 #include <OCCViewer_ViewModel.h>
84 #include <SALOME_Event.h>
86 #include <SUIT_DataBrowser.h>
87 #include <SUIT_DataObject.h>
88 #include <SUIT_ViewManager.h>
89 #include <SUIT_ResourceMgr.h>
90 #include <SUIT_Desktop.h>
91 #include <SUIT_Study.h>
92 #include <SUIT_Session.h>
94 #include <SVTK_ViewManager.h>
95 #include <SVTK_ViewModel.h>
96 #include <SVTK_ViewWindow.h>
97 #include <SVTK_Selector.h>
99 #include <OCCViewer_ViewPort3d.h>
101 #include <GEOMUtils.hxx>
102 #include <GeometryGUI.h>
104 #include <SALOMEDS_wrap.hxx>
107 #include <QApplication>
108 #include <QGraphicsSceneMouseEvent>
110 #include <QMouseEvent>
111 #include <QStatusBar>
115 #include "HYDRO_trace.hxx"
117 static size_t ViewManagerId = 1;
119 extern "C" HYDRO_EXPORT CAM_Module* createModule()
121 return new HYDROGUI_Module();
124 extern "C" HYDRO_EXPORT char* getModuleVersion()
126 return (char*)HYDRO_VERSION;
129 HYDROGUI_Module::HYDROGUI_Module()
130 : LightApp_Module( "HYDRO" ),
133 myIsUpdateEnabled( true ),
136 DEBTRACE("HYDROGUI_Module::HYDROGUI_Module()");
139 HYDROGUI_Module::~HYDROGUI_Module()
141 DEBTRACE("HYDROGUI_Module::~HYDROGUI_Module()");
144 int HYDROGUI_Module::getStudyId() const
146 DEBTRACE("HYDROGUI_Module::getStudyId()");
147 LightApp_Application* anApp = getApp();
148 return anApp ? anApp->activeStudy()->id() : 0;
151 void HYDROGUI_Module::initialize( CAM_Application* theApp )
153 DEBTRACE("HYDROGUI_Module::initialize");
154 LightApp_Module::initialize( theApp );
157 createUndoRedoActions();
162 setMenuShown( false );
163 setToolShown( false );
165 myDisplayer = new HYDROGUI_Displayer( this );
166 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
167 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
169 HYDROData_Tool::SetSIProgress( new HYDROGUI_SIProgressIndicator( theApp->desktop() ) );
170 HYDROData_Tool::SetZIProgress( new HYDROGUI_ZIProgressIndicator( theApp->desktop() ) );
173 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
175 DEBTRACE("HYDROGUI_Module::activateModule");
176 bool aRes = LightApp_Module::activateModule( theStudy );
178 LightApp_Application* anApp = getApp();
179 SUIT_Desktop* aDesktop = anApp->desktop();
181 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
183 setMenuShown( true );
184 setToolShown( true );
186 // import Python module that manages HYDRO plugins (need to be here because SalomePyQt API uses active module)
187 PyGILState_STATE gstate = PyGILState_Ensure();
188 PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
189 if ( !pluginsmanager ) {
194 PyObject_CallMethod(pluginsmanager, (char*)"initialize", (char*)"isss", 1, "hydro",
195 tr("MEN_DESK_HYDRO").toUtf8().data(),
196 tr("Python plugins").toUtf8().data());
201 PyGILState_Release(gstate);
202 // end of GEOM plugins loading
204 #ifndef DISABLE_PYCONSOLE
205 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
206 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
209 // Remove defunct view managers from the map.
210 // It's essential to do this before "update( UF_All )" call!
211 QList<size_t> anObsoleteIds;
212 ViewManagerList anAllViewManagers = anApp->viewManagers();
213 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
214 ViewManagerMapIterator anIter( myViewManagerMap );
215 while( anIter.hasNext() ) {
216 size_t anId = anIter.next().key();
217 const ViewManagerInfo& anInfo = anIter.value();
219 aHydroViewManagers << anInfo.first;
221 if ( !anAllViewManagers.contains( anInfo.first ) ) {
222 anObsoleteIds << anId;
225 foreach ( const size_t anId, anObsoleteIds ) {
226 myViewManagerMap.remove( anId );
227 myObjectStateMap.remove( anId );
228 myShapesMap.remove( anId );
229 myVTKPrsMap.remove( anId );
231 // Replace the default selector for all view managers.
232 // Add view managers created outside of HYDRO module to the map.
233 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
234 createSelector( aViewManager ); // replace the default selector
235 if ( !aHydroViewManagers.contains( aViewManager ) ) {
236 ViewManagerInfo anInfo( aViewManager, VMR_General );
237 myViewManagerMap.insert( ViewManagerId++, anInfo );
243 updateCommandsStatus();
245 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
247 ViewManagerList anOCCViewManagers;
248 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
250 foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
252 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
253 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
254 connect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
255 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
257 OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
260 occ_mgr->setChainedOperations( true );//TODO: via preferences
263 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() )
265 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
266 if ( aViewFrame && aViewFrame->getViewPort() )
268 aViewFrame->getViewPort()->installEventFilter( this );
273 preferencesChanged( "HYDRO", "zoom_shutoff" );
275 preferencesChanged( "HYDRO", "chained_panning" );
278 SalomeApp_Study* aStudy =
279 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
281 SALOMEDS::Study_var aDSStudy = GeometryGUI::getStudyServant();
282 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
283 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
284 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
285 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
286 if( !GEOM_var->_is_nil() ) {
287 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
293 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
294 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
295 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
300 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
302 DEBTRACE("HYDROGUI_Module::deactivateModule");
304 ViewManagerMapIterator anIter( myViewManagerMap );
305 while( anIter.hasNext() )
306 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
307 getApp()->removeViewManager( aViewManager );
308 myViewManagerMap.clear();
311 ViewManagerList anOCCViewManagers;
312 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
313 foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
315 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
316 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
317 disconnect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
318 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
320 OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
323 occ_mgr->setChainedOperations( false );
324 setAutoZoom( occ_mgr, true );
329 myObjectStateMap.clear();
334 // clear the status bar
335 SUIT_Desktop* aDesktop = getApp()->desktop();
336 if ( aDesktop && aDesktop->statusBar() ) {
337 aDesktop->statusBar()->clearMessage();
340 // clear the data model's list of copying objects
341 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
343 setMenuShown( false );
344 setToolShown( false );
346 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
348 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
350 myActiveOperationMap.clear();
352 myViewManagerMap.clear();
354 bool ret = LightApp_Module::deactivateModule( theStudy );
358 void HYDROGUI_Module::studyClosed(SUIT_Study* theStudy)
360 DEBTRACE("HYDROGUI_Module::studyClosed");
361 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
366 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
368 DEBTRACE("HYDROGUI_Module::windows");
369 static bool inWindows = false;
374 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
375 #ifndef DISABLE_PYCONSOLE
376 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
378 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
379 theMap.insert( OverviewWindow, Qt::LeftDockWidgetArea );
382 LightApp_Application* app = getApp();
383 if( app && app->getWindow( OverviewWindow )==0 )
385 const_cast<HYDROGUI_Module*>( this )->myOverview =
386 new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() );
387 app->insertDockWindow( OverviewWindow, myOverview );
388 app->placeDockWindow( OverviewWindow, Qt::LeftDockWidgetArea );
393 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
395 DEBTRACE("HYDROGUI_Module::viewManagers");
396 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
399 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
403 HYDROGUI_DataModel* aModel = getDataModel();
405 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
406 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
407 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
408 bool anIsVTKView = theClient == SVTK_Viewer::Type();
409 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
412 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
414 bool anIsSelectedDataObjects = false;
415 bool anIsVisibleInSelection = false;
416 bool anIsHiddenInSelection = false;
418 bool anIsImage = false;
419 bool anIsImportedImage = false;
420 bool anIsImageHasRefs = false;
421 bool anIsFusedImage = false;
422 bool anIsCutImage = false;
423 bool anIsSplitImage = false;
424 bool anIsMustObjectBeUpdated = false;
425 bool anIsPolyline = false;
426 bool anIsPolyline3D = false;
427 bool anIsProfile = false;
428 bool anIsValidProfile = false;
429 bool anAllAreProfiles = false;
430 bool anIsBathymetry = false;
431 bool anIsCalculation = false;
432 bool anIsImmersibleZone = false;
433 bool anIsVisualState = false;
434 bool anIsRegion = false;
435 bool anIsZone = false;
436 bool anIsObstacle = false;
437 bool anIsStricklerTable = false;
438 bool anIsLandCoverMap = false;
439 bool anIsStream = false;
440 bool anIsChannel = false;
441 bool anIsDigue = false;
442 bool anIsDummyObject3D = false;
443 bool anIsGroup = false;
444 bool anIsObjectCanBeColored = false;
446 bool isStreamHasBottom = false;
447 bool anIsBCPolygon = false;
449 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
450 SUIT_DataOwnerPtrList anOwners;
451 aSelectionMgr->selected( anOwners );
452 if( anIsObjectBrowser && anOwners.size()==1 )
454 QString anEntry = anOwners[0]->keyString();
455 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
457 isRoot = aStudy->isComponent( anEntry );
460 // Check the selected GEOM objects (take into account the Object Browser only)
461 if ( anIsObjectBrowser ) {
462 QList<GEOM::shape_type> anObstacleTypes =
463 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
464 QList<GEOM::shape_type> aPolylineTypes =
465 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
467 bool isCanBeImportedAsObstacle =
468 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
469 bool isCanBeImportedAsPolyline =
470 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
472 // Add import as obstacle action
473 if ( isCanBeImportedAsObstacle ) {
474 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
476 // Add import as polyline action
477 if ( isCanBeImportedAsPolyline ) {
478 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
481 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
482 theMenu->addSeparator();
486 // check the selected data model objects
487 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
488 int aNbOfSelectedProfiles = 0;
489 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
491 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
492 if( !anObject.IsNull() )
494 anIsSelectedDataObjects = true;
496 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
497 anIsVisibleInSelection |= aVisibility;
498 anIsHiddenInSelection |= !aVisibility;
500 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
502 anIsMustObjectBeUpdated = true;
505 ObjectKind anObjectKind = anObject->GetKind();
506 if( anObjectKind == KIND_IMAGE )
509 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
510 if( !anImage.IsNull() )
512 anIsImportedImage = anImage->HasLocalPoints();
513 anIsImageHasRefs = anImage->HasReferences();
514 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
516 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
518 QString anOperatorName = anOperator->name();
519 if( anOperatorName == ImageComposer_FuseOperator::Type() )
520 anIsFusedImage = true;
521 else if( anOperatorName == ImageComposer_CutOperator::Type() )
523 else if( anOperatorName == ImageComposer_CropOperator::Type() )
524 anIsSplitImage = true;
529 else if( anObjectKind == KIND_POLYLINEXY )
531 else if( anObjectKind == KIND_POLYLINE )
532 anIsPolyline3D = true;
533 else if( anObjectKind == KIND_PROFILE )
536 aNbOfSelectedProfiles++;
538 Handle(HYDROData_Profile) aProfile =
539 Handle(HYDROData_Profile)::DownCast( anObject );
540 if( !aProfile.IsNull() && aProfile->IsValid() ) {
541 anIsValidProfile = true;
544 else if( anObjectKind == KIND_CALCULATION )
545 anIsCalculation = true;
546 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
547 anIsImmersibleZone = true;
548 else if( anObjectKind == KIND_VISUAL_STATE )
549 anIsVisualState = true;
550 else if( anObjectKind == KIND_REGION )
552 else if( anObjectKind == KIND_ZONE )
554 else if( anObjectKind == KIND_BATHYMETRY )
555 anIsBathymetry = true;
556 else if( anObjectKind == KIND_OBSTACLE )
558 else if( anObjectKind == KIND_STRICKLER_TABLE )
559 anIsStricklerTable = true;
560 else if( anObjectKind == KIND_LAND_COVER_MAP )
561 anIsLandCoverMap = true;
562 else if (anObjectKind == KIND_BC_POLYGON)
563 anIsBCPolygon = true;
564 else if( anObjectKind == KIND_STREAM )
567 Handle(HYDROData_Stream) aStream =
568 Handle(HYDROData_Stream)::DownCast( anObject );
569 if ( !aStream.IsNull() )
570 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
572 else if( anObjectKind == KIND_CHANNEL )
574 else if( anObjectKind == KIND_DIGUE )
576 else if( anObjectKind == KIND_DUMMY_3D )
577 anIsDummyObject3D = true;
578 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLIT_GROUP )
582 if ( !anIsObjectCanBeColored )
583 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
586 // Check if all selected objects are profiles
587 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
588 ( aNbOfSelectedProfiles == aSeq.Length() );
590 // check the selected partitions
591 if( !anIsSelectedDataObjects && anIsObjectBrowser )
593 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
594 if( aSelectedPartition != KIND_UNKNOWN )
596 switch( aSelectedPartition )
599 theMenu->addAction( action( ImportImageId ) );
601 case KIND_BATHYMETRY:
602 theMenu->addAction( action( ImportBathymetryId ) );
604 case KIND_ARTIFICIAL_OBJECT:
605 theMenu->addAction( action( CreateChannelId ) );
606 theMenu->addAction( action( CreateDigueId ) );
608 case KIND_NATURAL_OBJECT:
609 theMenu->addAction( action( CreateImmersibleZoneId ) );
610 theMenu->addAction( action( CreateStreamId ) );
613 theMenu->addAction( action( ImportObstacleFromFileId ) );
614 theMenu->addAction( action( CreateBoxId ) );
615 theMenu->addAction( action( CreateCylinderId ) );
617 case KIND_STRICKLER_TABLE:
618 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
620 case KIND_LAND_COVER_MAP:
621 theMenu->addAction( action( CreateLandCoverMapId ) );
622 theMenu->addAction( action( ImportLandCoverMapId ) );
624 case KIND_CALCULATION:
625 theMenu->addAction( action( CreateCalculationId ) );
627 case KIND_POLYLINEXY:
628 theMenu->addAction( action( ImportPolylineId ) );
629 theMenu->addAction( action( CreatePolylineId ) );
632 theMenu->addAction( action( CreatePolyline3DId ) );
633 theMenu->addAction( action( ImportPolylineId ) );
636 theMenu->addAction( action( CreateProfileId ) );
637 theMenu->addAction( action( ImportProfilesId ) );
638 theMenu->addAction( action( AllGeoreferencementId ) );
640 case KIND_VISUAL_STATE:
641 theMenu->addAction( action( SaveVisualStateId ) );
643 case KIND_BC_POLYGON:
644 theMenu->addAction( action( ImportBCPolygonId ) );
647 theMenu->addSeparator();
651 Handle(HYDROData_CalculationCase) aCalcCase;
653 HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
654 if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
655 theMenu->addAction( action( RegenerateRegionColorsId ) );
659 if( anIsSelectedDataObjects )
661 if ( anIsMustObjectBeUpdated )
663 theMenu->addAction( action( UpdateObjectId ) );
664 theMenu->addSeparator();
668 theMenu->addAction( action( ForcedUpdateObjectId ) );
669 theMenu->addSeparator();
673 if( aSeq.Length() == 1 )
677 if( anIsImportedImage )
678 theMenu->addAction( action( EditImportedImageId ) );
679 else if( anIsImageHasRefs )
682 theMenu->addAction( action( EditFusedImageId ) );
683 else if( anIsCutImage )
684 theMenu->addAction( action( EditCutImageId ) );
685 else if( anIsSplitImage )
686 theMenu->addAction( action( EditSplitImageId ) );
689 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
690 theMenu->addAction( action( ExportImageId ) );
691 theMenu->addSeparator();
693 if( anIsImageHasRefs )
695 theMenu->addAction( action( RemoveImageRefsId ) );
696 theMenu->addSeparator();
699 theMenu->addAction( action( FuseImagesId ) );
700 theMenu->addAction( action( CutImagesId ) );
701 theMenu->addAction( action( SplitImageId ) );
702 theMenu->addSeparator();
703 theMenu->addAction( action( RecognizeContoursId ) );
704 theMenu->addSeparator();
706 else if( anIsBathymetry )
708 theMenu->addAction( action( EditImportedBathymetryId ) );
709 theMenu->addAction( action( BathymetryBoundsId ) );
710 theMenu->addSeparator();
712 else if( anIsPolyline )
714 theMenu->addAction( action( EditPolylineId ) );
715 theMenu->addSeparator();
716 theMenu->addAction( action( SplitPolylinesId ) );
717 theMenu->addAction( action( MergePolylinesId ) );
718 theMenu->addSeparator();
719 theMenu->addAction( action( ShowAttrPolylinesId ) );
720 theMenu->addSeparator();
722 else if( anIsPolyline3D )
724 theMenu->addAction( action( EditPolyline3DId ) );
725 theMenu->addSeparator();
727 else if( anIsProfile )
729 theMenu->addAction( action( EditProfileId ) );
730 theMenu->addAction( action( SelectedGeoreferencementId ) );
731 theMenu->addSeparator();
733 else if( anIsCalculation )
735 theMenu->addAction( action( EditCalculationId ) );
736 theMenu->addAction( action( ExportCalculationId ) );
737 theMenu->addAction( action( CompleteCalculationId ) );
738 theMenu->addSeparator();
740 else if( anIsImmersibleZone )
742 theMenu->addAction( action( EditImmersibleZoneId ) );
743 theMenu->addSeparator();
745 else if( anIsStream )
747 theMenu->addAction( action( EditStreamId ) );
748 if ( action( RiverBottomContextId ) )
750 theMenu->addAction( action( RiverBottomContextId ) );
751 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
753 theMenu->addAction( action( ProfileInterpolateId ) );
754 theMenu->addSeparator();
756 else if( anIsChannel )
758 theMenu->addAction( action( EditChannelId ) );
759 theMenu->addSeparator();
763 theMenu->addAction( action( EditDigueId ) );
764 theMenu->addSeparator();
766 else if( anIsObstacle )
768 theMenu->addAction( action( TranslateObstacleId ) );
769 theMenu->addSeparator();
771 else if( anIsStricklerTable )
773 theMenu->addAction( action( EditStricklerTableId ) );
774 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
775 theMenu->addAction( action( DuplicateStricklerTableId ) );
776 theMenu->addSeparator();
778 Handle(HYDROData_StricklerTable) aTable =
779 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
780 QString aCurrentTable =
781 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
782 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
784 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
785 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
786 theMenu->addSeparator();
789 else if( anIsLandCoverMap )
791 theMenu->addAction( action( AddLandCoverId ) );
792 theMenu->addAction( action( RemoveLandCoverId ) );
793 theMenu->addSeparator();
794 theMenu->addAction( action( SplitLandCoverId ) );
795 theMenu->addAction( action( MergeLandCoverId ) );
796 theMenu->addAction( action( ChangeLandCoverTypeId ) );
797 theMenu->addSeparator();
799 theMenu->addAction( action( ExportToShapeFileID ) );
800 theMenu->addSeparator();
802 else if( anIsVisualState && anIsObjectBrowser )
804 theMenu->addAction( action( SaveVisualStateId ) );
805 theMenu->addAction( action( LoadVisualStateId ) );
806 theMenu->addSeparator();
809 theMenu->addAction( action( ZoneSetColorId ) );
810 else if (anIsBCPolygon)
811 theMenu->addAction( action( SetBoundaryTypePolygonId ) );
813 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
815 theMenu->addAction( action( PolylineExtractionId ) );
816 theMenu->addSeparator();
819 // Add set color action for geometrical objects
820 if ( anIsObjectCanBeColored )
822 theMenu->addAction( action( SetColorId ) );
823 theMenu->addSeparator();
826 // Add transparency action for land cover map objects
827 if ( anIsLandCoverMap )
829 theMenu->addAction( action( SetTransparencyId ) );
830 theMenu->addSeparator();
833 else if ( anAllAreProfiles )
835 theMenu->addAction( action( EditProfileId ) );
836 theMenu->addAction( action( SelectedGeoreferencementId ) );
837 theMenu->addSeparator();
840 bool isPoly = anIsPolyline || anIsPolyline3D;
841 if (isPoly && !anIsLandCoverMap)
842 theMenu->addAction( action( ExportToShapeFileID ) );
845 QAction* aCopyAction = action( CopyId );
846 if( aCopyAction && aCopyAction->isEnabled() ) {
847 theMenu->addAction( action( CopyId ) );
848 theMenu->addSeparator();
852 if( !anIsDummyObject3D )
853 theMenu->addAction( action( DeleteId ) );
855 theMenu->addSeparator();
857 if( anIsImage || anIsPolyline || anIsPolyline3D ||
858 anIsImmersibleZone || anIsZone || anIsRegion ||
859 anIsBathymetry || anIsObstacle || anIsStream ||
860 anIsChannel || anIsDigue || anIsDummyObject3D ||
861 anIsValidProfile || anIsGroup || anIsLandCoverMap ||
864 if( anIsHiddenInSelection )
865 theMenu->addAction( action( ShowId ) );
866 theMenu->addAction( action( ShowOnlyId ) );
867 if( anIsVisibleInSelection )
868 theMenu->addAction( action( HideId ) );
869 theMenu->addSeparator();
875 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
876 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
877 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
878 theMenu->addAction( action( DeleteId ) );
880 theMenu->addSeparator();
881 theMenu->addAction( action( SetZLevelId ) );
882 theMenu->addSeparator();
884 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
885 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
886 theMenu->addSeparator();
890 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
892 theMenu->addAction( action( ShowAllId ) );
893 theMenu->addAction( action( HideAllId ) );
894 theMenu->addSeparator();
897 if ( anIsOCCView || anIsVTKView )
899 theMenu->addSeparator();
900 theMenu->addAction( action( CopyViewerPositionId ) );
904 theMenu->addAction( action( EditLocalCSId ) );
906 if( anIsObjectBrowser && anOwners.size()==1 )
908 if( aSeq.Size() > 0 )
910 Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
911 Handle(HYDROData_Object) anObject;
912 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
913 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
915 if (!anAObject.IsNull())
916 anObject = anAObject;
917 if (!aNObject.IsNull())
920 if( !anObject.IsNull() )
922 theMenu->addSeparator();
923 bool IsSubmersible = anObject->IsSubmersible();
926 theMenu->addAction( action( SubmersibleId ) );
927 action( SubmersibleId )->setCheckable(true);
928 action( SubmersibleId )->setChecked(true);
932 theMenu->addAction( action( UnSubmersibleId ) );
933 action( UnSubmersibleId )->setCheckable(true);
934 action( UnSubmersibleId )->setChecked(true);
940 theMenu->addSeparator();
941 QAction* a = action( ShowHideArrows );
942 a->setText( arrowsVisible() ? tr( "HIDE_ARROWS" ) : tr( "SHOW_ARROWS" ) );
943 theMenu->addAction( a );
946 void HYDROGUI_Module::createPreferences()
948 DEBTRACE("HYDROGUI_Module::createPreferences");
949 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
950 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
952 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
953 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
955 // Set property cursor type
956 QList<QVariant> aCursorTypeIndicesList;
957 QList<QVariant> aCursorTypeIconsList;
959 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
960 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
961 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
962 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
963 aCursorTypeIndicesList << i;
964 aCursorTypeIconsList << pixmap;
967 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
968 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
970 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
971 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
972 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
974 addPreference( tr( "PREF_VIEWER_ZOOM_SHUTOFF" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "zoom_shutoff" );
976 addPreference( tr( "PREF_VIEWER_CHAINED_PANNING" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "chained_panning" );
978 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
979 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
980 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
981 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
982 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
983 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
984 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
986 int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
987 int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
988 LightApp_Preferences::Selector, "polyline", "arrow_type" );
990 QList<QVariant> arrow_types;
991 arrow_types.append( tr( "No" ) );
992 arrow_types.append( tr( "Triangle" ) );
993 arrow_types.append( tr( "Cone" ) );
994 setPreferenceProperty( polylineArrow, "strings", arrow_types );
996 QList<QVariant> indices;
1000 setPreferenceProperty( polylineArrow, "indexes", indices );
1001 setPreferenceProperty( polylineArrow, "ids", indices );
1003 int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
1004 LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
1007 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
1009 DEBTRACE("HYDROGUI_Module::preferencesChanged");
1010 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
1011 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
1014 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
1015 if ( resMgr && !aDoc.IsNull() )
1016 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
1018 else if( theSection == "polyline" )
1024 resMgr->value( "polyline", "arrow_type", aType );
1025 resMgr->value( "polyline", "arrow_size", aSize );
1028 ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
1029 for( ; it!=last; it++ )
1031 size_t aViewerId = it.key();
1032 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
1034 getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
1037 else if (theSection == "HYDRO" && thePref == "zoom_shutoff")
1039 bool aZoomShutoff = resMgr->booleanValue( "HYDRO", "zoom_shutoff" );
1040 setAutoZoomToAllViewManagers(!aZoomShutoff);
1042 else if (theSection == "HYDRO" && thePref == "chained_panning")
1044 bool aChainedPan = resMgr->booleanValue( "HYDRO", "chained_panning" );
1047 ViewManagerList aViewManagers = getApp()->viewManagers();
1048 foreach (SUIT_ViewManager* aVMgr, aViewManagers)
1050 OCCViewer_ViewManager* anOCCViewMgr = dynamic_cast<OCCViewer_ViewManager*>( aVMgr );
1052 anOCCViewMgr->setChainedOperations( aChainedPan );
1055 QList<QDockWidget*> docW = getApp()->desktop()->findChildren<QDockWidget*>();
1056 foreach (QDockWidget* qw, docW)
1058 HYDROGUI_ProfileDlg* pdlg = dynamic_cast<HYDROGUI_ProfileDlg*>(qw);
1060 pdlg->viewManager()->setChainedOperations(aChainedPan);
1064 LightApp_Module::preferencesChanged( theSection, thePref );
1067 QCursor HYDROGUI_Module::getPrefEditCursor() const
1069 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
1070 if ( aCursorType >= Qt::BlankCursor)
1072 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
1076 void HYDROGUI_Module::update( const int flags )
1078 DEBTRACE("HYDROGUI_Module::update");
1079 if ( !isUpdateEnabled() )
1082 QApplication::setOverrideCursor( Qt::WaitCursor );
1084 // To prevent calling this method recursively
1085 // from one of the methods called below
1086 setUpdateEnabled( false );
1088 // store selected objects
1089 QStringList aSelectedEntries = storeSelection();
1091 bool aDoFitAll = flags & UF_FitAll;
1094 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1095 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
1098 if( ( flags & UF_Viewer ) )
1099 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
1101 if( ( flags & UF_OCCViewer ) )
1102 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
1104 if( ( flags & UF_VTKViewer ) )
1105 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
1107 if( ( flags & UF_Model ) && getDataModel() && getApp() )
1109 getDataModel()->update( getStudyId() );
1111 // Temporary workaround to prevent breaking
1112 // the selection in the object browser.
1113 // Note: processEvents() should be called after updateGV(),
1114 // otherwise the application crashes from time to time.
1115 //RKV: qApp->processEvents();
1116 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1117 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
1118 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
1119 if ( isResizeOnExpandItem && anObjectBrowser ) {
1120 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
1122 getApp()->updateObjectBrowser( true );
1123 if ( isResizeOnExpandItem && anObjectBrowser ) {
1124 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
1128 // Object browser is currently updated by using UF_Model flag
1129 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
1130 getApp()->updateObjectBrowser( true );
1132 if( ( flags & UF_Controls ) && getApp() )
1133 getApp()->updateActions();
1135 // restore selected objects
1136 restoreSelection( aSelectedEntries );
1138 setUpdateEnabled( true );
1140 preferencesChanged( "HYDRO", "zoom_shutoff" );
1142 preferencesChanged( "HYDRO", "chained_panning" );
1144 QApplication::restoreOverrideCursor();
1147 void HYDROGUI_Module::updateCommandsStatus()
1149 DEBTRACE("HYDROGUI_Module::updateCommandsStatus");
1150 LightApp_Module::updateCommandsStatus();
1152 updateUndoRedoControls();
1154 action( CopyId )->setEnabled( getDataModel()->canCopy() );
1155 action( PasteId )->setEnabled( getDataModel()->canPaste() );
1158 void HYDROGUI_Module::selectionChanged()
1160 DEBTRACE("HYDROGUI_Module::selectionChanged");
1161 LightApp_Module::selectionChanged();
1162 updateCommandsStatus();
1165 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1167 //DEBTRACE("HYDROGUI_Module::getDataModel()");
1168 return (HYDROGUI_DataModel*)dataModel();
1171 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1173 //DEBTRACE("HYDROGUI_Module::getDisplayer()");
1177 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1179 DEBTRACE("HYDROGUI_Module::getOCCDisplayer");
1180 return myOCCDisplayer;
1183 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1185 DEBTRACE("HYDROGUI_Module::getVTKDisplayer");
1186 return myVTKDisplayer;
1189 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const size_t theId ) const
1191 DEBTRACE("HYDROGUI_Module::getViewManager " << theId);
1192 if( myViewManagerMap.contains( theId ) )
1194 return myViewManagerMap[ theId ].first;
1199 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const size_t theId ) const
1201 DEBTRACE("HYDROGUI_Module::getViewer " << theId);
1202 if( myViewManagerMap.contains( theId ) )
1204 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1205 GraphicsView_ViewManager* aViewManager =
1206 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1208 return aViewManager->getViewer();
1213 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const size_t theId ) const
1215 DEBTRACE("HYDROGUI_Module::getOCCViewer " << theId);
1216 if( myViewManagerMap.contains( theId ) )
1218 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1219 OCCViewer_ViewManager* aViewManager =
1220 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1222 return aViewManager->getOCCViewer();
1227 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const size_t theId ) const
1229 DEBTRACE("HYDROGUI_Module::getVTKViewer " << theId);
1230 if( myViewManagerMap.contains( theId ) )
1232 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1233 SVTK_ViewManager* aViewManager =
1234 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1236 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1241 size_t HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1243 DEBTRACE("HYDROGUI_Module::getViewManagerId");
1244 ViewManagerMapIterator anIter( myViewManagerMap );
1245 while( anIter.hasNext() )
1247 size_t anId = anIter.next().key();
1248 const ViewManagerInfo& anInfo = anIter.value();
1249 if( anInfo.first == theViewManager )
1255 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1257 DEBTRACE("HYDROGUI_Module::getViewManagerRole");
1258 size_t anId = getViewManagerId( theViewManager );
1261 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1262 return anInfo.second;
1267 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1268 const ViewManagerRole theRole )
1270 DEBTRACE("HYDROGUI_Module::setViewManagerRole");
1271 size_t anId = getViewManagerId( theViewManager );
1274 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1275 anInfo.second = theRole;
1279 bool HYDROGUI_Module::isObjectVisible( const size_t theViewId,
1280 const Handle(HYDROData_Entity)& theObject ) const
1282 if( theObject.IsNull() )
1285 if( theViewId == 0 )
1288 foreach( size_t aViewId, myObjectStateMap.keys() )
1290 if( isObjectVisible( aViewId, theObject ) )
1296 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1297 if( anIter1 != myObjectStateMap.end() )
1299 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1300 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1302 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1303 if( anIter2 != aEntry2ObjectStateMap.end() )
1305 const ObjectState& anObjectState = anIter2.value();
1306 return anObjectState.Visibility;
1312 void HYDROGUI_Module::setObjectVisible( const size_t theViewId,
1313 const Handle(HYDROData_Entity)& theObject,
1314 const bool theState )
1316 DEBTRACE("setObjectVisible, theViewId: " << theViewId);
1317 if( !theObject.IsNull() )
1319 DEBTRACE("myObjectStateMap.size: " << myObjectStateMap.size());
1320 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1321 DEBTRACE("anEntry: " << anEntry.toStdString());
1322 if (myObjectStateMap.find(theViewId) == myObjectStateMap.end())
1324 DEBTRACE("theViewId is not a valid key for myObjectStateMap");
1328 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ]; // created OK if it does not exist
1329 DEBTRACE("myObjectStateMap key created");
1331 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1332 anObjectState.Visibility = theState;
1335 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1338 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1341 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1342 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1343 if ( visState != Qtx::UnpresentableState )
1344 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1348 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1349 setLandCoversScalarMapModeOff( theViewId );
1350 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1351 getOCCDisplayer()->SetToUpdateColorScale();
1356 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1357 const bool theState )
1359 DEBTRACE("HYDROGUI_Module::setIsToUpdate");
1360 if( !theObject.IsNull() )
1362 // Process OCC shapes
1363 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1364 while( aShapesMapIter != myShapesMap.end() )
1366 const ListOfShapes& aShapesList = aShapesMapIter.value();
1367 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1369 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1371 aShape->setIsToUpdate( theState );
1376 // Process VTK shapes
1377 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1378 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1380 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1381 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1383 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1385 aShape->setIsToUpdate( theState );
1393 /////////////////// OCC SHAPES PROCESSING
1394 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const size_t theViewId,
1395 ObjectKind theKind ) const
1397 QList<HYDROGUI_Shape*> aResult;
1399 if ( myShapesMap.contains( theViewId ) )
1401 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1402 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1404 if( aShape && aShape->getObject()->GetKind()==theKind )
1405 aResult.append( aShape );
1411 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const size_t theViewId,
1412 const Handle(HYDROData_Entity)& theObject ) const
1414 HYDROGUI_Shape* aResShape = NULL;
1415 if( theObject.IsNull() )
1418 if ( myShapesMap.contains( theViewId ) )
1420 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1421 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1423 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1434 void HYDROGUI_Module::setObjectShape( const size_t theViewId,
1435 const Handle(HYDROData_Entity)& theObject,
1436 HYDROGUI_Shape* theShape )
1438 if( theObject.IsNull() )
1441 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1442 aViewShapes.append( theShape );
1445 void HYDROGUI_Module::removeObjectShape( const size_t theViewId,
1446 const Handle(HYDROData_Entity)& theObject )
1448 if ( !myShapesMap.contains( theViewId ) )
1451 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1452 Handle(HYDROData_Entity) anObject;
1453 for ( int i = 0; i < aViewShapes.length(); )
1455 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1456 anObject = aShape->getObject();
1457 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1460 aViewShapes.removeAt( i );
1468 void HYDROGUI_Module::removeViewShapes( const size_t theViewId )
1470 if ( !myShapesMap.contains( theViewId ) )
1473 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1474 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1476 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1481 myShapesMap.remove( theViewId );
1483 /////////////////// END OF OCC SHAPES PROCESSING
1485 /////////////////// VTKPrs PROCESSING
1486 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const size_t theViewId,
1487 const Handle(HYDROData_Entity)& theObject ) const
1489 HYDROGUI_VTKPrs* aResShape = NULL;
1490 if( theObject.IsNull() )
1493 if ( myVTKPrsMap.contains( theViewId ) )
1495 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1496 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1498 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1509 void HYDROGUI_Module::setObjectVTKPrs( const size_t theViewId,
1510 const Handle(HYDROData_Entity)& theObject,
1511 HYDROGUI_VTKPrs* theShape )
1513 if( theObject.IsNull() )
1516 if( theShape && theShape->needScalarBar() )
1518 // Compute the new global Z range from the added presentation and the old global Z range.
1519 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1520 double* aRange = theShape->getInternalZRange();
1521 bool anIsUpdate = false;
1522 if ( aRange[0] < aGlobalRange[0] )
1524 aGlobalRange[0] = aRange[0];
1527 if ( aRange[1] > aGlobalRange[1] )
1529 aGlobalRange[1] = aRange[1];
1535 updateVTKZRange( theViewId, aGlobalRange );
1539 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1540 aViewShapes.append( theShape );
1543 void HYDROGUI_Module::removeObjectVTKPrs( const size_t theViewId,
1544 const QString& theEntry )
1546 if ( !myVTKPrsMap.contains( theViewId ) )
1549 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1550 Handle(HYDROData_Entity) anObject;
1552 for ( int i = 0; i < aViewShapes.length(); )
1554 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1555 anObject = aShape->getObject();
1556 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1557 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1560 aViewShapes.removeAt( i );
1567 // Invalidate global Z range
1568 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1569 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1572 void HYDROGUI_Module::removeObjectVTKPrs( const size_t theViewId,
1573 const Handle(HYDROData_Entity)& theObject )
1575 if ( !myVTKPrsMap.contains( theViewId ) )
1578 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1579 Handle(HYDROData_Entity) anObject;
1580 for ( int i = 0; i < aViewShapes.length(); )
1582 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1583 anObject = aShape->getObject();
1584 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1587 aViewShapes.removeAt( i );
1594 // Invalidate global Z range
1595 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1596 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1599 void HYDROGUI_Module::removeViewVTKPrs( const size_t theViewId )
1601 if ( !myVTKPrsMap.contains( theViewId ) )
1604 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1605 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1607 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1612 myVTKPrsMap.remove( theViewId );
1615 void HYDROGUI_Module::updateVTKZRange( const size_t theViewId, double theRange[] )
1617 if ( myVTKPrsMap.contains( theViewId ) )
1619 // For the given viewer id update all VTK presentations ...
1620 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1621 HYDROGUI_VTKPrs* aShape;
1622 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1624 aShape = aViewShapes.at( i );
1625 if ( aShape && aShape->needScalarBar() )
1627 aShape->setZRange( theRange );
1631 // ... and update the global color legend scalar bar.
1632 getVTKDisplayer()->SetZRange( theViewId, theRange );
1634 /////////////////// END OF VTKPrs PROCESSING
1636 void HYDROGUI_Module::clearCache()
1638 DEBTRACE("HYDROGUI_Module::clearCache");
1639 myObjectStateMap.clear();
1642 CAM_DataModel* HYDROGUI_Module::createDataModel()
1644 DEBTRACE("HYDROGUI_Module::createDataModel");
1645 return new HYDROGUI_DataModel( this );
1648 void HYDROGUI_Module::customEvent( QEvent* e )
1650 int aType = e->type();
1651 if ( aType == NewViewEvent )
1653 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1654 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1656 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1658 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1659 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1661 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1663 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1664 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1666 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1667 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1668 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1670 //ouv: temporarily commented
1671 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1674 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1675 update( UF_Viewer );
1677 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1683 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1685 QEvent::Type aType = theEvent->type();
1686 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1688 if( aType == QEvent::Show )
1690 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1691 e->setData( theObj );
1692 QApplication::postEvent( this, e );
1693 theObj->removeEventFilter( this );
1696 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1698 if( aType == QEvent::Leave )
1700 SUIT_Desktop* aDesktop = getApp()->desktop();
1701 if ( aDesktop && aDesktop->statusBar() ) {
1702 aDesktop->statusBar()->clearMessage();
1706 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1708 if( aType == QEvent::Leave )
1710 SUIT_Desktop* aDesktop = getApp()->desktop();
1711 if ( aDesktop && aDesktop->statusBar() ) {
1712 aDesktop->statusBar()->clearMessage();
1717 return LightApp_Module::eventFilter( theObj, theEvent );
1720 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1722 DEBTRACE("HYDROGUI_Module::onViewManagerAdded");
1723 LightApp_Module::onViewManagerAdded( theViewManager );
1725 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1727 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1728 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1730 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1732 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1733 //mgr->setChainedOperations( true );
1735 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1736 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1737 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1738 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1739 connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
1740 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1742 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1744 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1745 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1746 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1747 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1750 createSelector( theViewManager ); // replace the default selector
1752 ViewManagerInfo anInfo( theViewManager, VMR_General );
1753 myViewManagerMap.insert( ViewManagerId++, anInfo );
1756 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1758 DEBTRACE("HYDROGUI_Module::onViewManagerRemoved");
1759 LightApp_Module::onViewManagerRemoved( theViewManager );
1761 createSelector( theViewManager ); // replace the default selector
1763 size_t anId = getViewManagerId( theViewManager );
1766 OCCViewer_ViewManager* anOCCViewManager =
1767 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1768 if ( anOCCViewManager )
1770 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1771 if ( anOCCViewer ) {
1772 size_t aViewerId = (size_t)anOCCViewer;
1773 removeViewShapes( aViewerId );
1774 setLandCoversScalarMapModeOff( aViewerId );
1778 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1780 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1783 getVTKDisplayer()->EraseScalarBar( anId, true );
1784 removeViewShapes( (size_t)aVTKViewer );
1788 myViewManagerMap.remove( anId );
1792 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1794 DEBTRACE("HYDROGUI_Module::onViewCreated");
1795 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1797 DEBTRACE("theViewWindow->inherits( 'GraphicsView_ViewFrame' )");
1798 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1801 aViewFrame->installEventFilter( this );
1803 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1804 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1806 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1807 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1810 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1812 DEBTRACE("theViewWindow->inherits( 'OCCViewer_ViewFrame' )");
1813 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1816 aViewFrame->onTopView();
1818 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1819 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1821 aViewPort->installEventFilter( this );
1825 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1827 DEBTRACE("theViewWindow->inherits( 'SVTK_ViewWindow' )");
1828 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1831 aViewFrame->installEventFilter( this );
1836 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1838 /* ouv: currently unused
1839 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1841 SUIT_ViewManager* aViewManager = 0;
1843 QObject* aParent = aViewPort;
1844 while( aParent = aParent->parent() )
1846 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1848 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1850 aViewManager = aViewer->getViewManager();
1859 double aMouseX = theEvent->scenePos().x();
1860 double aMouseY = theEvent->scenePos().y();
1862 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1863 if( aRole == VMR_General )
1865 int aXDeg = 0, aYDeg = 0;
1866 int aXMin = 0, aYMin = 0;
1867 double aXSec = 0, aYSec = 0;
1868 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1869 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1871 QString aDegSymbol( QChar( 0x00B0 ) );
1872 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1873 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1875 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1877 else if( aRole == VMR_TransformImage )
1878 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1883 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1884 const bool theIsInit,
1885 const bool theIsForced,
1886 const bool theDoFitAll )
1888 DEBTRACE("HYDROGUI_Module::updateViewer");
1889 QList<size_t> aViewManagerIdList;
1891 // currently, all views are updated
1892 ViewManagerMapIterator anIter( myViewManagerMap );
1893 while( anIter.hasNext() )
1895 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1897 if ( theDisplayer->IsApplicable( aViewManager ) )
1899 int anId = anIter.key();
1900 aViewManagerIdList.append( anId );
1904 QListIterator<size_t> anIdIter( aViewManagerIdList );
1905 while( anIdIter.hasNext() )
1907 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1908 myOverview->setTopView();
1912 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1914 DEBTRACE("HYDROGUI_Module::createSelector");
1915 if( !theViewManager )
1918 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1919 if( !aSelectionMgr )
1922 QString aViewType = theViewManager->getType();
1923 DEBTRACE("aViewType " << aViewType.toStdString() << " " << GraphicsView_Viewer::Type().toStdString() << " " << OCCViewer_Viewer::Type().toStdString());
1924 if( aViewType != GraphicsView_Viewer::Type() &&
1925 aViewType != OCCViewer_Viewer::Type())
1928 QList<SUIT_Selector*> aSelectorList;
1929 aSelectionMgr->selectors( aViewType, aSelectorList );
1931 // disable all alien selectors
1934 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1935 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1937 SUIT_Selector* aSelector = *anIter;
1941 DEBTRACE("Selector " << aSelector->type().toStdString());
1942 if (dynamic_cast<HYDROGUI_GVSelector*>( aSelector ))
1946 DEBTRACE("HYDROGUI_GVSelector");
1948 else if (dynamic_cast<SVTK_Selector*>( aSelector ))
1951 DEBTRACE("SVTK_Selector");
1953 else if (dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ))
1957 DEBTRACE("HYDROGUI_OCCSelector");
1961 DEBTRACE("Selector enabled " << aSelector->type().toStdString());
1962 aSelector->setEnabled( true );
1966 DEBTRACE("Selector disabled " << aSelector->type().toStdString());
1967 aSelector->setEnabled( false );
1972 if ( !isGV && aViewType == GraphicsView_Viewer::Type() )
1974 GraphicsView_ViewManager* aViewManager =
1975 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1978 HYDROGUI_GVSelector* sel = new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1979 DEBTRACE("new HYDROGUI_GVSelector " << sel << " " << sel->type().toStdString());
1980 sel->setEnabled( true );
1983 else if ( !isOCC && aViewType == OCCViewer_Viewer::Type() )
1985 OCCViewer_ViewManager* aViewManager =
1986 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1989 HYDROGUI_OCCSelector* sel = new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1990 DEBTRACE("new HYDROGUI_OCCSelector " << sel << " " << sel->type().toStdString());
1991 sel->setEnabled( true );
1996 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1998 DEBTRACE("HYDROGUI_Module::setUpdateEnabled");
1999 bool aPrevState = myIsUpdateEnabled;
2000 myIsUpdateEnabled = theState;
2004 bool HYDROGUI_Module::isUpdateEnabled() const
2006 return myIsUpdateEnabled;
2009 QStringList HYDROGUI_Module::storeSelection() const
2011 DEBTRACE("HYDROGUI_Module::storeSelection");
2012 QStringList anEntryList;
2013 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
2015 SUIT_DataOwnerPtrList aList( true );
2016 aSelectionMgr->selected( aList );
2018 SUIT_DataOwnerPtrList::iterator anIter;
2019 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
2021 const LightApp_DataOwner* anOwner =
2022 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
2024 anEntryList.append( anOwner->entry() );
2030 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
2032 DEBTRACE("HYDROGUI_Module::restoreSelection");
2033 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
2035 SUIT_DataOwnerPtrList aList( true );
2036 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
2037 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
2038 aSelectionMgr->setSelected( aList );
2042 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
2045 bool doShow = false;
2046 HYDROGUI_Displayer* aDisplayer = getDisplayer();
2048 aDisplayer->SaveCursorViewPosition( theViewWindow );
2049 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
2053 // Show the coordinates in the status bar
2054 SUIT_Desktop* aDesktop = getApp()->desktop();
2055 if ( aDesktop && aDesktop->statusBar() )
2057 gp_Pnt aWPnt( X, Y, Z );
2058 HYDROData_Document::Document()->Transform( aWPnt, false );
2059 double WX = aWPnt.X(), WY = aWPnt.Y();
2061 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
2062 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
2063 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
2064 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
2065 QString aMsg = tr( "COORDINATES_INFO" );
2066 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
2067 aDesktop->statusBar()->showMessage( aMsg );
2073 * Returns stack of active operations;
2075 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
2077 DEBTRACE("HYDROGUI_Module::getActiveOperations");
2078 return myActiveOperationMap;
2082 * Returns the module active operation. If the active operation is show/hide,
2083 * the method returns the previous operation if it is.
2085 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
2087 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
2089 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
2091 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
2093 aVIt.previous(); // skip the top show/hide operation
2094 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
2101 * \brief Virtual public slot
2103 * This method is called after the object inserted into data view to update their visibility state
2104 * This is default implementation
2106 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
2108 if ( !isActiveModule() )
2111 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
2113 // change visibility of object
2114 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
2117 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
2119 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
2120 Qtx::VisibilityState visState = treeModel->visibilityState( id );
2121 if ( visState == Qtx::UnpresentableState )
2124 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
2125 treeModel->setVisibilityState( id, visState );
2127 bool vis = visState == Qtx::ShownState;
2128 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
2131 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
2133 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
2136 bool HYDROGUI_Module::isDraggable( const SUIT_DataObject* what ) const
2141 bool HYDROGUI_Module::isDropAccepted( const SUIT_DataObject* where ) const
2147 void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
2148 const int row, Qt::DropAction action )
2150 if ( action != Qt::CopyAction && action != Qt::MoveAction )
2156 if (where->level() < 2 )
2159 DataObjectList::ConstIterator it = what.constBegin();
2160 for (;it != what.constEnd();++it)
2162 if ((*it)->parent() != where)
2166 it = what.constBegin();
2169 for (;it != what.constEnd();++it)
2171 SUIT_DataObject* objWhat = *it;
2173 DataObjectList objInSect = where->children();
2175 //std::list<SUIT_DataObject*> t1 = where->children().toStdList(); //debug
2176 int ind = objInSect.indexOf(objWhat);
2179 HYDROGUI_DataModel* aModel = getDataModel();
2188 where->moveChildPos(objWhat, pos);
2189 //std::list<SUIT_DataObject*> t2 = where->children().toStdList(); //debug
2193 getApp()->updateObjectBrowser(true);
2197 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const size_t theViewId ) const
2199 Handle(HYDROData_StricklerTable) aTable;
2201 if ( myLandCoverColoringMap.contains( theViewId ) ) {
2202 aTable = myLandCoverColoringMap.value( theViewId );
2208 void HYDROGUI_Module::setLandCoverColoringTable( const size_t theViewId,
2209 const Handle(HYDROData_StricklerTable)& theTable )
2211 if ( !theTable.IsNull() && theViewId ) {
2212 myLandCoverColoringMap.insert( theViewId, theTable );
2216 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const size_t theViewId )
2218 myLandCoverColoringMap.remove( theViewId );
2221 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const size_t theViewId ) const
2223 return myLandCoverColoringMap.contains( theViewId );
2226 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
2228 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
2232 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
2233 Handle(HYDROData_StricklerTable) aTable =
2234 Handle(HYDROData_StricklerTable)::DownCast( theObject );
2235 QMutableMapIterator<size_t, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
2236 while ( anIter.hasNext() ) {
2237 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
2238 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
2245 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
2247 DEBTRACE("HYDROGUI_Module::onViewActivated");
2251 SUIT_ViewWindow* wnd = theMgr->getActiveView();
2252 OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
2256 myOverview->setMainView( occwnd );
2259 void HYDROGUI_Module::setAutoZoomToAllViewManagers(bool bAutoZoom)
2261 ViewManagerList aViewManagers = getApp()->viewManagers();
2262 foreach (SUIT_ViewManager* aVMgr, aViewManagers)
2263 setAutoZoom(aVMgr, bAutoZoom);
2266 void HYDROGUI_Module::setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom)
2270 QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
2271 foreach (SUIT_ViewWindow* aView, aViews)
2275 OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
2278 anOCCViewFrame->setAutomaticZoom(bAutoZoom);
2279 for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
2281 OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
2283 aV->setAutomaticZoom(bAutoZoom);
2286 OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
2287 if (anOCCViewWindow)
2288 anOCCViewWindow->setAutomaticZoom(bAutoZoom);