Beispiel #1
0
 def closeXYView(self, salomeViewID):
     Logger.Debug("CurveTabsView::closeXYView: %d" % salomeViewID)
     self._controller.setCurvePlotRequestingClose(True)
     self._controller._sgPyQt.closeView(salomeViewID)
     self._controller.setCurvePlotRequestingClose(False)
     # Destroy the view
     self._XYViews.pop(salomeViewID)
     Logger.Debug("CurveTabsView::closeXYView count %d" %
                  len(self._XYViews))
Beispiel #2
0
    def plotCurveFromTable(self,
                           table,
                           x_col_index=0,
                           y_col_index=1,
                           curve_label="",
                           append=True):
        """
    :returns: a tuple containing the unique curve ID and the plot set ID 
    """
        # Regardless of 'append', we must create a view if none there:
        if self._plotManager.getCurrentPlotSet() is None or not append:
            ps = self._plotManager.createXYPlotSet()
            self.setModelListener(ps, self._curveBrowserView)
            # For curve picking, controller must listen:
            self.setModelListener(ps, self)
            cps_title = table.getTitle()
        else:
            cps_title = None

        cps = self._plotManager.getCurrentPlotSet()

        cm = CurveModel(self, table, y_col_index)
        cm.setXAxisIndex(x_col_index)

        # X axis label
        tix = table.getColumnTitle(x_col_index)
        if tix != "":
            cps.setXLabel(tix)

        # Curve label
        if curve_label != "":
            cm.setTitle(curve_label)
        else:
            ti = table.getColumnTitle(y_col_index)
            if ti != "":
                cm.setTitle(ti)

        # Plot set title
        if cps_title != "" and cps_title is not None:
            Logger.Debug("about to set title to: " + cps_title)
            cps.setTitle(cps_title)

        cps.addCurve(cm)
        mp = self._curveTabsView.mapModId2ViewId()
        xyview_id = mp[cps.getID()]
        xyview = self._curveTabsView._XYViews[xyview_id]

        if cps_title is None:  # no plot set was created above
            self._plotManager.setCurrentPlotSet(cps.getID())

        # Make CurveBrowser and CurveView depend on changes in the curve itself:
        self.setModelListener(cm, self._curveBrowserView)
        self.setModelListener(cm, xyview._curveViews[cm.getID()])
        # Upon change on the curve also update the full plot, notably for the auto-fit and the legend:
        self.setModelListener(cm, xyview)

        return cm.getID(), cps.getID()
Beispiel #3
0
 def OnSalomeViewTryClose(cls, salome_view_id):
     control = cls.GetInstance()
     if not control._blockViewClosing:
         Logger.Debug("PlotController::OnSalomeViewTryClose %d" %
                      salome_view_id)
         #       control._sgPyQt.setViewClosable(salome_view_id, False)
         # Get XYView from SALOME view ID
         xyview = control._curveTabsView._XYViews.get(salome_view_id, None)
         if not xyview is None:
             plotSetID = xyview.getModel().getID()
             Logger.Debug(
                 "PlotController::OnSalomeViewTryClose internal CurvePlot view ID is %d"
                 % plotSetID)
             control._plotManager.removeXYPlotSet(plotSetID)
         else:
             Logger.Warning(
                 "Internal error - could not match SALOME view ID %d with CurvePlot view!"
                 % salome_view_id)
Beispiel #4
0
 def removeXYPlotSet(self, plotSetID):
     Logger.Debug("====> PlotManager::removeXYPlotSet() %d" % plotSetID)
     if not self._plotSets.has_key(plotSetID):
         print self._plotSets
         raise ValueError("Plot set ID (%d) not found for deletion!" %
                          plotSetID)
     ps = self._plotSets.pop(plotSetID)
     if self._currentPlotSet is ps:
         self._currentPlotSet = None
     self.notifyChange("RemovePlotSet")
     return ps
