QTfrontend/drawmapscene.cpp
author nemo
Sun, 13 May 2012 14:56:05 -0400
changeset 7076 fed718e7851d
parent 6952 7f70f37bbf08
child 7146 a822413207c9
permissions -rw-r--r--
Dammit Xeli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
     1
/*
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6952
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6935
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    15
 * along with this program; if not, write to the Free Software
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    17
 */
088d40d8aba2 Happy 2011 :)
koda
parents: 4938
diff changeset
    18
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    19
#include <QGraphicsSceneMouseEvent>
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    20
#include <QGraphicsPathItem>
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    21
#include <QtEndian>
4937
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    22
#include <QDebug>
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    23
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    24
#include "drawmapscene.h"
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    25
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    26
template <class T> T sqr(const T & x)
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    27
{
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    28
    return x*x;
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    29
}
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    30
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    31
DrawMapScene::DrawMapScene(QObject *parent) :
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    32
    QGraphicsScene(parent),
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    33
    m_pen(Qt::yellow),
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    34
    m_brush(Qt::yellow),
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    35
    m_cursor(new QGraphicsEllipseItem(-0.5, -0.5, 1, 1))
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    36
{
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    37
    setSceneRect(0, 0, 4096, 2048);
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    38
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    39
    QLinearGradient gradient(0, 0, 0, 2048);
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    40
    gradient.setColorAt(0, QColor(60, 60, 155));
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    41
    gradient.setColorAt(1, QColor(155, 155, 60));
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    42
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    43
    m_eraser = QBrush(gradient);
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    44
    setBackgroundBrush(m_eraser);
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    45
    m_isErasing = false;
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    46
6784
2c02ccb8f4ec Oops, fix range (2 is too small value)
unc0rr
parents: 6781
diff changeset
    47
    m_pen.setWidth(76);
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    48
    m_pen.setJoinStyle(Qt::RoundJoin);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    49
    m_pen.setCapStyle(Qt::RoundCap);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    50
    m_currPath = 0;
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    51
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    52
    m_isCursorShown = false;
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    53
    m_cursor->setPen(QPen(Qt::green));
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    54
    m_cursor->setZValue(1);
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    55
    m_cursor->setScale(m_pen.width());
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    56
}
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    57
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    58
void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    59
{
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    60
    if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton))
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    61
    {
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    62
        QPainterPath path = m_currPath->path();
4937
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    63
4938
0985edac2ad7 use ctrl instead of alt to avoid colliding with linux window positioning
nemo
parents: 4937
diff changeset
    64
        if(mouseEvent->modifiers() & Qt::ControlModifier)
4937
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    65
        {
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    66
            int c = path.elementCount();
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    67
            QPointF pos = mouseEvent->scenePos();
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    68
            path.setElementPositionAt(c - 1, pos.x(), pos.y());
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    69
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    70
        }
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
    71
        else
4937
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    72
        {
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    73
            path.lineTo(mouseEvent->scenePos());
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    74
            paths.first().points.append(mouseEvent->scenePos().toPoint());
4937
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    75
        }
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    76
        m_currPath->setPath(path);
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    77
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    78
        emit pathChanged();
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    79
    }
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    80
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    81
    if(!m_isCursorShown)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    82
        showCursor();
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
    83
    m_cursor->setPos(mouseEvent->scenePos());
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    84
}
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    85
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    86
void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    87
{
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    88
    m_currPath = addPath(QPainterPath(), m_pen);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    89
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    90
    QPainterPath path = m_currPath->path();
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    91
    QPointF p = mouseEvent->scenePos();
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    92
    p += QPointF(0.01, 0.01);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    93
    path.moveTo(p);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    94
    path.lineTo(mouseEvent->scenePos());
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    95
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    96
    PathParams params;
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    97
    params.width = serializePenWidth(m_pen.width());
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    98
    params.erasing = m_isErasing;
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
    99
    params.points = QList<QPoint>() << mouseEvent->scenePos().toPoint();
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   100
    paths.prepend(params);
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
   101
    m_currPath->setPath(path);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
   102
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   103
    emit pathChanged();
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
   104
}
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
   105
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
   106
