2018-01-23 09:52:05 -08:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2018, Lars Brubaker, John Lewin
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
2018-06-04 09:55:54 -07:00
|
|
|
|
using System.Threading;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using MatterHackers.Agg;
|
2018-02-27 18:16:07 -08:00
|
|
|
|
using MatterHackers.Agg.Image;
|
2018-02-12 17:45:57 -08:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.DataConverters3D;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2018-06-01 17:44:46 -07:00
|
|
|
|
using MatterHackers.MatterControl.DesignTools.EditableTypes;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
2018-06-04 09:55:54 -07:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow.View3D;
|
2018-02-09 18:10:41 -08:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
|
2018-01-23 09:52:05 -08:00
|
|
|
|
namespace MatterHackers.MatterControl.DesignTools
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-04-12 17:23:19 -07:00
|
|
|
|
public class EditableProperty
|
|
|
|
|
|
{
|
|
|
|
|
|
public IObject3D Item { get; private set; }
|
2018-06-08 08:41:15 -07:00
|
|
|
|
|
|
|
|
|
|
public object source;
|
2018-04-12 17:23:19 -07:00
|
|
|
|
public PropertyInfo PropertyInfo { get; private set; }
|
2018-06-09 07:38:27 -07:00
|
|
|
|
|
2018-06-08 08:41:15 -07:00
|
|
|
|
public EditableProperty(PropertyInfo p, object source)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-08 08:41:15 -07:00
|
|
|
|
this.source = source;
|
|
|
|
|
|
this.Item = source as IObject3D;
|
2018-04-12 17:23:19 -07:00
|
|
|
|
this.PropertyInfo = p;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string GetDescription(PropertyInfo prop)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nameAttribute = prop.GetCustomAttributes(true).OfType<DescriptionAttribute>().FirstOrDefault();
|
|
|
|
|
|
return nameAttribute?.Description ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetDisplayName(PropertyInfo prop)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nameAttribute = prop.GetCustomAttributes(true).OfType<DisplayNameAttribute>().FirstOrDefault();
|
|
|
|
|
|
return nameAttribute?.DisplayName ?? prop.Name.SplitCamelCase();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-08 08:41:15 -07:00
|
|
|
|
public object Value => PropertyInfo.GetGetMethod().Invoke(source, null);
|
2018-06-09 07:38:27 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Use reflection to set property value
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
|
public void SetValue(object value)
|
|
|
|
|
|
{
|
2018-06-08 08:41:15 -07:00
|
|
|
|
this.PropertyInfo.GetSetMethod().Invoke(source, new Object[] { value });
|
2018-06-09 07:38:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
public string DisplayName => GetDisplayName(PropertyInfo);
|
|
|
|
|
|
public string Description => GetDescription(PropertyInfo);
|
2018-04-23 16:18:16 -07:00
|
|
|
|
public Type PropertyType => PropertyInfo.PropertyType;
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-31 13:15:29 -08:00
|
|
|
|
public class PublicPropertyEditor : IObject3DEditor
|
2018-01-23 09:52:05 -08:00
|
|
|
|
{
|
|
|
|
|
|
public string Name => "Property Editor";
|
2018-01-20 12:58:14 -08:00
|
|
|
|
|
|
|
|
|
|
public bool Unlocked { get; } = true;
|
|
|
|
|
|
|
2018-06-20 08:09:35 -07:00
|
|
|
|
public IEnumerable<Type> SupportedTypes() => new Type[] { typeof(IObject3D) };
|
2018-03-27 14:03:12 -07:00
|
|
|
|
|
2018-02-27 18:16:07 -08:00
|
|
|
|
private static Type[] allowedTypes =
|
2018-01-28 07:53:23 -08:00
|
|
|
|
{
|
2018-03-13 11:52:23 -07:00
|
|
|
|
typeof(double), typeof(int), typeof(char), typeof(string), typeof(bool),
|
2018-02-12 17:45:57 -08:00
|
|
|
|
typeof(Vector2), typeof(Vector3),
|
2018-06-01 17:44:46 -07:00
|
|
|
|
typeof(DirectionVector), typeof(DirectionAxis),
|
2018-06-18 09:07:48 -07:00
|
|
|
|
typeof(ChildrenSelector),
|
|
|
|
|
|
typeof(ImageBuffer),
|
2018-01-28 07:53:23 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-01-31 14:34:10 -08:00
|
|
|
|
public const BindingFlags OwnedPropertiesOnly = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
2018-01-28 07:53:23 -08:00
|
|
|
|
|
2018-06-09 10:13:19 -07:00
|
|
|
|
public GuiWidget Create(IObject3D item, ThemeConfig theme)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
|
|
|
|
|
var mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-06-09 10:13:19 -07:00
|
|
|
|
// TODO: Long term we should have a solution where editors can extend Draw and Undo without this hack
|
|
|
|
|
|
var view3DWidget = ApplicationController.Instance.DragDropData.View3DWidget;
|
|
|
|
|
|
var undoBuffer = view3DWidget.sceneContext.Scene.UndoBuffer;
|
|
|
|
|
|
|
2018-06-09 09:01:24 -07:00
|
|
|
|
if (item is IEditorDraw editorDraw)
|
2018-03-17 20:53:36 -07:00
|
|
|
|
{
|
2018-06-09 10:13:19 -07:00
|
|
|
|
// TODO: Putting the drawing code in the IObject3D means almost certain bindings to MatterControl in IObject3D. If instead
|
|
|
|
|
|
// we had a UI layer object that used binding to register scene drawing hooks for specific types, we could avoid the bindings
|
2018-03-17 20:53:36 -07:00
|
|
|
|
view3DWidget.InteractionLayer.DrawGlOpaqueContent += editorDraw.DrawEditor;
|
|
|
|
|
|
mainContainer.Closed += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
view3DWidget.InteractionLayer.DrawGlOpaqueContent -= editorDraw.DrawEditor;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-09 09:26:37 -07:00
|
|
|
|
if (item != null)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-06-09 09:26:37 -07:00
|
|
|
|
var context = new PPEContext()
|
|
|
|
|
|
{
|
|
|
|
|
|
item = item
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// CreateEditor
|
2018-06-09 09:01:24 -07:00
|
|
|
|
AddWebPageLinkIfRequired(context, mainContainer, theme);
|
|
|
|
|
|
AddUnlockLinkIfRequired(context, mainContainer, theme);
|
|
|
|
|
|
|
|
|
|
|
|
// Create a field editor for each editable property detected via reflection
|
|
|
|
|
|
foreach (var property in GetEditablePropreties(context.item))
|
|
|
|
|
|
{
|
2018-06-09 10:28:06 -07:00
|
|
|
|
var editor = CreatePropertyEditor(property, undoBuffer, context, theme);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
if (editor != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mainContainer.AddChild(editor);
|
|
|
|
|
|
}
|
2018-06-09 09:01:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add in an Update button if applicable
|
2018-06-11 15:23:39 -07:00
|
|
|
|
var showUpdate = context.item.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() as ShowUpdateButtonAttribute;
|
|
|
|
|
|
if (showUpdate != null)
|
2018-06-09 09:01:24 -07:00
|
|
|
|
{
|
|
|
|
|
|
var updateButton = theme.ButtonFactory.Generate("Update".Localize());
|
|
|
|
|
|
updateButton.Margin = new BorderDouble(5);
|
|
|
|
|
|
updateButton.HAnchor = HAnchor.Right;
|
|
|
|
|
|
updateButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
2018-06-20 17:16:38 -07:00
|
|
|
|
context.item.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-06-09 09:01:24 -07:00
|
|
|
|
};
|
|
|
|
|
|
mainContainer.AddChild(updateButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Init with custom 'UpdateControls' hooks
|
|
|
|
|
|
(context.item as IPropertyGridModifier)?.UpdateControls(context);
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mainContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsRow(EditableProperty property, UIField field)
|
2018-05-09 13:35:38 -07:00
|
|
|
|
{
|
2018-06-08 16:20:57 -07:00
|
|
|
|
var row = CreateSettingsRow(property.DisplayName.Localize(), property.Description.Localize());
|
2018-06-09 07:24:53 -07:00
|
|
|
|
row.AddChild(field.Content);
|
2018-06-08 16:20:57 -07:00
|
|
|
|
|
|
|
|
|
|
return row;
|
2018-05-09 13:35:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-10 20:17:09 -08:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsRow(string labelText, string toolTipText = null)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
|
|
|
|
|
var rowContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-02-10 20:17:09 -08:00
|
|
|
|
Padding = new BorderDouble(5),
|
|
|
|
|
|
ToolTipText = toolTipText
|
2018-01-20 12:58:14 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-01-21 14:38:36 -08:00
|
|
|
|
var label = new TextWidget(labelText + ":", pointSize: 11, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0, 0, 3, 0),
|
|
|
|
|
|
VAnchor = VAnchor.Center
|
|
|
|
|
|
};
|
|
|
|
|
|
rowContainer.AddChild(label);
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(new HorizontalSpacer());
|
|
|
|
|
|
|
|
|
|
|
|
return rowContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
private static FlowLayoutWidget CreateSettingsColumn(EditableProperty property)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CreateSettingsColumn(property.DisplayName.Localize(), property.Description.Localize());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static FlowLayoutWidget CreateSettingsColumn(string labelText, string toolTipText = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var columnContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
Padding = new BorderDouble(5),
|
|
|
|
|
|
ToolTipText = toolTipText
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var label = new TextWidget(labelText + ":", pointSize: 11, textColor: ActiveTheme.Instance.PrimaryTextColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0, 3, 0, 0),
|
|
|
|
|
|
HAnchor = HAnchor.Left
|
|
|
|
|
|
};
|
|
|
|
|
|
columnContainer.AddChild(label);
|
|
|
|
|
|
|
|
|
|
|
|
return columnContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
public static IEnumerable<EditableProperty> GetEditablePropreties(IObject3D item)
|
2018-04-01 16:06:31 -07:00
|
|
|
|
{
|
|
|
|
|
|
return item.GetType().GetProperties(OwnedPropertiesOnly)
|
|
|
|
|
|
.Where(pi => (allowedTypes.Contains(pi.PropertyType) || pi.PropertyType.IsEnum)
|
|
|
|
|
|
&& pi.GetGetMethod() != null
|
|
|
|
|
|
&& pi.GetSetMethod() != null)
|
|
|
|
|
|
.Select(p => new EditableProperty(p, item));
|
2018-02-10 20:17:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-09 10:28:06 -07:00
|
|
|
|
public static GuiWidget CreatePropertyEditor(EditableProperty property, UndoBuffer undoBuffer, PPEContext context, ThemeConfig theme)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-20 08:09:35 -07:00
|
|
|
|
var rebuildable = property.Item;
|
2018-06-09 08:56:16 -07:00
|
|
|
|
var propertyGridModifier = property.Item as IPropertyGridModifier;
|
|
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
GuiWidget rowContainer = null;
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-06-11 16:45:04 -07:00
|
|
|
|
// Get reflected property value once, then test for each case below
|
|
|
|
|
|
var propertyValue = property.Value;
|
|
|
|
|
|
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a double editor
|
2018-06-11 16:45:04 -07:00
|
|
|
|
if (propertyValue is double doubleValue)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
var field = new DoubleField();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.DoubleValue = doubleValue;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-01-21 14:38:36 -08:00
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(field.DoubleValue);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-02-09 18:10:41 -08:00
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is Vector2 vector2)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
var field = new Vector2Field();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Vector2 = vector2;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(field.Vector2);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-02-10 20:17:09 -08:00
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is Vector3 vector3)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
var field = new Vector3Field();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Vector3 = vector3;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(field.Vector3);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-02-10 20:17:09 -08:00
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is DirectionVector directionVector)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-08 20:42:06 -07:00
|
|
|
|
var field = new DirectionVectorField();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(directionVector);
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-02-09 18:10:41 -08:00
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(field.DirectionVector);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-06-08 20:42:06 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-06-08 16:25:35 -07:00
|
|
|
|
};
|
2018-02-14 19:56:46 -08:00
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is DirectionAxis directionAxis)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-08 16:25:35 -07:00
|
|
|
|
// the direction axis
|
|
|
|
|
|
// the distance from the center of the part
|
|
|
|
|
|
// create a double editor
|
|
|
|
|
|
var field = new DoubleField();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.DoubleValue = directionAxis.Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(
|
2018-06-08 16:25:35 -07:00
|
|
|
|
new DirectionAxis()
|
2018-06-08 16:20:57 -07:00
|
|
|
|
{
|
2018-06-08 16:25:35 -07:00
|
|
|
|
Normal = Vector3.UnitZ, Origin = property.Item.Children.First().GetAxisAlignedBoundingBox().Center + new Vector3(field.DoubleValue, 0, 0)
|
2018-06-09 07:38:27 -07:00
|
|
|
|
});
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-06-08 16:25:35 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
|
|
|
|
|
};
|
2018-06-08 16:20:57 -07:00
|
|
|
|
|
2018-06-08 21:08:56 -07:00
|
|
|
|
// update this when changed
|
2018-06-08 16:25:35 -07:00
|
|
|
|
EventHandler<InvalidateArgs> updateData = (s, e) =>
|
2018-03-13 11:52:23 -07:00
|
|
|
|
{
|
2018-06-09 07:26:52 -07:00
|
|
|
|
field.DoubleValue = ((DirectionAxis)property.Value).Origin.X - property.Item.Children.First().GetAxisAlignedBoundingBox().Center.X;
|
2018-06-08 16:25:35 -07:00
|
|
|
|
};
|
|
|
|
|
|
property.Item.Invalidated += updateData;
|
2018-06-09 09:55:25 -07:00
|
|
|
|
field.Content.Closed += (s, e) =>
|
2018-06-08 16:25:35 -07:00
|
|
|
|
{
|
|
|
|
|
|
property.Item.Invalidated -= updateData;
|
|
|
|
|
|
};
|
2018-04-12 17:23:19 -07:00
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is ChildrenSelector childSelector)
|
2018-06-01 17:44:46 -07:00
|
|
|
|
{
|
|
|
|
|
|
rowContainer = CreateSettingsColumn(property);
|
|
|
|
|
|
rowContainer.AddChild(CreateSelector(childSelector, property.Item, theme));
|
|
|
|
|
|
}
|
2018-06-18 09:07:48 -07:00
|
|
|
|
else if (propertyValue is ImageBuffer imageBuffer)
|
|
|
|
|
|
{
|
|
|
|
|
|
rowContainer = CreateSettingsColumn(property);
|
|
|
|
|
|
rowContainer.AddChild(CreateImageDisplay(imageBuffer, property.Item, theme));
|
|
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a int editor
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is int intValue)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
var field = new IntField();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.IntValue = intValue;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-02-27 18:16:07 -08:00
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(field.IntValue);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-02-13 13:42:57 -08:00
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a bool editor
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is bool boolValue)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-04-12 17:45:50 -07:00
|
|
|
|
var field = new ToggleboxField(theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.Checked = boolValue;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(field.Checked);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
// create a string editor
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is string stringValue)
|
2018-01-20 12:58:14 -08:00
|
|
|
|
{
|
2018-06-08 16:48:50 -07:00
|
|
|
|
var field = new TextField();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(stringValue, false);
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(field.Value);
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-03-08 17:23:03 -08:00
|
|
|
|
};
|
2018-06-08 16:20:57 -07:00
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-03-08 17:23:03 -08:00
|
|
|
|
}
|
2018-04-12 17:23:19 -07:00
|
|
|
|
// create a char editor
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is char charValue)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-08 18:19:06 -07:00
|
|
|
|
var field = new CharField();
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.SetValue(charValue.ToString(), false);
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(Convert.ToChar(field.Value));
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-05-02 10:59:08 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
};
|
2018-06-08 18:19:06 -07:00
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
// create an enum editor
|
2018-04-23 16:18:16 -07:00
|
|
|
|
else if (property.PropertyType.IsEnum)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-09 07:14:38 -07:00
|
|
|
|
UIField field;
|
2018-06-09 06:34:31 -07:00
|
|
|
|
var iconsAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<IconsAttribute>().FirstOrDefault();
|
2018-06-09 07:14:38 -07:00
|
|
|
|
if (iconsAttribute != null)
|
|
|
|
|
|
{
|
2018-06-11 16:47:31 -07:00
|
|
|
|
field = new IconEnumField(property, iconsAttribute)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitialValue = propertyValue.ToString()
|
|
|
|
|
|
};
|
2018-06-09 07:14:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
field = new EnumField(property);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-09 06:34:31 -07:00
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
2018-06-09 07:38:27 -07:00
|
|
|
|
property.SetValue(Enum.Parse(property.PropertyType, field.Value));
|
2018-06-20 17:16:38 -07:00
|
|
|
|
rebuildable?.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties, undoBuffer));
|
2018-06-09 06:34:31 -07:00
|
|
|
|
propertyGridModifier?.UpdateControls(context);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-06-09 07:24:53 -07:00
|
|
|
|
rowContainer = CreateSettingsRow(property, field);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
// Use known IObject3D editors
|
2018-06-11 16:45:04 -07:00
|
|
|
|
else if (propertyValue is IObject3D object3D
|
2018-06-09 09:55:25 -07:00
|
|
|
|
&& ApplicationController.Instance.GetEditorsForType(property.PropertyType)?.FirstOrDefault() is IObject3DEditor iObject3DEditor)
|
2018-04-12 17:23:19 -07:00
|
|
|
|
{
|
2018-06-09 10:13:19 -07:00
|
|
|
|
rowContainer = iObject3DEditor.Create(object3D, theme);
|
2018-04-12 17:23:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remember the row name and widget
|
2018-05-02 10:59:08 -07:00
|
|
|
|
context.editRows.Add(property.PropertyInfo.Name, rowContainer);
|
2018-06-09 09:55:25 -07:00
|
|
|
|
|
|
|
|
|
|
return rowContainer;
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
2018-02-12 15:28:26 -08:00
|
|
|
|
|
2018-06-18 09:07:48 -07:00
|
|
|
|
private static GuiWidget CreateImageDisplay(ImageBuffer imageBuffer, IObject3D parent, ThemeConfig theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ImageWidget(imageBuffer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
private static GuiWidget CreateSelector(ChildrenSelector childSelector, IObject3D parent, ThemeConfig theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
GuiWidget tabContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
|
2018-06-04 09:55:54 -07:00
|
|
|
|
void UpdateSelectColors(bool selectionChanged = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var child in parent.Children.ToList())
|
|
|
|
|
|
{
|
2018-06-20 08:09:35 -07:00
|
|
|
|
using (child.RebuildLock())
|
2018-06-04 09:55:54 -07:00
|
|
|
|
{
|
2018-06-20 08:09:35 -07:00
|
|
|
|
if (!childSelector.Contains(child.ID)
|
|
|
|
|
|
|| tabContainer.HasBeenClosed)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Color = new Color(child.WorldColor(), 255);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Color = new Color(child.WorldColor(), 200);
|
|
|
|
|
|
}
|
2018-06-04 09:55:54 -07:00
|
|
|
|
|
2018-06-20 08:09:35 -07:00
|
|
|
|
if (selectionChanged)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Visible = true;
|
|
|
|
|
|
}
|
2018-06-04 09:55:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tabContainer.Closed += (s, e) => UpdateSelectColors();
|
|
|
|
|
|
|
2018-06-01 17:44:46 -07:00
|
|
|
|
var children = parent.Children.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<ICheckbox, IObject3D> objectChecks = new Dictionary<ICheckbox, IObject3D>();
|
|
|
|
|
|
|
|
|
|
|
|
List<GuiWidget> radioSiblings = new List<GuiWidget>();
|
|
|
|
|
|
for (int i = 0; i < children.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var itemIndex = i;
|
|
|
|
|
|
var child = children[itemIndex];
|
|
|
|
|
|
FlowLayoutWidget rowContainer = new FlowLayoutWidget();
|
|
|
|
|
|
|
|
|
|
|
|
GuiWidget selectWidget;
|
|
|
|
|
|
if (children.Count == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
|
|
|
|
|
|
{
|
|
|
|
|
|
Checked = childSelector.Contains(child.ID),
|
|
|
|
|
|
TextColor = ActiveTheme.Instance.PrimaryTextColor
|
|
|
|
|
|
};
|
|
|
|
|
|
radioSiblings.Add(radioButton);
|
|
|
|
|
|
radioButton.SiblingRadioButtonList = radioSiblings;
|
|
|
|
|
|
selectWidget = radioButton;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
|
|
|
|
|
|
{
|
|
|
|
|
|
Checked = childSelector.Contains(child.ID),
|
|
|
|
|
|
TextColor = ActiveTheme.Instance.PrimaryTextColor
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
objectChecks.Add((ICheckbox)selectWidget, child);
|
|
|
|
|
|
|
|
|
|
|
|
rowContainer.AddChild(selectWidget);
|
|
|
|
|
|
ICheckbox checkBox = selectWidget as ICheckbox;
|
|
|
|
|
|
|
|
|
|
|
|
checkBox.CheckedStateChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (s is ICheckbox checkbox)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (checkBox.Checked)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!childSelector.Contains(objectChecks[checkbox].ID))
|
|
|
|
|
|
{
|
|
|
|
|
|
childSelector.Add(objectChecks[checkbox].ID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (childSelector.Contains(objectChecks[checkbox].ID))
|
|
|
|
|
|
{
|
|
|
|
|
|
childSelector.Remove(objectChecks[checkbox].ID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-04 09:55:54 -07:00
|
|
|
|
|
|
|
|
|
|
if(parent is MeshWrapperObject3D meshWrapper)
|
|
|
|
|
|
{
|
2018-06-20 08:09:35 -07:00
|
|
|
|
using (meshWrapper.RebuildLock())
|
|
|
|
|
|
{
|
|
|
|
|
|
meshWrapper.ResetMeshWrapperMeshes(Object3DPropertyFlags.All, CancellationToken.None);
|
|
|
|
|
|
}
|
2018-06-04 09:55:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdateSelectColors(true);
|
2018-06-01 17:44:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
tabContainer.AddChild(rowContainer);
|
2018-06-04 09:55:54 -07:00
|
|
|
|
UpdateSelectColors();
|
2018-06-01 17:44:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
bool operationApplied = parent.Descendants()
|
|
|
|
|
|
.Where((obj) => obj.OwnerID == parent.ID)
|
|
|
|
|
|
.Where((objId) => objId.Mesh != objId.Children.First().Mesh).Any();
|
|
|
|
|
|
|
|
|
|
|
|
bool selectionHasBeenMade = parent.Descendants()
|
|
|
|
|
|
.Where((obj) => obj.OwnerID == parent.ID && obj.OutputType == PrintOutputTypes.Hole)
|
|
|
|
|
|
.Any();
|
|
|
|
|
|
|
|
|
|
|
|
if (!operationApplied && !selectionHasBeenMade)
|
|
|
|
|
|
{
|
|
|
|
|
|
// select the last item
|
|
|
|
|
|
if (tabContainer.Descendants().Where((d) => d is ICheckbox).Last() is ICheckbox lastCheckBox)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastCheckBox.Checked = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
updateButton.Enabled = !operationApplied;
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
return tabContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
private void AddUnlockLinkIfRequired(PPEContext context, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
|
2018-02-26 15:28:00 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var unlockLink = context.item.GetType().GetCustomAttributes(typeof(UnlockLinkAttribute), true).FirstOrDefault() as UnlockLinkAttribute;
|
2018-02-26 15:28:00 -08:00
|
|
|
|
if (unlockLink != null
|
2018-03-10 16:32:04 -08:00
|
|
|
|
&& !string.IsNullOrEmpty(unlockLink.UnlockPageLink)
|
2018-05-02 10:59:08 -07:00
|
|
|
|
&& !context.item.Persistable)
|
2018-02-26 15:28:00 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var row = CreateSettingsRow(context.item.Persistable ? "Registered".Localize() : "Demo Mode".Localize());
|
2018-03-07 10:51:58 -08:00
|
|
|
|
|
2018-02-26 15:28:00 -08:00
|
|
|
|
Button detailsLink = theme.ButtonFactory.Generate("Unlock".Localize(), AggContext.StaticData.LoadIcon("locked.png", 16, 16));
|
2018-05-08 18:06:21 -07:00
|
|
|
|
detailsLink.BackgroundColor = theme.Colors.PrimaryAccentColor.AdjustContrast(theme.Colors.PrimaryTextColor, 10).ToColor();
|
2018-02-26 15:28:00 -08:00
|
|
|
|
detailsLink.Margin = new BorderDouble(5);
|
|
|
|
|
|
detailsLink.Click += (s, e) =>
|
|
|
|
|
|
{
|
2018-03-10 16:32:04 -08:00
|
|
|
|
ApplicationController.Instance.LaunchBrowser(UnlockLinkAttribute.UnlockPageBaseUrl + unlockLink.UnlockPageLink);
|
|
|
|
|
|
};
|
|
|
|
|
|
row.AddChild(detailsLink);
|
|
|
|
|
|
editControlsContainer.AddChild(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-02 10:59:08 -07:00
|
|
|
|
private void AddWebPageLinkIfRequired(PPEContext context, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
|
2018-03-10 16:32:04 -08:00
|
|
|
|
{
|
2018-05-02 10:59:08 -07:00
|
|
|
|
var unlockLink = context.item.GetType().GetCustomAttributes(typeof(WebPageLinkAttribute), true).FirstOrDefault() as WebPageLinkAttribute;
|
2018-03-10 16:32:04 -08:00
|
|
|
|
if (unlockLink != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var row = CreateSettingsRow(unlockLink.Name.Localize());
|
|
|
|
|
|
|
|
|
|
|
|
Button detailsLink = theme.ButtonFactory.Generate("Open", AggContext.StaticData.LoadIcon("internet.png", 16, 16));
|
|
|
|
|
|
detailsLink.Margin = new BorderDouble(5);
|
|
|
|
|
|
detailsLink.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ApplicationController.Instance.LaunchBrowser(unlockLink.Url);
|
2018-02-26 15:28:00 -08:00
|
|
|
|
};
|
|
|
|
|
|
row.AddChild(detailsLink);
|
|
|
|
|
|
editControlsContainer.AddChild(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-01-20 12:58:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|