Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for render problem. #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
20 changes: 10 additions & 10 deletions Sources/ApollonEdit/Views/Create/CreateElement/ElementCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ struct ClassCreator: ElementCreator {
let element = UMLElement(id: elementID, type: type, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y, width: 200, height: 120))
let elementAttribute = UMLElement(name: "+ attribute: Type", type: .classAttribute, owner: elementID, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y + 40, width: 200, height: 40))
let elementMethod = UMLElement(name: "+ method()", type: .classMethod, owner: elementID, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y + 80, width: 200, height: 40))
element.attributes?.append(elementAttribute)
element.methods?.append(elementMethod)
element.addAttribute(elementAttribute)
element.addMethod(elementMethod)
return [element]
}
}
Expand All @@ -66,8 +66,8 @@ struct AbstractClassOrInterfaceCreator: ElementCreator {
let element = UMLElement(id: elementID, type: type, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y, width: 200, height: 130))
let elementAttribute = UMLElement(name: "+ attribute: Type", type: .classAttribute, owner: elementID, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y + 50, width: 200, height: 40))
let elementMethod = UMLElement(name: "+ method()", type: .classMethod, owner: elementID, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y + 90, width: 200, height: 40))
kurunbelemir marked this conversation as resolved.
Show resolved Hide resolved
element.attributes?.append(elementAttribute)
element.methods?.append(elementMethod)
element.addAttribute(elementAttribute)
element.addAttribute(elementMethod)
return [element]
}
}
Expand All @@ -79,10 +79,10 @@ struct EnumerationCreator: ElementCreator {
let elementAttribute1 = UMLElement(name: "Case 1", type: .classAttribute, owner: elementID, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y + 50, width: 200, height: 40))
let elementAttribute2 = UMLElement(name: "Case 2", type: .classAttribute, owner: elementID, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y + 90, width: 200, height: 40))
let elementAttribute3 = UMLElement(name: "Case 3", type: .classAttribute, owner: elementID, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y + 130, width: 200, height: 40))
element.addChild(elementAttribute1)
element.addChild(elementAttribute2)
element.addChild(elementAttribute3)
return [element, elementAttribute1, elementAttribute2, elementAttribute3]
element.addAttribute(elementAttribute1)
element.addAttribute(elementAttribute2)
element.addAttribute(elementAttribute3)
return [element]
}
}

Expand All @@ -91,8 +91,8 @@ struct ObjectCreator: ElementCreator {
let elementID = UUID().uuidString.lowercased()
let element = UMLElement(id: elementID, name: "Object", type: type, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y, width: 200, height: 70))
let elementAttribute = UMLElement(name: "attribute = value", type: .objectAttribute, owner: elementID, bounds: Boundary(x: pointToAdd.x, y: pointToAdd.y + 40, width: 200, height: 30))
element.addChild(elementAttribute)
return [element, elementAttribute]
element.addAttribute(elementAttribute)
return [element]
}
}

Expand Down
37 changes: 37 additions & 0 deletions Sources/ApollonShared/DataModels/UMLElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,43 @@ public class UMLElement: Codable, SelectableUMLItem {
self.children?.append(child)
}
}
//// NEWLY ADDED

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this? Is this from cursor?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it was a note to myself, I forgot to delete.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay let me k is once you have deleted those comments

public func addAttribute(_ attribute: UMLElement) {
if attributes == nil {
self.attributes = [attribute]
} else {
self.attributes?.append(attribute)
}
}
public func addMethod(_ method: UMLElement) {
if methods == nil {
self.methods = [method]
} else {
self.methods?.append(method)
}
}

public var verticallySortedAttributes: [UMLElement]? {
attributes?.sorted(by: { ($0.bounds?.y ?? 0.0) < ($1.bounds?.y ?? 0.0) })
}

public var verticallySortedMethods: [UMLElement]? {
methods?.sorted(by: { ($0.bounds?.y ?? 0.0) < ($1.bounds?.y ?? 0.0) })
}

public func removeAttribute(_ attribute: UMLElement) {
if let allAttributes = self.verticallySortedAttributes,
let indexOfAttributeToRemove = allAttributes.firstIndex(where: { $0.id == attribute.id }) {
for (index, element) in allAttributes.enumerated() where index > indexOfAttributeToRemove {
let newYForElement = (element.bounds?.y ?? 0) - (attribute.bounds?.height ?? 0)
allAttributes[index].bounds?.y = newYForElement
}
}
let newHeight = (self.bounds?.height ?? 0) - (attribute.bounds?.height ?? 0)
self.bounds?.height = newHeight
self.attributes?.removeAll { $0.id == attribute.id }
}
/////END OF NEWLY ADDED

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

/// Remove a child from a UML element
public func removeChild(_ child: UMLElement) {
if let allChildren = self.verticallySortedChildren,
Expand Down