1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_Displayer.h"
28 #include "HYDROGUI_GVSelector.h"
29 #include "HYDROGUI_InputPanel.h"
30 #include "HYDROGUI_ObjSelector.h"
31 #include "HYDROGUI_OCCDisplayer.h"
32 #include "HYDROGUI_OCCSelector.h"
33 #include "HYDROGUI_Operations.h"
34 #include "HYDROGUI_PrsImage.h"
35 #include "HYDROGUI_Tool.h"
36 #include "HYDROGUI_UpdateFlags.h"
37 #include "HYDROGUI_Shape.h"
38 #include "HYDROGUI_VTKPrs.h"
39 #include "HYDROGUI_VTKPrsDisplayer.h"
40 #include "HYDROGUI_AbstractDisplayer.h"
41 #include "HYDROGUI_PolylineOp.h"
43 #include <HYDROData_Image.h>
44 #include <HYDROData_Lambert93.h>
45 #include <HYDROData_Tool.h>
47 #include <HYDROData_OperationsFactory.h>
49 #include <GraphicsView_ViewFrame.h>
50 #include <GraphicsView_ViewManager.h>
51 #include <GraphicsView_ViewPort.h>
52 #include <GraphicsView_Viewer.h>
54 #include <ImageComposer_CutOperator.h>
55 #include <ImageComposer_CropOperator.h>
56 #include <ImageComposer_FuseOperator.h>
58 #include <LightApp_Application.h>
59 #include <LightApp_DataOwner.h>
60 #include <LightApp_GVSelector.h>
61 #include <LightApp_SelectionMgr.h>
62 #include <LightApp_UpdateFlags.h>
64 #include <OCCViewer_ViewFrame.h>
65 #include <OCCViewer_ViewManager.h>
66 #include <OCCViewer_ViewModel.h>
68 #include <SALOME_Event.h>
70 #include <SUIT_DataBrowser.h>
71 #include <SUIT_Desktop.h>
72 #include <SUIT_Study.h>
73 #include <SUIT_ViewManager.h>
75 #include <SVTK_ViewManager.h>
76 #include <SVTK_ViewModel.h>
77 #include <SVTK_Selector.h>
80 #include <QApplication>
81 #include <QGraphicsSceneMouseEvent>
84 static int ViewManagerId = 0;
86 extern "C" HYDRO_EXPORT CAM_Module* createModule()
88 return new HYDROGUI_Module();
91 extern "C" HYDRO_EXPORT char* getModuleVersion()
93 return (char*)HYDRO_VERSION;
96 HYDROGUI_Module::HYDROGUI_Module()
97 : LightApp_Module( "HYDRO" ),
100 myIsUpdateEnabled( true )
104 HYDROGUI_Module::~HYDROGUI_Module()
108 int HYDROGUI_Module::getStudyId() const
110 LightApp_Application* anApp = getApp();
111 return anApp ? anApp->activeStudy()->id() : 0;
114 void HYDROGUI_Module::initialize( CAM_Application* theApp )
116 LightApp_Module::initialize( theApp );
119 createUndoRedoActions();
124 setMenuShown( false );
125 setToolShown( false );
127 myDisplayer = new HYDROGUI_Displayer( this );
128 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
129 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
132 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
134 bool aRes = LightApp_Module::activateModule( theStudy );
136 LightApp_Application* anApp = getApp();
137 SUIT_Desktop* aDesktop = anApp->desktop();
139 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
141 setMenuShown( true );
142 setToolShown( true );
144 #ifndef DISABLE_PYCONSOLE
145 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
146 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
151 updateCommandsStatus();
153 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
154 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
159 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
161 ViewManagerMapIterator anIter( myViewManagerMap );
162 while( anIter.hasNext() )
163 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
164 getApp()->removeViewManager( aViewManager );
165 myViewManagerMap.clear();
167 myObjectStateMap.clear();
171 // clear the data model's list of copying objects
172 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
174 setMenuShown( false );
175 setToolShown( false );
177 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
179 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
180 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
182 return LightApp_Module::deactivateModule( theStudy );
185 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
188 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
189 #ifndef DISABLE_PYCONSOLE
190 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
192 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
195 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
197 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
200 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
204 HYDROGUI_DataModel* aModel = getDataModel();
206 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
207 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
208 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
209 bool anIsVTKView = theClient == SVTK_Viewer::Type();
210 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
213 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
215 bool anIsSelectedDataObjects = false;
216 bool anIsVisibleInSelection = false;
217 bool anIsHiddenInSelection = false;
219 bool anIsImage = false;
220 bool anIsImportedImage = false;
221 bool anIsImageHasRefs = false;
222 bool anIsFusedImage = false;
223 bool anIsCutImage = false;
224 bool anIsSplittedImage = false;
225 bool anIsMustBeUpdatedImage = false;
226 bool anIsPolyline = false;
227 bool anIsProfile = false;
228 bool anIsBathymetry = false;
229 bool anIsCalculation = false;
230 bool anIsImmersibleZone = false;
231 bool anIsVisualState = false;
232 bool anIsRegion = false;
233 bool anIsZone = false;
234 bool anIsObstacle = false;
235 bool anIsGeomObject = false;
237 // check the selected GEOM objects
238 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
239 theMenu->addAction( action( ImportGeomObjectId ) );
240 theMenu->addSeparator();
243 // check the selected data model objects
244 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
245 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
247 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
248 if( !anObject.IsNull() )
250 anIsSelectedDataObjects = true;
252 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
253 anIsVisibleInSelection |= aVisibility;
254 anIsHiddenInSelection |= !aVisibility;
256 if( anObject->GetKind() == KIND_IMAGE )
259 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
260 if( !anImage.IsNull() )
262 anIsImportedImage = anImage->HasLocalPoints();
263 anIsImageHasRefs = anImage->HasReferences();
264 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
266 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
268 QString anOperatorName = anOperator->name();
269 if( anOperatorName == ImageComposer_FuseOperator::Type() )
270 anIsFusedImage = true;
271 else if( anOperatorName == ImageComposer_CutOperator::Type() )
273 else if( anOperatorName == ImageComposer_CropOperator::Type() )
274 anIsSplittedImage = true;
277 if ( anImage->IsMustBeUpdated() )
279 anIsMustBeUpdatedImage = true;
283 else if( anObject->GetKind() == KIND_POLYLINEXY )
285 else if( anObject->GetKind() == KIND_PROFILE )
287 else if( anObject->GetKind() == KIND_CALCULATION )
288 anIsCalculation = true;
289 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
290 anIsImmersibleZone = true;
291 else if( anObject->GetKind() == KIND_VISUAL_STATE )
292 anIsVisualState = true;
293 else if( anObject->GetKind() == KIND_REGION )
295 else if( anObject->GetKind() == KIND_ZONE )
297 else if( anObject->GetKind() == KIND_BATHYMETRY )
298 anIsBathymetry = true;
299 else if( anObject->GetKind() == KIND_OBSTACLE )
303 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
306 // check the selected partitions
307 if( !anIsSelectedDataObjects && anIsObjectBrowser )
309 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
310 if( aSelectedPartition != KIND_UNKNOWN )
312 switch( aSelectedPartition )
315 theMenu->addAction( action( ImportImageId ) );
317 case KIND_POLYLINEXY:
318 theMenu->addAction( action( CreatePolylineId ) );
321 theMenu->addAction( action( CreateProfileId ) );
322 theMenu->addAction( action( ImportProfilesId ) );
324 case KIND_VISUAL_STATE:
325 theMenu->addAction( action( SaveVisualStateId ) );
327 case KIND_BATHYMETRY:
328 theMenu->addAction( action( ImportBathymetryId ) );
330 case KIND_CALCULATION:
331 theMenu->addAction( action( CreateCalculationId ) );
333 case KIND_IMMERSIBLE_ZONE:
334 theMenu->addAction( action( CreateImmersibleZoneId ) );
337 theMenu->addAction( action( ImportObstacleFromFileId ) );
338 theMenu->addAction( action( CreateBoxId ) );
339 theMenu->addAction( action( CreateCylinderId ) );
342 theMenu->addSeparator();
346 if( anIsSelectedDataObjects )
348 if ( anIsMustBeUpdatedImage )
350 theMenu->addAction( action( UpdateImageId ) );
351 theMenu->addSeparator();
354 if( aSeq.Length() == 1 )
358 if( anIsImportedImage )
359 theMenu->addAction( action( EditImportedImageId ) );
360 else if( anIsImageHasRefs )
363 theMenu->addAction( action( EditFusedImageId ) );
364 else if( anIsCutImage )
365 theMenu->addAction( action( EditCutImageId ) );
366 else if( anIsSplittedImage )
367 theMenu->addAction( action( EditSplittedImageId ) );
370 theMenu->addAction( action( ObserveImageId ) );
371 theMenu->addAction( action( ExportImageId ) );
372 theMenu->addSeparator();
374 if( anIsImageHasRefs )
376 theMenu->addAction( action( RemoveImageRefsId ) );
377 theMenu->addSeparator();
380 theMenu->addAction( action( FuseImagesId ) );
381 theMenu->addAction( action( CutImagesId ) );
382 theMenu->addAction( action( SplitImageId ) );
383 theMenu->addSeparator();
385 else if( anIsPolyline )
387 theMenu->addAction( action( EditPolylineId ) );
388 theMenu->addSeparator();
390 else if( anIsProfile )
392 theMenu->addAction( action( EditProfileId ) );
393 theMenu->addSeparator();
395 else if( anIsCalculation )
397 theMenu->addAction( action( EditCalculationId ) );
398 theMenu->addAction( action( ExportCalculationId ) );
399 theMenu->addSeparator();
401 else if( anIsImmersibleZone )
403 theMenu->addAction( action( EditImmersibleZoneId ) );
404 theMenu->addSeparator();
406 else if( anIsVisualState && anIsObjectBrowser )
408 theMenu->addAction( action( SaveVisualStateId ) );
409 theMenu->addAction( action( LoadVisualStateId ) );
410 theMenu->addSeparator();
413 // Add set color action for geometrical objects
414 if ( anIsGeomObject )
416 theMenu->addAction( action( SetColorId ) );
417 theMenu->addSeparator();
421 theMenu->addAction( action( DeleteId ) );
422 theMenu->addSeparator();
424 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle )
426 if( anIsHiddenInSelection )
427 theMenu->addAction( action( ShowId ) );
428 theMenu->addAction( action( ShowOnlyId ) );
429 if( anIsVisibleInSelection )
430 theMenu->addAction( action( HideId ) );
431 theMenu->addSeparator();
437 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
438 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
439 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
440 theMenu->addAction( action( DeleteId ) );
443 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
445 theMenu->addAction( action( ShowAllId ) );
446 theMenu->addAction( action( HideAllId ) );
447 theMenu->addSeparator();
451 void HYDROGUI_Module::update( const int flags )
453 if( !isUpdateEnabled() )
456 QApplication::setOverrideCursor( Qt::WaitCursor );
458 // To prevent calling this method recursively
459 // from one of the methods called below
460 setUpdateEnabled( false );
462 // store selected objects
463 QStringList aSelectedEntries = storeSelection();
465 bool aDoFitAll = flags & UF_FitAll;
466 if( ( flags & UF_Viewer ) )
467 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
469 if( ( flags & UF_OCCViewer ) )
470 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
472 if( ( flags & UF_VTKViewer ) )
473 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
475 if( ( flags & UF_Model ) && getDataModel() && getApp() )
477 getDataModel()->update( getStudyId() );
479 // Temporary workaround to prevent breaking
480 // the selection in the object browser.
481 // Note: processEvents() should be called after updateGV(),
482 // otherwise the application crashes from time to time.
483 //RKV: qApp->processEvents();
484 getApp()->updateObjectBrowser( true );
487 // Object browser is currently updated by using UF_Model flag
488 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
489 getApp()->updateObjectBrowser( true );
491 if( ( flags & UF_Controls ) && getApp() )
492 getApp()->updateActions();
494 // restore selected objects
495 restoreSelection( aSelectedEntries );
497 setUpdateEnabled( true );
499 QApplication::restoreOverrideCursor();
502 void HYDROGUI_Module::updateCommandsStatus()
504 LightApp_Module::updateCommandsStatus();
506 updateUndoRedoControls();
508 action( CopyId )->setEnabled( getDataModel()->canCopy() );
509 action( PasteId )->setEnabled( getDataModel()->canPaste() );
512 void HYDROGUI_Module::selectionChanged()
514 LightApp_Module::selectionChanged();
515 updateCommandsStatus();
518 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
520 return (HYDROGUI_DataModel*)dataModel();
523 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
528 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
530 return myOCCDisplayer;
533 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
535 return myVTKDisplayer;
538 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
540 if( myViewManagerMap.contains( theId ) )
542 return myViewManagerMap[ theId ].first;
547 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
549 if( myViewManagerMap.contains( theId ) )
551 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
552 GraphicsView_ViewManager* aViewManager =
553 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
555 return aViewManager->getViewer();
560 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
562 if( myViewManagerMap.contains( theId ) )
564 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
565 OCCViewer_ViewManager* aViewManager =
566 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
568 return aViewManager->getOCCViewer();
573 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
575 if( myViewManagerMap.contains( theId ) )
577 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
578 SVTK_ViewManager* aViewManager =
579 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
581 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
586 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
588 ViewManagerMapIterator anIter( myViewManagerMap );
589 while( anIter.hasNext() )
591 int anId = anIter.next().key();
592 const ViewManagerInfo& anInfo = anIter.value();
593 if( anInfo.first == theViewManager )
599 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
601 int anId = getViewManagerId( theViewManager );
604 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
605 return anInfo.second;
610 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
611 const ViewManagerRole theRole )
613 int anId = getViewManagerId( theViewManager );
616 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
617 anInfo.second = theRole;
621 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
622 const Handle(HYDROData_Entity)& theObject ) const
624 if( theObject.IsNull() )
627 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
628 if( anIter1 != myObjectStateMap.end() )
630 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
631 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
632 if( anIter2 != aName2ObjectStateMap.end() )
634 const ObjectState& anObjectState = anIter2.value();
635 return anObjectState.Visibility;
641 void HYDROGUI_Module::setObjectVisible( const int theViewId,
642 const Handle(HYDROData_Entity)& theObject,
643 const bool theState )
645 if( !theObject.IsNull() )
647 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
648 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
649 anObjectState.Visibility = theState;
653 /////////////////// OCC SHAPES PROCESSING
654 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
655 const Handle(HYDROData_Entity)& theObject ) const
657 HYDROGUI_Shape* aResShape = NULL;
658 if( theObject.IsNull() )
661 if ( myShapesMap.contains( theViewId ) )
663 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
664 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
666 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
677 void HYDROGUI_Module::setObjectShape( const int theViewId,
678 const Handle(HYDROData_Entity)& theObject,
679 HYDROGUI_Shape* theShape )
681 if( theObject.IsNull() )
684 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
685 aViewShapes.append( theShape );
688 void HYDROGUI_Module::removeObjectShape( const int theViewId,
689 const Handle(HYDROData_Entity)& theObject )
691 if ( !myShapesMap.contains( theViewId ) )
694 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
695 Handle(HYDROData_Entity) anObject;
696 for ( int i = 0; i < aViewShapes.length(); )
698 HYDROGUI_Shape* aShape = aViewShapes.at( i );
699 anObject = aShape->getObject();
700 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
703 aViewShapes.removeAt( i );
711 void HYDROGUI_Module::removeViewShapes( const int theViewId )
713 if ( !myShapesMap.contains( theViewId ) )
716 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
717 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
719 HYDROGUI_Shape* aShape = aViewShapes.at( i );
724 myShapesMap.remove( theViewId );
726 /////////////////// END OF OCC SHAPES PROCESSING
728 /////////////////// VTKPrs PROCESSING
729 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
730 const Handle(HYDROData_Entity)& theObject ) const
732 HYDROGUI_VTKPrs* aResShape = NULL;
733 if( theObject.IsNull() )
736 if ( myVTKPrsMap.contains( theViewId ) )
738 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
739 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
741 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
752 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
753 const Handle(HYDROData_Entity)& theObject,
754 HYDROGUI_VTKPrs* theShape )
756 if( theObject.IsNull() )
759 // Compute the new global Z range from the added presentation and the old global Z range.
760 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
761 double* aRange = theShape->getInternalZRange();
762 bool anIsUpdate = false;
763 if ( aRange[0] < aGlobalRange[0] )
765 aGlobalRange[0] = aRange[0];
768 if ( aRange[1] > aGlobalRange[1] )
770 aGlobalRange[1] = aRange[1];
776 updateVTKZRange( theViewId, aGlobalRange );
779 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
780 aViewShapes.append( theShape );
783 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
784 const Handle(HYDROData_Entity)& theObject )
786 if ( !myVTKPrsMap.contains( theViewId ) )
789 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
790 Handle(HYDROData_Entity) anObject;
791 for ( int i = 0; i < aViewShapes.length(); )
793 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
794 anObject = aShape->getObject();
795 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
798 aViewShapes.removeAt( i );
805 // Invalidate global Z range
806 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
807 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
810 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
812 if ( !myVTKPrsMap.contains( theViewId ) )
815 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
816 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
818 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
823 myVTKPrsMap.remove( theViewId );
826 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
828 if ( myVTKPrsMap.contains( theViewId ) )
830 // For the given viewer id update all VTK presentations ...
831 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
832 HYDROGUI_VTKPrs* aShape;
833 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
835 aShape = aViewShapes.at( i );
838 aShape->setZRange( theRange );
842 // ... and update the global color legend scalar bar.
843 getVTKDisplayer()->SetZRange( theViewId, theRange );
845 /////////////////// END OF VTKPrs PROCESSING
847 CAM_DataModel* HYDROGUI_Module::createDataModel()
849 return new HYDROGUI_DataModel( this );
852 void HYDROGUI_Module::customEvent( QEvent* e )
854 int aType = e->type();
855 if ( aType == NewViewEvent )
857 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
858 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
860 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
862 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
863 ViewManagerRole aRole = getViewManagerRole( aViewManager );
865 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
867 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
868 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
870 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
871 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
872 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
874 //ouv: temporarily commented
875 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
878 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
881 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
887 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
889 QEvent::Type aType = theEvent->type();
890 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
892 if( aType == QEvent::Show )
894 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
895 e->setData( theObj );
896 QApplication::postEvent( this, e );
897 theObj->removeEventFilter( this );
900 return LightApp_Module::eventFilter( theObj, theEvent );
903 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
905 LightApp_Module::onViewManagerAdded( theViewManager );
907 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
909 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
910 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
912 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
914 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
915 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
918 createSelector( theViewManager ); // replace the default selector
920 ViewManagerInfo anInfo( theViewManager, VMR_General );
921 myViewManagerMap.insert( ViewManagerId++, anInfo );
924 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
926 LightApp_Module::onViewManagerRemoved( theViewManager );
928 createSelector( theViewManager ); // replace the default selector
930 int anId = getViewManagerId( theViewManager );
933 OCCViewer_ViewManager* anOCCViewManager =
934 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
935 if ( anOCCViewManager )
937 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
939 removeViewShapes( (size_t)anOCCViewer );
942 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
944 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
947 getVTKDisplayer()->DeleteScalarBar( anId );
948 removeViewShapes( (size_t)aVTKViewer );
952 myViewManagerMap.remove( anId );
956 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
958 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
960 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
962 aViewFrame->installEventFilter( this );
964 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
966 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
967 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
970 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
972 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
974 aViewFrame->onTopView();
979 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
981 /* ouv: currently unused
982 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
984 SUIT_ViewManager* aViewManager = 0;
986 QObject* aParent = aViewPort;
987 while( aParent = aParent->parent() )
989 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
991 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
993 aViewManager = aViewer->getViewManager();
1002 double aMouseX = theEvent->scenePos().x();
1003 double aMouseY = theEvent->scenePos().y();
1005 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1006 if( aRole == VMR_General )
1008 int aXDeg = 0, aYDeg = 0;
1009 int aXMin = 0, aYMin = 0;
1010 double aXSec = 0, aYSec = 0;
1011 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1012 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1014 QString aDegSymbol( QChar( 0x00B0 ) );
1015 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1016 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1018 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1020 else if( aRole == VMR_TransformImage )
1021 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1026 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1027 const bool theIsInit,
1028 const bool theIsForced,
1029 const bool theDoFitAll )
1031 QList<int> aViewManagerIdList;
1033 // currently, all views are updated
1034 ViewManagerMapIterator anIter( myViewManagerMap );
1035 while( anIter.hasNext() )
1037 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1039 if ( theDisplayer->IsApplicable( aViewManager ) )
1041 int anId = anIter.key();
1042 aViewManagerIdList.append( anId );
1046 QListIterator<int> anIdIter( aViewManagerIdList );
1047 while( anIdIter.hasNext() )
1049 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1053 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1055 if( !theViewManager )
1058 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1059 if( !aSelectionMgr )
1062 QString aViewType = theViewManager->getType();
1063 if( aViewType != GraphicsView_Viewer::Type() &&
1064 aViewType != OCCViewer_Viewer::Type())
1067 QList<SUIT_Selector*> aSelectorList;
1068 aSelectionMgr->selectors( aViewType, aSelectorList );
1070 // disable all alien selectors
1071 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1072 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1074 SUIT_Selector* aSelector = *anIter;
1075 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1076 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1077 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1078 aSelector->setEnabled( false );
1081 if ( aViewType == GraphicsView_Viewer::Type() )
1083 GraphicsView_ViewManager* aViewManager =
1084 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1086 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1088 else if ( aViewType == OCCViewer_Viewer::Type() )
1090 OCCViewer_ViewManager* aViewManager =
1091 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1093 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1097 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1099 bool aPrevState = myIsUpdateEnabled;
1100 myIsUpdateEnabled = theState;
1104 bool HYDROGUI_Module::isUpdateEnabled() const
1106 return myIsUpdateEnabled;
1109 QStringList HYDROGUI_Module::storeSelection() const
1111 QStringList anEntryList;
1112 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1114 SUIT_DataOwnerPtrList aList( true );
1115 aSelectionMgr->selected( aList );
1117 SUIT_DataOwnerPtrList::iterator anIter;
1118 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1120 const LightApp_DataOwner* anOwner =
1121 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1123 anEntryList.append( anOwner->entry() );
1129 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1131 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1133 SUIT_DataOwnerPtrList aList( true );
1134 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1135 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1136 aSelectionMgr->setSelected( aList );