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);
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 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
1343 QString id = hydroObject->text( hydroObject->customData( Qtx::IdType ).toInt() );
1344 Qtx::VisibilityState visState = treeModel->visibilityState( id );
1345 if ( visState != Qtx::UnpresentableState )
1346 treeModel->setVisibilityState( id, theState ? Qtx::ShownState : Qtx::HiddenState );
1350 if ( theObject->GetKind() == KIND_BATHYMETRY && theState ) {
1351 setLandCoversScalarMapModeOff( theViewId );
1352 } else if ( theObject->GetKind() == KIND_LAND_COVER_MAP && theState ) {
1353 getOCCDisplayer()->SetToUpdateColorScale();
1358 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
1359 const bool theState )
1361 DEBTRACE("HYDROGUI_Module::setIsToUpdate");
1362 if( !theObject.IsNull() )
1364 // Process OCC shapes
1365 ViewId2ListOfShapes::const_iterator aShapesMapIter( myShapesMap.begin() );
1366 while( aShapesMapIter != myShapesMap.end() )
1368 const ListOfShapes& aShapesList = aShapesMapIter.value();
1369 foreach ( HYDROGUI_Shape* aShape, aShapesList )
1371 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1373 aShape->setIsToUpdate( theState );
1378 // Process VTK shapes
1379 ViewId2ListOfVTKPrs::const_iterator aVTKPrsMapIter( myVTKPrsMap.begin() );
1380 while( aVTKPrsMapIter != myVTKPrsMap.end() )
1382 const ListOfVTKPrs& aShapesList = aVTKPrsMapIter.value();
1383 foreach ( HYDROGUI_VTKPrs* aShape, aShapesList )
1385 if ( aShape && IsEqual( aShape->getObject(), theObject ) )
1387 aShape->setIsToUpdate( theState );
1395 /////////////////// OCC SHAPES PROCESSING
1396 QList<HYDROGUI_Shape*> HYDROGUI_Module::getObjectShapes( const size_t theViewId,
1397 ObjectKind theKind ) const
1399 QList<HYDROGUI_Shape*> aResult;
1401 if ( myShapesMap.contains( theViewId ) )
1403 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1404 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1406 if( aShape && aShape->getObject()->GetKind()==theKind )
1407 aResult.append( aShape );
1413 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const size_t theViewId,
1414 const Handle(HYDROData_Entity)& theObject ) const
1416 HYDROGUI_Shape* aResShape = NULL;
1417 if( theObject.IsNull() )
1420 if ( myShapesMap.contains( theViewId ) )
1422 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1423 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
1425 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1436 void HYDROGUI_Module::setObjectShape( const size_t theViewId,
1437 const Handle(HYDROData_Entity)& theObject,
1438 HYDROGUI_Shape* theShape )
1440 if( theObject.IsNull() )
1443 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1444 aViewShapes.append( theShape );
1447 void HYDROGUI_Module::removeObjectShape( const size_t theViewId,
1448 const Handle(HYDROData_Entity)& theObject )
1450 if ( !myShapesMap.contains( theViewId ) )
1453 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
1454 Handle(HYDROData_Entity) anObject;
1455 for ( int i = 0; i < aViewShapes.length(); )
1457 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1458 anObject = aShape->getObject();
1459 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1462 aViewShapes.removeAt( i );
1470 void HYDROGUI_Module::removeViewShapes( const size_t theViewId )
1472 if ( !myShapesMap.contains( theViewId ) )
1475 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
1476 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1478 HYDROGUI_Shape* aShape = aViewShapes.at( i );
1483 myShapesMap.remove( theViewId );
1485 /////////////////// END OF OCC SHAPES PROCESSING
1487 /////////////////// VTKPrs PROCESSING
1488 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const size_t theViewId,
1489 const Handle(HYDROData_Entity)& theObject ) const
1491 HYDROGUI_VTKPrs* aResShape = NULL;
1492 if( theObject.IsNull() )
1495 if ( myVTKPrsMap.contains( theViewId ) )
1497 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1498 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
1500 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
1511 void HYDROGUI_Module::setObjectVTKPrs( const size_t theViewId,
1512 const Handle(HYDROData_Entity)& theObject,
1513 HYDROGUI_VTKPrs* theShape )
1515 if( theObject.IsNull() )
1518 if( theShape && theShape->needScalarBar() )
1520 // Compute the new global Z range from the added presentation and the old global Z range.
1521 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
1522 double* aRange = theShape->getInternalZRange();
1523 bool anIsUpdate = false;
1524 if ( aRange[0] < aGlobalRange[0] )
1526 aGlobalRange[0] = aRange[0];
1529 if ( aRange[1] > aGlobalRange[1] )
1531 aGlobalRange[1] = aRange[1];
1537 updateVTKZRange( theViewId, aGlobalRange );
1541 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1542 aViewShapes.append( theShape );
1545 void HYDROGUI_Module::removeObjectVTKPrs( const size_t theViewId,
1546 const QString& theEntry )
1548 if ( !myVTKPrsMap.contains( theViewId ) )
1551 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1552 Handle(HYDROData_Entity) anObject;
1554 for ( int i = 0; i < aViewShapes.length(); )
1556 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1557 anObject = aShape->getObject();
1558 anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject );
1559 if ( aShape && (!anObject.IsNull()) && ( anEntryRef == theEntry ) )
1562 aViewShapes.removeAt( i );
1569 // Invalidate global Z range
1570 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1571 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1574 void HYDROGUI_Module::removeObjectVTKPrs( const size_t theViewId,
1575 const Handle(HYDROData_Entity)& theObject )
1577 if ( !myVTKPrsMap.contains( theViewId ) )
1580 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
1581 Handle(HYDROData_Entity) anObject;
1582 for ( int i = 0; i < aViewShapes.length(); )
1584 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1585 anObject = aShape->getObject();
1586 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
1589 aViewShapes.removeAt( i );
1596 // Invalidate global Z range
1597 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
1598 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
1601 void HYDROGUI_Module::removeViewVTKPrs( const size_t theViewId )
1603 if ( !myVTKPrsMap.contains( theViewId ) )
1606 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1607 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1609 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
1614 myVTKPrsMap.remove( theViewId );
1617 void HYDROGUI_Module::updateVTKZRange( const size_t theViewId, double theRange[] )
1619 if ( myVTKPrsMap.contains( theViewId ) )
1621 // For the given viewer id update all VTK presentations ...
1622 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
1623 HYDROGUI_VTKPrs* aShape;
1624 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
1626 aShape = aViewShapes.at( i );
1627 if ( aShape && aShape->needScalarBar() )
1629 aShape->setZRange( theRange );
1633 // ... and update the global color legend scalar bar.
1634 getVTKDisplayer()->SetZRange( theViewId, theRange );
1636 /////////////////// END OF VTKPrs PROCESSING
1638 void HYDROGUI_Module::clearCache()
1640 DEBTRACE("HYDROGUI_Module::clearCache");
1641 myObjectStateMap.clear();
1644 CAM_DataModel* HYDROGUI_Module::createDataModel()
1646 DEBTRACE("HYDROGUI_Module::createDataModel");
1647 return new HYDROGUI_DataModel( this );
1650 void HYDROGUI_Module::customEvent( QEvent* e )
1652 int aType = e->type();
1653 if ( aType == NewViewEvent )
1655 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
1656 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
1658 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
1660 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
1661 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1663 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
1665 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1666 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
1668 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
1669 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
1670 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
1672 //ouv: temporarily commented
1673 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
1676 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
1677 update( UF_Viewer );
1679 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
1685 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
1687 QEvent::Type aType = theEvent->type();
1688 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
1690 if( aType == QEvent::Show )
1692 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
1693 e->setData( theObj );
1694 QApplication::postEvent( this, e );
1695 theObj->removeEventFilter( this );
1698 else if ( theObj->inherits( "OCCViewer_ViewPort" ) )
1700 if( aType == QEvent::Leave )
1702 SUIT_Desktop* aDesktop = getApp()->desktop();
1703 if ( aDesktop && aDesktop->statusBar() ) {
1704 aDesktop->statusBar()->clearMessage();
1708 else if ( theObj->inherits( "SVTK_ViewWindow" ) )
1710 if( aType == QEvent::Leave )
1712 SUIT_Desktop* aDesktop = getApp()->desktop();
1713 if ( aDesktop && aDesktop->statusBar() ) {
1714 aDesktop->statusBar()->clearMessage();
1719 return LightApp_Module::eventFilter( theObj, theEvent );
1722 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
1724 DEBTRACE("HYDROGUI_Module::onViewManagerAdded");
1725 LightApp_Module::onViewManagerAdded( theViewManager );
1727 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
1729 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1730 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1732 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
1734 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( theViewManager );
1735 //mgr->setChainedOperations( true );
1737 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1738 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1739 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1740 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1741 connect( theViewManager, SIGNAL( activated( SUIT_ViewManager* ) ),
1742 this, SLOT( onViewActivated( SUIT_ViewManager* ) ) );
1744 else if( theViewManager->getType() == SVTK_Viewer::Type() )
1746 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1747 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
1748 connect( theViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
1749 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1752 createSelector( theViewManager ); // replace the default selector
1754 ViewManagerInfo anInfo( theViewManager, VMR_General );
1755 myViewManagerMap.insert( ViewManagerId++, anInfo );
1758 void HYDROGUI_Module::removeViewManager( SUIT_ViewManager* theViewManager)
1760 DEBTRACE("removeViewManager")
1762 size_t anId = getViewManagerId( theViewManager );
1765 bool isDisableGVSelector = theViewManager->getType() == GraphicsView_Viewer::Type();
1766 createSelector( theViewManager, isDisableGVSelector ); // replace the default selector
1768 OCCViewer_ViewManager* anOCCViewManager =
1769 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
1770 if ( anOCCViewManager )
1772 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
1773 if ( anOCCViewer ) {
1774 size_t aViewerId = (size_t)anOCCViewer;
1775 removeViewShapes( aViewerId );
1776 setLandCoversScalarMapModeOff( aViewerId );
1780 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
1782 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
1785 getVTKDisplayer()->EraseScalarBar( anId, true );
1786 removeViewShapes( (size_t)aVTKViewer );
1790 myViewManagerMap.remove( anId );
1794 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
1796 DEBTRACE("HYDROGUI_Module::onViewManagerRemoved");
1797 removeViewManager(theViewManager);
1798 LightApp_Module::onViewManagerRemoved( theViewManager );
1802 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
1804 DEBTRACE("HYDROGUI_Module::onViewCreated");
1805 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
1807 DEBTRACE("theViewWindow->inherits( 'GraphicsView_ViewFrame' )");
1808 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
1811 aViewFrame->installEventFilter( this );
1813 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1814 aViewPort->setInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling );
1816 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1817 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1820 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1822 DEBTRACE("theViewWindow->inherits( 'OCCViewer_ViewFrame' )");
1823 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1826 aViewFrame->onTopView();
1828 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1829 OCCViewer_ViewPort3d* aViewPort = aViewFrame->getViewPort();
1831 aViewPort->installEventFilter( this );
1835 else if( theViewWindow && theViewWindow->inherits( "SVTK_ViewWindow" ) )
1837 DEBTRACE("theViewWindow->inherits( 'SVTK_ViewWindow' )");
1838 if( SVTK_ViewWindow* aViewFrame = dynamic_cast<SVTK_ViewWindow*>( theViewWindow ) )
1841 aViewFrame->installEventFilter( this );
1846 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1848 /* ouv: currently unused
1849 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1851 SUIT_ViewManager* aViewManager = 0;
1853 QObject* aParent = aViewPort;
1854 while( aParent = aParent->parent() )
1856 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1858 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1860 aViewManager = aViewer->getViewManager();
1869 double aMouseX = theEvent->scenePos().x();
1870 double aMouseY = theEvent->scenePos().y();
1872 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1873 if( aRole == VMR_General )
1875 int aXDeg = 0, aYDeg = 0;
1876 int aXMin = 0, aYMin = 0;
1877 double aXSec = 0, aYSec = 0;
1878 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1879 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1881 QString aDegSymbol( QChar( 0x00B0 ) );
1882 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1883 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1885 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1887 else if( aRole == VMR_TransformImage )
1888 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1893 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1894 const bool theIsInit,
1895 const bool theIsForced,
1896 const bool theDoFitAll )
1898 DEBTRACE("HYDROGUI_Module::updateViewer");
1899 QList<size_t> aViewManagerIdList;
1901 // currently, all views are updated
1902 ViewManagerMapIterator anIter( myViewManagerMap );
1903 while( anIter.hasNext() )
1905 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1907 if ( theDisplayer->IsApplicable( aViewManager ) )
1909 int anId = anIter.key();
1910 aViewManagerIdList.append( anId );
1914 QListIterator<size_t> anIdIter( aViewManagerIdList );
1915 while( anIdIter.hasNext() )
1917 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1918 myOverview->setTopView();
1922 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager, bool isDisableGV )
1924 DEBTRACE("HYDROGUI_Module::createSelector " << isDisableGV);
1925 if( !theViewManager )
1928 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1929 if( !aSelectionMgr )
1932 QString aViewType = theViewManager->getType();
1933 DEBTRACE("aViewType " << aViewType.toStdString() << " " << GraphicsView_Viewer::Type().toStdString() << " " << OCCViewer_Viewer::Type().toStdString());
1934 if( aViewType != GraphicsView_Viewer::Type() &&
1935 aViewType != OCCViewer_Viewer::Type())
1938 QList<SUIT_Selector*> aSelectorList;
1939 aSelectionMgr->selectors( aViewType, aSelectorList );
1941 // disable all alien selectors
1944 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1945 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1947 SUIT_Selector* aSelector = *anIter;
1951 DEBTRACE("Selector " << aSelector->type().toStdString());
1952 if (dynamic_cast<HYDROGUI_GVSelector*>( aSelector ))
1954 isOk = !isDisableGV;
1956 DEBTRACE("HYDROGUI_GVSelector " << isOk);
1958 else if (dynamic_cast<SVTK_Selector*>( aSelector ))
1961 DEBTRACE("SVTK_Selector");
1963 else if (dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ))
1967 DEBTRACE("HYDROGUI_OCCSelector");
1971 DEBTRACE("Selector enabled " << aSelector->type().toStdString());
1972 aSelector->setEnabled( true );
1976 DEBTRACE("Selector disabled " << aSelector->type().toStdString());
1977 aSelector->setEnabled( false );
1982 if ( !isGV && aViewType == GraphicsView_Viewer::Type() )
1984 GraphicsView_ViewManager* aViewManager =
1985 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1988 HYDROGUI_GVSelector* sel = new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1989 DEBTRACE("new HYDROGUI_GVSelector " << sel << " " << sel->type().toStdString());
1990 sel->setEnabled( true );
1993 else if ( !isOCC && aViewType == OCCViewer_Viewer::Type() )
1995 OCCViewer_ViewManager* aViewManager =
1996 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1999 HYDROGUI_OCCSelector* sel = new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
2000 DEBTRACE("new HYDROGUI_OCCSelector " << sel << " " << sel->type().toStdString());
2001 sel->setEnabled( true );
2006 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
2008 DEBTRACE("HYDROGUI_Module::setUpdateEnabled");
2009 bool aPrevState = myIsUpdateEnabled;
2010 myIsUpdateEnabled = theState;
2014 bool HYDROGUI_Module::isUpdateEnabled() const
2016 return myIsUpdateEnabled;
2019 QStringList HYDROGUI_Module::storeSelection() const
2021 DEBTRACE("HYDROGUI_Module::storeSelection");
2022 QStringList anEntryList;
2023 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
2025 SUIT_DataOwnerPtrList aList( true );
2026 aSelectionMgr->selected( aList );
2028 SUIT_DataOwnerPtrList::iterator anIter;
2029 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
2031 const LightApp_DataOwner* anOwner =
2032 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
2034 anEntryList.append( anOwner->entry() );
2040 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
2042 DEBTRACE("HYDROGUI_Module::restoreSelection");
2043 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
2045 SUIT_DataOwnerPtrList aList( true );
2046 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
2047 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
2048 aSelectionMgr->setSelected( aList );
2052 void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* )
2055 bool doShow = false;
2056 HYDROGUI_Displayer* aDisplayer = getDisplayer();
2058 aDisplayer->SaveCursorViewPosition( theViewWindow );
2059 doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z );
2063 // Show the coordinates in the status bar
2064 SUIT_Desktop* aDesktop = getApp()->desktop();
2065 if ( aDesktop && aDesktop->statusBar() )
2067 gp_Pnt aWPnt( X, Y, Z );
2068 HYDROData_Document::Document()->Transform( aWPnt, false );
2069 double WX = aWPnt.X(), WY = aWPnt.Y();
2071 QString aXStr = HYDROGUI_Tool::GetCoordinateString( X, true );
2072 QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y, true );
2073 QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX, true );
2074 QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY, true );
2075 QString aMsg = tr( "COORDINATES_INFO" );
2076 aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr );
2077 aDesktop->statusBar()->showMessage( aMsg );
2083 * Returns stack of active operations;
2085 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
2087 DEBTRACE("HYDROGUI_Module::getActiveOperations");
2088 return myActiveOperationMap;
2092 * Returns the module active operation. If the active operation is show/hide,
2093 * the method returns the previous operation if it is.
2095 HYDROGUI_Operation* HYDROGUI_Module::activeOperation()
2097 HYDROGUI_Operation* anOp = !myActiveOperationMap.empty() ? myActiveOperationMap.top() : 0;
2099 if ( dynamic_cast<HYDROGUI_ShowHideOp*>( anOp ) )
2101 QVectorIterator<HYDROGUI_Operation*> aVIt( myActiveOperationMap );
2103 aVIt.previous(); // skip the top show/hide operation
2104 anOp = aVIt.hasPrevious() ? aVIt.previous() : 0;
2111 * \brief Virtual public slot
2113 * This method is called after the object inserted into data view to update their visibility state
2114 * This is default implementation
2116 void HYDROGUI_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
2118 if ( !isActiveModule() )
2121 HYDROGUI_DataObject* hydroObject = dynamic_cast<HYDROGUI_DataObject*>( theObject );
2123 // change visibility of object
2124 if ( !hydroObject || theColumn != SUIT_DataObject::VisibilityId )
2127 SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( getApp()->objectBrowser()->model() );
2129 QString id = theObject->text( theObject->customData( Qtx::IdType ).toInt() );
2130 Qtx::VisibilityState visState = treeModel->visibilityState( id );
2131 if ( visState == Qtx::UnpresentableState )
2134 visState = visState == Qtx::ShownState ? Qtx::HiddenState : Qtx::ShownState;
2135 treeModel->setVisibilityState( id, visState );
2137 bool vis = visState == Qtx::ShownState;
2138 if ( vis == isObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject() ) )
2141 setObjectVisible( HYDROGUI_Tool::GetActiveViewId( this ), hydroObject->modelObject(), vis );
2143 update( UF_OCCViewer | UF_VTKViewer | ( visState == Qtx::ShownState ? UF_FitAll : 0 ) );
2146 bool HYDROGUI_Module::isDraggable( const SUIT_DataObject* what ) const
2151 bool HYDROGUI_Module::isDropAccepted( const SUIT_DataObject* where ) const
2157 void HYDROGUI_Module::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
2158 const int row, Qt::DropAction action )
2160 if ( action != Qt::CopyAction && action != Qt::MoveAction )
2166 if (where->level() < 2 )
2169 DataObjectList::ConstIterator it = what.constBegin();
2170 for (;it != what.constEnd();++it)
2172 if ((*it)->parent() != where)
2176 it = what.constBegin();
2179 for (;it != what.constEnd();++it)
2181 SUIT_DataObject* objWhat = *it;
2183 DataObjectList objInSect = where->children();
2185 //std::list<SUIT_DataObject*> t1 = where->children().toStdList(); //debug
2186 int ind = objInSect.indexOf(objWhat);
2189 HYDROGUI_DataModel* aModel = getDataModel();
2198 where->moveChildPos(objWhat, pos);
2199 //std::list<SUIT_DataObject*> t2 = where->children().toStdList(); //debug
2203 getApp()->updateObjectBrowser(true);
2207 Handle(HYDROData_StricklerTable) HYDROGUI_Module::getLandCoverColoringTable( const size_t theViewId ) const
2209 Handle(HYDROData_StricklerTable) aTable;
2211 if ( myLandCoverColoringMap.contains( theViewId ) ) {
2212 aTable = myLandCoverColoringMap.value( theViewId );
2218 void HYDROGUI_Module::setLandCoverColoringTable( const size_t theViewId,
2219 const Handle(HYDROData_StricklerTable)& theTable )
2221 if ( !theTable.IsNull() && theViewId ) {
2222 myLandCoverColoringMap.insert( theViewId, theTable );
2226 void HYDROGUI_Module::setLandCoversScalarMapModeOff( const size_t theViewId )
2228 myLandCoverColoringMap.remove( theViewId );
2231 bool HYDROGUI_Module::isLandCoversScalarMapModeOn( const size_t theViewId ) const
2233 return myLandCoverColoringMap.contains( theViewId );
2236 void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObject )
2238 if ( theObject.IsNull() || !theObject->IsRemoved() ) {
2242 if ( theObject->GetKind() == KIND_STRICKLER_TABLE ) {
2243 Handle(HYDROData_StricklerTable) aTable =
2244 Handle(HYDROData_StricklerTable)::DownCast( theObject );
2245 QMutableMapIterator<size_t, Handle(HYDROData_StricklerTable)> anIter( myLandCoverColoringMap );
2246 while ( anIter.hasNext() ) {
2247 if ( HYDROGUI_DataObject::dataObjectEntry( anIter.next().value() ) ==
2248 HYDROGUI_DataObject::dataObjectEntry( aTable ) ) {
2255 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
2257 DEBTRACE("HYDROGUI_Module::onViewActivated");
2261 SUIT_ViewWindow* wnd = theMgr->getActiveView();
2262 OCCViewer_ViewFrame* occwnd = dynamic_cast<OCCViewer_ViewFrame*>( wnd );
2266 myOverview->setMainView( occwnd );
2269 void HYDROGUI_Module::setAutoZoomToAllViewManagers(bool bAutoZoom)
2271 ViewManagerList aViewManagers = getApp()->viewManagers();
2272 foreach (SUIT_ViewManager* aVMgr, aViewManagers)
2273 setAutoZoom(aVMgr, bAutoZoom);
2276 void HYDROGUI_Module::setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom)
2280 QVector<SUIT_ViewWindow*> aViews = aVMgr->getViews();
2281 foreach (SUIT_ViewWindow* aView, aViews)
2285 OCCViewer_ViewFrame* anOCCViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aView );
2288 anOCCViewFrame->setAutomaticZoom(bAutoZoom);
2289 for (int i = OCCViewer_ViewFrame::MAIN_VIEW; i<=OCCViewer_ViewFrame::TOP_RIGHT; i++)
2291 OCCViewer_ViewWindow* aV = anOCCViewFrame->getView(i);
2293 aV->setAutomaticZoom(bAutoZoom);
2296 OCCViewer_ViewWindow* anOCCViewWindow = dynamic_cast<OCCViewer_ViewWindow*>( aView );
2297 if (anOCCViewWindow)
2298 anOCCViewWindow->setAutomaticZoom(bAutoZoom);