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_Profile.h>
45 #include <HYDROData_Lambert93.h>
46 #include <HYDROData_Tool.h>
48 #include <HYDROData_OperationsFactory.h>
50 #include <GraphicsView_ViewFrame.h>
51 #include <GraphicsView_ViewManager.h>
52 #include <GraphicsView_ViewPort.h>
53 #include <GraphicsView_Viewer.h>
55 #include <ImageComposer_CutOperator.h>
56 #include <ImageComposer_CropOperator.h>
57 #include <ImageComposer_FuseOperator.h>
59 #include <LightApp_Application.h>
60 #include <LightApp_DataOwner.h>
61 #include <LightApp_GVSelector.h>
62 #include <LightApp_SelectionMgr.h>
63 #include <LightApp_UpdateFlags.h>
65 #include <OCCViewer_ViewFrame.h>
66 #include <OCCViewer_ViewManager.h>
67 #include <OCCViewer_ViewModel.h>
69 #include <SALOME_Event.h>
71 #include <SUIT_DataBrowser.h>
72 #include <SUIT_Desktop.h>
73 #include <SUIT_Study.h>
74 #include <SUIT_ViewManager.h>
76 #include <SVTK_ViewManager.h>
77 #include <SVTK_ViewModel.h>
78 #include <SVTK_Selector.h>
81 #include <QApplication>
82 #include <QGraphicsSceneMouseEvent>
85 static int ViewManagerId = 0;
87 extern "C" HYDRO_EXPORT CAM_Module* createModule()
89 return new HYDROGUI_Module();
92 extern "C" HYDRO_EXPORT char* getModuleVersion()
94 return (char*)HYDRO_VERSION;
97 HYDROGUI_Module::HYDROGUI_Module()
98 : LightApp_Module( "HYDRO" ),
101 myIsUpdateEnabled( true )
105 HYDROGUI_Module::~HYDROGUI_Module()
109 int HYDROGUI_Module::getStudyId() const
111 LightApp_Application* anApp = getApp();
112 return anApp ? anApp->activeStudy()->id() : 0;
115 void HYDROGUI_Module::initialize( CAM_Application* theApp )
117 LightApp_Module::initialize( theApp );
120 createUndoRedoActions();
125 setMenuShown( false );
126 setToolShown( false );
128 myDisplayer = new HYDROGUI_Displayer( this );
129 myOCCDisplayer = new HYDROGUI_OCCDisplayer( this );
130 myVTKDisplayer = new HYDROGUI_VTKPrsDisplayer( this );
133 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
135 bool aRes = LightApp_Module::activateModule( theStudy );
137 LightApp_Application* anApp = getApp();
138 SUIT_Desktop* aDesktop = anApp->desktop();
140 getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions
142 setMenuShown( true );
143 setToolShown( true );
145 #ifndef DISABLE_PYCONSOLE
146 aDesktop->tabifyDockWidget( HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_PyConsole ) ),
147 HYDROGUI_Tool::WindowDock( anApp->getWindow( LightApp_Application::WT_LogWindow ) ) );
152 updateCommandsStatus();
154 connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
155 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
157 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false );
162 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
164 ViewManagerMapIterator anIter( myViewManagerMap );
165 while( anIter.hasNext() )
166 if( SUIT_ViewManager* aViewManager = anIter.next().value().first )
167 getApp()->removeViewManager( aViewManager );
168 myViewManagerMap.clear();
170 myObjectStateMap.clear();
174 // clear the data model's list of copying objects
175 HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
177 setMenuShown( false );
178 setToolShown( false );
180 getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions
182 disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ),
183 this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) );
185 HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true );
187 return LightApp_Module::deactivateModule( theStudy );
190 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
193 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
194 #ifndef DISABLE_PYCONSOLE
195 theMap.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
197 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
200 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
202 theTypesList << OCCViewer_Viewer::Type() << GraphicsView_Viewer::Type();
205 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
209 HYDROGUI_DataModel* aModel = getDataModel();
211 bool anIsObjectBrowser = theClient == getApp()->objectBrowser()->popupClientType();
212 bool anIsGraphicsView = theClient == GraphicsView_Viewer::Type();
213 bool anIsOCCView = theClient == OCCViewer_Viewer::Type();
214 bool anIsVTKView = theClient == SVTK_Viewer::Type();
215 if( !anIsObjectBrowser && !anIsGraphicsView && !anIsOCCView && !anIsVTKView )
218 size_t anActiveViewId = HYDROGUI_Tool::GetActiveViewId( this );
220 bool anIsSelectedDataObjects = false;
221 bool anIsVisibleInSelection = false;
222 bool anIsHiddenInSelection = false;
224 bool anIsImage = false;
225 bool anIsImportedImage = false;
226 bool anIsImageHasRefs = false;
227 bool anIsFusedImage = false;
228 bool anIsCutImage = false;
229 bool anIsSplittedImage = false;
230 bool anIsMustBeUpdatedImage = false;
231 bool anIsPolyline = false;
232 bool anIsPolyline3D = false;
233 bool anIsProfile = false;
234 bool anIsValidProfile = false;
235 bool anAllAreProfiles = false;
236 bool anIsBathymetry = false;
237 bool anIsCalculation = false;
238 bool anIsImmersibleZone = false;
239 bool anIsVisualState = false;
240 bool anIsRegion = false;
241 bool anIsZone = false;
242 bool anIsObstacle = false;
243 bool anIsGeomObject = false;
245 // check the selected GEOM objects
246 if ( !HYDROGUI_Tool::GetSelectedGeomObjects( this ).isEmpty() ) {
247 theMenu->addAction( action( ImportGeomObjectId ) );
248 theMenu->addSeparator();
251 // check the selected data model objects
252 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
253 int aNbOfSelectedProfiles = 0;
254 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
256 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
257 if( !anObject.IsNull() )
259 anIsSelectedDataObjects = true;
261 bool aVisibility = isObjectVisible( anActiveViewId, anObject );
262 anIsVisibleInSelection |= aVisibility;
263 anIsHiddenInSelection |= !aVisibility;
265 if( anObject->GetKind() == KIND_IMAGE )
268 Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
269 if( !anImage.IsNull() )
271 anIsImportedImage = anImage->HasLocalPoints();
272 anIsImageHasRefs = anImage->HasReferences();
273 if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
275 if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) )
277 QString anOperatorName = anOperator->name();
278 if( anOperatorName == ImageComposer_FuseOperator::Type() )
279 anIsFusedImage = true;
280 else if( anOperatorName == ImageComposer_CutOperator::Type() )
282 else if( anOperatorName == ImageComposer_CropOperator::Type() )
283 anIsSplittedImage = true;
286 if ( anImage->IsMustBeUpdated() )
288 anIsMustBeUpdatedImage = true;
292 else if( anObject->GetKind() == KIND_POLYLINEXY )
294 else if( anObject->GetKind() == KIND_POLYLINE )
295 anIsPolyline3D = true;
296 else if( anObject->GetKind() == KIND_PROFILE ) {
298 aNbOfSelectedProfiles++;
300 Handle(HYDROData_Profile) aProfile =
301 Handle(HYDROData_Profile)::DownCast( anObject );
302 if( !aProfile.IsNull() && aProfile->IsValid() ) {
303 anIsValidProfile = true;
306 else if( anObject->GetKind() == KIND_CALCULATION )
307 anIsCalculation = true;
308 else if( anObject->GetKind() == KIND_IMMERSIBLE_ZONE )
309 anIsImmersibleZone = true;
310 else if( anObject->GetKind() == KIND_VISUAL_STATE )
311 anIsVisualState = true;
312 else if( anObject->GetKind() == KIND_REGION )
314 else if( anObject->GetKind() == KIND_ZONE )
316 else if( anObject->GetKind() == KIND_BATHYMETRY )
317 anIsBathymetry = true;
318 else if( anObject->GetKind() == KIND_OBSTACLE )
322 anIsGeomObject = HYDROData_Tool::IsGeometryObject( anObject );
325 // Check if all selected objects are profiles
326 anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
327 ( aNbOfSelectedProfiles == aSeq.Length() );
329 // check the selected partitions
330 if( !anIsSelectedDataObjects && anIsObjectBrowser )
332 ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this );
333 if( aSelectedPartition != KIND_UNKNOWN )
335 switch( aSelectedPartition )
338 theMenu->addAction( action( ImportImageId ) );
340 case KIND_POLYLINEXY:
341 theMenu->addAction( action( CreatePolylineId ) );
344 theMenu->addAction( action( CreatePolyline3DId ) );
347 theMenu->addAction( action( CreateProfileId ) );
348 theMenu->addAction( action( ImportProfilesId ) );
349 theMenu->addAction( action( AllGeoreferencementId ) );
351 case KIND_VISUAL_STATE:
352 theMenu->addAction( action( SaveVisualStateId ) );
354 case KIND_BATHYMETRY:
355 theMenu->addAction( action( ImportBathymetryId ) );
357 case KIND_CALCULATION:
358 theMenu->addAction( action( CreateCalculationId ) );
360 case KIND_IMMERSIBLE_ZONE:
361 theMenu->addAction( action( CreateImmersibleZoneId ) );
364 theMenu->addAction( action( ImportObstacleFromFileId ) );
365 theMenu->addAction( action( CreateBoxId ) );
366 theMenu->addAction( action( CreateCylinderId ) );
369 theMenu->addSeparator();
373 if( anIsSelectedDataObjects )
375 if ( anIsMustBeUpdatedImage )
377 theMenu->addAction( action( UpdateImageId ) );
378 theMenu->addSeparator();
381 if( aSeq.Length() == 1 )
385 if( anIsImportedImage )
386 theMenu->addAction( action( EditImportedImageId ) );
387 else if( anIsImageHasRefs )
390 theMenu->addAction( action( EditFusedImageId ) );
391 else if( anIsCutImage )
392 theMenu->addAction( action( EditCutImageId ) );
393 else if( anIsSplittedImage )
394 theMenu->addAction( action( EditSplittedImageId ) );
397 theMenu->addAction( action( ObserveImageId ) );
398 theMenu->addAction( action( ExportImageId ) );
399 theMenu->addSeparator();
401 if( anIsImageHasRefs )
403 theMenu->addAction( action( RemoveImageRefsId ) );
404 theMenu->addSeparator();
407 theMenu->addAction( action( FuseImagesId ) );
408 theMenu->addAction( action( CutImagesId ) );
409 theMenu->addAction( action( SplitImageId ) );
410 theMenu->addSeparator();
412 else if( anIsPolyline )
414 theMenu->addAction( action( EditPolylineId ) );
415 theMenu->addSeparator();
417 else if( anIsPolyline3D )
419 theMenu->addAction( action( EditPolyline3DId ) );
420 theMenu->addSeparator();
422 else if( anIsProfile )
424 theMenu->addAction( action( EditProfileId ) );
425 theMenu->addAction( action( SelectedGeoreferencementId ) );
426 theMenu->addSeparator();
428 else if( anIsCalculation )
430 theMenu->addAction( action( EditCalculationId ) );
431 theMenu->addAction( action( ExportCalculationId ) );
432 theMenu->addSeparator();
434 else if( anIsImmersibleZone )
436 theMenu->addAction( action( EditImmersibleZoneId ) );
437 theMenu->addSeparator();
439 else if( anIsVisualState && anIsObjectBrowser )
441 theMenu->addAction( action( SaveVisualStateId ) );
442 theMenu->addAction( action( LoadVisualStateId ) );
443 theMenu->addSeparator();
446 // Add set color action for geometrical objects
447 if ( anIsGeomObject )
449 theMenu->addAction( action( SetColorId ) );
450 theMenu->addSeparator();
452 } else if ( anAllAreProfiles ) {
453 theMenu->addAction( action( SelectedGeoreferencementId ) );
454 theMenu->addSeparator();
457 theMenu->addAction( action( DeleteId ) );
458 theMenu->addSeparator();
460 if( anIsImage || anIsPolyline || anIsPolyline3D || anIsImmersibleZone || anIsZone ||
461 anIsRegion || anIsBathymetry || anIsObstacle || anIsValidProfile )
463 if( anIsHiddenInSelection )
464 theMenu->addAction( action( ShowId ) );
465 theMenu->addAction( action( ShowOnlyId ) );
466 if( anIsVisibleInSelection )
467 theMenu->addAction( action( HideId ) );
468 theMenu->addSeparator();
474 SUIT_Operation* anOp = application()->activeStudy()->activeOperation();
475 HYDROGUI_PolylineOp* aPolylineOp = dynamic_cast<HYDROGUI_PolylineOp*>( anOp );
476 if ( aPolylineOp && aPolylineOp->deleteEnabled() )
477 theMenu->addAction( action( DeleteId ) );
480 if( anIsObjectBrowser || anIsGraphicsView || anIsOCCView || anIsVTKView )
482 theMenu->addAction( action( ShowAllId ) );
483 theMenu->addAction( action( HideAllId ) );
484 theMenu->addSeparator();
488 void HYDROGUI_Module::update( const int flags )
490 if( !isUpdateEnabled() )
493 QApplication::setOverrideCursor( Qt::WaitCursor );
495 // To prevent calling this method recursively
496 // from one of the methods called below
497 setUpdateEnabled( false );
499 // store selected objects
500 QStringList aSelectedEntries = storeSelection();
502 bool aDoFitAll = flags & UF_FitAll;
503 if( ( flags & UF_Viewer ) )
504 updateViewer( getDisplayer(), flags & UF_GV_Init, flags & UF_GV_Forced, aDoFitAll );
506 if( ( flags & UF_OCCViewer ) )
507 updateViewer( getOCCDisplayer(), flags & UF_OCC_Init, flags & UF_OCC_Forced, aDoFitAll );
509 if( ( flags & UF_VTKViewer ) )
510 updateViewer( getVTKDisplayer(), flags & UF_VTK_Init, flags & UF_VTK_Forced, aDoFitAll );
512 if( ( flags & UF_Model ) && getDataModel() && getApp() )
514 getDataModel()->update( getStudyId() );
516 // Temporary workaround to prevent breaking
517 // the selection in the object browser.
518 // Note: processEvents() should be called after updateGV(),
519 // otherwise the application crashes from time to time.
520 //RKV: qApp->processEvents();
521 getApp()->updateObjectBrowser( true );
524 // Object browser is currently updated by using UF_Model flag
525 if( ( flags & UF_ObjBrowser ) && ((flags & UF_Model) == 0) && getApp() )
526 getApp()->updateObjectBrowser( true );
528 if( ( flags & UF_Controls ) && getApp() )
529 getApp()->updateActions();
531 // restore selected objects
532 restoreSelection( aSelectedEntries );
534 setUpdateEnabled( true );
536 QApplication::restoreOverrideCursor();
539 void HYDROGUI_Module::updateCommandsStatus()
541 LightApp_Module::updateCommandsStatus();
543 updateUndoRedoControls();
545 action( CopyId )->setEnabled( getDataModel()->canCopy() );
546 action( PasteId )->setEnabled( getDataModel()->canPaste() );
549 void HYDROGUI_Module::selectionChanged()
551 LightApp_Module::selectionChanged();
552 updateCommandsStatus();
555 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
557 return (HYDROGUI_DataModel*)dataModel();
560 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
565 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
567 return myOCCDisplayer;
570 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
572 return myVTKDisplayer;
575 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
577 if( myViewManagerMap.contains( theId ) )
579 return myViewManagerMap[ theId ].first;
584 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
586 if( myViewManagerMap.contains( theId ) )
588 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
589 GraphicsView_ViewManager* aViewManager =
590 dynamic_cast<GraphicsView_ViewManager*>( anInfo.first );
592 return aViewManager->getViewer();
597 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
599 if( myViewManagerMap.contains( theId ) )
601 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
602 OCCViewer_ViewManager* aViewManager =
603 ::qobject_cast<OCCViewer_ViewManager*>( anInfo.first );
605 return aViewManager->getOCCViewer();
610 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
612 if( myViewManagerMap.contains( theId ) )
614 ViewManagerInfo anInfo = myViewManagerMap[ theId ];
615 SVTK_ViewManager* aViewManager =
616 ::qobject_cast<SVTK_ViewManager*>( anInfo.first );
618 return dynamic_cast<SVTK_Viewer*>( aViewManager->getViewModel() );
623 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
625 ViewManagerMapIterator anIter( myViewManagerMap );
626 while( anIter.hasNext() )
628 int anId = anIter.next().key();
629 const ViewManagerInfo& anInfo = anIter.value();
630 if( anInfo.first == theViewManager )
636 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
638 int anId = getViewManagerId( theViewManager );
641 const ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
642 return anInfo.second;
647 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
648 const ViewManagerRole theRole )
650 int anId = getViewManagerId( theViewManager );
653 ViewManagerInfo& anInfo = myViewManagerMap[ anId ];
654 anInfo.second = theRole;
658 bool HYDROGUI_Module::isObjectVisible( const int theViewId,
659 const Handle(HYDROData_Entity)& theObject ) const
661 if( theObject.IsNull() )
664 ViewId2Name2ObjectStateMap::const_iterator anIter1 = myObjectStateMap.find( theViewId );
665 if( anIter1 != myObjectStateMap.end() )
667 const Name2ObjectStateMap& aName2ObjectStateMap = anIter1.value();
668 Name2ObjectStateMap::const_iterator anIter2 = aName2ObjectStateMap.find( theObject->GetName());
669 if( anIter2 != aName2ObjectStateMap.end() )
671 const ObjectState& anObjectState = anIter2.value();
672 return anObjectState.Visibility;
678 void HYDROGUI_Module::setObjectVisible( const int theViewId,
679 const Handle(HYDROData_Entity)& theObject,
680 const bool theState )
682 if( !theObject.IsNull() )
684 Name2ObjectStateMap& aName2ObjectStateMap = myObjectStateMap[ theViewId ];
685 ObjectState& anObjectState = aName2ObjectStateMap[ theObject->GetName() ];
686 anObjectState.Visibility = theState;
690 /////////////////// OCC SHAPES PROCESSING
691 HYDROGUI_Shape* HYDROGUI_Module::getObjectShape( const int theViewId,
692 const Handle(HYDROData_Entity)& theObject ) const
694 HYDROGUI_Shape* aResShape = NULL;
695 if( theObject.IsNull() )
698 if ( myShapesMap.contains( theViewId ) )
700 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
701 foreach ( HYDROGUI_Shape* aShape, aViewShapes )
703 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
714 void HYDROGUI_Module::setObjectShape( const int theViewId,
715 const Handle(HYDROData_Entity)& theObject,
716 HYDROGUI_Shape* theShape )
718 if( theObject.IsNull() )
721 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
722 aViewShapes.append( theShape );
725 void HYDROGUI_Module::removeObjectShape( const int theViewId,
726 const Handle(HYDROData_Entity)& theObject )
728 if ( !myShapesMap.contains( theViewId ) )
731 ListOfShapes& aViewShapes = myShapesMap[ theViewId ];
732 Handle(HYDROData_Entity) anObject;
733 for ( int i = 0; i < aViewShapes.length(); )
735 HYDROGUI_Shape* aShape = aViewShapes.at( i );
736 anObject = aShape->getObject();
737 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
740 aViewShapes.removeAt( i );
748 void HYDROGUI_Module::removeViewShapes( const int theViewId )
750 if ( !myShapesMap.contains( theViewId ) )
753 const ListOfShapes& aViewShapes = myShapesMap.value( theViewId );
754 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
756 HYDROGUI_Shape* aShape = aViewShapes.at( i );
761 myShapesMap.remove( theViewId );
763 /////////////////// END OF OCC SHAPES PROCESSING
765 /////////////////// VTKPrs PROCESSING
766 HYDROGUI_VTKPrs* HYDROGUI_Module::getObjectVTKPrs( const int theViewId,
767 const Handle(HYDROData_Entity)& theObject ) const
769 HYDROGUI_VTKPrs* aResShape = NULL;
770 if( theObject.IsNull() )
773 if ( myVTKPrsMap.contains( theViewId ) )
775 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
776 foreach ( HYDROGUI_VTKPrs* aShape, aViewShapes )
778 if ( !aShape || !IsEqual( aShape->getObject(), theObject ) )
789 void HYDROGUI_Module::setObjectVTKPrs( const int theViewId,
790 const Handle(HYDROData_Entity)& theObject,
791 HYDROGUI_VTKPrs* theShape )
793 if( theObject.IsNull() )
796 // Compute the new global Z range from the added presentation and the old global Z range.
797 double* aGlobalRange = getVTKDisplayer()->GetZRange( theViewId );
798 double* aRange = theShape->getInternalZRange();
799 bool anIsUpdate = false;
800 if ( aRange[0] < aGlobalRange[0] )
802 aGlobalRange[0] = aRange[0];
805 if ( aRange[1] > aGlobalRange[1] )
807 aGlobalRange[1] = aRange[1];
813 updateVTKZRange( theViewId, aGlobalRange );
816 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
817 aViewShapes.append( theShape );
820 void HYDROGUI_Module::removeObjectVTKPrs( const int theViewId,
821 const Handle(HYDROData_Entity)& theObject )
823 if ( !myVTKPrsMap.contains( theViewId ) )
826 ListOfVTKPrs& aViewShapes = myVTKPrsMap[ theViewId ];
827 Handle(HYDROData_Entity) anObject;
828 for ( int i = 0; i < aViewShapes.length(); )
830 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
831 anObject = aShape->getObject();
832 if ( aShape && (!anObject.IsNull()) && IsEqual( anObject, theObject ) )
835 aViewShapes.removeAt( i );
842 // Invalidate global Z range
843 double anInvalidRange[2] = { HYDROGUI_VTKPrs::InvalidZValue(), HYDROGUI_VTKPrs::InvalidZValue() };
844 getVTKDisplayer()->SetZRange( theViewId, anInvalidRange );
847 void HYDROGUI_Module::removeViewVTKPrs( const int theViewId )
849 if ( !myVTKPrsMap.contains( theViewId ) )
852 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
853 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
855 HYDROGUI_VTKPrs* aShape = aViewShapes.at( i );
860 myVTKPrsMap.remove( theViewId );
863 void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
865 if ( myVTKPrsMap.contains( theViewId ) )
867 // For the given viewer id update all VTK presentations ...
868 const ListOfVTKPrs& aViewShapes = myVTKPrsMap.value( theViewId );
869 HYDROGUI_VTKPrs* aShape;
870 for ( int i = 0, n = aViewShapes.length(); i < n; ++i )
872 aShape = aViewShapes.at( i );
875 aShape->setZRange( theRange );
879 // ... and update the global color legend scalar bar.
880 getVTKDisplayer()->SetZRange( theViewId, theRange );
882 /////////////////// END OF VTKPrs PROCESSING
884 CAM_DataModel* HYDROGUI_Module::createDataModel()
886 return new HYDROGUI_DataModel( this );
889 void HYDROGUI_Module::customEvent( QEvent* e )
891 int aType = e->type();
892 if ( aType == NewViewEvent )
894 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
895 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
897 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
899 SUIT_ViewManager* aViewManager = aViewer->getViewManager();
900 ViewManagerRole aRole = getViewManagerRole( aViewManager );
902 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
904 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
905 aViewPort->scale( 1, -1 ); // invert the Y axis direction from down to up
907 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
908 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
909 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
911 //ouv: temporarily commented
912 //aViewPort->setViewLabelPosition( GraphicsView_ViewPort::VLP_BottomLeft, true );
915 if( aRole != VMR_TransformImage && aRole != VMR_ReferenceImage )
918 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
924 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
926 QEvent::Type aType = theEvent->type();
927 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
929 if( aType == QEvent::Show )
931 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
932 e->setData( theObj );
933 QApplication::postEvent( this, e );
934 theObj->removeEventFilter( this );
937 return LightApp_Module::eventFilter( theObj, theEvent );
940 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
942 LightApp_Module::onViewManagerAdded( theViewManager );
944 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
946 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
947 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
949 else if( theViewManager->getType() == OCCViewer_Viewer::Type() )
951 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
952 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
955 createSelector( theViewManager ); // replace the default selector
957 ViewManagerInfo anInfo( theViewManager, VMR_General );
958 myViewManagerMap.insert( ViewManagerId++, anInfo );
961 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
963 LightApp_Module::onViewManagerRemoved( theViewManager );
965 createSelector( theViewManager ); // replace the default selector
967 int anId = getViewManagerId( theViewManager );
970 OCCViewer_ViewManager* anOCCViewManager =
971 ::qobject_cast<OCCViewer_ViewManager*>( myViewManagerMap[ anId ].first );
972 if ( anOCCViewManager )
974 OCCViewer_Viewer* anOCCViewer = anOCCViewManager->getOCCViewer();
976 removeViewShapes( (size_t)anOCCViewer );
979 if ( getVTKDisplayer()->IsApplicable( theViewManager ) )
981 SVTK_Viewer* aVTKViewer = getVTKViewer( anId );
984 getVTKDisplayer()->DeleteScalarBar( anId );
985 removeViewShapes( (size_t)aVTKViewer );
989 myViewManagerMap.remove( anId );
993 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
995 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
997 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
999 aViewFrame->installEventFilter( this );
1001 GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
1003 connect( aViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ),
1004 this, SLOT( onViewPortMouseEvent( QGraphicsSceneMouseEvent* ) ) );
1007 else if( theViewWindow && theViewWindow->inherits( "OCCViewer_ViewFrame" ) )
1009 if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( theViewWindow ) )
1011 aViewFrame->onTopView();
1013 HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false );
1018 void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent )
1020 /* ouv: currently unused
1021 if( GraphicsView_ViewPort* aViewPort = qobject_cast<GraphicsView_ViewPort*>( sender() ) )
1023 SUIT_ViewManager* aViewManager = 0;
1025 QObject* aParent = aViewPort;
1026 while( aParent = aParent->parent() )
1028 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( aParent ) )
1030 if( GraphicsView_Viewer* aViewer = aViewFrame->getViewer() )
1032 aViewManager = aViewer->getViewManager();
1041 double aMouseX = theEvent->scenePos().x();
1042 double aMouseY = theEvent->scenePos().y();
1044 ViewManagerRole aRole = getViewManagerRole( aViewManager );
1045 if( aRole == VMR_General )
1047 int aXDeg = 0, aYDeg = 0;
1048 int aXMin = 0, aYMin = 0;
1049 double aXSec = 0, aYSec = 0;
1050 HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec );
1051 HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec );
1053 QString aDegSymbol( QChar( 0x00B0 ) );
1054 QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec );
1055 QString aYStr = QString( "%1%2 %3' %4\"" ).arg( aYDeg ).arg( aDegSymbol ).arg( aYMin ).arg( aYSec );
1057 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( aXStr ).arg( aYStr ) );
1059 else if( aRole == VMR_TransformImage )
1060 aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) );
1065 void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
1066 const bool theIsInit,
1067 const bool theIsForced,
1068 const bool theDoFitAll )
1070 QList<int> aViewManagerIdList;
1072 // currently, all views are updated
1073 ViewManagerMapIterator anIter( myViewManagerMap );
1074 while( anIter.hasNext() )
1076 SUIT_ViewManager* aViewManager = anIter.next().value().first;
1078 if ( theDisplayer->IsApplicable( aViewManager ) )
1080 int anId = anIter.key();
1081 aViewManagerIdList.append( anId );
1085 QListIterator<int> anIdIter( aViewManagerIdList );
1086 while( anIdIter.hasNext() )
1088 theDisplayer->UpdateAll( anIdIter.next(), theIsInit, theIsForced, theDoFitAll );
1092 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
1094 if( !theViewManager )
1097 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1098 if( !aSelectionMgr )
1101 QString aViewType = theViewManager->getType();
1102 if( aViewType != GraphicsView_Viewer::Type() &&
1103 aViewType != OCCViewer_Viewer::Type())
1106 QList<SUIT_Selector*> aSelectorList;
1107 aSelectionMgr->selectors( aViewType, aSelectorList );
1109 // disable all alien selectors
1110 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
1111 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
1113 SUIT_Selector* aSelector = *anIter;
1114 if( aSelector && ( !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) &&
1115 !dynamic_cast<SVTK_Selector*>( aSelector ) &&
1116 !dynamic_cast<HYDROGUI_OCCSelector*>( aSelector ) ) )
1117 aSelector->setEnabled( false );
1120 if ( aViewType == GraphicsView_Viewer::Type() )
1122 GraphicsView_ViewManager* aViewManager =
1123 ::qobject_cast<GraphicsView_ViewManager*>( theViewManager );
1125 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
1127 else if ( aViewType == OCCViewer_Viewer::Type() )
1129 OCCViewer_ViewManager* aViewManager =
1130 ::qobject_cast<OCCViewer_ViewManager*>( theViewManager );
1132 new HYDROGUI_OCCSelector( this, aViewManager->getOCCViewer(), aSelectionMgr );
1136 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
1138 bool aPrevState = myIsUpdateEnabled;
1139 myIsUpdateEnabled = theState;
1143 bool HYDROGUI_Module::isUpdateEnabled() const
1145 return myIsUpdateEnabled;
1148 QStringList HYDROGUI_Module::storeSelection() const
1150 QStringList anEntryList;
1151 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1153 SUIT_DataOwnerPtrList aList( true );
1154 aSelectionMgr->selected( aList );
1156 SUIT_DataOwnerPtrList::iterator anIter;
1157 for( anIter = aList.begin(); anIter != aList.end(); anIter++ )
1159 const LightApp_DataOwner* anOwner =
1160 dynamic_cast<const LightApp_DataOwner*>( (*anIter).operator->() );
1162 anEntryList.append( anOwner->entry() );
1168 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
1170 if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
1172 SUIT_DataOwnerPtrList aList( true );
1173 for( int anIndex = 0, aSize = theEntryList.size(); anIndex < aSize; anIndex++ )
1174 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( theEntryList[ anIndex ] ) ) );
1175 aSelectionMgr->setSelected( aList );