2
2
* vim: ts=4 sw=4 et tw=0 wm=0
4
4
* libavoid - Fast, Incremental, Object-avoiding Line Router
5
* Copyright (C) 2004-2006 Michael Wybrow <mjwybrow@users.sourceforge.net>
6
* Copyright (C) 2004-2008 Monash University
7
8
* This library is free software; you can redistribute it and/or
8
9
* modify it under the terms of the GNU Lesser General Public
9
10
* License as published by the Free Software Foundation; either
10
11
* version 2.1 of the License, or (at your option) any later version.
12
* See the file LICENSE.LGPL distributed with the library.
14
* Licensees holding a valid commercial license may use this file in
15
* accordance with the commercial license agreement provided with the
12
18
* This library is distributed in the hope that it will be useful,
13
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
* Author(s): Michael Wybrow <mjwybrow@users.sourceforge.net>
25
26
#include "libavoid/shape.h"
26
27
#include "libavoid/graph.h" // For alertConns
27
28
#include "libavoid/vertices.h"
28
#include "libavoid/polyutil.h"
29
29
#include "libavoid/router.h"
30
#include "libavoid/debug.h"
31
#include "libavoid/assertions.h"
35
ShapeRef::ShapeRef(Router *router, unsigned int id, Polygn& ply)
37
ShapeRef::ShapeRef(Router *router, Polygon& ply, const unsigned int id)
38
, _poly(copyPoly(ply))
40
41
, _inMoveList(false)
45
_id = router->assignId(id);
44
47
bool isShape = true;
45
VertID i = VertID(id, isShape, 0);
48
VertID i = VertID(_id, isShape, 0);
50
const bool addToRouterNow = false;
47
51
VertInf *last = NULL;
48
52
VertInf *node = NULL;
49
for (int pt_i = 0; pt_i < _poly.pn; pt_i++)
53
for (size_t pt_i = 0; pt_i < _poly.size(); ++pt_i)
51
node = new VertInf(_router, i, _poly.ps[pt_i]);
55
node = new VertInf(_router, i, _poly.ps[pt_i], addToRouterNow);
70
74
_lastVert->shNext = _firstVert;
71
75
_firstVert->shPrev = _lastVert;
77
79
ShapeRef::~ShapeRef()
79
assert(_firstVert != NULL);
81
COLA_ASSERT(!_router->shapeInQueuedActionList(this));
85
// Destroying a shape without calling removeShape(), so do it now.
86
_router->removeShape(this);
87
_router->processTransaction();
90
COLA_ASSERT(_firstVert != NULL);
83
92
VertInf *it = _firstVert;
91
100
while (it != _firstVert);
92
101
_firstVert = _lastVert = NULL;
98
void ShapeRef::setNewPoly(Polygn& poly)
105
void ShapeRef::setNewPoly(const Polygon& poly)
100
assert(_firstVert != NULL);
101
assert(_poly.pn == poly.pn);
107
COLA_ASSERT(_firstVert != NULL);
108
COLA_ASSERT(_poly.size() == poly.size());
103
110
VertInf *curr = _firstVert;
104
for (int pt_i = 0; pt_i < _poly.pn; pt_i++)
111
for (size_t pt_i = 0; pt_i < _poly.size(); ++pt_i)
106
assert(curr->visListSize == 0);
107
assert(curr->invisListSize == 0);
113
COLA_ASSERT(curr->visListSize == 0);
114
COLA_ASSERT(curr->invisListSize == 0);
109
116
// Reset with the new polygon point.
110
117
curr->Reset(poly.ps[pt_i]);
111
118
curr->pathNext = NULL;
114
120
curr = curr->shNext;
116
assert(curr == _firstVert);
122
COLA_ASSERT(curr == _firstVert);
119
_poly = copyPoly(poly);
123
128
void ShapeRef::makeActive(void)
130
COLA_ASSERT(!_active);
127
// Add to connRefs list.
132
// Add to shapeRefs list.
128
133
_pos = _router->shapeRefs.insert(_router->shapeRefs.begin(), this);
130
135
// Add points to vertex list.
224
235
// For each vertex.
225
236
EdgeInfList& visList = tmp->visList;
226
EdgeInfList::iterator finish = visList.end();
227
EdgeInfList::iterator edge;
237
EdgeInfList::const_iterator finish = visList.end();
238
EdgeInfList::const_iterator edge;
228
239
while ((edge = visList.begin()) != finish)
230
241
// Remove each visibility edge