Exemple #1
0
 def initialize(self):
     """
     Initialize the map before running it. This must be done in the right sequence:
     - prepare the output file
     """
     try:
         # first, instantiate the resources and the commands
         self.instantiate(self.d)
         # get the projection
         proj = get_or_default(self.d, 'projection', 'default-projection')
         self.projection = self.resolve_projection(proj)
         self.strings['projection-name'] = proj
         self.strings['projection-class'] = self.projection.cls
         if self.projection is None:
             raise MapperException(MX_UNRESOLVED_REFERENCE, 'Map.init_output', 'projection', proj)
         # then load the input file
         file_in = self.translate_string(self.d['file-in'])
         file_in = os.path.join(self.path, file_in)
         self.strings['input-file'] = file_in
         self.input_svg = svgfig_mc.load(file_in)
         # define all the layers of transformation between the input and the output file.
         self.set_transforms(self.d['viewport'])
         # and then prepare the output file
         self.file_out = self.translate_string(self.d['file-out'])
         self.file_out = os.path.join(self.path, self.file_out)
         self.strings['output-file'] = self.file_out
         self.init_output(get_or_default(self.d, 'append', False))
         self.mode = get_or_default(self.d, 'mode', 'keep')
         if self.mode not in {'keep', 'clip', 'crop'}:
             raise MapperException(MX_WRONG_VALUE, 'Map.initialize', 'mode', self.mode)
     except KeyError as ke:
         raise MapperException(MX_MISSING_PARAMETER, 'Map.initialize', str(ke), 'map')
Exemple #2
0
 def initialize(self):
     """
     Initialize the map before running it. This must be done in the right sequence:
     - prepare the output file
     """
     try:
         # first, instantiate the resources and the commands
         self.instantiate(self.d)
         # get the projection
         proj = get_or_default(self.d, 'projection', 'default-projection')
         self.projection = self.resolve_projection(proj)
         self.strings['projection-name'] = proj
         self.strings['projection-class'] = self.projection.cls
         if self.projection is None:
             raise MapperException(MX_UNRESOLVED_REFERENCE,
                                   'Map.init_output', 'projection', proj)
         # then load the input file
         file_in = self.translate_string(self.d['file-in'])
         file_in = os.path.join(self.path, file_in)
         self.strings['input-file'] = file_in
         self.input_svg = svgfig_mc.load(file_in)
         # define all the layers of transformation between the input and the output file.
         self.set_transforms(self.d['viewport'])
         # and then prepare the output file
         self.file_out = self.translate_string(self.d['file-out'])
         self.file_out = os.path.join(self.path, self.file_out)
         self.strings['output-file'] = self.file_out
         self.init_output(get_or_default(self.d, 'append', False))
         self.mode = get_or_default(self.d, 'mode', 'keep')
         if self.mode not in {'keep', 'clip', 'crop'}:
             raise MapperException(MX_WRONG_VALUE, 'Map.initialize', 'mode',
                                   self.mode)
     except KeyError as ke:
         raise MapperException(MX_MISSING_PARAMETER, 'Map.initialize',
                               str(ke), 'map')
 def load_symbol(self, name):
     """ Locates and returns the symbol's svg. """
     if self.svg is None:
         self.svg = svgfig_mc.load(os.path.join(self.path, self.filename))
     for k, s in self.svg:
         if isinstance(s, svgfig_mc.SVG):
             if 'id' in s.attr and name == s.attr['id']:
                 return s
     return None
Exemple #4
0
 def init_output(self, append):
     """
     Either create a new blank output file that is a copy of the input stripped of content,
     or load an existing one and index it.
     """
     if append and os.path.isfile(self.file_out):
         self.output_svg = svgfig_mc.load(self.file_out)
         for k, s in self.output_svg:
             if isinstance(s, svgfig_mc.SVG) and s.t == 'g' and 'inkscape:groupmode' in s.attr:
                 self.layers_out[s.attr['inkscape:label']] = s
     else:
         # Clone the header part of the input by iterating over all top-level members that are not groups.
         self.output_svg = svgfig_mc.SVG('svg')
         self.output_svg.attr = copy.deepcopy(self.input_svg.attr)
         for k, s in self.input_svg.depth_first(1):
             if isinstance(s, svgfig_mc.SVG) and s.t not in ['g', 'path']:
                 self.output_svg.append(s.clone())
Exemple #5
0
 def init_output(self, append):
     """
     Either create a new blank output file that is a copy of the input stripped of content,
     or load an existing one and index it.
     """
     if append and os.path.isfile(self.file_out):
         self.output_svg = svgfig_mc.load(self.file_out)
         for k, s in self.output_svg:
             if isinstance(
                     s, svgfig_mc.SVG
             ) and s.t == 'g' and 'inkscape:groupmode' in s.attr:
                 self.layers_out[s.attr['inkscape:label']] = s
     else:
         # Clone the header part of the input by iterating over all top-level members that are not groups.
         self.output_svg = svgfig_mc.SVG('svg')
         self.output_svg.attr = copy.deepcopy(self.input_svg.attr)
         for k, s in self.input_svg.depth_first(1):
             if isinstance(s, svgfig_mc.SVG) and s.t not in ['g', 'path']:
                 self.output_svg.append(s.clone())