layoutgenerator.cpp 19.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2012-2014                                               *
 *   Umbrello UML Modeller Authors <umbrello-devel@kde.org>                *
 ***************************************************************************/

#include "layoutgenerator.h"

#include "associationline.h"
#include "associationwidget.h"
15
#include "cmds.h"
16
17
#include "debug_utils.h"
#include "floatingtextwidget.h"
18
#include "uml.h"
19
20
#include "umlwidget.h"

21
// kde includes
22
23
#include <KConfigGroup>
#include <KDesktopFile>
24
25
#include <KLocalizedString>
#if QT_VERSION < 0x050000
26
#include <KStandardDirs>
27
#endif
28
29
30
31
32
33
34

// qt includes
#include <QDir>
#include <QFile>
#include <QHash>
#include <QProcess>
#include <QRegExp>
35
36
37
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#endif
38
39
40
41
42
43
44
45
46
47
48
#include <QString>
#include <QTemporaryFile>
//#include <QTextStream>

#define LAYOUTGENERATOR_DEBUG
//#define LAYOUTGENERATOR_DATA_DEBUG

#ifdef LAYOUTGENERATOR_DEBUG

static QString pngViewer()
{
49
#ifdef Q_OS_WIN
Oliver Kellogg's avatar
Oliver Kellogg committed
50
    return QLatin1String("start");
51
#else
52
#ifdef Q_OS_MAC
Oliver Kellogg's avatar
Oliver Kellogg committed
53
    return QLatin1String("unknown");
54
#else
Oliver Kellogg's avatar
Oliver Kellogg committed
55
    return QLatin1String("okular");
56
57
58
59
60
61
#endif
#endif
}

static QString textViewer()
{
62
#ifdef Q_OS_WIN
Oliver Kellogg's avatar
Oliver Kellogg committed
63
    return QLatin1String("start");
64
#else
65
#ifdef Q_OS_MAC
Oliver Kellogg's avatar
Oliver Kellogg committed
66
    return QLatin1String("unknown");
67
#else
Oliver Kellogg's avatar
Oliver Kellogg committed
68
    return QLatin1String("mcedit");
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#endif
#endif
}
#endif

/**
 * constructor
*/
LayoutGenerator::LayoutGenerator()
{
    setUseFullNodeLabels(false);
}

/**
 * Return state if layout generator is enabled.
 * It is enabled when the dot application has been found.
 *
 * @return true if enabled
*/
bool LayoutGenerator::isEnabled()
{
    Settings::OptionState& optionState = Settings::optionState();
    if (optionState.autoLayoutState.autoDotPath) {
        m_dotPath = currentDotPath();
    }
    else if (!optionState.autoLayoutState.dotPath.isEmpty()) {
        m_dotPath = optionState.autoLayoutState.dotPath;
    }
    return !m_dotPath.isEmpty();
}

/**
 * Return the path where dot is installed.
 *
 * @return string with dot path
 */
QString LayoutGenerator::currentDotPath()
{
107
108
109
#if QT_VERSION >= 0x050000
    QString executable = QStandardPaths::findExecutable(QLatin1String("dot"));
#else
Oliver Kellogg's avatar
Oliver Kellogg committed
110
    QString executable = KStandardDirs::findExe(QLatin1String("dot"));
111
#endif
112
113
114
115
116
117
    if (!executable.isEmpty()) {
        QFileInfo fi(executable);
        return fi.absolutePath();
    }
#ifdef Q_OS_WIN
    // search for dot installation
Ralf Habacker's avatar
Ralf Habacker committed
118
    QString appDir(QLatin1String(qgetenv("ProgramFiles").constData()));
119
120
    QDir dir(appDir);
    dir.setFilter(QDir::Dirs);
Ralf Habacker's avatar
Ralf Habacker committed
121
    dir.setNameFilters(QStringList() << QLatin1String("Graphviz*"));
122
123
124
125
    dir.setSorting(QDir::Reversed);
    QFileInfoList list = dir.entryInfoList();
    if (list.size() > 0) {
        QString dotPath = list.at(0).absoluteFilePath();
Ralf Habacker's avatar
Ralf Habacker committed
126
127
        QString exePath = QFile::exists(dotPath + QLatin1String("\\bin")) ? dotPath + QLatin1String("\\bin") : dotPath;
        return QFile::exists(exePath + QLatin1String("\\dot.exe")) ? exePath : QString();
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
    }
#endif
    return QString();
}