void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
   107
{
5108
b7483e29ea8c Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents: 5040
diff changeset
   108
    if (m_currPath)
b7483e29ea8c Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents: 5040
diff changeset
   109
    {
b7483e29ea8c Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents: 5040
diff changeset
   110
        QPainterPath path = m_currPath->path();
b7483e29ea8c Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents: 5040
diff changeset
   111
        path.lineTo(mouseEvent->scenePos());
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   112
        paths.first().points.append(mouseEvent->scenePos().toPoint());
5108
b7483e29ea8c Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents: 5040
diff changeset
   113
        m_currPath->setPath(path);
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   114
5108
b7483e29ea8c Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents: 5040
diff changeset
   115
        simplifyLast();
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   116
5108
b7483e29ea8c Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents: 5040
diff changeset
   117
        m_currPath = 0;
b7483e29ea8c Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents: 5040
diff changeset
   118
    }
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
   119
}
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
   120
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   121
void DrawMapScene::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent)
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   122
{
6784
2c02ccb8f4ec Oops, fix range (2 is too small value)
unc0rr
parents: 6781
diff changeset
   123
    if(wheelEvent->delta() > 0 && m_pen.width() < 516)
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   124
        m_pen.setWidth(m_pen.width() + 10);
6784
2c02ccb8f4ec Oops, fix range (2 is too small value)
unc0rr
parents: 6781
diff changeset
   125
    else if(wheelEvent->delta() < 0 && m_pen.width() >= 16)
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   126
        m_pen.setWidth(m_pen.width() - 10);
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   127
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   128
    m_cursor->setScale(m_pen.width());
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   129
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   130
    if(m_currPath)
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   131
    {
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   132
        m_currPath->setPen(m_pen);
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   133
        paths.first().width = serializePenWidth(m_pen.width());
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   134
    }
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   135
}
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   136
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   137
void DrawMapScene::showCursor()
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   138
{
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   139
    qDebug() << "show cursor";
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   140
    if(!m_isCursorShown)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   141
        addItem(m_cursor);
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   142
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   143
    m_isCursorShown = true;
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   144
}
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   145
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   146
void DrawMapScene::hideCursor()
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   147
{
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   148
    qDebug() << "hide cursor";
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   149
    if(m_isCursorShown)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   150
        removeItem(m_cursor);
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   151
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   152
    m_isCursorShown = false;
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   153
}
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   154
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
   155
