From 93f85738cbaa9ec9ad6c7aaeb477a960597b0b36 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sat, 26 Jun 2021 23:53:08 +0200 Subject: [PATCH] Organize properties in groups. --- source/external/rhinoimporter.js | 10 +++++--- source/import/importergltf.js | 6 ++++- source/model/element.js | 16 ++++++------- source/model/property.js | 24 +++++++++++++++++++ test/tests/model_test.js | 14 ----------- test/tests/property_test.js | 40 ++++++++++++++++++++++++++++++++ website/o3dv/sidebar.js | 25 ++++++++++++++++---- website/o3dv/website.css | 10 ++++++++ 8 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 test/tests/property_test.js diff --git a/source/external/rhinoimporter.js b/source/external/rhinoimporter.js index 0fd5c56..12abaea 100644 --- a/source/external/rhinoimporter.js +++ b/source/external/rhinoimporter.js @@ -181,9 +181,13 @@ OV.Importer3dm = class extends OV.ImporterBase mesh.SetName (rhinoAttributes.name); let userStrings = rhinoAttributes.getUserStrings (); - for (let i = 0; i < userStrings.length; i++) { - let userString = userStrings[i]; - mesh.AddProperty (new OV.Property (OV.PropertyType.Text, userString[0], userString[1])); + if (userStrings.length > 0) { + let propertyGroup = new OV.PropertyGroup ('User texts'); + for (let i = 0; i < userStrings.length; i++) { + let userString = userStrings[i]; + propertyGroup.AddProperty (new OV.Property (OV.PropertyType.Text, userString[0], userString[1])); + } + mesh.AddPropertyGroup (propertyGroup); } let materialIndex = this.GetMaterialIndex (rhinoDoc, rhinoObject, rhinoInstanceReferences); diff --git a/source/import/importergltf.js b/source/import/importergltf.js index 2f49956..c604715 100644 --- a/source/import/importergltf.js +++ b/source/import/importergltf.js @@ -508,14 +508,18 @@ OV.ImporterGltf = class extends OV.ImporterBase ImportModelProperties (gltf) { + let propertyGroup = new OV.PropertyGroup ('Asset properties'); for (let propertyName in gltf.asset) { if (gltf.asset.hasOwnProperty (propertyName)) { if (typeof gltf.asset[propertyName] === 'string') { const property = new OV.Property (OV.PropertyType.Text, propertyName, gltf.asset[propertyName]); - this.model.AddProperty (property); + propertyGroup.AddProperty (property); } } } + if (propertyGroup.PropertyCount () > 0) { + this.model.AddPropertyGroup (propertyGroup); + } } GetDefaultScene (gltf) diff --git a/source/model/element.js b/source/model/element.js index 639769f..a4ea19b 100644 --- a/source/model/element.js +++ b/source/model/element.js @@ -3,7 +3,7 @@ OV.Element = class constructor () { this.name = ''; - this.properties = []; + this.propertyGroups = []; } GetName () @@ -36,20 +36,20 @@ OV.Element = class return 0; } - PropertyCount () + PropertyGroupCount () { - return this.properties.length; + return this.propertyGroups.length; } - AddProperty (property) + AddPropertyGroup (propertyGroup) { - this.properties.push (property); - return this.properties.length - 1; + this.propertyGroups.push (propertyGroup); + return this.propertyGroups.length - 1; } - GetProperty (index) + GetPropertyGroup (index) { - return this.properties[index]; + return this.propertyGroups[index]; } EnumerateVertices (onVertex) diff --git a/source/model/property.js b/source/model/property.js index f99d72e..7b42be3 100644 --- a/source/model/property.js +++ b/source/model/property.js @@ -16,3 +16,27 @@ OV.Property = class this.value = value; } }; + +OV.PropertyGroup = class +{ + constructor (name) + { + this.name = name; + this.properties = []; + } + + PropertyCount () + { + return this.properties.length; + } + + AddProperty (property) + { + this.properties.push (property); + } + + GetProperty (index) + { + return this.properties[index]; + } +}; diff --git a/test/tests/model_test.js b/test/tests/model_test.js index 1c92a18..6189302 100644 --- a/test/tests/model_test.js +++ b/test/tests/model_test.js @@ -184,20 +184,6 @@ describe ('Model Finalization', function() { }); }); -describe ('Model Properties', function() { - let model = new OV.Model (); - model.AddProperty (new OV.Property (OV.PropertyType.Text, 'name 01', 'value 01')); - model.AddProperty (new OV.Property (OV.PropertyType.Integer, 'name 02', 2)); - model.AddProperty (new OV.Property (OV.PropertyType.Number, 'name 03', 3.5)); - assert.strictEqual (model.PropertyCount (), 3); - assert.strictEqual (model.GetProperty (0).name, 'name 01'); - assert.strictEqual (model.GetProperty (0).value, 'value 01'); - assert.strictEqual (model.GetProperty (1).name, 'name 02'); - assert.strictEqual (model.GetProperty (1).value, 2); - assert.strictEqual (model.GetProperty (2).name, 'name 03'); - assert.strictEqual (model.GetProperty (2).value, 3.5); -}); - describe ('Color Conversion', function() { it ('Color equality check', function () { assert (OV.ColorIsEqual (new OV.Color (10, 20, 30), new OV.Color (10, 20, 30))); diff --git a/test/tests/property_test.js b/test/tests/property_test.js new file mode 100644 index 0000000..301d1c3 --- /dev/null +++ b/test/tests/property_test.js @@ -0,0 +1,40 @@ +var assert = require ('assert'); + +describe ('Property Test', function () { + it ('Property Group', function() { + let group = new OV.PropertyGroup ('Group'); + group.AddProperty (new OV.Property (OV.PropertyType.Text, 'name 01', 'value 01')); + group.AddProperty (new OV.Property (OV.PropertyType.Integer, 'name 02', 2)); + group.AddProperty (new OV.Property (OV.PropertyType.Number, 'name 03', 3.5)); + assert.strictEqual (group.PropertyCount (), 3); + assert.strictEqual (group.GetProperty (0).name, 'name 01'); + assert.strictEqual (group.GetProperty (0).value, 'value 01'); + assert.strictEqual (group.GetProperty (1).name, 'name 02'); + assert.strictEqual (group.GetProperty (1).value, 2); + assert.strictEqual (group.GetProperty (2).name, 'name 03'); + assert.strictEqual (group.GetProperty (2).value, 3.5); + }); + + it ('Model Properties', function() { + let model = new OV.Model (); + let group1 = new OV.PropertyGroup ('Group 01'); + let group2 = new OV.PropertyGroup ('Group 02'); + let group3 = new OV.PropertyGroup ('Group 03'); + group1.AddProperty (new OV.Property (OV.PropertyType.Text, 'name 01', 'value 01')); + group2.AddProperty (new OV.Property (OV.PropertyType.Integer, 'name 02', 2)); + group3.AddProperty (new OV.Property (OV.PropertyType.Number, 'name 03', 3.5)); + model.AddPropertyGroup (group1); + model.AddPropertyGroup (group2); + model.AddPropertyGroup (group3); + assert.strictEqual (model.PropertyGroupCount (), 3); + assert.strictEqual (model.GetPropertyGroup (0).name, 'Group 01'); + assert.strictEqual (model.GetPropertyGroup (1).name, 'Group 02'); + assert.strictEqual (model.GetPropertyGroup (2).name, 'Group 03'); + assert.strictEqual (model.GetPropertyGroup (0).GetProperty (0).name, 'name 01'); + assert.strictEqual (model.GetPropertyGroup (0).GetProperty (0).value, 'value 01'); + assert.strictEqual (model.GetPropertyGroup (1).GetProperty (0).name, 'name 02'); + assert.strictEqual (model.GetPropertyGroup (1).GetProperty (0).value, 2); + assert.strictEqual (model.GetPropertyGroup (2).GetProperty (0).name, 'name 03'); + assert.strictEqual (model.GetPropertyGroup (2).GetProperty (0).value, 3.5); + }); +}); diff --git a/website/o3dv/sidebar.js b/website/o3dv/sidebar.js index c19cd17..dd12b04 100644 --- a/website/o3dv/sidebar.js +++ b/website/o3dv/sidebar.js @@ -38,6 +38,12 @@ OV.Sidebar = class return this.visible; } + AddPropertyGroup (table, propertyGroup) + { + let row = $('
').addClass ('ov_property_table_row group').appendTo (table); + row.html (propertyGroup.name).attr ('title', propertyGroup.name); + } + AddProperty (table, property) { let row = $('
').addClass ('ov_property_table_row').appendTo (table); @@ -45,6 +51,13 @@ OV.Sidebar = class let valueColumn = $('
').addClass ('ov_property_table_cell ov_property_table_value').appendTo (row); nameColum.html (property.name + ':').attr ('title', property.name); this.DisplayPropertyValue (property, valueColumn); + return row; + } + + AddPropertyInGroup (table, property) + { + let row = this.AddProperty (table, property); + row.addClass ('ingroup'); } AddCalculatedProperty (table, name, calculateValue) @@ -121,11 +134,15 @@ OV.Sidebar = class } return new OV.Property (OV.PropertyType.Number, null, volume); }); - if (element.PropertyCount () > 0) { + if (element.PropertyGroupCount () > 0) { let customTable = $('
').addClass ('ov_property_table ov_property_table_custom').appendTo (this.contentDiv); - for (let i = 0; i < element.PropertyCount (); i++) { - const property = element.GetProperty (i); - this.AddProperty (customTable, property); + for (let i = 0; i < element.PropertyGroupCount (); i++) { + const propertyGroup = element.GetPropertyGroup (i); + this.AddPropertyGroup (customTable, propertyGroup); + for (let j = 0; j < propertyGroup.PropertyCount (); j++) { + const property = propertyGroup.GetProperty (j); + this.AddPropertyInGroup (customTable, property); + } } } this.Resize (); diff --git a/website/o3dv/website.css b/website/o3dv/website.css index 63f2005..3e94910 100644 --- a/website/o3dv/website.css +++ b/website/o3dv/website.css @@ -674,6 +674,16 @@ div.ov_property_table div.ov_property_table_row overflow: auto; } +div.ov_property_table div.ov_property_table_row.group +{ + padding: 4px 0px; +} + +div.ov_property_table div.ov_property_table_row.ingroup +{ + margin-left: 15px; +} + div.ov_property_table div.ov_property_table_cell { padding: 4px 0px;