Source code for node_export_figures

# -*- coding: utf-8 -*-
# Copyright (c) 2016, 2017, System Engineering Software Society
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of the System Engineering Software Society nor the
#       names of its contributors may be used to endorse or promote products
#       derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.
# IN NO EVENT SHALL SYSTEM ENGINEERING SOFTWARE SOCIETY BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import (print_function, division, unicode_literals,
                        absolute_import)
import os
from sympathy.api import node as synode
from sympathy.api.nodeconfig import Port, Ports, Tag, Tags, deprecated_node
from sympathy.api import exporters
from sylib.export import base


[docs]class ExportFigures(base.ExportMultiple, synode.Node): """ Export Figures to a selected data format. :Ref. nodes: :ref:`org.sysess.sympathy.visualize.figure`, :ref:`org.sysess.sympathy.visualize.figures` """ name = 'Export Figures' description = 'Export Figures to image files.' icon = 'export_figure.svg' tags = Tags(Tag.Output.Export) author = 'Benedikt Ziegler' nodeid = 'org.sysess.sympathy.export.exportfigures' version = '0.2' inputs = Ports([Port.Figures('Input figures', name='figures'), Port.Datasources( 'External filenames', name='port1', n=(0, 1, 0))]) plugins = (exporters.FigureDataExporterBase, ) parameters = base.base_params() def update_parameters(self, old_params): extension = old_params._parameter_dict.pop('extension', None) width = old_params._parameter_dict.pop('width', None) height = old_params._parameter_dict.pop('height', None) if 'custom_exporter_data' not in old_params: custom_exporter_data = old_params.create_group( 'custom_exporter_data') else: custom_exporter_data = old_params['custom_exporter_data'] if 'Image' not in custom_exporter_data: image = custom_exporter_data.create_group('Image') else: image = custom_exporter_data['Image'] if extension is not None: image.set_list('extension', label=extension['label'], description=extension['description'], value=extension['value'], plist=extension['list'], editor=extension['editor']) if width is not None: image.set_integer('width', label=width['label'], description=width['description'], value=width['value'], editor=width['editor']) if height is not None: image.set_integer('height', label=height['label'], description=height['description'], value=height['value'], editor=height['editor']) return old_params
[docs]@deprecated_node('1.7.0', 'Export Figures (with optional datasource port)') class ExportFiguresWithDsrcs(base.ExportMultiple, synode.Node): """ Export Figures to a selected data format with a list of datasources for output paths. """ name = 'Export Figures with Datasources' description = 'Export Figures to image files.' icon = 'export_figure.svg' tags = Tags(Tag.Output.Export) author = 'Magnus Sandén' nodeid = 'org.sysess.sympathy.export.exportfigureswithdscrs' version = '0.1' inputs = Ports([ Port.Figures('Input figures', name='figures'), Port.Datasources('Datasources', name='dsrcs')]) plugins = (exporters.FigureDataExporterBase, ) parameters = base.base_params() def _exporter_ext_filenames_portname(self): return 'dsrcs' def _exporter_ext_filename(self, custom_parameters, filename): if not os.path.splitext(filename)[1]: ext = custom_parameters['extension'].selected filename = '{}.{}'.format(filename, ext) return filename