Organize properties in groups.

This commit is contained in:
kovacsv 2021-06-26 23:53:08 +02:00
parent 4c499ca4ba
commit 93f85738cb
8 changed files with 115 additions and 30 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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)

View File

@ -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];
}
};

View File

@ -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)));

View File

@ -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);
});
});

View File

@ -38,6 +38,12 @@ OV.Sidebar = class
return this.visible;
}
AddPropertyGroup (table, propertyGroup)
{
let row = $('<div>').addClass ('ov_property_table_row group').appendTo (table);
row.html (propertyGroup.name).attr ('title', propertyGroup.name);
}
AddProperty (table, property)
{
let row = $('<div>').addClass ('ov_property_table_row').appendTo (table);
@ -45,6 +51,13 @@ OV.Sidebar = class
let valueColumn = $('<div>').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 = $('<div>').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 ();

View File

@ -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;