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 anIsBathymetry = false;
227 bool anIsCalculation = false;
228 bool anIsImmersibleZone = false;
229 bool anIsVisualState = false;
230 bool anIsRegion = false;
231 bool anIsZone = false;
232 bool anIsObstacle = false;
233 bool anIsGeomObject = false;
235 // check the selected GEOM objects
236 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
237 theMenu->addAction( action( ImportGeomObjectId ) );
238 theMenu->addSeparator();
241 // check the selected data model objects
242 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
243 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
245 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
246 if( !anObject.IsNull() )
248 anIsSelectedDataObjects = true;
250 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
251 anIsVisibleInSelection |= aVisibility;
252 anIsHiddenInSelection |= !aVisibility;
254 if( anObject->GetKind() == KIND_IMAGE )
257 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
258 if( !anImage.IsNull() )
260 anIsImportedImage = anImage->HasLocalPoints() && !anImage->IsSelfSplitted();
261 anIsImageHasRefs = anImage->HasReferences();
262 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
264 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
266 QString anOperatorName = anOperator->name();
267 if( anOperatorName == ImageComposer_FuseOperator::Type() )
268 anIsFusedImage = true;
269 else if( anOperatorName == ImageComposer_CutOperator::Type() )
271 else if( anOperatorName == ImageComposer_CropOperator::Type() )
272 anIsSplittedImage = true;
275 if ( anImage->IsMustBeUpdated() )
277 anIsMustBeUpdatedImage = true;
281 else if( anObject->GetKind() == KIND_POLYLINE )
283 else if( anObject->GetKind() == KIND_CALCULATION )
284 anIsCalculation = true;
285 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
286 anIsImmersibleZone = true;
287 else if( anObject->GetKind() == KIND_VISUAL_STATE )
288 anIsVisualState = true;
289 else if( anObject->GetKind() == KIND_REGION )
291 else if( anObject->GetKind() == KIND_ZONE )
293 else if( anObject->GetKind() == KIND_BATHYMETRY )
294 anIsBathymetry = true;
295 else if( anObject->GetKind() == KIND_OBSTACLE )
299 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
302 // check the selected partitions
303 if( !anIsSelectedDataObjects && anIsObjectBrowser )
305 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
306 if( aSelectedPartition != KIND_UNKNOWN )
308 switch( aSelectedPartition )
311 theMenu->addAction( action( ImportImageId ) );
314 theMenu->addAction( action( CreatePolylineId ) );
316 case KIND_VISUAL_STATE:
317 theMenu->addAction( action( SaveVisualStateId ) );
319 case KIND_BATHYMETRY:
320 theMenu->addAction( action( ImportBathymetryId ) );
322 case KIND_CALCULATION:
323 theMenu->addAction( action( CreateCalculationId ) );
325 case KIND_IMMERSIBLE_ZONE:
326 theMenu->addAction( action( CreateImmersibleZoneId ) );
329 theMenu->addAction( action( ImportObstacleFromFileId ) );
330 theMenu->addAction( action( CreateBoxId ) );
331 theMenu->addAction( action( CreateCylinderId ) );
334 theMenu->addSeparator();
338 if( anIsSelectedDataObjects )
340 if ( anIsMustBeUpdatedImage )
342 theMenu->addAction( action( UpdateImageId ) );
343 theMenu->addSeparator();
346 if( aSeq.Length() == 1 )
350 if( anIsImportedImage )
351 theMenu->addAction( action( EditImportedImageId ) );
352 else if( anIsImageHasRefs )
355 theMenu->addAction( action( EditFusedImageId ) );
356 else if( anIsCutImage )
357 theMenu->addAction( action( EditCutImageId ) );
358 else if( anIsSplittedImage )
359 theMenu->addAction( action( EditSplittedImageId ) );
362 theMenu->addAction( action( ObserveImageId ) );
363 theMenu->addAction( action( ExportImageId ) );
364 theMenu->addSeparator();
366 if( anIsImageHasRefs )
368 theMenu->addAction( action( RemoveImageRefsId ) );
369 theMenu->addSeparator();
372 theMenu->addAction( action( FuseImagesId ) );
373 theMenu->addAction( action( CutImagesId ) );
374 theMenu->addAction( action( SplitImageId ) );
375 theMenu->addSeparator();
377 else if( anIsPolyline )
379 theMenu->addAction( action( EditPolylineId ) );
380 theMenu->addSeparator();
382 else if( anIsCalculation )
384 theMenu->addAction( action( EditCalculationId ) );
385 theMenu->addAction( action( ExportCalculationId ) );
386 theMenu->addSeparator();
388 else if( anIsImmersibleZone )
390 theMenu->addAction( action( EditImmersibleZoneId ) );
391 theMenu->addSeparator();
393 else if( anIsVisualState && anIsObjectBrowser )
395 theMenu->addAction( action( SaveVisualStateId ) );
396 theMenu->addAction( action( LoadVisualStateId ) );
397 theMenu->addSeparator();
400 // Add set color action for geometrical objects
401 if ( anIsGeomObject )
403 theMenu->addAction( action( SetColorId ) );
404 theMenu->addSeparator();
408 theMenu->addAction( action( DeleteId ) );
409 theMenu->addSeparator();
411 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle )
413 if( anIsHiddenInSelection )
414 theMenu->addAction( action( ShowId ) );
415 theMenu->addAction( action( ShowOnlyId ) );
416 if( anIsVisibleInSelection )
417 theMenu->addAction( action( HideId ) );
418 theMenu->addSeparator();
424 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
425 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
426 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
427 theMenu->addAction( action( DeleteId ) );
430 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
432 theMenu->addAction( action( ShowAllId ) );
433 theMenu->addAction( action( HideAllId ) );
434 theMenu->addSeparator();
438 void HYDROGUI_Module::update( const int flags )
440 if( !isUpdateEnabled() )
443 QApplication::setOverrideCursor( Qt::WaitCursor );
445 // To prevent calling this method recursively
446 // from one of the methods called below
447 setUpdateEnabled( false );
449 // store selected objects
450 QStringList aSelectedEntries = storeSelection();
452 bool aDoFitAll = flags & UF_FitAll;
453 if( ( flags & UF_Viewer ) )
454 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
456 if( ( flags & UF_OCCViewer ) )
457 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
459 if( ( flags & UF_VTKViewer ) )
460 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
462 if( ( flags & UF_Model ) && getDataModel() && getApp() )
464 getDataModel()->update( getStudyId() );
466 // Temporary workaround to prevent breaking
467 // the selection in the object browser.
468 // Note: processEvents() should be called after updateGV(),
469 // otherwise the application crashes from time to time.
470 //RKV: qApp->processEvents();
471 getApp()->updateObjectBrowser( true );
474 // Object browser is currently updated by using UF_Model flag
475 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
476 getApp()->updateObjectBrowser( true );
478 if( ( flags & UF_Controls ) && getApp() )
479 getApp()->updateActions();
481 // restore selected objects
482 restoreSelection( aSelectedEntries );
484 setUpdateEnabled( true );
486 QApplication::restoreOverrideCursor();
489 void HYDROGUI_Module::updateCommandsStatus()
491 LightApp_Module::updateCommandsStatus();
493 updateUndoRedoControls();
495 action( CopyId )->setEnabled( getDataModel()->canCopy() );
496 action( PasteId )->setEnabled( getDataModel()->canPaste() );
499 void HYDROGUI_Module::selectionChanged()
501 LightApp_Module::selectionChanged();
502 updateCommandsStatus();
505 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
507 return (HYDROGUI_DataModel*)dataModel();
510 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
515 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
517 return myOCCDisplayer;
520 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
522 return myVTKDisplayer;
525 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
527 if( myViewManagerMap.contains( theId ) )
529 return myViewManagerMap[ theId ].first;
534 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
536 if( myViewManagerMap.contains( theId ) )
538 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
539 GraphicsView_ViewManager* aViewManager =
540 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
542 return aViewManager->getViewer();
547 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
549 if( myViewManagerMap.contains( theId ) )
551 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
552 OCCViewer_ViewManager* aViewManager =
553 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
555 return aViewManager->getOCCViewer();
560 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
562 if( myViewManagerMap.contains( theId ) )
564 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
565 SVTK_ViewManager* aViewManager =
566 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
568 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
573 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
575 ViewManagerMapIterator anIter( myViewManagerMap );
576 while( anIter.hasNext() )
578 int anId = anIter.next().key();
579 const ViewManagerInfo& anInfo = anIter.value();
580 if( anInfo.first == theViewManager )
586 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
588 int anId = getViewManagerId( theViewManager );
591 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
592 return anInfo.second;
597 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
598 const ViewManagerRole theRole )
600 int anId = getViewManagerId( theViewManager );
603 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
604 anInfo.second = theRole;
608 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
609 const Handle(HYDROData_Entity)& theObject ) const
611 if( theObject.IsNull() )
614 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
615 if( anIter1 != myObjectStateMap.end() )
617 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
618 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
619 if( anIter2 != aName2ObjectStateMap.end() )
621 const ObjectState& anObjectState = anIter2.value();
622 return anObjectState.Visibility;
628 void HYDROGUI_Module::setObjectVisible( const int theViewId,
629 const Handle(HYDROData_Entity)& theObject,
630 const bool theState )
632 if( !theObject.IsNull() )
634 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
635 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
636 anObjectState.Visibility = theState;
640 /////////////////// OCC SHAPES PROCESSING
641 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
642 const Handle(HYDROData_Entity)& theObject ) const
644 HYDROGUI_Shape* aResShape = NULL;
645 if( theObject.IsNull() )
648 if ( myShapesMap.contains( theViewId ) )
650 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
651 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
653 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
664 void HYDROGUI_Module::setObjectShape( const int theViewId,
665 const Handle(HYDROData_Entity)& theObject,
666 HYDROGUI_Shape* theShape )
668 if( theObject.IsNull() )
671 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
672 aViewShapes.append( theShape );
675 void HYDROGUI_Module::removeObjectShape( const int theViewId,
676 const Handle(HYDROData_Entity)& theObject )
678 if ( !myShapesMap.contains( theViewId ) )
681 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
682 Handle(HYDROData_Entity) anObject;
683 for ( int i = 0; i < aViewShapes.length(); )
685 HYDROGUI_Shape* aShape = aViewShapes.at( i );
686 anObject = aShape->getObject();
687 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
690 aViewShapes.removeAt( i );
698 void HYDROGUI_Module::removeViewShapes( const int theViewId )
700 if ( !myShapesMap.contains( theViewId ) )
703 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
704 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
706 HYDROGUI_Shape* aShape = aViewShapes.at( i );
711 myShapesMap.remove( theViewId );
713 /////////////////// END OF OCC SHAPES PROCESSING
715 /////////////////// VTKPrs PROCESSING
716 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
717 const Handle(HYDROData_Entity)& theObject ) const
719 HYDROGUI_VTKPrs* aResShape = NULL;
720 if( theObject.IsNull() )
723 if ( myVTKPrsMap.contains( theViewId ) )
725 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
726 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
728 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
739 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
740 const Handle(HYDROData_Entity)& theObject,
741 HYDROGUI_VTKPrs* theShape )
743 if( theObject.IsNull() )
746 // Compute the new global Z range from the added presentation and the old global Z range.
747 double* aGlobalRange = getVTKDisplayer()->GetZRange();
748 double* aRange = theShape->getInternalZRange();
749 bool anIsUpdate = false;
750 if ( aRange[0] < aGlobalRange[0] )
752 aGlobalRange[0] = aRange[0];
755 if ( aRange[1] > aGlobalRange[1] )
757 aGlobalRange[1] = aRange[1];
763 updateVTKZRange( aGlobalRange );
766 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
767 aViewShapes.append( theShape );
770 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
771 const Handle(HYDROData_Entity)& theObject )
773 if ( !myVTKPrsMap.contains( theViewId ) )
776 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
777 Handle(HYDROData_Entity) anObject;
778 for ( int i = 0; i < aViewShapes.length(); )
780 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
781 anObject = aShape->getObject();
782 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
785 aViewShapes.removeAt( i );
792 // Invalidate global Z range
793 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
794 getVTKDisplayer()->SetZRange( anInvalidRange );
797 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
799 if ( !myVTKPrsMap.contains( theViewId ) )
802 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
803 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
805 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
810 myVTKPrsMap.remove( theViewId );
813 void HYDROGUI_Module::updateVTKZRange( double theRange[] )
815 // For all VTK viewers ...
816 QList<int> aViewIdList = myVTKPrsMap.keys();
817 foreach( int aViewId, aViewIdList )
819 // ... update all VTK presentations ...
820 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( aViewId );
821 HYDROGUI_VTKPrs* aShape;
822 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
824 aShape = aViewShapes.at( i );
827 aShape->setZRange( theRange );
831 // ... and update the global color legend scalar bar.
832 getVTKDisplayer()->SetZRange( theRange );
834 /////////////////// END OF VTKPrs PROCESSING
836 CAM_DataModel* HYDROGUI_Module::createDataModel()
838 return new HYDROGUI_DataModel( this );
841 void HYDROGUI_Module::customEvent( QEvent* e )
843 int aType = e->type();
844 if ( aType == NewViewEvent )
846 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
847 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
849 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
851 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
852 ViewManagerRole aRole = getViewManagerRole( aViewManager );
854 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
856 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
857 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
859 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
860 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
861 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
863 //ouv: temporarily commented
864 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
867 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
870 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
876 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
878 QEvent::Type aType = theEvent->type();
879 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
881 if( aType == QEvent::Show )
883 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
884 e->setData( theObj );
885 QApplication::postEvent( this, e );
886 theObj->removeEventFilter( this );
889 return LightApp_Module::eventFilter( theObj, theEvent );
892 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
894 LightApp_Module::onViewManagerAdded( theViewManager );
896 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
898 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
899 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
901 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
903 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
904 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
907 createSelector( theViewManager ); // replace the default selector
909 ViewManagerInfo anInfo( theViewManager, VMR_General );
910 myViewManagerMap.insert( ViewManagerId++, anInfo );
913 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
915 LightApp_Module::onViewManagerRemoved( theViewManager );
917 createSelector( theViewManager ); // replace the default selector
919 int anId = getViewManagerId( theViewManager );
922 OCCViewer_ViewManager* anOCCViewManager =
923 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
924 if ( anOCCViewManager )
926 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
928 removeViewShapes( (size_t)anOCCViewer );
931 myViewManagerMap.remove( anId );
935 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
937 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
939 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
941 aViewFrame->installEventFilter( this );
943 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
945 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
946 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
949 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
951 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
953 aViewFrame->onTopView();
958 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
960 /* ouv: currently unused
961 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
963 SUIT_ViewManager* aViewManager = 0;
965 QObject* aParent = aViewPort;
966 while( aParent = aParent->parent() )
968 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
970 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
972 aViewManager = aViewer->getViewManager();
981 double aMouseX = theEvent->scenePos().x();
982 double aMouseY = theEvent->scenePos().y();
984 ViewManagerRole aRole = getViewManagerRole( aViewManager );
985 if( aRole == VMR_General )
987 int aXDeg = 0, aYDeg = 0;
988 int aXMin = 0, aYMin = 0;
989 double aXSec = 0, aYSec = 0;
990 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
991 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
993 QString aDegSymbol( QChar( 0x00B0 ) );
994 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
995 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
997 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
999 else if( aRole == VMR_TransformImage )
1000 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1005 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1006 const bool theIsInit,
1007 const bool theIsForced,
1008 const bool theDoFitAll )
1010 QList<int> aViewManagerIdList;
1012 // currently, all views are updated
1013 ViewManagerMapIterator anIter( myViewManagerMap );
1014 while( anIter.hasNext() )
1016 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1018 if ( theDisplayer->IsApplicable( aViewManager ) )
1020 int anId = anIter.key();
1021 aViewManagerIdList.append( anId );
1025 QListIterator<int> anIdIter( aViewManagerIdList );
1026 while( anIdIter.hasNext() )
1028 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1032 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1034 if( !theViewManager )
1037 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1038 if( !aSelectionMgr )
1041 QString aViewType = theViewManager->getType();
1042 if( aViewType != GraphicsView_Viewer::Type() &&
1043 aViewType != OCCViewer_Viewer::Type())
1046 QList<SUIT_Selector*> aSelectorList;
1047 aSelectionMgr->selectors( aViewType, aSelectorList );
1049 // disable all alien selectors
1050 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1051 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1053 SUIT_Selector* aSelector = *anIter;
1054 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1055 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1056 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1057 aSelector->setEnabled( false );
1060 if ( aViewType == GraphicsView_Viewer::Type() )
1062 GraphicsView_ViewManager* aViewManager =
1063 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1065 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1067 else if ( aViewType == OCCViewer_Viewer::Type() )
1069 OCCViewer_ViewManager* aViewManager =
1070 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1072 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1076 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1078 bool aPrevState = myIsUpdateEnabled;
1079 myIsUpdateEnabled = theState;
1083 bool HYDROGUI_Module::isUpdateEnabled() const
1085 return myIsUpdateEnabled;
1088 QStringList HYDROGUI_Module::storeSelection() const
1090 QStringList anEntryList;
1091 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1093 SUIT_DataOwnerPtrList aList( true );
1094 aSelectionMgr->selected( aList );
1096 SUIT_DataOwnerPtrList::iterator anIter;
1097 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1099 const LightApp_DataOwner* anOwner =
1100 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1102 anEntryList.append( anOwner->entry() );
1108 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1110 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1112 SUIT_DataOwnerPtrList aList( true );
1113 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1114 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1115 aSelectionMgr->setSelected( aList );