/**
 * generate layout and apply it to the given diagram.
 *
 * @return true if generating succeeded
*/
bool LayoutGenerator::generate(UMLScene *scene, const QString &variant)
{
    QTemporaryFile in;
    QTemporaryFile out;
    QTemporaryFile xdotOut;
    if (!isEnabled()) {
        uWarning() << "Could not apply autolayout because graphviz installation has not been found.";
        return false;
    }

#ifdef LAYOUTGENERATOR_DEBUG
    in.setAutoRemove(false);
    out.setAutoRemove(false);
    xdotOut.setAutoRemove(false);
#endif

    // generate filenames
    in.open();
    in.close();
    out.open();
    out.close();
    xdotOut.open();
    xdotOut.close();

#ifdef LAYOUTGENERATOR_DEBUG
    qDebug() << textViewer() << in.fileName();
    qDebug() << textViewer() << out.fileName();
    qDebug() << textViewer() << xdotOut.fileName();
#endif

    if (!createDotFile(scene, in.fileName(), variant))
        return false;

Oliver Kellogg's avatar
Oliver Kellogg committed
171
    QString executable = m_dotPath + QLatin1Char('/') + m_generator;
172
173
174

    QProcess p;
    QStringList args;
Oliver Kellogg's avatar
Oliver Kellogg committed
175
    args << QLatin1String("-o") << out.fileName() << QLatin1String("-Tplain-ext") << in.fileName();
176
177
178
179
    p.start(executable, args);
    p.waitForFinished();

    args.clear();
Oliver Kellogg's avatar
Oliver Kellogg committed
180
    args << QLatin1String("-o") << xdotOut.fileName() << QLatin1String("-Txdot") << in.fileName();
181
182
183
184
185
186
    p.start(executable, args);
    p.waitForFinished();

#ifdef LAYOUTGENERATOR_DEBUG
    QTemporaryFile pngFile;
    pngFile.setAutoRemove(false);
Oliver Kellogg's avatar
Oliver Kellogg committed
187
    pngFile.setFileTemplate(QDir::tempPath() + QLatin1String("/umbrello-layoutgenerator-XXXXXX.png"));
188
189
190
191
    pngFile.open();
    pngFile.close();
    qDebug() << pngViewer() << pngFile.fileName();
    args.clear();
Oliver Kellogg's avatar
Oliver Kellogg committed
192
    args << QLatin1String("-o") << pngFile.fileName() << QLatin1String("-Tpng") << in.fileName();
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
    p.start(executable, args);
    p.waitForFinished();
#endif
#ifndef USE_XDOT
    if (!readGeneratedDotFile(out.fileName()))
#else
    if (!readGeneratedDotFile(xdotOut.fileName()))
#endif
        return false;

    return true;
}

/**
 * apply auto layout to the given scene
 * @param scene
 * @return true if autolayout has been applied
 */
