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();
170 // clear the data model's list of copying objects
171 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
173 setMenuShown( false );
174 setToolShown( false );
176 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
178 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
179 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
181 return LightApp_Module::deactivateModule( theStudy );
184 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
187 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
188 #ifndef DISABLE_PYCONSOLE
189 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
191 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
194 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
196 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
199 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
203 HYDROGUI_DataModel* aModel = getDataModel();
205 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
206 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
207 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
208 bool anIsVTKView = theClient == SVTK_Viewer::Type();
209 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
212 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
214 bool anIsSelectedDataObjects = false;
215 bool anIsVisibleInSelection = false;
216 bool anIsHiddenInSelection = false;
218 bool anIsImage = false;
219 bool anIsImportedImage = false;
220 bool anIsImageHasRefs = false;
221 bool anIsFusedImage = false;
222 bool anIsCutImage = false;
223 bool anIsSplittedImage = false;
224 bool anIsMustBeUpdatedImage = false;
225 bool anIsPolyline = false;
226 bool anIsProfile = false;
227 bool anIsBathymetry = false;
228 bool anIsCalculation = false;
229 bool anIsImmersibleZone = false;
230 bool anIsVisualState = false;
231 bool anIsRegion = false;
232 bool anIsZone = false;
233 bool anIsObstacle = false;
234 bool anIsGeomObject = false;
236 // check the selected GEOM objects
237 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
238 theMenu->addAction( action( ImportGeomObjectId ) );
239 theMenu->addSeparator();
242 // check the selected data model objects
243 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
244 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
246 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
247 if( !anObject.IsNull() )
249 anIsSelectedDataObjects = true;
251 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
252 anIsVisibleInSelection |= aVisibility;
253 anIsHiddenInSelection |= !aVisibility;
255 if( anObject->GetKind() == KIND_IMAGE )
258 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
259 if( !anImage.IsNull() )
261 anIsImportedImage = anImage->HasLocalPoints();
262 anIsImageHasRefs = anImage->HasReferences();
263 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
265 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
267 QString anOperatorName = anOperator->name();
268 if( anOperatorName == ImageComposer_FuseOperator::Type() )
269 anIsFusedImage = true;
270 else if( anOperatorName == ImageComposer_CutOperator::Type() )
272 else if( anOperatorName == ImageComposer_CropOperator::Type() )
273 anIsSplittedImage = true;
276 if ( anImage->IsMustBeUpdated() )
278 anIsMustBeUpdatedImage = true;
282 else if( anObject->GetKind() == KIND_POLYLINEXY )
284 else if( anObject->GetKind() == KIND_PROFILE )
286 else if( anObject->GetKind() == KIND_CALCULATION )
287 anIsCalculation = true;
288 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
289 anIsImmersibleZone = true;
290 else if( anObject->GetKind() == KIND_VISUAL_STATE )
291 anIsVisualState = true;
292 else if( anObject->GetKind() == KIND_REGION )
294 else if( anObject->GetKind() == KIND_ZONE )
296 else if( anObject->GetKind() == KIND_BATHYMETRY )
297 anIsBathymetry = true;
298 else if( anObject->GetKind() == KIND_OBSTACLE )
302 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
305 // check the selected partitions
306 if( !anIsSelectedDataObjects && anIsObjectBrowser )
308 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
309 if( aSelectedPartition != KIND_UNKNOWN )
311 switch( aSelectedPartition )
314 theMenu->addAction( action( ImportImageId ) );
316 case KIND_POLYLINEXY:
317 theMenu->addAction( action( CreatePolylineId ) );
320 theMenu->addAction( action( CreateProfileId ) );
321 theMenu->addAction( action( ImportProfilesId ) );
323 case KIND_VISUAL_STATE:
324 theMenu->addAction( action( SaveVisualStateId ) );
326 case KIND_BATHYMETRY:
327 theMenu->addAction( action( ImportBathymetryId ) );
329 case KIND_CALCULATION:
330 theMenu->addAction( action( CreateCalculationId ) );
332 case KIND_IMMERSIBLE_ZONE:
333 theMenu->addAction( action( CreateImmersibleZoneId ) );
336 theMenu->addAction( action( ImportObstacleFromFileId ) );
337 theMenu->addAction( action( CreateBoxId ) );
338 theMenu->addAction( action( CreateCylinderId ) );
341 theMenu->addSeparator();
345 if( anIsSelectedDataObjects )
347 if ( anIsMustBeUpdatedImage )
349 theMenu->addAction( action( UpdateImageId ) );
350 theMenu->addSeparator();
353 if( aSeq.Length() == 1 )
357 if( anIsImportedImage )
358 theMenu->addAction( action( EditImportedImageId ) );
359 else if( anIsImageHasRefs )
362 theMenu->addAction( action( EditFusedImageId ) );
363 else if( anIsCutImage )
364 theMenu->addAction( action( EditCutImageId ) );
365 else if( anIsSplittedImage )
366 theMenu->addAction( action( EditSplittedImageId ) );
369 theMenu->addAction( action( ObserveImageId ) );
370 theMenu->addAction( action( ExportImageId ) );
371 theMenu->addSeparator();
373 if( anIsImageHasRefs )
375 theMenu->addAction( action( RemoveImageRefsId ) );
376 theMenu->addSeparator();
379 theMenu->addAction( action( FuseImagesId ) );
380 theMenu->addAction( action( CutImagesId ) );
381 theMenu->addAction( action( SplitImageId ) );
382 theMenu->addSeparator();
384 else if( anIsPolyline )
386 theMenu->addAction( action( EditPolylineId ) );
387 theMenu->addSeparator();
389 else if( anIsProfile )
391 theMenu->addAction( action( EditProfileId ) );
392 theMenu->addSeparator();
394 else if( anIsCalculation )
396 theMenu->addAction( action( EditCalculationId ) );
397 theMenu->addAction( action( ExportCalculationId ) );
398 theMenu->addSeparator();
400 else if( anIsImmersibleZone )
402 theMenu->addAction( action( EditImmersibleZoneId ) );
403 theMenu->addSeparator();
405 else if( anIsVisualState && anIsObjectBrowser )
407 theMenu->addAction( action( SaveVisualStateId ) );
408 theMenu->addAction( action( LoadVisualStateId ) );
409 theMenu->addSeparator();
412 // Add set color action for geometrical objects
413 if ( anIsGeomObject )
415 theMenu->addAction( action( SetColorId ) );
416 theMenu->addSeparator();
420 theMenu->addAction( action( DeleteId ) );
421 theMenu->addSeparator();
423 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle )
425 if( anIsHiddenInSelection )
426 theMenu->addAction( action( ShowId ) );
427 theMenu->addAction( action( ShowOnlyId ) );
428 if( anIsVisibleInSelection )
429 theMenu->addAction( action( HideId ) );
430 theMenu->addSeparator();
436 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
437 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
438 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
439 theMenu->addAction( action( DeleteId ) );
442 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
444 theMenu->addAction( action( ShowAllId ) );
445 theMenu->addAction( action( HideAllId ) );
446 theMenu->addSeparator();
450 void HYDROGUI_Module::update( const int flags )
452 if( !isUpdateEnabled() )
455 QApplication::setOverrideCursor( Qt::WaitCursor );
457 // To prevent calling this method recursively
458 // from one of the methods called below
459 setUpdateEnabled( false );
461 // store selected objects
462 QStringList aSelectedEntries = storeSelection();
464 bool aDoFitAll = flags & UF_FitAll;
465 if( ( flags & UF_Viewer ) )
466 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
468 if( ( flags & UF_OCCViewer ) )
469 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
471 if( ( flags & UF_VTKViewer ) )
472 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
474 if( ( flags & UF_Model ) && getDataModel() && getApp() )
476 getDataModel()->update( getStudyId() );
478 // Temporary workaround to prevent breaking
479 // the selection in the object browser.
480 // Note: processEvents() should be called after updateGV(),
481 // otherwise the application crashes from time to time.
482 //RKV: qApp->processEvents();
483 getApp()->updateObjectBrowser( true );
486 // Object browser is currently updated by using UF_Model flag
487 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
488 getApp()->updateObjectBrowser( true );
490 if( ( flags & UF_Controls ) && getApp() )
491 getApp()->updateActions();
493 // restore selected objects
494 restoreSelection( aSelectedEntries );
496 setUpdateEnabled( true );
498 QApplication::restoreOverrideCursor();
501 void HYDROGUI_Module::updateCommandsStatus()
503 LightApp_Module::updateCommandsStatus();
505 updateUndoRedoControls();
507 action( CopyId )->setEnabled( getDataModel()->canCopy() );
508 action( PasteId )->setEnabled( getDataModel()->canPaste() );
511 void HYDROGUI_Module::selectionChanged()
513 LightApp_Module::selectionChanged();
514 updateCommandsStatus();
517 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
519 return (HYDROGUI_DataModel*)dataModel();
522 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
527 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
529 return myOCCDisplayer;
532 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
534 return myVTKDisplayer;
537 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
539 if( myViewManagerMap.contains( theId ) )
541 return myViewManagerMap[ theId ].first;
546 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
548 if( myViewManagerMap.contains( theId ) )
550 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
551 GraphicsView_ViewManager* aViewManager =
552 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
554 return aViewManager->getViewer();
559 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
561 if( myViewManagerMap.contains( theId ) )
563 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
564 OCCViewer_ViewManager* aViewManager =
565 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
567 return aViewManager->getOCCViewer();
572 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
574 if( myViewManagerMap.contains( theId ) )
576 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
577 SVTK_ViewManager* aViewManager =
578 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
580 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
585 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
587 ViewManagerMapIterator anIter( myViewManagerMap );
588 while( anIter.hasNext() )
590 int anId = anIter.next().key();
591 const ViewManagerInfo& anInfo = anIter.value();
592 if( anInfo.first == theViewManager )
598 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
600 int anId = getViewManagerId( theViewManager );
603 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
604 return anInfo.second;
609 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
610 const ViewManagerRole theRole )
612 int anId = getViewManagerId( theViewManager );
615 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
616 anInfo.second = theRole;
620 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
621 const Handle(HYDROData_Entity)& theObject ) const
623 if( theObject.IsNull() )
626 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
627 if( anIter1 != myObjectStateMap.end() )
629 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
630 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
631 if( anIter2 != aName2ObjectStateMap.end() )
633 const ObjectState& anObjectState = anIter2.value();
634 return anObjectState.Visibility;
640 void HYDROGUI_Module::setObjectVisible( const int theViewId,
641 const Handle(HYDROData_Entity)& theObject,
642 const bool theState )
644 if( !theObject.IsNull() )
646 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
647 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
648 anObjectState.Visibility = theState;
652 /////////////////// OCC SHAPES PROCESSING
653 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
654 const Handle(HYDROData_Entity)& theObject ) const
656 HYDROGUI_Shape* aResShape = NULL;
657 if( theObject.IsNull() )
660 if ( myShapesMap.contains( theViewId ) )
662 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
663 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
665 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
676 void HYDROGUI_Module::setObjectShape( const int theViewId,
677 const Handle(HYDROData_Entity)& theObject,
678 HYDROGUI_Shape* theShape )
680 if( theObject.IsNull() )
683 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
684 aViewShapes.append( theShape );
687 void HYDROGUI_Module::removeObjectShape( const int theViewId,
688 const Handle(HYDROData_Entity)& theObject )
690 if ( !myShapesMap.contains( theViewId ) )
693 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
694 Handle(HYDROData_Entity) anObject;
695 for ( int i = 0; i < aViewShapes.length(); )
697 HYDROGUI_Shape* aShape = aViewShapes.at( i );
698 anObject = aShape->getObject();
699 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
702 aViewShapes.removeAt( i );
710 void HYDROGUI_Module::removeViewShapes( const int theViewId )
712 if ( !myShapesMap.contains( theViewId ) )
715 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
716 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
718 HYDROGUI_Shape* aShape = aViewShapes.at( i );
723 myShapesMap.remove( theViewId );
725 /////////////////// END OF OCC SHAPES PROCESSING
727 /////////////////// VTKPrs PROCESSING
728 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
729 const Handle(HYDROData_Entity)& theObject ) const
731 HYDROGUI_VTKPrs* aResShape = NULL;
732 if( theObject.IsNull() )
735 if ( myVTKPrsMap.contains( theViewId ) )
737 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
738 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
740 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
751 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
752 const Handle(HYDROData_Entity)& theObject,
753 HYDROGUI_VTKPrs* theShape )
755 if( theObject.IsNull() )
758 // Compute the new global Z range from the added presentation and the old global Z range.
759 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
760 double* aRange = theShape->getInternalZRange();
761 bool anIsUpdate = false;
762 if ( aRange[0] < aGlobalRange[0] )
764 aGlobalRange[0] = aRange[0];
767 if ( aRange[1] > aGlobalRange[1] )
769 aGlobalRange[1] = aRange[1];
775 updateVTKZRange( theViewId, aGlobalRange );
778 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
779 aViewShapes.append( theShape );
782 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
783 const Handle(HYDROData_Entity)& theObject )
785 if ( !myVTKPrsMap.contains( theViewId ) )
788 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
789 Handle(HYDROData_Entity) anObject;
790 for ( int i = 0; i < aViewShapes.length(); )
792 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
793 anObject = aShape->getObject();
794 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
797 aViewShapes.removeAt( i );
804 // Invalidate global Z range
805 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
806 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
809 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
811 if ( !myVTKPrsMap.contains( theViewId ) )
814 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
815 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
817 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
822 myVTKPrsMap.remove( theViewId );
825 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
827 if ( myVTKPrsMap.contains( theViewId ) )
829 // For the given viewer id update all VTK presentations ...
830 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
831 HYDROGUI_VTKPrs* aShape;
832 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
834 aShape = aViewShapes.at( i );
837 aShape->setZRange( theRange );
841 // ... and update the global color legend scalar bar.
842 getVTKDisplayer()->SetZRange( theViewId, theRange );
844 /////////////////// END OF VTKPrs PROCESSING
846 CAM_DataModel* HYDROGUI_Module::createDataModel()
848 return new HYDROGUI_DataModel( this );
851 void HYDROGUI_Module::customEvent( QEvent* e )
853 int aType = e->type();
854 if ( aType == NewViewEvent )
856 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
857 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
859 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
861 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
862 ViewManagerRole aRole = getViewManagerRole( aViewManager );
864 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
866 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
867 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
869 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
870 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
871 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
873 //ouv: temporarily commented
874 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
877 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
880 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
886 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
888 QEvent::Type aType = theEvent->type();
889 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
891 if( aType == QEvent::Show )
893 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
894 e->setData( theObj );
895 QApplication::postEvent( this, e );
896 theObj->removeEventFilter( this );
899 return LightApp_Module::eventFilter( theObj, theEvent );
902 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
904 LightApp_Module::onViewManagerAdded( theViewManager );
906 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
908 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
909 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
911 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
913 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
914 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
917 createSelector( theViewManager ); // replace the default selector
919 ViewManagerInfo anInfo( theViewManager, VMR_General );
920 myViewManagerMap.insert( ViewManagerId++, anInfo );
923 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
925 LightApp_Module::onViewManagerRemoved( theViewManager );
927 createSelector( theViewManager ); // replace the default selector
929 int anId = getViewManagerId( theViewManager );
932 OCCViewer_ViewManager* anOCCViewManager =
933 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
934 if ( anOCCViewManager )
936 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
938 removeViewShapes( (size_t)anOCCViewer );
941 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
943 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
946 getVTKDisplayer()->DeleteScalarBar( anId );
947 removeViewShapes( (size_t)aVTKViewer );
951 myViewManagerMap.remove( anId );
955 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
957 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
959 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
961 aViewFrame->installEventFilter( this );
963 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
965 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
966 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
969 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
971 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
973 aViewFrame->onTopView();
978 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
980 /* ouv: currently unused
981 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
983 SUIT_ViewManager* aViewManager = 0;
985 QObject* aParent = aViewPort;
986 while( aParent = aParent->parent() )
988 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
990 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
992 aViewManager = aViewer->getViewManager();
1001 double aMouseX = theEvent->scenePos().x();
1002 double aMouseY = theEvent->scenePos().y();
1004 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1005 if( aRole == VMR_General )
1007 int aXDeg = 0, aYDeg = 0;
1008 int aXMin = 0, aYMin = 0;
1009 double aXSec = 0, aYSec = 0;
1010 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1011 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1013 QString aDegSymbol( QChar( 0x00B0 ) );
1014 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1015 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1017 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1019 else if( aRole == VMR_TransformImage )
1020 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1025 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1026 const bool theIsInit,
1027 const bool theIsForced,
1028 const bool theDoFitAll )
1030 QList<int> aViewManagerIdList;
1032 // currently, all views are updated
1033 ViewManagerMapIterator anIter( myViewManagerMap );
1034 while( anIter.hasNext() )
1036 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1038 if ( theDisplayer->IsApplicable( aViewManager ) )
1040 int anId = anIter.key();
1041 aViewManagerIdList.append( anId );
1045 QListIterator<int> anIdIter( aViewManagerIdList );
1046 while( anIdIter.hasNext() )
1048 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1052 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1054 if( !theViewManager )
1057 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1058 if( !aSelectionMgr )
1061 QString aViewType = theViewManager->getType();
1062 if( aViewType != GraphicsView_Viewer::Type() &&
1063 aViewType != OCCViewer_Viewer::Type())
1066 QList<SUIT_Selector*> aSelectorList;
1067 aSelectionMgr->selectors( aViewType, aSelectorList );
1069 // disable all alien selectors
1070 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1071 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1073 SUIT_Selector* aSelector = *anIter;
1074 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1075 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1076 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1077 aSelector->setEnabled( false );
1080 if ( aViewType == GraphicsView_Viewer::Type() )
1082 GraphicsView_ViewManager* aViewManager =
1083 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1085 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1087 else if ( aViewType == OCCViewer_Viewer::Type() )
1089 OCCViewer_ViewManager* aViewManager =
1090 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1092 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1096 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1098 bool aPrevState = myIsUpdateEnabled;
1099 myIsUpdateEnabled = theState;
1103 bool HYDROGUI_Module::isUpdateEnabled() const
1105 return myIsUpdateEnabled;
1108 QStringList HYDROGUI_Module::storeSelection() const
1110 QStringList anEntryList;
1111 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1113 SUIT_DataOwnerPtrList aList( true );
1114 aSelectionMgr->selected( aList );
1116 SUIT_DataOwnerPtrList::iterator anIter;
1117 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1119 const LightApp_DataOwner* anOwner =
1120 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1122 anEntryList.append( anOwner->entry() );
1128 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1130 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1132 SUIT_DataOwnerPtrList aList( true );
1133 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1134 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1135 aSelectionMgr->setSelected( aList );