|
|
1 | /** |
|
|
2 | * ZANavi, Zoff Android Navigation system. |
|
|
3 | * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc> |
|
|
4 | * |
|
|
5 | * This program is free software; you can redistribute it and/or |
|
|
6 | * modify it under the terms of the GNU General Public License |
|
|
7 | * version 2 as published by the Free Software Foundation. |
|
|
8 | * |
|
|
9 | * This program is distributed in the hope that it will be useful, |
|
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
12 | * GNU General Public License for more details. |
|
|
13 | * |
|
|
14 | * You should have received a copy of the GNU General Public License |
|
|
15 | * along with this program; if not, write to the |
|
|
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
|
17 | * Boston, MA 02110-1301, USA. |
|
|
18 | */ |
|
|
19 | |
1 | /** |
20 | /** |
2 | * Navit, a modular navigation system. |
21 | * Navit, a modular navigation system. |
3 | * Copyright (C) 2005-2008 Navit Team |
22 | * Copyright (C) 2005-2008 Navit Team |
4 | * |
23 | * |
5 | * This program is free software; you can redistribute it and/or |
24 | * This program is free software; you can redistribute it and/or |
… | |
… | |
23 | #include "debug.h" |
42 | #include "debug.h" |
24 | #include "item.h" |
43 | #include "item.h" |
25 | #include "roadprofile.h" |
44 | #include "roadprofile.h" |
26 | #include "vehicleprofile.h" |
45 | #include "vehicleprofile.h" |
27 | |
46 | |
28 | static void |
|
|
29 | vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr) |
47 | static void vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr) |
30 | { |
48 | { |
31 | dbg(1,"%s:%d\n", attr_to_name(attr->type), attr->u.num); |
49 | dbg(1, "%s:%d\n", attr_to_name(attr->type), attr->u.num); |
32 | switch (attr->type) { |
50 | switch (attr->type) |
|
|
51 | { |
33 | case attr_flags: |
52 | case attr_flags: |
34 | this_->flags=attr->u.num; |
53 | this_->flags = attr->u.num; |
35 | break; |
54 | break; |
36 | case attr_flags_forward_mask: |
55 | case attr_flags_forward_mask: |
37 | this_->flags_forward_mask=attr->u.num; |
56 | this_->flags_forward_mask = attr->u.num; |
38 | break; |
57 | break; |
39 | case attr_flags_reverse_mask: |
58 | case attr_flags_reverse_mask: |
40 | this_->flags_reverse_mask=attr->u.num; |
59 | this_->flags_reverse_mask = attr->u.num; |
41 | break; |
60 | break; |
42 | case attr_maxspeed_handling: |
61 | case attr_maxspeed_handling: |
43 | this_->maxspeed_handling=attr->u.num; |
62 | this_->maxspeed_handling = attr->u.num; |
44 | break; |
63 | break; |
45 | case attr_route_mode: |
64 | case attr_route_mode: |
46 | this_->mode=attr->u.num; |
65 | this_->mode = attr->u.num; |
47 | break; |
66 | break; |
48 | case attr_name: |
67 | case attr_name: |
49 | if(this_->name) |
68 | if (this_->name) |
50 | g_free(this_->name); |
69 | g_free(this_->name); |
51 | /* previously used strdupn not available on win32 */ |
70 | /* previously used strdupn not available on win32 */ |
52 | this_->name = g_strdup(attr->u.str); |
71 | this_->name = g_strdup(attr->u.str); |
53 | break; |
72 | break; |
54 | case attr_vehicle_axle_weight: |
73 | case attr_vehicle_axle_weight: |
55 | this_->axle_weight=attr->u.num; |
74 | this_->axle_weight = attr->u.num; |
56 | break; |
75 | break; |
57 | case attr_vehicle_height: |
76 | case attr_vehicle_height: |
58 | this_->height=attr->u.num; |
77 | this_->height = attr->u.num; |
59 | break; |
78 | break; |
60 | case attr_vehicle_length: |
79 | case attr_vehicle_length: |
61 | this_->length=attr->u.num; |
80 | this_->length = attr->u.num; |
62 | break; |
81 | break; |
63 | case attr_vehicle_weight: |
82 | case attr_vehicle_weight: |
64 | this_->weight=attr->u.num; |
83 | this_->weight = attr->u.num; |
65 | break; |
84 | break; |
66 | case attr_vehicle_width: |
85 | case attr_vehicle_width: |
67 | this_->width=attr->u.num; |
86 | this_->width = attr->u.num; |
68 | break; |
87 | break; |
69 | case attr_static_speed: |
88 | case attr_static_speed: |
70 | this_->static_speed=attr->u.num; |
89 | this_->static_speed = attr->u.num; |
71 | break; |
90 | break; |
72 | case attr_static_distance: |
91 | case attr_static_distance: |
73 | this_->static_distance=attr->u.num; |
92 | this_->static_distance = attr->u.num; |
74 | break; |
93 | break; |
75 | case attr_through_traffic_penalty: |
94 | case attr_through_traffic_penalty: |
76 | this_->through_traffic_penalty=attr->u.num; |
95 | this_->through_traffic_penalty = attr->u.num; |
77 | break; |
96 | break; |
78 | default: |
97 | default: |
79 | break; |
98 | break; |
80 | } |
99 | } |
81 | } |
100 | } |
82 | |
101 | |
83 | struct vehicleprofile * |
102 | struct vehicleprofile * |
84 | vehicleprofile_new(struct attr *parent, struct attr **attrs) |
103 | vehicleprofile_new(struct attr *parent, struct attr **attrs) |
85 | { |
104 | { |
86 | dbg(0,"EEnter\n"); |
105 | dbg(0, "EEnter\n"); |
87 | |
106 | |
88 | struct vehicleprofile *this_; |
107 | struct vehicleprofile *this_; |
89 | struct attr **attr, *type_attr; |
108 | struct attr **attr, *type_attr; |
90 | if (! (type_attr=attr_search(attrs, NULL, attr_name))) { |
109 | if (!(type_attr = attr_search(attrs, NULL, attr_name))) |
|
|
110 | { |
91 | return NULL; |
111 | return NULL; |
92 | } |
|
|
93 | this_=g_new0(struct vehicleprofile, 1); |
112 | } this_=g_new0(struct vehicleprofile, 1); |
94 | this_->attrs=attr_list_dup(attrs); |
113 | this_->attrs = attr_list_dup(attrs); |
95 | this_->roadprofile_hash=g_hash_table_new(NULL, NULL); |
114 | this_->roadprofile_hash = g_hash_table_new(NULL, NULL); |
96 | this_->length=-1; |
115 | this_->length = -1; |
97 | this_->width=-1; |
116 | this_->width = -1; |
98 | this_->height=-1; |
117 | this_->height = -1; |
99 | this_->weight=-1; |
118 | this_->weight = -1; |
100 | this_->axle_weight=-1; |
119 | this_->axle_weight = -1; |
101 | this_->through_traffic_penalty=9000; |
120 | this_->through_traffic_penalty = 9000; |
102 | for (attr=attrs;*attr; attr++) |
121 | for (attr = attrs; *attr; attr++) |
103 | { |
122 | { |
104 | vehicleprofile_set_attr_do(this_, *attr); |
123 | vehicleprofile_set_attr_do(this_, *attr); |
105 | } |
124 | } |
106 | |
125 | |
107 | dbg(0,"return\n"); |
126 | dbg(0, "return\n"); |
108 | return this_; |
127 | return this_; |
109 | } |
128 | } |
110 | |
129 | |
111 | int |
|
|
112 | vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) |
130 | int vehicleprofile_get_attr(struct vehicleprofile *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) |
113 | { |
131 | { |
114 | return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter); |
132 | return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter); |
115 | } |
133 | } |
116 | |
134 | |
117 | int |
|
|
118 | vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr) |
135 | int vehicleprofile_set_attr(struct vehicleprofile *this_, struct attr *attr) |
119 | { |
136 | { |
120 | vehicleprofile_set_attr_do(this_, attr); |
137 | vehicleprofile_set_attr_do(this_, attr); |
121 | this_->attrs=attr_generic_set_attr(this_->attrs, attr); |
138 | this_->attrs = attr_generic_set_attr(this_->attrs, attr); |
122 | return 1; |
139 | return 1; |
123 | } |
140 | } |
124 | |
141 | |
125 | int |
|
|
126 | vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr) |
142 | int vehicleprofile_add_attr(struct vehicleprofile *this_, struct attr *attr) |
127 | { |
143 | { |
128 | struct attr item_types_attr; |
144 | struct attr item_types_attr; |
129 | this_->attrs=attr_generic_add_attr(this_->attrs, attr); |
145 | this_->attrs = attr_generic_add_attr(this_->attrs, attr); |
130 | switch (attr->type) { |
146 | switch (attr->type) |
|
|
147 | { |
131 | case attr_roadprofile: |
148 | case attr_roadprofile: |
132 | if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL)) { |
149 | if (roadprofile_get_attr(attr->u.roadprofile, attr_item_types, &item_types_attr, NULL)) |
|
|
150 | { |
133 | enum item_type *types=item_types_attr.u.item_types; |
151 | enum item_type *types = item_types_attr.u.item_types; |
134 | while (*types != type_none) { |
152 | while (*types != type_none) |
|
|
153 | { |
135 | g_hash_table_insert(this_->roadprofile_hash, (void *)(long)(*types), attr->u.roadprofile); |
154 | g_hash_table_insert(this_->roadprofile_hash, (void *) (long) (*types), attr->u.roadprofile); |
136 | types++; |
155 | types++; |
|
|
156 | } |
137 | } |
157 | } |
138 | } |
|
|
139 | break; |
158 | break; |
140 | default: |
159 | default: |
141 | break; |
160 | break; |
142 | } |
161 | } |
143 | return 1; |
162 | return 1; |
144 | } |
163 | } |
145 | |
164 | |
146 | int |
|
|
147 | vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr) |
165 | int vehicleprofile_remove_attr(struct vehicleprofile *this_, struct attr *attr) |
148 | { |
166 | { |
149 | this_->attrs=attr_generic_remove_attr(this_->attrs, attr); |
167 | this_->attrs = attr_generic_remove_attr(this_->attrs, attr); |
150 | return 1; |
168 | return 1; |
151 | } |
169 | } |
152 | |
170 | |
153 | struct roadprofile * |
171 | struct roadprofile * |
154 | vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type) |
172 | vehicleprofile_get_roadprofile(struct vehicleprofile *this_, enum item_type type) |
155 | { |
173 | { |
156 | return g_hash_table_lookup(this_->roadprofile_hash, (void *)(long)type); |
174 | return g_hash_table_lookup(this_->roadprofile_hash, (void *) (long) type); |
157 | } |
175 | } |
158 | |
176 | |
159 | char * |
177 | char * |
160 | vehicleprofile_get_name(struct vehicleprofile *this_) |
178 | vehicleprofile_get_name(struct vehicleprofile *this_) |
161 | { |
179 | { |
162 | return this_->name; |
180 | return this_->name; |
163 | } |
181 | } |