1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # Author : A. Bruneton
26 from pyqtside.QtCore import SIGNAL, SLOT, Slot, Qt, QTimer
27 from pyqtside.QtGui import QMainWindow,QMenu
34 from curveplot.utils import Logger
36 from PlotController import PlotController as curveplot
37 from utils import Logger
39 class TestDesktop(QMainWindow):
40 """ Dummy desktop for testing purposes.
42 def __init__(self, sgPyQt):
43 QMainWindow.__init__(self)
50 """ Initialize is called later than __init__() so that the Desktop and the SgPyQt
51 objects can be properly initialized.
55 self._sgDesktop = self
57 self._plotController = curveplot.PlotController.GetInstance(self._sgPyQt)
59 self._plotController = curveplot.GetInstance(self._sgPyQt)
63 context_actions = [self.itemDelAction]
65 for a in context_actions:
67 self._plotController.setBrowserContextualMenu(menu)
73 self.connect(self.curveSameFigAction,SIGNAL("activated()"),self.curveSameFig)
74 self.connect(self.curveNewFigAction,SIGNAL("activated()"),self.curveNewFig)
75 self.connect(self.itemDelAction,SIGNAL("activated()"),self.itemDel)
76 self.connect(self.cpsAction,SIGNAL("activated()"),self.clearPlotSet)
77 self.connect(self.plotTableAction,SIGNAL("activated()"),self.plotTable)
78 self.connect(self.addPSAction,SIGNAL("activated()"),self.addPS)
79 self.connect(self.addTabAction,SIGNAL("activated()"),self.addTab)
80 self.connect(self.memAction,SIGNAL("activated()"),self.memPrint)
81 self.connect(self.perfTestAction,SIGNAL("activated()"),self.perfTest)
89 self.curveSameFigActionID = self.generateID()
90 self.curveNewFigActionID = self.generateID()
91 self.itemDelActionID = self.generateID()
92 self.cpsActionID = self.generateID()
93 self.plotTableActionID = self.generateID()
94 self.addPSActionID = self.generateID()
95 self.addTabActionID = self.generateID()
96 self.memActionID = self.generateID()
97 self.perfActionID = self.generateID()
100 self.etudeMenuID = self.generateID()
101 self.dummyMenuID = self.generateID()
103 def createActions(self):
104 ca = self._sgPyQt.createAction
105 self.curveSameFigAction = ca(self.curveSameFigActionID, "Curve on same fig", "Curve on same fig", "", "")
106 self.curveNewFigAction = ca(self.curveNewFigActionID, "Curve on new fig", "Curve on new fig", "", "")
107 self.itemDelAction = ca(self.itemDelActionID, "Delete selected", "Delete selected", "", "")
108 self.cpsAction = ca(self.cpsActionID, "Clear plot set", "Clear plot set", "", "")
109 self.plotTableAction = ca(self.plotTableActionID, "Plot from table", "Plot from table", "", "")
110 self.addPSAction = ca(self.addPSActionID, "Add plot set", "Add plot set", "", "")
111 self.addTabAction = ca(self.addTabActionID, "Add tab", "Add tab", "", "")
112 self.memAction = ca(self.memActionID, "Display used mem", "Display used mem", "", "")
113 self.perfTestAction = ca(self.perfActionID, "Perf test", "Perf test", "", "")
115 def createToolbars(self):
117 # self.Toolbar = self._sgPyQt.createTool(self.tr("Toolbar"))
118 # self._sgPyQt.createTool(self.fileNewAction, self.Toolbar)
119 # self._sgPyQt.createTool(self.filePrintAction, self.Toolbar)
120 # sep = self._sgPyQt.createSeparator()
121 # self._sgPyQt.createTool(sep, self.Toolbar)
122 # self._sgPyQt.createTool(self.editUndoAction, self.Toolbar)
123 # self._sgPyQt.createTool(self.editRedoAction, self.Toolbar)
125 def createMenus(self):
126 curveMenu = self._sgPyQt.createMenu( "Curve test", -1, self.etudeMenuID, self._sgPyQt.defaultMenuGroup() )
127 self._sgPyQt.createMenu(self.curveSameFigAction, curveMenu)
128 self._sgPyQt.createMenu(self.curveNewFigAction, curveMenu)
129 self._sgPyQt.createMenu(self.itemDelAction, curveMenu)
130 self._sgPyQt.createMenu(self.cpsAction, curveMenu)
131 self._sgPyQt.createMenu(self.plotTableAction, curveMenu)
132 self._sgPyQt.createMenu(self.addPSAction, curveMenu)
133 self._sgPyQt.createMenu(self.memAction, curveMenu)
134 self._sgPyQt.createMenu(self.perfTestAction, curveMenu)
136 dummyMenu = self._sgPyQt.createMenu( "Dummy", -1, self.dummyMenuID, self._sgPyQt.defaultMenuGroup() )
137 self._sgPyQt.createMenu(self.addTabAction, dummyMenu)
139 def createView(self):
142 def showCurveTreeView(self) :
143 self._dockCurveBrowserView = self._plotController._curveBrowserView
144 self._sgDesktop.addDockWidget(Qt.LeftDockWidgetArea, self._dockCurveBrowserView)
146 def __generateRandomData(self, nPoints=100):
147 from random import random
148 x = np.arange(nPoints) / 5.0
149 ampl = 20.0*random() + 1.0
150 y = ampl * np.sin(x*random())
156 def curveSameFig(self):
157 x, y = self.__generateRandomData()
158 _, ps_id = curveplot.AddCurve(x, y, x_label="the x axis", y_label="the y axis", append=True)
159 curveplot.SetLegendVisible(ps_id, True)
161 QTimer.singleShot(self.timeLap, self, SLOT("itemDel()"))
163 def curveNewFig(self):
164 x, y = self.__generateRandomData()
165 curveplot.AddCurve(x, y, x_label="the x axis", y_label="the y axis", append=False)
169 curveplot.DeleteCurrentItem()
171 QTimer.singleShot(self.timeLap, self, SLOT("memPrint()"))
178 x, y = self.__generateRandomData(1000)
179 lx.append(x); ly.append(y)
180 print("Done generating")
181 from time import time
183 curveplot.LockRepaint()
185 curveplot.AddCurve(lx[i], ly[i], append=True)
186 curveplot.UnlockRepaint()
187 print("Elapsed: %.2f" % ( time() - t0))
189 def clearPlotSet(self):
190 curveplot.ClearPlotSet()
193 # Also a test for unicode!
194 curveplot.AddPlotSet('ça m embête')
198 # from PyQt4.QtGui import QPushButton
199 # self.qp = QPushButton("Hi!")
200 # self._sgPyQt.createView("Dummy", self.qp)
203 from curveplot import TableModel
206 t.addColumn([1.0,2.0,3.0,4.0])
207 t.addColumn([1.0,2.0,3.0,4.0])
208 t.addColumn([1.0,4.0,9.0,16.0])
209 t.setColumnTitle(0, "X-s")
210 t.setColumnTitle(1, "Identity")
211 t.setColumnTitle(2, "Square")
212 cont = curveplot.PlotController.GetInstance()
213 cont.plotCurveFromTable(t, y_col_index=1, append=False)
214 cont.plotCurveFromTable(t, y_col_index=2, append=True)
218 i, t = curveplot.GetAllPlotSets()
219 print(list(zip(i, t)))
220 new_id = curveplot.CopyCurve(curve_id=0, plot_set_id=1)
221 print("created curve: %d" % new_id)
223 m = resource.getrusage(resource.RUSAGE_SELF)[2]*resource.getpagesize()/1e6
224 print("** Used memory: %.2f Mb" % m)
225 if self.cnt >= 0 and self.cnt < self.MAX_CNT:
227 QTimer.singleShot(self.timeLap, self, SLOT("curveSameFig()"))