Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

1122 drawing layer fill patterns #1272

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
161f3fe
feat(#1122): fillPatterns, labels, icons
danielsteinkogler Mar 4, 2024
13a0b5e
feat(#1122): use backend types
danielsteinkogler Mar 28, 2024
b3cd314
Change fill_enabled => fill_pattern in backend.
horenso Apr 1, 2024
f3e49b0
feat(#1122): change type of fill pattern
danielsteinkogler Apr 3, 2024
146c575
feat(#1122): fix texts
danielsteinkogler Apr 9, 2024
67f3629
add migration for shape types
danielsteinkogler Apr 9, 2024
601e53e
Add text+images to drawings backend.
horenso Apr 11, 2024
389ccba
feat(#1122): fix types and make text editable
danielsteinkogler Apr 11, 2024
7be682c
feat(#1122): fillPatterns, labels, icons
danielsteinkogler Mar 4, 2024
cda48a4
feat(#1122): use backend types
danielsteinkogler Mar 28, 2024
4a1d641
Change fill_enabled => fill_pattern in backend.
horenso Apr 1, 2024
836769c
feat(#1122): change type of fill pattern
danielsteinkogler Apr 3, 2024
178907b
feat(#1122): fix texts
danielsteinkogler Apr 9, 2024
68b6d00
add migration for shape types
danielsteinkogler Apr 9, 2024
bef4ece
Add text+images to drawings backend.
horenso Apr 11, 2024
ef9ee61
feat(#1122): fix types and make text editable
danielsteinkogler Apr 11, 2024
948b4f9
Merge branch '1122-drawingLayer-fillPatterns' of https://github.com/E…
danielsteinkogler Apr 11, 2024
8ba2236
add changelog entry
danielsteinkogler Apr 11, 2024
867748e
feat(#1122): remove ts-ignore and some renaming
danielsteinkogler Apr 12, 2024
a4f34e1
Merge branch 'master' into 1122-drawingLayer-fillPatterns
danielsteinkogler Apr 12, 2024
b1d5aba
feat(#1122): add new fill patterns
danielsteinkogler Apr 12, 2024
433d840
Merge branch 'master' into 1122-drawingLayer-fillPatterns
danielsteinkogler Apr 12, 2024
a0a2639
feat(#1122): scale preview shapes
danielsteinkogler Apr 12, 2024
4d74f3e
Merge branch '1122-drawingLayer-fillPatterns' of https://github.com/E…
danielsteinkogler Apr 12, 2024
20a803f
feat(#1122): edit description for adding image
danielsteinkogler Apr 16, 2024
3575379
feat(#1122): edit translations
danielsteinkogler Apr 16, 2024
8893408
Merge branch 'master' into 1122-drawingLayer-fillPatterns
danielsteinkogler Apr 16, 2024
777afc9
Fix migrations.
horenso Apr 16, 2024
835c23e
Combine two migrations into one.
horenso Apr 16, 2024
7df9a03
Merge branch 'master' into 1122-drawingLayer-fillPatterns
markus2330 Apr 19, 2024
7883c41
Merge branch 'master' into 1122-drawingLayer-fillPatterns
danielsteinkogler Apr 23, 2024
c4c717a
feat(1122): fix typos
danielsteinkogler Apr 23, 2024
254593f
update editable text input
danielsteinkogler Apr 23, 2024
3414558
added water fill pattern
danielsteinkogler Apr 23, 2024
625fa22
fix bezier polygon
danielsteinkogler Apr 23, 2024
1b0804c
fix scale of wave pattern
danielsteinkogler Apr 24, 2024
568375a
feat(#1122): fix pattern scaling of polygon
danielsteinkogler Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions backend/migrations/2024-04-01-191448_add_image_and_text/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ALTER TYPE drawing_shape_type RENAME TO drawing_shape_type_old;

CREATE TYPE drawing_shape_type AS ENUM (
'rectangle',
'ellipse',
'free line',
'bezier polygon'
);

ALTER TABLE drawings ALTER COLUMN shape_type TYPE drawing_shape_type USING shape_type::text::drawing_shape_type;

DROP TYPE drawing_shape_type_old;

ALTER TABLE drawings
ADD COLUMN color varchar,
ADD COLUMN fill_enabled boolean,
ADD COLUMN stroke_width real;

UPDATE drawings
SET
color = '',
fill_enabled = false,
stroke_width = 1.0;


ALTER TABLE drawings ALTER COLUMN color SET NOT NULL;
ALTER TABLE drawings ALTER COLUMN fill_enabled SET NOT NULL;
ALTER TABLE drawings ALTER COLUMN stroke_width SET NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TYPE drawing_shape_type ADD VALUE 'label text';
ALTER TYPE drawing_shape_type ADD VALUE 'image';

ALTER TABLE drawings
DROP COLUMN color,
DROP COLUMN fill_enabled,
DROP COLUMN stroke_width;
36 changes: 34 additions & 2 deletions backend/src/config/api_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use utoipa_swagger_ui::SwaggerUi;
use super::auth::Config;
use crate::{
controller::{
base_layer_image, blossoms, config, guided_tours, layers, map, plant_layer, plantings,
plants, seed, timeline, users,
base_layer_image, blossoms, config, drawings, guided_tours, layers, map, plant_layer,
plantings, plants, seed, timeline, users,
},
model::{
dto::{
Expand All @@ -20,6 +20,11 @@ use crate::{
ActionDtoWrapperNewPlantings, ActionDtoWrapperUpdatePlantings,
TimelinePagePlantingsDto,
},
drawings::{
DrawingDto, EllipseProperties, FreeLineProperties, ImageProperties,
LabelTextProperties, PolygonProperties, RectangleProperties,
UpdateAddDateDrawingDto, UpdateRemoveDateDrawingDto,
},
plantings::{
MovePlantingDto, NewPlantingDto, PlantingDto, TransformPlantingDto,
UpdateAddDatePlantingDto, UpdatePlantingDto, UpdatePlantingNoteDto,
Expand Down Expand Up @@ -256,6 +261,32 @@ struct BlossomsApiDoc;
)]
struct TimelineApiDoc;

/// Struct used by [`utoipa`] to generate `OpenApi` documentation for drawings endpoints.
#[derive(OpenApi)]
#[openapi(
paths(
drawings::find,
drawings::create,
drawings::update,
drawings::delete,
),
components(
schemas(
DrawingDto,
RectangleProperties,
EllipseProperties,
FreeLineProperties,
PolygonProperties,
LabelTextProperties,
ImageProperties,
UpdateAddDateDrawingDto,
UpdateRemoveDateDrawingDto
)
),
modifiers(&SecurityAddon)
)]
struct DrawingsApiDoc;

/// Merges `OpenApi` and then serves it using `Swagger`.
pub fn config(cfg: &mut web::ServiceConfig) {
let mut openapi = ConfigApiDoc::openapi();
Expand All @@ -268,6 +299,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
openapi.merge(PlantingsApiDoc::openapi());
openapi.merge(UsersApiDoc::openapi());
openapi.merge(TimelineApiDoc::openapi());
openapi.merge(DrawingsApiDoc::openapi());

cfg.service(SwaggerUi::new("/doc/api/swagger/ui/{_:.*}").url("/doc/api/openapi.json", openapi));
}
Expand Down
95 changes: 90 additions & 5 deletions backend/src/model/dto/drawings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use typeshare::typeshare;
use utoipa::ToSchema;
use uuid::Uuid;

use crate::model::r#enum::drawing_shape_type::DrawingShapeType;

/// Represents user drawing.
#[typeshare]
#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DrawingDto {
pub id: Uuid,
pub shape_type: DrawingShapeType,

pub variant: DrawingVariant,

pub layer_id: i32,
pub add_date: Option<NaiveDate>,
pub remove_date: Option<NaiveDate>,
Expand All @@ -21,10 +21,95 @@ pub struct DrawingDto {
pub scale_y: f32,
pub x: i32,
pub y: i32,
}

#[typeshare]
#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RectangleProperties {
pub width: f32,
pub height: f32,
pub color: String,
pub fill_pattern: FillPatternType,
pub stroke_width: f32,
}

#[typeshare]
#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EllipseProperties {
pub radius_x: f32,
pub radius_y: f32,
pub color: String,
pub fill_pattern: FillPatternType,
pub stroke_width: f32,
}

#[typeshare]
#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FreeLineProperties {
pub points: Vec<Vec<f32>>,
pub color: String,
pub fill_pattern: FillPatternType,
pub stroke_width: f32,
}

#[typeshare]
#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PolygonProperties {
pub points: Vec<Vec<f32>>,
pub color: String,
pub fill_enabled: bool,
pub fill_pattern: FillPatternType,
pub stroke_width: f32,
pub properties: serde_json::Value,
}

#[typeshare]
#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LabelTextProperties {
pub text: String,
pub width: i32,
pub height: i32,
pub color: String,
}

#[typeshare]
#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ImageProperties {
pub path: String,
}

/// Represents user drawing.
#[typeshare]
#[derive(Debug, Clone, Deserialize, ToSchema, Serialize)]
#[serde(tag = "type", content = "properties")]
pub enum DrawingVariant {
Rectangle(RectangleProperties),
Ellipse(EllipseProperties),
FreeLine(FreeLineProperties),
BezierPolygon(PolygonProperties),
LabelText(LabelTextProperties),
Image(ImageProperties),
}

#[typeshare]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum FillPatternType {
#[serde(rename = "fill")]
Fill,
#[serde(rename = "none")]
None,
#[serde(rename = "hatchdown")]
HatchDown,
#[serde(rename = "hatchup")]
HatchUp,
#[serde(rename = "crosshatch")]
CrossHatch,
#[serde(rename = "points")]
Points,
}

/// Used to change the `add_date` of a drawing.
Expand Down
79 changes: 62 additions & 17 deletions backend/src/model/dto/drawings_impl.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@
use super::drawings::{
DrawingDto, UpdateAddDateDrawingDto, UpdateDrawingsDto, UpdateRemoveDateDrawingDto,
DrawingDto, DrawingVariant, UpdateAddDateDrawingDto, UpdateDrawingsDto,
UpdateRemoveDateDrawingDto,
};
use crate::model::entity::drawings::{Drawing, UpdateDrawing};
use crate::model::{
entity::drawings::{Drawing, UpdateDrawing},
r#enum::drawing_shape_type::DrawingShapeType,
};

impl DrawingVariant {
pub fn to_enum_and_json(&self) -> (DrawingShapeType, serde_json::Value) {
match self {
DrawingVariant::Rectangle(x) => (
DrawingShapeType::Rectangle,
serde_json::to_value(&x).unwrap(),
),
DrawingVariant::Ellipse(x) => {
(DrawingShapeType::Ellipse, serde_json::to_value(&x).unwrap())
}
DrawingVariant::FreeLine(x) => (
DrawingShapeType::FreeLine,
serde_json::to_value(&x).unwrap(),
),
DrawingVariant::BezierPolygon(x) => (
DrawingShapeType::BezierPolygon,
serde_json::to_value(&x).unwrap(),
),
DrawingVariant::LabelText(x) => (
DrawingShapeType::LabelText,
serde_json::to_value(&x).unwrap(),
),
DrawingVariant::Image(x) => {
(DrawingShapeType::Image, serde_json::to_value(&x).unwrap())
}
}
}
}

impl From<Drawing> for DrawingDto {
fn from(drawing: Drawing) -> Self {
let drawing_variant = match drawing.shape_type {
DrawingShapeType::Rectangle => {
DrawingVariant::Rectangle(serde_json::from_value(drawing.properties).unwrap())
}
DrawingShapeType::Ellipse => {
DrawingVariant::Ellipse(serde_json::from_value(drawing.properties).unwrap())
}
DrawingShapeType::FreeLine => {
DrawingVariant::FreeLine(serde_json::from_value(drawing.properties).unwrap())
}
DrawingShapeType::BezierPolygon => {
DrawingVariant::BezierPolygon(serde_json::from_value(drawing.properties).unwrap())
}
DrawingShapeType::LabelText => {
DrawingVariant::LabelText(serde_json::from_value(drawing.properties).unwrap())
}
DrawingShapeType::Image => {
DrawingVariant::Image(serde_json::from_value(drawing.properties).unwrap())
}
};
Self {
id: drawing.id,
shape_type: drawing.shape_type,
variant: drawing_variant,
layer_id: drawing.layer_id,
add_date: drawing.add_date,
remove_date: drawing.remove_date,
Expand All @@ -16,19 +69,16 @@ impl From<Drawing> for DrawingDto {
scale_y: drawing.scale_y,
x: drawing.x,
y: drawing.y,
color: drawing.color,
fill_enabled: drawing.fill_enabled,
stroke_width: drawing.stroke_width,
properties: drawing.properties,
}
}
}

impl From<DrawingDto> for Drawing {
fn from(drawing_dto: DrawingDto) -> Self {
let (shape_type, properties) = drawing_dto.variant.to_enum_and_json();
Self {
id: drawing_dto.id,
shape_type: drawing_dto.shape_type,
shape_type,
layer_id: drawing_dto.layer_id,
add_date: drawing_dto.add_date,
remove_date: drawing_dto.remove_date,
Expand All @@ -37,19 +87,17 @@ impl From<DrawingDto> for Drawing {
scale_y: drawing_dto.scale_y,
x: drawing_dto.x,
y: drawing_dto.y,
color: drawing_dto.color,
fill_enabled: drawing_dto.fill_enabled,
stroke_width: drawing_dto.stroke_width,
properties: drawing_dto.properties,
properties,
}
}
}

impl From<DrawingDto> for UpdateDrawing {
fn from(drawing_dto: DrawingDto) -> Self {
let (shape_type, properties) = drawing_dto.variant.to_enum_and_json();
Self {
id: drawing_dto.id,
shape_type: Some(drawing_dto.shape_type),
shape_type: Some(shape_type),
layer_id: Some(drawing_dto.layer_id),
add_date: Some(drawing_dto.add_date),
remove_date: Some(drawing_dto.remove_date),
Expand All @@ -58,10 +106,7 @@ impl From<DrawingDto> for UpdateDrawing {
scale_y: Some(drawing_dto.scale_y),
x: Some(drawing_dto.x),
y: Some(drawing_dto.y),
color: Some(drawing_dto.color),
fill_enabled: Some(drawing_dto.fill_enabled),
stroke_width: Some(drawing_dto.stroke_width),
properties: Some(drawing_dto.properties),
properties: Some(properties),
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions backend/src/model/entity/drawings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use chrono::NaiveDate;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
use serde_json;
use uuid::Uuid;

use crate::model::r#enum::drawing_shape_type::DrawingShapeType;
Expand All @@ -18,9 +19,6 @@ pub struct Drawing {
pub scale_y: f32,
pub x: i32,
pub y: i32,
pub color: String,
pub fill_enabled: bool,
pub stroke_width: f32,
pub properties: serde_json::Value,
}

Expand All @@ -37,8 +35,5 @@ pub struct UpdateDrawing {
pub scale_y: Option<f32>,
pub x: Option<i32>,
pub y: Option<i32>,
pub color: Option<String>,
pub fill_enabled: Option<bool>,
pub stroke_width: Option<f32>,
pub properties: Option<serde_json::Value>,
}
4 changes: 4 additions & 0 deletions backend/src/model/enum/drawing_shape_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ pub enum DrawingShapeType {
FreeLine,
#[db_rename = "bezier polygon"]
BezierPolygon,
#[db_rename = "label text"]
LabelText,
#[db_rename = "image"]
Image,
}
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Syntax: `- short text describing the change _(Your Name)_`
- Add key combinations for map geometry _(Daniel Steinkogler)_
- Add documentation for adding a new field to an entity _(Christoph Schreiner)_
- Add tooltips to show keybindings _(Daniel Steinkogler)_
- Added fill patterns, labels and images to drawing layer _(Daniel Steinkogler, Jannis Adamek)_
danielsteinkogler marked this conversation as resolved.
Show resolved Hide resolved
- Use arrow keys to navigate between timepicker sliders and fix timeline performance issues _(Daniel Steinkogler)_
- Use integer for plant spread and height _(Christoph Schreiner)_
- Increased zoom scaling factor for Map Editor / faster zooming _(Samuel)_
Expand Down
2 changes: 1 addition & 1 deletion doc/decisions/backend_orm_crate.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Backend ORM/SQL Crate
p# Backend ORM/SQL Crate
danielsteinkogler marked this conversation as resolved.
Show resolved Hide resolved

## Problem

Expand Down
Loading