2015-02-26 13:28:36 -08:00
|
|
|
|
/*
|
2018-05-22 07:00:00 -07:00
|
|
|
|
Copyright (c) 2018, 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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2018-11-15 14:30:53 -08:00
|
|
|
|
using System;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2022-03-15 11:21:25 -07:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2018-06-08 08:41:15 -07:00
|
|
|
|
using JsonPath;
|
2017-03-15 16:17:06 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2018-02-17 19:03:33 -08:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
2015-02-26 13:28:36 -08:00
|
|
|
|
using MatterHackers.Agg.UI;
|
2017-10-18 14:56:10 -07:00
|
|
|
|
using MatterHackers.DataConverters3D;
|
2021-05-21 14:24:45 -07:00
|
|
|
|
using MatterHackers.ImageProcessing;
|
2017-03-15 16:17:06 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2017-11-15 09:24:56 -08:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2018-01-30 11:50:22 -08:00
|
|
|
|
using MatterHackers.MatterControl.DesignTools;
|
2018-12-12 09:38:04 -08:00
|
|
|
|
using MatterHackers.MatterControl.DesignTools.Operations;
|
2018-02-17 19:03:33 -08:00
|
|
|
|
using MatterHackers.MatterControl.Library;
|
2018-10-06 15:09:01 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2018-06-08 08:41:15 -07:00
|
|
|
|
using static JsonPath.JsonPathContext.ReflectionValueSystem;
|
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-11 01:13:38 -08:00
|
|
|
|
public class SelectedObjectPanel : FlowLayoutWidget, IContentStore
|
2017-03-15 16:17:06 -07:00
|
|
|
|
{
|
2018-05-22 07:42:35 -07:00
|
|
|
|
private IObject3D item = new Object3D();
|
2017-10-18 14:56:10 -07:00
|
|
|
|
|
2019-05-18 22:06:06 -07:00
|
|
|
|
private readonly ThemeConfig theme;
|
|
|
|
|
|
private readonly ISceneContext sceneContext;
|
|
|
|
|
|
private readonly SectionWidget editorSectionWidget;
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2019-05-18 22:06:06 -07:00
|
|
|
|
private readonly GuiWidget editorPanel;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
2019-05-18 22:06:06 -07:00
|
|
|
|
private readonly string editorTitle = "Properties".Localize();
|
2018-11-01 17:11:24 -07:00
|
|
|
|
|
2019-02-01 16:12:12 -08:00
|
|
|
|
public SelectedObjectPanel(View3DWidget view3DWidget, ISceneContext sceneContext, ThemeConfig theme)
|
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-05-22 12:51:04 -07:00
|
|
|
|
this.Padding = 0;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
this.theme = theme;
|
2018-05-31 20:07:49 -07:00
|
|
|
|
this.sceneContext = sceneContext;
|
2017-10-18 14:56:10 -07:00
|
|
|
|
|
2018-06-23 12:06:46 -07:00
|
|
|
|
var toolbar = new LeftClipFlowLayoutWidget()
|
2018-01-09 18:43:58 -08:00
|
|
|
|
{
|
2018-11-03 09:50:09 -07:00
|
|
|
|
BackgroundColor = theme.BackgroundColor,
|
2018-01-09 18:43:58 -08:00
|
|
|
|
Padding = theme.ToolbarPadding,
|
2018-06-23 12:06:46 -07:00
|
|
|
|
HAnchor = HAnchor.Fit,
|
2018-01-09 18:43:58 -08:00
|
|
|
|
VAnchor = VAnchor.Fit
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
scene = sceneContext.Scene;
|
2018-05-31 20:07:49 -07:00
|
|
|
|
|
2020-05-29 08:15:32 -07:00
|
|
|
|
// put in the container for dynamic actions
|
|
|
|
|
|
primaryActionsPanel = new FlowLayoutWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Fit,
|
|
|
|
|
|
VAnchor = VAnchor.Center | VAnchor.Fit
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
toolbar.AddChild(primaryActionsPanel);
|
|
|
|
|
|
|
2018-08-11 09:16:19 -07:00
|
|
|
|
// put in a make permanent button
|
2021-05-21 14:24:45 -07:00
|
|
|
|
var icon = StaticData.Instance.LoadIcon("apply.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply();
|
2022-01-22 15:43:50 -08:00
|
|
|
|
applyButton = new IconButton(icon, theme)
|
2018-08-11 09:16:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
Margin = theme.ButtonSpacing,
|
2020-05-29 08:15:32 -07:00
|
|
|
|
ToolTipText = "Apply".Localize(),
|
2018-12-12 09:38:04 -08:00
|
|
|
|
Enabled = true
|
2018-08-11 09:16:19 -07:00
|
|
|
|
};
|
2022-01-22 15:43:50 -08:00
|
|
|
|
applyButton.Click += (s, e) =>
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2022-01-22 15:43:50 -08:00
|
|
|
|
if (this.item.CanApply)
|
2018-12-12 09:38:04 -08:00
|
|
|
|
{
|
2019-01-26 09:31:50 -08:00
|
|
|
|
var item = this.item;
|
2022-02-26 22:49:12 -08:00
|
|
|
|
using (new DataConverters3D.SelectionMaintainer(view3DWidget.Scene))
|
2019-01-26 09:31:50 -08:00
|
|
|
|
{
|
2022-01-22 15:43:50 -08:00
|
|
|
|
item.Apply(view3DWidget.Scene.UndoBuffer);
|
2019-01-26 09:31:50 -08:00
|
|
|
|
}
|
2018-12-12 09:38:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// try to ungroup it
|
|
|
|
|
|
sceneContext.Scene.UngroupSelection();
|
|
|
|
|
|
}
|
2018-08-11 09:16:19 -07:00
|
|
|
|
};
|
2022-01-22 15:43:50 -08:00
|
|
|
|
toolbar.AddChild(applyButton);
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2018-08-11 09:16:19 -07:00
|
|
|
|
// put in a remove button
|
2022-01-22 15:43:50 -08:00
|
|
|
|
cancelButton = new IconButton(StaticData.Instance.LoadIcon("cancel.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(), theme)
|
2018-08-11 09:16:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
Margin = theme.ButtonSpacing,
|
2020-05-29 08:15:32 -07:00
|
|
|
|
ToolTipText = "Cancel".Localize(),
|
2018-08-28 18:45:58 -07:00
|
|
|
|
Enabled = scene.SelectedItem != null
|
2018-08-11 09:16:19 -07:00
|
|
|
|
};
|
2022-01-22 15:43:50 -08:00
|
|
|
|
cancelButton.Click += (s, e) =>
|
2018-02-12 15:28:26 -08:00
|
|
|
|
{
|
2019-01-26 09:31:50 -08:00
|
|
|
|
var item = this.item;
|
2022-02-26 22:49:12 -08:00
|
|
|
|
using (new DataConverters3D.SelectionMaintainer(view3DWidget.Scene))
|
2018-08-08 14:07:02 -07:00
|
|
|
|
{
|
2022-01-22 15:43:50 -08:00
|
|
|
|
item.Cancel(view3DWidget.Scene.UndoBuffer);
|
2018-08-08 14:07:02 -07:00
|
|
|
|
}
|
2018-02-12 15:28:26 -08:00
|
|
|
|
};
|
2022-01-22 15:43:50 -08:00
|
|
|
|
toolbar.AddChild(cancelButton);
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
overflowButton = new OverflowBar.OverflowMenuButton(theme)
|
2018-08-28 18:45:58 -07:00
|
|
|
|
{
|
|
|
|
|
|
Enabled = scene.SelectedItem != null,
|
|
|
|
|
|
};
|
2020-12-30 10:35:47 -08:00
|
|
|
|
overflowButton.ToolTipText = "Selected Object Options".Localize();
|
2018-06-23 12:06:46 -07:00
|
|
|
|
overflowButton.DynamicPopupContent = () =>
|
|
|
|
|
|
{
|
2020-09-26 10:59:31 -07:00
|
|
|
|
return ApplicationController.Instance.GetModifyMenu(view3DWidget.sceneContext);
|
2018-06-23 12:06:46 -07:00
|
|
|
|
};
|
|
|
|
|
|
toolbar.AddChild(overflowButton);
|
|
|
|
|
|
|
2018-06-22 18:27:02 -07:00
|
|
|
|
editorPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2018-01-09 18:43:58 -08:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
2018-08-03 17:06:31 -07:00
|
|
|
|
Name = "editorPanel",
|
2018-06-08 15:09:10 -07:00
|
|
|
|
};
|
2018-06-23 12:06:46 -07:00
|
|
|
|
|
2018-06-23 07:05:26 -07:00
|
|
|
|
// Wrap editorPanel with scrollable container
|
|
|
|
|
|
var scrollableWidget = new ScrollableWidget(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Stretch
|
|
|
|
|
|
};
|
|
|
|
|
|
scrollableWidget.AddChild(editorPanel);
|
|
|
|
|
|
scrollableWidget.ScrollArea.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
|
2018-11-01 17:11:24 -07:00
|
|
|
|
editorSectionWidget = new SectionWidget(editorTitle, scrollableWidget, theme, toolbar, expandingContent: false, defaultExpansion: true, setContentVAnchor: false)
|
2018-06-07 18:16:16 -07:00
|
|
|
|
{
|
2018-09-10 18:24:09 -07:00
|
|
|
|
VAnchor = VAnchor.Stretch
|
2018-06-07 18:16:16 -07:00
|
|
|
|
};
|
2018-09-08 12:08:06 -07:00
|
|
|
|
this.AddChild(editorSectionWidget);
|
2018-01-08 23:34:40 -08:00
|
|
|
|
|
2018-09-08 12:08:06 -07:00
|
|
|
|
this.ContentPanel = editorPanel;
|
|
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Register listeners
|
|
|
|
|
|
scene.SelectionChanged += Scene_SelectionChanged;
|
2017-10-18 14:56:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-11 11:29:21 -07:00
|
|
|
|
public GuiWidget ContentPanel { get; set; }
|
|
|
|
|
|
|
2022-01-21 15:21:07 -08:00
|
|
|
|
private readonly JsonPathContext pathGetter = new JsonPathContext();
|
2022-01-22 15:43:50 -08:00
|
|
|
|
private readonly IconButton applyButton;
|
|
|
|
|
|
private readonly IconButton cancelButton;
|
2019-05-18 22:06:06 -07:00
|
|
|
|
private readonly OverflowBar.OverflowMenuButton overflowButton;
|
|
|
|
|
|
private readonly InteractiveScene scene;
|
|
|
|
|
|
private readonly FlowLayoutWidget primaryActionsPanel;
|
2019-01-14 18:31:09 -08:00
|
|
|
|
|
2020-09-24 13:53:49 -07:00
|
|
|
|
public void SetActiveItem(ISceneContext sceneContext)
|
2017-10-18 14:56:10 -07:00
|
|
|
|
{
|
2020-09-25 23:20:58 -07:00
|
|
|
|
var selectedItem = sceneContext?.Scene?.SelectedItem;
|
2018-10-31 22:13:59 -07:00
|
|
|
|
if (this.item == selectedItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 00:04:03 -07:00
|
|
|
|
this.item = selectedItem;
|
2021-01-29 16:44:47 -08:00
|
|
|
|
editorPanel.CloseChildren();
|
2018-06-22 00:04:03 -07:00
|
|
|
|
|
|
|
|
|
|
// Allow caller to clean up with passing null for selectedItem
|
|
|
|
|
|
if (item == null)
|
|
|
|
|
|
{
|
2018-11-01 17:11:24 -07:00
|
|
|
|
editorSectionWidget.Text = editorTitle;
|
2018-06-22 00:04:03 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-26 17:53:54 -08:00
|
|
|
|
var selectedItemType = selectedItem.GetType();
|
|
|
|
|
|
|
2021-01-29 16:44:47 -08:00
|
|
|
|
primaryActionsPanel.RemoveChildren();
|
2019-01-14 18:31:09 -08:00
|
|
|
|
|
2020-09-26 10:59:31 -07:00
|
|
|
|
IEnumerable<SceneOperation> primaryActions;
|
|
|
|
|
|
|
|
|
|
|
|
if ((primaryActions = SceneOperations.GetPrimaryOperations(selectedItemType)) == null)
|
2019-01-14 18:31:09 -08:00
|
|
|
|
{
|
2020-09-24 13:53:49 -07:00
|
|
|
|
primaryActions = new List<SceneOperation>();
|
2019-01-14 18:31:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Loop over primary actions creating a button for each
|
2019-05-18 22:06:06 -07:00
|
|
|
|
foreach (var primaryAction in primaryActions)
|
2019-01-14 18:31:09 -08:00
|
|
|
|
{
|
|
|
|
|
|
// TODO: Run visible/enable rules on actions, conditionally add/enable as appropriate
|
2021-05-21 14:24:45 -07:00
|
|
|
|
var button = new IconButton(primaryAction.Icon(theme), theme)
|
2019-01-14 18:31:09 -08:00
|
|
|
|
{
|
2019-05-18 22:06:06 -07:00
|
|
|
|
// Name = namedAction.Title + " Button",
|
2019-01-24 18:03:43 -08:00
|
|
|
|
ToolTipText = primaryAction.Title,
|
2019-01-14 18:31:09 -08:00
|
|
|
|
Margin = theme.ButtonSpacing,
|
|
|
|
|
|
BackgroundColor = theme.ToolbarButtonBackground,
|
|
|
|
|
|
HoverColor = theme.ToolbarButtonHover,
|
|
|
|
|
|
MouseDownColor = theme.ToolbarButtonDown,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
button.Click += (s, e) =>
|
|
|
|
|
|
{
|
2020-09-24 13:53:49 -07:00
|
|
|
|
primaryAction.Action.Invoke(sceneContext);
|
2019-01-14 18:31:09 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
primaryActionsPanel.AddChild(button);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-26 10:59:31 -07:00
|
|
|
|
if (primaryActionsPanel.Children.Any())
|
2020-05-29 08:15:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
// add in a separator from the apply and cancel buttons
|
2020-10-19 18:08:15 -07:00
|
|
|
|
primaryActionsPanel.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin));
|
2020-05-29 08:15:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-23 12:06:46 -07:00
|
|
|
|
editorSectionWidget.Text = selectedItem.Name ?? selectedItemType.Name;
|
2017-10-18 14:56:10 -07:00
|
|
|
|
|
2019-02-04 08:41:08 -08:00
|
|
|
|
HashSet<IObject3DEditor> mappedEditors = ApplicationController.Instance.Extensions.GetEditorsForType(selectedItemType);
|
2018-05-22 07:42:35 -07:00
|
|
|
|
|
2018-06-08 08:41:15 -07:00
|
|
|
|
var undoBuffer = sceneContext.Scene.UndoBuffer;
|
|
|
|
|
|
|
2022-03-15 11:21:25 -07:00
|
|
|
|
void GetNextSelectionColor(Action<Color> setColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
var scene = sceneContext.Scene;
|
|
|
|
|
|
var startingSelection = scene.SelectedItem;
|
|
|
|
|
|
CancellationTokenSource cancellationToken = null;
|
|
|
|
|
|
|
|
|
|
|
|
void SelectionChanged(object s, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var selection = scene.SelectedItem;
|
|
|
|
|
|
if (selection != null)
|
|
|
|
|
|
{
|
2022-04-29 14:37:14 -07:00
|
|
|
|
setColor?.Invoke(selection.WorldColor());
|
2022-03-15 11:21:25 -07:00
|
|
|
|
scene.SelectionChanged -= SelectionChanged;
|
|
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
|
scene.SelectedItem = startingSelection;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var durationSeconds = 20;
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationController.Instance.Tasks.Execute("Select an object to copy its color".Localize(),
|
|
|
|
|
|
null,
|
|
|
|
|
|
(progress, cancellationTokenIn) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
cancellationToken = cancellationTokenIn;
|
|
|
|
|
|
var time = UiThread.CurrentTimerMs;
|
|
|
|
|
|
var status = new ProgressStatus();
|
|
|
|
|
|
while (UiThread.CurrentTimerMs < time + durationSeconds * 1000
|
|
|
|
|
|
&& !cancellationToken.IsCancellationRequested)
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(30);
|
|
|
|
|
|
status.Progress0To1 = (UiThread.CurrentTimerMs - time) / 1000.0 / durationSeconds;
|
|
|
|
|
|
progress.Report(status);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
scene.SelectionChanged -= SelectionChanged;
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
scene.SelectionChanged += SelectionChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-17 22:35:53 -07:00
|
|
|
|
if (!(selectedItem.GetType().GetCustomAttributes(typeof(HideMeterialAndColor), true).FirstOrDefault() is HideMeterialAndColor))
|
2018-10-06 15:09:01 -07:00
|
|
|
|
{
|
2022-04-29 17:33:29 -07:00
|
|
|
|
var firstDetectedColor = selectedItem.VisibleMeshes()?.FirstOrDefault()?.WorldColor();
|
|
|
|
|
|
var worldColor = Color.White;
|
|
|
|
|
|
if (firstDetectedColor != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
worldColor = firstDetectedColor.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-17 22:35:53 -07:00
|
|
|
|
// put in a color edit field
|
2022-04-29 17:33:29 -07:00
|
|
|
|
var colorField = new ColorField(theme, worldColor, GetNextSelectionColor, true);
|
2021-04-17 22:35:53 -07:00
|
|
|
|
colorField.Initialize(0);
|
|
|
|
|
|
colorField.ValueChanged += (s, e) =>
|
2018-10-06 15:09:01 -07:00
|
|
|
|
{
|
2021-04-17 22:35:53 -07:00
|
|
|
|
if (selectedItem.Color != colorField.Color)
|
|
|
|
|
|
{
|
2022-05-27 17:44:03 -07:00
|
|
|
|
if (colorField.Color == Color.Transparent)
|
|
|
|
|
|
{
|
|
|
|
|
|
undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color, PrintOutputTypes.Default));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color, PrintOutputTypes.Solid));
|
|
|
|
|
|
}
|
2021-04-17 22:35:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2018-10-06 15:09:01 -07:00
|
|
|
|
|
2022-05-07 20:00:07 -07:00
|
|
|
|
ColorButton holeButton = null;
|
|
|
|
|
|
var solidButton = colorField.Content.Descendants<ColorButton>().FirstOrDefault();
|
|
|
|
|
|
GuiWidget otherContainer = null;
|
|
|
|
|
|
TextWidget otherText = null;
|
2022-05-10 08:29:08 -07:00
|
|
|
|
GuiWidget holeContainer = null;
|
|
|
|
|
|
GuiWidget solidContainer = null;
|
2022-05-07 20:00:07 -07:00
|
|
|
|
void SetOtherOutputSelection(string text)
|
2022-05-07 18:38:51 -07:00
|
|
|
|
{
|
2022-05-07 20:00:07 -07:00
|
|
|
|
otherText.Text = text;
|
|
|
|
|
|
otherContainer.Visible = true;
|
2022-05-10 08:29:08 -07:00
|
|
|
|
holeContainer.BackgroundOutlineWidth = 0;
|
2022-05-07 20:00:07 -07:00
|
|
|
|
holeButton.BackgroundOutlineWidth = 1;
|
2022-05-07 18:38:51 -07:00
|
|
|
|
|
2022-05-10 08:29:08 -07:00
|
|
|
|
solidContainer.BackgroundOutlineWidth = 0;
|
2022-05-07 20:00:07 -07:00
|
|
|
|
solidButton.BackgroundOutlineWidth = 1;
|
2022-05-07 18:38:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-07 20:00:07 -07:00
|
|
|
|
var scaledButtonSize = 24 * GuiWidget.DeviceScale;
|
|
|
|
|
|
void SetButtonStates()
|
|
|
|
|
|
{
|
2022-05-26 15:56:55 -07:00
|
|
|
|
switch (selectedItem.OutputType)
|
2022-05-07 20:00:07 -07:00
|
|
|
|
{
|
|
|
|
|
|
case PrintOutputTypes.Hole:
|
2022-05-10 08:29:08 -07:00
|
|
|
|
holeContainer.BackgroundOutlineWidth = 1;
|
2022-05-09 18:20:02 -07:00
|
|
|
|
holeButton.BackgroundOutlineWidth = 2;
|
2022-05-07 20:00:07 -07:00
|
|
|
|
holeButton.BackgroundRadius = scaledButtonSize / 2 - 1;
|
|
|
|
|
|
|
2022-05-10 08:29:08 -07:00
|
|
|
|
solidContainer.BackgroundOutlineWidth = 0;
|
|
|
|
|
|
solidButton.BackgroundOutlineWidth = 1;
|
2022-05-07 20:00:07 -07:00
|
|
|
|
solidButton.BackgroundRadius = scaledButtonSize / 2;
|
|
|
|
|
|
otherContainer.Visible = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case PrintOutputTypes.Default:
|
|
|
|
|
|
case PrintOutputTypes.Solid:
|
2022-05-10 08:29:08 -07:00
|
|
|
|
holeContainer.BackgroundOutlineWidth = 0;
|
|
|
|
|
|
holeButton.BackgroundOutlineWidth = 1;
|
2022-05-07 20:00:07 -07:00
|
|
|
|
holeButton.BackgroundRadius = scaledButtonSize / 2;
|
|
|
|
|
|
|
2022-05-10 08:29:08 -07:00
|
|
|
|
solidContainer.BackgroundOutlineWidth = 1;
|
|
|
|
|
|
solidButton.BackgroundOutlineWidth = 2;
|
2022-05-07 20:00:07 -07:00
|
|
|
|
solidButton.BackgroundRadius = scaledButtonSize / 2 - 1;
|
|
|
|
|
|
otherContainer.Visible = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case PrintOutputTypes.Support:
|
|
|
|
|
|
SetOtherOutputSelection("Support".Localize());
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case PrintOutputTypes.WipeTower:
|
|
|
|
|
|
SetOtherOutputSelection("Wipe Tower".Localize());
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case PrintOutputTypes.Fuzzy:
|
|
|
|
|
|
SetOtherOutputSelection("Fuzzy".Localize());
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-07 18:38:51 -07:00
|
|
|
|
|
|
|
|
|
|
void SetToSolid()
|
|
|
|
|
|
{
|
2021-09-02 11:26:00 -07:00
|
|
|
|
// make sure the render mode is set to shaded or outline
|
2022-05-12 18:15:07 -07:00
|
|
|
|
switch(sceneContext.ViewState.RenderType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case RenderOpenGl.RenderTypes.Shaded:
|
|
|
|
|
|
case RenderOpenGl.RenderTypes.Outlines:
|
|
|
|
|
|
case RenderOpenGl.RenderTypes.Polygons:
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
// make sure the render mode is set to outline
|
|
|
|
|
|
sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Outlines;
|
|
|
|
|
|
break;
|
2021-04-17 22:35:53 -07:00
|
|
|
|
}
|
2022-04-29 14:18:55 -07:00
|
|
|
|
|
2022-05-26 15:56:55 -07:00
|
|
|
|
var currentOutputType = selectedItem.OutputType;
|
2022-04-29 17:33:29 -07:00
|
|
|
|
if (currentOutputType != PrintOutputTypes.Solid && currentOutputType != PrintOutputTypes.Default)
|
2022-04-29 14:18:55 -07:00
|
|
|
|
{
|
2022-05-27 15:16:44 -07:00
|
|
|
|
undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color, PrintOutputTypes.Solid));
|
2022-04-29 14:18:55 -07:00
|
|
|
|
}
|
2022-05-07 18:38:51 -07:00
|
|
|
|
|
2022-05-07 20:00:07 -07:00
|
|
|
|
SetButtonStates();
|
2022-05-10 08:29:08 -07:00
|
|
|
|
Invalidate();
|
2022-05-07 18:38:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-07 20:00:07 -07:00
|
|
|
|
solidButton.Parent.MouseDown += (s, e) => SetToSolid();
|
2019-05-24 09:03:27 -07:00
|
|
|
|
|
2022-05-07 20:00:07 -07:00
|
|
|
|
var colorRow = new SettingsRow("Output".Localize(), null, colorField.Content, theme)
|
2022-04-19 18:10:09 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Special top border style for first item in editor
|
|
|
|
|
|
Border = new BorderDouble(0, 1)
|
2022-04-29 14:18:55 -07:00
|
|
|
|
};
|
|
|
|
|
|
editorPanel.AddChild(colorRow);
|
2022-04-19 18:10:09 -07:00
|
|
|
|
|
2022-04-29 14:18:55 -07:00
|
|
|
|
// put in a hole button
|
2022-05-07 18:38:51 -07:00
|
|
|
|
holeButton = new ColorButton(Color.DarkGray)
|
2022-04-19 18:10:09 -07:00
|
|
|
|
{
|
2022-04-29 14:18:55 -07:00
|
|
|
|
Margin = new BorderDouble(5, 0, 11, 0),
|
|
|
|
|
|
Width = scaledButtonSize,
|
|
|
|
|
|
Height = scaledButtonSize,
|
|
|
|
|
|
BackgroundRadius = scaledButtonSize / 2,
|
|
|
|
|
|
BackgroundOutlineWidth = 1,
|
|
|
|
|
|
VAnchor = VAnchor.Center,
|
|
|
|
|
|
DisabledColor = theme.MinimalShade,
|
|
|
|
|
|
BorderColor = theme.TextColor,
|
|
|
|
|
|
ToolTipText = "Convert to Hole".Localize(),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-05-10 08:29:08 -07:00
|
|
|
|
GuiWidget NewTextContainer(string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
var textWidget = new TextWidget(text.Localize(), pointSize: theme.FontSize10, textColor: theme.TextColor)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(5, 4, 5, 5),
|
|
|
|
|
|
AutoExpandBoundsToText = true,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var container = new GuiWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(5, 0),
|
|
|
|
|
|
VAnchor = VAnchor.Fit | VAnchor.Center,
|
|
|
|
|
|
HAnchor = HAnchor.Fit,
|
|
|
|
|
|
BackgroundRadius = 3,
|
|
|
|
|
|
BackgroundOutlineWidth = 1,
|
|
|
|
|
|
BorderColor = theme.PrimaryAccentColor,
|
|
|
|
|
|
Selectable = true,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
container.AddChild(textWidget);
|
|
|
|
|
|
|
|
|
|
|
|
return container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-07 20:00:07 -07:00
|
|
|
|
var buttonRow = solidButton.Parents<FlowLayoutWidget>().FirstOrDefault();
|
2022-05-10 08:29:08 -07:00
|
|
|
|
solidContainer = NewTextContainer("Solid");
|
|
|
|
|
|
buttonRow.AddChild(solidContainer, 0);
|
|
|
|
|
|
|
2022-04-29 14:18:55 -07:00
|
|
|
|
buttonRow.AddChild(holeButton, 0);
|
2022-05-10 08:29:08 -07:00
|
|
|
|
holeContainer = NewTextContainer("Hole");
|
|
|
|
|
|
buttonRow.AddChild(holeContainer, 0);
|
|
|
|
|
|
|
|
|
|
|
|
otherContainer = NewTextContainer("");
|
2022-05-07 20:00:07 -07:00
|
|
|
|
buttonRow.AddChild(otherContainer, 0);
|
|
|
|
|
|
|
2022-05-10 08:29:08 -07:00
|
|
|
|
otherText = otherContainer.Children.First() as TextWidget;
|
2022-04-29 14:18:55 -07:00
|
|
|
|
|
2022-05-07 18:38:51 -07:00
|
|
|
|
void SetToHole()
|
|
|
|
|
|
{
|
2022-05-26 15:56:55 -07:00
|
|
|
|
if (selectedItem.OutputType != PrintOutputTypes.Hole)
|
2022-04-19 18:10:09 -07:00
|
|
|
|
{
|
|
|
|
|
|
undoBuffer.AddAndDo(new MakeHole(selectedItem));
|
|
|
|
|
|
}
|
2022-05-07 20:00:07 -07:00
|
|
|
|
SetButtonStates();
|
2022-05-10 08:29:08 -07:00
|
|
|
|
Invalidate();
|
2022-05-07 18:38:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
holeButton.Click += (s, e) => SetToHole();
|
2022-05-10 08:29:08 -07:00
|
|
|
|
holeContainer.Click += (s, e) => SetToHole();
|
|
|
|
|
|
solidContainer.Click += (s, e) => SetToSolid();
|
2022-05-07 18:38:51 -07:00
|
|
|
|
|
2022-05-07 20:00:07 -07:00
|
|
|
|
SetButtonStates();
|
|
|
|
|
|
void SelectedItemOutputChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetButtonStates();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selectedItem.Invalidated += SelectedItemOutputChanged;
|
|
|
|
|
|
Closed += (s, e) => selectedItem.Invalidated -= SelectedItemOutputChanged;
|
2019-05-24 09:17:02 -07:00
|
|
|
|
|
2021-04-17 22:35:53 -07:00
|
|
|
|
// put in a material edit field
|
|
|
|
|
|
var materialField = new MaterialIndexField(sceneContext.Printer, theme, selectedItem.MaterialIndex);
|
|
|
|
|
|
materialField.Initialize(0);
|
|
|
|
|
|
materialField.ValueChanged += (s, e) =>
|
2018-10-07 12:12:08 -07:00
|
|
|
|
{
|
2021-04-17 22:35:53 -07:00
|
|
|
|
if (selectedItem.MaterialIndex != materialField.MaterialIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
undoBuffer.AddAndDo(new ChangeMaterial(selectedItem, materialField.MaterialIndex));
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2018-10-07 12:12:08 -07:00
|
|
|
|
|
2021-04-17 22:35:53 -07:00
|
|
|
|
materialField.Content.MouseDown += (s, e) =>
|
2018-10-07 18:11:02 -07:00
|
|
|
|
{
|
2021-04-17 22:35:53 -07:00
|
|
|
|
if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Materials)
|
|
|
|
|
|
{
|
2021-09-02 11:26:00 -07:00
|
|
|
|
// make sure the render mode is set to material
|
|
|
|
|
|
sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Materials;
|
2021-04-17 22:35:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2019-05-24 09:03:27 -07:00
|
|
|
|
|
2021-04-17 22:35:53 -07:00
|
|
|
|
// material row
|
2022-04-19 18:10:09 -07:00
|
|
|
|
editorPanel.AddChild(new SettingsRow("Material".Localize(), null, materialField.Content, theme));
|
2022-05-07 20:00:07 -07:00
|
|
|
|
}
|
2018-10-06 15:09:01 -07:00
|
|
|
|
|
2022-05-07 20:00:07 -07:00
|
|
|
|
var rows = new SafeList<SettingsRow>();
|
2021-06-04 07:13:34 -07:00
|
|
|
|
|
2018-10-06 15:09:01 -07:00
|
|
|
|
// put in the normal editor
|
2018-08-02 13:18:37 -07:00
|
|
|
|
if (selectedItem is ComponentObject3D componentObject
|
|
|
|
|
|
&& componentObject.Finalized)
|
2022-03-21 15:41:57 -07:00
|
|
|
|
{
|
|
|
|
|
|
AddComponentEditor(selectedItem, undoBuffer, rows, componentObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2018-06-27 11:58:11 -07:00
|
|
|
|
{
|
2020-05-20 13:51:36 -07:00
|
|
|
|
if (item != null
|
|
|
|
|
|
&& ApplicationController.Instance.Extensions.GetEditorsForType(item.GetType())?.FirstOrDefault() is IObject3DEditor editor)
|
2018-06-27 11:58:11 -07:00
|
|
|
|
{
|
2019-05-18 22:06:06 -07:00
|
|
|
|
ShowObjectEditor((editor, item, item.Name), selectedItem);
|
2018-06-27 11:58:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-07 20:00:07 -07:00
|
|
|
|
}
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
2022-03-21 15:41:57 -07:00
|
|
|
|
private void AddComponentEditor(IObject3D selectedItem, UndoBuffer undoBuffer, SafeList<SettingsRow> rows, ComponentObject3D componentObject)
|
|
|
|
|
|
{
|
|
|
|
|
|
var context = new PPEContext();
|
|
|
|
|
|
PublicPropertyEditor.AddUnlockLinkIfRequired(selectedItem, editorPanel, theme);
|
|
|
|
|
|
var editorList = componentObject.SurfacedEditors;
|
|
|
|
|
|
for (var editorIndex = 0; editorIndex < editorList.Count; editorIndex++)
|
|
|
|
|
|
{
|
|
|
|
|
|
// if it is a reference to a sheet cell
|
|
|
|
|
|
if (editorList[editorIndex].StartsWith("!"))
|
|
|
|
|
|
{
|
|
|
|
|
|
AddSheetCellEditor(undoBuffer, componentObject, editorList, editorIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
else // parse it as a path to an object
|
|
|
|
|
|
{
|
|
|
|
|
|
// Get the named property via reflection
|
|
|
|
|
|
// Selector example: '$.Children<CylinderObject3D>'
|
|
|
|
|
|
var match = pathGetter.Select(componentObject, editorList[editorIndex]).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
//// - Add editor row for each
|
|
|
|
|
|
foreach (var instance in match)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (instance is IObject3D object3D)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ApplicationController.Instance.Extensions.GetEditorsForType(object3D.GetType())?.FirstOrDefault() is IObject3DEditor editor)
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowObjectEditor((editor, object3D, object3D.Name), selectedItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (JsonPathContext.ReflectionValueSystem.LastMemberValue is ReflectionTarget reflectionTarget)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (reflectionTarget.Source is IObject3D editedChild)
|
|
|
|
|
|
{
|
|
|
|
|
|
context.item = editedChild;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
context.item = item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var editableProperty = new EditableProperty(reflectionTarget.PropertyInfo, reflectionTarget.Source);
|
|
|
|
|
|
|
|
|
|
|
|
var editor = PublicPropertyEditor.CreatePropertyEditor(rows, editableProperty, undoBuffer, context, theme);
|
|
|
|
|
|
if (editor != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
editorPanel.AddChild(editor);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Init with custom 'UpdateControls' hooks
|
|
|
|
|
|
(context.item as IPropertyGridModifier)?.UpdateControls(new PublicPropertyChange(context, "Update_Button"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Enforce panel padding
|
|
|
|
|
|
foreach (var sectionWidget in editorPanel.Descendants<SectionWidget>())
|
|
|
|
|
|
{
|
|
|
|
|
|
sectionWidget.Margin = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AddSheetCellEditor(UndoBuffer undoBuffer, ComponentObject3D componentObject, List<string> editorList, int editorIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
var firtSheet = componentObject.Descendants<SheetObject3D>().FirstOrDefault();
|
|
|
|
|
|
if (firtSheet != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var (cellId, cellData) = componentObject.DecodeContent(editorIndex);
|
|
|
|
|
|
var cell = firtSheet.SheetData[cellId];
|
|
|
|
|
|
if (cell != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// create an expresion editor
|
|
|
|
|
|
var field = new ExpressionField(theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = cellId + " Field"
|
|
|
|
|
|
};
|
|
|
|
|
|
field.Initialize(0);
|
|
|
|
|
|
if (cellData.Contains("="))
|
|
|
|
|
|
{
|
|
|
|
|
|
field.SetValue(cellData, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else // make sure it is formatted
|
|
|
|
|
|
{
|
|
|
|
|
|
double.TryParse(cellData, out double value);
|
|
|
|
|
|
var format = "0." + new string('#', 5);
|
|
|
|
|
|
field.SetValue(value.ToString(format), false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
field.ClearUndoHistory();
|
|
|
|
|
|
|
|
|
|
|
|
var doOrUndoing = false;
|
|
|
|
|
|
field.ValueChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!doOrUndoing)
|
|
|
|
|
|
{
|
|
|
|
|
|
var oldValue = componentObject.DecodeContent(editorIndex).cellData;
|
|
|
|
|
|
var newValue = field.Value;
|
|
|
|
|
|
undoBuffer.AddAndDo(new UndoRedoActions(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
doOrUndoing = true;
|
|
|
|
|
|
editorList[editorIndex] = "!" + cellId + "," + oldValue;
|
|
|
|
|
|
var expression = new DoubleOrExpression(oldValue);
|
|
|
|
|
|
cell.Expression = expression.Value(componentObject).ToString();
|
|
|
|
|
|
componentObject.Invalidate(InvalidateType.SheetUpdated);
|
|
|
|
|
|
doOrUndoing = false;
|
|
|
|
|
|
},
|
|
|
|
|
|
() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
doOrUndoing = true;
|
|
|
|
|
|
editorList[editorIndex] = "!" + cellId + "," + newValue;
|
|
|
|
|
|
var expression = new DoubleOrExpression(newValue);
|
|
|
|
|
|
cell.Expression = expression.Value(componentObject).ToString();
|
|
|
|
|
|
componentObject.Invalidate(InvalidateType.SheetUpdated);
|
|
|
|
|
|
doOrUndoing = false;
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-03-22 15:54:19 -07:00
|
|
|
|
var row = new SettingsRow(cell.Name == null ? cellId : cell.Name.Replace("_", " "), null, field.Content, theme);
|
2022-03-21 15:41:57 -07:00
|
|
|
|
editorPanel.AddChild(row);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class OperationButton : TextButton
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2020-09-24 13:53:49 -07:00
|
|
|
|
private readonly SceneOperation sceneOperation;
|
|
|
|
|
|
private readonly ISceneContext sceneContext;
|
2018-01-30 11:50:22 -08:00
|
|
|
|
|
2020-09-24 13:53:49 -07:00
|
|
|
|
public OperationButton(SceneOperation sceneOperation, ISceneContext sceneContext, ThemeConfig theme)
|
|
|
|
|
|
: base(sceneOperation.Title, theme)
|
2018-01-30 11:50:22 -08:00
|
|
|
|
{
|
2020-09-24 13:53:49 -07:00
|
|
|
|
this.sceneOperation = sceneOperation;
|
|
|
|
|
|
this.sceneContext = sceneContext;
|
2018-01-30 11:50:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void EnsureAvailablity()
|
|
|
|
|
|
{
|
2020-09-24 13:53:49 -07:00
|
|
|
|
this.Enabled = sceneOperation.IsEnabled?.Invoke(sceneContext) != false;
|
2018-01-30 11:50:22 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-18 22:06:06 -07:00
|
|
|
|
private void ShowObjectEditor((IObject3DEditor editor, IObject3D item, string displayName) scopeItem, IObject3D rootSelection)
|
2017-10-18 18:18:10 -07:00
|
|
|
|
{
|
2018-06-27 11:08:58 -07:00
|
|
|
|
var selectedItem = scopeItem.item;
|
2017-10-18 18:18:10 -07:00
|
|
|
|
|
2019-03-07 17:56:41 -08:00
|
|
|
|
var editorWidget = scopeItem.editor.Create(selectedItem, sceneContext.Scene.UndoBuffer, theme);
|
2018-06-27 11:08:58 -07:00
|
|
|
|
editorWidget.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
editorWidget.VAnchor = VAnchor.Fit;
|
2018-05-21 13:30:06 -07:00
|
|
|
|
|
2018-06-27 11:08:58 -07:00
|
|
|
|
if (scopeItem.item != rootSelection
|
|
|
|
|
|
&& scopeItem.editor is PublicPropertyEditor)
|
|
|
|
|
|
{
|
|
|
|
|
|
editorWidget.Padding = new BorderDouble(10, 10, 10, 0);
|
2018-03-27 14:15:28 -07:00
|
|
|
|
|
2018-06-27 11:08:58 -07:00
|
|
|
|
// EditOutline section
|
|
|
|
|
|
var sectionWidget = new SectionWidget(
|
|
|
|
|
|
scopeItem.displayName ?? "Unknown",
|
|
|
|
|
|
editorWidget,
|
|
|
|
|
|
theme);
|
2018-04-14 20:52:35 -07:00
|
|
|
|
|
2018-06-27 11:08:58 -07:00
|
|
|
|
theme.ApplyBoxStyle(sectionWidget, margin: 0);
|
2018-03-27 14:15:28 -07:00
|
|
|
|
|
2018-06-27 11:08:58 -07:00
|
|
|
|
editorWidget = sectionWidget;
|
2018-05-22 07:26:22 -07:00
|
|
|
|
}
|
2018-06-27 11:08:58 -07:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
editorWidget.Padding = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
editorPanel.AddChild(editorWidget);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2017-11-15 09:24:56 -08:00
|
|
|
|
|
2022-04-04 16:26:28 -07:00
|
|
|
|
public Task Save(ILibraryItem item, IObject3D content)
|
2017-11-15 09:24:56 -08:00
|
|
|
|
{
|
2018-05-22 07:42:35 -07:00
|
|
|
|
this.item.Parent.Children.Modify(children =>
|
2017-11-15 09:24:56 -08:00
|
|
|
|
{
|
2018-05-22 07:42:35 -07:00
|
|
|
|
children.Remove(this.item);
|
2017-11-15 09:24:56 -08:00
|
|
|
|
children.Add(content);
|
|
|
|
|
|
});
|
2022-04-04 16:26:28 -07:00
|
|
|
|
|
|
|
|
|
|
return null;
|
2017-11-15 09:24:56 -08:00
|
|
|
|
}
|
2018-11-16 08:44:56 -08:00
|
|
|
|
|
|
|
|
|
|
public override void OnClosed(EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Unregister listeners
|
|
|
|
|
|
scene.SelectionChanged -= Scene_SelectionChanged;
|
|
|
|
|
|
|
|
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Scene_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (editorPanel.Children.FirstOrDefault()?.DescendantsAndSelf<SectionWidget>().FirstOrDefault() is SectionWidget firstSectionWidget)
|
|
|
|
|
|
{
|
|
|
|
|
|
firstSectionWidget.Margin = firstSectionWidget.Margin.Clone(top: 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var selectedItem = scene.SelectedItem;
|
|
|
|
|
|
|
2022-01-22 15:43:50 -08:00
|
|
|
|
applyButton.Enabled = selectedItem != null
|
2018-12-12 09:38:04 -08:00
|
|
|
|
&& (selectedItem is GroupObject3D
|
2020-05-29 08:15:32 -07:00
|
|
|
|
|| (selectedItem.GetType() == typeof(Object3D) && selectedItem.Children.Any())
|
2022-01-22 15:43:50 -08:00
|
|
|
|
|| selectedItem.CanApply);
|
|
|
|
|
|
cancelButton.Enabled = selectedItem != null;
|
2018-11-16 08:44:56 -08:00
|
|
|
|
overflowButton.Enabled = selectedItem != null;
|
2019-05-18 22:06:06 -07:00
|
|
|
|
if (selectedItem == null)
|
2019-01-24 18:03:43 -08:00
|
|
|
|
{
|
2021-01-29 16:44:47 -08:00
|
|
|
|
primaryActionsPanel.RemoveChildren();
|
2019-01-24 18:03:43 -08:00
|
|
|
|
}
|
2018-11-16 08:44:56 -08:00
|
|
|
|
}
|
2022-02-02 17:31:44 -08:00
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|