Skip to content
This repository was archived by the owner on Jan 25, 2019. It is now read-only.

Commit 928c3dc

Browse files
Connect parser and Gui
1 parent 9fdc5ff commit 928c3dc

File tree

6 files changed

+57
-71
lines changed

6 files changed

+57
-71
lines changed

input.txt

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,31 @@
11
Model:Class
22

33
AbstractClass:Person
4+
--
45
private String name
56
private String vorname
67
--
7-
public String getFullName()
8+
public static String getFullName()
89

910
Class:Angestellter
11+
--
1012
private static int ID
11-
private String position
13+
private String<ll> position
1214
--
1315
public Auftrag auftragErstellen()
14-
public void auftragBearbeiten()
16+
public void auftragBearbeiten<lol>()
1517

1618
Class:Auftrag
19+
--
1720
private MyList<Item> inhalt
1821
private boolean done
1922
--
20-
public void setDone(boolean isDone)
23+
public void setDone(booleanisDone)
2124
public int getCumulativePrice()
2225
public ArrayList<Item> getInhalt()
2326

2427
Class:Item
25-
private String description
26-
private int singlePrice
27-
private int countInStock
2828
--
29-
public String getDescription()
30-
public int getSinglePrice()
31-
public int getCountInStock()
32-
public void changeCountInStock(int amount)
33-
34-
Class:MyList
35-
36-
Class:List
37-
<<interface>>
38-
39-
Inheritance
40-
Angestellter,Person
41-
1,1
42-
43-
Association
44-
Angestellter,Auftrag
45-
0..n,1
46-
47-
Aggregation
48-
Item,Auftrag
49-
1,1..n
50-
51-
Implementation
52-
MyList,List
53-
54-
Association
55-
Auftrag,MyList
29+
private String description
5630

5731
/Model
58-
>>>>>>> Stashed changes

output.png

3.55 KB
Loading

src/drawer.rs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,48 @@ use self::rand::Rng;
1919
use self::image::{DynamicImage, GenericImage, Pixel, Rgba, RgbaImage, ImageFormat};
2020

2121

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)) {
2323

2424
let (mut dim_x, mut dim_y) = (1, 1);
2525
let mut layout_vec = Vec::new();
2626
let mut layout2_vec = Vec::new();
2727

28+
2829
// Get the layout vec and picture dimensions
2930
match model.model_type {
3031
ModelType::ClassModel => {
32+
let cm = model.class_model.unwrap();
3133
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
3436
);
3537
layout_vec = a;
3638
layout2_vec = b;
3739
dim_x = c;
3840
dim_y = d;
41+
model = ModelContainer { model_type: ModelType::ClassModel, class_model: Some(cm), object_model:None, package_model:None, use_case_model:None };
3942
}
4043
ModelType::ObjectModel => {
44+
let om = model.object_model.unwrap();
4145
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
4448
);
4549
layout_vec = a;
4650
layout2_vec = b;
4751
dim_x = c;
4852
dim_y = d;
53+
model = ModelContainer { model_type: ModelType::ObjectModel, class_model:None, object_model: Some(om), package_model:None, use_case_model:None };
4954
}
5055
ModelType::PackageModel => {
5156
// TODO
5257
}
5358
ModelType::UseCaseModel => {
5459
// TODO
5560
}
61+
ModelType::None => {
62+
// Done
63+
}
5664
}
5765

