~ubuntu-branches/ubuntu/precise/inkscape/precise-updates

« back to all changes in this revision

Viewing changes to src/libavoid/shape.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alex Valavanis
  • Date: 2010-09-12 19:44:58 UTC
  • mfrom: (1.1.12 upstream) (45.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20100912194458-4sjwmbl7dlsrk5dc
Tags: 0.48.0-1ubuntu1
* Merge with Debian unstable (LP: #628048, LP: #401567, LP: #456248, 
  LP: #463602, LP: #591986)
* debian/control: 
  - Ubuntu maintainers
  - Promote python-lxml, python-numpy, python-uniconvertor to Recommends.
  - Demote pstoedit to Suggests (universe package).
  - Suggests ttf-dejavu instead of ttf-bitstream-vera (LP: #513319)
* debian/rules:
  - Run intltool-update on build (Ubuntu-specific).
  - Add translation domain to .desktop files (Ubuntu-specific).
* debian/dirs:
  - Add usr/share/pixmaps.  Allow inkscape.xpm installation
* drop 50-poppler-API.dpatch (now upstream)
* drop 51-paste-in-unwritable-directory.dpatch (now upstream) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * vim: ts=4 sw=4 et tw=0 wm=0
3
3
 *
4
4
 * libavoid - Fast, Incremental, Object-avoiding Line Router
5
 
 * Copyright (C) 2004-2006  Michael Wybrow <mjwybrow@users.sourceforge.net>
 
5
 *
 
6
 * Copyright (C) 2004-2008  Monash University
6
7
 *
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.
 
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.
11
17
 *
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.  
16
21
 *
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
20
 
 * 
 
22
 * Author(s):   Michael Wybrow <mjwybrow@users.sourceforge.net>
21
23
*/
22
24
 
23
 
#include <cassert>
24
25
 
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"
30
32
 
31
33
 
32
34
namespace Avoid {
33
35
 
34
36
 
35
 
ShapeRef::ShapeRef(Router *router, unsigned int id, Polygn& ply)
 
37
ShapeRef::ShapeRef(Router *router, Polygon& ply, const unsigned int id)
36
38
    : _router(router)
37
 
    , _id(id)
38
 
    , _poly(copyPoly(ply))
 
39
    , _poly(ply)
39
40
    , _active(false)
40
41
    , _inMoveList(false)
41
42
    , _firstVert(NULL)
42
43
    , _lastVert(NULL)
43
44
{
 
45
    _id = router->assignId(id);
 
46
 
44
47
    bool isShape = true;
45
 
    VertID i = VertID(id, isShape, 0);
 
48
    VertID i = VertID(_id, isShape, 0);
46
49
    
 
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)
50
54
    {
51
 
        node = new VertInf(_router, i, _poly.ps[pt_i]);
 
55
        node = new VertInf(_router, i, _poly.ps[pt_i], addToRouterNow);
52
56
 
53
57
        if (!_firstVert)
54
58
        {
69
73
    
70
74
    _lastVert->shNext = _firstVert;
71
75
    _firstVert->shPrev = _lastVert;
72
 
    
73
 
    makeActive();
74
76
}
75
77
 
76
78
 
77
79
ShapeRef::~ShapeRef()
78
80
{
79
 
    assert(_firstVert != NULL);
 
81
    COLA_ASSERT(!_router->shapeInQueuedActionList(this));
 
82
 
 
83
    if (_active)
 
84
    {
 
85
        // Destroying a shape without calling removeShape(), so do it now.
 
86
        _router->removeShape(this);
 
87
        _router->processTransaction();
 
88
    }
 
89
 
 
90
    COLA_ASSERT(_firstVert != NULL);
80
91
    
81
 
    makeInactive();
82
 
 
83
92
    VertInf *it = _firstVert;
84
93
    do
85
94
    {
90
99
    }
91
100
    while (it != _firstVert);
92
101
    _firstVert = _lastVert = NULL;
93
 
 
94
 
    freePoly(_poly);
95
102
}
96
103
 
97
104
 
98
 
void ShapeRef::setNewPoly(Polygn& poly)
 
105
void ShapeRef::setNewPoly(const Polygon& poly)
99
106
{
100
 
    assert(_firstVert != NULL);
101
 
    assert(_poly.pn == poly.pn);
 
107
    COLA_ASSERT(_firstVert != NULL);
 
108
    COLA_ASSERT(_poly.size() == poly.size());
102
109
    
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)
105
112
    {
106
 
        assert(curr->visListSize == 0);
107
 
        assert(curr->invisListSize == 0);
 
113
        COLA_ASSERT(curr->visListSize == 0);
 
114
        COLA_ASSERT(curr->invisListSize == 0);
108
115
 
109
116
        // Reset with the new polygon point.
110
117
        curr->Reset(poly.ps[pt_i]);
111
118
        curr->pathNext = NULL;
112
 
        curr->pathDist = 0;
113
119
        
114
120
        curr = curr->shNext;
115
121
    }
116
 
    assert(curr == _firstVert);
 
122
    COLA_ASSERT(curr == _firstVert);
117
123
        
118
 
    freePoly(_poly);
119
 
    _poly = copyPoly(poly);
 
124
    _poly = poly;
120
125
}
121
126
 
122
127
 
123
128
void ShapeRef::makeActive(void)
124
129
{
125
 
    assert(!_active);
 
130
    COLA_ASSERT(!_active);
126
131
    
127
 
    // Add to connRefs list.
 
132
    // Add to shapeRefs list.
128
133
    _pos = _router->shapeRefs.insert(_router->shapeRefs.begin(), this);
129
134
 
130
135
    // Add points to vertex list.
144
149
 
145
150
void ShapeRef::makeInactive(void)
146
151
{
147
 
    assert(_active);
 
152
    COLA_ASSERT(_active);
148
153
    
149
 
    // Remove from connRefs list.
 
154
    // Remove from shapeRefs list.
150
155
    _router->shapeRefs.erase(_pos);
151
156
 
152
157
    // Remove points from vertex list.
162
167
    
163
168
    _active = false;
164
169
}
165
 
    
 
170
 
 
171
 
 
172
bool ShapeRef::isActive(void) const
 
173
{
 
174
    return _active;
 
175
}
 
176
 
166
177
 
167
178
VertInf *ShapeRef::firstVert(void)
168
179
{
176
187
}
177
188
 
178
189
 
179
 
unsigned int ShapeRef::id(void)
 
190
unsigned int ShapeRef::id(void) const
180
191
{
181
192
    return _id;
182
193
}
183
194
 
184
195
 
185
 
Polygn ShapeRef::poly(void)
 
196
const Polygon& ShapeRef::polygon(void) const
186
197
{
187
198
    return _poly;
188
199
}
189
200
 
190
201
 
191
 
Router *ShapeRef::router(void)
 
202
Router *ShapeRef::router(void) const
192
203
{
193
204
    return _router;
194
205
}
196
207
 
197
208
void ShapeRef::boundingBox(BBox& bbox)
198
209
{
199
 
    assert(_poly.pn > 0);
 
210
    COLA_ASSERT(!_poly.empty());
200
211
 
201
212
    bbox.a = bbox.b = _poly.ps[0];
202
213
    Point& a = bbox.a;
203
214
    Point& b = bbox.b;
204
215
 
205
 
    for (int i = 1; i < _poly.pn; ++i)
 
216
    for (size_t i = 1; i < _poly.size(); ++i)
206
217
    {
207
218
        const Point& p = _poly.ps[i];
208
219
 
223
234
        
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)
229
240
        {
230
241
            // Remove each visibility edge
239
250
            // Remove each invisibility edge
240
251
            delete (*edge);
241
252
        }
 
253
 
 
254
        EdgeInfList& orthogList = tmp->orthogVisList;
 
255
        finish = orthogList.end();
 
256
        while ((edge = orthogList.begin()) != finish)
 
257
        {
 
258
            // Remove each orthogonal visibility edge
 
259
            (*edge)->alertConns();
 
260
            delete (*edge);
 
261
        }
242
262
    }
243
263
}
244
264
 
251
271
    }
252
272
    else
253
273
    {
254
 
        fprintf(stderr, "WARNING: two moves queued for same shape prior to "
255
 
                "rerouting.\n         This is not safe.\n");
 
274
        db_printf("WARNING: two moves queued for same shape prior to rerouting."
 
275
                "\n         This is not safe.\n");
256
276
    }
257
277
}
258
278