bool LayoutGenerator::apply(UMLScene *scene)
{
    foreach(AssociationWidget *assoc, scene->associationList()) {
        AssociationLine *path = assoc->associationLine();
        QString type = Uml::AssociationType::toString(assoc->associationType()).toLower();
Oliver Kellogg's avatar
Oliver Kellogg committed
216
        QString key = QLatin1String("type::") + type;
217
218

        QString id;
Oliver Kellogg's avatar
Oliver Kellogg committed
219
        if (m_edgeParameters.contains(QLatin1String("id::") + key) && m_edgeParameters[QLatin1String("id::") + key] == QLatin1String("swap"))
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
            id = fixID(Uml::ID::toString(assoc->widgetLocalIDForRole(Uml::RoleType::A)) + Uml::ID::toString(assoc->widgetLocalIDForRole(Uml::RoleType::B)));
        else
            id = fixID(Uml::ID::toString(assoc->widgetLocalIDForRole(Uml::RoleType::B)) + Uml::ID::toString(assoc->widgetLocalIDForRole(Uml::RoleType::A)));

        // adjust associations not used in the dot file
        if (!m_edges.contains(id)) {
            // shorten line path
            AssociationLine *path = assoc->associationLine();
            if (path->count() > 2 && assoc->widgetLocalIDForRole(Uml::RoleType::A) != assoc->widgetLocalIDForRole(Uml::RoleType::B)) {
                while(path->count() > 2)
                    path->removePoint(1);
            }
            continue;
        }

        EdgePoints &p = m_edges[id];
        int len = p.size();

        while(path->count() > 1) {
            path->removePoint(0);
        }
        path->setEndPoints(mapToScene(p[0]), mapToScene(p[len-1]));

        // set label position
        QPointF &l = m_edgeLabelPosition[id];
        FloatingTextWidget *tw = assoc->nameWidget();
        if (tw) {
            tw->setPos(mapToScene(l));
        }
        // FIXME: set remaining association line points
        /*
        for(int i = 1; i < len-1; i++) {
            path->insertPoint(i, mapToScene((p[i]));
        }
        */
        /*
         * here stuff could be added to add more points from information returned by dot.
        */
    }

260
261
    UMLApp::app()->beginMacro(i18n("Apply layout"));

262
263
264
265
266
    foreach(UMLWidget *widget, scene->widgetList()) {
        QString id = Uml::ID::toString(widget->localID());
        if (!m_nodes.contains(id))
            continue;
        QPoint p = origin(id);
267
        widget->setStartMovePosition(widget->pos());
268
269
270
        widget->setX(p.x());
        widget->setY(p.y()-widget->height());
        widget->adjustAssocs(widget->x(), widget->y());    // adjust assoc lines
271
272

        UMLApp::app()->executeCommand(new Uml::CmdMoveWidget(widget));
273
    }
274
    UMLApp::app()->endMacro();
275
276
277
278
279
280

    foreach(AssociationWidget *assoc, scene->associationList()) {
        assoc->calculateEndingPoints();
        if (assoc->associationLine())
            assoc->associationLine()->update();
        assoc->resetTextPositions();
281
        assoc->saveIdealTextPositions();
282
283
284
285
286
287
288
289
290
291
292
293
294
295
    }
    return true;
}

/**
 * Return a list of available templates for a given scene type
 *
 * @param scene The diagram
 * @param configFiles will contain the collected list of config files
 * @return true if collecting succeeds
 */
bool LayoutGenerator::availableConfigFiles(UMLScene *scene, QHash<QString,QString> &configFiles)
{
    QString diagramType = Uml::DiagramType::toString(scene->type()).toLower();
296
297
298
#if QT_VERSION >= 0x050000
    QStringList fileNames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("umbrello/layouts/%1*.desktop").arg(diagramType));
#else
299
    KStandardDirs dirs;
Oliver Kellogg's avatar
Oliver Kellogg committed
300
    QStringList fileNames = dirs.findAllResources("data", QString::fromLatin1("umbrello/layouts/%1*.desktop").arg(diagramType));
301
#endif
302
303
304
    foreach(const QString &fileName, fileNames) {
        QFileInfo fi(fileName);
        QString baseName;
Oliver Kellogg's avatar
Oliver Kellogg committed
305
306
        if (fi.baseName().contains(QLatin1String("-")))
            baseName = fi.baseName().remove(diagramType + QLatin1Char('-'));
307
308
309
        else if (fi.baseName() == diagramType)
            baseName = fi.baseName();
        else
Oliver Kellogg's avatar
Oliver Kellogg committed
310
            baseName = QLatin1String("default");
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
        KDesktopFile desktopFile(fileName);
        configFiles[baseName] = desktopFile.readName();
    }
    return true;
}

/**
 * Return the origin of node based on the bottom/left corner
 *
 * @param id The widget id to fetch the origin from
 * @return QPoint instance with the coordinates
 */
QPoint LayoutGenerator::origin(const QString &id)
{
    QString key = fixID(id);
    if (!m_nodes.contains(key)) {
#ifdef LAYOUTGENERATOR_DATA_DEBUG
        uDebug() << key;
#endif
        return QPoint(0,0);
    }
    QRectF &r = m_nodes[key];
    QPoint p(m_origin.x() + r.x() - r.width()/2, m_boundingRect.height() - r.y() + r.height()/2 + m_origin.y());
#ifdef LAYOUTGENERATOR_DATA_DEBUG
    uDebug() << r << p;
#endif
    return p;
}

