Code

a08b9ab8af19bd185fab5ec6ee93e2f2ff95a753
[inkscape.git] / src / libavoid / connector.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libavoid - Fast, Incremental, Object-avoiding Line Router
5  * Copyright (C) 2004-2005  Michael Wybrow <mjwybrow@users.sourceforge.net>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * 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.
16  *
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  * 
21 */
23 #ifndef AVOID_CONNECTOR_H
24 #define AVOID_CONNECTOR_H
26 #include "libavoid/geometry.h"
27 #include "libavoid/shape.h"
28 #include <list>
31 namespace Avoid {
33 class ConnRef;
35 typedef std::list<ConnRef *> ConnRefList;
36 typedef std::list<unsigned int> IntList;
39 class ConnRef
40 {
41     public:
42         ConnRef(const unsigned int id);
43         ConnRef(const unsigned int id, const Point& src, const Point& dst);
44         ~ConnRef();
45         
46         PolyLine& route(void);
47         bool needsReroute(void);
48         void moveRoute(const int& diff_x, const int& diff_y);
49         void freeRoute(void);
50         void calcRouteDist(void);
51         void updateEndPoint(const unsigned int type, const Point& point);
52         void setEndPointId(const unsigned int type, const unsigned int id);
53         void makeActive(void);
54         void makeInactive(void);
55         void lateSetup(const Point& src, const Point& dst);
56         VertInf *src(void);
57         VertInf *dst(void);
58         void removeFromGraph(void);
59         bool isInitialised(void);
60         void unInitialise(void);
61         void setCallback(void (*cb)(void *), void *ptr);
62         void handleInvalid(void);
63         int generatePath(Point p0, Point p1);
64         void makePathInvalid(void);
65         
66         friend void markConnectors(ShapeRef *shape);
67         friend void attachedShapes(IntList &shapes,
68                 const unsigned int shapeId, const unsigned int type);
69         friend void attachedConns(IntList &conns,
70                 const unsigned int shapeId, const unsigned int type);
72         static const unsigned int runningTo;
73         static const unsigned int runningFrom;
74         static const unsigned int runningToAndFrom;
75         
76     private:
77         unsigned int _id;
78         unsigned int _srcId, _dstId;
79         bool _needs_reroute_flag;
80         bool _false_path;
81         bool _active;
82         PolyLine _route;
83         double _route_dist;
84         ConnRefList::iterator _pos;
85         VertInf *_srcVert;
86         VertInf *_dstVert;
87         bool _initialised;
88         void (*_callback)(void *);
89         void *_connector;
90 };
93 extern ConnRefList connRefs;
95 extern void callbackAllInvalidConnectors(void);
96 extern void attachedConns(IntList &conns, const unsigned int shapeId,
97         const unsigned int type);
98 extern void attachedShapes(IntList &shapes, const unsigned int shapeId,
99         const unsigned int type);
104 #endif