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& ) ) );
156 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
161 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
163 ViewManagerMapIterator anIter( myViewManagerMap );
164 while( anIter.hasNext() )
165 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
166 getApp()->removeViewManager( aViewManager );
167 myViewManagerMap.clear();
169 myObjectStateMap.clear();
173 // clear the data model's list of copying objects
174 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
176 setMenuShown( false );
177 setToolShown( false );
179 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
181 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
182 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
184 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
186 return LightApp_Module::deactivateModule( theStudy );
189 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
192 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
193 #ifndef DISABLE_PYCONSOLE
194 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
196 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
199 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
201 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
204 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
208 HYDROGUI_DataModel* aModel = getDataModel();
210 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
211 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
212 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
213 bool anIsVTKView = theClient == SVTK_Viewer::Type();
214 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
217 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
219 bool anIsSelectedDataObjects = false;
220 bool anIsVisibleInSelection = false;
221 bool anIsHiddenInSelection = false;
223 bool anIsImage = false;
224 bool anIsImportedImage = false;
225 bool anIsImageHasRefs = false;
226 bool anIsFusedImage = false;
227 bool anIsCutImage = false;
228 bool anIsSplittedImage = false;
229 bool anIsMustBeUpdatedImage = false;
230 bool anIsPolyline = false;
231 bool anIsProfile = false;
232 bool anAllAreProfiles = false;
233 bool anIsBathymetry = false;
234 bool anIsCalculation = false;
235 bool anIsImmersibleZone = false;
236 bool anIsVisualState = false;
237 bool anIsRegion = false;
238 bool anIsZone = false;
239 bool anIsObstacle = false;
240 bool anIsGeomObject = false;
242 // check the selected GEOM objects
243 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
244 theMenu->addAction( action( ImportGeomObjectId ) );
245 theMenu->addSeparator();
248 // check the selected data model objects
249 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
250 int aNbOfSelectedProfiles = 0;
251 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
253 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
254 if( !anObject.IsNull() )
256 anIsSelectedDataObjects = true;
258 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
259 anIsVisibleInSelection |= aVisibility;
260 anIsHiddenInSelection |= !aVisibility;
262 if( anObject->GetKind() == KIND_IMAGE )
265 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
266 if( !anImage.IsNull() )
268 anIsImportedImage = anImage->HasLocalPoints();
269 anIsImageHasRefs = anImage->HasReferences();
270 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
272 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
274 QString anOperatorName = anOperator->name();
275 if( anOperatorName == ImageComposer_FuseOperator::Type() )
276 anIsFusedImage = true;
277 else if( anOperatorName == ImageComposer_CutOperator::Type() )
279 else if( anOperatorName == ImageComposer_CropOperator::Type() )
280 anIsSplittedImage = true;
283 if ( anImage->IsMustBeUpdated() )
285 anIsMustBeUpdatedImage = true;
289 else if( anObject->GetKind() == KIND_POLYLINEXY )
291 else if( anObject->GetKind() == KIND_PROFILE ) {
293 aNbOfSelectedProfiles++;
295 else if( anObject->GetKind() == KIND_CALCULATION )
296 anIsCalculation = true;
297 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
298 anIsImmersibleZone = true;
299 else if( anObject->GetKind() == KIND_VISUAL_STATE )
300 anIsVisualState = true;
301 else if( anObject->GetKind() == KIND_REGION )
303 else if( anObject->GetKind() == KIND_ZONE )
305 else if( anObject->GetKind() == KIND_BATHYMETRY )
306 anIsBathymetry = true;
307 else if( anObject->GetKind() == KIND_OBSTACLE )
311 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
314 // Check if all selected objects are profiles
315 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
316 ( aNbOfSelectedProfiles == aSeq.Length() );
318 // check the selected partitions
319 if( !anIsSelectedDataObjects && anIsObjectBrowser )
321 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
322 if( aSelectedPartition != KIND_UNKNOWN )
324 switch( aSelectedPartition )
327 theMenu->addAction( action( ImportImageId ) );
329 case KIND_POLYLINEXY:
330 theMenu->addAction( action( CreatePolylineId ) );
333 theMenu->addAction( action( CreateProfileId ) );
334 theMenu->addAction( action( ImportProfilesId ) );
335 theMenu->addAction( action( AllGeoreferencementId ) );
337 case KIND_VISUAL_STATE:
338 theMenu->addAction( action( SaveVisualStateId ) );
340 case KIND_BATHYMETRY:
341 theMenu->addAction( action( ImportBathymetryId ) );
343 case KIND_CALCULATION:
344 theMenu->addAction( action( CreateCalculationId ) );
346 case KIND_IMMERSIBLE_ZONE:
347 theMenu->addAction( action( CreateImmersibleZoneId ) );
350 theMenu->addAction( action( ImportObstacleFromFileId ) );
351 theMenu->addAction( action( CreateBoxId ) );
352 theMenu->addAction( action( CreateCylinderId ) );
355 theMenu->addSeparator();
359 if( anIsSelectedDataObjects )
361 if ( anIsMustBeUpdatedImage )
363 theMenu->addAction( action( UpdateImageId ) );
364 theMenu->addSeparator();
367 if( aSeq.Length() == 1 )
371 if( anIsImportedImage )
372 theMenu->addAction( action( EditImportedImageId ) );
373 else if( anIsImageHasRefs )
376 theMenu->addAction( action( EditFusedImageId ) );
377 else if( anIsCutImage )
378 theMenu->addAction( action( EditCutImageId ) );
379 else if( anIsSplittedImage )
380 theMenu->addAction( action( EditSplittedImageId ) );
383 theMenu->addAction( action( ObserveImageId ) );
384 theMenu->addAction( action( ExportImageId ) );
385 theMenu->addSeparator();
387 if( anIsImageHasRefs )
389 theMenu->addAction( action( RemoveImageRefsId ) );
390 theMenu->addSeparator();
393 theMenu->addAction( action( FuseImagesId ) );
394 theMenu->addAction( action( CutImagesId ) );
395 theMenu->addAction( action( SplitImageId ) );
396 theMenu->addSeparator();
398 else if( anIsPolyline )
400 theMenu->addAction( action( EditPolylineId ) );
401 theMenu->addSeparator();
403 else if( anIsProfile )
405 theMenu->addAction( action( EditProfileId ) );
406 theMenu->addAction( action( SelectedGeoreferencementId ) );
407 theMenu->addSeparator();
409 else if( anIsCalculation )
411 theMenu->addAction( action( EditCalculationId ) );
412 theMenu->addAction( action( ExportCalculationId ) );
413 theMenu->addSeparator();
415 else if( anIsImmersibleZone )
417 theMenu->addAction( action( EditImmersibleZoneId ) );
418 theMenu->addSeparator();
420 else if( anIsVisualState && anIsObjectBrowser )
422 theMenu->addAction( action( SaveVisualStateId ) );
423 theMenu->addAction( action( LoadVisualStateId ) );
424 theMenu->addSeparator();
427 // Add set color action for geometrical objects
428 if ( anIsGeomObject )
430 theMenu->addAction( action( SetColorId ) );
431 theMenu->addSeparator();
435 if ( anAllAreProfiles ) {
436 theMenu->addAction( action( SelectedGeoreferencementId ) );
437 theMenu->addSeparator();
440 theMenu->addAction( action( DeleteId ) );
441 theMenu->addSeparator();
443 if( anIsImage || anIsPolyline || anIsImmersibleZone || anIsZone || anIsRegion || anIsBathymetry || anIsObstacle )
445 if( anIsHiddenInSelection )
446 theMenu->addAction( action( ShowId ) );
447 theMenu->addAction( action( ShowOnlyId ) );
448 if( anIsVisibleInSelection )
449 theMenu->addAction( action( HideId ) );
450 theMenu->addSeparator();
456 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
457 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
458 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
459 theMenu->addAction( action( DeleteId ) );
462 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
464 theMenu->addAction( action( ShowAllId ) );
465 theMenu->addAction( action( HideAllId ) );
466 theMenu->addSeparator();
470 void HYDROGUI_Module::update( const int flags )
472 if( !isUpdateEnabled() )
475 QApplication::setOverrideCursor( Qt::WaitCursor );
477 // To prevent calling this method recursively
478 // from one of the methods called below
479 setUpdateEnabled( false );
481 // store selected objects
482 QStringList aSelectedEntries = storeSelection();
484 bool aDoFitAll = flags & UF_FitAll;
485 if( ( flags & UF_Viewer ) )
486 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
488 if( ( flags & UF_OCCViewer ) )
489 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
491 if( ( flags & UF_VTKViewer ) )
492 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
494 if( ( flags & UF_Model ) && getDataModel() && getApp() )
496 getDataModel()->update( getStudyId() );
498 // Temporary workaround to prevent breaking
499 // the selection in the object browser.
500 // Note: processEvents() should be called after updateGV(),
501 // otherwise the application crashes from time to time.
502 //RKV: qApp->processEvents();
503 getApp()->updateObjectBrowser( true );
506 // Object browser is currently updated by using UF_Model flag
507 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
508 getApp()->updateObjectBrowser( true );
510 if( ( flags & UF_Controls ) && getApp() )
511 getApp()->updateActions();
513 // restore selected objects
514 restoreSelection( aSelectedEntries );
516 setUpdateEnabled( true );
518 QApplication::restoreOverrideCursor();
521 void HYDROGUI_Module::updateCommandsStatus()
523 LightApp_Module::updateCommandsStatus();
525 updateUndoRedoControls();
527 action( CopyId )->setEnabled( getDataModel()->canCopy() );
528 action( PasteId )->setEnabled( getDataModel()->canPaste() );
531 void HYDROGUI_Module::selectionChanged()
533 LightApp_Module::selectionChanged();
534 updateCommandsStatus();
537 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
539 return (HYDROGUI_DataModel*)dataModel();
542 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
547 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
549 return myOCCDisplayer;
552 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
554 return myVTKDisplayer;
557 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
559 if( myViewManagerMap.contains( theId ) )
561 return myViewManagerMap[ theId ].first;
566 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
568 if( myViewManagerMap.contains( theId ) )
570 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
571 GraphicsView_ViewManager* aViewManager =
572 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
574 return aViewManager->getViewer();
579 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
581 if( myViewManagerMap.contains( theId ) )
583 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
584 OCCViewer_ViewManager* aViewManager =
585 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
587 return aViewManager->getOCCViewer();
592 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
594 if( myViewManagerMap.contains( theId ) )
596 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
597 SVTK_ViewManager* aViewManager =
598 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
600 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
605 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
607 ViewManagerMapIterator anIter( myViewManagerMap );
608 while( anIter.hasNext() )
610 int anId = anIter.next().key();
611 const ViewManagerInfo& anInfo = anIter.value();
612 if( anInfo.first == theViewManager )
618 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
620 int anId = getViewManagerId( theViewManager );
623 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
624 return anInfo.second;
629 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
630 const ViewManagerRole theRole )
632 int anId = getViewManagerId( theViewManager );
635 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
636 anInfo.second = theRole;
640 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
641 const Handle(HYDROData_Entity)& theObject ) const
643 if( theObject.IsNull() )
646 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
647 if( anIter1 != myObjectStateMap.end() )
649 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
650 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
651 if( anIter2 != aName2ObjectStateMap.end() )
653 const ObjectState& anObjectState = anIter2.value();
654 return anObjectState.Visibility;
660 void HYDROGUI_Module::setObjectVisible( const int theViewId,
661 const Handle(HYDROData_Entity)& theObject,
662 const bool theState )
664 if( !theObject.IsNull() )
666 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
667 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
668 anObjectState.Visibility = theState;
672 /////////////////// OCC SHAPES PROCESSING
673 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
674 const Handle(HYDROData_Entity)& theObject ) const
676 HYDROGUI_Shape* aResShape = NULL;
677 if( theObject.IsNull() )
680 if ( myShapesMap.contains( theViewId ) )
682 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
683 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
685 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
696 void HYDROGUI_Module::setObjectShape( const int theViewId,
697 const Handle(HYDROData_Entity)& theObject,
698 HYDROGUI_Shape* theShape )
700 if( theObject.IsNull() )
703 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
704 aViewShapes.append( theShape );
707 void HYDROGUI_Module::removeObjectShape( const int theViewId,
708 const Handle(HYDROData_Entity)& theObject )
710 if ( !myShapesMap.contains( theViewId ) )
713 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
714 Handle(HYDROData_Entity) anObject;
715 for ( int i = 0; i < aViewShapes.length(); )
717 HYDROGUI_Shape* aShape = aViewShapes.at( i );
718 anObject = aShape->getObject();
719 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
722 aViewShapes.removeAt( i );
730 void HYDROGUI_Module::removeViewShapes( const int theViewId )
732 if ( !myShapesMap.contains( theViewId ) )
735 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
736 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
738 HYDROGUI_Shape* aShape = aViewShapes.at( i );
743 myShapesMap.remove( theViewId );
745 /////////////////// END OF OCC SHAPES PROCESSING
747 /////////////////// VTKPrs PROCESSING
748 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
749 const Handle(HYDROData_Entity)& theObject ) const
751 HYDROGUI_VTKPrs* aResShape = NULL;
752 if( theObject.IsNull() )
755 if ( myVTKPrsMap.contains( theViewId ) )
757 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
758 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
760 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
771 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
772 const Handle(HYDROData_Entity)& theObject,
773 HYDROGUI_VTKPrs* theShape )
775 if( theObject.IsNull() )
778 // Compute the new global Z range from the added presentation and the old global Z range.
779 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
780 double* aRange = theShape->getInternalZRange();
781 bool anIsUpdate = false;
782 if ( aRange[0] < aGlobalRange[0] )
784 aGlobalRange[0] = aRange[0];
787 if ( aRange[1] > aGlobalRange[1] )
789 aGlobalRange[1] = aRange[1];
795 updateVTKZRange( theViewId, aGlobalRange );
798 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
799 aViewShapes.append( theShape );
802 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
803 const Handle(HYDROData_Entity)& theObject )
805 if ( !myVTKPrsMap.contains( theViewId ) )
808 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
809 Handle(HYDROData_Entity) anObject;
810 for ( int i = 0; i < aViewShapes.length(); )
812 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
813 anObject = aShape->getObject();
814 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
817 aViewShapes.removeAt( i );
824 // Invalidate global Z range
825 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
826 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
829 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
831 if ( !myVTKPrsMap.contains( theViewId ) )
834 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
835 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
837 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
842 myVTKPrsMap.remove( theViewId );
845 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
847 if ( myVTKPrsMap.contains( theViewId ) )
849 // For the given viewer id update all VTK presentations ...
850 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
851 HYDROGUI_VTKPrs* aShape;
852 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
854 aShape = aViewShapes.at( i );
857 aShape->setZRange( theRange );
861 // ... and update the global color legend scalar bar.
862 getVTKDisplayer()->SetZRange( theViewId, theRange );
864 /////////////////// END OF VTKPrs PROCESSING
866 CAM_DataModel* HYDROGUI_Module::createDataModel()
868 return new HYDROGUI_DataModel( this );
871 void HYDROGUI_Module::customEvent( QEvent* e )
873 int aType = e->type();
874 if ( aType == NewViewEvent )
876 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
877 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
879 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
881 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
882 ViewManagerRole aRole = getViewManagerRole( aViewManager );
884 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
886 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
887 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
889 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
890 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
891 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
893 //ouv: temporarily commented
894 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
897 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
900 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
906 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
908 QEvent::Type aType = theEvent->type();
909 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
911 if( aType == QEvent::Show )
913 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
914 e->setData( theObj );
915 QApplication::postEvent( this, e );
916 theObj->removeEventFilter( this );
919 return LightApp_Module::eventFilter( theObj, theEvent );
922 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
924 LightApp_Module::onViewManagerAdded( theViewManager );
926 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
928 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
929 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
931 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
933 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
934 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
937 createSelector( theViewManager ); // replace the default selector
939 ViewManagerInfo anInfo( theViewManager, VMR_General );
940 myViewManagerMap.insert( ViewManagerId++, anInfo );
943 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
945 LightApp_Module::onViewManagerRemoved( theViewManager );
947 createSelector( theViewManager ); // replace the default selector
949 int anId = getViewManagerId( theViewManager );
952 OCCViewer_ViewManager* anOCCViewManager =
953 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
954 if ( anOCCViewManager )
956 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
958 removeViewShapes( (size_t)anOCCViewer );
961 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
963 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
966 getVTKDisplayer()->DeleteScalarBar( anId );
967 removeViewShapes( (size_t)aVTKViewer );
971 myViewManagerMap.remove( anId );
975 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
977 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
979 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
981 aViewFrame->installEventFilter( this );
983 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
985 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
986 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
989 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
991 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
993 aViewFrame->onTopView();
995 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1000 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1002 /* ouv: currently unused
1003 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1005 SUIT_ViewManager* aViewManager = 0;
1007 QObject* aParent = aViewPort;
1008 while( aParent = aParent->parent() )
1010 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1012 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1014 aViewManager = aViewer->getViewManager();
1023 double aMouseX = theEvent->scenePos().x();
1024 double aMouseY = theEvent->scenePos().y();
1026 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1027 if( aRole == VMR_General )
1029 int aXDeg = 0, aYDeg = 0;
1030 int aXMin = 0, aYMin = 0;
1031 double aXSec = 0, aYSec = 0;
1032 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1033 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1035 QString aDegSymbol( QChar( 0x00B0 ) );
1036 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1037 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1039 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1041 else if( aRole == VMR_TransformImage )
1042 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1047 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1048 const bool theIsInit,
1049 const bool theIsForced,
1050 const bool theDoFitAll )
1052 QList<int> aViewManagerIdList;
1054 // currently, all views are updated
1055 ViewManagerMapIterator anIter( myViewManagerMap );
1056 while( anIter.hasNext() )
1058 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1060 if ( theDisplayer->IsApplicable( aViewManager ) )
1062 int anId = anIter.key();
1063 aViewManagerIdList.append( anId );
1067 QListIterator<int> anIdIter( aViewManagerIdList );
1068 while( anIdIter.hasNext() )
1070 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1074 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1076 if( !theViewManager )
1079 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1080 if( !aSelectionMgr )
1083 QString aViewType = theViewManager->getType();
1084 if( aViewType != GraphicsView_Viewer::Type() &&
1085 aViewType != OCCViewer_Viewer::Type())
1088 QList<SUIT_Selector*> aSelectorList;
1089 aSelectionMgr->selectors( aViewType, aSelectorList );
1091 // disable all alien selectors
1092 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1093 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1095 SUIT_Selector* aSelector = *anIter;
1096 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1097 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1098 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1099 aSelector->setEnabled( false );
1102 if ( aViewType == GraphicsView_Viewer::Type() )
1104 GraphicsView_ViewManager* aViewManager =
1105 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1107 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1109 else if ( aViewType == OCCViewer_Viewer::Type() )
1111 OCCViewer_ViewManager* aViewManager =
1112 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1114 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1118 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1120 bool aPrevState = myIsUpdateEnabled;
1121 myIsUpdateEnabled = theState;
1125 bool HYDROGUI_Module::isUpdateEnabled() const
1127 return myIsUpdateEnabled;
1130 QStringList HYDROGUI_Module::storeSelection() const
1132 QStringList anEntryList;
1133 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1135 SUIT_DataOwnerPtrList aList( true );
1136 aSelectionMgr->selected( aList );
1138 SUIT_DataOwnerPtrList::iterator anIter;
1139 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1141 const LightApp_DataOwner* anOwner =
1142 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1144 anEntryList.append( anOwner->entry() );
1150 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1152 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1154 SUIT_DataOwnerPtrList aList( true );
1155 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1156 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1157 aSelectionMgr->setSelected( aList );