Working on making unlockable design apps

This commit is contained in:
LarsBrubaker 2019-05-04 08:35:43 -07:00
parent 7aeafb3cda
commit d40a9235c8
7 changed files with 62 additions and 83 deletions

View file

@ -439,6 +439,7 @@ namespace MatterHackers.MatterControl
public Action RedeemDesignCode;
public Action EnterShareCode;
public Func<Type, bool> UserHasPermissions;
public Func<Type, string> GetUnlockPage;
private static ApplicationController globalInstance;

View file

@ -1,45 +0,0 @@
/*
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;
namespace MatterHackers.MatterControl.DesignTools
{
[AttributeUsage(AttributeTargets.Class)]
public class UnlockLinkAttribute : Attribute
{
public static string UnlockPageBaseUrl => "https://www.matterhackers.com/store/l/";
public string UnlockPageLink { get; private set; }
public UnlockLinkAttribute(string unlockPageLink)
{
UnlockPageLink = unlockPageLink;
}
}
}

View file

@ -39,7 +39,6 @@ using System.Threading.Tasks;
namespace MatterHackers.MatterControl.DesignTools
{
[UnlockLinkAttribute("mattercontrol-image-converter-add-on")]
public class ChairFootObject3D : Object3D
{
public enum OutputMode { Final_Part, Fit_Test };

View file

@ -54,7 +54,6 @@ namespace MatterHackers.MatterControl.DesignTools
{
private readonly double innerDiameter = 35;
private readonly double outerDiameter = 40;
private object locker = new object();
public ImageCoinObject3D()
{
@ -85,6 +84,8 @@ namespace MatterHackers.MatterControl.DesignTools
return imageCoin;
}
public override bool Persistable { get => ApplicationController.Instance.UserHasPermissions(this.GetType()); }
public override async void OnInvalidate(InvalidateArgs invalidateType)
{
if ((invalidateType.InvalidateType.HasFlag(InvalidateType.Children)

View file

@ -808,11 +808,11 @@ namespace MatterHackers.MatterControl.DesignTools
private void AddUnlockLinkIfRequired(PPEContext context, FlowLayoutWidget editControlsContainer, ThemeConfig theme)
{
if (context.item.GetType().GetCustomAttributes(typeof(UnlockLinkAttribute), true).FirstOrDefault() is UnlockLinkAttribute unlockLink
&& !string.IsNullOrEmpty(unlockLink.UnlockPageLink)
&& !context.item.Persistable)
var unlockUrl = ApplicationController.Instance.GetUnlockPage?.Invoke(context.item.GetType());
if (!context.item.Persistable
&& !string.IsNullOrEmpty(unlockUrl))
{
FlowLayoutWidget row = GetUnlockRow(theme, unlockLink.UnlockPageLink);
FlowLayoutWidget row = GetUnlockRow(theme, unlockUrl);
editControlsContainer.AddChild(row);
}
@ -824,11 +824,12 @@ namespace MatterHackers.MatterControl.DesignTools
var detailsLink = new TextIconButton("Unlock".Localize(), AggContext.StaticData.LoadIcon("locked.png", 16, 16, theme.InvertIcons), theme)
{
Margin = 5
Margin = 5,
ToolTipText = "Visit MatterHackers.com to Purchase".Localize()
};
detailsLink.Click += (s, e) =>
{
ApplicationController.Instance.LaunchBrowser(UnlockLinkAttribute.UnlockPageBaseUrl + unlockLinkUrl);
ApplicationController.Instance.LaunchBrowser(unlockLinkUrl);
};
row.AddChild(detailsLink);
theme.ApplyPrimaryActionStyle(detailsLink);

View file

@ -31,6 +31,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
@ -211,35 +213,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
foreach (var item in object3D.VisibleMeshes())
{
// check for correct persistable rendering
if (InteractionLayer.ViewOnlyTexture != null
&& item.Mesh.Faces.Count > 0)
{
ImageBuffer faceTexture = null;
// item.Mesh.FaceTexture.TryGetValue((item.Mesh.Faces[0], 0), out faceTexture);
bool hasPersistableTexture = faceTexture == InteractionLayer.ViewOnlyTexture;
if (item.WorldPersistable())
{
if (hasPersistableTexture)
{
// make sure it does not have the view only texture
item.Mesh.RemoveTexture(ViewOnlyTexture, 0);
}
}
else
{
if (!hasPersistableTexture)
{
// make sure it does have the view only texture
var aabb = item.Mesh.GetAxisAlignedBoundingBox();
var matrix = Matrix4X4.CreateScale(.5, .5, 1);
matrix *= Matrix4X4.CreateRotationZ(MathHelper.Tau / 8);
item.Mesh.PlaceTexture(ViewOnlyTexture, matrix);
}
}
}
// check for correct protection rendering
ValidateViewOnlyTexturing(item);
Color drawColor = this.GetItemColor(item, selectedItem);
@ -279,6 +254,53 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
private static void ValidateViewOnlyTexturing(IObject3D item)
{
// if there is no view only texture or the item is locked
if (InteractionLayer.ViewOnlyTexture == null
|| item.Mesh.Faces.Count == 0)
{
return;
}
// if the item is not currently be processed
if (!item.RebuildLocked)
{
item.Mesh.FaceTextures.TryGetValue(0, out FaceTextureData faceTexture);
bool viewOnlyTexture = faceTexture?.image == InteractionLayer.ViewOnlyTexture;
// if not persistable and has view only texture, remove the view only texture if it has it
if (item.WorldPersistable()
&& viewOnlyTexture)
{
// make sure it does not have the view only texture
using (item.RebuildLock())
{
item.Mesh.RemoveTexture(ViewOnlyTexture, 0);
}
}
else if (!item.WorldPersistable()
&& !viewOnlyTexture)
{
// add a view only texture if it does not have one
// make a copy of the mesh and texture it
Task.Run(() =>
{
// make sure it does have the view only texture
var aabb = item.Mesh.GetAxisAlignedBoundingBox();
var matrix = Matrix4X4.CreateScale(.5, .5, 1);
matrix *= Matrix4X4.CreateRotationZ(MathHelper.Tau / 8);
// make sure it has it's own copy of the mesh
using (item.RebuildLock())
{
item.Mesh = item.Mesh.Copy(CancellationToken.None);
item.Mesh.PlaceTexture(ViewOnlyTexture, matrix);
}
});
}
}
}
private Color GetItemColor(IObject3D item, IObject3D selectedItem)
{
Color drawColor = item.WorldColor();

@ -1 +1 @@
Subproject commit 6bdef5348083690dfb616e49d4e9fd1e57d9d0ca
Subproject commit 6fd2d52f27741fcf723e46a4a9e615fa0d2fb6f1