void DrawMapScene::undo()
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
   156
{
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   157
    // cursor is a part of items()
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   158
    if(m_isCursorShown)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   159
        return;
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   160
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
   161
    if(items().size())
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   162
    {
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
   163
        removeItem(items().first());
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   164
        paths.removeFirst();
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   165
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   166
        emit pathChanged();
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   167
    }
5858
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   168
    else if(oldItems.size())
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   169
    {
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   170
        while(oldItems.size())
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   171
            addItem(oldItems.takeFirst());
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   172
        paths = oldPaths;
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   173
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   174
        emit pathChanged();
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   175
    }
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
   176
}
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   177
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   178
void DrawMapScene::clearMap()
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   179
{
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   180
    // cursor is a part of items()
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   181
    if(m_isCursorShown)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   182
        return;
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   183
5858
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   184
    // don't clear if already cleared
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   185
    if(!items().size())
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   186
        return;
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   187
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   188
    oldItems.clear();
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   189
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   190
    // do this since clear() would _destroy_ all items
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
   191
    while(items().size())
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
   192
    {
5858
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   193
        oldItems.push_front(items().first());
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   194
        removeItem(items().first());
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   195
    }
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   196
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   197
    oldPaths = paths;
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   198
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   199
    paths.clear();
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   200
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   201
    emit pathChanged();
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   202
}
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   203
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   204
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   205
void DrawMapScene::setErasing(bool erasing)
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   206
{
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   207
    m_isErasing = erasing;
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   208
    if(erasing)
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   209
        m_pen.setBrush(m_eraser);
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   210
    else
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   211
        m_pen.setBrush(m_brush);
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   212
}
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   213
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   214
QByteArray DrawMapScene::encode()
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   215
{
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   216
    QByteArray b;
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   217
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   218
    for(int i = paths.size() - 1; i >= 0; --i)
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   219
    {
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   220
        int cnt = 0;
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   221
        PathParams params = paths.at(i);
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   222
        foreach(QPoint point, params.points)
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   223
        {
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   224
            qint16 px = qToBigEndian((qint16)point.x());
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   225
            qint16 py = qToBigEndian((qint16)point.y());
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   226
            quint8 flags = 0;
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   227
            if(!cnt) flags = 0x80 + params.width;
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   228
            if(params.erasing) flags |= 0x40;
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   229
            b.append((const char *)&px, 2);
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   230
            b.append((const char *)&py, 2);
4457
ffb766e85150 - Change painted map file format
unc0rr
parents: 4442
diff changeset
   231
            b.append((const char *)&flags, 1);
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   232
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   233
            ++cnt;
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   234
        }
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   235
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   236
    }
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   237
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   238
    return b;
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   239
}
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   240
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   241
void DrawMapScene::decode(QByteArray data)
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   242
{
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   243
    bool erasing = m_isErasing;
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   244
5858
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   245
    oldItems.clear();
1f4a8cf9efcb hand drawn map editor: allow "undo" after "clear"
sheepluva
parents: 5108
diff changeset
   246
    oldPaths.clear();
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   247
    clear();
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   248
    paths.clear();
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   249
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   250
    PathParams params;
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   251
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   252
    while(data.size() >= 5)
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   253
    {
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   254
        qint16 px = qFromBigEndian(*(qint16 *)data.data());
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   255
        data.remove(0, 2);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   256
        qint16 py = qFromBigEndian(*(qint16 *)data.data());
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   257
        data.remove(0, 2);
4457
ffb766e85150 - Change painted map file format
unc0rr
parents: 4442
diff changeset
   258
        quint8 flags = *(quint8 *)data.data();
ffb766e85150 - Change painted map file format
unc0rr
parents: 4442
diff changeset
   259
        data.remove(0, 1);
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   260
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   261
        if(flags & 0x80)
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   262
        {
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   263
            if(params.points.size())
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   264
            {
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   265
                addPath(pointsToPath(params.points), m_pen);
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   266
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   267
                paths.prepend(params);
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   268
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   269
                params.points.clear();
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   270
            }
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   271
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   272
            quint8 penWidth = flags & 0x3f;
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   273
            m_pen.setWidth(deserializePenWidth(penWidth));
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   274
            if(flags & 0x40)
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   275
                m_pen.setBrush(m_eraser);
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   276
            else
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   277
                m_pen.setBrush(m_brush);
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   278
            params.width = penWidth;
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   279
        }
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   280
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   281
        params.points.append(QPoint(px, py));
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   282
    }
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   283
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   284
    if(params.points.size())
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   285
    {
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   286
        addPath(pointsToPath(params.points), m_pen);
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   287
        paths.prepend(params);
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   288
    }
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   289
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   290
    emit pathChanged();
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   291
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   292
    setErasing(erasing);
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   293
}
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   294
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   295
void DrawMapScene::simplifyLast()
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   296
{
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   297
    if(!paths.size()) return;
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   298
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   299
    QList<QPoint> points = paths.at(0).points;
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   300
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   301
    QPoint prevPoint = points.first();
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   302
    int i = 1;
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   303
    while(i < points.size())
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   304
    {
4471
220d44cb8659 Always keep last point of drawn polyline
unc0rr
parents: 4457
diff changeset
   305
        if( (i != points.size() - 1)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
   306
                && (sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000)
4471
220d44cb8659 Always keep last point of drawn polyline
unc0rr
parents: 4457
diff changeset
   307
          )
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   308
            points.removeAt(i);
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   309
        else
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   310
        {
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   311
            prevPoint = points[i];
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   312
            ++i;
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   313
        }
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   314
    }
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   315
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   316
    paths[0].points = points;
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   317
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   318
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   319
    // redraw path
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   320
    {
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   321
        QGraphicsPathItem * pathItem = static_cast<QGraphicsPathItem *>(items()[m_isCursorShown ? 1 : 0]);
6873
30840365af0a Eraser tool
unc0rr
parents: 6784
diff changeset
   322
        pathItem->setPath(pointsToPath(paths[0].points));
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   323
    }
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   324
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   325
    emit pathChanged();
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   326
}
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   327
6935
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   328
int DrawMapScene::pointsCount()
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   329
{
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   330
    int cnt = 0;
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   331
    foreach(PathParams p, paths)
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   332
        cnt += p.points.size();
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   333
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   334
    return cnt;
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   335
}
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   336
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   337
QPainterPath DrawMapScene::pointsToPath(const QList<QPoint> points)
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   338
{
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   339
    QPainterPath path;
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   340
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   341
    if(points.size())
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   342
    {
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   343
        QPointF p = points[0] + QPointF(0.01, 0.01);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   344
        path.moveTo(p);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   345
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   346
        foreach(QPoint p, points)
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 5858
diff changeset
   347
        path.lineTo(p);
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   348
    }
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   349
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   350
    return path;
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   351
}
6781
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   352
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   353
quint8 DrawMapScene::serializePenWidth(int width)
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   354
{
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   355
    return (width - 6) / 10;
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   356
}
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   357
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   358
int DrawMapScene::deserializePenWidth(quint8 width)
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   359
{
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   360
    return width * 10 + 6;
23f627ba8ee9 Variable pen width
unc0rr
parents: 6700
diff changeset
   361
}