diff -r 5b32dc297d05 -r 3c36c452f013 sysmodellibs/sysmodelgen/src/SysModelGen.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sysmodellibs/sysmodelgen/src/SysModelGen.pm Wed Oct 13 16:21:25 2010 +0100 @@ -0,0 +1,1372 @@ +# Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# Package: SysModelGen +# Build an SVG System Model diagram +# +# + +package SysModelGen; + +use Cwd; +use Cwd 'abs_path'; +use File::Copy; +use File::Path; +use FindBin; +use lib $FindBin::Bin."/../common"; +use Getopt::Long qw(:config no_ignore_case); +use File::Basename; +use File::Spec; +use Logger; +use Env qw(@PATH); +use Env qw(@PATHEXT); +use Env qw(@CLASSPATH); +use strict; + +my @Filters; + + +use constant KSystemModelGenerator => 201; + +#------------------------------------------------------------------------------------------------- +# Subroutine: new +# Purpose: +# Input: None (extracted from command line args) +# Output: A reference to itself +#------------------------------------------------------------------------------------------------- +sub new + { + my $package = shift; + my $self = {}; # Create reference to object + bless $self, $package; # Associate a reference with class name + + my $dataroot =&SystemModelXmlDataDir(); + my @yr = gmtime(); + my %Args = ( + 'iHelp' => {'param' => "h", + 'desc' => 'Help on usage'}, + 'iIniFile' => { 'param' => "i=s", 'type'=>'file', + 'desc' => 'An INI file listing one argument per line, with the syntax: = . Command line arguments will override ini file settings.' }, + 'iDiagram' => { 'param' => "output=s" , default=>"sysmodel.svg",'type'=>'outfile', + 'class' => 'Build Control', 'desc' => 'The name of the file to save the built System Model SVG. If in the format filename.svgz, it will attempt to compress the file. If compression is not supported, it will rename the output to filename.svg. Defaults to sysmodel.svg or sysmodel.svgz if -compress is set.'}, + 'iOutputCsv' => { 'param' => "csv_output=s" , 'type'=>'outfile', + 'class' => 'Build Control', 'desc' => 'The name of the file to save a CSV description of the built System Model. Only items shown on the system model will be included.'}, + 'iCsvColumns' => { 'param' => "csv_columns=s" , 'type'=>'outfile', + 'class' => 'Build Control', 'desc' => 'Comma-separated list of columns to include in the output CSV. This does nothing if -csv_output is not present. By default (if -csv_columns is not present), the columns will be a sorted list of all attributes on all items. '}, + 'iCsvLabels' => { 'param' => "csv_labels=s" , 'type'=>'outfile', + 'class' => 'Build Control', 'desc' => 'Comma-separated list of columns labels include in the output CSV. Do not use quotes or commas in label names. This does nothing if -csv_output is not present. If this list is shorter than -csv_columns, the remaining columns will use the attribute name as the label. '}, + 'iOutputXml' => { 'param' => 'xml_output=s' ,'type'=>'outfile', + 'class' => 'Build Control', 'desc' => 'The name of the file to save a combined system definition XML. Only items shown in the built system model will be included.'}, + 'iWarningLevel' => { 'param' => "w=s", 'type' => 'number', + 'class' =>'Build Control', 'desc' => 'Warning level. 1: errors only (default), 2: warnings as well as errors, 3: info messages, warnings and errors, 4: all plus deep syntax validation and reporting -- note that this can take a long time to compute so do not use this warning level by default'}, + 'iLowMem' => { 'param' => "lowmem", + 'class' =>'Build Control', 'desc' => 'Build the model storing more data in the temp directory and using less runtime memory. If building fails due to an out of memory condition, try running again with the -lowmem option.'}, + "iClean" => { 'param' => 'clean' , + 'class' => 'Build Control', 'desc' =>'Caution: if set, it will delete the contents of the temporary directory.'}, + 'iCompress' => { 'param' => "compress", + 'class' => 'Build Control', 'desc' => 'If set, it will attempt to compress the output as an SVGZ file. In order to success gzip must be installed and in the PATH. This will also rename the output file from filename.svg to filename.svgz.'}, + 'iTemporaryDirectory' => { 'param' => "tempdir=s", 'default' => 'drawsvg_temp','type'=>'dir', + 'class' => 'Build Control', 'desc' => 'Temporary directory for build files.'}, + 'iLogFile' => { 'param' => "log=s", 'type'=>'outfile', + 'class' => 'Build Control', 'desc' => 'File in which to store output. Defaults to stdout'}, + 'iModel' => { 'param' => "model=s" ,'type'=>'file/uri', 'default' => "$dataroot/ModelTemplate.xml", + 'class' => 'Files or URIs', 'desc' => 'The location of the Model XML file to use to build the file. Content of this file will be overridden by anything set on the command line on in an ini file'}, + 'iSysDefFile' => { 'param' => "sysdef=s", 'multi' => 1,'type'=>'file/uri', 'xpath' => '/model/sysdef', + 'class' => 'Model Control', 'desc' => 'The System Definition XML file(s) used to build the model.'}, + "iSourceRoot" => {'param'=>'srcvar=s' ,'multi' => 1, + 'class' => 'Model Control'}, + 'iPathPrefix' => {'param' => 'sysdef-prefix=s', 'multi' => 1, 'class' => 'Model Control','type'=>'file/uri',}, + "iSysDefPath" => {'param' => "sysdef-path=s", 'multi' => 1,'type'=>'path', + 'class' => 'Model Control', 'desc' => 'The directory which the system definition file should be considered to be in when turning unit\'s relative links into absolute paths. This is only necessary to provide if the result requires the absolute paths to be meaningful. The order of this parameter must match the order of the -sysdef parameter'}, + 'iShapes' => { 'param' => "shapes=s", 'xpath' => '/model/@shapes','type'=>'file/uri', + 'class' => 'Files or URIs', 'desc' => 'The location of the Shapes XML file used to provide rules to control the display of the system model items. If not present, default behaviour (in Shapes.xml) is used. This and the default bahaviours are overrriden by using the -color, -border, -pattern, and -style options. '}, + 'iLink' => { 'param' => "link=s", 'xpath' => '/model/@link', + 'class' => 'Files or URIs', 'desc' => 'The base URL to use for all hyperlinks in the model. A base URL will be appended by the type and name (e.g. Blocks/Comms%20Services.html) of the items to create the full URL of the linked file. Window directories will be converted into file URIs.'}, + 'iLinkExpr' => { 'param' => "link-expr=s", 'multi' => 1, 'xpath' => 'model/link', + 'class' => 'Model Control', 'desc' => 'The link used on any system model item. Any values within {...} are evaluled as an expression on the item. All xpath locations in the expresion must be set otherwise the link will not be created for the item'}, + 'iName' => { 'param' => "system_name=s" , 'xpath' => '/model/@name', + 'class' => "Labels", 'desc' =>'The name of the product described in the model. It appears at the bottom right.'}, + 'iRelease' => { 'param' => "system_version=s" , 'xpath' => '/model/@ver', + 'class' =>"Labels", 'desc' =>'The version of the product described in the model. It appears at the bottom right after the name.'}, + 'iLabel' => { 'param' => "model_name=s" , 'xpath' => '/model/@label', + 'class' =>"Labels", 'desc' =>'The label for the model. It appears at the bottom right, under the name.'}, + 'iRevision' => { 'param' => "model_version=s", 'xpath' => '/model/@revision', + 'class' =>"Labels", 'desc' =>'A number which appears before the model-revision-type. If specified this overrides the build number used by depmodel. If not building depmodel, this defaults to "1"'}, + 'iRevisionType' => { 'param' => "model_version_type=s", 'xpath' => '/model/@revision-type', + 'class' =>"Labels", 'desc' =>'One of "draft", "issued", "build", "date" or free-text value. Appears below the model label. If specified this overrides the build number used by DepToolkit.If not building depmodel, this defaults to "draft"'}, + 'iCopyright' => { 'param' => "copyright=s", 'default' => (1900+$yr[5])." Nokia Corporation", 'xpath' => '/model/@copyright', + 'class' =>"Labels", 'desc' =>'The copyright to appear in the lower left. Set to empty string to leave out.'}, + 'iDistribution' => { 'param' => "distribution=s", 'xpath' => '/model/@distribution', + 'class' => "Labels", 'desc' =>'Text to appear on the bottom centre to indicate to whom the model can be shown. Informational only. Suggested values are "internal", "secret" or "unrestrictred". Not shown if not set.'}, + 'iLgdTitle' => { 'param' => "legend_title=s", 'xpath' => '/model/layout/legend/@label', + 'class' =>"Labels", 'desc' =>'The title to appear in the leftmost part of the legend.'}, + 'iLgdFloat' => { 'param' => "legend_float=s", 'xpath' => '/model/layout/legend/@float', 'type' => 'boolean', + 'class' =>"Model Control", 'desc' =>'If set, the legend will appear when the mouse hovers over the bottom of the window. The floating legend will span the full width of the window. This may not be readable, depending on the amonent of content in the legend.'}, + 'iCoreOs' => { 'param' => "coreos=s", 'type' => 'on/off/new', + 'class' =>'Model Control', 'desc' => 'Turn on or off Core OS colouring for 9.4 and later models -- For backwards compatibility only! Use "on" for Symbian OS 9.4 models and "new" for Symbian OS 9.5 and later models (non-Foundation)'}, + + 'iExtra' => { 'multi' => 1, 'param' => "sysinfo=s",'type'=>'file/uri', info=>'extra', 'xpath' => '/model/sysdef', + 'class' => 'Files or URIs', 'desc' => 'The location of extra component information used to provided additional properies for components. By default, the provided "SystemInfo.xml" is used.'}, + 'iLocalize' => { 'multi' => 1, 'param' => "localize=s", 'xpath' => '/model/layout','type'=>'file/uri', info=>'abbrev', + 'class' => 'Files or URIs', 'desc' => 'The location of the Localization file used to provide displayable names for the model entities.'}, + 'iDict' => { 'param' => "dictionary=s", 'type'=>'file/uri', + 'class' => 'Build Control', 'desc' => 'A term dictionary file used to semi-intelligently generate the abbreviations for the names of system model entries. Anything mentioned in the Localization files overrides generated abbreviations.'}, + 'iS12' => { 'multi' => 1, 'param' => "s12=s",'type'=>'file/uri' , info=>'s12', 'xpath' => '/model/sysdef', + 'depr' => "Only works on 2.0 syntax and older models", + 'class' => 'Files or URIs', 'desc' => 'The location of the Schedule 12 XML file used to provide the border shapres of the components. If this a directory, the S12 XML file is found by appending "Symbian_OS_v[system_version]_Schedule12.xml" to the directory.'}, + 'iLevels' => { 'multi' => 1, 'param' => "levels=s",'type'=>'file/uri' , info=>'levels', 'xpath' => '/model/sysdef', + 'depr' => "Only works on 2.0 syntax and older models. Use info file instead", + 'class' =>'Files or URIs', 'desc' => 'The location of the Levels XML file used to override the stacking of collections. '}, + 'iDepsFile' => { 'multi' => 1, 'param' => "deps=s", 'xpath' => '/model/sysdef','type'=>'file/uri', info=>'extra', + 'class' => 'Files or URIs', 'desc' => 'The location of a sysinfo file containing Dependencies. If not present, dependencies will not be drawn'}, + + 'iColor' => { 'multi' => 1, 'param' => "color=s", 'xpath' => '/model/layout','type'=>'file/uri', 'info'=>'color', + 'class' =>'Files or URIs', 'desc' => 'The location of a Values XML file used to specify per-component colours. If not present, the default colours are used.'}, + 'iBorder' => { 'multi' => 1, 'param' => "border-shape=s", 'xpath' => '/model/layout','type'=>'file/uri','info'=>'border', + 'class' =>'Files or URIs', 'desc' => 'The location of a Values XML file used to specify the shape (border) of each component. If not present, the default borders are used.'}, + 'iOverlay' => { 'multi' => 1, 'param' => "pattern=s", 'xpath' => '/model/layout','type'=>'file/uri','info'=>'overlay', + 'class' => 'Files or URIs', 'desc' => 'The location of a Values XML file used to specify per-component overlay patterns. If not present, the default patterns (for new and reference components) are used.'}, + 'iStyle' => { 'multi' => 1, 'param' => "border-style=s", 'xpath' => '/model/layout','type'=>'file/uri','info'=>'style', + 'class' => 'Files or URIs', 'desc' => 'The location of a Values XML file used to specify per-component border styles. If not present, the default border styles are used. '}, + + 'iFilter' =>{ 'type' => 'filter-name', 'multi' => 1, 'param' => "filter=s", + 'depr' => "Only works on 2.0 syntax and older models", + 'class' =>'Model Control', 'desc' => 'The name of a filter to turn on when building the model. All filters on an item must be present in this list in order for that item to appear. Can have any number of these Defaults to "java" and "gt"'}, + 'iFilterHas' =>{ 'type' => 'filter-name', 'ordered' => 1,'param' => "filter-has=s", + 'class' => 'Model Control', 'desc' =>'Like -filter, except any filter on an item must be present in this list in order for that item to appear. Include "*" in the list in order to show items with no filters. Equivalent to "-show-attr filter xxx"'}, + 'iShow' => { 'type' => 'attr[=val]', 'ordered' => 1,'param' => "show-attr=s", + 'class' =>'Model Control', 'desc' => 'A mechanism of filtering which allows filtering based on component attribute values. If a value is set for that attribute, the component will be shown. Use in conjunction with -hide-attr for fine contol of what is shown. "class" and "filter" attribtues are handled specially -- see the documentation for details'}, + 'iHide' => { 'type' => 'attr[=val]', 'ordered' => 1,'param' => "hide-attr=s", + 'class' =>'Model Control', 'desc' => 'A mechanism of filtering which allows filtering based on component attribute values. If a value is set for that attribute, the component will not be shown on the model. Use in conjunction with -show-attr for fine contol of what is shown. "class" and "filter" attribtues are handled specially -- see the documentation for details'}, + 'iIgnore' => { 'type' => 'item', 'multi' => 1, 'param' => "ignore=s", 'xpath' => '/model/ignore', + 'class' =>'Model Control', 'desc' => 'The ID of a model entity to not draw. Any number of these can be used'}, + 'iIgnoreMeta' => { 'type' => 'item', 'multi' => 1, 'param' => "ignore-meta=s", 'xpath' => '/model/ignore', + 'class' =>'Model Control', 'desc' => 'The "rel" meta value to ignore. Takes the form of [relvalue] or [relvalue]:[type]. Any number of these can be used'}, + + 'iNavCtrl' =>{'param' => "navctrl=s" , 'type'=>'boolean' , 'xpath' => '/model/layout/@navctrl', + 'class' =>'Model Control', 'desc' => 'If set, a navigation control widget will appear in the upper left corner of the model. The control might not work on some SVG viewers.'}, + 'iDetail' =>{'param' => "detail=s", 'type' => 'item-type' , 'xpath' => '/model/layout/@detail', + 'class' =>'Model Control', 'desc' => 'The type of the smallest System Model entity to draw. One of "layer", "package", "collection" or "component". Defaults to "component"'}, + 'iLevelDetail' =>{'param' => "level-detail=s", 'type' => 'show/hide' , 'xpath' => '/model/layout/@levels', + 'class' =>'Model Control', 'desc' => 'Toggles display of level names on packages or layers. A value of "show" will display level names inside either layers (at "layer" level of detail only) or packages (at "package" level of detail only). A value of "hide" (default) will not show any level names.'}, + 'iDetailType' => { 'param' => "detail-type=s", 'type' => 'type' , 'xpath' => '/model/layout/@detail-type', + 'class' =>'Model Control', 'desc' => 'If set to "fixed", the smallest System Model entity drawn will have a fixed with (rather then sized by their invisible components). This can be used to reduce the size and complexity of the overall model.'}, + 'iPlaceholderDetail' => { 'param' => "placeholder=s", 'type' => 'item-type' , 'xpath' => '/model/layout/@placeholder-detail', + 'class' =>'Model Control', 'desc' => 'The type of the smallest *empty* System Model entity to draw. One of "layer", "package", "collection" or "component". For example, if set to "package" empty layers and packages will be drawn, but empty collections will be ignored. If not set, no empty items will be drawn.'}, + 'iPageWidth' =>{'param' => "page-width=s", 'type' => 'length', 'xpath' => '/model/layout/@page-width', + 'depr' => "Only works on 2.0 syntax and older models", + 'class' =>'Model Control', 'desc' => 'The width of the drawn image (with units). If not specified it will fit the viewer window. Valid units: "in", "mm", "cm", "px", "pt"'}, + 'iStatic' => { 'param' => "static=s", 'type' => 'boolean', 'xpath' => '/model/layout/@static', + 'class' =>'Model Control', 'desc' => 'If present, the model will not have any mouseover effects (this is overriden by builing the depmodel).'}, + 'iPrintResolution' =>{ 'param' => "dpi=s", 'type' => 'number', 'xpath' => '/model/layout/@resolution', + 'class' =>'Model Control', 'desc' => 'The DPI to use when printing from the Adobe SVG Viewer. If not present, it will print well at A4 size. A value of 300 will look good on A3 size paper'}, + 'iModelFont' =>{'param' => "model_font=s", 'type' =>'font', 'xpath' => '/model/layout/@font', + 'class' =>'Model Control', 'desc' => 'The name of the base font to use to draw the model. This will be overriden by any custom CSS in the Shapes XML'}, + 'iVersions' => { 'param' => "version-list=s", + 'class' =>'Model Control'}, + 'iLogoSrc' =>{ 'param' => "logo=s", 'type'=>'file/uri', 'xpath' => '/model/layout/logo/@src', + 'class' => 'Model Control', 'desc' => 'If present, the logo will be drawn in the lower-left corner of the model. If the logo is an SVG file, -logo-width and -logo-height are optional, otherwise the must both be specified'}, + 'iLogoEmbed' =>{ 'xpath' => '/model/layout/logo/@embed', 'class' => 'Model Control' }, + 'iLogoHeight' => { 'param' => "logo-height=s", 'type' => 'length', 'xpath' => '/model/layout/logo/@height', + 'class' =>'Model Control', 'desc' => 'Specifies the height of the logo (if any) in mm. Width is scaled along with height unless otherwise specified. Both width and height MUST be specified if a bitmap image is used'}, + 'iLogoWidth' => { 'param' => "logo-width=s", 'type' => 'length', 'xpath' => '/model/layout/logo/@width', + 'class' =>'Model Control', 'desc' => 'Specifies the width of the logo (if any) in mm. Height is scaled along with width unless otherwise specified. Both width and height MUST be specified if a bitmap image is used'}, + 'iLegendWidth' =>{ 'param' => "legend-width=s", 'type' => '%', 'xpath' => '/model/layout/legend/@width', + 'class' => 'Model Control', 'desc' =>'The percent width of the model the legend takes up. This will scale the size of the legend and model title, but not the logo, to fill the specified space. If a logo is included, but no width specified, the legend cannot be scaled since it will not be able to determine the available space. Note that that -max-legend-scale will further limit the potential width.'}, + 'iLegendMaxScale' =>{ 'param' => "legend-max-scale=s", 'type' => 'scale', 'xpath' => '/model/layout/legend/@maxscale', + 'class' => 'Model Control', 'desc' =>'Specifies the maximum scale factor for resizing the legend. If this is present and -legend-width is not, the legend and title will scale to 100% of the available width. If both are present the scale factor will take precedent. If neither is present, the legend will not resize. Note that when this is used, the legend can shrink if it would normally be wider than the model.'}, + 'iTitleScale' => { 'param' => "title-scale=s", 'type' => 'scale', 'xpath' => '/model/layout/legend/@title-scale', + 'class' => 'Model Control', 'desc' =>'Specifies the scale factor for the size of the title font (the text in the lower right). Use this instead of CSS to control the size, since the model generator needs to explicitly know how much space to allocate for the title.'}, + 'iXsltParam' =>{ 'multi' => 2, 'param' => "xslt-param=s", + 'class' =>'Build Control', 'desc' => 'Advanced: Parameters to feed directly to the XSLT transforms'}, + 'iLegendNote' =>{ 'multi' => 1, 'param' => "note=s", 'xpath' => '/model/layout/legend/note', + 'class' => 'Labels', 'desc' => 'Free text to appear inside the legend box, on the rightmost side. If multiple ones are provided, they will appear as separate boxes from left to right. Newlines and other special characters can be entity-encoded (e.g. ). When using entities in an INI file, you *must* quote the value, otherwise the # will be treated as a comment delimiter.',} + ); + + $self->{iArgs} = \%Args; + + + # basic test of command line: + if (scalar(@ARGV) == 0) + { + $self->Help(); + exit Logger::KErrorNone; # nothing to do. Leave + } + + # process the input: + $self->ParseCommandLineOptions(); + + $self->{iReturnCode} = Logger::KErrorNone; + return $self; + } + + +sub ParseCommandLineOptions() + { + my $self = shift; + + my %opt; + while(my ($n,$b) = each %{$self->{iArgs}} ) + { + if(!$b->{'param'}) {next} # not a command line arg + my @ps = ($b->{'param'}); + ($ps[1]=$ps[0]) =~ tr/_-/-_/; + if($ps[1] eq $ps[0]) {shift(@ps)} + foreach my $p (@ps) + { + if($b->{'multi'}==1) + { + $opt{$p} = \@{$self->{$n}}; + } + elsif($b->{'multi'}==2) + { + $opt{$p} = \%{$self->{$n}}; + } + elsif($b->{'ordered'}) + { + $opt{$p} = \&OrderedOption; + } + else + { + $opt{$p} = \$self->{$n}; + } + } + } + + foreach (@ARGV) { + # some MS products replace "-" with en-dash in an effort to be "intelligent". + # This replaces all leading en-dashes in the command line with "-" + # There is a small risk that the en-dash is intentional and this will clobber it. + s/^\x96/-/; + } + + GetOptions(%opt); + + if ($self->{'iHelp'}) + { + $self->Help(); + exit Logger::KErrorNone; + } + + # set read files to absolute paths + my $dir = cwd; + + while(my ($n,$b) = each %{$self->{iArgs}} ) + { + my $type =$b->{'type'}; + if( $type eq 'file' or $type eq 'dir' or $type eq 'file/uri') + { + if($self->{$n} eq '') {next} # no value, so do nothing + if ($b->{'multi'} == 1) + { + foreach my $v (@{$self->{$n}}) + { + $v =&fixFile($type,$dir,$v); + } + } + elsif ($b->{'multi'} == 2) + { + while(my ($var,$val)=each (%{$self->{$n}})) + { + $self->{$n}->{$var}=&fixFile($type,$dir,$val); + } + } + else + { + $self->{$n} = &fixFile($type,$dir,$self->{$n} ); + } + } + } + + + @{$self->{'iFiltering'}} = @Filters; + @Filters=(); + my $i=0; + for($i=0;$i<=$#ARGV;$i++) + { # check remaining args to ensure they are valid + if($ARGV[$i]=~/^(http|file):\/\//) { # assume URLs are correct + next; + } + if($ARGV[$i] eq "-" || $ARGV[$i] eq "") + { #special values to use nothing or use the tmp file, but only valid for odd numbered args + if($i%2==1) {next} + $self->HelpBase(); + &Logger::LogFatal("Invalid syntax", KSystemModelGenerator, 0,Logger::KIncorrectSyntax); + } + if(!(-e $ARGV[$i])) { + $self->HelpBase(); + &Logger::LogFatal("file $ARGV[$i] does not exist", KSystemModelGenerator, 0,Logger::KFileDoesNotExist); + } + } + $self->ReadIniFile(); + + if($self->{'iDetail'}) + { # for ease of BC with ini files + $self->{'iDetail'} =~ s/^(block|subblock|logical(sub)?set)$/package/ || + $self->{'iDetail'} =~ s/^(module)$/collection/; + } + + + while(my ($n,$b) = each %{$self->{iArgs}} ) # set defaults + { + if($b->{'default'} and !defined $self->{$n}) + { + $self->{$n} =$b->{'default'}; + } + if($b->{'type'} eq 'boolean' and (defined $self->{$n})) + { #set booleans to true/false + if($self->{$n} == 1 or $self->{$n} =~/^(yes|on|true|y)$/i) + { + $self->{$n} = 'true'; + } + else + { + $self->{$n} = 'false'; + } + } + } + + # computed defaults: + + # if saving to .svgz, try to compress + $self->{iCompress} = $self->{iCompress} || ( $self->{iDiagram} =~ /\.svgz$/i ); + + if($self->{'iLogoSrc'} =~ /\.svg$/i) # embed SVG logos only + { + $self->{'iLogoEmbed'}= "yes"; + } + + if(defined $self->{iCoreOs} and ($self->{'iModel'} eq $self->{'iArgs'}->{'iModel'}->{'default'})) + { + my $dataroot =&SystemModelXmlDataDir(); + if($self->{iCoreOs}=~/(on|yes|true)$/i ) + { + $self->{'iModel'} = "$dataroot/ModelTemplate.94.xml", + } + elsif($self->{iCoreOs}=~/(off|no|false)$/i ) + { + $self->{'iModel'} = "$dataroot/ModelTemplate.xml", + } + elsif(! ($self->{iCoreOs}=~/^[0-9]+$/ )) # any other non-number + { + $self->{'iModel'} = "$dataroot/ModelTemplate.95.xml", + } + } + + + $self->{iTemporaryDirectory} = &fixFile('dir', cwd,$self->{iTemporaryDirectory} ); # now gives the full path name $self->{iTemporaryDirectory} + + mkpath $self->{iTemporaryDirectory} if ! -d $self->{iTemporaryDirectory}; + + # set the log file if needed: + $Logger::LOGFILE = $self->{iLogFile} if $self->{iLogFile}; + + # set the correct warning level: + # -w=1: errors only (default) + # -w=2: warnings as well as errors + # -w=3: info messages, warnings and errors. + if (defined $self->{iWarningLevel} and $self->{iWarningLevel} > 1) + { + if ($self->{iWarningLevel} == 2) + { + $self->{iWarningLevel} = LogItem::WARNING; + } + elsif ($self->{iWarningLevel} == 3) + { + $self->{iWarningLevel} = LogItem::INFO; + } + else # for anything higher than set it to LogItem::VERBOSE + { + $self->{iWarningLevel} = LogItem::VERBOSE; + } + } + else + { + $self->{iWarningLevel} = LogItem::ERROR; + } + # set the logger up: + $Logger::SEVERITY = $self->{iWarningLevel}; + + #determine the XSLT Processor we need to use + $self->{'iXslt'} = XsltProcessor(); + + } + +sub OrderedOption() { + my $var = shift; + my $val = shift; + if($var=~/^(show|hide)-attr$/) { + my $f = ""); + }elsif($var eq 'filter-has') { + if(!scalar(@Filters)) { # if the 1st is showing a filter than that implies everythig without a filter is turned off + push(@Filters,''); + } + foreach my $v (split(/,/,$val)) { + push(@Filters,""); + } + } +} + + +sub fixFile { + my $type = shift; + my $dir = shift; + my $val = shift; + if($val eq '') {return} + $val = &FullPath("$dir/", $val ); + if($type eq 'file/uri') { $val =&FileAsUrl($val)} + return $val; +} + + +sub FullPath { + my $root = shift; + my $file = shift; + + # If the file is not specified then return null + if (!$file) { + return; + } + + + # If the file is a URL or Windows path then return it as is + if ($file =~ /:/) { + return $file; + } + + # If the file is a windows remote path then return it as is + if ($file =~ /\\\\/ || $file =~ /\/\//) { + return $file; + } + + if ($root && !-e $root) { + &Logger::LogFatal("root$root does not exist"); + } + + if (-f $root) { + $root = File::Basename::dirname($root) + } + + # if root is empty or the same dir, then file is relative + if($root eq '' or $root eq '.') { + return $file; + } + + # If the file is relative from the root then we want to add the drive letter to the file (if one exists) + if ($file =~ s/^[\\\/]// ) { + if ($root =~ /^([a-z]:)/i) { + return File::Spec->catdir($1, $file); + } else { # it's a unix path, put the / back on + return "/$file"; + } + } + + # Return the concatenated root and filename + return File::Spec->catdir($root, $file); +} + + +sub ReadIniFile() + { + my $self = shift; + my %setHere; + return if ! defined $self->{iIniFile}; + + # Log a fatal error if the ini file is defined but doesn't exist: + &Logger::LogFatal("ini file does not exist\"$self->{iIniFile}\": $!", KSystemModelGenerator) if ! -e $self->{iIniFile}; + + open(INI, $self->{iIniFile}) or + &Logger::LogFatal("Could not open the ini file \"$self->{iIniFile}\": $!", KSystemModelGenerator); + + &Logger::LogInfo("Reading ini file \"$self->{iIniFile}...", KSystemModelGenerator); + + + my %IniMap; # map from ini var to internal var + foreach my $a (keys %{$self->{'iArgs'}}) { + my $v = $self->{'iArgs'}->{$a}->{'param'}; + $v=~s/=.*//; + $IniMap{$v}=$a; + $v=~tr/-_/_-/; # allow both model_name and model-name + $IniMap{$v}=$a; + } + + my $iniDir = $self->{iIniFile}; + $iniDir =~ s,[^\\//]+$,,; + #$iniDir .= '\\'; + + foreach my $line () + { + $line =~ s/^\s*//; # remove spaces + $line =~ s/\s*$//; # a/a + $line =~ s/\n$//; # remove new line + if($line =~/"/) { + $line =~ s/^(([^"#]*"[^"]*")+)#.*$/$1/; # remove comments indicated by # (to the end of the line) + } else { + $line =~ s/#.*$//; # remove comments indicated by # (to the end of the line) + } + next if $line eq ""; # ignore blank lines + if ($line =~ m/([^=]+)\s*=\s*(.*)/) + { + my $argType = lc $1; # case-insensitive + my $argValue = $2; # case-sensitive as it can have strings intended for html output + + $argType =~ s/^\s*//; # remove spaces on either end (Cannot use s/\s+// as this will not be suitable for html text) + $argType =~ s/\s*$//; + $argValue =~ s/^\s*//; + $argValue =~ s/\s*$//; + + $argValue =~ s/^'//; # no need for quotes around the values + $argValue =~ s/'$//; + $argValue =~ s/^"//; + $argValue =~ s/"$//; + + if(!defined $IniMap{$argType}) {next} + my $param = $IniMap{$argType}; + if($self->{'iArgs'}->{$param}->{'ordered'}) { + &OrderedOption($argType, $argValue); + } else { + my $type = $self->{'iArgs'}->{$param}->{'type'}; + # make sure all files mentioned are taken relative to the ini file + if($type eq 'file' or $type eq 'outfile' or $type eq 'dir' or $type eq 'file/uri') + { + $argValue =&fixFile($type,$iniDir,$argValue); + } + + # do not override! Only set values that have not been set on command line already + + if ($self->{'iArgs'}->{$param}->{'multi'} == 1) { + if(scalar(@{$self->{$param}})==0 || $setHere{$param}) { + push(@{$self->{$param}}, $argValue) ; + $setHere{$param}=1; + } + } elsif ($self->{'iArgs'}->{$param}->{'multi'} == 2) { + $argValue=~s/^([^=]+)=//; + if(scalar(%{$self->{$param}})==0 || $setHere{$param}) { + $self->{$param}->{$1}=$argValue; + $setHere{$param} = 1; + } + } else + { + $self->{$param} = $argValue if ! $self->{$param}; + } + } + } + } + + close(INI); + @{$self->{'iFiltering'}} = @Filters if ! @{$self->{'iFiltering'}}; + @Filters=(); + } + +sub getModel() + { + my $self = shift; + + my $tempDirectoryPathname = $self->{iTemporaryDirectory}; + my $modelXml = "$tempDirectoryPathname/Model.xml"; + + if(defined $self->{'iModelCreated'}) {return $modelXml} + + my $needsMod=0; + # the following needs a bit of work + foreach my $param (keys %{$self->{'iArgs'}}) { + if (! ($self->{'iArgs'}->{$param}->{'class'} =~ /^(Build Control|)$/ )) + { + if ($self->IsSet($param)) {$needsMod=1; last} + } + } + # if no parameters are set that would impact the model, just use the raw Model XML provided + if(!$needsMod) {return $self->{iModel}} + + my $dir = $self->{iModel}; + $dir=~s,[^/\\]+$,,; + + my $command = $self->XsltTransformCmd("-",$self->{'iModel'},$modelXml,1); # does not take any params + + open XSLT, "|$command" + #open XSLT, ">$tempDirectoryPathname/xslt.xsl" + || &Logger::LogFatal("error in running $command", KSystemModelGenerator); + my $basedir = &FileAsUrl($dir); + $basedir=~s,/$,,; # make sure no // +print XSLT ' +',$basedir,'/ + + + + + + + + +