2015-08-15 16:38:07 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Lars Brubaker
|
|
|
|
|
|
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 MatterHackers.Agg;
|
2014-05-25 11:11:11 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.MeshVisualizer;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2015-08-15 16:38:07 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
2016-05-07 20:06:43 -07:00
|
|
|
|
using MatterHackers.Agg.PlatformAbstract;
|
|
|
|
|
|
using MatterHackers.Agg.ImageProcessing;
|
2017-05-22 18:17:35 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
|
|
|
|
|
using MatterHackers.RenderOpenGl;
|
|
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
using System.Linq;
|
2014-05-25 11:11:11 -07:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PartPreviewWindow
|
|
|
|
|
|
{
|
2015-05-29 15:13:56 -07:00
|
|
|
|
public enum ViewControls3DButtons
|
|
|
|
|
|
{
|
|
|
|
|
|
Rotate,
|
|
|
|
|
|
Scale,
|
|
|
|
|
|
Translate,
|
|
|
|
|
|
PartSelect
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-25 17:58:20 -07:00
|
|
|
|
public class TransformStateChangedEventArgs : EventArgs
|
|
|
|
|
|
{
|
|
|
|
|
|
public ViewControls3DButtons TransformMode { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public class ViewControls3D : FlowLayoutWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
private GuiWidget partSelectSeparator;
|
2015-11-09 12:36:47 -08:00
|
|
|
|
private Button resetViewButton;
|
|
|
|
|
|
|
2015-05-29 15:13:56 -07:00
|
|
|
|
private RadioButton translateButton;
|
|
|
|
|
|
private RadioButton rotateButton;
|
|
|
|
|
|
private RadioButton scaleButton;
|
|
|
|
|
|
private RadioButton partSelectButton;
|
|
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
private EventHandler unregisterEvents;
|
|
|
|
|
|
|
2017-05-26 00:23:20 -07:00
|
|
|
|
internal OverflowDropdown OverflowButton;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
|
2015-11-09 12:36:47 -08:00
|
|
|
|
public event EventHandler ResetView;
|
|
|
|
|
|
|
2017-05-25 17:58:20 -07:00
|
|
|
|
public event EventHandler<TransformStateChangedEventArgs> TransformStateChanged;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
public bool PartSelectVisible
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return partSelectSeparator.Visible; }
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
partSelectSeparator.Visible = value;
|
|
|
|
|
|
partSelectButton.Visible = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-05-29 15:13:56 -07:00
|
|
|
|
private ViewControls3DButtons activeTransformState = ViewControls3DButtons.Rotate;
|
|
|
|
|
|
|
|
|
|
|
|
public ViewControls3DButtons ActiveButton
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return activeTransformState;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
this.activeTransformState = value;
|
2017-05-25 17:58:20 -07:00
|
|
|
|
switch (this.activeTransformState)
|
2015-05-29 15:13:56 -07:00
|
|
|
|
{
|
2017-05-25 17:58:20 -07:00
|
|
|
|
case ViewControls3DButtons.Rotate:
|
|
|
|
|
|
rotateButton.Checked = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ViewControls3DButtons.Translate:
|
|
|
|
|
|
translateButton.Checked = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ViewControls3DButtons.Scale:
|
|
|
|
|
|
scaleButton.Checked = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ViewControls3DButtons.PartSelect:
|
|
|
|
|
|
partSelectButton.Checked = true;
|
|
|
|
|
|
break;
|
2015-05-29 15:13:56 -07:00
|
|
|
|
}
|
2017-05-25 17:58:20 -07:00
|
|
|
|
|
|
|
|
|
|
TransformStateChanged?.Invoke(this, new TransformStateChangedEventArgs()
|
|
|
|
|
|
{
|
|
|
|
|
|
TransformMode = activeTransformState
|
|
|
|
|
|
});
|
2015-05-29 15:13:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-25 17:58:20 -07:00
|
|
|
|
public ViewControls3D(TextImageButtonFactory buttonFactory)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-03-15 16:17:06 -07:00
|
|
|
|
string iconPath;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "reset.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
resetViewButton = buttonFactory.Generate("", StaticData.Instance.LoadIcon(iconPath,32,32).InvertLightness());
|
2015-11-09 12:36:47 -08:00
|
|
|
|
resetViewButton.ToolTipText = "Reset View".Localize();
|
2017-03-15 16:17:06 -07:00
|
|
|
|
resetViewButton.Click += (s, e) => ResetView?.Invoke(this, null);
|
2017-05-24 19:11:51 -07:00
|
|
|
|
AddChild(resetViewButton);
|
2015-11-09 12:36:47 -08:00
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "rotate.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
rotateButton = buttonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(iconPath,32,32));
|
2015-08-21 13:31:36 -07:00
|
|
|
|
rotateButton.ToolTipText = "Rotate (Alt + Left Mouse)".Localize();
|
2017-03-15 16:17:06 -07:00
|
|
|
|
rotateButton.Margin = new BorderDouble(3);
|
|
|
|
|
|
rotateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Rotate;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
AddChild(rotateButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "translate.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
translateButton = buttonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(iconPath,32,32));
|
2015-08-21 13:31:36 -07:00
|
|
|
|
translateButton.ToolTipText = "Move (Shift + Left Mouse)".Localize();
|
2017-03-15 16:17:06 -07:00
|
|
|
|
translateButton.Margin = new BorderDouble(3);
|
|
|
|
|
|
translateButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Translate;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
AddChild(translateButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "scale.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
scaleButton = buttonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(iconPath,32,32));
|
2015-08-21 13:31:36 -07:00
|
|
|
|
scaleButton.ToolTipText = "Zoom (Ctrl + Left Mouse)".Localize();
|
2017-05-22 18:17:35 -07:00
|
|
|
|
scaleButton.Margin = 3;
|
2017-03-15 16:17:06 -07:00
|
|
|
|
scaleButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.Scale;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
AddChild(scaleButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
partSelectSeparator = new GuiWidget(2, 32);
|
|
|
|
|
|
partSelectSeparator.BackgroundColor = RGBA_Bytes.White;
|
2017-05-22 18:17:35 -07:00
|
|
|
|
partSelectSeparator.Margin = 3;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
AddChild(partSelectSeparator);
|
|
|
|
|
|
|
2017-03-15 16:17:06 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "partSelect.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
partSelectButton = buttonFactory.GenerateRadioButton("", StaticData.Instance.LoadIcon(iconPath,32,32));
|
2017-05-22 18:17:35 -07:00
|
|
|
|
partSelectButton.ToolTipText = "Select Part".Localize();
|
|
|
|
|
|
partSelectButton.Margin = new BorderDouble(3);
|
2017-03-15 16:17:06 -07:00
|
|
|
|
partSelectButton.Click += (s, e) => this.ActiveButton = ViewControls3DButtons.PartSelect;
|
2017-05-24 19:11:51 -07:00
|
|
|
|
AddChild(partSelectButton);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2017-05-24 19:11:51 -07:00
|
|
|
|
iconPath = Path.Combine("ViewTransformControls", "layers.png");
|
2017-05-25 17:58:20 -07:00
|
|
|
|
var layersButton = buttonFactory.Generate("", StaticData.Instance.LoadIcon(iconPath, 32, 32).InvertLightness());
|
2017-05-24 19:11:51 -07:00
|
|
|
|
layersButton.ToolTipText = "Layers".Localize();
|
|
|
|
|
|
layersButton.Margin = 3;
|
|
|
|
|
|
layersButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var parentTabPage = this.Parents<PartPreviewContent.PrinterTabPage>().First();
|
|
|
|
|
|
parentTabPage.ToggleView();
|
|
|
|
|
|
};
|
|
|
|
|
|
AddChild(layersButton);
|
|
|
|
|
|
|
2017-05-26 00:23:20 -07:00
|
|
|
|
OverflowButton = new OverflowDropdown(allowLightnessInvert: false);
|
|
|
|
|
|
OverflowButton.ToolTipText = "More...".Localize();
|
|
|
|
|
|
OverflowButton.Margin = 3;
|
|
|
|
|
|
AddChild(OverflowButton);
|
2017-05-22 18:17:35 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
HAnchor |= Agg.UI.HAnchor.ParentLeft;
|
|
|
|
|
|
VAnchor = Agg.UI.VAnchor.ParentTop;
|
2017-05-23 19:03:30 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
rotateButton.Checked = true;
|
2017-03-15 16:17:06 -07:00
|
|
|
|
BackgroundColor = new RGBA_Bytes(0, 0, 0, 120);
|
2017-05-22 18:17:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-03 13:06:08 -08:00
|
|
|
|
public override void OnClosed(ClosedEventArgs e)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-03-15 16:17:06 -07:00
|
|
|
|
unregisterEvents?.Invoke(this, null);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
base.OnClosed(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|