From aeda3ee0d06f7e77a032f544a9f6a4547930300f Mon Sep 17 00:00:00 2001 From: Roman Pytkov Date: Mon, 23 Feb 2026 23:52:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D1=82=D1=8C=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B2=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/Document.zig | 14 ++++++++++++++ src/models/Object.zig | 8 -------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/models/Document.zig b/src/models/Document.zig index 83fe9b2..72a27cf 100644 --- a/src/models/Document.zig +++ b/src/models/Document.zig @@ -26,3 +26,17 @@ pub fn addObject(self: *Document, template: Object) !void { const obj = try template.clone(self.allocator); try self.objects.append(self.allocator, obj); } + +pub fn addShape(self: *Document, parent: ?*Object, shape: Object.ShapeKind) !void { + const obj = switch (shape) { + .line => try Object.createLine(self.allocator), + .ellipse => try Object.createEllipse(self.allocator), + .broken => try Object.createBrokenLine(self.allocator), + .arc => return error.ArcNotImplemented, + }; + if (parent) |p| { + try p.addChild(self.allocator, obj); + } else { + try self.addObject(obj); + } +} diff --git a/src/models/Object.zig b/src/models/Object.zig index 13f5604..5566d6c 100644 --- a/src/models/Object.zig +++ b/src/models/Object.zig @@ -8,7 +8,6 @@ const defaultCommonProperties = @import("Property.zig").defaultCommonProperties; const Object = @This(); pub const ShapeKind = enum { - rect, line, ellipse, arc, @@ -81,13 +80,6 @@ fn createWithCommonProperties(allocator: std.mem.Allocator, shape: ShapeKind) !O }; } -pub fn createRect(allocator: std.mem.Allocator) !Object { - var obj = try createWithCommonProperties(allocator, .rect); - errdefer obj.deinit(allocator); - try obj.properties.append(allocator, .{ .data = .{ .size = .{ .width = 100, .height = 100 } } }); - return obj; -} - pub fn createEllipse(allocator: std.mem.Allocator) !Object { var obj = try createWithCommonProperties(allocator, .ellipse); errdefer obj.deinit(allocator);