2015-02-26 13:28:36 -08:00
|
|
|
|
/*
|
2017-10-18 14:56:10 -07:00
|
|
|
|
Copyright (c) 2017, Lars Brubaker, John Lewin
|
2015-02-26 13:28:36 -08:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2015-02-26 13:28:36 -08:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2015-02-26 13:28:36 -08:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2015-02-26 13:28:36 -08:00
|
|
|
|
|
|
|
|
|
|
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
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2015-02-26 13:28:36 -08:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-10-18 18:18:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2017-11-15 09:24:56 -08:00
|
|
|
|
using System.Threading.Tasks;
|
2017-03-15 16:17:06 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2015-02-26 13:28:36 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-10-18 14:56:10 -07:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2017-03-15 16:17:06 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2017-11-15 09:24:56 -08:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
|
|
|
|
|
using MatterHackers.MatterControl.Library;
|
2018-01-30 11:50:22 -08:00
|
|
|
|
using MatterHackers.MatterControl.DesignTools;
|
|
|
|
|
|
using MatterHackers.MatterControl.DesignTools.Operations;
|
2018-01-31 14:36:08 -08:00
|
|
|
|
using System.Reflection;
|
2018-02-05 17:22:19 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
using MatterHackers.Agg.Image;
|
2018-02-12 15:28:26 -08:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2015-02-26 13:28:36 -08:00
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
2015-02-26 13:28:36 -08:00
|
|
|
|
{
|
2018-01-31 14:36:08 -08:00
|
|
|
|
public interface IObject3DComponent
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-11 01:13:38 -08:00
|
|
|
|
public class SelectedObjectPanel : FlowLayoutWidget, IContentStore
|
2017-03-15 16:17:06 -07:00
|
|
|
|
{
|
2017-10-18 14:56:10 -07:00
|
|
|
|
private IObject3D item = new Object3D();
|
|
|
|
|
|
|
2018-01-09 18:43:58 -08:00
|
|
|
|
private FlowLayoutWidget scrollableContent;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
private ThemeConfig theme;
|
|
|
|
|
|
private View3DWidget view3DWidget;
|
|
|
|
|
|
private InteractiveScene scene;
|
2017-11-29 16:40:46 -08:00
|
|
|
|
private PrinterConfig printer;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
private Dictionary<Type, HashSet<IObject3DEditor>> objectEditorsByType;
|
2018-01-08 23:34:40 -08:00
|
|
|
|
private SectionWidget editorSection;
|
|
|
|
|
|
private TextButton editButton;
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2018-01-09 18:43:58 -08:00
|
|
|
|
private GuiWidget editorPanel;
|
2018-01-17 23:17:49 -08:00
|
|
|
|
private InlineTitleEdit inlineTitleEdit;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
2017-11-29 16:40:46 -08:00
|
|
|
|
public SelectedObjectPanel(View3DWidget view3DWidget, InteractiveScene scene, ThemeConfig theme, PrinterConfig printer)
|
2017-10-18 14:56:10 -07:00
|
|
|
|
: base(FlowDirection.TopToBottom)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-01-08 14:23:26 -08:00
|
|
|
|
this.HAnchor = HAnchor.Stretch;
|
2017-10-18 14:56:10 -07:00
|
|
|
|
this.VAnchor = VAnchor.Top | VAnchor.Fit;
|
2018-01-08 23:34:40 -08:00
|
|
|
|
this.Padding = 0; // new BorderDouble(8, 10);
|
2018-01-09 18:43:58 -08:00
|
|
|
|
//this.MinimumSize = new VectorMath.Vector2(220, 0);
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
|
|
|
|
|
this.view3DWidget = view3DWidget;
|
|
|
|
|
|
this.theme = theme;
|
|
|
|
|
|
this.scene = scene;
|
2017-11-29 16:40:46 -08:00
|
|
|
|
this.printer = printer;
|
2017-10-18 14:56:10 -07:00
|
|
|
|
|
2018-01-24 17:49:16 -08:00
|
|
|
|
this.AddChild(inlineTitleEdit = new InlineTitleEdit("", theme, "Object Name"));
|
2018-01-17 23:17:49 -08:00
|
|
|
|
inlineTitleEdit.TitleChanged += (s, e) =>
|
2018-01-08 23:34:40 -08:00
|
|
|
|
{
|
2018-01-17 23:17:49 -08:00
|
|
|
|
if (item != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Name = inlineTitleEdit.Text;
|
|
|
|
|
|
}
|
2018-01-08 23:34:40 -08:00
|
|
|
|
};
|
2017-10-18 14:56:10 -07:00
|
|
|
|
|
2018-01-09 18:43:58 -08:00
|
|
|
|
scrollableContent = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2017-10-18 14:56:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
2018-01-05 11:45:11 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var scrollable = new ScrollableWidget(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "editorPanel",
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-01-09 18:43:58 -08:00
|
|
|
|
scrollable.AddChild(scrollableContent);
|
2018-01-05 11:45:11 -08:00
|
|
|
|
scrollable.ScrollArea.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
|
|
|
|
|
|
this.AddChild(scrollable);
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
2018-01-08 23:34:40 -08:00
|
|
|
|
// Add heading separator
|
2018-01-09 18:43:58 -08:00
|
|
|
|
scrollableContent.AddChild(new HorizontalLine(25)
|
2018-01-08 23:34:40 -08:00
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0)
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-09 18:43:58 -08:00
|
|
|
|
var editorColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var toolbar = new Toolbar()
|
|
|
|
|
|
{
|
|
|
|
|
|
Padding = theme.ToolbarPadding,
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
};
|
|
|
|
|
|
editorColumn.AddChild(toolbar);
|
|
|
|
|
|
|
|
|
|
|
|
// put in the button for making the behavior solid
|
2018-02-14 08:08:18 -08:00
|
|
|
|
var solidBehaviorButton = new PopupMenuButton("Color".Localize(), theme)
|
2018-01-09 18:43:58 -08:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Solid Colors",
|
2018-02-14 08:08:18 -08:00
|
|
|
|
DrawArrow = true,
|
2018-01-09 18:43:58 -08:00
|
|
|
|
AlignToRightEdge = true,
|
2018-02-16 09:29:54 -08:00
|
|
|
|
PopupContent = new ColorSwatchSelector(scene, theme, buttonSpacing: 3)
|
2018-01-09 18:43:58 -08:00
|
|
|
|
{
|
2018-02-15 22:29:47 -08:00
|
|
|
|
BackgroundColor = ActiveTheme.Instance.TertiaryBackgroundColor,
|
2018-01-09 18:43:58 -08:00
|
|
|
|
HAnchor = HAnchor.Fit,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
},
|
|
|
|
|
|
Margin = theme.ButtonSpacing.Clone(left: 0),
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade
|
|
|
|
|
|
};
|
|
|
|
|
|
toolbar.AddChild(solidBehaviorButton);
|
|
|
|
|
|
|
|
|
|
|
|
editButton = new TextButton("Edit".Localize(), theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
Margin = theme.ButtonSpacing
|
|
|
|
|
|
};
|
|
|
|
|
|
editButton.Click += async (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var bed = new BedConfig();
|
|
|
|
|
|
|
|
|
|
|
|
var partPreviewContent = this.Parents<PartPreviewContent>().FirstOrDefault();
|
|
|
|
|
|
partPreviewContent.CreatePartTab(
|
|
|
|
|
|
"New Part",
|
|
|
|
|
|
bed,
|
|
|
|
|
|
theme);
|
|
|
|
|
|
|
2018-02-05 17:22:19 -08:00
|
|
|
|
var clonedItem = this.item.Clone();
|
|
|
|
|
|
|
|
|
|
|
|
// Edit in Identity transform
|
|
|
|
|
|
clonedItem.Matrix = Matrix4X4.Identity;
|
|
|
|
|
|
|
2018-01-09 18:43:58 -08:00
|
|
|
|
await bed.LoadContent(
|
|
|
|
|
|
new EditContext()
|
|
|
|
|
|
{
|
2018-02-09 21:21:49 -08:00
|
|
|
|
ContentStore = new DynamicContentStore((libraryItem, object3D) =>
|
2018-02-05 17:22:19 -08:00
|
|
|
|
{
|
2018-02-05 17:24:05 -08:00
|
|
|
|
var replacement = object3D.Clone();
|
|
|
|
|
|
|
2018-02-05 17:22:19 -08:00
|
|
|
|
this.item.Parent.Children.Modify(list =>
|
|
|
|
|
|
{
|
|
|
|
|
|
list.Remove(item);
|
|
|
|
|
|
|
|
|
|
|
|
// Restore matrix of item being replaced
|
|
|
|
|
|
replacement.Matrix = item.Matrix;
|
|
|
|
|
|
|
|
|
|
|
|
list.Add(replacement);
|
|
|
|
|
|
|
|
|
|
|
|
item = replacement;
|
|
|
|
|
|
});
|
2018-02-05 17:24:05 -08:00
|
|
|
|
|
|
|
|
|
|
scene.SelectedItem = replacement;
|
2018-02-05 17:22:19 -08:00
|
|
|
|
}),
|
|
|
|
|
|
SourceItem = new InMemoryItem(clonedItem),
|
2018-01-09 18:43:58 -08:00
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
toolbar.AddChild(editButton);
|
|
|
|
|
|
|
2018-02-12 15:28:26 -08:00
|
|
|
|
// put in a bake button
|
|
|
|
|
|
var icon = AggContext.StaticData.LoadIcon("bake.png", 16, 16).SetPreMultiply();
|
|
|
|
|
|
var bakeButton = new IconButton(icon, theme)
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2018-02-12 15:28:26 -08:00
|
|
|
|
Margin = theme.ButtonSpacing,
|
|
|
|
|
|
ToolTipText = "Bake operation into parts".Localize()
|
2018-01-30 11:50:22 -08:00
|
|
|
|
};
|
2018-02-12 15:28:26 -08:00
|
|
|
|
bakeButton.Click += (s, e) =>
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2018-02-12 15:28:26 -08:00
|
|
|
|
scene.SelectedItem = null;
|
|
|
|
|
|
this.item.Bake();
|
2018-01-30 11:50:22 -08:00
|
|
|
|
};
|
2018-02-12 15:28:26 -08:00
|
|
|
|
scene.SelectionChanged += (s, e) => bakeButton.Enabled = scene.SelectedItem?.CanBake == true;
|
|
|
|
|
|
toolbar.AddChild(bakeButton);
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2018-02-12 15:28:26 -08:00
|
|
|
|
// put in a remove button
|
|
|
|
|
|
var removeButton = new IconButton(ThemeConfig.RestoreNormal, theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = theme.ButtonSpacing,
|
|
|
|
|
|
ToolTipText = "Remove operation from parts".Localize()
|
|
|
|
|
|
};
|
|
|
|
|
|
removeButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
scene.SelectedItem = null;
|
|
|
|
|
|
this.item.Remove();
|
|
|
|
|
|
};
|
|
|
|
|
|
scene.SelectionChanged += (s, e) => removeButton.Enabled = scene.SelectedItem?.CanRemove == true;
|
|
|
|
|
|
toolbar.AddChild(removeButton);
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2018-01-09 18:43:58 -08:00
|
|
|
|
// Add container used to host the current specialized editor for the selection
|
2018-01-30 11:50:22 -08:00
|
|
|
|
editorColumn.AddChild(editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2018-01-09 18:43:58 -08:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
2018-01-11 01:07:44 -08:00
|
|
|
|
Padding = new BorderDouble(top: 10)
|
2018-01-09 18:43:58 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
2018-01-10 15:00:59 -08:00
|
|
|
|
editorSection = new SectionWidget("Editor", editorColumn, theme);
|
2018-01-09 18:43:58 -08:00
|
|
|
|
scrollableContent.AddChild(editorSection);
|
2018-01-08 23:34:40 -08:00
|
|
|
|
|
2018-02-16 09:29:54 -08:00
|
|
|
|
var colorSection = new SectionWidget("Color".Localize(), new ColorSwatchSelector(scene, theme, buttonSize: 16, buttonSpacing: new BorderDouble(1, 1, 0, 0))
|
2018-02-15 22:29:47 -08:00
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(left: 10)
|
|
|
|
|
|
}, theme, expanded: false)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Color Panel",
|
|
|
|
|
|
};
|
|
|
|
|
|
scrollableContent.AddChild(colorSection);
|
|
|
|
|
|
|
2018-01-10 15:00:59 -08:00
|
|
|
|
var mirrorSection = new SectionWidget("Mirror".Localize(), new MirrorControls(scene, theme), theme, expanded: false)
|
2018-01-08 23:34:40 -08:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Mirror Panel",
|
|
|
|
|
|
};
|
2018-01-09 18:43:58 -08:00
|
|
|
|
scrollableContent.AddChild(mirrorSection);
|
2018-01-08 23:34:40 -08:00
|
|
|
|
|
2018-01-10 15:00:59 -08:00
|
|
|
|
var scaleSection = new SectionWidget("Scale".Localize(), new ScaleControls(scene, theme), theme, expanded: false)
|
2018-01-08 23:34:40 -08:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Scale Panel",
|
|
|
|
|
|
};
|
2018-01-09 18:43:58 -08:00
|
|
|
|
scrollableContent.AddChild(scaleSection);
|
2018-01-08 23:34:40 -08:00
|
|
|
|
|
2018-01-10 15:00:59 -08:00
|
|
|
|
var materialsSection = new SectionWidget("Materials".Localize(), new MaterialControls(scene, theme), theme, expanded: false)
|
2018-01-08 23:34:40 -08:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Materials Panel",
|
|
|
|
|
|
};
|
2018-01-09 18:43:58 -08:00
|
|
|
|
scrollableContent.AddChild(materialsSection);
|
2018-01-08 23:34:40 -08:00
|
|
|
|
|
2018-01-10 09:04:31 -08:00
|
|
|
|
// Enforce panel padding in sidebar
|
|
|
|
|
|
foreach(var sectionWidget in scrollableContent.Children<SectionWidget>())
|
|
|
|
|
|
{
|
2018-02-16 18:47:28 -08:00
|
|
|
|
sectionWidget.ContentPanel.Padding = new BorderDouble(10, 10, 10, 0);
|
2018-01-10 09:04:31 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-18 18:18:10 -07:00
|
|
|
|
HashSet<IObject3DEditor> mappedEditors;
|
|
|
|
|
|
objectEditorsByType = new Dictionary<Type, HashSet<IObject3DEditor>>();
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Consider only loading once into a static
|
|
|
|
|
|
var objectEditors = PluginFinder.CreateInstancesOf<IObject3DEditor>();
|
|
|
|
|
|
foreach (IObject3DEditor editor in objectEditors)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (Type type in editor.SupportedTypes())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!objectEditorsByType.TryGetValue(type, out mappedEditors))
|
|
|
|
|
|
{
|
|
|
|
|
|
mappedEditors = new HashSet<IObject3DEditor>();
|
|
|
|
|
|
objectEditorsByType.Add(type, mappedEditors);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mappedEditors.Add(editor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-18 14:56:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
private static Type componentType = typeof(IObject3DComponent);
|
|
|
|
|
|
private static Type iobject3DType = typeof(IObject3D);
|
|
|
|
|
|
|
2017-10-18 18:18:10 -07:00
|
|
|
|
public void SetActiveItem(IObject3D selectedItem)
|
2017-10-18 14:56:10 -07:00
|
|
|
|
{
|
2017-10-18 18:18:10 -07:00
|
|
|
|
if (!scene.HasSelection)
|
|
|
|
|
|
{
|
2017-10-20 07:26:14 -07:00
|
|
|
|
this.Parent.Visible = false;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-26 17:53:54 -08:00
|
|
|
|
var selectedItemType = selectedItem.GetType();
|
|
|
|
|
|
|
2017-11-16 15:47:48 -08:00
|
|
|
|
editButton.Enabled = (selectedItem.Children.Count > 0);
|
|
|
|
|
|
|
2018-01-26 17:53:54 -08:00
|
|
|
|
inlineTitleEdit.Text = selectedItem.Name ?? selectedItemType.Name;
|
2017-10-18 14:56:10 -07:00
|
|
|
|
|
|
|
|
|
|
this.item = selectedItem;
|
|
|
|
|
|
|
2017-11-29 16:40:46 -08:00
|
|
|
|
var viewMode = printer?.ViewState.ViewMode;
|
|
|
|
|
|
|
|
|
|
|
|
this.Parent.Visible = viewMode == null || viewMode == PartViewMode.Model;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
HashSet<IObject3DEditor> mappedEditors = GetEditorsForType(selectedItemType);
|
2018-02-06 08:49:05 -08:00
|
|
|
|
|
|
|
|
|
|
var activeEditors = new List<(IObject3DEditor, IObject3D)>();
|
|
|
|
|
|
|
|
|
|
|
|
if (componentType.IsAssignableFrom(selectedItemType))
|
2017-10-18 18:18:10 -07:00
|
|
|
|
{
|
2018-02-06 08:49:05 -08:00
|
|
|
|
var members = from item in selectedItemType.GetProperties(PublicPropertyEditor.OwnedPropertiesOnly)
|
|
|
|
|
|
let value = item.GetValue(selectedItem, null) as IObject3D
|
|
|
|
|
|
let propertyType = item.PropertyType
|
|
|
|
|
|
where iobject3DType.IsAssignableFrom(propertyType)
|
|
|
|
|
|
select new
|
|
|
|
|
|
{
|
|
|
|
|
|
Type = propertyType,
|
|
|
|
|
|
Value = value
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var member in members)
|
2017-10-18 18:18:10 -07:00
|
|
|
|
{
|
2018-02-06 08:49:05 -08:00
|
|
|
|
if (this.GetEditorsForType(member.Type)?.FirstOrDefault() is IObject3DEditor editor)
|
2017-10-18 18:18:10 -07:00
|
|
|
|
{
|
2018-02-06 08:49:05 -08:00
|
|
|
|
activeEditors.Add((editor, member.Value));
|
2017-10-18 18:18:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-06 08:49:05 -08:00
|
|
|
|
if (mappedEditors?.Any() == true)
|
|
|
|
|
|
{
|
2017-10-18 18:18:10 -07:00
|
|
|
|
// Select the active editor or fall back to the first if not found
|
2018-02-07 18:04:34 -08:00
|
|
|
|
var firstFilteredEditor = (from editor in mappedEditors
|
2018-01-31 14:36:08 -08:00
|
|
|
|
let type = editor.GetType()
|
|
|
|
|
|
where type.Name == selectedItem.ActiveEditor
|
|
|
|
|
|
select editor).FirstOrDefault();
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
2018-02-07 18:04:34 -08:00
|
|
|
|
// Use first filtered or fall back to unfiltered first
|
|
|
|
|
|
activeEditors.Add((firstFilteredEditor ?? mappedEditors.First(), selectedItem));
|
2017-10-18 18:18:10 -07:00
|
|
|
|
}
|
2018-02-06 08:49:05 -08:00
|
|
|
|
|
|
|
|
|
|
ShowObjectEditor(activeEditors);
|
2017-10-18 18:18:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
private HashSet<IObject3DEditor> GetEditorsForType(Type selectedItemType)
|
|
|
|
|
|
{
|
|
|
|
|
|
HashSet<IObject3DEditor> mappedEditors;
|
|
|
|
|
|
objectEditorsByType.TryGetValue(selectedItemType, out mappedEditors);
|
|
|
|
|
|
|
|
|
|
|
|
if (mappedEditors == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var kvp in objectEditorsByType)
|
|
|
|
|
|
{
|
|
|
|
|
|
var editorType = kvp.Key;
|
|
|
|
|
|
|
|
|
|
|
|
if (editorType.IsAssignableFrom(selectedItemType))
|
|
|
|
|
|
{
|
|
|
|
|
|
mappedEditors = kvp.Value;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mappedEditors;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-30 11:50:22 -08:00
|
|
|
|
private class OperationButton :TextButton
|
|
|
|
|
|
{
|
|
|
|
|
|
private GraphOperation graphOperation;
|
|
|
|
|
|
private IObject3D sceneItem;
|
|
|
|
|
|
|
|
|
|
|
|
public OperationButton(GraphOperation graphOperation, IObject3D sceneItem, ThemeConfig theme)
|
|
|
|
|
|
: base(graphOperation.Title, theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.graphOperation = graphOperation;
|
|
|
|
|
|
this.sceneItem = sceneItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void EnsureAvailablity()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Enabled = graphOperation.IsEnabled(sceneItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
private void ShowObjectEditor(IEnumerable<(IObject3DEditor editor, IObject3D item)> scope)
|
2017-10-18 18:18:10 -07:00
|
|
|
|
{
|
2018-01-09 18:43:58 -08:00
|
|
|
|
editorPanel.CloseAllChildren();
|
|
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
if (scope == null)
|
2017-10-18 18:18:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
foreach (var scopeItem in scope)
|
|
|
|
|
|
{
|
|
|
|
|
|
var selectedItem = scopeItem.item;
|
|
|
|
|
|
var selectedItemType = selectedItem.GetType();
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
var editorWidget = scopeItem.editor.Create(selectedItem, view3DWidget, theme);
|
|
|
|
|
|
editorWidget.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
editorWidget.VAnchor = VAnchor.Fit;
|
|
|
|
|
|
editorWidget.Padding = 0;
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
editorPanel.AddChild(editorWidget);
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
var buttons = new List<OperationButton>();
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
foreach (var graphOperation in ApplicationController.Instance.Graph.Operations)
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2018-01-31 14:36:08 -08:00
|
|
|
|
foreach (var type in graphOperation.MappedTypes)
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2018-01-31 14:36:08 -08:00
|
|
|
|
if (type.IsAssignableFrom(selectedItemType))
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2018-02-06 08:49:05 -08:00
|
|
|
|
var button = new OperationButton(graphOperation, selectedItem, theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = theme.MinimalShade,
|
|
|
|
|
|
Margin = theme.ButtonSpacing
|
|
|
|
|
|
};
|
2018-01-31 14:36:08 -08:00
|
|
|
|
button.EnsureAvailablity();
|
|
|
|
|
|
button.Click += (s, e) =>
|
|
|
|
|
|
{
|
2018-02-06 08:49:05 -08:00
|
|
|
|
graphOperation.Operation(selectedItem, scene).ConfigureAwait(false);
|
2018-01-31 14:36:08 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
buttons.Add(button);
|
|
|
|
|
|
}
|
2018-01-30 11:50:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-31 14:36:08 -08:00
|
|
|
|
if (buttons.Any())
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2018-01-31 14:36:08 -08:00
|
|
|
|
var toolbar = new Toolbar()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
Padding = theme.ToolbarPadding,
|
|
|
|
|
|
Margin = new BorderDouble(0, 8)
|
|
|
|
|
|
};
|
|
|
|
|
|
editorPanel.AddChild(toolbar);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var button in buttons)
|
|
|
|
|
|
{
|
|
|
|
|
|
toolbar.AddChild(button);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Fix likely leak
|
|
|
|
|
|
selectedItem.Invalidated += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var button in toolbar.ActionArea.Children.OfType<OperationButton>())
|
|
|
|
|
|
{
|
|
|
|
|
|
button.EnsureAvailablity();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2018-01-30 11:50:22 -08:00
|
|
|
|
}
|
2018-01-31 14:36:08 -08:00
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2017-11-15 09:24:56 -08:00
|
|
|
|
|
|
|
|
|
|
public void Save(ILibraryItem item, IObject3D content)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.item.Parent.Children.Modify(children =>
|
|
|
|
|
|
{
|
|
|
|
|
|
children.Remove(this.item);
|
|
|
|
|
|
children.Add(content);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-12 13:05:42 -08:00
|
|
|
|
public class InMemoryItem : ILibraryObject3D
|
2017-11-15 09:24:56 -08:00
|
|
|
|
{
|
|
|
|
|
|
private IObject3D existingItem;
|
|
|
|
|
|
|
|
|
|
|
|
public InMemoryItem(IObject3D existingItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.existingItem = existingItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ID => existingItem.ID;
|
|
|
|
|
|
|
|
|
|
|
|
public string Name => existingItem.Name;
|
|
|
|
|
|
|
2018-02-12 12:59:20 -08:00
|
|
|
|
public string FileName => $"{this.Name}.{this.ContentType}";
|
|
|
|
|
|
|
2017-11-15 09:24:56 -08:00
|
|
|
|
public bool IsProtected => !existingItem.Persistable;
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsVisible => existingItem.Visible;
|
|
|
|
|
|
|
2018-02-12 12:59:20 -08:00
|
|
|
|
public string ContentType => "mcx";
|
|
|
|
|
|
|
|
|
|
|
|
public string Category => "General";
|
2017-11-15 09:24:56 -08:00
|
|
|
|
|
2018-02-12 12:59:20 -08:00
|
|
|
|
public string AssetPath { get; set; }
|
2017-11-15 09:24:56 -08:00
|
|
|
|
|
2018-02-12 13:05:42 -08:00
|
|
|
|
public Task<IObject3D> GetObject3D(Action<double, string> reportProgress)
|
2017-11-15 09:24:56 -08:00
|
|
|
|
{
|
|
|
|
|
|
return Task.FromResult(existingItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2018-01-11 01:13:38 -08:00
|
|
|
|
|
|
|
|
|
|
public enum AxisAlignment { Min, Center, Max, SourceCoordinateSystem };
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|