diff --git a/GLLara.xcodeproj/project.pbxproj b/GLLara.xcodeproj/project.pbxproj index 1d73a705..7440100c 100644 --- a/GLLara.xcodeproj/project.pbxproj +++ b/GLLara.xcodeproj/project.pbxproj @@ -44,7 +44,7 @@ 52301E2D2087D91600B3E331 /* GLLOptionalPartController.m in Sources */ = {isa = PBXBuildFile; fileRef = 52301E2C2087D91600B3E331 /* GLLOptionalPartController.m */; }; 52301E302087E36100B3E331 /* GLLItemOptionalPartMarker.m in Sources */ = {isa = PBXBuildFile; fileRef = 52301E2F2087E36100B3E331 /* GLLItemOptionalPartMarker.m */; }; 52301E322087E6FC00B3E331 /* GLLOptionalPartView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 52301E312087E6FC00B3E331 /* GLLOptionalPartView.xib */; }; - 52301E352087E71400B3E331 /* GLLOptionalPartViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 52301E342087E71400B3E331 /* GLLOptionalPartViewController.m */; }; + 52301E352087E71400B3E331 /* GLLOptionalPartViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52301E342087E71400B3E331 /* GLLOptionalPartViewController.swift */; }; 52301E382089372200B3E331 /* GLLOptionalPart.m in Sources */ = {isa = PBXBuildFile; fileRef = 52301E372089372200B3E331 /* GLLOptionalPart.m */; }; 52301E472096518500B3E331 /* GLLDrawingPreferencesView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 52301E492096518500B3E331 /* GLLDrawingPreferencesView.xib */; }; 52329F4C16C1D71E00338A0A /* GLLItemExportView.strings in Resources */ = {isa = PBXBuildFile; fileRef = 52329F4A16C1D71E00338A0A /* GLLItemExportView.strings */; }; @@ -311,7 +311,7 @@ 52CDFEE42875B46700BC4298 /* GLLSceneDrawer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52CDFEE32875B46700BC4298 /* GLLSceneDrawer.swift */; }; 52CDFEE62875C4AA00BC4298 /* GLLViewDrawer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52CDFEE52875C4AA00BC4298 /* GLLViewDrawer.swift */; }; 52CDFEE8287619D800BC4298 /* Square.metal in Sources */ = {isa = PBXBuildFile; fileRef = 52CDFEE7287619D800BC4298 /* Square.metal */; }; - 52CE280C1605FE98005A86E9 /* GLLLogarithmicValueTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 52CE280B1605FE98005A86E9 /* GLLLogarithmicValueTransformer.m */; }; + 52CE280C1605FE98005A86E9 /* GLLLogarithmicValueTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52CE280B1605FE98005A86E9 /* GLLLogarithmicValueTransformer.swift */; }; 52D18D5229A2716400BE2815 /* GLLConnexionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 52D18D5129A2716400BE2815 /* GLLConnexionManager.m */; }; 52D3D72916029BD9006CB743 /* GLLRenderAccessoryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 52D3D72816029BD8006CB743 /* GLLRenderAccessoryViewController.m */; }; 52D6A09715F8B0F7002A0BB4 /* GLLMeshViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 52D6A09515F8B0F7002A0BB4 /* GLLMeshViewController.m */; }; @@ -466,8 +466,7 @@ 52301E2E2087E36100B3E331 /* GLLItemOptionalPartMarker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GLLItemOptionalPartMarker.h; sourceTree = ""; }; 52301E2F2087E36100B3E331 /* GLLItemOptionalPartMarker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GLLItemOptionalPartMarker.m; sourceTree = ""; }; 52301E312087E6FC00B3E331 /* GLLOptionalPartView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GLLOptionalPartView.xib; sourceTree = ""; }; - 52301E332087E71400B3E331 /* GLLOptionalPartViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GLLOptionalPartViewController.h; sourceTree = ""; }; - 52301E342087E71400B3E331 /* GLLOptionalPartViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GLLOptionalPartViewController.m; sourceTree = ""; }; + 52301E342087E71400B3E331 /* GLLOptionalPartViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLOptionalPartViewController.swift; sourceTree = ""; }; 52301E362089372200B3E331 /* GLLOptionalPart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GLLOptionalPart.h; sourceTree = ""; }; 52301E372089372200B3E331 /* GLLOptionalPart.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GLLOptionalPart.m; sourceTree = ""; }; 52301E482096518500B3E331 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/GLLDrawingPreferencesView.xib; sourceTree = ""; }; @@ -787,8 +786,7 @@ 52CDFEE32875B46700BC4298 /* GLLSceneDrawer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLSceneDrawer.swift; sourceTree = ""; }; 52CDFEE52875C4AA00BC4298 /* GLLViewDrawer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GLLViewDrawer.swift; sourceTree = ""; }; 52CDFEE7287619D800BC4298 /* Square.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Square.metal; sourceTree = ""; }; - 52CE280A1605FE98005A86E9 /* GLLLogarithmicValueTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLLLogarithmicValueTransformer.h; sourceTree = ""; }; - 52CE280B1605FE98005A86E9 /* GLLLogarithmicValueTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLLLogarithmicValueTransformer.m; sourceTree = ""; }; + 52CE280B1605FE98005A86E9 /* GLLLogarithmicValueTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GLLLogarithmicValueTransformer.swift; sourceTree = ""; }; 52D18D5029A2716400BE2815 /* GLLConnexionManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GLLConnexionManager.h; sourceTree = ""; }; 52D18D5129A2716400BE2815 /* GLLConnexionManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GLLConnexionManager.m; sourceTree = ""; }; 52D18D5329A2A29100BE2815 /* GLLaraRelease.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GLLaraRelease.entitlements; sourceTree = ""; }; @@ -1455,8 +1453,7 @@ 5227834A1C0A6083002E43FD /* GLLRenderAccessoryView.xib */, 52D3D72716029BD8006CB743 /* GLLRenderAccessoryViewController.h */, 52D3D72816029BD8006CB743 /* GLLRenderAccessoryViewController.m */, - 52CE280A1605FE98005A86E9 /* GLLLogarithmicValueTransformer.h */, - 52CE280B1605FE98005A86E9 /* GLLLogarithmicValueTransformer.m */, + 52CE280B1605FE98005A86E9 /* GLLLogarithmicValueTransformer.swift */, 522783471C0A607E002E43FD /* GLLItemExportView.xib */, 52ED9E1C168399AE0082EABB /* GLLSelection.h */, 52ED9E1D168399AE0082EABB /* GLLSelection.m */, @@ -1476,8 +1473,7 @@ 5213F8811C0E411C007A9EBB /* GLLPreferencesWindowController.m */, 5213F88A1C0E478C007A9EBB /* GLLPreferencesWindow.xib */, 52301E312087E6FC00B3E331 /* GLLOptionalPartView.xib */, - 52301E332087E71400B3E331 /* GLLOptionalPartViewController.h */, - 52301E342087E71400B3E331 /* GLLOptionalPartViewController.m */, + 52301E342087E71400B3E331 /* GLLOptionalPartViewController.swift */, 52301E362089372200B3E331 /* GLLOptionalPart.h */, 52301E372089372200B3E331 /* GLLOptionalPart.m */, 52301E492096518500B3E331 /* GLLDrawingPreferencesView.xib */, @@ -1905,7 +1901,7 @@ 527270B22BE8254E00EE52B5 /* GLLCameraTarget.swift in Sources */, 527270A32BE7E0F100EE52B5 /* GLLItem+Extensions.swift in Sources */, 52D3D72916029BD9006CB743 /* GLLRenderAccessoryViewController.m in Sources */, - 52CE280C1605FE98005A86E9 /* GLLLogarithmicValueTransformer.m in Sources */, + 52CE280C1605FE98005A86E9 /* GLLLogarithmicValueTransformer.swift in Sources */, 527270A72BE810A600EE52B5 /* GLLItemMesh+Extensions.swift in Sources */, 5275F6821607293000978779 /* GLLItemController.m in Sources */, 52C516FF2871998C000EB8C2 /* GLLPipelineStateInformation.swift in Sources */, @@ -1916,7 +1912,7 @@ 525BF29D287A0AE200E30D48 /* GLLView.swift in Sources */, 527270A52BE8064100EE52B5 /* GLLDataReader.swift in Sources */, 52CDFEE42875B46700BC4298 /* GLLSceneDrawer.swift in Sources */, - 52301E352087E71400B3E331 /* GLLOptionalPartViewController.m in Sources */, + 52301E352087E71400B3E331 /* GLLOptionalPartViewController.swift in Sources */, 52B6C51F2BE28DE7005E53CE /* GLLItemDragDestination.swift in Sources */, 52F73EA8288BE06600A580EC /* GLLDrawingPreferencesViewController.swift in Sources */, 52C3AD8C29A13DEB002EC334 /* WillinglyBlock.swift in Sources */, diff --git a/GLLara/GLLDocument.m b/GLLara/GLLDocument.m index 2bcbbc77..1b6b23aa 100644 --- a/GLLara/GLLDocument.m +++ b/GLLara/GLLDocument.m @@ -16,7 +16,6 @@ #import "GLLItem.h" #import "GLLItemBone.h" #import "GLLItemMesh.h" -#import "GLLLogarithmicValueTransformer.h" #import "GLLRenderWindowController.h" #import "GLLSelection.h" diff --git a/GLLara/GLLDocumentWindowController.m b/GLLara/GLLDocumentWindowController.m index eef5d8e9..c8e5304c 100644 --- a/GLLara/GLLDocumentWindowController.m +++ b/GLLara/GLLDocumentWindowController.m @@ -22,7 +22,6 @@ #import "GLLItemViewController.h" #import "GLLLightsListController.h" #import "GLLMeshViewController.h" -#import "GLLOptionalPartViewController.h" #import "GLLSelection.h" #import "GLLSettingsListController.h" diff --git a/GLLara/GLLLogarithmicValueTransformer.h b/GLLara/GLLLogarithmicValueTransformer.h deleted file mode 100644 index 88b3a1eb..00000000 --- a/GLLara/GLLLogarithmicValueTransformer.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// GLLLogarithmicValueTransformer.h -// GLLara -// -// Created by Torsten Kammer on 16.09.12. -// Copyright (c) 2012 Torsten Kammer. All rights reserved. -// - -#import - -/*! - * @abstract Logarithmic Value Transformer - * @discussion Used to allow setting of things like scales with a slider - * that uses logarithmic scale. works in base 10. - */ -@interface GLLLogarithmicValueTransformer : NSValueTransformer - -@end diff --git a/GLLara/GLLLogarithmicValueTransformer.m b/GLLara/GLLLogarithmicValueTransformer.m deleted file mode 100644 index 9ebc5e02..00000000 --- a/GLLara/GLLLogarithmicValueTransformer.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// GLLLogarithmicValueTransformer.m -// GLLara -// -// Created by Torsten Kammer on 16.09.12. -// Copyright (c) 2012 Torsten Kammer. All rights reserved. -// - -#import "GLLLogarithmicValueTransformer.h" - -@implementation GLLLogarithmicValueTransformer - -+ (BOOL)allowsReverseTransformation -{ - return YES; -} - -+ (Class)transformedValueClass -{ - return [NSNumber class]; -} - -- (id)reverseTransformedValue:(id)value -{ - return @(pow(10.0, [value doubleValue])); -} - -- (id)transformedValue:(id)value -{ - return @(log10([value doubleValue])); -} - -@end diff --git a/GLLara/GLLLogarithmicValueTransformer.swift b/GLLara/GLLLogarithmicValueTransformer.swift new file mode 100644 index 00000000..2145121f --- /dev/null +++ b/GLLara/GLLLogarithmicValueTransformer.swift @@ -0,0 +1,31 @@ +// +// GLLLogarithmicValueTransformer.swift +// GLLara +// +// Created by Torsten Kammer on 16.09.12. +// Copyright (c) 2012 Torsten Kammer. All rights reserved. +// + +import Foundation + +/** + * @abstract Logarithmic Value Transformer + * @discussion Used to allow setting of things like scales with a slider + * that uses logarithmic scale. works in base 10. + */ +@objc class GLLLogarithmicValueTransformer: ValueTransformer { + @objc override class func allowsReverseTransformation() -> Bool { + return true + } + @objc override class func transformedValueClass() -> AnyClass { + return NSNumber.self + } + + override func transformedValue(_ value: Any?) -> Any? { + return log10((value as! NSNumber).doubleValue) + } + + override func reverseTransformedValue(_ value: Any?) -> Any? { + return pow(10.0, (value as! NSNumber).doubleValue) + } +} diff --git a/GLLara/GLLOptionalPartViewController.h b/GLLara/GLLOptionalPartViewController.h deleted file mode 100644 index a135b51a..00000000 --- a/GLLara/GLLOptionalPartViewController.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// GLLOptionalPartViewController.h -// GLLara -// -// Created by Torsten Kammer on 18.04.18. -// Copyright © 2018 Torsten Kammer. All rights reserved. -// - -#import - -@class GLLOptionalPart; - -@interface GLLOptionalPartViewController : NSViewController - -@property (nonatomic, retain) IBOutlet NSTableView *tableView; - -@property (nonatomic, copy) NSArray *parts; - -@end diff --git a/GLLara/GLLOptionalPartViewController.m b/GLLara/GLLOptionalPartViewController.m deleted file mode 100644 index fbfc50d5..00000000 --- a/GLLara/GLLOptionalPartViewController.m +++ /dev/null @@ -1,107 +0,0 @@ -// -// GLLOptionalPartViewController.m -// GLLara -// -// Created by Torsten Kammer on 18.04.18. -// Copyright © 2018 Torsten Kammer. All rights reserved. -// - -#import "GLLOptionalPartViewController.h" - -#import "GLLItem.h" -#import "GLLItemMesh.h" -#import "GLLOptionalPart.h" - -#import "GLLara-Swift.h" - -@implementation GLLOptionalPartViewController - -- (id)init -{ - self = [super initWithNibName:@"GLLOptionalPartView" bundle:nil]; - if (!self) - return nil; - - _parts = [NSArray array]; - - return self; -} - -- (void)viewDidLoad { - [super viewDidLoad]; - - // TODO: Fill list with stuff - // Meaning set up observing of the GLLSelection (which needs to be passed in - // as a parameter here), and when it changes and it contains one item - // (otherwise empty): - // - Get all the names of optional items. I think that's just from the - // initial +/- to the first "." - // - That list is now what we show. For column 0, show all/none/some, for - // column 1 just show the name. - // - handle clicks on column 0 correctly. Column 1 is not editable. -} - -- (void)setRepresentedObject:(id)representedObject { - NSMutableArray *topLevelParts = [NSMutableArray array]; - if (representedObject) { - GLLItem *representedItem = [representedObject valueForKey:@"item"]; - for (GLLItemMesh *mesh in representedItem.meshes) { - NSArray *names = mesh.mesh.optionalPartNames; - if (names.count == 0) - continue; - - BOOL existsAlready = NO; - - // Find parent - GLLOptionalPart *parent = nil; - if (names.count > 1) { - // Find root - NSString *parentName = names[0]; - for (GLLOptionalPart *part in topLevelParts) { - if ([part.name isEqualToString:parentName]) { - parent = part; - break; - } - } - if (!parent) { - parent = [[GLLOptionalPart alloc] initWithItem:representedItem name:names[0] parent:nil]; - [topLevelParts addObject:parent]; - } - - // Find rest of path - for (NSUInteger i = 1; i < names.count - 1; i++) { - GLLOptionalPart *newParent = [parent childWithName:names[i]]; - if (!newParent) { - newParent = [[GLLOptionalPart alloc] initWithItem:representedItem name:names[i] parent:parent]; - } - parent = newParent; - } - // Check whether we already have this element - if ([parent childWithName:names[names.count - 1]]) { - existsAlready = YES; - } - } else { - for (GLLOptionalPart *part in topLevelParts) { - if ([part.name isEqualToString:names[0]]) { - existsAlready = YES; - break; - } - } - } - if (existsAlready) - continue; - - - // Create and insert part - GLLOptionalPart *part = [[GLLOptionalPart alloc] initWithItem:representedItem name:names[names.count - 1] parent:parent]; - if (parent == nil) { - [topLevelParts addObject:part]; - } - } - } - self.parts = topLevelParts; - - [super setRepresentedObject:representedObject]; -} - -@end diff --git a/GLLara/GLLOptionalPartViewController.swift b/GLLara/GLLOptionalPartViewController.swift new file mode 100644 index 00000000..df420dd2 --- /dev/null +++ b/GLLara/GLLOptionalPartViewController.swift @@ -0,0 +1,99 @@ +// +// GLLOptionalPartViewController.m +// GLLara +// +// Created by Torsten Kammer on 18.04.18. +// Copyright © 2018 Torsten Kammer. All rights reserved. +// + +import Cocoa + +@objc class GLLOptionalPartViewController : NSViewController { + init() { + super.init(nibName:"GLLOptionalPartView", bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + @IBOutlet var tableView: NSTableView? + @objc dynamic var parts: [GLLOptionalPart] = [] + + override func viewDidLoad() { + super.viewDidLoad() + + // TODO: Fill list with stuff + // Meaning set up observing of the GLLSelection (which needs to be passed in + // as a parameter here), and when it changes and it contains one item + // (otherwise empty): + // - Get all the names of optional items. I think that's just from the + // initial +/- to the first "." + // - That list is now what we show. For column 0, show all/none/some, for + // column 1 just show the name. + // - handle clicks on column 0 correctly. Column 1 is not editable. + } + + override var representedObject: Any? { + didSet { + guard let representedObject, let representedItem = (representedObject as! NSObject).value(forKeyPath: "item") as? GLLItem else { + return + } + + var topLevelParts: [GLLOptionalPart] = [] + + for mesh in representedItem.meshes { + let names = (mesh as! GLLItemMesh).mesh.optionalPartNames + if names.count == 0 { + continue + } + + var existsAlready = false + + // Find parent + var parent: GLLOptionalPart? = nil + if names.count > 1 { + // Find root + let parentName = names[0]; + for part in topLevelParts { + if part.name == parentName { + parent = part + break + } + } + if parent == nil { + parent = GLLOptionalPart(item: representedItem, name: names[0], parent: nil) + topLevelParts.append(parent!) + } + + // Find rest of path + for i in 1 ..< names.count - 1 { + let newParent = parent?.child(withName: names[i]) + if newParent == nil { + parent = GLLOptionalPart(item: representedItem, name: names[0], parent: nil) + } + parent = newParent + } + // Check whether we already have this element + if parent!.child(withName: names.last!) != nil { + existsAlready = true + } + } else { + existsAlready = topLevelParts.contains(where: { $0.name == names[0] }) + } + if existsAlready { + continue + } + + // Create and insert part + let part = GLLOptionalPart(item: representedItem, name: names.last!, parent: parent) + if parent == nil { + topLevelParts.append(part) + } + } + + parts = topLevelParts + } + } + +} diff --git a/GLLara/GLLara-Bridging-Header.h b/GLLara/GLLara-Bridging-Header.h index 88afe082..a0d6dd20 100644 --- a/GLLara/GLLara-Bridging-Header.h +++ b/GLLara/GLLara-Bridging-Header.h @@ -14,6 +14,7 @@ #import "GLLItemMesh.h" #import "GLLNotifications.h" #import "GLLVertexAttrib.h" +#import "GLLOptionalPart.h" #import "GLLPreferencesWindowController.h" #import "GLLRenderParameter.h" #import "GLLRenderParameters.h"