#!/usr/bin/python
# Copyright (C) 2011 by Aivars Kalvans <aivars.kalvans@gmail.com>
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import sys
import optparse

parser = optparse.OptionParser(usage='usage: %prog [options] <sUML string>')
parser.add_option('-p', '--png', action='store_true', dest='png',
                help='create a png file')
parser.add_option('-s', '--svg', action='store_true', dest='svg',
                help='create a svg file')
parser.add_option('--scruffy', action='store_true', dest='scruffy',
                help='process result with scruffy (works for svg and png output_file)')
parser.add_option('--shadow', action='store_true', dest='shadow', default=False,
                help='add shadow to scruffy output_file')
parser.add_option('--sequence', action='store_true', dest='sequence',
                help='draw sequence diagram')
parser.add_option('--class', action='store_true', dest='klass',
                help='draw class diagram')
parser.add_option('-o', '--output_file', action='store', dest='output_file',
                help='output_file file name')
parser.add_option('-i', '--input_file', action='store', dest='input_file',
                help='input_file file name')
parser.add_option('--font-family', action='store', dest='font',
                help='set output_file font family')
(options, args) = parser.parse_args()

if len(args) > 1:
    parser.error('Too many arguments')

fout = sys.stdout
if options.output_file:
    fout = open(options.output_file, 'wb')

if options.input_file:
    spec = open(options.input_file, 'r').read()
elif len(args) == 0:
    lines = sys.stdin.read()
    spec = lines.replace('\n', ',')
else:
    spec = args[0]

if options.scruffy and not options.font:
    import suml.common
    options.font = suml.common.defaultScruffyFont()

if options.sequence:
    import suml.suml2pic
    suml.suml2pic.transform(spec, fout, options)
else:
    import suml.yuml2dot
    suml.yuml2dot.transform(spec, fout, options)
