Projet

Général

Profil

Anomalie #56 » importexport.py

Christophe MASSE, 07/11/2014 10:10

 
1
# -*- coding:utf-8 -*-
2

    
3
import ConfigParser
4
#import codecs
5
import os.path
6
from qsphere_tools import *
7

    
8
from PyQt4 import QtCore, QtGui
9
from PyQt4 import QtCore, QtGui
10
from PyQt4.QtCore import * 
11
from PyQt4.QtGui import * 
12
from qgis.core import *
13
from qgis.gui import *
14

    
15
import urllib
16

    
17
   
18
#==================================================
19
# FUNCTIONS TO LOAD (IMPORT) AND SAVE / EXPORT QSP
20
#==================================================
21
def SaveQSP(self, zFile):
22
    zIndex = self.tabWidget.currentIndex()
23
    zLOG = open(zFile, "w")
24
    Config = ConfigParser.ConfigParser()
25
    
26
    zTabs = self.tabWidget.count()
27
    zObj = None
28
    for i in range(zTabs):
29
        self.tabWidget.setCurrentIndex(i)
30
        zTab = self.tabWidget.currentWidget()
31
        zObjs = zTab.children()
32
        for j in range(len(zObjs)):
33
            zNameObj = "%s" % (zObjs[j].accessibleName())
34
            if zNameObj != "" and (not zObjs[j].metaObject().className()=="QLabel") and zNameObj.find("help_")==-1 and zNameObj.find("Ajouter_")==-1 and zNameObj.find("Effacer_")==-1 :
35
               Config.add_section(zNameObj)
36
               zClassObjName = "%s" % (zObjs[j].metaObject().className())
37
               Config.set(zNameObj,'Type',zClassObjName)
38
               if zClassObjName=="QCalendarWidget" : Config.set(zNameObj,'Date',ReturnDate(self, zObjs[j]))
39
               elif zClassObjName=="QTextEdit" : Config.set(zNameObj,'Text',zObjs[j].toPlainText())
40
               elif zClassObjName in ("QLineEdit", "MySimpleWidgetLineEdit", "MyWidgetLineEdit") : Config.set(zNameObj,'Text',zObjs[j].text())
41
               elif zClassObjName=="QComboBox" :
42
                   Config.set(zNameObj,'ItemCount',zObjs[j].model().rowCount())
43
                   for k in range(zObjs[j].model().rowCount()): Config.set(zNameObj,'Item_%s' % (k),zObjs[j].itemText(k))
44
                   Config.set(zNameObj,'Index',zObjs[j].currentIndex())
45
               elif zClassObjName=="QGroupBox" :
46
                    zChildren = zObjs[j].children()
47
                    for i in range(len(zChildren)):
48
                        zChild = zChildren[i]
49
                        zChildClassName = "%s" % (zChild.metaObject().className())
50
                        if zChildClassName == "QRadioButton" and zChild.isChecked(): Config.set(zNameObj, "radio","%s" % (i))
51
                        elif zChildClassName == "QComboBox" : Config.set(zNameObj,'Index',zChild.currentIndex())
52
                        elif zChildClassName == "QTableWidget":
53
                             Config.set(zNameObj,'subtype',zChildClassName)
54
                             Config.set(zNameObj,'zRows',zChild.rowCount())
55
                             Config.set(zNameObj,'zCols',zChild.columnCount())
56
                             for k in range(zChild.rowCount()):
57
                                  zWidget = zChild.cellWidget(k, 0)
58
                                  Config.set(zNameObj,'zRow_%s' % (k),zWidget.value())
59
                        elif zChildClassName == "QTableView":
60
                             Config.set(zNameObj,'subtype',zChildClassName)
61
                             zItems = ""
62
                             Config.set(zNameObj,'ItemCount',zChild.model().rowCount())
63
                             for k in range(zChild.model().rowCount()):
64
                                 zValues = ""
65
                                 for l in range(zChild.model().columnCount()): zValues+= "%s" % (zChild.model().item(k, l).text()) if zValues == "" else "|%s" % (zChild.model().item(k, l).text())
66
                                 Config.set(zNameObj,'Item_%s' % (k),zValues)
67
                                 zItem = zChild.model().item(k, 0)
68
                                 if zItem.checkState()== Qt.Checked: zItems+= "%s" % (k) if zItems=="" else "|%s" % (k)  
69
                             Config.set(zNameObj,'Indexes',zItems)                                      
70
                   
71
               elif zClassObjName=="QTableView" :
72
                   zItems = ""
73
                   Config.set(zNameObj,'ItemCount',zObjs[j].model().rowCount())
74
                   for k in range(zObjs[j].model().rowCount()):
75
                       zValues = ""
76
                       for l in range(zObjs[j].model().columnCount()): zValues+= zObjs[j].model().item(k, l).text() if zValues == "" else "|"+zObjs[j].model().item(k, l).text()
77
                       Config.set(zNameObj,'Item_%s' % (k),zValues)
78
                       zItem = zObjs[j].model().item(k, 0)
79
                       if zItem.checkState()== Qt.Checked: zItems+= "%s" % (k) if zItems=="" else "|%s" % (k)  
80
                   Config.set(zNameObj,'Indexes',zItems)
81

    
82
               elif zClassObjName=="QTableWidget" :
83
                  Config.set(zNameObj,'zRows',zObjs[j].rowCount())
84
                  Config.set(zNameObj,'zCols',zObjs[j].columnCount())
85
                  for z in range(zObjs[j].columnCount()):
86
                      zObj = zObjs[j].cellWidget(0, z)
87
                      if zObj != None :
88
                          zClassWidgetName = zObjs[j].cellWidget(0, z).metaObject().className()
89
                          Config.set(zNameObj,'zWidget_%s' % (z), zClassWidgetName+"|"+zObjs[j].cellWidget(0, z).accessibleDescription())
90
                      else: Config.set(zNameObj,'zWidget_%s' % (z), "standard")   
91

    
92
                  for k in range(zObjs[j].rowCount()):
93
                      zLine = ""
94
                      for z in range(zObjs[j].columnCount()):
95
                          zObj = zObjs[j].cellWidget(0, z)
96
                          if zObj != None :
97
                              zWidget = zObjs[j].cellWidget(k, z)
98
                              if zObjs[j].cellWidget(0, z).metaObject().className()=="QComboBox" :
99
                                  if zWidget.isEditable() : zLine+= "%s" % (returnText(zWidget.currentText())) if zLine == "" else "|%s" % (returnText(zWidget.currentText()))  
100
                                  else : zLine+= "%s" % (zWidget.currentIndex()) if zLine == "" else "|%s" % (zWidget.currentIndex())
101
                              elif zObjs[j].cellWidget(0, z).metaObject().className()=="QCheckBox" : zLine+= "%s" % (zWidget.checkState()) if zLine == "" else "|%s" % (zWidget.checkState())
102
                              elif zObjs[j].cellWidget(0, z).metaObject().className()=="MySpinBox" : zLine+= "%s" % (zWidget.value()) if zLine == "" else "|%s" % (zWidget.value())
103
                              elif zObjs[j].cellWidget(0, z).metaObject().className() in ("QPushButton", "MyButton") : zLine+= "action" if zLine == "" else "|action"
104
                              else : zLine+= "%s" % (returnText(zWidget.text())) if z==0 else "|%s" % (returnText(zWidget.text()))
105
                          else:
106
                              zCell = zObjs[j].item(k, z)
107
                              if zCell != None : zLine+= "%s" % (zObjs[j].item(k, z).text()) if zLine == "" else  "|%s" % (zObjs[j].item(k, z).text())
108
                              else : zLine+= "" if (zLine == "" and z == 0) else  "|"  
109
                      Config.set(zNameObj,'zRow_%s' % (k),zLine)
110

    
111
    #Config.write(codecs.open(zFile,'wb+','utf-8'))
112
    Config.write(zLOG)
113
    CloseLOG(zLOG)
114
    self.setWindowTitle("%s%s" % (self.racWindowTitle,zFile))
115
    self.listeOnglets.setCurrentIndex(zIndex)
116

    
117

    
118
def returnText(zText):
119
    if zText == "" : zText = " "
120
    return zText
121

    
122
def LoadQSP(self, zFile):
123
    zFile = os.path.abspath(zFile)
124
    self.setWindowTitle("%s%s" % (self.racWindowTitle,zFile))
125
    zIndex = self.tabWidget.currentIndex()
126
    zTitle = "Information"
127
    
128
    config = ConfigParser.ConfigParser()
129
    config.read(zFile)
130
    zSections = config.sections()
131

    
132
    self.tabWidget.setVisible(False)
133
    self.progressBar.setVisible(True)
134
    zBounds = len(zSections)
135
    
136
    zMsg1 = QtGui.QApplication.translate("QSphere","Object ", None, QtGui.QApplication.UnicodeUTF8)
137
    
138
    for i in range(zBounds):
139
        zSection = zSections[i]
140
        zObj = getWidget(self, zSection)
141

    
142
        if zObj !=None :
143
            zClassObjName = "%s" % (zObj.metaObject().className())
144
            zType = config.get(zSection,'Type')
145

    
146
            if zType == zClassObjName :
147
           
148
                if zClassObjName=="QCalendarWidget" : 
149
                    zInfos = config.get(zSection,'Date')
150
                    zInfos = zInfos.rstrip()
151
                    if zInfos!="" and zInfos.find("-")!=-1:
152
                       zEltsDate = zInfos.split("-")
153
                       zObj.setSelectedDate(QDate(int(zEltsDate[0]), int(zEltsDate[1]), int(zEltsDate[2]) ))
154
                    else: zObj.showToday()
155

    
156
                elif zClassObjName=="QTextEdit" :
157
                    zInfos = config.get(zSection,'Text')
158
                    zInfos = zInfos.rstrip()
159
                    if zSection != "coherence" : zObj.setPlainText(zInfos)
160
                    else : self.UpdateCoherence(zSection, zInfos)
161

    
162
                elif zClassObjName in ("QLineEdit", "MySimpleWidgetLineEdit", "MyWidgetLineEdit") :
163
                    zInfos = config.get(zSection,'Text')
164
                    zInfos = zInfos.rstrip()
165
                    zObj.setText(zInfos)
166

    
167
                elif zClassObjName=="QComboBox" :
168
                    zInfos = config.get(zSection,'Index')
169
                    zIndexObj = int(zInfos.rstrip())
170
                    zInfosItem = config.get(zSection,'ItemCount')
171
                    zItemCount = int(zInfosItem.rstrip())
172
                    zObj.clear()
173
                    for k in range(zItemCount): zObj.addItem(config.get(zSection,'Item_%s' % (k)))
174
                    zObj.setCurrentIndex(zIndexObj)
175

    
176
                elif zClassObjName=="QTableView" : ReLOADTableView(self, config, zObj, zSection)
177
                     
178
                elif zClassObjName=="QGroupBox" :
179
                    zChildren = zObj.children()
180
                    zInfos = "%s" % (config.get(zSection, "radio"))
181
                    zIndexObj = int(zInfos.rstrip())
182
                    try : zChildren[zIndexObj].setChecked(True)
183
                    except : pass
184

    
185
                    for child in zChildren :
186
                        if child.metaObject().className()== "QTableView" : ReLOADTableView(self, config, child, zSection)
187
                        elif child.metaObject().className()== "QTableWidget" :
188
                            child.clearContents()
189
                            for j in range(child.rowCount()): child.removeRow(0)
190
                            zRows = int(config.get(zSection,'zRows'))
191
                            for j in range(zRows):
192
                                 child.insertRow(j)
193
                                 zInfos = float(config.get(zSection,'zRow_%s' % (j)))
194
                                 AddLineWidget(self, child, j,  0, 4, 0, zInfos)
195
                        elif child.metaObject().className()== "QComboBox" :
196
                            zIndexCombo = int(config.get(zSection, "Index"))
197
                            child.setCurrentIndex(zIndexCombo)
198

    
199
                elif zClassObjName=="QTableWidget" :
200
                            ReLOADTableWidget(self, config, zObj, zSection)
201
                            if zObj.accessibleName() == "tablemotsclefsf":
202
                               for i in range(zObj.rowCount()):
203
                                   zCheckBox = zObj.cellWidget(i, 1)
204
                                   for j in range(2,5):
205
                                       zItemEditLine = zObj.cellWidget(i, j)
206
                                       try : zItemEditLine.setEnabled(zCheckBox.isChecked())
207
                                       except : pass
208

    
209
            else :
210
                zMsg2 = QtGui.QApplication.translate("QSphere","'s properties not similar. Import data aborded.", None, QtGui.QApplication.UnicodeUTF8)
211
                SendMessage(self, zTitle , "%s%s%s" % (zMsg1, zSection, zMsg2), QgsMessageBar.WARNING, 5)
212
        else :
213
            zMsg2 = QtGui.QApplication.translate("QSphere"," not find in the QSphere's collection.", None, QtGui.QApplication.UnicodeUTF8)
214
            SendMessage(self, zTitle , "%s%s%s" % (zMsg1, zSection, zMsg2), QgsMessageBar.WARNING, 5)
215

    
216
        self.progressBar.setValue(int(100 * i/zBounds))
217

    
218
    self.listeOnglets.setCurrentIndex(zIndex)
219
    self.progressBar.setValue(0)
220
    self.tabWidget.setVisible(True)
221
    self.progressBar.setVisible(False)
222
    
223
#==============================
224
# FONCTION TO WRITE XML EXPORT       
225
#==============================
226
def ExportToXML(self, zFile):
227
    zIndex = self.tabWidget.currentIndex()
228
    zLOG = file(zFile, "w")
229
    
230
    if not zLOG : return
231
    
232
    MakeEnteteXML(self, zLOG)
233
    MakeFileIdentifierXML(self, zLOG, zFile)
234
    MakeFileLanguageXML(self, zLOG)
235
    MakeCharacterSetCodeXML(self, zLOG)
236
    MakeHierarchyLevelXML(self, zLOG)
237
    MakeContactXML(self, zLOG)
238
    MakeDateStampXML(self, zLOG)
239
    MakeMetadataStandardNameXML(self, zLOG)
240
    MakeMetadataStandardVersionXML(self, zLOG)
241
    MakeSpatialRepresentation(self, zLOG)    
242
    MakeReferenceSystemInfoXML(self, zLOG)
243
    MakeIdentificationInfoXML(self, zLOG)
244
    MakeDistributionInfoXML(self, zLOG)
245
    MakeDataQualityInfoXML(self, zLOG)
246
    MakeEndXML(self, zLOG)
247

    
248
    CloseLOG(zLOG)
249
    self.listeOnglets.setCurrentIndex(zIndex)
250

    
251
def ExportCatToXML(self, zFile):
252
    zIndex = self.tabWidget.currentIndex()
253
    zLOG = file(zFile, "w")
254
    
255
    if not zLOG : return
256
    
257
    MakeEnteteCatXML(self, zLOG)
258
    MakeNameCat(self, zLOG)
259
    MakeScopeCat(self, zLOG)
260
    MakeVersionCat(self, zLOG)
261
    MakeDateCat(self, zLOG)
262
    MakeProductorCat(self, zLOG)
263
    MakeFieldMapXML(self, zLOG)
264
    MakeEndCatXML(self, zLOG)
265

    
266
    CloseLOG(zLOG)
267
    self.listeOnglets.setCurrentIndex(zIndex)
268
    
269
#------------------------------------
270
# FONCTION TO WRITE BLOCX XML EXPORT       
271
#------------------------------------
272
def MakeEnteteCatXML(self, zLOG):
273
    zPath = os.path.dirname(__file__).replace("\\","/")
274
    zFileXSL = "%s/xml/XSL/transformation_%s.xsl" % (zPath, self.Lang)
275
    #zXSL = '<?xml-stylesheet type="text/xsl" href="XSL/transformation_%s.xsl"?>' % (self.Lang) if os.path.exists(zFileXSL) else ""
276
    zXSL = ""
277
    zObj = getWidget(self, "namelayer")
278
    
279
    WriteInLOG(zLOG, '<?xml version="1.0" encoding="UTF-8"?>' \
280
                     '%s' \
281
                     '<gfc:FC_FeatureCatalogue uuid="CA_%s" xmlns:gfc="http://www.isotc211.org/2005/gfc" xmlns:gmd="http://www.isotc211.org/2005/gmd"' \
282
                     ' xmlns:gco="http://www.isotc211.org/2005/gco"' \
283
                     ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' \
284
                     ' xsi:schemaLocation="http://www.isotc211.org/2005/gfc http://www.isotc211.org/2005/gfc/gfc.xsd">\n' %(zXSL, zObj.text()))
285

    
286
def MakeEndCatXML(self, zLOG):
287
     WriteInLOG(zLOG, '</gfc:FC_FeatureCatalogue>')   
288

    
289
def MakeNameCat(self, zLOG):
290
     zValue, zText = GetTextWidget(self, "namelayer", False)
291
     WriteInLOG(zLOG, '<gfc:name><gco:CharacterString>\n')
292
     WriteInLOG(zLOG, '%s - %s' % (zValue,"Catalogue d'attributs"))
293
     WriteInLOG(zLOG, '</gco:CharacterString></gfc:name>\n')
294

    
295
def MakeScopeCat(self, zLOG):
296
    zObj = getWidget(self, "namelayer")
297
    WriteInLOG(zLOG, '<gfc:scope>\n')
298
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.text()))
299
    WriteInLOG(zLOG, '</gfc:scope>\n')
300

    
301
def MakeVersionCat(self, zLOG):
302
    WriteInLOG(zLOG, '<gfc:versionNumber>\n')
303
    WriteInLOG(zLOG, '<gco:CharacterString>NC</gco:CharacterString>\n')
304
    WriteInLOG(zLOG, '</gfc:versionNumber>\n')
305

    
306
def MakeDateCat(self, zLOG):
307
    zObj = getWidget(self, "datecredata")
308
    WriteInLOG(zLOG, '<gfc:versionDate>\n')
309
    WriteInLOG(zLOG, '<gco:Date>%s</gco:Date>\n' % (ReturnDate(self, zObj)))
310
    WriteInLOG(zLOG, '</gfc:versionDate> \n')   
311

    
312
def MakeProductorCat(self, zLOG):
313
    zObj = getWidget(self, "tableroles")
314
    for i in range(zObj.rowCount()):
315
        zValue = self.DicoListOfRules[zObj.cellWidget(i, 0).currentIndex()]
316
        if zValue == "pointOfContact" : 
317
            WriteInLOG(zLOG, '<gfc:producer>\n')
318
            MakeResponsibleParty(self, zLOG, zObj, zValue, i, True)
319
            WriteInLOG(zLOG, '</gfc:producer>\n')
320
            break
321
    
322
def MakeFieldMapXML(self, zLOG):
323
    WriteInLOG(zLOG, '<gfc:featureType>\n')
324
    WriteInLOG(zLOG, '<gfc:FC_FeatureType>\n')
325
    WriteInLOG(zLOG, '<gfc:typeName><gco:LocalName>%s</gco:LocalName></gfc:typeName>\n' % (self.ComboLayers.currentText()))
326
    WriteInLOG(zLOG, '<gfc:definition><gco:CharacterString>%s</gco:CharacterString></gfc:definition>\n' % (""))
327

    
328
    zObj = getWidget(self, "tabledico")
329
    for i in range(zObj.rowCount()):
330
        WriteInLOG(zLOG, '<gfc:carrierOfCharacteristics>\n')
331
        WriteInLOG(zLOG, '<gfc:FC_FeatureAttribute>\n')
332
        WriteInLOG(zLOG, '<gfc:memberName>\n')
333
        WriteInLOG(zLOG, '<gco:LocalName>%s</gco:LocalName>\n' % (zObj.item( i, 1 ).text()))
334
        WriteInLOG(zLOG, '</gfc:memberName>\n')
335
        WriteInLOG(zLOG, '<gfc:definition><gco:CharacterString>%s</gco:CharacterString></gfc:definition>\n' % (zObj.item( i, 5 ).text()))
336
        WriteInLOG(zLOG, '<gfc:cardinality>\n')
337
        WriteInLOG(zLOG, '<gco:Multiplicity>\n')
338
        WriteInLOG(zLOG, '<gco:range>\n')
339
        WriteInLOG(zLOG, '<gco:MultiplicityRange>\n')
340
        WriteInLOG(zLOG, '<gco:lower>\n')
341
        WriteInLOG(zLOG, '<gco:Integer>1</gco:Integer>\n')
342
        WriteInLOG(zLOG, '</gco:lower>\n')
343
        WriteInLOG(zLOG, '<gco:upper>\n')
344
        WriteInLOG(zLOG, '<gco:UnlimitedInteger isInfinite="false">1</gco:UnlimitedInteger>\n')
345
        WriteInLOG(zLOG, '</gco:upper>\n')
346
        WriteInLOG(zLOG, '</gco:MultiplicityRange>\n')
347
        WriteInLOG(zLOG, '</gco:range>\n')
348
        WriteInLOG(zLOG, ' </gco:Multiplicity>\n')
349
        WriteInLOG(zLOG, '</gfc:cardinality>\n')
350
        WriteInLOG(zLOG, '<gfc:valueType>\n')
351
        WriteInLOG(zLOG, '<gco:TypeName>\n')
352
        WriteInLOG(zLOG, '<gco:aName>\n')
353
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.item( i, 2 ).text()))
354
        WriteInLOG(zLOG, '</gco:aName>\n')
355
        WriteInLOG(zLOG, '</gco:TypeName>\n')
356
        WriteInLOG(zLOG, '</gfc:valueType>\n')
357
        WriteInLOG(zLOG, '</gfc:FC_FeatureAttribute>\n')
358
        WriteInLOG(zLOG, '</gfc:carrierOfCharacteristics>\n')
359

    
360
    WriteInLOG(zLOG, '</gfc:FC_FeatureType>\n')
361
    WriteInLOG(zLOG, '</gfc:featureType>\n')
362
    
363
def MakeEnteteXML(self, zLOG):
364
    zPath = os.path.dirname(__file__).replace("\\","/")
365
    zFileXSL = "%s/xml/XSL/transformation_%s.xsl" % (zPath, self.Lang)
366
    #zXSL = '<?xml-stylesheet type="text/xsl" href="XSL/transformation_%s.xsl"?>' % (self.Lang) if os.path.exists(zFileXSL) else ""
367
    zXSL = ""
368
    
369
    WriteInLOG(zLOG, '<?xml version="1.0" encoding="UTF-8"?>' \
370
                     '%s' \
371
                     '<gmd:MD_Metadata xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20060504/gmd/gmd.xsd"' \
372
                     ' xmlns:gmd="http://www.isotc211.org/2005/gmd"' \
373
                     ' xmlns:gco="http://www.isotc211.org/2005/gco"' \
374
                     ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' \
375
                     ' xmlns:gml="http://www.opengis.net/gml"' \
376
                     ' xmlns:xlink="http://www.w3.org/1999/xlink">\n' % (zXSL))
377

    
378
def MakeFileIdentifierXML(self, zLOG, zFile):
379
    #TOTO 2.6.1
380
    #zValue = os.path.basename(zFile)
381
    zObj = getWidget(self, "identificator")
382
    WriteInLOG(zLOG, '<gmd:fileIdentifier>\n')
383
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.text())) 
384
    WriteInLOG(zLOG, '</gmd:fileIdentifier>\n')
385

    
386
def MakeFileLanguageXML(self, zLOG):
387
    zObj = getWidget(self, "langmetada")
388
    zValue = zObj.currentText()#.toPlainText()
389
    MakeBlocLangue(self, zLOG, zValue)
390

    
391
def MakeCharacterSetCodeXML(self, zLOG):
392
    zObj = getWidget(self, "tablecarac")
393
    zValue = "MD_CharacterSetCode_%s" % (zObj.currentText().lower())
394
    WriteInLOG(zLOG, '<gmd:characterSet>\n')
395
    WriteInLOG(zLOG, '<gmd:MD_CharacterSetCode codeListValue="%s" codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml#MD_CharacterSetCode">%s</gmd:MD_CharacterSetCode>\n' % (zValue, zValue))
396
    WriteInLOG(zLOG, '</gmd:characterSet>\n')
397

    
398
def MakeHierarchyLevelXML(self, zLOG):
399
    zObj = getWidget(self, "typedata")
400
    zValue = self.TypeData[zObj.currentIndex()]
401
    WriteInLOG(zLOG, '<gmd:hierarchyLevel>\n')
402
    WriteInLOG(zLOG, '<gmd:MD_ScopeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/gmxCodelists.xml#MD_ScopeCode" codeListValue="%s">%s</gmd:MD_ScopeCode>\n' % (zValue, zValue))
403
    WriteInLOG(zLOG, '</gmd:hierarchyLevel>\n')
404

    
405
def MakeContactXML(self, zLOG):
406
    zObj = getWidget(self, "tableroles")
407
    for i in range(zObj.rowCount()):
408
        zValue = self.DicoListOfRules[zObj.cellWidget(i, 0).currentIndex()]
409
        if zValue == "pointOfContact" :
410
           MakeBlocRole(self, zLOG, zObj, zValue, i, True)
411
           break
412
            
413
def MakeDateStampXML(self, zLOG):
414
    zValue, zText = GetTextWidget(self, "datemetada", False)
415
    WriteInLOG(zLOG, '<gmd:dateStamp>\n')
416
    WriteInLOG(zLOG, '<gco:Date>%s</gco:Date>\n' % (zValue))
417
    WriteInLOG(zLOG, '</gmd:dateStamp>\n')
418

    
419
def MakeMetadataStandardNameXML(self, zLOG):
420
    WriteInLOG(zLOG, '<gmd:metadataStandardName>\n')
421
    WriteInLOG(zLOG, '<gco:CharacterString>ISO19115</gco:CharacterString>\n')
422
    WriteInLOG(zLOG, '</gmd:metadataStandardName>\n')
423

    
424
def MakeMetadataStandardVersionXML(self, zLOG):
425
    WriteInLOG(zLOG, '<gmd:metadataStandardVersion>\n')
426
    WriteInLOG(zLOG, '<gco:CharacterString>2003/Cor.1:2006</gco:CharacterString>\n')
427
    WriteInLOG(zLOG, '</gmd:metadataStandardVersion>\n')
428

    
429
def MakeReferenceSystemInfoXML(self, zLOG):
430
    zObj = getWidget(self, "tablescr")
431
    for i in range(zObj.rowCount()): 
432
        zEPSG = zObj.cellWidget(i, 0).text()
433
        if zObj.rowCount() == 1 :  WriteInLOG(zLOG, '<gmd:referenceSystemInfo>\n')
434
        else : WriteInLOG(zLOG, '<gmd:referenceSystemInfo id="proj00%s">\n' % (i+1))
435
        WriteInLOG(zLOG, '<gmd:MD_ReferenceSystem>\n')
436
        WriteInLOG(zLOG, '<gmd:referenceSystemIdentifier>\n')        
437
        WriteInLOG(zLOG, '<gmd:RS_Identifier>\n')
438
        zCodeESPG = int(zEPSG.replace("EPSG:",""))
439
        WriteInLOG(zLOG, '<gmd:code>\n')
440
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zCodeESPG))
441
        WriteInLOG(zLOG, '</gmd:code>\n')
442
        WriteInLOG(zLOG, '<gmd:codeSpace>\n')
443
        WriteInLOG(zLOG, '<gco:CharacterString>urn:ogc:def:crs:EPSG:6.11</gco:CharacterString>\n')
444
        WriteInLOG(zLOG, '</gmd:codeSpace>\n')
445
        WriteInLOG(zLOG, '<gmd:version>\n')
446
        WriteInLOG(zLOG, '<gco:CharacterString>6.11</gco:CharacterString>\n')
447
        WriteInLOG(zLOG, '</gmd:version>\n')
448
        WriteInLOG(zLOG, '</gmd:RS_Identifier>\n')
449
        WriteInLOG(zLOG, '</gmd:referenceSystemIdentifier>\n')
450
        WriteInLOG(zLOG, '</gmd:MD_ReferenceSystem>\n')    
451
        WriteInLOG(zLOG, '</gmd:referenceSystemInfo>\n')
452

    
453
def MakeIdentificationInfoXML(self, zLOG):     
454
    WriteInLOG(zLOG, '<gmd:identificationInfo>\n')
455
    WriteInLOG(zLOG, '<gmd:MD_DataIdentification>\n')
456
    #CITATION BLOC
457
    WriteInLOG(zLOG, '<gmd:citation>\n')
458
    WriteInLOG(zLOG, '<gmd:CI_Citation>\n')
459
    zValue, zText = GetTextWidget(self, "intitule", False)
460
    WriteInLOG(zLOG, '<gmd:title>\n')
461
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zValue))
462
    WriteInLOG(zLOG, '</gmd:title>\n')
463
    
464
    zObj = getWidget(self, "tabledatepubdata")
465
    for i in range(zObj.rowCount()):
466
        zValue = zObj.cellWidget(i, 0).text()
467
        zTypeDate = GetDateType(2, False) 
468
        if zValue.find("--") == -1 : MakeBlocDate(self, zLOG, zValue, zTypeDate)
469
    
470
    for i in range(0, 2):
471
        zWidgetDate = GetDateType(i, True) 
472
        zTypeDate = GetDateType(i, False)
473
        zValue, zText = GetTextWidget(self, zWidgetDate, False)
474
        if zValue.find("--") == -1 : MakeBlocDate(self, zLOG, zValue, zTypeDate)
475

    
476
    """
477
    zValue, zText = GetTextWidget(self, "identificator", False)
478
    WriteInLOG(zLOG, '<gmd:identifier>\n')
479
    WriteInLOG(zLOG, '<gmd:RS_Identifier>\n')
480
    WriteInLOG(zLOG, '<gmd:code>\n')
481
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zValue))
482
    WriteInLOG(zLOG, '</gmd:code>\n')
483
    WriteInLOG(zLOG, '<gmd:codeSpace>\n')
484
    WriteInLOG(zLOG, '<gco:CharacterString>Unkwon</gco:CharacterString>\n')
485
    WriteInLOG(zLOG, '</gmd:codeSpace>\n')
486
    WriteInLOG(zLOG, '</gmd:RS_Identifier>\n')
487
    WriteInLOG(zLOG, '</gmd:identifier>\n')
488
    """
489
               
490
    WriteInLOG(zLOG, '</gmd:CI_Citation>\n')
491
    WriteInLOG(zLOG, '</gmd:citation>\n')
492
    #End CITATION BLOC
493

    
494
    #ABSTRACT BLOC
495
    zValue, zText = GetTextWidget(self, "resume", False)
496
    WriteInLOG(zLOG, '<gmd:abstract>\n')
497
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zValue))
498
    WriteInLOG(zLOG, '</gmd:abstract>\n')
499
    #End ABSTRACT BLOC
500

    
501
    #ROLES BLOC
502
    zObj = getWidget(self, "tableroles")
503
    for i in range(zObj.rowCount()):
504
        zValue = self.DicoListOfRules[zObj.cellWidget(i, 0).currentIndex()]
505
        if zValue != "pointOfContact" : MakeBlocRole(self, zLOG, zObj, zValue, i, False)
506
    #End ROLES BLOC
507

    
508
    #BLOC INSPIRE optional keywords 
509
    zObj = getWidget(self, "tablemotsclefsf")
510
    for i in range(zObj.rowCount()):
511
        WriteInLOG(zLOG, '<gmd:descriptiveKeywords>\n')
512
        WriteInLOG(zLOG, '<gmd:MD_Keywords>\n')
513
        WriteInLOG(zLOG, '<gmd:keyword>\n')
514
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 0).text()))
515
        WriteInLOG(zLOG, '</gmd:keyword>\n')
516

    
517
        zValueTHE = zObj.cellWidget(i, 2).text()
518
        if zValueTHE != "" :
519
            WriteInLOG(zLOG, '<gmd:thesaurusName>\n')
520
            WriteInLOG(zLOG, '<gmd:CI_Citation>\n')
521
            WriteInLOG(zLOG, '<gmd:title>\n')
522
            WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zValueTHE))
523
            WriteInLOG(zLOG, '</gmd:title>\n')
524

    
525
            zValueDate = zObj.cellWidget(i, 3).text()
526
            if zValueDate.find("--")==-1:
527
                zValueTypeDate = GetDateType(zObj.cellWidget(i, 4).currentIndex(), False)
528
                MakeBlocDate(self, zLOG, zValueDate, zValueTypeDate)
529
               
530
            WriteInLOG(zLOG, '</gmd:CI_Citation>\n')
531
            WriteInLOG(zLOG, '</gmd:thesaurusName>\n')
532
    
533
        WriteInLOG(zLOG, '</gmd:MD_Keywords>\n')
534
        WriteInLOG(zLOG, '</gmd:descriptiveKeywords>\n')
535
    #End BLOC INSPIRE optional keywords
536

    
537
    #BLOC INSPIRE required keywords
538
    zObj = getWidget(self, "tablemotsclefso")
539
    for i in range(zObj.rowCount()):
540
        WriteInLOG(zLOG, '<gmd:descriptiveKeywords>\n')
541
        WriteInLOG(zLOG, '<gmd:MD_Keywords>\n')
542
        WriteInLOG(zLOG, '<gmd:keyword>\n')
543
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 1).currentText()))
544
        WriteInLOG(zLOG, '</gmd:keyword>\n')
545
        WriteInLOG(zLOG, '<gmd:thesaurusName>\n')
546
        WriteInLOG(zLOG, '<gmd:CI_Citation>\n')
547
        WriteInLOG(zLOG, '<gmd:title>\n')
548
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 0).currentText()))
549
        WriteInLOG(zLOG, '</gmd:title>\n')
550

    
551
        MakeBlocDate(self, zLOG, self.DateListOfThesaurus[zObj.cellWidget(i, 0).currentIndex()], "publication")
552

    
553
        WriteInLOG(zLOG, '</gmd:CI_Citation>\n')
554
        WriteInLOG(zLOG, '</gmd:thesaurusName>\n')
555
        WriteInLOG(zLOG, '</gmd:MD_Keywords>\n')
556
        WriteInLOG(zLOG, '</gmd:descriptiveKeywords>\n')
557
    #End BLOC INSPIRE required keywords   
558

    
559
    #BLOC resourceConstraints
560
    WriteInLOG(zLOG, '<gmd:resourceConstraints>\n')
561
    WriteInLOG(zLOG, '<gmd:MD_LegalConstraints>\n')
562
    zObj = getWidget(self, "licence")
563
    WriteInLOG(zLOG, '<gmd:useLimitation>\n')
564
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.toPlainText()))
565
    WriteInLOG(zLOG, '</gmd:useLimitation>\n')
566
    zObj = getWidget(self, "groupedroits")
567

    
568
    if zObj.children()[0].isChecked() :
569
        WriteInLOG(zLOG, '<gmd:accessConstraints>\n')
570
        WriteInLOG(zLOG, '<gmd:MD_RestrictionCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#MD_RestrictionCode" codeListValue="otherRestrictions">otherRestrictions</gmd:MD_RestrictionCode>\n')
571
        WriteInLOG(zLOG, '</gmd:accessConstraints>\n')
572
        WriteInLOG(zLOG, '<gmd:otherConstraints>\n')
573
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (QtGui.QApplication.translate("QSphere","No restriction for public access with INSPIRE", None, QtGui.QApplication.UnicodeUTF8)))
574
        WriteInLOG(zLOG, '</gmd:otherConstraints>\n')
575
    else :
576
        WriteInLOG(zLOG, '<gmd:accessConstraints>\n')
577
        WriteInLOG(zLOG, '<gmd:MD_RestrictionCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#MD_RestrictionCode" codeListValue="otherRestrictions">otherRestrictions</gmd:MD_RestrictionCode>\n')
578
        WriteInLOG(zLOG, '</gmd:accessConstraints>\n')
579
        zChild = zObj.children()[2]
580
        zRows = zChild.model().rowCount()
581
        for i in range(zRows):
582
            zItem = zChild.model().item(i, 0)
583
            if zItem.checkState()== Qt.Checked:
584
                zValue = zChild.model().item(i, 1).text()
585
                WriteInLOG(zLOG, '<gmd:otherConstraints>\n')
586
                WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zValue))
587
                WriteInLOG(zLOG, '</gmd:otherConstraints>\n')
588

    
589
    WriteInLOG(zLOG, '</gmd:MD_LegalConstraints>\n')
590
    WriteInLOG(zLOG, '</gmd:resourceConstraints>\n')
591
    #End BLOC resourceConstraints
592

    
593
    #BLOC spatialRepresentationType - not yet implemented (vector, raster, other ? ...)
594
    """
595
    WriteInLOG(zLOG, '<gmd:spatialRepresentationType>\n')
596
    WriteInLOG(zLOG, '<gmd:MD_SpatialRepresentationTypeCode codeList="http://librairies.ign.fr/geoportail/resources/CodeLists.xml#MD_SpatialRepresentationTypeCode" codeListValue="vector">vector</gmd:MD_SpatialRepresentationTypeCode>\n')
597
    WriteInLOG(zLOG, '</gmd:spatialRepresentationType>\n')
598
    """
599

    
600
    #BLOC Spatial Resolution
601
    zObj = getWidget(self, "grouperesolutionscale")
602
    zChild = zObj.children()[2]
603
    for i in range(zChild.rowCount()):
604
        zWidget = zChild.cellWidget(i, 0)
605
        if zObj.children()[0].isChecked() :
606
            WriteInLOG(zLOG, '<gmd:spatialResolution>\n')
607
            WriteInLOG(zLOG, '<gmd:MD_Resolution>\n')
608
            WriteInLOG(zLOG, '<gmd:equivalentScale>\n')
609
            WriteInLOG(zLOG, '<gmd:MD_RepresentativeFraction>\n')
610
            WriteInLOG(zLOG, '<gmd:denominator>\n')
611
            WriteInLOG(zLOG, '<gco:Integer>%s</gco:Integer>\n' % (int(zWidget.value())))
612
            WriteInLOG(zLOG, '</gmd:denominator>\n')
613
            WriteInLOG(zLOG, '</gmd:MD_RepresentativeFraction>\n')
614
            WriteInLOG(zLOG, '</gmd:equivalentScale>\n')
615
            WriteInLOG(zLOG, '</gmd:MD_Resolution>\n')
616
            WriteInLOG(zLOG, '</gmd:spatialResolution>\n')
617
        else:
618
            zValueMesureUnit = "%s" % (zObj.children()[3].currentText())
619
            WriteInLOG(zLOG, '<gmd:spatialResolution>\n')
620
            WriteInLOG(zLOG, '<gmd:MD_Resolution>\n')
621
            WriteInLOG(zLOG, '<gmd:distance>\n')
622
            WriteInLOG(zLOG, '<gco:Distance uom="%s">%s</gco:Distance>\n' % (zValueMesureUnit, zWidget.value()))
623
            WriteInLOG(zLOG, '</gmd:distance>\n')
624
            WriteInLOG(zLOG, '</gmd:MD_Resolution>\n')
625
            WriteInLOG(zLOG, '</gmd:spatialResolution>\n')
626
    #End BLOC Spatial Resolution
627

    
628
    #BLOC Language for the resource
629
    zObj = getWidget(self, "tablelangues")
630
    zRows = zObj.model().rowCount()
631
    for i in range(zRows):
632
        zItem = zObj.model().item(i, 0)
633
        if zItem.checkState()== Qt.Checked:
634
           zValue = zObj.model().item(i, 0).text()
635
           MakeBlocLangue(self, zLOG, zValue)
636
    #End BLOC Language for the resource
637

    
638
    #BLOC INSPIRE category(/ISO)
639
    zObj = getWidget(self, "tablecategories")
640
    zRows = zObj.model().rowCount() 
641
    WriteInLOG(zLOG, '<gmd:topicCategory>\n')
642
    for i in range(zRows):
643
        zItem = zObj.model().item(i, 0)
644
        if zItem.checkState()== Qt.Checked: WriteInLOG(zLOG, '<gmd:MD_TopicCategoryCode>%s</gmd:MD_TopicCategoryCode>\n' % (MakeCAT(self, zObj.model().item(i, 2).text())))
645
    WriteInLOG(zLOG, '</gmd:topicCategory>\n')
646
    #End BLOC INSPIRE category(/ISO)
647

    
648
    #BLOC Extents
649
    WriteInLOG(zLOG, '<gmd:extent>\n')
650
    WriteInLOG(zLOG, '<gmd:EX_Extent>\n')
651
    zObj = getWidget(self, "tableemprises")
652
    WriteInLOG(zLOG, '<gmd:description>\n')
653
    WriteInLOG(zLOG, '<gco:CharacterString>Liste des emprises</gco:CharacterString>\n')
654
    WriteInLOG(zLOG, '</gmd:description>\n')
655
    for i in range(zObj.rowCount()):
656
        WriteInLOG(zLOG, '<gmd:geographicElement>\n')
657
        WriteInLOG(zLOG, '<gmd:EX_GeographicBoundingBox>\n')
658
        WriteInLOG(zLOG, '<gmd:westBoundLongitude>\n')
659
        WriteInLOG(zLOG, '<gco:Decimal>%s</gco:Decimal>\n' % (zObj.cellWidget(i, 2).value()))
660
        WriteInLOG(zLOG, '</gmd:westBoundLongitude>\n')
661
        WriteInLOG(zLOG, '<gmd:eastBoundLongitude>\n')
662
        WriteInLOG(zLOG, '<gco:Decimal>%s</gco:Decimal>\n' % (zObj.cellWidget(i, 3).value()))
663
        WriteInLOG(zLOG, '</gmd:eastBoundLongitude>\n')
664
        WriteInLOG(zLOG, '<gmd:southBoundLatitude>\n')
665
        WriteInLOG(zLOG, '<gco:Decimal>%s</gco:Decimal>\n' % (zObj.cellWidget(i, 1).value()))
666
        WriteInLOG(zLOG, '</gmd:southBoundLatitude>\n')
667
        WriteInLOG(zLOG, '<gmd:northBoundLatitude>\n')
668
        WriteInLOG(zLOG, '<gco:Decimal>%s</gco:Decimal>\n' % (zObj.cellWidget(i, 0).value()))
669
        WriteInLOG(zLOG, '</gmd:northBoundLatitude>\n')    
670
        WriteInLOG(zLOG, '</gmd:EX_GeographicBoundingBox>\n')
671
        WriteInLOG(zLOG, '</gmd:geographicElement>\n')
672
       
673
    zObj = getWidget(self, "tableetenduetemporelle")
674
    for i in range(zObj.rowCount()):
675
        zWidgetDates = "%s" % (zObj.cellWidget(i, 0).text())
676
        if zWidgetDates.find("-- --") == -1 :
677
            zDates = zWidgetDates.split(" ")
678
            WriteInLOG(zLOG, '<gmd:temporalElement>\n')
679
            if zObj.rowCount() == 1 :  WriteInLOG(zLOG, '<gmd:EX_TemporalExtent>\n')
680
            else : WriteInLOG(zLOG, '<gmd:EX_TemporalExtent gml:id="tp00%s">\n' % (i+1)) 
681
            WriteInLOG(zLOG, '<gmd:extent>\n')
682
            WriteInLOG(zLOG, '<gml:TimePeriod xsi:type="gml:TimePeriodType">\n') 
683
            WriteInLOG(zLOG, '<gml:beginPosition>%s</gml:beginPosition>\n' % (zDates[0]))
684
            WriteInLOG(zLOG, '<gml:endPosition>%s</gml:endPosition>\n'  % (zDates[1]))
685
            WriteInLOG(zLOG, '</gml:TimePeriod>\n')
686
            WriteInLOG(zLOG, '</gmd:extent>\n')
687
            WriteInLOG(zLOG, '</gmd:EX_TemporalExtent>\n')
688
            WriteInLOG(zLOG, '</gmd:temporalElement>\n')
689
    WriteInLOG(zLOG, '</gmd:EX_Extent>\n')
690
    WriteInLOG(zLOG, '</gmd:extent>\n')
691
    #End BLOC Extents
692
    
693
    WriteInLOG(zLOG, '</gmd:MD_DataIdentification>\n')
694
    WriteInLOG(zLOG, '</gmd:identificationInfo>\n')
695

    
696
def MakeDistributionInfoXML(self, zLOG):
697
    WriteInLOG(zLOG, '<gmd:distributionInfo>\n')
698
    WriteInLOG(zLOG, '<gmd:MD_Distribution>\n')
699
    zObj = getWidget(self, "tableformats")
700
    for i in range(zObj.rowCount()): MakeBlocFormat(self, zLOG, zObj, i)
701
   
702
    WriteInLOG(zLOG, '<gmd:transferOptions>\n')
703
    WriteInLOG(zLOG, '<gmd:MD_DigitalTransferOptions>\n')
704
    zObj = getWidget(self, "tablelocalisator")
705
    for i in range(zObj.rowCount()):
706
        WriteInLOG(zLOG, '<gmd:onLine>\n')
707
        WriteInLOG(zLOG, '<gmd:CI_OnlineResource>\n')
708
        WriteInLOG(zLOG, '<gmd:linkage>\n')
709
        WriteInLOG(zLOG, '<gmd:URL>%s</gmd:URL>\n' % (urllib.quote_plus(zObj.cellWidget(i, 0).text())))
710
        WriteInLOG(zLOG, '</gmd:linkage>\n')
711
        WriteInLOG(zLOG, '<gmd:name>\n')
712
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (urllib.quote_plus(zObj.cellWidget(i, 1).text())))
713
        WriteInLOG(zLOG, '</gmd:name>\n')
714
        WriteInLOG(zLOG, '</gmd:CI_OnlineResource>\n')
715
        WriteInLOG(zLOG, '</gmd:onLine>\n')
716
    WriteInLOG(zLOG, '</gmd:MD_DigitalTransferOptions>\n')
717
    WriteInLOG(zLOG, '</gmd:transferOptions>\n')
718
    
719
    WriteInLOG(zLOG, '</gmd:MD_Distribution>\n')
720
    WriteInLOG(zLOG, '</gmd:distributionInfo>\n')
721

    
722
def MakeDataQualityInfoXML(self, zLOG):
723
    zObj = getWidget(self, "typedata")
724
    zValue = self.TypeData[zObj.currentIndex()]
725
    
726
    WriteInLOG(zLOG, '<gmd:dataQualityInfo>\n')
727
    WriteInLOG(zLOG, '<gmd:DQ_DataQuality>\n')
728
    WriteInLOG(zLOG, '<gmd:scope>\n')
729
    WriteInLOG(zLOG, '<gmd:DQ_Scope>\n')
730
    WriteInLOG(zLOG, '<gmd:level>\n')
731
    WriteInLOG(zLOG, '<gmd:MD_ScopeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#MD_ScopeCode" codeListValue="%s">%s</gmd:MD_ScopeCode>\n' % (zValue, zValue))
732
    WriteInLOG(zLOG, '</gmd:level>\n')
733
    WriteInLOG(zLOG, '</gmd:DQ_Scope>\n')
734
    WriteInLOG(zLOG, '</gmd:scope>\n')
735

    
736
    zObj = getWidget(self, "tablespecifications")
737

    
738
    if zObj.rowCount()> 0 : WriteInLOG(zLOG, '<gmd:report>\n')
739
    for i in range(zObj.rowCount()):
740
        zValueSPEC = zObj.cellWidget(i, 0).text() 
741
        if zValueSPEC != "" :
742
            WriteInLOG(zLOG, '<gmd:DQ_DomainConsistency xsi:type="gmd:DQ_DomainConsistency_Type">\n')
743
            WriteInLOG(zLOG, '<gmd:result>\n')
744
            WriteInLOG(zLOG, '<gmd:DQ_ConformanceResult xsi:type="gmd:DQ_ConformanceResult_Type">\n')
745
            WriteInLOG(zLOG, '<gmd:specification>\n')
746
            WriteInLOG(zLOG, '<gmd:CI_Citation>\n')
747
            WriteInLOG(zLOG, '<gmd:title>\n')
748
            WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zValueSPEC))
749
            WriteInLOG(zLOG, '</gmd:title>\n')
750

    
751
            zValueDate = zObj.cellWidget(i, 1).text()
752
            if zValueDate.find("--") == -1 :
753
                zValueTypeDate = GetDateType(zObj.cellWidget(i, 2).currentIndex(), False) 
754
                MakeBlocDate(self, zLOG, zValueDate, zValueTypeDate)
755

    
756
            WriteInLOG(zLOG, '</gmd:CI_Citation>\n')
757
            WriteInLOG(zLOG, '</gmd:specification>\n')
758
            WriteInLOG(zLOG, '<gmd:explanation>\n')
759
            WriteInLOG(zLOG, '<gco:CharacterString>See the referenced specification</gco:CharacterString>\n')
760
            WriteInLOG(zLOG, '</gmd:explanation>\n')
761
            
762
            zIndesDegre = zObj.cellWidget(i, 3).currentIndex()
763
            if zIndesDegre == 0 : zValue = "true"
764
            elif zIndesDegre : zValue = "false"
765
            else : zValue = ""
766
            if zValue != "" :
767
                WriteInLOG(zLOG, '<gmd:pass>\n')
768
                WriteInLOG(zLOG, '<gco:Boolean>%s</gco:Boolean>\n' % (zValue))
769
                WriteInLOG(zLOG, '</gmd:pass>\n')
770
            else: WriteInLOG(zLOG, '<gmd:pass/>\n')   
771
            
772
            WriteInLOG(zLOG, '</gmd:DQ_ConformanceResult>\n')
773
            WriteInLOG(zLOG, '</gmd:result>\n')
774
            WriteInLOG(zLOG, '</gmd:DQ_DomainConsistency>\n')
775
    if zObj.rowCount()> 0 : WriteInLOG(zLOG, '</gmd:report>\n')
776

    
777
    zObj = getWidget(self, "genealogie")
778
    zValue = zObj.toPlainText()
779
    WriteInLOG(zLOG, '<gmd:lineage>\n')
780
    WriteInLOG(zLOG, '<gmd:LI_Lineage>\n')
781
    WriteInLOG(zLOG, '<gmd:statement>\n')
782
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zValue))
783
    WriteInLOG(zLOG, '</gmd:statement>\n')
784
    WriteInLOG(zLOG, '</gmd:LI_Lineage>\n')
785
    WriteInLOG(zLOG, '</gmd:lineage>\n')  
786

    
787
    WriteInLOG(zLOG, '</gmd:DQ_DataQuality>\n')
788
    WriteInLOG(zLOG, '</gmd:dataQualityInfo>\n')
789

    
790
def MakeSpatialRepresentation(self, zLOG):
791
    zObj = getWidget(self, "coherence")
792
    if zObj.toPlainText() != "" :
793
        import ast
794
        try : mydict = ast.literal_eval("%s" % (zObj.toPlainText()))
795
        except : mydict = None
796

    
797
        if mydict != None and type(mydict)==dict:
798

    
799
            zcondTopologyLevelCode = True if mydict.has_key('TopologyLevelCode') and mydict['TopologyLevelCode']!= 'unknow' else False
800
            zcondGeometricObjectTypeCode = True if mydict.has_key('GeometricObjectTypeCode') and mydict['GeometricObjectTypeCode']!= 'unknow' else False
801

    
802
            if zcondTopologyLevelCode or zcondGeometricObjectTypeCode :
803
                    WriteInLOG(zLOG, '<gmd:spatialRepresentationInfo>\n')
804
                    WriteInLOG(zLOG, '<gmd:MD_VectorSpatialRepresentation>\n')
805
                    if zcondTopologyLevelCode :
806
                        WriteInLOG(zLOG, '<gmd:topologyLevel>\n')
807
                        WriteInLOG(zLOG, '<gmd:MD_TopologyLevelCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#MD_TopologyLevelCode" codeListValue="%s">%s</gmd:MD_TopologyLevelCode>\n' % (mydict['TopologyLevelCode'], mydict['TopologyLevelCode']))
808
                        WriteInLOG(zLOG, '</gmd:topologyLevel>\n')
809
                    if zcondGeometricObjectTypeCode :    
810
                        WriteInLOG(zLOG, '<gmd:geometricObjects>\n')
811
                        WriteInLOG(zLOG, '<gmd:MD_GeometricObjects>\n')
812
                        WriteInLOG(zLOG, '<gmd:geometricObjectType>\n')
