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_Operation.h"
34 #include "HYDROGUI_PrsImage.h"
35 #include "HYDROGUI_Tool.h"
36 #include "HYDROGUI_Tool2.h"
37 #include "HYDROGUI_UpdateFlags.h"
38 #include "HYDROGUI_Shape.h"
39 #include "HYDROGUI_VTKPrs.h"
40 #include "HYDROGUI_VTKPrsDisplayer.h"
41 #include "HYDROGUI_AbstractDisplayer.h"
42 #include "HYDROGUI_PolylineOp.h"
43 #include "HYDROGUI_SetColorOp.h"
44 #include "HYDROGUI_ImportGeomObjectOp.h"
45 #include "HYDROGUI_ShowHideOp.h"
46 #include "HYDROGUI_Overview.h"
47 #include <HYDROGUI_ProfileDlg.h>
48 #include <HYDROGUI_SIProgressIndicator.h>
49 #include <HYDROGUI_ZIProgressIndicator.h>
50 #include <HYDROData_Tool.h>
51 #include <HYDROData_Image.h>
52 #include <HYDROData_Stream.h>
53 #include <HYDROData_Profile.h>
54 #include <HYDROData_Lambert93.h>
55 #include <HYDROData_Polyline3D.h>
56 #include <HYDROData_StricklerTable.h>
57 #include <HYDROData_ArtificialObject.h>
58 #include <HYDROData_NaturalObject.h>
60 #include <HYDROData_OperationsFactory.h>
62 #include <CurveCreator_Utils.hxx>
64 #include <GraphicsView_ViewFrame.h>
65 #include <GraphicsView_ViewManager.h>
66 #include <GraphicsView_ViewPort.h>
67 #include <GraphicsView_Viewer.h>
69 #include <ImageComposer_CutOperator.h>
70 #include <ImageComposer_CropOperator.h>
71 #include <ImageComposer_FuseOperator.h>
73 #include <LightApp_Application.h>
74 #include <LightApp_DataOwner.h>
75 #include <LightApp_GVSelector.h>
76 #include <LightApp_SelectionMgr.h>
77 #include <LightApp_UpdateFlags.h>
79 #include <SalomeApp_Study.h>
81 #include <OCCViewer_ViewFrame.h>
82 #include <OCCViewer_ViewManager.h>
83 #include <OCCViewer_ViewModel.h>
85 #include <SALOME_Event.h>
87 #include <SUIT_DataBrowser.h>
88 #include <SUIT_DataObject.h>
89 #include <SUIT_ViewManager.h>
90 #include <SUIT_ResourceMgr.h>
91 #include <SUIT_Desktop.h>
92 #include <SUIT_Study.h>
93 #include <SUIT_Session.h>
95 #include <SVTK_ViewManager.h>
96 #include <SVTK_ViewModel.h>
97 #include <SVTK_ViewWindow.h>
98 #include <SVTK_Selector.h>
100 #include <OCCViewer_ViewPort3d.h>
102 #include <GEOMUtils.hxx>
103 #include <GeometryGUI.h>
105 #include <SALOMEDS_wrap.hxx>
108 #include <QApplication>
109 #include <QGraphicsSceneMouseEvent>
111 #include <QMouseEvent>
112 #include <QStatusBar>
116 #include "HYDRO_trace.hxx"
118 static size_t ViewManagerId = 1;
120 extern "C" HYDRO_EXPORT CAM_Module* createModule()
122 return new HYDROGUI_Module();
125 extern "C" HYDRO_EXPORT char* getModuleVersion()
127 return (char*)HYDRO_VERSION;
130 HYDROGUI_Module::HYDROGUI_Module()
131 : LightApp_Module( "HYDRO" ),
134 myIsUpdateEnabled( true ),
137 DEBTRACE("HYDROGUI_Module::HYDROGUI_Module()");
140 HYDROGUI_Module::~HYDROGUI_Module()
142 DEBTRACE("HYDROGUI_Module::~HYDROGUI_Module()");
145 int HYDROGUI_Module::getStudyId() const
147 DEBTRACE("HYDROGUI_Module::getStudyId()");
148 LightApp_Application* anApp = getApp();
149 return anApp ? anApp->activeStudy()->id() : 0;
152 void HYDROGUI_Module::initialize( CAM_Application* theApp )
154 DEBTRACE("HYDROGUI_Module::initialize");
155 LightApp_Module::initialize( theApp );
158 createUndoRedoActions();
163 setMenuShown( false );
164 setToolShown( false );
166 myDisplayer = new HYDROGUI_Displayer( this );
167 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
168 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
170 //HYDROData_Tool::SetSIProgress( new HYDROGUI_SIProgressIndicator( theApp->desktop() ) );
171 //HYDROData_Tool::SetZIProgress( new HYDROGUI_ZIProgressIndicator( theApp->desktop() ) );
174 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
176 DEBTRACE("HYDROGUI_Module::activateModule");
177 bool aRes = LightApp_Module::activateModule( theStudy );
179 LightApp_Application* anApp = getApp();
180 SUIT_Desktop* aDesktop = anApp->desktop();
182 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
184 setMenuShown( true );
185 setToolShown( true );
187 // import Python module that manages HYDRO plugins (need to be here because SalomePyQt API uses active module)
188 PyGILState_STATE gstate = PyGILState_Ensure();
189 PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
190 if ( !pluginsmanager ) {
195 PyObject_CallMethod(pluginsmanager, (char*)"initialize", (char*)"isss", 1, "hydro",
196 tr("MEN_DESK_HYDRO").toUtf8().data(),
197 tr("Python plugins").toUtf8().data());
202 PyGILState_Release(gstate);
203 // end of GEOM plugins loading
205 #ifndef DISABLE_PYCONSOLE
206 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
207 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
210 // Remove defunct view managers from the map.
211 // It's essential to do this before "update( UF_All )" call!
212 QList<size_t> anObsoleteIds;
213 ViewManagerList anAllViewManagers = anApp->viewManagers();
214 ViewManagerList aHydroViewManagers; // view managers created inside the HYDRO module
215 ViewManagerMapIterator anIter( myViewManagerMap );
216 while( anIter.hasNext() ) {
217 size_t anId = anIter.next().key();
218 const ViewManagerInfo& anInfo = anIter.value();
220 aHydroViewManagers << anInfo.first;
222 if ( !anAllViewManagers.contains( anInfo.first ) ) {
223 anObsoleteIds << anId;
226 foreach ( const size_t anId, anObsoleteIds ) {
227 myViewManagerMap.remove( anId );
228 myObjectStateMap.remove( anId );
229 myShapesMap.remove( anId );
230 myVTKPrsMap.remove( anId );
232 // Replace the default selector for all view managers.
233 // Add view managers created outside of HYDRO module to the map.
234 foreach ( SUIT_ViewManager* aViewManager, anAllViewManagers ) {
235 createSelector( aViewManager ); // replace the default selector
236 if ( !aHydroViewManagers.contains( aViewManager ) ) {
237 ViewManagerInfo anInfo( aViewManager, VMR_General );
238 myViewManagerMap.insert( ViewManagerId++, anInfo );
244 updateCommandsStatus();
246 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
248 ViewManagerList anOCCViewManagers;
249 anApp->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
251 foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
253 connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
254 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
255 connect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
256 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
258 OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
261 occ_mgr->setChainedOperations( true );//TODO: via preferences
264 foreach( SUIT_ViewWindow* aViewWindow, aViewManager->getViews() )
266 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWindow );
267 if ( aViewFrame && aViewFrame->getViewPort() )
269 aViewFrame->getViewPort()->installEventFilter( this );
274 preferencesChanged( "HYDRO", "zoom_shutoff" );
276 preferencesChanged( "HYDRO", "chained_panning" );
279 SalomeApp_Study* aStudy =
280 dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
282 SALOMEDS::Study_var aDSStudy = GeometryGUI::getStudyServant();
283 GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
284 if ( !aGeomEngine->_is_nil() && !aGeomEngine->_is_nil() ) {
285 SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder();
286 SALOMEDS::SComponent_wrap GEOM_var = aDSStudy->FindComponent( "GEOM" );
287 if( !GEOM_var->_is_nil() ) {
288 aStudyBuilder->LoadWith( GEOM_var, aGeomEngine );
294 // SUIT_DataBrowser* ob = getApp()->objectBrowser();
295 // SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
296 // treeModel->setAppropriate( SUIT_DataObject::VisibilityId, Qtx::Toggled );
301 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
303 DEBTRACE("HYDROGUI_Module::deactivateModule");
305 ViewManagerMapIterator anIter( myViewManagerMap );
306 while( anIter.hasNext() )
307 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
308 getApp()->removeViewManager( aViewManager );
309 myViewManagerMap.clear();
312 ViewManagerList anOCCViewManagers;
313 getApp()->viewManagers( OCCViewer_Viewer::Type(), anOCCViewManagers );
314 foreach ( SUIT_ViewManager* aViewManager, anOCCViewManagers )
316 disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
317 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
318 disconnect( aViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
319 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
321 OCCViewer_ViewManager* occ_mgr = dynamic_cast<OCCViewer_ViewManager*>( aViewManager );
324 occ_mgr->setChainedOperations( false );
325 setAutoZoom( occ_mgr, true );
330 myObjectStateMap.clear();
335 // clear the status bar
336 SUIT_Desktop* aDesktop = getApp()->desktop();
337 if ( aDesktop && aDesktop->statusBar() ) {
338 aDesktop->statusBar()->clearMessage();
341 // clear the data model's list of copying objects
342 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
344 setMenuShown( false );
345 setToolShown( false );
347 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
349 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
351 myActiveOperationMap.clear();
353 myViewManagerMap.clear();
355 bool ret = LightApp_Module::deactivateModule( theStudy );
359 void HYDROGUI_Module::studyClosed(SUIT_Study* theStudy)
361 DEBTRACE("HYDROGUI_Module::studyClosed");
362 HYDROGUI_Operation::myIsClear = false; // force clear of Zlayers on next study
363 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
368 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
370 DEBTRACE("HYDROGUI_Module::windows");
371 static bool inWindows = false;
376 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
377 #ifndef DISABLE_PYCONSOLE
378 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
380 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
381 theMap.insert( OverviewWindow, Qt::LeftDockWidgetArea );
384 LightApp_Application* app = getApp();
385 if( app && app->getWindow( OverviewWindow )==0 )
387 const_cast<HYDROGUI_Module*>( this )->myOverview =
388 new HYDROGUI_Overview( tr( "OVERVIEW" ), 0, app->desktop() );
389 app->insertDockWindow( OverviewWindow, myOverview );
390 app->placeDockWindow( OverviewWindow, Qt::LeftDockWidgetArea );
395 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
397 DEBTRACE("HYDROGUI_Module::viewManagers");
398 theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
401 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
405 HYDROGUI_DataModel* aModel = getDataModel();
407 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
408 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
409 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
410 bool anIsVTKView = theClient == SVTK_Viewer::Type();
411 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
414 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
416 bool anIsSelectedDataObjects = false;
417 bool anIsVisibleInSelection = false;
418 bool anIsHiddenInSelection = false;
420 bool anIsImage = false;
421 bool anIsImportedImage = false;
422 bool anIsImageHasRefs = false;
423 bool anIsFusedImage = false;
424 bool anIsCutImage = false;
425 bool anIsSplitImage = false;
426 bool anIsMustObjectBeUpdated = false;
427 bool anIsPolyline = false;
428 bool anIsPolyline3D = false;
429 bool anIsProfile = false;
430 bool anIsValidProfile = false;
431 bool anAllAreProfiles = false;
432 bool anIsBathymetry = false;
433 bool anIsCalculation = false;
434 bool anIsImmersibleZone = false;
435 bool anIsVisualState = false;
436 bool anIsRegion = false;
437 bool anIsZone = false;
438 bool anIsObstacle = false;
439 bool anIsStricklerTable = false;
440 bool anIsLandCoverMap = false;
441 bool anIsStream = false;
442 bool anIsChannel = false;
443 bool anIsDigue = false;
444 bool anIsDummyObject3D = false;
445 bool anIsGroup = false;
446 bool anIsObjectCanBeColored = false;
448 bool isStreamHasBottom = false;
449 bool anIsBCPolygon = false;
451 SUIT_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
452 SUIT_DataOwnerPtrList anOwners;
453 aSelectionMgr->selected( anOwners );
454 if( anIsObjectBrowser && anOwners.size()==1 )
456 QString anEntry = anOwners[0]->keyString();
457 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( getApp()->activeStudy() );
459 isRoot = aStudy->isComponent( anEntry );
462 // Check the selected GEOM objects (take into account the Object Browser only)
463 if ( anIsObjectBrowser ) {
464 QList<GEOM::shape_type> anObstacleTypes =
465 HYDROGUI_ImportGeomObjectOp::getObstacleTypes();
466 QList<GEOM::shape_type> aPolylineTypes =
467 HYDROGUI_ImportGeomObjectOp::getPolylineTypes();
469 bool isCanBeImportedAsObstacle =
470 !HYDROGUI_Tool::GetSelectedGeomObjects( this, anObstacleTypes ).isEmpty();
471 bool isCanBeImportedAsPolyline =
472 !HYDROGUI_Tool::GetSelectedGeomObjects( this, aPolylineTypes ).isEmpty();
474 // Add import as obstacle action
475 if ( isCanBeImportedAsObstacle ) {
476 theMenu->addAction( action( ImportGeomObjectAsObstacleId ) );
478 // Add import as polyline action
479 if ( isCanBeImportedAsPolyline ) {
480 theMenu->addAction( action( ImportGeomObjectAsPolylineId ) );
483 if ( isCanBeImportedAsObstacle || isCanBeImportedAsPolyline ) {
484 theMenu->addSeparator();
488 // check the selected data model objects
489 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
490 int aNbOfSelectedProfiles = 0;
491 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
493 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
494 if( !anObject.IsNull() )
496 anIsSelectedDataObjects = true;
498 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
499 anIsVisibleInSelection |= aVisibility;
500 anIsHiddenInSelection |= !aVisibility;
502 if ( anObject->CanBeUpdated() && anObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
504 anIsMustObjectBeUpdated = true;
507 ObjectKind anObjectKind = anObject->GetKind();
508 if( anObjectKind == KIND_IMAGE )
511 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
512 if( !anImage.IsNull() )
514 anIsImportedImage = anImage->HasLocalPoints();
515 anIsImageHasRefs = anImage->HasReferences();
516 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
518 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
520 QString anOperatorName = anOperator->name();
521 if( anOperatorName == ImageComposer_FuseOperator::Type() )
522 anIsFusedImage = true;
523 else if( anOperatorName == ImageComposer_CutOperator::Type() )
525 else if( anOperatorName == ImageComposer_CropOperator::Type() )
526 anIsSplitImage = true;
531 else if( anObjectKind == KIND_POLYLINEXY )
533 else if( anObjectKind == KIND_POLYLINE )
534 anIsPolyline3D = true;
535 else if( anObjectKind == KIND_PROFILE )
538 aNbOfSelectedProfiles++;
540 Handle(HYDROData_Profile) aProfile =
541 Handle(HYDROData_Profile)::DownCast( anObject );
542 if( !aProfile.IsNull() && aProfile->IsValid() ) {
543 anIsValidProfile = true;
546 else if( anObjectKind == KIND_CALCULATION )
547 anIsCalculation = true;
548 else if( anObjectKind == KIND_IMMERSIBLE_ZONE )
549 anIsImmersibleZone = true;
550 else if( anObjectKind == KIND_VISUAL_STATE )
551 anIsVisualState = true;
552 else if( anObjectKind == KIND_REGION )
554 else if( anObjectKind == KIND_ZONE )
556 else if( anObjectKind == KIND_BATHYMETRY )
557 anIsBathymetry = true;
558 else if( anObjectKind == KIND_OBSTACLE )
560 else if( anObjectKind == KIND_STRICKLER_TABLE )
561 anIsStricklerTable = true;
562 else if( anObjectKind == KIND_LAND_COVER_MAP )
563 anIsLandCoverMap = true;
564 else if (anObjectKind == KIND_BC_POLYGON)
565 anIsBCPolygon = true;
566 else if( anObjectKind == KIND_STREAM )
569 Handle(HYDROData_Stream) aStream =
570 Handle(HYDROData_Stream)::DownCast( anObject );
571 if ( !aStream.IsNull() )
572 isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
574 else if( anObjectKind == KIND_CHANNEL )
576 else if( anObjectKind == KIND_DIGUE )
578 else if( anObjectKind == KIND_DUMMY_3D )
579 anIsDummyObject3D = true;
580 else if( anObjectKind == KIND_SHAPES_GROUP || anObjectKind == KIND_SPLIT_GROUP )
584 if ( !anIsObjectCanBeColored )
585 anIsObjectCanBeColored = HYDROGUI_SetColorOp::CanObjectBeColored( anObject, this );
588 // Check if all selected objects are profiles
589 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
590 ( aNbOfSelectedProfiles == aSeq.Length() );
592 // check the selected partitions
593 if( !anIsSelectedDataObjects && anIsObjectBrowser )
595 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
596 if( aSelectedPartition != KIND_UNKNOWN )
598 switch( aSelectedPartition )
601 theMenu->addAction( action( ImportImageId ) );
603 case KIND_BATHYMETRY:
604 theMenu->addAction( action( ImportBathymetryId ) );
606 case KIND_ARTIFICIAL_OBJECT:
607 theMenu->addAction( action( CreateChannelId ) );
608 theMenu->addAction( action( CreateDigueId ) );
610 case KIND_NATURAL_OBJECT:
611 theMenu->addAction( action( CreateImmersibleZoneId ) );
612 theMenu->addAction( action( CreateStreamId ) );
615 theMenu->addAction( action( ImportObstacleFromFileId ) );
616 theMenu->addAction( action( CreateBoxId ) );
617 theMenu->addAction( action( CreateCylinderId ) );
619 case KIND_STRICKLER_TABLE:
620 theMenu->addAction( action( ImportStricklerTableFromFileId ) );
622 case KIND_LAND_COVER_MAP:
623 theMenu->addAction( action( CreateLandCoverMapId ) );
624 theMenu->addAction( action( ImportLandCoverMapId ) );
626 case KIND_CALCULATION:
627 theMenu->addAction( action( CreateCalculationId ) );
629 case KIND_POLYLINEXY:
630 theMenu->addAction( action( ImportPolylineId ) );
631 theMenu->addAction( action( CreatePolylineId ) );
634 theMenu->addAction( action( CreatePolyline3DId ) );
635 theMenu->addAction( action( ImportPolylineId ) );
638 theMenu->addAction( action( CreateProfileId ) );
639 theMenu->addAction( action( ImportProfilesId ) );
640 theMenu->addAction( action( AllGeoreferencementId ) );
642 case KIND_VISUAL_STATE:
643 theMenu->addAction( action( SaveVisualStateId ) );
645 case KIND_BC_POLYGON:
646 theMenu->addAction( action( ImportBCPolygonId ) );
649 theMenu->addSeparator();
653 Handle(HYDROData_CalculationCase) aCalcCase;
655 HYDROGUI_Tool::IsSelectedPartOfCalcCase(this, aCalcCase, outStr);
656 if (outStr == HYDROGUI_DataModel::partitionName( KIND_REGION ))
657 theMenu->addAction( action( RegenerateRegionColorsId ) );
661 if( anIsSelectedDataObjects )
663 if ( anIsMustObjectBeUpdated )
665 theMenu->addAction( action( UpdateObjectId ) );
666 theMenu->addSeparator();
670 theMenu->addAction( action( ForcedUpdateObjectId ) );
671 theMenu->addSeparator();
675 if( aSeq.Length() == 1 )
679 if( anIsImportedImage )
680 theMenu->addAction( action( EditImportedImageId ) );
681 else if( anIsImageHasRefs )
684 theMenu->addAction( action( EditFusedImageId ) );
685 else if( anIsCutImage )
686 theMenu->addAction( action( EditCutImageId ) );
687 else if( anIsSplitImage )
688 theMenu->addAction( action( EditSplitImageId ) );
691 //RKV: BUG#98: theMenu->addAction( action( ObserveImageId ) );
692 theMenu->addAction( action( ExportImageId ) );
693 theMenu->addSeparator();
695 if( anIsImageHasRefs )
697 theMenu->addAction( action( RemoveImageRefsId ) );
698 theMenu->addSeparator();
701 theMenu->addAction( action( FuseImagesId ) );
702 theMenu->addAction( action( CutImagesId ) );
703 theMenu->addAction( action( SplitImageId ) );
704 theMenu->addSeparator();
705 theMenu->addAction( action( RecognizeContoursId ) );
706 theMenu->addSeparator();
708 else if( anIsBathymetry )
710 theMenu->addAction( action( EditImportedBathymetryId ) );
711 theMenu->addAction( action( BathymetryBoundsId ) );
712 theMenu->addSeparator();
714 else if( anIsPolyline )
716 theMenu->addAction( action( EditPolylineId ) );
717 theMenu->addSeparator();
718 theMenu->addAction( action( SplitPolylinesId ) );
719 theMenu->addAction( action( MergePolylinesId ) );
720 theMenu->addSeparator();
721 theMenu->addAction( action( ShowAttrPolylinesId ) );
722 theMenu->addSeparator();
724 else if( anIsPolyline3D )
726 theMenu->addAction( action( EditPolyline3DId ) );
727 theMenu->addSeparator();
729 else if( anIsProfile )
731 theMenu->addAction( action( EditProfileId ) );
732 theMenu->addAction( action( SelectedGeoreferencementId ) );
733 theMenu->addSeparator();
735 else if( anIsCalculation )
737 theMenu->addAction( action( EditCalculationId ) );
738 theMenu->addAction( action( ExportCalculationId ) );
739 theMenu->addAction( action( CompleteCalculationId ) );
740 theMenu->addSeparator();
742 else if( anIsImmersibleZone )
744 theMenu->addAction( action( EditImmersibleZoneId ) );
745 theMenu->addSeparator();
747 else if( anIsStream )
749 theMenu->addAction( action( EditStreamId ) );
750 if ( action( RiverBottomContextId ) )
752 theMenu->addAction( action( RiverBottomContextId ) );
753 action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
755 theMenu->addAction( action( ProfileInterpolateId ) );
756 theMenu->addSeparator();
758 else if( anIsChannel )
760 theMenu->addAction( action( EditChannelId ) );
761 theMenu->addSeparator();
765 theMenu->addAction( action( EditDigueId ) );
766 theMenu->addSeparator();
768 else if( anIsObstacle )
770 theMenu->addAction( action( TranslateObstacleId ) );
771 theMenu->addSeparator();
773 else if( anIsStricklerTable )
775 theMenu->addAction( action( EditStricklerTableId ) );
776 theMenu->addAction( action( ExportStricklerTableFromFileId ) );
777 theMenu->addAction( action( DuplicateStricklerTableId ) );
778 theMenu->addSeparator();
780 Handle(HYDROData_StricklerTable) aTable =
781 Handle(HYDROData_StricklerTable)::DownCast( aSeq.First() );
782 QString aCurrentTable =
783 HYDROGUI_DataObject::dataObjectEntry( getLandCoverColoringTable( anActiveViewId ) );
784 bool isUsed = aCurrentTable == HYDROGUI_DataObject::dataObjectEntry( aTable );
786 if ( !isUsed && !getObjectShapes( anActiveViewId, KIND_LAND_COVER_MAP ).isEmpty() ) {
787 theMenu->addAction( action( LandCoverScalarMapModeOnId ) );
788 theMenu->addSeparator();
791 else if( anIsLandCoverMap )
793 theMenu->addAction( action( AddLandCoverId ) );
794 theMenu->addAction( action( RemoveLandCoverId ) );
795 theMenu->addSeparator();
796 theMenu->addAction( action( SplitLandCoverId ) );
797 theMenu->addAction( action( MergeLandCoverId ) );
798 theMenu->addAction( action( ChangeLandCoverTypeId ) );
799 theMenu->addSeparator();
801 theMenu->addAction( action( ExportToShapeFileID ) );
802 theMenu->addSeparator();
804 else if( anIsVisualState && anIsObjectBrowser )
806 theMenu->addAction( action( SaveVisualStateId ) );
807 theMenu->addAction( action( LoadVisualStateId ) );
808 theMenu->addSeparator();
811 theMenu->addAction( action( ZoneSetColorId ) );
812 else if (anIsBCPolygon)
813 theMenu->addAction( action( SetBoundaryTypePolygonId ) );
815 if ( anIsStream || anIsChannel || anIsDigue || anIsObstacle )
817 theMenu->addAction( action( PolylineExtractionId ) );
818 theMenu->addSeparator();
821 // Add set color action for geometrical objects
822 if ( anIsObjectCanBeColored )
824 theMenu->addAction( action( SetColorId ) );
825 theMenu->addSeparator();
828 // Add transparency action for land cover map objects
829 if ( anIsLandCoverMap )
831 theMenu->addAction( action( SetTransparencyId ) );
832 theMenu->addSeparator();
835 else if ( anAllAreProfiles )
837 theMenu->addAction( action( EditProfileId ) );
838 theMenu->addAction( action( SelectedGeoreferencementId ) );
839 theMenu->addSeparator();
842 bool isPoly = anIsPolyline || anIsPolyline3D;
843 if (isPoly && !anIsLandCoverMap)
844 theMenu->addAction( action( ExportToShapeFileID ) );
847 QAction* aCopyAction = action( CopyId );
848 if( aCopyAction && aCopyAction->isEnabled() ) {
849 theMenu->addAction( action( CopyId ) );
850 theMenu->addSeparator();
854 if( !anIsDummyObject3D )
855 theMenu->addAction( action( DeleteId ) );
857 theMenu->addSeparator();
859 if( anIsImage || anIsPolyline || anIsPolyline3D ||
860 anIsImmersibleZone || anIsZone || anIsRegion ||
861 anIsBathymetry || anIsObstacle || anIsStream ||
862 anIsChannel || anIsDigue || anIsDummyObject3D ||
863 anIsValidProfile || anIsGroup || anIsLandCoverMap ||
866 if( anIsHiddenInSelection )
867 theMenu->addAction( action( ShowId ) );
868 theMenu->addAction( action( ShowOnlyId ) );
869 if( anIsVisibleInSelection )
870 theMenu->addAction( action( HideId ) );
871 theMenu->addSeparator();
877 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
878 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
879 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
880 theMenu->addAction( action( DeleteId ) );
882 theMenu->addSeparator();
883 theMenu->addAction( action( SetZLevelId ) );
884 theMenu->addSeparator();
886 if ( isLandCoversScalarMapModeOn( anActiveViewId ) ) {
887 theMenu->addAction( action( LandCoverScalarMapModeOffId ) );
888 theMenu->addSeparator();
892 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
894 theMenu->addAction( action( ShowAllId ) );
895 theMenu->addAction( action( HideAllId ) );
896 theMenu->addSeparator();
899 if ( anIsOCCView || anIsVTKView )
901 theMenu->addSeparator();
902 theMenu->addAction( action( CopyViewerPositionId ) );
906 theMenu->addAction( action( EditLocalCSId ) );
908 if( anIsObjectBrowser && anOwners.size()==1 )
910 if( aSeq.Size() > 0 )
912 Handle( HYDROData_Entity ) aFirstEnt = aSeq.First();
913 Handle(HYDROData_Object) anObject;
914 Handle(HYDROData_ArtificialObject) anAObject = Handle( HYDROData_ArtificialObject )::DownCast(aFirstEnt);
915 Handle(HYDROData_NaturalObject) aNObject = Handle( HYDROData_NaturalObject )::DownCast(aFirstEnt);
917 if (!anAObject.IsNull())
918 anObject = anAObject;
919 if (!aNObject.IsNull())
922 if( !anObject.IsNull() )
924 theMenu->addSeparator();
925 bool IsSubmersible = anObject->IsSubmersible();
928 theMenu->addAction( action( SubmersibleId ) );
929 action( SubmersibleId )->setCheckable(true);
930 action( SubmersibleId )->setChecked(true);
934 theMenu->addAction( action( UnSubmersibleId ) );
935 action( UnSubmersibleId )->setCheckable(true);
936 action( UnSubmersibleId )->setChecked(true);
942 theMenu->addSeparator();
943 QAction* a = action( ShowHideArrows );
944 a->setText( arrowsVisible() ? tr( "HIDE_ARROWS" ) : tr( "SHOW_ARROWS" ) );
945 theMenu->addAction( a );
948 void HYDROGUI_Module::createPreferences()
950 DEBTRACE("HYDROGUI_Module::createPreferences");
951 int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
952 int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
954 int typeOfCursor = addPreference( tr( "PREF_TYPE_OF_CURSOR" ), CursorGroup,
955 LightApp_Preferences::Selector, "preferences", "type_of_cursor" );
957 // Set property cursor type
958 QList<QVariant> aCursorTypeIndicesList;
959 QList<QVariant> aCursorTypeIconsList;
961 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
962 for ( int i = CT_ArrowCursor; i < CT_User; i++ ) {
963 QString icoFile = QString( "ICON_CURSOR_%1" ).arg( i+1 );
964 QPixmap pixmap = resMgr->loadPixmap( "HYDRO", tr( qPrintable( icoFile ) ) );
965 aCursorTypeIndicesList << i;
966 aCursorTypeIconsList << pixmap;
969 setPreferenceProperty( typeOfCursor, "indexes", aCursorTypeIndicesList );
970 setPreferenceProperty( typeOfCursor, "icons", aCursorTypeIconsList );
972 int viewerGroup = addPreference( tr( "PREF_GROUP_VIEWER" ), genTab );
973 addPreference( tr( "PREF_VIEWER_AUTO_FITALL" ), viewerGroup,
974 LightApp_Preferences::Bool, "HYDRO", "auto_fit_all" );
976 addPreference( tr( "PREF_VIEWER_ZOOM_SHUTOFF" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "zoom_shutoff" );
978 addPreference( tr( "PREF_VIEWER_CHAINED_PANNING" ), viewerGroup, LightApp_Preferences::Bool, "HYDRO", "chained_panning" );
980 int StricklerTableGroup = addPreference( tr( "PREF_GROUP_STRICKLER_TABLE" ), genTab );
981 int defaultStricklerCoef = addPreference( tr( "PREF_DEFAULT_STRICKLER_COEFFICIENT" ), StricklerTableGroup,
982 LightApp_Preferences::DblSpin, "preferences", "default_strickler_coefficient" );
983 setPreferenceProperty( defaultStricklerCoef, "precision", 2 );
984 setPreferenceProperty( defaultStricklerCoef, "min", 0.00 );
985 setPreferenceProperty( defaultStricklerCoef, "max", 1000000.00 );
986 setPreferenceProperty( defaultStricklerCoef, "step", 0.01 );
988 int polylinesGroup = addPreference( tr( "PREF_GROUP_POLYLINES" ), genTab );
989 int polylineArrow = addPreference( tr( "PREF_POLYLINE_ARROW" ), polylinesGroup,
990 LightApp_Preferences::Selector, "polyline", "arrow_type" );
992 QList<QVariant> arrow_types;
993 arrow_types.append( tr( "No" ) );
994 arrow_types.append( tr( "Triangle" ) );
995 arrow_types.append( tr( "Cone" ) );
996 setPreferenceProperty( polylineArrow, "strings", arrow_types );
998 QList<QVariant> indices;
1000 indices.append( 1 );
1001 indices.append( 2 );
1002 setPreferenceProperty( polylineArrow, "indexes", indices );
1003 setPreferenceProperty( polylineArrow, "ids", indices );
1005 int polylineSize = addPreference( tr( "PREF_POLYLINE_ARROW_SIZE" ), polylinesGroup,
1006 LightApp_Preferences::IntSpin, "polyline", "arrow_size" );
1009 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
1011 DEBTRACE("HYDROGUI_Module::preferencesChanged");
1012 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
1013 if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
1016 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
1017 if ( resMgr && !aDoc.IsNull() )
1018 aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( theSection, thePref, 0 ) );
1020 else if( theSection == "polyline" )
1026 resMgr->value( "polyline", "arrow_type", aType );
1027 resMgr->value( "polyline", "arrow_size", aSize );
1030 ViewManagerMap::const_iterator it = myViewManagerMap.begin(), last = myViewManagerMap.end();
1031 for( ; it!=last; it++ )
1033 size_t aViewerId = it.key();
1034 OCCViewer_ViewManager* aMgr = dynamic_cast<OCCViewer_ViewManager*>( it.value().first );
1036 getOCCDisplayer()->UpdatePolylines( aViewerId, aType, aSize );
1039 else if (theSection == "HYDRO" && thePref == "zoom_shutoff")
1041 bool aZoomShutoff = resMgr->booleanValue( "HYDRO", "zoom_shutoff" );
1042 setAutoZoomToAllViewManagers(!aZoomShutoff);
1044 else if (theSection == "HYDRO" && thePref == "chained_panning")
1046 bool aChainedPan = resMgr->booleanValue( "HYDRO", "chained_panning" );
1049 ViewManagerList aViewManagers = getApp()->viewManagers();
1050 foreach (SUIT_ViewManager* aVMgr, aViewManagers)
1052 OCCViewer_ViewManager* anOCCViewMgr = dynamic_cast<OCCViewer_ViewManager*>( aVMgr );
1054 anOCCViewMgr->setChainedOperations( aChainedPan );
1057 QList<QDockWidget*> docW = getApp()->desktop()->findChildren<QDockWidget*>();
1058 foreach (QDockWidget* qw, docW)
1060 HYDROGUI_ProfileDlg* pdlg = dynamic_cast<HYDROGUI_ProfileDlg*>(qw);
1062 pdlg->viewManager()->setChainedOperations(aChainedPan);
1066 LightApp_Module::preferencesChanged( theSection, thePref );
1069 QCursor HYDROGUI_Module::getPrefEditCursor() const
1071 int aCursorType = SUIT_Session::session()->resourceMgr()->integerValue("preferences", "type_of_cursor", (int)CT_CrossCursor );
1072 if ( aCursorType >= Qt::BlankCursor)
1074 QCursor aCursor = QCursor( Qt::CursorShape(aCursorType) );
1078 void HYDROGUI_Module::update( const int flags )
1080 DEBTRACE("HYDROGUI_Module::update");
1081 if ( !isUpdateEnabled() )
1084 QApplication::setOverrideCursor( Qt::WaitCursor );
1086 // To prevent calling this method recursively
1087 // from one of the methods called below
1088 setUpdateEnabled( false );
1090 // store selected objects
1091 QStringList aSelectedEntries = storeSelection();
1093 bool aDoFitAll = flags & UF_FitAll;
1096 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1097 aDoFitAll = aResMgr->booleanValue( "HYDRO", "auto_fit_all", false );
1100 if( ( flags & UF_Viewer ) )
1101 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
1103 if( ( flags & UF_OCCViewer ) )
1104 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
1106 if( ( flags & UF_VTKViewer ) )
1107 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
1109 if( ( flags & UF_Model ) && getDataModel() && getApp() )
1111 getDataModel()->update( getStudyId() );
1113 // Temporary workaround to prevent breaking
1114 // the selection in the object browser.
1115 // Note: processEvents() should be called after updateGV(),
1116 // otherwise the application crashes from time to time.
1117 //RKV: qApp->processEvents();
1118 SUIT_ResourceMgr* aResMgr = getApp()->resourceMgr();
1119 bool isResizeOnExpandItem = aResMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
1120 SUIT_DataBrowser* anObjectBrowser = getApp()->objectBrowser();
1121 if ( isResizeOnExpandItem && anObjectBrowser ) {
1122 anObjectBrowser->setResizeOnExpandItem( false ); // MZN: ISSUE #280
1124 getApp()->updateObjectBrowser( true );
1125 if ( isResizeOnExpandItem && anObjectBrowser ) {
1126 anObjectBrowser->setResizeOnExpandItem( true ); // MZN: ISSUE #280
1130 // Object browser is currently updated by using UF_Model flag
1131 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
1132 getApp()->updateObjectBrowser( true );
1134 if( ( flags & UF_Controls ) && getApp() )
1135 getApp()->updateActions();
1137 // restore selected objects
1138 restoreSelection( aSelectedEntries );
1140 setUpdateEnabled( true );
1142 preferencesChanged( "HYDRO", "zoom_shutoff" );
1144 preferencesChanged( "HYDRO", "chained_panning" );
1146 QApplication::restoreOverrideCursor();
1149 void HYDROGUI_Module::updateCommandsStatus()
1151 DEBTRACE("HYDROGUI_Module::updateCommandsStatus");
1152 LightApp_Module::updateCommandsStatus();
1154 updateUndoRedoControls();
1156 action( CopyId )->setEnabled( getDataModel()->canCopy() );
1157 action( PasteId )->setEnabled( getDataModel()->canPaste() );
1160 void HYDROGUI_Module::selectionChanged()
1162 DEBTRACE("HYDROGUI_Module::selectionChanged");
1163 LightApp_Module::selectionChanged();
1164 updateCommandsStatus();
1167 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
1169 //DEBTRACE("HYDROGUI_Module::getDataModel()");
1170 return (HYDROGUI_DataModel*)dataModel();
1173 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
1175 //DEBTRACE("HYDROGUI_Module::getDisplayer()");
1179 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
1181 DEBTRACE("HYDROGUI_Module::getOCCDisplayer");
1182 return myOCCDisplayer;
1185 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
1187 DEBTRACE("HYDROGUI_Module::getVTKDisplayer");
1188 return myVTKDisplayer;
1191 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const size_t theId ) const
1193 DEBTRACE("HYDROGUI_Module::getViewManager " << theId);
1194 if( myViewManagerMap.contains( theId ) )
1196 return myViewManagerMap[ theId ].first;
1201 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const size_t theId ) const
1203 DEBTRACE("HYDROGUI_Module::getViewer " << theId);
1204 if( myViewManagerMap.contains( theId ) )
1206 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1207 GraphicsView_ViewManager* aViewManager =
1208 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
1210 return aViewManager->getViewer();
1215 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const size_t theId ) const
1217 DEBTRACE("HYDROGUI_Module::getOCCViewer " << theId);
1218 if( myViewManagerMap.contains( theId ) )
1220 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1221 OCCViewer_ViewManager* aViewManager =
1222 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
1224 return aViewManager->getOCCViewer();
1229 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const size_t theId ) const
1231 DEBTRACE("HYDROGUI_Module::getVTKViewer " << theId);
1232 if( myViewManagerMap.contains( theId ) )
1234 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
1235 SVTK_ViewManager* aViewManager =
1236 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
1238 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
1243 size_t HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
1245 DEBTRACE("HYDROGUI_Module::getViewManagerId");
1246 ViewManagerMapIterator anIter( myViewManagerMap );
1247 while( anIter.hasNext() )
1249 size_t anId = anIter.next().key();
1250 const ViewManagerInfo& anInfo = anIter.value();
1251 if( anInfo.first == theViewManager )
1257 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
1259 DEBTRACE("HYDROGUI_Module::getViewManagerRole");
1260 size_t anId = getViewManagerId( theViewManager );
1263 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1264 return anInfo.second;
1269 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
1270 const ViewManagerRole theRole )
1272 DEBTRACE("HYDROGUI_Module::setViewManagerRole");
1273 size_t anId = getViewManagerId( theViewManager );
1276 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
1277 anInfo.second = theRole;
1281 bool HYDROGUI_Module::isObjectVisible( const size_t theViewId,
1282 const Handle(HYDROData_Entity)& theObject ) const
1284 if( theObject.IsNull() )
1287 if( theViewId == 0 )
1290 foreach( size_t aViewId, myObjectStateMap.keys() )
1292 if( isObjectVisible( aViewId, theObject ) )
1298 ViewId2Entry2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
1299 if( anIter1 != myObjectStateMap.end() )
1301 const Entry2ObjectStateMap& aEntry2ObjectStateMap = anIter1.value();
1302 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1304 Entry2ObjectStateMap::const_iterator anIter2 = aEntry2ObjectStateMap.find( anEntry );
1305 if( anIter2 != aEntry2ObjectStateMap.end() )
1307 const ObjectState& anObjectState = anIter2.value();
1308 return anObjectState.Visibility;
1314 void HYDROGUI_Module::setObjectVisible( const size_t theViewId,
1315 const Handle(HYDROData_Entity)& theObject,
1316 const bool theState )
1318 DEBTRACE("setObjectVisible, theViewId: " << theViewId << " " << theState);
1319 if( !theObject.IsNull() )
1321 DEBTRACE("myObjectStateMap.size: " << myObjectStateMap.size());
1322 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject );
1323 DEBTRACE("anEntry: " << anEntry.toStdString());
1324 if (myObjectStateMap.find(theViewId) == myObjectStateMap.end())
1326 DEBTRACE("theViewId is not a valid key for myObjectStateMap");
1330 Entry2ObjectStateMap& aEntry2ObjectStateMap = myObjectStateMap[ theViewId ]; // created OK if it does not exist
1331 DEBTRACE("myObjectStateMap key created");
1333 ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ];
1334 anObjectState.Visibility = theState;
1337 HYDROGUI_DataObject* hydroObject = getDataModel()->getDataObject( theObject );
1340 DEBTRACE("hydroObject " << hydroObject);
1341 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1344 DEBTRACE("treeModel " << treeModel);
1345 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1346 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1347 DEBTRACE("id " << id << " visState "<< visState);
1348 if ( visState != Qtx::UnpresentableState )
1349 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1353 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1354 setLandCoversScalarMapModeOff( theViewId );
1355 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1356 getOCCDisplayer()->SetToUpdateColorScale();
1361 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1362 const bool theState )
1364 DEBTRACE("HYDROGUI_Module::setIsToUpdate");
1365 if( !theObject.IsNull() )
1367 // Process OCC shapes
1368 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1369 while( aShapesMapIter != myShapesMap.end() )
1371 const ListOfShapes& aShapesList = aShapesMapIter.value();
1372 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1374 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1376 aShape->setIsToUpdate( theState );
1381 // Process VTK shapes
1382 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1383 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1385 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1386 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1388 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1390 aShape->setIsToUpdate( theState );
1398 /////////////////// OCC SHAPES PROCESSING
1399 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const size_t theViewId,
1400 ObjectKind theKind ) const
1402 QList<HYDROGUI_Shape*> aResult;
1404 if ( myShapesMap.contains( theViewId ) )
1406 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1407 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1409 if( aShape && aShape->getObject()->GetKind()==theKind )
1410 aResult.append( aShape );
1416 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const size_t theViewId,
1417 const Handle(HYDROData_Entity)& theObject ) const
1419 HYDROGUI_Shape* aResShape = NULL;
1420 if( theObject.IsNull() )
1423 if ( myShapesMap.contains( theViewId ) )
1425 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1426 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1428 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1439 void HYDROGUI_Module::setObjectShape( const size_t theViewId,
1440 const Handle(HYDROData_Entity)& theObject,
1441 HYDROGUI_Shape* theShape )
1443 if( theObject.IsNull() )
1446 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1447 aViewShapes.append( theShape );
1450 void HYDROGUI_Module::removeObjectShape( const size_t theViewId,
1451 const Handle(HYDROData_Entity)& theObject )
1453 if ( !myShapesMap.contains( theViewId ) )
1456 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1457 Handle(HYDROData_Entity) anObject;
1458 for ( int i = 0; i < aViewShapes.length(); )
1460 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1461 anObject = aShape->getObject();
1462 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1464 DEBTRACE("delete shape :" << aShape->getObject()->GetName().toStdString());
1466 aViewShapes.removeAt( i );
1474 void HYDROGUI_Module::removeViewShapes( const size_t theViewId )
1476 if ( !myShapesMap.contains( theViewId ) )
1479 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1480 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1482 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1487 myShapesMap.remove( theViewId );
1489 /////////////////// END OF OCC SHAPES PROCESSING
1491 /////////////////// VTKPrs PROCESSING
1492 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const size_t theViewId,
1493 const Handle(HYDROData_Entity)& theObject ) const
1495 HYDROGUI_VTKPrs* aResShape = NULL;
1496 if( theObject.IsNull() )
1499 if ( myVTKPrsMap.contains( theViewId ) )
1501 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1502 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1504 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1515 void HYDROGUI_Module::setObjectVTKPrs( const size_t theViewId,
1516 const Handle(HYDROData_Entity)& theObject,
1517 HYDROGUI_VTKPrs* theShape )
1519 if( theObject.IsNull() )
1522 if( theShape && theShape->needScalarBar() )
1524 // Compute the new global Z range from the added presentation and the old global Z range.
1525 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1526 double* aRange = theShape->getInternalZRange();
1527 bool anIsUpdate = false;
1528 if ( aRange[0] < aGlobalRange[0] )
1530 aGlobalRange[0] = aRange[0];
1533 if ( aRange[1] > aGlobalRange[1] )
1535 aGlobalRange[1] = aRange[1];
1541 updateVTKZRange( theViewId, aGlobalRange );
1545 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1546 aViewShapes.append( theShape );
1549 void HYDROGUI_Module::removeObjectVTKPrs( const size_t theViewId,
1550 const QString& theEntry )
1552 if ( !myVTKPrsMap.contains( theViewId ) )
1555 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1556 Handle(HYDROData_Entity) anObject;
1558 for ( int i = 0; i < aViewShapes.length(); )
1560 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1561 anObject = aShape->getObject();
1562 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1563 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1566 aViewShapes.removeAt( i );
1573 // Invalidate global Z range
1574 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1575 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1578 void HYDROGUI_Module::removeObjectVTKPrs( const size_t theViewId,
1579 const Handle(HYDROData_Entity)& theObject )
1581 if ( !myVTKPrsMap.contains( theViewId ) )
1584 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1585 Handle(HYDROData_Entity) anObject;
1586 for ( int i = 0; i < aViewShapes.length(); )
1588 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1589 anObject = aShape->getObject();
1590 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1593 aViewShapes.removeAt( i );
1600 // Invalidate global Z range
1601 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1602 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1605 void HYDROGUI_Module::removeViewVTKPrs( const size_t theViewId )
1607 if ( !myVTKPrsMap.contains( theViewId ) )
1610 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1611 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1613 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1618 myVTKPrsMap.remove( theViewId );
1621 void HYDROGUI_Module::updateVTKZRange( const size_t theViewId, double theRange[] )
1623 if ( myVTKPrsMap.contains( theViewId ) )
1625 // For the given viewer id update all VTK presentations ...
1626 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1627 HYDROGUI_VTKPrs* aShape;
1628 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1630 aShape = aViewShapes.at( i );
1631 if ( aShape && aShape->needScalarBar() )
1633 aShape->setZRange( theRange );
1637 // ... and update the global color legend scalar bar.
1638 getVTKDisplayer()->SetZRange( theViewId, theRange );
1640 /////////////////// END OF VTKPrs PROCESSING
1642 void HYDROGUI_Module::clearCache()
1644 DEBTRACE("HYDROGUI_Module::clearCache");
1645 myObjectStateMap.clear();
1648 CAM_DataModel* HYDROGUI_Module::createDataModel()
1650 DEBTRACE("HYDROGUI_Module::createDataModel");
1651 return new HYDROGUI_DataModel( this );
1654 void HYDROGUI_Module::customEvent( QEvent* e )
1656 int aType = e->type();
1657 if ( aType == NewViewEvent )
1659 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1660 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1662 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1664 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1665 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1667 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1669 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1670 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1672 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1673 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1674 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1676 //ouv: temporarily commented
1677 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1680 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1681 update( UF_Viewer );
1683 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1689 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1691 QEvent::Type aType = theEvent->type();
1692 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1694 if( aType == QEvent::Show )
1696 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1697 e->setData( theObj );
1698 QApplication::postEvent( this, e );
1699 theObj->removeEventFilter( this );
1702 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1704 if( aType == QEvent::Leave )
1706 SUIT_Desktop* aDesktop = getApp()->desktop();
1707 if ( aDesktop && aDesktop->statusBar() ) {
1708 aDesktop->statusBar()->clearMessage();
1712 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1714 if( aType == QEvent::Leave )
1716 SUIT_Desktop* aDesktop = getApp()->desktop();
1717 if ( aDesktop && aDesktop->statusBar() ) {
1718 aDesktop->statusBar()->clearMessage();
1723 return LightApp_Module::eventFilter( theObj, theEvent );
1726 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1728 DEBTRACE("HYDROGUI_Module::onViewManagerAdded");
1729 LightApp_Module::onViewManagerAdded( theViewManager );
1731 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1733 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1734 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1736 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1738 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1739 //mgr->setChainedOperations( true );
1741 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1742 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1743 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1744 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1745 connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
1746 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1748 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1750 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1751 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1752 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1753 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1756 createSelector( theViewManager ); // replace the default selector
1758 ViewManagerInfo anInfo( theViewManager, VMR_General );
1759 myViewManagerMap.insert( ViewManagerId++, anInfo );
1762 void HYDROGUI_Module::removeViewManager( SUIT_ViewManager* theViewManager)
1764 DEBTRACE("removeViewManager")
1766 size_t anId = getViewManagerId( theViewManager );
1769 bool isDisableGVSelector = theViewManager->getType() == GraphicsView_Viewer::Type();
1770 createSelector( theViewManager, isDisableGVSelector ); // replace the default selector
1772 OCCViewer_ViewManager* anOCCViewManager =
1773 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1774 if ( anOCCViewManager )
1776 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1777 if ( anOCCViewer ) {
1778 size_t aViewerId = (size_t)anOCCViewer;
1779 removeViewShapes( aViewerId );
1780 setLandCoversScalarMapModeOff( aViewerId );
1784 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1786 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1789 getVTKDisplayer()->EraseScalarBar( anId, true );
1790 removeViewShapes( (size_t)aVTKViewer );
1794 myViewManagerMap.remove( anId );
1798 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1800 DEBTRACE("HYDROGUI_Module::onViewManagerRemoved");
1801 removeViewManager(theViewManager);
1802 LightApp_Module::onViewManagerRemoved( theViewManager );
1806 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1808 DEBTRACE("HYDROGUI_Module::onViewCreated");
1809 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1811 DEBTRACE("theViewWindow->inherits( 'GraphicsView_ViewFrame' )");
1812 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1815 aViewFrame->installEventFilter( this );
1817 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1818 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1820 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1821 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1824 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1826 DEBTRACE("theViewWindow->inherits( 'OCCViewer_ViewFrame' )");
1827 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1830 aViewFrame->onTopView();
1832 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1833 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1835 aViewPort->installEventFilter( this );
1839 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1841 DEBTRACE("theViewWindow->inherits( 'SVTK_ViewWindow' )");
1842 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1845 aViewFrame->installEventFilter( this );
1850 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1852 /* ouv: currently unused
1853 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1855 SUIT_ViewManager* aViewManager = 0;
1857 QObject* aParent = aViewPort;
1858 while( aParent = aParent->parent() )
1860 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1862 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1864 aViewManager = aViewer->getViewManager();
1873 double aMouseX = theEvent->scenePos().x();
1874 double aMouseY = theEvent->scenePos().y();
1876 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1877 if( aRole == VMR_General )
1879 int aXDeg = 0, aYDeg = 0;
1880 int aXMin = 0, aYMin = 0;
1881 double aXSec = 0, aYSec = 0;
1882 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1883 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1885 QString aDegSymbol( QChar( 0x00B0 ) );
1886 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1887 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1889 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1891 else if( aRole == VMR_TransformImage )
1892 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1897 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1898 const bool theIsInit,
1899 const bool theIsForced,
1900 const bool theDoFitAll )
1902 DEBTRACE("HYDROGUI_Module::updateViewer");
1903 QList<size_t> aViewManagerIdList;
1905 // currently, all views are updated
1906 ViewManagerMapIterator anIter( myViewManagerMap );
1907 while( anIter.hasNext() )
1909 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1911 if ( theDisplayer->IsApplicable( aViewManager ) )
1913 int anId = anIter.key();
1914 aViewManagerIdList.append( anId );
1918 QListIterator<size_t> anIdIter( aViewManagerIdList );
1919 while( anIdIter.hasNext() )
1921 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1922 myOverview->setTopView();
1926 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager, bool isDisableGV )
1928 DEBTRACE("HYDROGUI_Module::createSelector " << isDisableGV);
1929 if( !theViewManager )
1932 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1933 if( !aSelectionMgr )
1936 QString aViewType = theViewManager->getType();
1937 DEBTRACE("aViewType " << aViewType.toStdString());
1938 if( aViewType != GraphicsView_Viewer::Type() &&
1939 aViewType != OCCViewer_Viewer::Type())
1942 QList<SUIT_Selector*> aSelectorList;
1943 aSelectionMgr->selectors( aViewType, aSelectorList );
1945 // disable all alien selectors
1948 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1949 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1951 SUIT_Selector* aSelector = *anIter;
1955 DEBTRACE("Selector " << aSelector->type().toStdString());
1956 if (dynamic_cast<HYDROGUI_GVSelector*>( aSelector ))
1958 isOk = !isDisableGV;
1960 DEBTRACE("HYDROGUI_GVSelector " << isOk);
1962 else if (dynamic_cast<SVTK_Selector*>( aSelector ))
1965 DEBTRACE("SVTK_Selector");
1967 else if (dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ))
1971 DEBTRACE("HYDROGUI_OCCSelector");
1975 DEBTRACE("Selector enabled " << aSelector->type().toStdString());
1976 aSelector->setEnabled( true );
1980 DEBTRACE("Selector disabled " << aSelector->type().toStdString());
1981 aSelector->setEnabled( false );
1986 if ( aViewType == GraphicsView_Viewer::Type() )
1988 GraphicsView_ViewManager* aViewManager =
1989 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1992 HYDROGUI_GVSelector* sel = new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1993 DEBTRACE("new HYDROGUI_GVSelector " << sel << " " << sel->type().toStdString());
1994 sel->setEnabled( true );
1997 else if ( aViewType == OCCViewer_Viewer::Type() )
1999 OCCViewer_ViewManager* aViewManager =
2000 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
2003 HYDROGUI_OCCSelector* sel = new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
2004 DEBTRACE("new HYDROGUI_OCCSelector " << sel << " " << sel->type().toStdString());
2005 sel->setEnabled( true );
2010 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
2012 DEBTRACE("HYDROGUI_Module::setUpdateEnabled");
2013 bool aPrevState = myIsUpdateEnabled;
2014 myIsUpdateEnabled = theState;
2018 bool HYDROGUI_Module::isUpdateEnabled() const
2020 return myIsUpdateEnabled;
2023 QStringList HYDROGUI_Module::storeSelection() const
2025 DEBTRACE("HYDROGUI_Module::storeSelection");
2026 QStringList anEntryList;
2027 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
2029 SUIT_DataOwnerPtrList aList( true );
2030 aSelectionMgr->selected( aList );
2032 SUIT_DataOwnerPtrList::iterator anIter;
2033 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
2035 const LightApp_DataOwner* anOwner =
2036 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
2038 anEntryList.append( anOwner->entry() );
2044 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
2046 DEBTRACE("HYDROGUI_Module::restoreSelection");
2047 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
2049 SUIT_DataOwnerPtrList aList( true );
2050 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
2051 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
2052 aSelectionMgr->setSelected( aList );
2056 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
2059 bool doShow = false;
2060 HYDROGUI_Displayer* aDisplayer = getDisplayer();
2062 aDisplayer->SaveCursorViewPosition( theViewWindow );
2063 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
2067 // Show the coordinates in the status bar
2068 SUIT_Desktop* aDesktop = getApp()->desktop();
2069 if ( aDesktop && aDesktop->statusBar() )
2071 gp_Pnt aWPnt( X, Y, Z );
2072 HYDROData_Document::Document()->Transform( aWPnt, false );
2073 double WX = aWPnt.X(), WY = aWPnt.Y();
2075 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
2076 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
2077 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
2078 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
2079 QString aMsg = tr( "COORDINATES_INFO" );
2080 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
2081 aDesktop->statusBar()->showMessage( aMsg );
2087 * Returns stack of active operations;
2089 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
2091 DEBTRACE("HYDROGUI_Module::getActiveOperations");
2092 return myActiveOperationMap;
2096 * Returns the module active operation. If the active operation is show/hide,
2097 * the method returns the previous operation if it is.
2099 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
2101 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
2103 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
2105 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
2107 aVIt.previous(); // skip the top show/hide operation
2108 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
2115 * \brief Virtual public slot
2117 * This method is called after the object inserted into data view to update their visibility state
2118 * This is default implementation
2120 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
2122 if ( !isActiveModule() )
2125 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
2127 // change visibility of object
2128 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
2131 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
2133 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
2134 Qtx::VisibilityState visState = treeModel->visibilityState( id );
2135 if ( visState == Qtx::UnpresentableState )
2138 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
2139 treeModel->setVisibilityState( id, visState );
2141 bool vis = visState == Qtx::ShownState;
2142 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
2145 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
2147 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
2150 bool HYDROGUI_Module::isDraggable( const SUIT_DataObject* what ) const
2155 bool HYDROGUI_Module::isDropAccepted( const SUIT_DataObject* where ) const
2161 void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
2162 const int row, Qt::DropAction action )
2164 if ( action != Qt::CopyAction && action != Qt::MoveAction )
2170 if (where->level() < 2 )
2173 DataObjectList::ConstIterator it = what.constBegin();
2174 for (;it != what.constEnd();++it)
2176 if ((*it)->parent() != where)
2180 it = what.constBegin();
2183 for (;it != what.constEnd();++it)
2185 SUIT_DataObject* objWhat = *it;
2187 DataObjectList objInSect = where->children();
2189 //std::list<SUIT_DataObject*> t1 = where->children().toStdList(); //debug
2190 int ind = objInSect.indexOf(objWhat);
2193 HYDROGUI_DataModel* aModel = getDataModel();
2202 where->moveChildPos(objWhat, pos);
2203 //std::list<SUIT_DataObject*> t2 = where->children().toStdList(); //debug
2207 getApp()->updateObjectBrowser(true);
2211 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const size_t theViewId ) const
2213 Handle(HYDROData_StricklerTable) aTable;
2215 if ( myLandCoverColoringMap.contains( theViewId ) ) {
2216 aTable = myLandCoverColoringMap.value( theViewId );
2222 void HYDROGUI_Module::setLandCoverColoringTable( const size_t theViewId,
2223 const Handle(HYDROData_StricklerTable)& theTable )
2225 if ( !theTable.IsNull() && theViewId ) {
2226 myLandCoverColoringMap.insert( theViewId, theTable );
2230 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const size_t theViewId )
2232 myLandCoverColoringMap.remove( theViewId );
2235 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const size_t theViewId ) const
2237 return myLandCoverColoringMap.contains( theViewId );
2240 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
2242 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
2246 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
2247 Handle(HYDROData_StricklerTable) aTable =
2248 Handle(HYDROData_StricklerTable)::DownCast( theObject );
2249 QMutableMapIterator<size_t, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
2250 while ( anIter.hasNext() ) {
2251 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
2252 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
2259 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
2261 DEBTRACE("HYDROGUI_Module::onViewActivated");
2265 SUIT_ViewWindow* wnd = theMgr->getActiveView();
2266 OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
2270 myOverview->setMainView( occwnd );
2273 void HYDROGUI_Module::setAutoZoomToAllViewManagers(bool bAutoZoom)
2275 ViewManagerList aViewManagers = getApp()->viewManagers();
2276 foreach (SUIT_ViewManager* aVMgr, aViewManagers)
2277 setAutoZoom(aVMgr, bAutoZoom);
2280 void HYDROGUI_Module::setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom)
2284 QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
2285 foreach (SUIT_ViewWindow* aView, aViews)
2289 OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
2292 anOCCViewFrame->setAutomaticZoom(bAutoZoom);
2293 for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
2295 OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
2297 aV->setAutomaticZoom(bAutoZoom);
2300 OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
2301 if (anOCCViewWindow)
2302 anOCCViewWindow->setAutomaticZoom(bAutoZoom);