Salome HOME
epaisseur des polylignes = 2
[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 HYDROGUI_AbstractDisplayer::HYDROGUI_AbstractDisplayer( HYDROGUI_Module* theModule )
29 : myModule( theModule )
30 {
31 }
32
33 HYDROGUI_AbstractDisplayer::~HYDROGUI_AbstractDisplayer()
34 {
35 }
36
37 bool HYDROGUI_AbstractDisplayer::IsApplicable( const int theViewerId ) const
38 {
39   return IsApplicable( myModule->getViewManager( theViewerId ) );
40 }
41
42 bool HYDROGUI_AbstractDisplayer::IsApplicable( const SUIT_ViewManager* theViewMgr ) const
43 {
44   return ( theViewMgr && ( theViewMgr->getType() == GetType() ) );
45 }
46
47 void HYDROGUI_AbstractDisplayer::UpdateAll( const int  theViewerId,
48                                        const bool theIsInit,
49                                        const bool theIsForced,
50                                        const bool theDoFitAll )
51 {
52   if ( theIsInit )
53     EraseAll( theViewerId );
54
55   DisplayAll( theViewerId, theIsForced, theDoFitAll );
56 }
57
58 void HYDROGUI_AbstractDisplayer::DisplayAll( const int  theViewerId,
59                                              const bool theIsForced,
60                                              const bool theDoFitAll )
61 {
62   HYDROData_SequenceOfObjects aSeq;
63   HYDROGUI_Tool::GetPrsSubObjects( myModule, aSeq );
64   Update( aSeq, theViewerId, theIsForced, theDoFitAll );
65 }
66
67 void HYDROGUI_AbstractDisplayer::Update( const HYDROData_SequenceOfObjects& theObjs,
68                                          const int                          theViewerId,
69                                          const bool                         theIsForced,
70                                          const bool                         theDoFitAll )
71 {
72   // First of all, kill all bad presentations
73   purgeObjects( theViewerId );
74
75   // Now dig in the data model
76   HYDROData_SequenceOfObjects anObjectsToErase, anObjectsToDisplay;
77   SUIT_ViewModel* aViewer = module()->getViewManager( theViewerId )->getViewModel();
78
79   for( int i = 1, n = theObjs.Length(); i <= n; i++ )
80   {
81     const Handle(HYDROData_Entity)& anObj = theObjs.Value( i );
82
83     if( module()->isObjectVisible( (size_t)aViewer, anObj ) ) 
84     {
85       anObjectsToDisplay.Append( anObj );
86     }
87     else
88     {
89       anObjectsToErase.Append( anObj );
90     }
91   }
92
93   if( anObjectsToErase.Length() )
94     Erase( anObjectsToErase, theViewerId );
95   if( anObjectsToDisplay.Length() )
96     Display( anObjectsToDisplay, theViewerId, theIsForced, theDoFitAll );
97 }