Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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 histInputData.iteritems():
            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
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def ComputeNodes(self, activate):
        """Start/stop snapping mode"""

        if not haveCtypes:
            GMessage(parent=self,
                     message=_("Unable to use ctypes. \n") +
                     _("Snapping mode can not be activated."))
            return -1

        if not activate:

            if self.tmp_maps.HasTmpVectMap("vnet_snap_points"):
                self.snapPts.DeleteRenderLayer()

                self.giface.updateMap.emit(render=False, renderVector=False)

            if 'cmdThread' in self.snapData:
                self.snapData['cmdThread'].abort()

            self.data.SetSnapping(False)

            self.snapping.emit(evt="deactivated")

            return -1

        self.data.SetSnapping(activate)

        params, inv_params, flags = self.data.GetParams()
        if not self.data.InputsErrorMsgs(
                msg=_("Snapping mode can not be activated."),
                analysis=None,
                params=params,
                inv_params=inv_params,
                flags=flags,
                relevant_params=["input", "node_layer"]):
            return -1

        if not self.tmp_maps.HasTmpVectMap("vnet_snap_points"):
            endStr = _(
                "Do you really want to activate snapping and overwrite it?")
            self.snapPts = self.tmp_maps.AddTmpVectMap("vnet_snap_points",
                                                       endStr)

            if not self.snapPts:
                return -1

        elif self.snapPts.VectMapState() == 0:
            dlg = wx.MessageDialog(
                message=_("Temporary map '%s' was changed outside " +
                          "vector analysis tool.\n"
                          "Do you really want to activate " +
                          "snapping and overwrite it? ") %
                self.snapPts.GetVectMapName(),
                caption=_("Overwrite map"),
                style=wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION | wx.CENTRE)

            ret = dlg.ShowModal()
            dlg.Destroy()

            if ret == wx.ID_NO:
                self.tmp_maps.DeleteTmpMap(self.snapPts)
                return -1

        self.data.SetSnapping(True)

        inpFullName = params["input"]
        inpName, mapSet = inpFullName.split("@")
        computeNodes = True

        if "inputMap" not in self.snapData:
            pass
        elif inpFullName != self.snapData["inputMap"].GetVectMapName():
            self.snapData["inputMap"] = VectMap(None, inpFullName)
        elif self.snapData["inputMap"].VectMapState() == 1:
            computeNodes = False

        # new map needed
        if computeNodes:
            if 'cmdThread' not in self.snapData:
                self.snapData['cmdThread'] = CmdThread(self)
            else:
                self.snapData['cmdThread'].abort()

            cmd = [
                "v.to.points", "input=" + params['input'],
                "output=" + self.snapPts.GetVectMapName(), "use=node",
                "--overwrite"
            ]
            # process GRASS command with argument
            self.snapData["inputMap"] = VectMap(None, inpFullName)
            self.snapData["inputMap"].SaveVectMapState()

            self.Bind(EVT_CMD_DONE, self._onNodesDone)
            self.snapData['cmdThread'].RunCmd(cmd)

            self.snapping.emit(evt="computing_points")

            return 0
        # map is already created and up to date for input data
        else:
            self.snapPts.AddRenderLayer()

            self.giface.updateMap.emit(render=True, renderVector=True)

            self.snapping.emit(evt="computing_points_done")

            return 1