Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
actioninfo.cpp
Go to the documentation of this file.
1/*
2 * vim: ts=4 sw=4 et tw=0 wm=0
3 *
4 * libavoid - Fast, Incremental, Object-avoiding Line Router
5 *
6 * Copyright (C) 2004-2011 Monash University
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 * See the file LICENSE.LGPL distributed with the library.
13 *
14 * Licensees holding a valid commercial license may use this file in
15 * accordance with the commercial license agreement provided with the
16 * library.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 *
22 * Author(s): Michael Wybrow
23*/
24
25
26#include <algorithm>
27
28#include "libavoid/actioninfo.h"
29#include "libavoid/shape.h"
30#include "libavoid/connector.h"
31#include "libavoid/junction.h"
32
33namespace Avoid {
34
35
37 : type(t),
38 objPtr(s),
39 newPoly(p),
40 firstMove(fM)
41{
42 COLA_ASSERT(type == ShapeMove);
43}
44
45
47 : type(t),
48 objPtr(s)
49
50{
51 COLA_ASSERT((type == ShapeAdd) || (type == ShapeRemove) ||
52 (type == ShapeMove));
53}
54
55
57 : type(t),
58 objPtr(j),
59 newPosition(p)
60{
61 COLA_ASSERT(type == JunctionMove);
62}
63
64
66 : type(t),
67 objPtr(j)
68{
69 COLA_ASSERT((type == JunctionAdd) || (type == JunctionRemove) ||
70 (type == JunctionMove));
71}
72
74 : type(t),
75 objPtr(c)
76{
77 COLA_ASSERT(type == ConnChange);
78}
79
80
82 : type(t),
83 objPtr(p)
84{
85 COLA_ASSERT(type == ConnectionPinChange);
86}
87
88
92
93
95{
96 COLA_ASSERT((type == ShapeMove) || (type == ShapeAdd) ||
97 (type == ShapeRemove) || (type == JunctionMove) ||
98 (type == JunctionAdd) || (type == JunctionRemove));
99 return (static_cast<Obstacle *> (objPtr));
100}
101
102
104{
105 return (dynamic_cast<ShapeRef *> (obstacle()));
106}
107
108
110{
111 COLA_ASSERT(type == ConnChange);
112 return (static_cast<ConnRef *> (objPtr));
113}
114
116{
117 return (dynamic_cast<JunctionRef *> (obstacle()));
118}
119
120
121void ActionInfo::addConnEndUpdate(const unsigned int type,
122 const ConnEnd& connEnd, bool isConnPinMoveUpdate)
123{
124 bool alreadyExists = false;
125 for (ConnUpdateList::iterator conn = conns.begin();
126 conn != conns.end(); ++conn)
127 {
128 // Look for an existing queued change to the same end.
129 if (conn->first == type)
130 {
131 // Found a queued change to the same endpoint of the
132 // connector. If this is a pin change as a result of a
133 // shape move, then leave the user created update
134 // that was found (since it may be moving the connection
135 // to connect to a different shape/pin. But if this is a
136 // user change, then overwrite the previous change.
137 alreadyExists = true;
138 if (!isConnPinMoveUpdate)
139 {
140 // Overwrite the queued change with this one.
141 conn->second = connEnd;
142 }
143 break;
144 }
145 }
146
147 if (!alreadyExists)
148 {
149 // Matching change not found, so add this one.
150 conns.push_back(std::make_pair(type, connEnd));
151 }
152}
153
154
155bool ActionInfo::operator==(const ActionInfo& rhs) const
156{
157 return (type == rhs.type) && (objPtr == rhs.objPtr);
158}
159
160
161bool ActionInfo::operator<(const ActionInfo& rhs) const
162{
163 if (type != rhs.type)
164 {
165 return type < rhs.type;
166 }
167
168 if (type == ConnChange)
169 {
170 return conn()->id() < rhs.conn()->id();
171 }
172 else if (type == ConnectionPinChange)
173 {
174 // NOTE Comparing pointers may not preserve the order of
175 // objects, but the order of Connection Pins is not
176 // used so this is not an issue here.
177 return objPtr < rhs.objPtr;
178 }
179 else
180 {
181 return obstacle()->id() < rhs.obstacle()->id();
182 }
183}
184
185
186}
187
bool operator==(const ActionInfo &rhs) const
Obstacle * obstacle(void) const
ShapeRef * shape(void) const
ConnRef * conn(void) const
void addConnEndUpdate(const unsigned int type, const ConnEnd &connEnd, bool isConnPinMoveUpdate)
JunctionRef * junction(void) const
ConnUpdateList conns
Definition actioninfo.h:82
bool operator<(const ActionInfo &rhs) const
ActionInfo(ActionType t, ShapeRef *s, const Polygon &p, bool fM)
ActionType type
Definition actioninfo.h:77
The ConnEnd class represents different possible endpoints for connectors.
Definition connend.h:111
The ConnRef class represents a connector object.
Definition connector.h:132
unsigned int id(void) const
Returns the ID of this connector.
The JunctionRef class represents a fixed or free-floating point that connectors can be attached to.
Definition junction.h:58
unsigned int id(void) const
Returns the ID of this obstacle.
Definition obstacle.cpp:249
The Point class defines a point in the plane.
Definition geomtypes.h:53
A dynamic Polygon, to which points can be easily added and removed.
Definition geomtypes.h:208
The ShapeConnectionPin class represents a fixed point or "pin" on a shape that can be connected to.
The ShapeRef class represents a shape object.
Definition shape.h:82
Contains the interface for the ConnRef class.
double c[8][4]
Contains the interface for the JunctionRef class.
libavoid: Object-avoiding orthogonal and polyline connector routing library.
@ ConnChange
Definition actioninfo.h:53
@ JunctionMove
Definition actioninfo.h:50
@ ShapeAdd
Definition actioninfo.h:48
@ ShapeRemove
Definition actioninfo.h:49
@ JunctionRemove
Definition actioninfo.h:52
@ ShapeMove
Definition actioninfo.h:47
@ JunctionAdd
Definition actioninfo.h:51
@ ConnectionPinChange
Definition actioninfo.h:54
Contains the interface for the ShapeRef class.