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_OCCDisplayer.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
28 #include "HYDROGUI_Shape.h"
30 #include <AIS_InteractiveContext.hxx>
31 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 #include <AIS_ListOfInteractive.hxx>
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewModel.h>
36 #include <OCCViewer_ViewWindow.h>
38 HYDROGUI_OCCDisplayer::HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule )
39 : HYDROGUI_AbstractDisplayer( theModule )
43 HYDROGUI_OCCDisplayer::~HYDROGUI_OCCDisplayer()
47 void HYDROGUI_OCCDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
48 const int theViewerId )
50 OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId );
54 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
56 Handle(HYDROData_Entity) anObj = theObjs.Value( i );
60 HYDROGUI_Shape* anObjShape = module()->getObjectShape( (size_t)aViewer, anObj );
64 anObjShape->setIsToUpdate( true );
68 void HYDROGUI_OCCDisplayer::EraseAll( const int theViewerId )
70 OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId );
74 module()->removeViewShapes( (size_t)aViewer );
77 void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
78 const int theViewerId )
80 OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId );
84 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
86 Handle(HYDROData_Entity) anObj = theObjs.Value( i );
90 module()->removeObjectShape( (size_t)aViewer, anObj );
95 HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int theViewerId,
96 const Handle(AIS_InteractiveContext)& theContext,
97 const Handle(HYDROData_Entity)& theObject )
99 HYDROGUI_Shape* aResShape = NULL;
100 if ( theContext.IsNull() || theObject.IsNull() )
103 ObjectKind anObjectKind = theObject->GetKind();
104 if ( anObjectKind != KIND_IMAGE &&
105 anObjectKind != KIND_POLYLINEXY &&
106 anObjectKind != KIND_POLYLINE &&
107 anObjectKind != KIND_IMMERSIBLE_ZONE &&
108 anObjectKind != KIND_REGION &&
109 anObjectKind != KIND_ZONE &&
110 anObjectKind != KIND_OBSTACLE &&
111 anObjectKind != KIND_PROFILE &&
112 anObjectKind != KIND_STREAM &&
113 anObjectKind != KIND_CHANNEL &&
114 anObjectKind != KIND_DIGUE )
117 aResShape = new HYDROGUI_Shape( theContext, theObject );
118 module()->setObjectShape( theViewerId, theObject, aResShape );
123 void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs,
124 const int theViewerId,
125 const bool theIsForced,
126 const bool theDoFitAll )
128 OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId );
132 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
136 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
138 Handle(HYDROData_Entity) anObj = theObjs.Value( i );
139 if ( anObj.IsNull() || anObj->IsRemoved() )
142 HYDROGUI_Shape* anObjShape = module()->getObjectShape( (size_t)aViewer, anObj );
144 if ( !anObjShape || anObjShape->getIsToUpdate() || theIsForced )
147 anObjShape = createShape( (size_t)aViewer, aCtx, anObj );
150 anObjShape->update( false );
155 bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj );
156 anObjShape->setVisible( anIsVisible, false );
162 OCCViewer_ViewManager* aViewManager
163 = ::qobject_cast<OCCViewer_ViewManager*>( aViewer->getViewManager() );
166 OCCViewer_ViewWindow* aViewWindow =
167 ::qobject_cast<OCCViewer_ViewWindow*>( aViewManager->getActiveView() );
170 aViewWindow->onFitAll();
176 void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId )
178 OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId );
182 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
186 AIS_ListOfInteractive aDisplayedObjects;
187 aCtx->DisplayedObjects( aDisplayedObjects );
189 AIS_ListIteratorOfListOfInteractive aListIter( aDisplayedObjects );
190 for ( ; aListIter.More(); aListIter.Next() )
192 Handle(AIS_InteractiveObject) aPrsObj = aListIter.Value();
193 if ( aPrsObj.IsNull() )
196 Handle(HYDROData_Entity) anOwnerObj =
197 Handle(HYDROData_Entity)::DownCast( aPrsObj->GetOwner() );
198 if ( !anOwnerObj.IsNull() && anOwnerObj->IsRemoved() )
199 module()->removeObjectShape( (size_t)aViewer, anOwnerObj );
203 QString HYDROGUI_OCCDisplayer::GetType() const
205 return OCCViewer_Viewer::Type();