/**
 * Read generated dot file and extract positions
 * of the contained widgets.
 *
 * @return true if extracting succeeded
*/
bool LayoutGenerator::readGeneratedDotFile(const QString &fileName)
{
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    QTextStream in(&file);
    while (!in.atEnd()) {
        QString line = in.readLine();
Oliver Kellogg's avatar
Oliver Kellogg committed
355
        while(line.endsWith(QLatin1Char(',')))
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
            line += in.readLine();
        parseLine(line);
    }
    return true;
}

#ifndef USE_XDOT
/**
 * Parse line from dot generated plain-ext output format
 *
 *  The format is documented at http://graphviz.org/content/output-formats#dplain-ext and looks like:
 *
 *   graph 1 28.083 10.222
 *   node ITfDmJvJE00m 8.0833 8.7361 0.86111 0.45833 QObject solid box black lightgrey
 *   edge sL4cKPpHnJkU sL4cKPpHnJkU 7 8.1253 7.2568 8.2695 7.2687 8.375 7.3127 8.375 7.3889 8.375 7.4377 8.3317 7.4733 8.2627 7.4957 Aggregation 8.8472 7.3889 solid black
 *
 * @param line line in dot plain-ext output format
 * @return true if line could be parsed successfully
*/
bool LayoutGenerator::parseLine(const QString &line)
{
Oliver Kellogg's avatar
Oliver Kellogg committed
377
378
    QStringList a = line.split(QLatin1Char(' '));
    if (a[0] == QLatin1String("graph")) {
379
380
        m_boundingRect = QRectF(0, 0, a[2].toDouble()*m_scale, a[3].toDouble()*m_scale);
        return true;
Oliver Kellogg's avatar
Oliver Kellogg committed
381
    } else if (a[0] == QLatin1String("node")) {
382
        QString key = fixID(a[1]);
383
384
        m_nodes[key] = QRectF(a[2].toDouble()*m_scale, a[3].toDouble()*m_scale,
                              a[4].toDouble()*m_scale, a[5].toDouble()*m_scale);
385
        return true;
Oliver Kellogg's avatar
Oliver Kellogg committed
386
    } else if (a[0] == QLatin1String("edge")) {
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
        QString key = fixID(a[1]+a[2]);
        EdgePoints p;
        int len = a[3].toInt();
        for(int i = 0; i < len; i++)
            p.append(QPointF(a[i*2+4].toDouble()*m_scale, a[i*2+5].toDouble()*m_scale));
        m_edges[key] = p;

        int b = len*2 + 4;
        bool ok;
        double x = a[b+1].toDouble(&ok);
        if (!ok)
            return true;
        double y = a[b+2].toDouble(&ok);
        if (!ok)
            return true;
        m_edgeLabelPosition[key] = QPointF(x*m_scale, y*m_scale);

        return true;
Oliver Kellogg's avatar
Oliver Kellogg committed
405
    } else if (a[0] == QLatin1String("stop")) {
406
407
408
409
410
411
412
413
414
415
416
        return true;
    }
    return false;
}

#else
typedef QMap<QString,QStringList> ParameterList;

