1 # Copyright (C) 2016-2022 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from .View import View
21 from .XYView import XYView
22 from .utils import Logger
24 class CurveTabsView(View):
25 def __init__(self, controller):
26 View.__init__(self, controller)
27 self._XYViews = {} # key: SALOME view ID, value: XYView
29 def closeXYView(self, salomeViewID):
30 Logger.Debug("CurveTabsView::closeXYView: %d" % salomeViewID)
31 self._controller.setCurvePlotRequestingClose(True)
32 self._controller._sgPyQt.closeView(salomeViewID)
33 self._controller.setCurvePlotRequestingClose(False)
35 self._XYViews.pop(salomeViewID)
36 Logger.Debug("CurveTabsView::closeXYView count %d" % len(self._XYViews))
38 def createXYView(self, model):
39 v = XYView(self._controller)
40 self._controller.associate(model, v)
43 def onCurrentPlotSetChange(self):
44 """ Avoid a unnecessary call to update() when just switching current plot set! """
45 cps = self._model.getCurrentPlotSet()
47 mp = self.mapModId2ViewId()
48 salomeViewID = mp[cps.getID()]
49 self._controller._sgPyQt.activateView(salomeViewID)
51 def mapModId2ViewId(self):
52 """ Gives a map from model ID (the model behind the XYView) to view ID
54 lst = [(v._model.getID(), view_id) for view_id, v in list(self._XYViews.items())]
59 Updates the list of tabs shown in the GUI
61 if self._model is None:
65 set_mod = set(self._model._plotSets.keys())
66 set_view = { v._model.getID() for v in list(self._XYViews.values()) }
67 mp = self.mapModId2ViewId()
69 # Deleted/Added curves:
70 dels = set_view - set_mod
71 added = set_mod - set_view
75 v = self._XYViews[salomeViewID]
77 self.closeXYView(salomeViewID)
81 newViews.append(self.createXYView(self._model._plotSets[a]))
83 # Now update all tabs individually (this will trigger creation of new ones if not already there):
84 for v in list(self._XYViews.values()) + newViews:
85 # The update on newViews will trigger the SALOME view creation:
88 # And complete internal structure for new views
91 self._XYViews[v._salomeViewID] = v
93 # Finally activate the proper tab:
94 self.onCurrentPlotSetChange()