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 anAllAreProfiles = false;
229 bool anIsBathymetry = false;
230 bool anIsCalculation = false;
231 bool anIsImmersibleZone = false;
232 bool anIsVisualState = false;
233 bool anIsRegion = false;
234 bool anIsZone = false;
235 bool anIsObstacle = false;
236 bool anIsGeomObject = false;
238 // check the selected GEOM objects
239 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
240 theMenu->addAction( action( ImportGeomObjectId ) );
241 theMenu->addSeparator();
244 // check the selected data model objects
245 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
246 int aNbOfSelectedProfiles = 0;
247 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
249 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
250 if( !anObject.IsNull() )
252 anIsSelectedDataObjects = true;
254 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
255 anIsVisibleInSelection |= aVisibility;
256 anIsHiddenInSelection |= !aVisibility;
258 if( anObject->GetKind() == KIND_IMAGE )
261 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
262 if( !anImage.IsNull() )
264 anIsImportedImage = anImage->HasLocalPoints();
265 anIsImageHasRefs = anImage->HasReferences();
266 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
268 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
270 QString anOperatorName = anOperator->name();
271 if( anOperatorName == ImageComposer_FuseOperator::Type() )
272 anIsFusedImage = true;
273 else if( anOperatorName == ImageComposer_CutOperator::Type() )
275 else if( anOperatorName == ImageComposer_CropOperator::Type() )
276 anIsSplittedImage = true;
279 if ( anImage->IsMustBeUpdated() )
281 anIsMustBeUpdatedImage = true;
285 else if( anObject->GetKind() == KIND_POLYLINEXY )
287 else if( anObject->GetKind() == KIND_PROFILE ) {
289 aNbOfSelectedProfiles++;
291 else if( anObject->GetKind() == KIND_CALCULATION )
292 anIsCalculation = true;
293 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
294 anIsImmersibleZone = true;
295 else if( anObject->GetKind() == KIND_VISUAL_STATE )
296 anIsVisualState = true;
297 else if( anObject->GetKind() == KIND_REGION )
299 else if( anObject->GetKind() == KIND_ZONE )
301 else if( anObject->GetKind() == KIND_BATHYMETRY )
302 anIsBathymetry = true;
303 else if( anObject->GetKind() == KIND_OBSTACLE )
307 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
310 // Check if all selected objects are profiles
311 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
312 ( aNbOfSelectedProfiles == aSeq.Length() );
314 // check the selected partitions
315 if( !anIsSelectedDataObjects && anIsObjectBrowser )
317 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
318 if( aSelectedPartition != KIND_UNKNOWN )
320 switch( aSelectedPartition )
323 theMenu->addAction( action( ImportImageId ) );
325 case KIND_POLYLINEXY:
326 theMenu->addAction( action( CreatePolylineId ) );
329 theMenu->addAction( action( CreateProfileId ) );
330 theMenu->addAction( action( ImportProfilesId ) );
331 theMenu->addAction( action( AllGeoreferencementId ) );
333 case KIND_VISUAL_STATE:
334 theMenu->addAction( action( SaveVisualStateId ) );
336 case KIND_BATHYMETRY:
337 theMenu->addAction( action( ImportBathymetryId ) );
339 case KIND_CALCULATION:
340 theMenu->addAction( action( CreateCalculationId ) );
342 case KIND_IMMERSIBLE_ZONE:
343 theMenu->addAction( action( CreateImmersibleZoneId ) );
346 theMenu->addAction( action( ImportObstacleFromFileId ) );
347 theMenu->addAction( action( CreateBoxId ) );
348 theMenu->addAction( action( CreateCylinderId ) );
351 theMenu->addSeparator();
355 if( anIsSelectedDataObjects )
357 if ( anIsMustBeUpdatedImage )
359 theMenu->addAction( action( UpdateImageId ) );
360 theMenu->addSeparator();
363 if( aSeq.Length() == 1 )
367 if( anIsImportedImage )
368 theMenu->addAction( action( EditImportedImageId ) );
369 else if( anIsImageHasRefs )
372 theMenu->addAction( action( EditFusedImageId ) );
373 else if( anIsCutImage )
374 theMenu->addAction( action( EditCutImageId ) );
375 else if( anIsSplittedImage )
376 theMenu->addAction( action( EditSplittedImageId ) );
379 theMenu->addAction( action( ObserveImageId ) );
380 theMenu->addAction( action( ExportImageId ) );
381 theMenu->addSeparator();
383 if( anIsImageHasRefs )
385 theMenu->addAction( action( RemoveImageRefsId ) );
386 theMenu->addSeparator();
389 theMenu->addAction( action( FuseImagesId ) );
390 theMenu->addAction( action( CutImagesId ) );
391 theMenu->addAction( action( SplitImageId ) );
392 theMenu->addSeparator();
394 else if( anIsPolyline )
396 theMenu->addAction( action( EditPolylineId ) );
397 theMenu->addSeparator();
399 else if( anIsProfile )
401 theMenu->addAction( action( EditProfileId ) );
402 theMenu->addAction( action( SelectedGeoreferencementId ) );
403 theMenu->addSeparator();
405 else if( anIsCalculation )
407 theMenu->addAction( action( EditCalculationId ) );
408 theMenu->addAction( action( ExportCalculationId ) );
409 theMenu->addSeparator();
411 else if( anIsImmersibleZone )
413 theMenu->addAction( action( EditImmersibleZoneId ) );
414 theMenu->addSeparator();
416 else if( anIsVisualState && anIsObjectBrowser )
418 theMenu->addAction( action( SaveVisualStateId ) );
419 theMenu->addAction( action( LoadVisualStateId ) );
420 theMenu->addSeparator();
423 // Add set color action for geometrical objects
424 if ( anIsGeomObject )
426 theMenu->addAction( action( SetColorId ) );
427 theMenu->addSeparator();
431 if ( anAllAreProfiles ) {
432 theMenu->addAction( action( SelectedGeoreferencementId ) );
433 theMenu->addSeparator();
436 theMenu->addAction( action( DeleteId ) );
437 theMenu->addSeparator();
439 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle )
441 if( anIsHiddenInSelection )
442 theMenu->addAction( action( ShowId ) );
443 theMenu->addAction( action( ShowOnlyId ) );
444 if( anIsVisibleInSelection )
445 theMenu->addAction( action( HideId ) );
446 theMenu->addSeparator();
452 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
453 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
454 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
455 theMenu->addAction( action( DeleteId ) );
458 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
460 theMenu->addAction( action( ShowAllId ) );
461 theMenu->addAction( action( HideAllId ) );
462 theMenu->addSeparator();
466 void HYDROGUI_Module::update( const int flags )
468 if( !isUpdateEnabled() )
471 QApplication::setOverrideCursor( Qt::WaitCursor );
473 // To prevent calling this method recursively
474 // from one of the methods called below
475 setUpdateEnabled( false );
477 // store selected objects
478 QStringList aSelectedEntries = storeSelection();
480 bool aDoFitAll = flags & UF_FitAll;
481 if( ( flags & UF_Viewer ) )
482 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
484 if( ( flags & UF_OCCViewer ) )
485 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
487 if( ( flags & UF_VTKViewer ) )
488 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
490 if( ( flags & UF_Model ) && getDataModel() && getApp() )
492 getDataModel()->update( getStudyId() );
494 // Temporary workaround to prevent breaking
495 // the selection in the object browser.
496 // Note: processEvents() should be called after updateGV(),
497 // otherwise the application crashes from time to time.
498 //RKV: qApp->processEvents();
499 getApp()->updateObjectBrowser( true );
502 // Object browser is currently updated by using UF_Model flag
503 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
504 getApp()->updateObjectBrowser( true );
506 if( ( flags & UF_Controls ) && getApp() )
507 getApp()->updateActions();
509 // restore selected objects
510 restoreSelection( aSelectedEntries );
512 setUpdateEnabled( true );
514 QApplication::restoreOverrideCursor();
517 void HYDROGUI_Module::updateCommandsStatus()
519 LightApp_Module::updateCommandsStatus();
521 updateUndoRedoControls();
523 action( CopyId )->setEnabled( getDataModel()->canCopy() );
524 action( PasteId )->setEnabled( getDataModel()->canPaste() );
527 void HYDROGUI_Module::selectionChanged()
529 LightApp_Module::selectionChanged();
530 updateCommandsStatus();
533 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
535 return (HYDROGUI_DataModel*)dataModel();
538 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
543 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
545 return myOCCDisplayer;
548 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
550 return myVTKDisplayer;
553 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
555 if( myViewManagerMap.contains( theId ) )
557 return myViewManagerMap[ theId ].first;
562 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
564 if( myViewManagerMap.contains( theId ) )
566 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
567 GraphicsView_ViewManager* aViewManager =
568 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
570 return aViewManager->getViewer();
575 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
577 if( myViewManagerMap.contains( theId ) )
579 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
580 OCCViewer_ViewManager* aViewManager =
581 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
583 return aViewManager->getOCCViewer();
588 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
590 if( myViewManagerMap.contains( theId ) )
592 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
593 SVTK_ViewManager* aViewManager =
594 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
596 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
601 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
603 ViewManagerMapIterator anIter( myViewManagerMap );
604 while( anIter.hasNext() )
606 int anId = anIter.next().key();
607 const ViewManagerInfo& anInfo = anIter.value();
608 if( anInfo.first == theViewManager )
614 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
616 int anId = getViewManagerId( theViewManager );
619 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
620 return anInfo.second;
625 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
626 const ViewManagerRole theRole )
628 int anId = getViewManagerId( theViewManager );
631 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
632 anInfo.second = theRole;
636 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
637 const Handle(HYDROData_Entity)& theObject ) const
639 if( theObject.IsNull() )
642 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
643 if( anIter1 != myObjectStateMap.end() )
645 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
646 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
647 if( anIter2 != aName2ObjectStateMap.end() )
649 const ObjectState& anObjectState = anIter2.value();
650 return anObjectState.Visibility;
656 void HYDROGUI_Module::setObjectVisible( const int theViewId,
657 const Handle(HYDROData_Entity)& theObject,
658 const bool theState )
660 if( !theObject.IsNull() )
662 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
663 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
664 anObjectState.Visibility = theState;
668 /////////////////// OCC SHAPES PROCESSING
669 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
670 const Handle(HYDROData_Entity)& theObject ) const
672 HYDROGUI_Shape* aResShape = NULL;
673 if( theObject.IsNull() )
676 if ( myShapesMap.contains( theViewId ) )
678 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
679 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
681 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
692 void HYDROGUI_Module::setObjectShape( const int theViewId,
693 const Handle(HYDROData_Entity)& theObject,
694 HYDROGUI_Shape* theShape )
696 if( theObject.IsNull() )
699 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
700 aViewShapes.append( theShape );
703 void HYDROGUI_Module::removeObjectShape( const int theViewId,
704 const Handle(HYDROData_Entity)& theObject )
706 if ( !myShapesMap.contains( theViewId ) )
709 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
710 Handle(HYDROData_Entity) anObject;
711 for ( int i = 0; i < aViewShapes.length(); )
713 HYDROGUI_Shape* aShape = aViewShapes.at( i );
714 anObject = aShape->getObject();
715 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
718 aViewShapes.removeAt( i );
726 void HYDROGUI_Module::removeViewShapes( const int theViewId )
728 if ( !myShapesMap.contains( theViewId ) )
731 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
732 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
734 HYDROGUI_Shape* aShape = aViewShapes.at( i );
739 myShapesMap.remove( theViewId );
741 /////////////////// END OF OCC SHAPES PROCESSING
743 /////////////////// VTKPrs PROCESSING
744 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
745 const Handle(HYDROData_Entity)& theObject ) const
747 HYDROGUI_VTKPrs* aResShape = NULL;
748 if( theObject.IsNull() )
751 if ( myVTKPrsMap.contains( theViewId ) )
753 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
754 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
756 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
767 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
768 const Handle(HYDROData_Entity)& theObject,
769 HYDROGUI_VTKPrs* theShape )
771 if( theObject.IsNull() )
774 // Compute the new global Z range from the added presentation and the old global Z range.
775 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
776 double* aRange = theShape->getInternalZRange();
777 bool anIsUpdate = false;
778 if ( aRange[0] < aGlobalRange[0] )
780 aGlobalRange[0] = aRange[0];
783 if ( aRange[1] > aGlobalRange[1] )
785 aGlobalRange[1] = aRange[1];
791 updateVTKZRange( theViewId, aGlobalRange );
794 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
795 aViewShapes.append( theShape );
798 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
799 const Handle(HYDROData_Entity)& theObject )
801 if ( !myVTKPrsMap.contains( theViewId ) )
804 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
805 Handle(HYDROData_Entity) anObject;
806 for ( int i = 0; i < aViewShapes.length(); )
808 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
809 anObject = aShape->getObject();
810 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
813 aViewShapes.removeAt( i );
820 // Invalidate global Z range
821 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
822 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
825 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
827 if ( !myVTKPrsMap.contains( theViewId ) )
830 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
831 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
833 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
838 myVTKPrsMap.remove( theViewId );
841 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
843 if ( myVTKPrsMap.contains( theViewId ) )
845 // For the given viewer id update all VTK presentations ...
846 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
847 HYDROGUI_VTKPrs* aShape;
848 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
850 aShape = aViewShapes.at( i );
853 aShape->setZRange( theRange );
857 // ... and update the global color legend scalar bar.
858 getVTKDisplayer()->SetZRange( theViewId, theRange );
860 /////////////////// END OF VTKPrs PROCESSING
862 CAM_DataModel* HYDROGUI_Module::createDataModel()
864 return new HYDROGUI_DataModel( this );
867 void HYDROGUI_Module::customEvent( QEvent* e )
869 int aType = e->type();
870 if ( aType == NewViewEvent )
872 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
873 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
875 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
877 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
878 ViewManagerRole aRole = getViewManagerRole( aViewManager );
880 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
882 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
883 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
885 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
886 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
887 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
889 //ouv: temporarily commented
890 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
893 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
896 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
902 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
904 QEvent::Type aType = theEvent->type();
905 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
907 if( aType == QEvent::Show )
909 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
910 e->setData( theObj );
911 QApplication::postEvent( this, e );
912 theObj->removeEventFilter( this );
915 return LightApp_Module::eventFilter( theObj, theEvent );
918 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
920 LightApp_Module::onViewManagerAdded( theViewManager );
922 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
924 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
925 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
927 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
929 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
930 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
933 createSelector( theViewManager ); // replace the default selector
935 ViewManagerInfo anInfo( theViewManager, VMR_General );
936 myViewManagerMap.insert( ViewManagerId++, anInfo );
939 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
941 LightApp_Module::onViewManagerRemoved( theViewManager );
943 createSelector( theViewManager ); // replace the default selector
945 int anId = getViewManagerId( theViewManager );
948 OCCViewer_ViewManager* anOCCViewManager =
949 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
950 if ( anOCCViewManager )
952 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
954 removeViewShapes( (size_t)anOCCViewer );
957 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
959 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
962 getVTKDisplayer()->DeleteScalarBar( anId );
963 removeViewShapes( (size_t)aVTKViewer );
967 myViewManagerMap.remove( anId );
971 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
973 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
975 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
977 aViewFrame->installEventFilter( this );
979 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
981 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
982 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
985 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
987 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
989 aViewFrame->onTopView();
994 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
996 /* ouv: currently unused
997 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
999 SUIT_ViewManager* aViewManager = 0;
1001 QObject* aParent = aViewPort;
1002 while( aParent = aParent->parent() )
1004 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1006 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1008 aViewManager = aViewer->getViewManager();
1017 double aMouseX = theEvent->scenePos().x();
1018 double aMouseY = theEvent->scenePos().y();
1020 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1021 if( aRole == VMR_General )
1023 int aXDeg = 0, aYDeg = 0;
1024 int aXMin = 0, aYMin = 0;
1025 double aXSec = 0, aYSec = 0;
1026 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1027 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1029 QString aDegSymbol( QChar( 0x00B0 ) );
1030 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1031 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1033 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1035 else if( aRole == VMR_TransformImage )
1036 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1041 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1042 const bool theIsInit,
1043 const bool theIsForced,
1044 const bool theDoFitAll )
1046 QList<int> aViewManagerIdList;
1048 // currently, all views are updated
1049 ViewManagerMapIterator anIter( myViewManagerMap );
1050 while( anIter.hasNext() )
1052 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1054 if ( theDisplayer->IsApplicable( aViewManager ) )
1056 int anId = anIter.key();
1057 aViewManagerIdList.append( anId );
1061 QListIterator<int> anIdIter( aViewManagerIdList );
1062 while( anIdIter.hasNext() )
1064 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1068 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1070 if( !theViewManager )
1073 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1074 if( !aSelectionMgr )
1077 QString aViewType = theViewManager->getType();
1078 if( aViewType != GraphicsView_Viewer::Type() &&
1079 aViewType != OCCViewer_Viewer::Type())
1082 QList<SUIT_Selector*> aSelectorList;
1083 aSelectionMgr->selectors( aViewType, aSelectorList );
1085 // disable all alien selectors
1086 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1087 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1089 SUIT_Selector* aSelector = *anIter;
1090 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1091 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1092 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1093 aSelector->setEnabled( false );
1096 if ( aViewType == GraphicsView_Viewer::Type() )
1098 GraphicsView_ViewManager* aViewManager =
1099 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1101 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1103 else if ( aViewType == OCCViewer_Viewer::Type() )
1105 OCCViewer_ViewManager* aViewManager =
1106 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1108 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1112 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1114 bool aPrevState = myIsUpdateEnabled;
1115 myIsUpdateEnabled = theState;
1119 bool HYDROGUI_Module::isUpdateEnabled() const
1121 return myIsUpdateEnabled;
1124 QStringList HYDROGUI_Module::storeSelection() const
1126 QStringList anEntryList;
1127 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1129 SUIT_DataOwnerPtrList aList( true );
1130 aSelectionMgr->selected( aList );
1132 SUIT_DataOwnerPtrList::iterator anIter;
1133 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1135 const LightApp_DataOwner* anOwner =
1136 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1138 anEntryList.append( anOwner->entry() );
1144 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1146 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1148 SUIT_DataOwnerPtrList aList( true );
1149 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1150 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1151 aSelectionMgr->setSelected( aList );