From: jh777916 Date: Wed, 6 Sep 2023 07:03:05 +0000 (+0200) Subject: Adding a barplot : dirac seems to be nicely added and selectable. Lets try to add... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a46b4425619c5f4ee76fda85eeab3757810839ff;p=modules%2Fgui.git Adding a barplot : dirac seems to be nicely added and selectable. Lets try to add some non-dirac stuff --- diff --git a/tools/CurvePlot/CMakeLists.txt b/tools/CurvePlot/CMakeLists.txt index 357c13095..e70d4b140 100644 --- a/tools/CurvePlot/CMakeLists.txt +++ b/tools/CurvePlot/CMakeLists.txt @@ -36,7 +36,7 @@ SET(${PROJECT_NAME_UC}_VERSION_DEV 0) # User options # ============ OPTION(SALOME_CURVEPLOT_STANDALONE "Standalone installation of CURVEPLOT" OFF) -OPTION(SALOME_BUILD_DOC "Generate SALOME CURVEPLOT documentation" ON) +OPTION(SALOME_BUILD_DOC "Generate SALOME CURVEPLOT documentation" OFF) OPTION(SALOME_BUILD_TESTS "Generate SALOME CURVEPLOT tests" ON) # Common CMake macros diff --git a/tools/CurvePlot/src/python/controller/PlotController.py b/tools/CurvePlot/src/python/controller/PlotController.py index abdbe65d0..a75619fc2 100644 --- a/tools/CurvePlot/src/python/controller/PlotController.py +++ b/tools/CurvePlot/src/python/controller/PlotController.py @@ -21,6 +21,7 @@ from .CurveBrowserView import CurveBrowserView from .PlotManager import PlotManager from .CurveTabsView import CurveTabsView from .CurveModel import CurveModel +from .BarModel import BarModel from .TableModel import TableModel from .utils import Logger import numpy as np @@ -787,7 +788,7 @@ class PlotController(object): if curve_label != "": bm.setTitle(curve_label) else: - ti = table.getColumnTitle(y_col_index) + ti = table.getColumnTitle(height_col_index) if ti != "": bm.setTitle(ti) diff --git a/tools/CurvePlot/src/python/controller/utils.py.in b/tools/CurvePlot/src/python/controller/utils.py.in index 0b1302a76..4af81f726 100644 --- a/tools/CurvePlot/src/python/controller/utils.py.in +++ b/tools/CurvePlot/src/python/controller/utils.py.in @@ -21,7 +21,7 @@ class Logger(object): """ Debug Info. """ - LOG_LEVEL = 1 # 0 means all, 1 means all but DEBUG, 2 means all but INFO and DEBUG, 3 only FATAL + LOG_LEVEL = 0 # 0 means all, 1 means all but DEBUG, 2 means all but INFO and DEBUG, 3 only FATAL @classmethod def Debug(cls, msg): diff --git a/tools/CurvePlot/src/python/model/CMakeLists.txt b/tools/CurvePlot/src/python/model/CMakeLists.txt index c48bc88a3..400a87853 100644 --- a/tools/CurvePlot/src/python/model/CMakeLists.txt +++ b/tools/CurvePlot/src/python/model/CMakeLists.txt @@ -20,6 +20,7 @@ SET(_all_lib_SCRIPTS Model.py CurveModel.py + BarModel.py TableModel.py PlotManager.py XYPlotSetModel.py diff --git a/tools/CurvePlot/src/python/model/CurveModel.py b/tools/CurvePlot/src/python/model/CurveModel.py index 0089cd680..50cdf7f0c 100644 --- a/tools/CurvePlot/src/python/model/CurveModel.py +++ b/tools/CurvePlot/src/python/model/CurveModel.py @@ -23,6 +23,8 @@ from .utils import toUnicodeWithWarning class CurveModel(Model): def __init__(self, controller, table=None, index=-1): Model.__init__(self, controller) + + # self._name = "CurveModel" self._title = "Curve %d" % self.getID() self._table = table self._yaxisIndex = index # column index in the table diff --git a/tools/CurvePlot/src/python/test/CMakeLists.txt b/tools/CurvePlot/src/python/test/CMakeLists.txt index b2e7569fb..de81a52dd 100644 --- a/tools/CurvePlot/src/python/test/CMakeLists.txt +++ b/tools/CurvePlot/src/python/test/CMakeLists.txt @@ -22,8 +22,10 @@ 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/TestDesktop_test.py b/tools/CurvePlot/src/python/test/TestDesktop_test.py index 200249779..cfcc38cbc 100755 --- a/tools/CurvePlot/src/python/test/TestDesktop_test.py +++ b/tools/CurvePlot/src/python/test/TestDesktop_test.py @@ -76,6 +76,7 @@ class TestDesktop_test(QMainWindow): self.addTabAction.triggered.connect(self.addTab) self.memAction.triggered.connect(self.memPrint) self.perfTestAction.triggered.connect(self.perfTest) + self.addBarPlotAction.triggered.connect(self.addBarplot) def generateID(self): self._currID += 1 @@ -92,6 +93,7 @@ class TestDesktop_test(QMainWindow): self.addTabActionID = self.generateID() self.memActionID = self.generateID() self.perfActionID = self.generateID() + self.addBarPlotActionID = self.generateID() # Menus self.etudeMenuID = self.generateID() @@ -130,6 +132,7 @@ class TestDesktop_test(QMainWindow): self._sgPyQt.createMenu(self.addPSAction, curveMenu) self._sgPyQt.createMenu(self.memAction, curveMenu) self._sgPyQt.createMenu(self.perfTestAction, curveMenu) + self._sgPyQt.createMenu(self.addBarPlotAction, curveMenu) dummyMenu = self._sgPyQt.createMenu( "Dummy", -1, self.dummyMenuID, self._sgPyQt.defaultMenuGroup() ) self._sgPyQt.createMenu(self.addTabAction, dummyMenu) @@ -184,6 +187,17 @@ class TestDesktop_test(QMainWindow): curveplot.UnlockRepaint() print("Elapsed: %.2f" % ( time() - t0)) + @pyqtSlot() + def addBarplot(self): + x, height = self.__generateRandomData() + width = np.full(x.size, 0.05) + isDirac = True + _, ps_id = curveplot.AddBarPlot(x, height, width, isDirac, + 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 clearPlotSet(self): curveplot.ClearPlotSet() diff --git a/tools/CurvePlot/src/python/views/CurveView.py b/tools/CurvePlot/src/python/views/CurveView.py index c9df3e62e..708ce92e2 100644 --- a/tools/CurvePlot/src/python/views/CurveView.py +++ b/tools/CurvePlot/src/python/views/CurveView.py @@ -22,6 +22,7 @@ from .utils import Logger class CurveView(View): _PICKER_PRECISION = 20 #pts + _PICKER_PRECISION_BAR = 5 #pts def __init__(self, controller, parentXYView): View.__init__(self, controller) @@ -31,6 +32,7 @@ class CurveView(View): self._isHighlighted = False self._initialLineWidth = None + self._initialEdgeColorBar = None self._parentXYView = parentXYView self._marker = None @@ -44,7 +46,7 @@ class CurveView(View): m = self._model # Check si BarModel ou CurveModel if (m._name == "BarModel"): - self._mplAxes.container.BarContainer.remove(self._mplBars[0]) + self._mplBars.remove() self._mplBars = None else: self._mplAxes.lines.remove(self._mplLines[0]) @@ -57,8 +59,12 @@ class CurveView(View): x_idx, height_idx, width_idx = m.getXAxisIndex(), m.getHeightIndex(), m.getWidthIndex() x_align = "center" if m.getIsDirac() else "edge" d = self._model.getTable().getData() - self._mplBars = self._mplAxes.bar(d[:, x_idx], d[:, height_idx], width=d[:, height_idx], - align=x_align, label=m._title, picker=self._PICKER_PRECISION) + self._mplBars = self._mplAxes.bar(d[:, x_idx], d[:, height_idx], width=d[:, width_idx], + align=x_align, label=m._title, picker=self._PICKER_PRECISION_BAR) + self._initialLineWidth = self._mplBars[0].get_linewidth() + print("Bar initial lw : ", self._initialLineWidth) + self._initialEdgeColorBar = self._mplBars[0].get_edgecolor() + print("Bar initial ec : ", self._initialEdgeColorBar) else: x_idx, y_idx = m.getXAxisIndex(), m.getYAxisIndex() d = self._model.getTable().getData() @@ -72,7 +78,7 @@ class CurveView(View): if (m._name == "BarModel"): if self._mplBars is None: return - self._mplBars[0].set_label(self._model._title) + self._mplBars.set_label(self._model._title) else: if self._mplLines is None: return @@ -90,7 +96,7 @@ class CurveView(View): self.erase() self.draw() self.setColor(color) - # self.toggleHighlight(self._isHighlighted, force=True) + self.toggleHighlight(self._isHighlighted, force=True) else: if self._mplLines is None: return @@ -122,16 +128,32 @@ class CurveView(View): return self._mplLines[0].get_marker() def toggleHighlight(self, highlight, force=False): - lin = self._mplLines[0] - if highlight and (force or not self._isHighlighted): - lin.set_linewidth(2*self._initialLineWidth) - self._isHighlighted = True - elif not highlight and (force or self._isHighlighted): - lin.set_linewidth(self._initialLineWidth) - self._isHighlighted = False + if (self._model._name == "BarModel"): + bar = self._mplBars.patches + if highlight and (force or not self._isHighlighted): + for rect in bar : + rect.set_linewidth(2*self._initialLineWidth) + rect.set_edgecolor("red") + self._isHighlighted = True + elif not highlight and (force or self._isHighlighted): + for rect in bar : + rect.set_linewidth(self._initialLineWidth) + rect.set_edgecolor(self._initialEdgeColorBar) + self._isHighlighted = False + else: + # Nothing to do, already the correct state + return else: - # Nothing to do, already the correct state - return + lin = self._mplLines[0] + if highlight and (force or not self._isHighlighted): + lin.set_linewidth(2*self._initialLineWidth) + self._isHighlighted = True + elif not highlight and (force or self._isHighlighted): + lin.set_linewidth(self._initialLineWidth) + self._isHighlighted = False + else: + # Nothing to do, already the correct state + return def isHighlighted(self): return self._isHighlighted @@ -140,7 +162,7 @@ class CurveView(View): m = self._model # Check si BarModel ou CurveModel if (m._name == "BarModel"): - bar = self._mplBars[0] + bar = self._mplBars bar.set_color(rgb_color) else: lin = self._mplLines[0] diff --git a/tools/CurvePlot/src/python/views/XYView.py b/tools/CurvePlot/src/python/views/XYView.py index 492d35007..128736f23 100644 --- a/tools/CurvePlot/src/python/views/XYView.py +++ b/tools/CurvePlot/src/python/views/XYView.py @@ -19,6 +19,7 @@ import matplotlib.pyplot as plt import matplotlib.colors as colors +from matplotlib.patches import Rectangle from pyqtside import QtWidgets, QtCore from pyqtside.QtCore import QObject from matplotlib.figure import Figure @@ -122,7 +123,10 @@ class XYView(View): newC.setModel(self._model._curves[curveID]) newC.setMPLAxes(self._mplAxes) newC.draw() - newC.setMarker(self.getMarker(go_next=True)) + if (self._model._curves[curveID]._name == "BarModel"): + print("Appending un bar model !") + else: + newC.setMarker(self.getMarker(go_next=True)) self._curveViews[curveID] = newC def removeCurve(self, curveID): @@ -168,7 +172,7 @@ class XYView(View): def onClearAll(self): """ Just does an update with a reset of the marker cycle. """ if self.__repaintOK(): - self._lastMarkerID = -1 + if (self._model._name != "BarModel") : self._lastMarkerID = -1 self.update() def onPick(self, event): @@ -177,9 +181,17 @@ class XYView(View): if event.mouseevent.button == 1: selected_id = -1 a = event.artist + for crv_id, cv in list(self._curveViews.items()): - if cv._mplLines[0] is a: - selected_id = crv_id + if (cv._model._name == "BarModel") : + # Checks if the picked artist is in the list of Rectangles + if a in cv._mplBars: + selected_id = crv_id + print(selected_id, " barplot selected") + else: + if cv._mplLines[0] is a: + selected_id = crv_id + print(selected_id, " curve selected") # Use the plotmanager so that other plot sets get their current reset: self._controller._plotManager.setCurrentCurve(selected_id) @@ -323,10 +335,12 @@ class XYView(View): action = self._curveActionGroup.checkedAction() if action is self._pointsAction : for crv_view in list(self._curveViews.values()): - crv_view.setLineStyle("None") + if (crv_view._model._name != "BarModel") : + crv_view.setLineStyle("None") elif action is self._linesAction : for crv_view in list(self._curveViews.values()): - crv_view.setLineStyle("-") + if (crv_view._model._name != "BarModel") : + crv_view.setLineStyle("-") else : raise NotImplementedError if repaint: