Newer
Older
####################################################################################################
#
# Patro - A Python implementation of Valentina Pattern Drafting Software
# Copyright (C) 2017 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
####################################################################################################
import logging
from lxml import etree
from Patro.Xml.Objectivity import StringAttribute, XmlObjectAdaptator
from Patro.Xml.XmlFile import XmlFileMixin
from Patro.Pattern.Measurement import Measurements, Measurement
####################################################################################################
_module_logger = logging.getLogger(__name__)
####################################################################################################
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# <?xml version='1.0' encoding='UTF-8'?>
# <vit>
# <!--Measurements created with Valentina (http://www.valentina-project.org/).-->
# <version>0.3.3</version>
# <read-only>false</read-only>
# <notes/>
# <unit>cm</unit>
# <pm_system>998</pm_system>
# <personal>
# <family-name>..</family-name>
# <given-name>...</given-name>
# <birth-date>...</birth-date>
# <gender>...</gender>
# <email/>
# </personal>
# <body-measurements>
# <m value="46" name="height_knee"/>
# </body-measurements>
# </vit>
####################################################################################################
class XmlMeasurement(XmlObjectAdaptator):
__tag__ = 'm'
__attributes__ = (
StringAttribute('name'),
StringAttribute('value'),
StringAttribute('full_name', default=''),
StringAttribute('description', default=''),
)
####################################################################################################
class VitFile(XmlFileMixin):
_logger = _module_logger.getChild('VitFile')
##############################################
def __init__(self, path):
XmlFileMixin.__init__(self, path)
self._measurements = Measurements()
self._read()
##############################################
@property
def measurements(self):
return self._measurements
##############################################
def _read(self):
self._logger.info('Load measurements from ' + str(self._path))
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
tree = self._parse()
measurements = self._measurements
version = self._get_xpath_element(tree, 'version').text
# self._read_only = self._get_xpath_element(tree, 'read-only').text
# self._notes = self._get_xpath_element(tree, 'notes').text
self.unit = self._get_xpath_element(tree, 'unit').text
self.pattern_makin_system = self._get_xpath_element(tree, 'pm_system').text
personal = measurements.personal
personal_element = self._get_xpath_element(tree, 'personal')
personal.last_name = self._get_xpath_element(personal_element, 'family-name').text
personal.first_name = self._get_xpath_element(personal_element, 'given-name').text
personal.birth_date = self._get_xpath_element(personal_element, 'birth-date').text
personal.gender = self._get_xpath_element(personal_element, 'gender').text
personal.email = self._get_xpath_element(personal_element, 'email').text
elements = self._get_xpath_element(tree, 'body-measurements')
for element in elements:
if element.tag == XmlMeasurement.__tag__:
xml_measurement = XmlMeasurement(element)
measurements.add(**xml_measurement.to_dict())
else:
raise NotImplementedError
measurements.eval()