Beispiel #5
0
 def update(self):
     Logger.Debug("CurveView::udpate")
     if self._mplLines is None:
         return
     lineStyle, marker, color = self.getLineStyle(), self.getMarker(
     ), self.getColor()
     self.erase()
     self.draw()
     # Reset correctly color, marker and highlight state
     self.setLineStyle(lineStyle)
     self.setMarker(marker)
     self.setColor(color)
     self.toggleHighlight(self._isHighlighted, force=True)
Beispiel #6
0
    def update(self):
        if self._salomeViewID is None:
            self.createPlotWidget()
            self._salomeViewID = self._sgPyQt.createView(
                "CurvePlot", self._plotWidget)
            Logger.Debug("Creating SALOME view ID=%d" % self._salomeViewID)
            self._sgPyQt.setViewVisible(self._salomeViewID, True)

        self.updateViewTitle()

        # Check list of curve views:
        set_mod = set(self._model._curves.keys())
        set_view = set(self._curveViews.keys())

        # Deleted/Added curves:
        dels = set_view - set_mod
        added = set_mod - set_view

        for d in dels:
            self.removeCurve(d)

        if not len(self._curveViews):
            # Reset color cycle
            self._mplAxes.set_color_cycle(None)

        for a in added:
            self.appendCurve(a)

        # Axes labels and title
        self._mplAxes.set_xlabel(self._model._xlabel)
        self._mplAxes.set_ylabel(self._model._ylabel)
        self._mplAxes.set_title(self._model._title)

        self.onViewHorizontalMode(repaint=False)
        self.onViewVerticalMode(repaint=False)
        self.changeModeCurve(repaint=False)
        self.showHideLegend(
            repaint=False
        )  # The canvas is repainted anyway (needed to get legend bounding box)
        self.changeFormatAxis()

        # Redo auto-fit
        self.autoFit(repaint=False)
        self.repaint()
Beispiel #7
0
    def DeleteCurve(cls, curve_id=-1):
        """ By default, delete the current curve, if any. Otherwise do nothing.
        @return the id of the deleted curve or -1
    """
        Logger.Debug("Delete curve")
        control = cls.GetInstance()
        # Find the right plot set:
        if curve_id == -1:
            curve_id = cls.GetCurrentCurveID()
            if curve_id == -1:
                # No current curve, do nothing
                return -1

        psID = cls.GetPlotSetID(curve_id)
        if psID == -1:
            raise ValueError("Curve ID (%d) not found for deletion!" %
                             curve_id)
        crv = control._plotManager._plotSets[psID]._curves[curve_id]
        control._plotManager._plotSets[psID].removeCurve(curve_id)
        control.removeModelListeners(crv)
        return curve_id
Beispiel #8
0
    def DeletePlotSet(cls, plot_set_id=-1):
        """ By default, delete the current plot set, if any. Otherwise do nothing.
        This will automatically make the last added plot set the current one.
        @return the id of the deleted plot set or -1
    """
        Logger.Debug("PlotController::DeletePlotSet %d" % plot_set_id)
        control = cls.GetInstance()
        # Find the right plot set:
        if plot_set_id == -1:
            plot_set_id = cls.GetCurrentPlotSetID()
            if plot_set_id == -1:
                # No current, do nothing
                return -1

        ps = control._plotManager.removeXYPlotSet(plot_set_id)
        for _, crv in ps._curves.items():
            control.removeModelListeners(crv)
        control.removeModelListeners(ps)
        psets = control._plotManager._plotSets
        if len(psets):
            control._plotManager.setCurrentPlotSet(psets.keys()[-1])
        return plot_set_id
Beispiel #9
0
 def onItemDoubleCliked(self):
     Logger.Debug("item doubled clicked")
Beispiel #10
0
 def repaint(self):
     if self.__repaintOK():
         Logger.Debug("XYView::draw")
         self._mplCanvas.draw()