5866
println!("x: {}, y:{}", dim_x, dim_y);
@@ -113,10 +121,11 @@ pub fn get_image(model: ModelContainer) -> (image::ImageBuffer<image::Bgra<u8>,
113121
// ------ DRAW ------
114122
match model.model_type {
115123
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() {
117126
draw_class(&mut img_buf, &general, &font_vec, &c, &layout_vec[i]);
118127
}
119-
for (i, r) in model.class_model.relations.iter().enumerate() {
128+
for (i, r) in cm.relations.iter().enumerate() {
120129
draw_rel(&mut img_buf, &general,
121130
&font_vec,
122131
&r,
@@ -128,13 +137,14 @@ pub fn get_image(model: ModelContainer) -> (image::ImageBuffer<image::Bgra<u8>,
128137
}
129138
}
130139
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() {
132142
draw_object(&mut img_buf, &general, &font_vec, &o, &layout_vec[i]);
133143
}
134-
for (i, r) in model.object_model.links.iter().enumerate() {
144+
for (i, l) in om.links.iter().enumerate() {
135145
draw_link(&mut img_buf, &general,
136146
&font_vec,
137-
&r,
147+
&l,
138148
&layout2_vec[i].start,
139149
&layout2_vec[i].end,
140150
layout2_vec[i].base_first,
@@ -148,6 +158,9 @@ pub fn get_image(model: ModelContainer) -> (image::ImageBuffer<image::Bgra<u8>,
148158
ModelType::UseCaseModel => {
149159
// TODO
150160
}
161+
ModelType::None => {
162+
// Done
163+
}
151164
}
152165

153166
//---------
@@ -207,10 +220,10 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
207220

208221
// Draw all other lines of text or just lines
209222
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() {
211224
let mut is_horizontal_line: bool = false;
212225
let mut is_underlined: bool = false;
213-
match class.content_decor[i] {
226+
match class.lines[i].decor {
214227
TextDecoration::None => {
215228
}
216229
TextDecoration::HorizontalLine => {
@@ -229,7 +242,7 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
229242
is_underlined = true;
230243
}
231244
}
232-
if is_horizontal_line || line.is_empty() || line == "-" {
245+
if is_horizontal_line || line.content.is_empty() || line.content == "-" {
233246
draw_hollow_rect_mut(
234247
buffer, imageproc::rect::Rect::at(
235248
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
239252
} else {
240253
draw_text_mut(
241254
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);
243256
if is_underlined {
244257
draw_line_segment_mut(buffer,
245258
((class_layout.lt.x + ::PADDING_LEFT) as f32,
246259
height_to_write_at as f32 + ::LINE_HEIGHT as f32 - 6.0),
247260
((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)),
249262
height_to_write_at as f32 + ::LINE_HEIGHT as f32 - 6.0),
250263
general.colors.black);
251264
}
@@ -295,10 +308,10 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
295308

296309
// Draw all other lines of text or just lines
297310
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() {
299312
let mut is_horizontal_line: bool = false;
300313
let mut is_underlined: bool = false;
301-
match class.content_decor[i] {
314+
match class.lines[i].decor {
302315
TextDecoration::None => {
303316
}
304317
TextDecoration::HorizontalLine => {
@@ -317,7 +330,7 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
317330
is_underlined = true;
318331
}
319332
}
320-
if is_horizontal_line || line.is_empty() || line == "-" {
333+
if is_horizontal_line || line.content.is_empty() || line.content == "-" {
321334
draw_hollow_rect_mut(
322335
buffer, imageproc::rect::Rect::at(
323336
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
327340
} else {
328341
draw_text_mut(
329342
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);
331344
if is_underlined {
332345
draw_line_segment_mut(buffer,
333346
((class_layout.lt.x + ::PADDING_LEFT) as f32,
334347
height_to_write_at as f32 + ::LINE_HEIGHT as f32 - 6.0),
335348
((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)),
337350
height_to_write_at as f32 + ::LINE_HEIGHT as f32 - 6.0),
338351
general.colors.black);
339352
}
@@ -389,10 +402,10 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
389402

390403
// Draw all other lines of text or just lines
391404
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() {
393406
let mut is_horizontal_line: bool = false;
394407
let mut is_underlined: bool = false;
395-
match class.content_decor[i] {
408+
match class.lines[i].decor {
396409
TextDecoration::None => {
397410
}
398411
TextDecoration::HorizontalLine => {
@@ -411,7 +424,7 @@ pub fn draw_class(buffer: &mut image::ImageBuffer<image::Bgra<u8>, Vec<u8>>, gen
411424
is_underlined = true;
412425
}
413426
}
414-
if is_horizontal_line || line.is_empty() || line == "-" {
427+
if is_horizontal_line || line.content.is_empty() || line.content == "-" {
415428
draw_hollow_rect_mut(
416429
buffer, imageproc::rect::Rect::at(
417430
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
421434
} else {
422435
draw_text_mut(
423436
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);
425438
if is_underlined {
426439
draw_line_segment_mut(buffer,
427440
((class_layout.lt.x + ::ACTIVE_PADDING) as f32,
428441
height_to_write_at as f32 + ::LINE_HEIGHT as f32 - 6.0),
429442
((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)),
431444
height_to_write_at as f32 + ::LINE_HEIGHT as f32 - 6.0),
432445
general.colors.black);
433446
}

src/generator.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn generate_class_model_layout(class_vec: &[Class], rel_vec: &[Relation]) ->
3838
if !c.class_stereotype.is_empty() {
3939
greatest_height += 1;
4040
}
41-
greatest_height += c.content_lines.len() as u32;
41+
greatest_height += c.lines.len() as u32;
4242
}
4343
if greatest_height > greatest_height_first_half {
4444
greatest_height_first_half = greatest_height;
@@ -56,7 +56,7 @@ pub fn generate_class_model_layout(class_vec: &[Class], rel_vec: &[Relation]) ->
5656
if !c.class_stereotype.is_empty() {
5757
greatest_height += 1;
5858
}
59-
greatest_height += c.content_lines.len() as u32;
59+
greatest_height += c.lines.len() as u32;
6060
}
6161
if greatest_height > greatest_height_second_half {
6262
greatest_height_second_half = greatest_height;
@@ -76,9 +76,9 @@ pub fn generate_class_model_layout(class_vec: &[Class], rel_vec: &[Relation]) ->
7676
for (i,c) in class_vec.iter().enumerate() {
7777

7878
let mut greatest_width: u32 = 0;
79-
for line in c.content_lines.iter() {
80-
if line.len() as u32 > greatest_width {
81-
greatest_width = line.len() as u32;
79+
for line in c.lines.iter() {
80+
if line.content.len() as u32 > greatest_width {
81+
greatest_width = line.content.len() as u32;
8282
}
8383
}
8484
if !c.class_name.is_empty() {
@@ -101,7 +101,7 @@ pub fn generate_class_model_layout(class_vec: &[Class], rel_vec: &[Relation]) ->
101101
if !c.class_stereotype.is_empty() {
102102
height += 1;
103103
}
104-
height += c.content_lines.len() as u32;
104+
height += c.lines.len() as u32;
105105

106106
height *= ::LINE_HEIGHT;
107107

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ extern crate rand;
77
extern crate nom;
88

99
pub(crate) mod parser;
10-
//pub(crate) mod generator;
11-
//pub(crate) mod drawer;
10+
pub(crate) mod generator;
11+
pub(crate) mod drawer;
1212
mod reader;
13-
use reader::*;
14-
//mod gui;
13+
mod gui;
1514
mod defines;
1615
use std::str::*;
1716
use std::env::*;
@@ -86,6 +85,7 @@ fn main() {
8685
// let (classes, relations) = parser::init(&input_filename).unwrap();
8786
// let image_buf = generator::generate_pic(&classes, &relations);
8887
// image_buf.save(&Path::new(&output_filename)).unwrap();
88+
8989
}
9090

9191
type InputFilePath = String;

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub fn parse_model(lines: &[String]) -> Result<ModelContainer, ParseError> {
291291
count = count + count;
292292
}
293293

294-
let mc = match m_type {
294+
let mut mc = match m_type {
295295
ModelType::ClassModel => {
296296
let class_model = match cd_class_model(all_lines.as_bytes()){
297297
Ok(val) => val.1,

0 commit comments

Comments
 (0)