From dd184f153018fbb0a75e0803b2b6c1e34f10f26d Mon Sep 17 00:00:00 2001 From: jh777916 Date: Thu, 14 Sep 2023 09:11:18 +0200 Subject: [PATCH] Continuing the cleaning --- .../CurvePlot/src/python/test/CMakeLists.txt | 2 - .../python/test/PlotCurve_Standalone_test.py | 64 ---- .../CurvePlot/src/python/test/TestDesktop.py | 85 ++++- .../src/python/test/TestDesktop_test.py | 303 ------------------ 4 files changed, 77 insertions(+), 377 deletions(-) delete mode 100755 tools/CurvePlot/src/python/test/PlotCurve_Standalone_test.py delete mode 100755 tools/CurvePlot/src/python/test/TestDesktop_test.py diff --git a/tools/CurvePlot/src/python/test/CMakeLists.txt b/tools/CurvePlot/src/python/test/CMakeLists.txt index 57e618999..fd4c59f81 100644 --- a/tools/CurvePlot/src/python/test/CMakeLists.txt +++ b/tools/CurvePlot/src/python/test/CMakeLists.txt @@ -22,10 +22,8 @@ SALOME_CONFIGURE_FILE(SalomePyQt_MockUp.py.in mockup/SalomePyQt_MockUp.py) SET(_all_SCRIPTS PlotCurve_Standalone.py - PlotCurve_Standalone_test.py plot_test.py TestDesktop.py - TestDesktop_test.py ) SET(_test_SCRIPTS diff --git a/tools/CurvePlot/src/python/test/PlotCurve_Standalone_test.py b/tools/CurvePlot/src/python/test/PlotCurve_Standalone_test.py deleted file mode 100755 index 08db134ff..000000000 --- a/tools/CurvePlot/src/python/test/PlotCurve_Standalone_test.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: latin-1 -*- -# Copyright (C) 2007-2022 CEA/DEN, EDF R&D -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# Author : A. Bruneton -# -from pyqtside.QtWidgets import QApplication -from pyqtside.QtCore import QTimer, QTranslator - -from TestDesktop_test import TestDesktop_test -import SalomePyQt_MockUp - -desktop = None - -def activate(): - """This method mimicks SALOME's module activation """ - global desktop - - desktop.showCurveTreeView() - return True - -def activeViewChanged( viewID ): - from curveplot import PlotController - PlotController.ActiveViewChanged(viewID) - -def main(args) : - global desktop - - app = QApplication(args) - dw = app.desktop() - x, y = dw.width()*0.25, dw.height()*0.7 - - desktop = TestDesktop_test(None) - sgPyQt = SalomePyQt_MockUp.SalomePyQt(desktop) - sgPyQt.currentTabChanged.connect(activeViewChanged) - desktop._sgPyQt = sgPyQt - desktop.initialize() - desktop.resize(x,y) - desktop.show() - activate() - # - QTimer.singleShot(200, desktop.curveSameFig) - # - app.lastWindowClosed.connect(app.quit) - app.exec_() - -if __name__ == "__main__" : - import sys - main(sys.argv) diff --git a/tools/CurvePlot/src/python/test/TestDesktop.py b/tools/CurvePlot/src/python/test/TestDesktop.py index 7ab9510a7..2357b4f4e 100644 --- a/tools/CurvePlot/src/python/test/TestDesktop.py +++ b/tools/CurvePlot/src/python/test/TestDesktop.py @@ -33,7 +33,7 @@ except: from PlotController import PlotController as curveplot from utils import Logger -class TestDesktop(QMainWindow): +class TestDesktop_test(QMainWindow): """ Dummy desktop for testing purposes. """ def __init__(self, sgPyQt): @@ -76,6 +76,10 @@ class TestDesktop(QMainWindow): self.addTabAction.triggered.connect(self.addTab) self.memAction.triggered.connect(self.memPrint) self.perfTestAction.triggered.connect(self.perfTest) + self.addStemPlotAction.triggered.connect(self.addStemplot) + self.addBarPlotNonDiracAction.triggered.connect(self.addBarplotNonDirac) + self.addBarPlotDiracAction.triggered.connect(self.addBarplotDirac) + def generateID(self): self._currID += 1 @@ -92,6 +96,9 @@ class TestDesktop(QMainWindow): self.addTabActionID = self.generateID() self.memActionID = self.generateID() self.perfActionID = self.generateID() + self.addStemPlotActionID = self.generateID() + self.addBarPlotNonDiracActionID = self.generateID() + self.addBarPlotDiracActionID = self.generateID() # Menus self.etudeMenuID = self.generateID() @@ -108,16 +115,19 @@ class TestDesktop(QMainWindow): self.addTabAction = ca(self.addTabActionID, "Add tab", "Add tab", "", "") self.memAction = ca(self.memActionID, "Display used mem", "Display used mem", "", "") self.perfTestAction = ca(self.perfActionID, "Perf test", "Perf test", "", "") + self.addStemPlotAction = ca(self.addStemPlotActionID, "Add StemPlot - Dirac", "Add StemPlot - Dirac", "", "") + self.addBarPlotNonDiracAction = ca(self.addBarPlotNonDiracActionID, "Add BarPlot - Non Dirac", "Add BarPlot- Non Dirac", "", "") + self.addBarPlotDiracAction = ca(self.addBarPlotDiracActionID, "Add BarPlot - Dirac", "Add BarPlot - Dirac", "", "") def createToolbars(self): pass -# self.Toolbar = self._sgPyQt.createTool(self.tr("Toolbar")) -# self._sgPyQt.createTool(self.fileNewAction, self.Toolbar) -# self._sgPyQt.createTool(self.filePrintAction, self.Toolbar) -# sep = self._sgPyQt.createSeparator() -# self._sgPyQt.createTool(sep, self.Toolbar) -# self._sgPyQt.createTool(self.editUndoAction, self.Toolbar) -# self._sgPyQt.createTool(self.editRedoAction, self.Toolbar) +# self.Toolbar = self._sgPyQt.createTool(self.tr("Toolbar")) +# self._sgPyQt.createTool(self.fileNewAction, self.Toolbar) +# self._sgPyQt.createTool(self.filePrintAction, self.Toolbar) +# sep = self._sgPyQt.createSeparator() +# self._sgPyQt.createTool(sep, self.Toolbar) +# self._sgPyQt.createTool(self.editUndoAction, self.Toolbar) +# self._sgPyQt.createTool(self.editRedoAction, self.Toolbar) def createMenus(self): curveMenu = self._sgPyQt.createMenu( "Curve test", -1, self.etudeMenuID, self._sgPyQt.defaultMenuGroup() ) @@ -129,6 +139,9 @@ class TestDesktop(QMainWindow): self._sgPyQt.createMenu(self.addPSAction, curveMenu) self._sgPyQt.createMenu(self.memAction, curveMenu) self._sgPyQt.createMenu(self.perfTestAction, curveMenu) + self._sgPyQt.createMenu(self.addStemPlotAction, curveMenu) + self._sgPyQt.createMenu(self.addBarPlotNonDiracAction, curveMenu) + self._sgPyQt.createMenu(self.addBarPlotDiracAction, curveMenu) dummyMenu = self._sgPyQt.createMenu( "Dummy", -1, self.dummyMenuID, self._sgPyQt.defaultMenuGroup() ) self._sgPyQt.createMenu(self.addTabAction, dummyMenu) @@ -183,6 +196,62 @@ class TestDesktop(QMainWindow): curveplot.UnlockRepaint() print("Elapsed: %.2f" % ( time() - t0)) + @pyqtSlot() + def addBarplotDirac(self): + energy_val = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7]) + + intensity = np.random.rand(energy_val.size) * 10 + isDirac = True + width_dirac = np.full(energy_val.size, 0.05) + + _, ps_id = curveplot.AddBarPlot(energy_val, intensity, width_dirac, isDirac, + x_label="Energy", y_label="Intensity", append=True) + + curveplot.SetLegendVisible(ps_id, True) + + @pyqtSlot() + def addStemplot(self): + energy_val = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7]) + + intensity = np.random.rand(energy_val.size) * 10 + + _, ps_id = curveplot.AddStemPlot(energy_val, intensity, + x_label="Energy", y_label="Intensity", append=True) + + curveplot.SetLegendVisible(ps_id, True) + + + @pyqtSlot() + def addBarplotNonDirac(self): + from curveplot import TableModel + from random import random + + energy_inf = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7]) + energy_sup = np.array([1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7, 20.]) + deltaE = energy_sup - energy_inf + intensity = np.random.rand(energy_inf.size) * 10 + isDirac = False + + t = TableModel(None) + t.setTitle("Non Dirac data") + t.addColumn(energy_inf) # x : energy inf + t.addColumn(intensity) # height : intensity + t.addColumn(deltaE) # width : delta energy + t.setColumnTitle(0, "Energy") + t.setColumnTitle(1, "Intensity") + t.setColumnTitle(2, "DeltaE") + + bar_label = "Some spectrum" + cont = curveplot.PlotController.GetInstance() + crv_id, ps_id = cont.plotBarPlotFromTable(t, isDirac, + x_col_index=0, height_col_index=1, width_col_index=2, + curve_label=bar_label, + append=True) + + curveplot.SetLegendVisible(ps_id, True) + + + def clearPlotSet(self): curveplot.ClearPlotSet() diff --git a/tools/CurvePlot/src/python/test/TestDesktop_test.py b/tools/CurvePlot/src/python/test/TestDesktop_test.py deleted file mode 100755 index 7d68b1214..000000000 --- a/tools/CurvePlot/src/python/test/TestDesktop_test.py +++ /dev/null @@ -1,303 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2022 CEA/DEN, EDF R&D -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# Author : A. Bruneton -# - -from pyqtside.QtCore import Qt, QTimer, pyqtSlot -from pyqtside.QtWidgets import QMainWindow,QMenu -import numpy as np - -import curveplot - -try: - import curveplot - from curveplot.utils import Logger -except: - from PlotController import PlotController as curveplot - from utils import Logger - -class TestDesktop_test(QMainWindow): - """ Dummy desktop for testing purposes. - """ - def __init__(self, sgPyQt): - QMainWindow.__init__(self) - self.cnt = -1 - self.MAX_CNT = 20 - self.timeLap = 100 - self._sgPyQt = sgPyQt - - def initialize(self): - """ Initialize is called later than __init__() so that the Desktop and the SgPyQt - objects can be properly initialized. - """ - self._currID = 1234 - - self._sgDesktop = self - try: - self._plotController = curveplot.PlotController.GetInstance(self._sgPyQt) - except: - self._plotController = curveplot.GetInstance(self._sgPyQt) - self.createIDs() - self.createActions() - - context_actions = [self.itemDelAction] - menu = QMenu(self) - for a in context_actions: - menu.addAction(a) - self._plotController.setBrowserContextualMenu(menu) - - self.createToolbars() - self.createMenus() - self.createView() - - self.curveSameFigAction.triggered.connect(self.curveSameFig) - self.curveNewFigAction.triggered.connect(self.curveNewFig) - self.itemDelAction.triggered.connect(self.itemDel) - self.cpsAction.triggered.connect(self.clearPlotSet) - self.plotTableAction.triggered.connect(self.plotTable) - self.addPSAction.triggered.connect(self.addPS) - self.addTabAction.triggered.connect(self.addTab) - self.memAction.triggered.connect(self.memPrint) - self.perfTestAction.triggered.connect(self.perfTest) - self.addStemPlotAction.triggered.connect(self.addStemplot) - self.addBarPlotNonDiracAction.triggered.connect(self.addBarplotNonDirac) - self.addBarPlotDiracAction.triggered.connect(self.addBarplotDirac) - - - def generateID(self): - self._currID += 1 - return self._currID - - def createIDs(self): - # Actions - self.curveSameFigActionID = self.generateID() - self.curveNewFigActionID = self.generateID() - self.itemDelActionID = self.generateID() - self.cpsActionID = self.generateID() - self.plotTableActionID = self.generateID() - self.addPSActionID = self.generateID() - self.addTabActionID = self.generateID() - self.memActionID = self.generateID() - self.perfActionID = self.generateID() - self.addStemPlotActionID = self.generateID() - self.addBarPlotNonDiracActionID = self.generateID() - self.addBarPlotDiracActionID = self.generateID() - - # Menus - self.etudeMenuID = self.generateID() - self.dummyMenuID = self.generateID() - - def createActions(self): - ca = self._sgPyQt.createAction - self.curveSameFigAction = ca(self.curveSameFigActionID, "Curve on same fig", "Curve on same fig", "", "") - self.curveNewFigAction = ca(self.curveNewFigActionID, "Curve on new fig", "Curve on new fig", "", "") - self.itemDelAction = ca(self.itemDelActionID, "Delete selected", "Delete selected", "", "") - self.cpsAction = ca(self.cpsActionID, "Clear plot set", "Clear plot set", "", "") - self.plotTableAction = ca(self.plotTableActionID, "Plot from table", "Plot from table", "", "") - self.addPSAction = ca(self.addPSActionID, "Add plot set", "Add plot set", "", "") - self.addTabAction = ca(self.addTabActionID, "Add tab", "Add tab", "", "") - self.memAction = ca(self.memActionID, "Display used mem", "Display used mem", "", "") - self.perfTestAction = ca(self.perfActionID, "Perf test", "Perf test", "", "") - self.addStemPlotAction = ca(self.addStemPlotActionID, "Add StemPlot - Dirac", "Add StemPlot - Dirac", "", "") - self.addBarPlotNonDiracAction = ca(self.addBarPlotNonDiracActionID, "Add BarPlot - Non Dirac", "Add BarPlot- Non Dirac", "", "") - self.addBarPlotDiracAction = ca(self.addBarPlotDiracActionID, "Add BarPlot - Dirac", "Add BarPlot - Dirac", "", "") - - def createToolbars(self): - pass -# self.Toolbar = self._sgPyQt.createTool(self.tr("Toolbar")) -# self._sgPyQt.createTool(self.fileNewAction, self.Toolbar) -# self._sgPyQt.createTool(self.filePrintAction, self.Toolbar) -# sep = self._sgPyQt.createSeparator() -# self._sgPyQt.createTool(sep, self.Toolbar) -# self._sgPyQt.createTool(self.editUndoAction, self.Toolbar) -# self._sgPyQt.createTool(self.editRedoAction, self.Toolbar) - - def createMenus(self): - curveMenu = self._sgPyQt.createMenu( "Curve test", -1, self.etudeMenuID, self._sgPyQt.defaultMenuGroup() ) - self._sgPyQt.createMenu(self.curveSameFigAction, curveMenu) - self._sgPyQt.createMenu(self.curveNewFigAction, curveMenu) - self._sgPyQt.createMenu(self.itemDelAction, curveMenu) - self._sgPyQt.createMenu(self.cpsAction, curveMenu) - self._sgPyQt.createMenu(self.plotTableAction, curveMenu) - self._sgPyQt.createMenu(self.addPSAction, curveMenu) - self._sgPyQt.createMenu(self.memAction, curveMenu) - self._sgPyQt.createMenu(self.perfTestAction, curveMenu) - self._sgPyQt.createMenu(self.addStemPlotAction, curveMenu) - self._sgPyQt.createMenu(self.addBarPlotNonDiracAction, curveMenu) - self._sgPyQt.createMenu(self.addBarPlotDiracAction, curveMenu) - - dummyMenu = self._sgPyQt.createMenu( "Dummy", -1, self.dummyMenuID, self._sgPyQt.defaultMenuGroup() ) - self._sgPyQt.createMenu(self.addTabAction, dummyMenu) - - def createView(self): - pass - - def showCurveTreeView(self) : - self._dockCurveBrowserView = self._plotController._curveBrowserView - self._sgDesktop.addDockWidget(Qt.LeftDockWidgetArea, self._dockCurveBrowserView) - - def __generateRandomData(self, nPoints=100): - from random import random - x = np.arange(nPoints) / 5.0 - ampl = 20.0*random() + 1.0 - y = ampl * np.sin(x*random()) -# x = np.arange(5e5) -# y = x - return x, y - - @pyqtSlot() - def curveSameFig(self): - x, y = self.__generateRandomData() - _, ps_id = curveplot.AddCurve(x, y, x_label="the x axis", y_label="the y axis", append=True) - curveplot.SetLegendVisible(ps_id, True) - if self.cnt >= 0: - QTimer.singleShot(self.timeLap, self, SLOT("itemDel()")) - - def curveNewFig(self): - x, y = self.__generateRandomData() - curveplot.AddCurve(x, y, x_label="the x axis", y_label="the y axis", append=False) - - @pyqtSlot() - def itemDel(self): - curveplot.DeleteCurrentItem() - if self.cnt >= 0: - QTimer.singleShot(self.timeLap, self, SLOT("memPrint()")) - - @pyqtSlot() - def perfTest(self): - lx, ly = [], [] - nC = 200 - for _ in range(nC): - x, y = self.__generateRandomData(1000) - lx.append(x); ly.append(y) - print("Done generating") - from time import time - t0 = time() - curveplot.LockRepaint() - for i in range(nC): - curveplot.AddCurve(lx[i], ly[i], append=True) - curveplot.UnlockRepaint() - print("Elapsed: %.2f" % ( time() - t0)) - - @pyqtSlot() - def addBarplotDirac(self): - energy_val = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7]) - # energy_val = np.array([8.15, 8.42, 8.75, 8.88, 9.1, 9.55, 9.79]) - - intensity = np.random.rand(energy_val.size) * 10 - isDirac = True - width_dirac = np.full(energy_val.size, 0.05) - - _, ps_id = curveplot.AddBarPlot(energy_val, intensity, width_dirac, isDirac, - x_label="Energy", y_label="Intensity", append=True) - - curveplot.SetLegendVisible(ps_id, True) - # if self.cnt >= 0: - # QTimer.singleShot(self.timeLap, self, SLOT("itemDel()")) - - - @pyqtSlot() - def addStemplot(self): - energy_val = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7]) - # energy_val = np.array([8.15, 8.42, 8.75, 8.88, 9.1, 9.55, 9.79]) - - intensity = np.random.rand(energy_val.size) * 10 - - _, ps_id = curveplot.AddStemPlot(energy_val, intensity, - x_label="Energy", y_label="Intensity", append=True) - - curveplot.SetLegendVisible(ps_id, True) - # if self.cnt >= 0: - # QTimer.singleShot(self.timeLap, self, SLOT("itemDel()")) - - - @pyqtSlot() - def addBarplotNonDirac(self): - # Testing with TableModel - from curveplot import TableModel - from random import random - - energy_inf = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7]) - energy_sup = np.array([1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7, 20.]) - deltaE = energy_sup - energy_inf - intensity = np.random.rand(energy_inf.size) * 10 - isDirac = False - - t = TableModel(None) - t.setTitle("Non Dirac data") - t.addColumn(energy_inf) # x : energy inf - t.addColumn(intensity) # height : intensity - t.addColumn(deltaE) # width : delta energy - t.setColumnTitle(0, "Energy") - t.setColumnTitle(1, "Intensity") - t.setColumnTitle(2, "DeltaE") - - bar_label = "Some spectrum" - cont = curveplot.PlotController.GetInstance() - crv_id, ps_id = cont.plotBarPlotFromTable(t, isDirac, - x_col_index=0, height_col_index=1, width_col_index=2, - curve_label=bar_label, - append=True) - - curveplot.SetLegendVisible(ps_id, True) - - # if self.cnt >= 0: - # QTimer.singleShot(self.timeLap, self, SLOT("itemDel()")) - - - def clearPlotSet(self): - curveplot.ClearPlotSet() - - def addPS(self): - # Also a test for unicode! - curveplot.AddPlotSet('ça m embête') - - def addTab(self): - pass -# from PyQt5.QtWidgets import QPushButton -# self.qp = QPushButton("Hi!") -# self._sgPyQt.createView("Dummy", self.qp) - - def plotTable(self): - from curveplot import TableModel - t = TableModel(None) - t.setTitle("coucou") - t.addColumn([1.0,2.0,3.0,4.0]) - t.addColumn([1.0,2.0,3.0,4.0]) - t.addColumn([1.0,4.0,9.0,16.0]) - t.setColumnTitle(0, "X-s") - t.setColumnTitle(1, "Identity") - t.setColumnTitle(2, "Square") - cont = curveplot.PlotController.GetInstance() - cont.plotCurveFromTable(t, y_col_index=1, append=False) - cont.plotCurveFromTable(t, y_col_index=2, append=True) - - @pyqtSlot() - def memPrint(self): - i, t = curveplot.GetAllPlotSets() - print(list(zip(i, t))) - new_id = curveplot.CopyCurve(curve_id=0, plot_set_id=1) - print("created curve: %d" % new_id) - import resource - m = resource.getrusage(resource.RUSAGE_SELF)[2]*resource.getpagesize()/1e6 - print("** Used memory: %.2f Mb" % m) - if self.cnt >= 0 and self.cnt < self.MAX_CNT: - self.cnt += 1 - QTimer.singleShot(self.timeLap, self.curveSameFig) -- 2.39.2