bool LayoutGenerator::splitParameters(QMap<QString,QStringList> &map, const QString &s)
{
    // FIXME: add shape=box without '"'
Oliver Kellogg's avatar
Oliver Kellogg committed
417
418
    static QRegExp rx(QLatin1String("([a-zA-Z_]+)=\"([a-zA-Z0-9.- #]+)\""));
    static QRegExp rx2(QLatin1String("([a-zA-Z_]+)=([a-zA-Z0-9.- #]+)"));
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
    int pos = 0;
    int count = 0;
    /*
    *        while ((pos = rx2.indexIn(s, pos)) != -1) {
    *            QString key = rx2.cap(1);
    *            QString value = rx2.cap(2);
    *            ++count;
    *            pos += rx2.matchedLength();
    *            //qDebug() << key << value;
    *            if (map.contains(key))
    *                map[key] << value;
    *            else
    *                map[key] = QStringList() << value;
    }
    */
    pos = 0;
    while ((pos = rx.indexIn(s, pos)) != -1) {
        QString key = rx.cap(1);
        QString value = rx.cap(2);
        ++count;
        pos += rx.matchedLength();
        //qDebug() << key << value;

        QStringList data;
Oliver Kellogg's avatar
Oliver Kellogg committed
443
444
445
446
447
        if (key == QLatin1String("pos")) {
            value.remove(QLatin1String("e,"));
            data = value.split(QLatin1Char(' '));
        } else if (key.startsWith(QLatin1Char('_'))) {
            data = value.split(QLatin1Char(' '));
448
        }
Oliver Kellogg's avatar
Oliver Kellogg committed
449
        else if (key == QLatin1String("label"))
450
451
            data = QStringList() << value;
        else
Oliver Kellogg's avatar
Oliver Kellogg committed
452
            data = value.split(QLatin1Char(','));
453
454
455
456
457

        if (map.contains(key))
            map[key] << data;
        else
            map[key] = data;
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
    }
    return true;
}

/**
 *
digraph G {
    graph [splines=polyline, rankdir=BT, outputorder=nodesfirst, ranksep="0.5", nodesep="0.5"];
    node [label="\N"];
    graph [bb="0,0,2893,638",
    _draw_="c 9 -#ffffffff C 9 -#ffffffff P 4 0 -1 0 638 2894 638 2894 -1 ",
    xdotversion="1.2"];
    XC0weWhArzOJ [label=note, shape=box, width="2.5833", height="0.86111", pos="93,31", _draw_="c 9 -#000000ff p 4 186 62 0 62 0 0 186 0 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 93 27 0 24 4 -note "];
    sL4cKPpHnJkU -> ITfDmJvJE00m [arrowhead=normal, weight="1.0", label=" ", pos="e,2326.3,600.47 2299.7,543.57 2306.1,557.22 2314.9,575.99 2322.1,591.39", lp="2319,572", _draw_="c 9 -#000000ff B 4 2300 544 2306 557 2315 576 2322 591 ", _hdraw_="S 5 -solid c 9 -#000000ff C 9 -#000000ff P 3 2319 593 2326 600 2325 590 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 2319 568 0 4 1 -  "];
    sL4cKPpHnJkU -> sL4cKPpHnJkU [label=" ", arrowtail=odiamond, dir=back, constraint=false, pos="s,2339.3,516.43 2351.5,516.59 2365.1,517.35 2375,520.16 2375,525 2375,531.2 2358.7,534.06 2339.3,533.57", lp="2377,525", _draw_="c 9 -#000000ff B 7 2351 517 2365 517 2375 520 2375 525 2375 531 2359 534 2339 534 ", _tdraw_="S 5 -solid c 9 -#000000ff p 4 2351 517 2345 521 2339 516 2345 513 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 2377 521 0 4 1 -  "];
*/

