Book a Demo

Author Topic: PNGs and Image Library  (Read 4305 times)

gdbgeek

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
PNGs and Image Library
« on: April 02, 2014, 06:45:15 am »
I'm trying to set up some alternate images for our standard diagrams. I have a few questions;

1) EA doesnt seem to correctly recognise the transparency of my PNG format images. If I import bitmaps with a white background they work fine but then I cannot overlap images (as they are no longer transparent)

2) Is there a way to bulk import images?

3) Related to #2 I imported the image library from here (http://www.sparxsystems.com/resources/image_library.html). Is it possible to generate one of these XML files using my own images?

Thanks

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: PNGs and Image Library
« Reply #1 on: April 02, 2014, 07:14:01 am »
1) IIRC this was enhanced with V11
2) only with a script

q.

gdbgeek

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: PNGs and Image Library
« Reply #2 on: April 02, 2014, 07:15:24 am »
Thanks qwerty, I'll try V11.

Do you know where I can find a sample script to bulk import images?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: PNGs and Image Library
« Reply #3 on: April 02, 2014, 07:17:50 am »
I have one written in Perl if that helps.

q.

gdbgeek

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: PNGs and Image Library
« Reply #4 on: April 02, 2014, 07:19:29 am »
I would like to have a look at it if that's possible? Im not a Perl user but if I can see how its done that would be great. Thanks

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: PNGs and Image Library
« Reply #5 on: April 02, 2014, 07:38:02 am »
Here it is:
Code: [Select]
use strict;
no strict 'refs';
use Win32::OLE qw (in);
use XML::Simple;
use MIME::Base64 ();
use DBI;

#use EaSimulator;
#EaSimulator->new ({'PACKAGE'=>"{088A0FC2-E1E4-41d8-9661-900C18E2243D}"});

my %tableData =
  ('t_image' => {PRIMARY => 'ImageID', COLUMNS => ['Type', 'Name', 'ImageID', 'Image']},
   't_propertytypes' => {PRIMARY => 'Property', COLUMNS => ['Property', 'Description', 'Notes']},
   't_statustypes' => {PRIMARY => 'Status', COLUMNS => ['Status', 'Description']});

my $rep = $ENV{'REP'};

my $dbName = $rep->ConnectionString;
my $dbi;
if ($dbName =~ /\.eap$/i) { $dbi = "dbi:ADO:Data Source=$dbName;Provider=Microsoft.Jet.OLEDB.4.0" }
elsif ($dbName =~ /Data Source=([^;]*)/) { $dbi = "dbi:ODBC:$1" }
else { die "can not figure out DB type from $dbName" }
my $dbh = DBI->connect($dbi, "") or die "Can't connect to $dbi";

my $fn = $rep->xmiPath($rep->GetTreeSelectedObject()) . 'RefData.xml';

my $xs = XML::Simple->new(); # convert the XML return string into a hash
my $ref = $xs->XMLin($fn);

for my $key (keys %{$ref->{'DataSet'}}) {
  import ($ref->{'DataSet'}->{$key});
}

return 1;

sub import {
  my $data = shift;
  my $table = $data->{'table'};
  my $primary = $tableData{$table}->{PRIMARY} or return;

  my %xref;
  my $columns = "`" . join ("`, `", @{$tableData{$table}->{COLUMNS}}) . "`";
  my $sth;
  $sth = $dbh->prepare("delete * from $table where 1");
  $sth->execute();

  if (ref ($data->{'DataRow'}) eq "HASH") {
    $data->{'DataRow'} = [$data->{'DataRow'}];
  }
  for (in @{$data->{'DataRow'}}) {
    my $row = $_->{ 'Column'};
    next if $#{$tableData{$table}->{COLUMNS}} < 0;
    my $sql;

    $sql = "INSERT INTO $table (";
    my $values = "";
    my $sep = "";
    for my $col (@{$tableData{$table}->{COLUMNS}}) {
      if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
        $values .= $sep . '?';
      } else {
        next unless $row->{$col}->{'value'};
        $values .= $sep . quote ($row->{$col}->{'value'});
      }
      $sql .= "$sep`$col`";
      $sep = ", ";
    }
    $sql .= ") VALUES ($values)";
    $sth = $dbh->prepare($sql);
    my $param = 0;
    for my $col (@{$tableData{$table}->{COLUMNS}}) {
      if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
        $param++;
        $sth->bind_param($param, MIME::Base64::decode($row->{$col}->{'content'}), DBI::SQL_BLOB);
      }
    }
    $sth->execute();
  }
}

sub quote {
  $_ = shift();
  s/'/''/gm;
  s/‰/&auml;/gm;
  s/ˆ/&ouml;/gm;
  s/¸/&uuml;/gm;
  s/ƒ/&Auml;/gm;
  s/÷/&Ouml;/gm;
  s/‹/&Uuml;/gm;
  s/[ch64258]/&szlig;/gm;
  return "'$_'";
}
I used it to import all kind of ref-data.

q.

P.S. Why does this crappy YABB interpret smileys inside a code block?

gdbgeek

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: PNGs and Image Library
« Reply #6 on: April 02, 2014, 07:39:33 am »
Much appreciated qwerty!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: PNGs and Image Library
« Reply #7 on: April 02, 2014, 07:40:45 am »
It's probably not that easy to read if you're not a Perl monk. OTOH it's not too long  ;)

q.
« Last Edit: April 02, 2014, 07:41:05 am by qwerty »