]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_AbstractDisplayer.cxx
Salome HOME
test h019 simplified
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_AbstractDisplayer.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_AbstractDisplayer.h"
20
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_Tool2.h"
24
25 #include <SUIT_ViewManager.h>
26 #include <SUIT_ViewModel.h>
27
28 //#define _DEVDEBUG_
29 #include "HYDRO_trace.hxx"
30
31 HYDROGUI_AbstractDisplayer::HYDROGUI_AbstractDisplayer( HYDROGUI_Module* theModule )
32 : myModule( theModule )
33 {
34 }
35
36 HYDROGUI_AbstractDisplayer::~HYDROGUI_AbstractDisplayer()
37 {
38 }
39
40 bool HYDROGUI_AbstractDisplayer::IsApplicable( const size_t theViewerId ) const
41 {
42   return IsApplicable( myModule->getViewManager( theViewerId ) );
43 }
44
45 bool HYDROGUI_AbstractDisplayer::IsApplicable( const SUIT_ViewManager* theViewMgr ) const
46 {
47   return ( theViewMgr && ( theViewMgr->getType() == GetType() ) );
48 }
49
50 void HYDROGUI_AbstractDisplayer::UpdateAll( const size_t theViewerId,
51                                        const bool theIsInit,
52                                        const bool theIsForced,
53                                        const bool theDoFitAll )
54 {
55   DEBTRACE("UpdateAll");
56   if ( theIsInit )
57     EraseAll( theViewerId );
58
59   DisplayAll( theViewerId, theIsForced, theDoFitAll );
60 }
61
62 void HYDROGUI_AbstractDisplayer::DisplayAll( const size_t theViewerId,
63                                              const bool theIsForced,
64                                              const bool theDoFitAll )
65 {
66         DEBTRACE("DisplayAll");
67   HYDROData_SequenceOfObjects aSeq;
68   HYDROGUI_Tool::GetPrsSubObjects( myModule, aSeq );
69   Update( aSeq, theViewerId, theIsForced, theDoFitAll );
70 }
71
72 void HYDROGUI_AbstractDisplayer::Update( const HYDROData_SequenceOfObjects& theObjs,
73                                          const size_t                       theViewerId,
74                                          const bool                         theIsForced,
75                                          const bool                         theDoFitAll )
76 {
77         DEBTRACE("Update");
78   // First of all, kill all bad presentations
79   purgeObjects( theViewerId );
80
81   // Now dig in the data model
82   HYDROData_SequenceOfObjects anObjectsToErase, anObjectsToDisplay;
83   SUIT_ViewModel* aViewer = module()->getViewManager( theViewerId )->getViewModel();
84
85   for( int i = 1, n = theObjs.Length(); i <= n; i++ )
86   {
87     const Handle(HYDROData_Entity)& anObj = theObjs.Value( i );
88
89     if( module()->isObjectVisible( (size_t)aViewer, anObj ) ) 
90     {
91       anObjectsToDisplay.Append( anObj );
92     }
93     else
94     {
95       anObjectsToErase.Append( anObj );
96     }
97   }
98
99   if( anObjectsToErase.Length() )
100     Erase( anObjectsToErase, theViewerId );
101   if( anObjectsToDisplay.Length() )
102     Display( anObjectsToDisplay, theViewerId, theIsForced, theDoFitAll );
103 }