813
                        WriteInLOG(zLOG, '<gmd:MD_GeometricObjectTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#MD_GeometricObjectTypeCode" codeListValue="%s">%s</gmd:MD_GeometricObjectTypeCode>\n' % (mydict['GeometricObjectTypeCode'],mydict['GeometricObjectTypeCode']))
814
                        WriteInLOG(zLOG, '</gmd:geometricObjectType>\n')
815
                        WriteInLOG(zLOG, '</gmd:MD_GeometricObjects>\n')
816
                        WriteInLOG(zLOG, '</gmd:geometricObjects>\n')
817
                    WriteInLOG(zLOG, '</gmd:MD_VectorSpatialRepresentation>\n')
818
                    WriteInLOG(zLOG, '</gmd:spatialRepresentationInfo>\n')
819

    
820
def MakeEndXML(self, zLOG):
821
    WriteInLOG(zLOG, '</gmd:MD_Metadata>')
822
    
823
#-----------------------------
824
# PRIMARY BLOC FOR XML EXPORT       
825
#----------------------------- 
826
def MakeBlocFormat(self, zLOG, zObj, i):
827
    if zObj.cellWidget(i, 0).styleSheet() == "background-color:#AEEE00;" :
828
        WriteInLOG(zLOG, '<gmd:distributionFormat>\n')
829
        WriteInLOG(zLOG, '<gmd:MD_Format>\n')
830
        WriteInLOG(zLOG, '<gmd:name>\n')
831
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 0).text()))
832
        WriteInLOG(zLOG, '</gmd:name>\n')
833
        WriteInLOG(zLOG, '<gmd:version>\n')
834
        WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 2).text())) 
835
        WriteInLOG(zLOG, '</gmd:version>\n')
836
        WriteInLOG(zLOG, '</gmd:MD_Format>\n')
837
        WriteInLOG(zLOG, '</gmd:distributionFormat>\n')
838
        """            
839
        WriteInLOG(zLOG, '<gmd:amendmentNumber></gmd:amendmentNumber>\n')
840
        WriteInLOG(zLOG, '<gmd:specification></gmd:specification>\n')
841
        WriteInLOG(zLOG, '<gmd:fileDecompressionTechnique></gmd:fileDecompressionTechnique>\n')
842
        WriteInLOG(zLOG, '<gmd:formatDistributor></gmd:formatDistributor>\n')
843
        """
844
    
845
def MakeBlocLangue(self, zLOG, zValue):
846
    WriteInLOG(zLOG, '<gmd:language>\n')
847
    WriteInLOG(zLOG, '<gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/" codeListValue="%s">%s</gmd:LanguageCode>\n' % (zValue, zValue))
848
    WriteInLOG(zLOG, '</gmd:language>\n')
849

    
850
def MakeBlocDate(self, zLOG, zValue, zType):
851
    WriteInLOG(zLOG, '<gmd:date>\n')
852
    WriteInLOG(zLOG, '<gmd:CI_Date>\n')
853
    WriteInLOG(zLOG, '<gmd:date>\n')
854
    WriteInLOG(zLOG, '<gco:Date>%s</gco:Date>\n' % (zValue))
855
    WriteInLOG(zLOG, '</gmd:date>\n')
856
    WriteInLOG(zLOG, '<gmd:dateType>\n')
857
    WriteInLOG(zLOG, '<gmd:CI_DateTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#CI_DateTypeCode" codeListValue="%s">%s</gmd:CI_DateTypeCode>\n' % (zType, zType))
858
    WriteInLOG(zLOG, '</gmd:dateType>\n')
859
    WriteInLOG(zLOG, '</gmd:CI_Date>\n')
860
    WriteInLOG(zLOG, '</gmd:date>\n')
861

    
862
def MakeBlocRole(self, zLOG, zObj, zValue, i, isPointOfContact):
863
    WriteInLOG(zLOG, '<gmd:contact>\n') if isPointOfContact else WriteInLOG(zLOG, '<gmd:pointOfContact>\n')
864
    MakeResponsibleParty(self, zLOG, zObj, zValue, i, isPointOfContact)
865
    WriteInLOG(zLOG, '</gmd:contact>\n') if isPointOfContact else WriteInLOG(zLOG, '</gmd:pointOfContact>\n')
866

    
867
def MakeResponsibleParty(self, zLOG, zObj, zValue, i, isPointOfContact):
868
    WriteInLOG(zLOG, '<gmd:CI_ResponsibleParty>\n')
869
    WriteInLOG(zLOG, '<gmd:organisationName>\n')
870
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 1).text()))
871
    WriteInLOG(zLOG, '</gmd:organisationName>\n')
872
    WriteInLOG(zLOG, '<gmd:contactInfo>\n')
873
    WriteInLOG(zLOG, '<gmd:CI_Contact>\n')
874
    WriteInLOG(zLOG, '<gmd:address>\n')
875
    WriteInLOG(zLOG, '<gmd:CI_Address>\n')
876
    WriteInLOG(zLOG, '<gmd:deliveryPoint>\n')
877
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 2).text()))
878
    WriteInLOG(zLOG, '</gmd:deliveryPoint>\n')
879
    WriteInLOG(zLOG, '<gmd:city>\n')
880
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 5).text()))
881
    WriteInLOG(zLOG, '</gmd:city>\n')
882
    WriteInLOG(zLOG, '<gmd:postalCode>\n')
883
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 4).text()))
884
    WriteInLOG(zLOG, '</gmd:postalCode>\n')
885
    WriteInLOG(zLOG, '<gmd:country>\n')
886
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 3).currentText().rstrip().lstrip()))
887
    WriteInLOG(zLOG, '</gmd:country>\n')
888
    WriteInLOG(zLOG, '<gmd:electronicMailAddress>\n')
889
    WriteInLOG(zLOG, '<gco:CharacterString>%s</gco:CharacterString>\n' % (zObj.cellWidget(i, 6).text()))
890
    WriteInLOG(zLOG, '</gmd:electronicMailAddress>\n')
891
    WriteInLOG(zLOG, '</gmd:CI_Address>\n')
892
    WriteInLOG(zLOG, '</gmd:address>\n')
893
    WriteInLOG(zLOG, '</gmd:CI_Contact>\n')
894
    WriteInLOG(zLOG, '</gmd:contactInfo>\n')
895
    WriteInLOG(zLOG, '<gmd:role>\n')
896
    WriteInLOG(zLOG, '<gmd:CI_RoleCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#CI_RoleCode" codeListValue="%s">%s</gmd:CI_RoleCode>\n' % (zValue, zValue))
897
    WriteInLOG(zLOG, '</gmd:role>\n')
898
    WriteInLOG(zLOG, '</gmd:CI_ResponsibleParty>\n')
899
    
900
#-------------------------------
901
# FONCTIONs TO WRITE XML EXPORT       
902
#-------------------------------
903
def GetDateType(index, TheKey):
904
    if index > 2 : index = 0
905
    zDates = (("datecredata", "creation"), ("daterevdata","revision"), ("datepubdata","publication"))
906
    return zDates[index][0] if TheKey else zDates[index][1]
907
    
908
def MakeCAT(self, zText):
909
    zTemp = zText.split("(")
910
    zCat = zTemp[1].replace(")", "")
911
    return "%s" % (zCat)
912

    
913
def MakeLOG(self, zFile):
914
    zLOG = file(zFile, "w")
915
    return zLOG
916

    
917
def WriteInLOG(zLOG, zMsg):
918
    if zLOG != None : zLOG.write(zMsg.encode("utf-8"))
919

    
920
def CloseLOG(zLOG):     
921
    if zLOG != None : zLOG.close()
922

    
(3-3/5)