Skip to content

Commit

Permalink
Certificado castastral Villa Florida
Browse files Browse the repository at this point in the history
  • Loading branch information
fdiaz authored and fdiaz committed May 31, 2022
1 parent d216bb6 commit a8ec32a
Show file tree
Hide file tree
Showing 10 changed files with 507 additions and 128 deletions.
58 changes: 49 additions & 9 deletions actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from gvsig import currentLayer

from java.io import File

from org.gvsig.fmap.mapcontext.layers.vectorial import FLyrVect
from org.gvsig.app import ApplicationLocator
from org.gvsig.andami import PluginsLocator
from org.gvsig.scripting.app.extension import ScriptingExtension
Expand All @@ -20,6 +20,27 @@

class CertificadoCatastralVillaFloridaExtension(ScriptingExtension):
def __init__(self):
self.attrNames = [
'CODIGO',
'MAPA',
'CUADRANTE',
'MANZANA',
'N_LOTE',
'PROPIETARI',
'TENENCIA',
'AREA_DE_TE',
#'FRENTE_s_m',
'TIPO_DE_CA',
'USO_DE_SUE',
'MEJORAS_DE',
'USO_CONSTR',
#'CATEGORIAS',
#'AREA_CONST',
#'OBSERVECIO',
'BARRIO',
'UBICACION'#,
#'IMAGEN'
]
pass

def canQueryByAction(self):
Expand All @@ -31,20 +52,39 @@ def isVisible(self, action):
return False

def isLayerValid(self, layer):
if not isinstance(layer, FLyrVect):
return False
store = layer.getFeatureStore()
featureType = store.getDefaultFeatureTypeQuietly()
for attrName in self.attrNames:
if featureType.get(attrName) == None:
return False
return True

def isEnabled(self, action):
#if not self.isLayerValid(layer):
# return False
if currentView()!=None:
return True
return False
view = currentView()
if view==None:
return False
mapContext = view.getMapContext()
activeLayers = mapContext.getLayers().getActives()
if len(activeLayers) != 1:
return False
layer = activeLayers[0]
if not self.isLayerValid(layer):
return False
store = layer.getFeatureStore()
selection = store.getSelection()
if selection.getSelectedCount() != 1:
return False
return True

def execute(self,actionCommand, *args):
actionCommand = actionCommand.lower()
if actionCommand == "settool-CertificadoCatastralVillaFlorida":
certificadoCatastralVillaFlorida = CertificadoCatastralVillaFloridaPanel()
print actionCommand
if actionCommand == "settool-certificadocatastralvillaflorida":
certificadoCatastralVillaFlorida = CertificadoCatastralVillaFloridaPanel(currentLayer())
i18n = ToolsLocator.getI18nManager()
print "showTool"
certificadoCatastralVillaFlorida.showTool(i18n.getTranslation("_Certificado_Catastral_Villa_Florida"))

def selfRegisterI18n():
Expand All @@ -58,7 +98,7 @@ def selfRegister():
actionManager = PluginsLocator.getActionInfoManager()
iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent()

icon = File(gvsig.getResource(__file__,"images","CertificadoCatastral.png")).toURI().toURL()
icon = File(gvsig.getResource(__file__,"images","CertificadoCatastral_16x16.png")).toURI().toURL()
iconTheme.registerDefault("scripting.CertificadoCatastralVillaFlorida", "action", "tools-CertificadoCatastralVillaFlorida", None, icon)

CertificadoCatastralVillaFlorida_extension = CertificadoCatastralVillaFloridaExtension()
Expand Down
133 changes: 102 additions & 31 deletions certificadoCatastralVillaFloridaPanel.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,117 @@
# encoding: utf-8

import gvsig
import os

from gvsig.uselib import use_plugin
use_plugin("org.gvsig.app.document.layout2.app.mainplugin")

from org.gvsig.tools import ToolsLocator
from org.gvsig.pdf.swing.api import PDFSwingLocator, PDFViewer
from org.gvsig.pdf.lib.api import PDFLocator
from org.gvsig.tools.swing.api import ToolsSwingLocator
from org.gvsig.tools.swing.api.windowmanager import WindowManager
from java.io import File, FileInputStream
from gvsig.libs.formpanel import FormPanel, FormComponent
from gvsig import currentLayer
from org.gvsig.app.project.documents.layout.gui import DefaultLayoutPanel




class CertificadoCatastralVillaFloridaPanel(FormPanel):
def __init__(self):
FormPanel.__init__(self,getResource(__file__,"certificadoCatastralVillaFloridaPanel.xml"))
def __init__(self, layer):
FormPanel.__init__(self, gvsig.getResource(__file__,"certificadoCatastralVillaFloridaPanel.xml"))
i18n = ToolsLocator.getI18nManager()
self.setPreferredSize(320,180)
swingManager = ToolsSwingLocator.getToolsSwingManager()
self.setPreferredSize(480,180)
self.layer = layer

