-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraphOmniGraffle.swift
43 lines (31 loc) · 1.17 KB
/
GraphOmniGraffle.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// GraphOmniGraffle.swift
// ogg
//
// Created by michael isbell on 2/4/17.
// Copyright © 2017 michael prenez-isbell. All rights reserved.
//
import Foundation
func buildGraphForCanvas(canvas: OmniGraffleCanvas) -> Graph {
let graph = Graph()
for shape_ in canvas.shapes!() {
let shape = shape_ as! OmniGraffleShape
graph.addNode(node: Node(identifier: shape.id!))
}
for line_ in canvas.lines!() {
let line = line_ as! OmniGraffleLine
let sourceIdentifier = (line.source! as! OmniGraffleShape).id!
let destinationIdentifier = (line.destination! as! OmniGraffleShape).id!
let sourceNode = graph.nodeByIdentifier(identifier: sourceIdentifier)!
let destinationNode = graph.nodeByIdentifier(identifier: destinationIdentifier)!
graph.addEdgeFromNode(source: sourceNode, toNode: destinationNode)
}
return graph
}
func mapIDsToShapes(canvas: OmniGraffleCanvas) -> [Int: OmniGraffleShape] {
var map = [Int: OmniGraffleShape]()
for shape in canvas.shapes!() {
map[(shape as AnyObject).id!] = shape as? OmniGraffleShape
}
return map
}