def get_info(self): """Retrieve various bits of info about the blueprint.""" rowsets = [layer.grid.rows for layer in self.layers] cells = map(lambda r: r.flatten(), rowsets) if len(cells) == 0: raise BlueprintError('No row data in blueprint.') commands = [c.command for c in cells[0]] cmdset = set(commands) # uniques if '' in cmdset: cmdset.remove('') # count the number of occurrences of each command in the blueprint counts = [(c, commands.count(c)) for c in cmdset] counts.sort(key=lambda x: x[1], reverse=True) # look for the manual-mat character anywhere in the commands, # and check that phase=build (the only mode that we'll support # manual material selection with right now) uses_manual_mats = util.is_substring_in_list(':', cmdset) and \ self.build_type == 'build' # make a row of repeating numbers to annotate the blueprint with width = self.layers[0].grid.width # build the blueprint preview return textwrap.dedent(""" Blueprint name: %s Build type: %s Comment: %s Start position: %s Start comment: %s First layer width: %d First layer height: %d Layer count: %d Uses manual material selection: %s Command use counts: %s """).strip() % ( self.name, self.build_type, self.comment or '', add_points(self.start, (1, 1)), self.start_comment or '', width, self.layers[0].grid.height, len(self.layers), uses_manual_mats, ', '.join("%s:%d" % c for c in counts) ) + \ "\nBlueprint preview:\n" + \ '\n'.join( Grid.str_commands(layer.grid.rows, annotate=True) + \ '\n#' + ''.join(layer.onexit) for layer in self.layers )
def get_blueprint_info(path, transform_str): """ Returns information about the blueprint at path. If transform_str is given, blueprint will be transformed accordingly before returning. """ sheets = filereader.get_sheet_names(path) newphase, transforms, ztransforms = \ transformer.parse_transform_str(transform_str) result = '' for sheet in sheets: try: (layers, details) = filereader.parse_file(path, sheet[1]) # transform the blueprint if transforms is not None: logmsg('transform', 'Transforming with: %s' % transform_str) if newphase is not None: details[ 'build_type'] = buildconfig.get_full_build_type_name( newphase) tran = Transformer(layers, details['start']) tran.transform(transforms) # do the x/y transformations details['start'] = tran.start layers = tran.layers logmsg('transform', 'Results of transform:') loglines('transform', lambda: FileLayer.str_layers(layers)) layers = FileLayers_to_GridLayers(layers) bp = Blueprint(sheet[0], layers, details) # perform any requested z-transforms if ztransforms is not None: layers = bp.repeat_ztransforms(ztransforms, bp.layers, Blueprint.repeater_layers) bp.layers = layers formatted = bp.get_info() # add this sheet's info to the result string result += '>>>> Sheet id %d\n' % sheet[1] result += formatted + '\n' except BlueprintError as ex: continue # ignore blank/missing sheets if result: return result else: raise BlueprintError("No valid blueprints found in '%s'." % path)
def convert_blueprint(layers, details, startpos, transform_str, output_mode, output_title, visualize): """ Transforms the provided layers if required by transform_str, then renders keystrokes/macros required to plot or visualize the blueprint specified by layers and details and pursuant to args. """ # apply aliases.txt to blueprint contents # TODO abstract this better alii = aliases.load_aliases( os.path.join(exetest.get_main_dir(), 'config/aliases.txt')) layers = aliases.apply_aliases(layers, alii) # transform the blueprint ztransforms = [] if transform_str: logmsg('transform', 'Transforming with: %s' % transform_str) newphase, transforms, ztransforms = \ transformer.parse_transform_str(transform_str) if newphase is not None: details['build_type'] = buildconfig.get_full_build_type_name( newphase) tran = Transformer(layers, details['start']) tran.transform(transforms) # do the x/y transformations details['start'] = tran.start layers = tran.layers logmsg('file', 'Results of transform:') loglines('file', lambda: FileLayer.str_layers(layers)) layers = FileLayers_to_GridLayers(layers) if not layers: # empty blueprint handling raise BlueprintError("Blueprint appears to be empty.") # override starting position if startpos command line option was given if startpos is not None: details['start'] = parse_startpos(startpos, layers[0].grid.width, layers[0].grid.height) # convert layers and other data to Blueprint bp = Blueprint('', layers, details) # get keys/macrocode to outline or plot the blueprint keys = [] if output_mode == 'csv': bp.analyze() # perform any awaiting z-transforms layers = bp.repeat_ztransforms(ztransforms, bp.layers, Blueprint.repeater_layers) bp.layers = layers output = str(bp) else: if visualize: keys = bp.trace_outline() else: bp.analyze() keys = bp.plot(ztransforms) output = keystroker.convert_keys(keys, output_mode, output_title) loglines('summary', lambda: str_summary(bp, keys)) return output