@@ -19,40 +19,48 @@ use self::rand::Rng;
19
19
use self :: image:: { DynamicImage , GenericImage , Pixel , Rgba , RgbaImage , ImageFormat } ;
20
20
21
21
22
- pub fn get_image ( model : ModelContainer ) -> ( image:: ImageBuffer < image:: Bgra < u8 > , Vec < u8 > > , ( u32 , u32 ) ) {
22
+ pub fn get_image ( mut model : ModelContainer ) -> ( image:: ImageBuffer < image:: Bgra < u8 > , Vec < u8 > > , ( u32 , u32 ) ) {
23
23
24
24
let ( mut dim_x, mut dim_y) = ( 1 , 1 ) ;
25
25
let mut layout_vec = Vec :: new ( ) ;
26
26
let mut layout2_vec = Vec :: new ( ) ;
27
27
28
+
28
29
// Get the layout vec and picture dimensions
29
30
match model. model_type {
30
31
ModelType :: ClassModel => {
32
+ let cm = model. class_model . unwrap ( ) ;
31
33
let ( a, b, c, d) = generator:: generate_class_model_layout (
32
- & model . class_model . classes ,
33
- & model . class_model . relations
34
+ & cm . classes ,
35
+ & cm . relations
34
36
) ;
35
37
layout_vec = a;
36
38
layout2_vec = b;
37
39
dim_x = c;
38
40
dim_y = d;
41
+ model = ModelContainer { model_type : ModelType :: ClassModel , class_model : Some ( cm) , object_model : None , package_model : None , use_case_model : None } ;
39
42
}
40
43
ModelType :: ObjectModel => {
44
+ let om = model. object_model . unwrap ( ) ;
41
45
let ( a, b, c, d) = generator:: generate_object_model_layout (
42
- & model . object_model . objects ,
43
- & model . object_model . links
46
+ & om . objects ,
47
+ & om . links
44
48
) ;
45
49
layout_vec = a;
46
50
layout2_vec = b;
47
51
dim_x = c;
48
52
dim_y = d;
53
+ model = ModelContainer { model_type : ModelType :: ObjectModel , class_model : None , object_model : Some ( om) , package_model : None , use_case_model : None } ;
49
54
}
50
55
ModelType :: PackageModel => {
51
56
// TODO
52
57
}
53
58
ModelType :: UseCaseModel => {
54
59
// TODO
55
60
}
61
+ ModelType :: None => {
62
+ // Done
63
+ }
56
64
}
57
65
58
66
println ! ( "x: {}, y:{}" , dim_x, dim_y) ;
@@ -113,10 +121,11 @@ pub fn get_image(model: ModelContainer) -> (image::ImageBuffer<image::Bgra<u8>,
113
121
// ------ DRAW ------
114
122
match model. model_type {
115
123
ModelType :: ClassModel => {
116
- for ( i, c) in model. class_model . classes . iter ( ) . enumerate ( ) {
124
+ let cm = model. class_model . unwrap ( ) ;
125
+ for ( i, c) in cm. classes . iter ( ) . enumerate ( ) {
117
126
draw_class ( & mut img_buf, & general, & font_vec, & c, & layout_vec[ i] ) ;
118
127
}
119
- for ( i, r) in model . class_model . relations . iter ( ) . enumerate ( ) {
128
+ for ( i, r) in cm . relations . iter ( ) . enumerate ( ) {
120
129
draw_rel ( & mut img_buf, & general,
121
130
& font_vec,
122
131
& r,
@@ -128,13 +137,14 @@ pub fn get_image(model: ModelContainer) -> (image::ImageBuffer<image::Bgra<u8>,
128
137
}
129
138
}
130
139
ModelType :: ObjectModel => {
131
- for ( i, o) in model. object_model . objects . iter ( ) . enumerate ( ) {
140
+ let om = model. object_model . unwrap ( ) ;
141
+ for ( i, o) in om. objects . iter ( ) . enumerate ( ) {
132
142
draw_object ( & mut img_buf, & general, & font_vec, & o, & layout_vec[ i] ) ;
133
143
}
134
- for ( i, r ) in model . object_model . links . iter ( ) . enumerate ( ) {
144
+ for ( i, l ) in om . links . iter ( ) . enumerate ( ) {
135
145
draw_link ( & mut img_buf, & general,
136
146
& font_vec,
137
- & r ,
147
+ & l ,
138
148
& layout2_vec[ i] . start ,
139
149
& layout2_vec[ i] . end ,
140
150
layout2_vec[ i] . base_first ,
@@ -148,6 +158,9 @@ pub fn get_image(model: ModelContainer) -> (image::ImageBuffer<image::Bgra<u8>,
148
158
ModelType :: UseCaseModel => {
149
159
// TODO
150
160
}
161
+ ModelType :: None => {
162
+ // Done
163
+ }
151
164
}
152
165
153
166
//---------
@@ -207,10 +220,10 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
207
220
208
221
// Draw all other lines of text or just lines
209
222
let mut deco_font: u32 = 0 ;
210
- for ( i, line) in class. content_lines . iter ( ) . enumerate ( ) {
223
+ for ( i, line) in class. lines . iter ( ) . enumerate ( ) {
211
224
let mut is_horizontal_line: bool = false ;
212
225
let mut is_underlined: bool = false ;
213
- match class. content_decor [ i] {
226
+ match class. lines [ i] . decor {
214
227
TextDecoration :: None => {
215
228
}
216
229
TextDecoration :: HorizontalLine => {
@@ -229,7 +242,7 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
229
242
is_underlined = true ;
230
243
}
231
244
}
232
- if is_horizontal_line || line. is_empty ( ) || line == "-" {
245
+ if is_horizontal_line || line. content . is_empty ( ) || line. content == "-" {
233
246
draw_hollow_rect_mut (
234
247
buffer, imageproc:: rect:: Rect :: at (
235
248
class_layout. lt . x as i32 , class_layout. lt . y as i32 ) . of_size (
@@ -239,13 +252,13 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
239
252
} else {
240
253
draw_text_mut (
241
254
buffer, colors. black , class_layout. lt . x + :: PADDING_LEFT ,
242
- height_to_write_at, scales. two , & fonts[ deco_font as usize ] , & line) ;
255
+ height_to_write_at, scales. two , & fonts[ deco_font as usize ] , & line. content ) ;
243
256
if is_underlined {
244
257
draw_line_segment_mut ( buffer,
245
258
( ( class_layout. lt . x + :: PADDING_LEFT ) as f32 ,
246
259
height_to_write_at as f32 + :: LINE_HEIGHT as f32 - 6.0 ) ,
247
260
( ( class_layout. lt . x + :: PADDING_LEFT ) as f32 +
248
- ( :: LETTER_WIDTH as f32 * ( line. len ( ) as f32 - 1.0 ) ) ,
261
+ ( :: LETTER_WIDTH as f32 * ( line. content . len ( ) as f32 - 1.0 ) ) ,
249
262
height_to_write_at as f32 + :: LINE_HEIGHT as f32 - 6.0 ) ,
250
263
general. colors . black ) ;
251
264
}
@@ -295,10 +308,10 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
295
308
296
309
// Draw all other lines of text or just lines
297
310
let mut deco_font: u32 = 0 ;
298
- for ( i, line) in class. content_lines . iter ( ) . enumerate ( ) {
311
+ for ( i, line) in class. lines . iter ( ) . enumerate ( ) {
299
312
let mut is_horizontal_line: bool = false ;
300
313
let mut is_underlined: bool = false ;
301
- match class. content_decor [ i] {
314
+ match class. lines [ i] . decor {
302
315
TextDecoration :: None => {
303
316
}
304
317
TextDecoration :: HorizontalLine => {
@@ -317,7 +330,7 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
317
330
is_underlined = true ;
318
331
}
319
332
}
320
- if is_horizontal_line || line. is_empty ( ) || line == "-" {
333
+ if is_horizontal_line || line. content . is_empty ( ) || line. content == "-" {
321
334
draw_hollow_rect_mut (
322
335
buffer, imageproc:: rect:: Rect :: at (
323
336
class_layout. lt . x as i32 , class_layout. lt . y as i32 ) . of_size (
@@ -327,13 +340,13 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
327
340
} else {
328
341
draw_text_mut (
329
342
buffer, colors. black , class_layout. lt . x + :: PADDING_LEFT ,
330
- height_to_write_at, scales. two , & fonts[ deco_font as usize ] , & line) ;
343
+ height_to_write_at, scales. two , & fonts[ deco_font as usize ] , & line. content ) ;
331
344
if is_underlined {
332
345
draw_line_segment_mut ( buffer,
333
346
( ( class_layout. lt . x + :: PADDING_LEFT ) as f32 ,
334
347
height_to_write_at as f32 + :: LINE_HEIGHT as f32 - 6.0 ) ,
335
348
( ( class_layout. lt . x + :: PADDING_LEFT ) as f32 +
336
- ( :: LETTER_WIDTH as f32 * ( line. len ( ) as f32 - 1.0 ) ) ,
349
+ ( :: LETTER_WIDTH as f32 * ( line. content . len ( ) as f32 - 1.0 ) ) ,
337
350
height_to_write_at as f32 + :: LINE_HEIGHT as f32 - 6.0 ) ,
338
351
general. colors . black ) ;
339
352
}
@@ -389,10 +402,10 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
389
402
390
403
// Draw all other lines of text or just lines
391
404
let mut deco_font: u32 = 0 ;
392
- for ( i, line) in class. content_lines . iter ( ) . enumerate ( ) {
405
+ for ( i, line) in class. lines . iter ( ) . enumerate ( ) {
393
406
let mut is_horizontal_line: bool = false ;
394
407
let mut is_underlined: bool = false ;
395
- match class. content_decor [ i] {
408
+ match class. lines [ i] . decor {
396
409
TextDecoration :: None => {
397
410
}
398
411
TextDecoration :: HorizontalLine => {
@@ -411,7 +424,7 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
411
424
is_underlined = true ;
412
425
}
413
426
}
414
- if is_horizontal_line || line. is_empty ( ) || line == "-" {
427
+ if is_horizontal_line || line. content . is_empty ( ) || line. content == "-" {
415
428
draw_hollow_rect_mut (
416
429
buffer, imageproc:: rect:: Rect :: at (
417
430
class_layout. lt . x as i32 , class_layout. lt . y as i32 ) . of_size (
@@ -421,13 +434,13 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
421
434
} else {
422
435
draw_text_mut (
423
436
buffer, colors. black , class_layout. lt . x + :: ACTIVE_PADDING ,
424
- height_to_write_at, scales. two , & fonts[ deco_font as usize ] , & line) ;
437
+ height_to_write_at, scales. two , & fonts[ deco_font as usize ] , & line. content ) ;
425
438
if is_underlined {
426
439
draw_line_segment_mut ( buffer,
427
440
( ( class_layout. lt . x + :: ACTIVE_PADDING ) as f32 ,
428
441
height_to_write_at as f32 + :: LINE_HEIGHT as f32 - 6.0 ) ,
429
442
( ( class_layout. lt . x + :: ACTIVE_PADDING ) as f32 +
430
- ( :: LETTER_WIDTH as f32 * ( line. len ( ) as f32 - 1.0 ) ) ,
443
+ ( :: LETTER_WIDTH as f32 * ( line. content . len ( ) as f32 - 1.0 ) ) ,
431
444
height_to_write_at as f32 + :: LINE_HEIGHT as f32 - 6.0 ) ,
432
445
general. colors . black ) ;
433
446
}
0 commit comments