self.pickerFolder = swingManager.createFolderPickerController(
self.txtImagesFolder,
self.btnImagesFolder)

def btnGenerarPdf_click(self, event):
swingManager.translate(self.lblApplicant)
swingManager.translate(self.lblImagesFolder)
swingManager.translate(self.btnGenerateCertificate)


def btnGenerateCertificate_click(self, event):
layout = self.loadTemplate()
context = layout.getLayoutContext()
feature = None #Coger la feature seleccionada de la vista
# Nos recorremos todos los elementos del mapa buscando los que hemos etiquetado
for elemento in context.getAllFFrames():
if elemento.getTag() == "Vista":
# Ajustamos el encuadre de la vista al del elemento seleccionado
mapContext = elemento.getMapContext()
mapContext.getViewPort().setEnvelope(encuadre)
mapContext.invalidate()

elif elemento.getTag() == "Solicitante":
elemento.clearText()
elemento.addText(self.txtSolicitante.getText())

elif elemento.getTag() == "atributo":
name = elemento.getText().get(0)
elemento.clearText()
elemento.addText(feature.getString(name))

elif elemento.getTag() == "Imagen1":# esto por cada imagen
# Cambiamos la imagen del logotipo
elemento.setImage(self.getImage(1))

store = self.layer.getFeatureStore()
selection = store.getSelection()
if selection.getSelectedCount() != 1:
return

images = self.getImages()
for feature in selection:
#feature = None #Coger la feature seleccionada de la vista
geometry = feature.getDefaultGeometry()
encuadre = geometry.buffer(2).getEnvelope()
# Nos recorremos todos los elementos del mapa buscando los que hemos etiquetado
for elemento in context.getAllFFrames():
if elemento.getTag() == "VISTA":
# Ajustamos el encuadre de la vista al del elemento seleccionado
mapContext = elemento.getMapContext()
mapContext.getViewPort().setEnvelope(encuadre)
mapContext.invalidate()

elif elemento.getTag() == "SOLICITANTE":
elemento.clearText()
elemento.addText(self.txtSolicitante.getText())

elif elemento.getTag() == "ATRIBUTO":
name = elemento.getText().get(0)
elemento.clearText()
elemento.addText(feature.getString(name))

elif elemento.getTag() == "IMAGEN0" and len(images) > 0:
elemento.setImage(images[0])

elif elemento.getTag() == "IMAGEN1" and len(images) > 1:
elemento.setImage(images[1])

elif elemento.getTag() == "IMAGEN2" and len(images) > 2:
elemento.setImage(images[2])
break
context.fullRefresh()
layout.getLayoutControl().getLayoutDraw().initialize()

tmpFile = ToolsLocator.getFoldersManager().getUniqueTemporaryFile("informe.pdf")

layout.layoutToPDF(tmpFile);

def getImage(self, idx):
#TODO
return None
pdfDoc = PDFLocator.getPDFManager().createPDFDocument(tmpFile)
pdfViewer = PDFSwingLocator.getPDFSwingManager().createPDFViewer()
pdfViewer.setMode(PDFViewer.MODE_COMPLETE)
pdfViewer.put(pdfDoc)

i18n = ToolsLocator.getI18nManager()
ToolsSwingLocator.getWindowManager().showWindow(
pdfViewer.asJComponent(),
i18n.getTranslation("_Report"),
WindowManager.MODE.WINDOW
)

def getImages(self):
toolsSwingManager = ToolsSwingLocator.getToolsSwingManager()
folder=self.pickerFolder.get()
if folder == None:
return list()
basePath = folder.getAbsolutePath()
imagesPath = os.listdir(basePath)
images = list()
for n in range(0,3):
if len(imagesPath) <= n:
images.append(None)
continue
image = toolsSwingManager.createSimpleImage(basePath+os.sep+imagesPath[n])
images.append(image.getBufferedImage())
return images

def loadTemplate(self):
xmlFile = File(self,getResource(__file__,"plantilla.gvslt"))
xmlFile = File(gvsig.getResource(__file__,"plantilla.gvslt"))
inputStream = FileInputStream(xmlFile)

persistenceManager = ToolsLocator.getPersistenceManager()
Expand All @@ -54,7 +122,10 @@ def loadTemplate(self):

def main(*args):

#Remove this lines and add here your code
i18n = ToolsLocator.getI18nManager()
swingManager = ToolsSwingLocator.getToolsSwingManager()
f = CertificadoCatastralVillaFloridaPanel(currentLayer())
f.showWindow(i18n.getTranslation("_Certificado_Catastral_Villa_Florida"))

print "hola mundo"
pass
Loading

0 comments on commit a8ec32a

Please sign in to comment.