bool LayoutGenerator::parseLine(const QString &line)
{
Oliver Kellogg's avatar
Oliver Kellogg committed
477
    static QRegExp m_cols(QLatin1String("^[\t ]*(.*)[\t ]*\\[(.*)\\]"));
478
479
    static int m_level = -1;

Oliver Kellogg's avatar
Oliver Kellogg committed
480
    if (line.contains(QLatin1Char('{'))) {
481
482
483
        m_level++;
        return true;
    }
Oliver Kellogg's avatar
Oliver Kellogg committed
484
    else if (line.contains(QLatin1Char('}'))) {
485
486
487
488
489
490
491
492
493
494
495
496
497
498
        m_level--;
        return true;
    }
    int pos = 0;
    if (m_cols.indexIn(line, pos) == -1)
        return false;

    QString keyword = m_cols.cap(1).trimmed();
    QString attributeString = m_cols.cap(2);
    uDebug() << keyword << attributeString;
    ParameterList attributes;
    splitParameters(attributes, attributeString);
    uDebug() << attributes;

Oliver Kellogg's avatar
Oliver Kellogg committed
499
500
501
    if (keyword == QLatin1String("graph")) {
        if (attributes.contains(QLatin1String("bb"))) {
            QStringList &a = attributes[QLatin1String("bb")];
502
503
504
505
506
            m_boundingRect.setLeft(a[0].toDouble());
            m_boundingRect.setTop(a[1].toDouble());
            m_boundingRect.setRight(a[2].toDouble());
            m_boundingRect.setBottom(a[3].toDouble());
        }
Oliver Kellogg's avatar
Oliver Kellogg committed
507
    } else if (keyword == QLatin1String("node")) {
508
        return true;
Oliver Kellogg's avatar
Oliver Kellogg committed
509
    } else if (keyword == QLatin1String("edge")) {
510
511
        return true;
    // transistion
Oliver Kellogg's avatar
Oliver Kellogg committed
512
513
    } else if (line.contains(QLatin1String("->"))) {
        QStringList k = keyword.split(QLatin1Char(' '));
514
515
516
517
        if (k.size() < 3)
            return false;
        QString key = fixID(k[0]+k[2]);

Oliver Kellogg's avatar
Oliver Kellogg committed
518
519
        if (attributes.contains(QLatin1String("pos"))) {
            QStringList &a = attributes[QLatin1String("pos")];
520
521
522
            EdgePoints points;

            for(int i = 1; i < a.size(); i++) {
Oliver Kellogg's avatar
Oliver Kellogg committed
523
                QStringList b = a[i].split(QLatin1Char(','));
524
525
526
                QPointF p(b[0].toDouble(), b[1].toDouble());
                points.append(p);
            }
Oliver Kellogg's avatar
Oliver Kellogg committed
527
            QStringList b = a[0].split(QLatin1Char(','));
528
529
530
531
532
            QPointF p(b[0].toDouble(), b[1].toDouble());
            points.append(p);

            m_edges[key] = points;
        }
Oliver Kellogg's avatar
Oliver Kellogg committed
533
534
535
        if (0 && attributes.contains(QLatin1String("_draw_"))) {
            QStringList &a = attributes[QLatin1String("_draw_")];
            if (a.size() < 5 || (a[3] != QLatin1String("L") && a[3] != QLatin1String("p")))
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
                return false;
            int size = a[4].toInt();
            EdgePoints points;

            for(int i = 0; i < size; i++) {
                QPointF p(a[i*2+5].toDouble(), a[i*2+6].toDouble());
                points.append(p);
            }
            m_edges[key] = points;
        }
        return true;
    // single node
    } else {
        double scale = 72.0;
        QRectF f(0, 0, 0, 0);
        QString id = fixID(keyword);
Oliver Kellogg's avatar
Oliver Kellogg committed
552
553
554
        if (attributes.contains(QLatin1String("pos"))) {
            QStringList &a = attributes[QLatin1String("pos")];
            QStringList b = a[0].split(QLatin1Char(','));
555
556
557
            f.setLeft(b[0].toDouble());
            f.setTop(b[1].toDouble());
        }
Oliver Kellogg's avatar
Oliver Kellogg committed
558
559
        if (attributes.contains(QLatin1String("height"))) {
            QStringList &a = attributes[QLatin1String("height")];
560
561
562
            f.setHeight(a[0].toDouble()*scale);
        }

Oliver Kellogg's avatar
Oliver Kellogg committed
563
564
        if (attributes.contains(QLatin1String("width"))) {
            QStringList &a = attributes[QLatin1String("width")];
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
            f.setWidth(a[0].toDouble()*scale);
        }
        uDebug() << "adding" << id << f;
        m_nodes[id] = f;
    }
return true;
}
#endif

/**
 * map dot coordinate to scene coordinate
 * @param p dot point to map
 * @return uml scene coordinate
 */
QPointF LayoutGenerator::mapToScene(const QPointF &p)
{
    return QPointF(p.x()+ m_origin.x(), m_boundingRect.height() - p.y() + m_origin.y());
}

#if 0
static QDebug operator<<(QDebug out, LayoutGenerator &c)
{
    out << "LayoutGenerator:"
        << "m_boundingRect:" << c.m_boundingRect
        << "m_nodes:" << c.m_nodes
        << "m_edges:" << c.m_edges
        << "m_scale:" << c.m_scale
        << "m_executable:" << c.m_executable;
    return out;
}
#endif