示例#1
0
 def _attributes(self, layer, site, name):
     attributes = {}
     attributes[layer.fieldNameIndex('site')] = site
     attributes[layer.fieldNameIndex('id')] = name
     attributes[layer.fieldNameIndex('created')] = utils.timestamp()
     attributes[layer.fieldNameIndex('creator')] = 'ARK Grid Tool'
     return attributes
示例#2
0
 def _logItemAction(self, item, action, timestamp=None):
     if self.collection('plan').settings.log:
         if not timestamp:
             timestamp = utils.timestamp()
         fd = open(self._itemLogPath, 'a')
         fd.write(utils.doublequote(timestamp) + ',' + utils.doublequote(action) + ',' + item.toCsv() + '\n')
         fd.close()
示例#3
0
    def configure(self):
        wizard = ProjectWizard(self._plugin.iface.mainWindow())

        ok = wizard.exec_()

        if ok:

            if wizard.newProject():
                if Project.exists():
                    Project.write()
                Project.clear()
                projectFolderPath = os.path.join(wizard.projectFolder(), 'project')
                if not QDir(projectFolderPath).mkpath('.'):
                    return False
                projectFilePath = os.path.join(projectFolderPath, wizard.projectFilename() + '.qgs')
                Project.setFileName(projectFilePath)

            Settings.setProjectCode(wizard.project().projectCode())
            Settings.setProjectName(wizard.project().projectName())
            Settings.setSiteCode(wizard.project().siteCode())
            if not Project.title():
                Project.setTitle(wizard.project().projectCode() + ' - ' + wizard.project().projectName())

            self._initialised = Project.write()
            if self._initialised:

                # We always want the site collection
                self._addCollection('site')
                self.collection('site').loadCollection()
                # Add the Site Location if entered
                location = wizard.projectLocation()
                if not location.isEmpty():
                    siteCode = wizard.project().siteCode() if wizard.project().siteCode() else wizard.project().projectCode()
                    item = Item(siteCode, 'site', siteCode)
                    source = Source('other', item)
                    audit = Audit(Settings.userFullName(), utils.timestamp())
                    itemFeature = ItemFeature(item, 'loc', None, source, 'New Project Wizard', audit)
                    layer = self.collection('site').layer('points')
                    feature = QgsFeature(layer.pendingFields(), 0)
                    feature.setGeometry(QgsGeometry(location))
                    attributes = itemFeature.toFeature(feature)
                    layers.addFeatures([feature], layer)

                # Temp load of other collection, later do on demand
                self._addCollection('plan')
                self.collection('plan').loadCollection()
                self._addCollection('section')
                self.collection('section').loadCollection()
                self._addCollection('grid')
                self.collection('grid').loadCollection()

                # self._configureDrawing('context')
                # self._configureDrawing('plan')
                # self._configureDrawing('section')

                Settings.setProjectConfigured()

        return ok
示例#4
0
 def _deleteSectionSchematic(self):
     item = self._dock.contextItem()
     label = 'This action ***DELETES*** ***ALL*** Section Schematics from item ' + \
         str(item.itemId()) + '\n\nPlease enter the item ID to confirm.'
     if self._confirmDelete(item.itemId(), 'Confirm Delete Section Schematic', label):
         request = self._categoryRequest(item, 'scs')
         timestamp = utils.timestamp()
         action = 'Delete Section Schematic'
         if self.collection().deleteFeatureRequest(request, action, timestamp):
             self._logItemAction(item, action, timestamp)
         self._findContext(item)
示例#5
0
    def _mergeBuffers(self, collection):
        # Check the layers are writable
        name = collection.settings.collectionGroupName
        if not collection.isWritable():
            self._plugin.showCriticalMessage(
                name + ' layers are not writable! Please correct the permissions and log out.', 0)
            return

        # Check the buffers contain valid data
        errors = self._preMergeBufferCheck(collection.buffer('points'))
        errors.extend(self._preMergeBufferCheck(collection.buffer('lines')))
        errors.extend(self._preMergeBufferCheck(collection.buffer('polygons')))
        if len(errors) > 0:
            dialog = ItemFeatureErrorDialog()
            dialog.loadErrors(errors)
            dialog.exec_()
            if not dialog.ignoreErrors():
                return

        # Update the audit attributes
        timestamp = utils.timestamp()
        user = Settings.userFullName()
        self._preMergeBufferUpdate(collection.buffer('points'), timestamp, user)
        self._preMergeBufferUpdate(collection.buffer('lines'), timestamp, user)
        self._preMergeBufferUpdate(collection.buffer('polygons'), timestamp, user)

        # Finally actually merge the data
        if collection.mergeBuffers('Merge data', timestamp):
            self._plugin.showInfoMessage(name + ' data successfully merged.')
            # TODO pass current Item...
            self._logItemAction(Item(), 'Merge Buffers', timestamp)
            # TODO Signal out layers merged for schematic dock to catch
            # if self._editSchematic:
            #     self._editSchematic = False
            #     self._dock.activateSchematicCheck()
            #     self._findContext()
        else:
            self._plugin.showCriticalMessage(
                name + ' data merge failed! Some data has not been saved, please check your data.', 5)
示例#6
0
 def deleteItem(self, item, logMessage='Delete Item', timestamp=None):
     return self.deleteFeatureRequest(item.featureRequest(), logMessage, timestamp or utils.timestamp())
示例#7
0
 def copyItemToBuffers(self, item, logMessage='Copy Item to Buffers', timestamp=None):
     return self.copyFeatureRequestToBuffers(item.featureRequest(), logMessage, timestamp or utils.timestamp())
示例#8
0
 def moveItemToBuffers(self, item, logMessage='Move Item to Buffers', timestamp=None):
     return self.moveFeatureRequestToBuffers(item.featureRequest(), logMessage, timestamp or utils.timestamp())
示例#9
0
 def deleteItem(self, item):
     if self._confirmDelete(item.itemId(), 'Confirm Delete Item'):
         timestamp = utils.timestamp()
         if self.collection('plan').deleteItem(item, 'Delete Item', timestamp):
             self._logItemAction(item, 'Delete Item', timestamp)
示例#10
0
 def editInBuffers(self, item):
     timestamp = utils.timestamp()
     if self.collection('plan').moveItemToBuffers(item, 'Edit Item', timestamp):
         self._logItemAction(item, 'Edit Item', timestamp)
         self._metadataFromBuffers(item)