Example #1
0
    def __init__(self, guiparent, data, tmp_maps):
        self.history = History()
        self.guiparent = guiparent

        self.tmp_maps = tmp_maps

        # variable, which appends  unique number to every name of map, which is saved into history
        self.histTmpVectMapNum = 0

        self.data = data
Example #2
0
class VNETHistory():
    def __init__(self, guiparent, data, tmp_maps):
        self.history = History()
        self.guiparent = guiparent

        self.tmp_maps = tmp_maps

        # variable, which appends  unique number to every name of map, which is
        # saved into history
        self.histTmpVectMapNum = 0

        self.data = data

    def Undo(self):
        """Step back in history"""
        histStepData = self.history.GetPrev()

        if histStepData:
            return self._updateHistStepData(histStepData)

        return None

    def Redo(self):
        """Step forward in history"""
        histStepData = self.history.GetNext()

        if histStepData:
            return self._updateHistStepData(histStepData)

        return None

    def GetHistStep(self):
        return self.history.GetCurrHistStep(), self.history.GetStepsNum()

    def SaveHistStep(self):
        """Save new step into history"""
        removedHistData = self.history.SaveHistStep()

        if not removedHistData:
            return

        # delete temporary maps in history steps which were deleted
        for removedStep in six.itervalues(removedHistData):
            mapsNames = removedStep["tmp_data"]["maps"]
            for vectMapName in mapsNames:
                tmpMap = self.tmp_maps.GetTmpVectMap(vectMapName)
                self.tmp_maps.DeleteTmpMap(tmpMap)

    def DeleteNewHistStepData(self):
        # history - delete data in buffer for hist step
        self.history.DeleteNewHistStepData()
        # empty list for maps to be saved to history
        self.tmpVectMapsToHist = []

    def _updateHistStepData(self, histStepData):
        """Updates dialog according to chosen history step"""
        # set analysis module
        analysis = histStepData["vnet_modules"]["curr_module"]
        self.data.SetParams({"analysis": analysis}, {})

        pts = []
        # add points to list
        for iPt in range(len(histStepData["points"])):
            ptDataHist = histStepData["points"]["pt" + str(iPt)]

            e, n = ptDataHist["coords"]
            pt_data = {"e": e, "n": n}

            pt_data['type'] = int(ptDataHist["catIdx"])

            pt_data['topology'] = ptDataHist["topology"]

            pt_data['use'] = ptDataHist["checked"]

            pts.append(pt_data)

        self.data.GetPointsData().SetPoints(pts)

        # update analysis result maps
        mapsNames = histStepData["tmp_data"]["maps"]
        for m in mapsNames:
            if "vnet_tmp_result" in m:
                resultMapName = m
                break

        # update parameters
        params = {}
        histInputData = histStepData["an_params"]
        for inpName, inp in six.iteritems(histInputData):
            params[inpName] = str(inp)
            if inpName == "input":
                inpMap = inp

        prevInpModTime = str(histStepData["other"]["input_modified"])
        currInpModTime = VectMap(None, inpMap).GetLastModified()

        if currInpModTime.strip() != prevInpModTime.strip():
            dlg = wx.MessageDialog(
                parent=self.guiparent,
                message=_("Input map '%s' for analysis was changed outside " +
                          "vector network analysis tool.\n" +
                          "Topology column may not " +
                          "correspond to changed situation.") % inpMap,
                caption=_("Input changed outside"),
                style=wx.ICON_INFORMATION | wx.CENTRE)
            dlg.ShowModal()
            dlg.Destroy()

        # TODO
        flags = {}
        return analysis, resultMapName, params, flags

    def _saveAnInputToHist(self, analysis, params, flags):
        """Save all data needed for analysis into history buffer"""
        pts_num = self.data.GetPointsData().GetPointsCount()

        for pt_id in range(pts_num):
            data = self.data.GetPointsData().GetPointData(pt_id)

            ptName = "pt" + str(pt_id)

            coords = [data["e"], data["n"]]
            self.history.Add(key="points",
                             subkey=[ptName, "coords"],
                             value=coords)

            self.history.Add(key="points",
                             subkey=[ptName, "catIdx"],
                             value=data['type'])

            self.history.Add(key="points",
                             subkey=[ptName, "topology"],
                             value=data['topology'])

            self.history.Add(key="points",
                             subkey=[ptName, "checked"],
                             value=data["use"])

            for param, value in six.iteritems(params):

                if param == "input":
                    inpMap = VectMap(self, value)
                    self.history.Add(key="other",
                                     subkey="input_modified",
                                     value=inpMap.GetLastModified())
                    param_val = value
                else:
                    param_val = value

                self.history.Add(key="an_params",
                                 subkey=param,
                                 value=param_val)

        self.history.Add(key="vnet_modules",
                         subkey="curr_module",
                         value=analysis)

    def NewTmpVectMapToHist(self, prefMapName):
        """Add new vector map, which will be saved into history step"""

        mapName = prefMapName + str(self.histTmpVectMapNum)
        self.histTmpVectMapNum += 1

        tmpMap = AddTmpMapAnalysisMsg(mapName, self.tmp_maps)
        if not tmpMap:
            return tmpMap

        self.tmpVectMapsToHist.append(tmpMap.GetVectMapName())
        self.history.Add(key="tmp_data",
                         subkey="maps",
                         value=self.tmpVectMapsToHist)

        return tmpMap