Getting the Braille plug-in working.

This commit is contained in:
Lars Brubaker 2015-09-14 17:39:48 -07:00
parent fce926cc2d
commit 9837707845
8 changed files with 1366 additions and 3 deletions

View file

@ -0,0 +1,73 @@
/*
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.UI;
using MatterHackers.MatterControl.CreatorPlugins;
using MatterHackers.MatterControl.PluginSystem;
using System;
namespace MatterHackers.MatterControl.Plugins.BrailleBuilder
{
public class BrailleBuilderPlugin : MatterControlPlugin
{
public BrailleBuilderPlugin()
{
}
private GuiWidget mainApplication;
public override void Initialize(GuiWidget application)
{
CreatorInformation information = new CreatorInformation(LaunchNewBrailleBuilder, "259.png", "Braille Builder");
RegisteredCreators.Instance.RegisterLaunchFunction(information);
mainApplication = application;
UiThread.RunOnIdle(() =>
{
LaunchNewBrailleBuilder(null, null);
}, .5);
}
public override string GetPluginInfoJSon()
{
return "{" +
"\"Name\": \"Braille Builder\"," +
"\"UUID\": \"9F1152BA-2D9E-44FC-93FD-B55FC6FD8D9E\"," +
"\"About\": \"A Creator that allows you to type in text and have it turned into aprintable Braille extrusions.\"," +
"\"Developer\": \"MatterHackers, Inc.\"," +
"\"URL\": \"https://www.matterhackers.com\"" +
"}";
}
public void LaunchNewBrailleBuilder(object sender, EventArgs e)
{
BrailleBuilderMainWindow mainWindow = new BrailleBuilderMainWindow();
}
}
}

View file

@ -0,0 +1,209 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{70FBB82C-558D-4B5F-BE75-A922D392E650}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MatterHackers.Plugins.BrailBuilder</RootNamespace>
<AssemblyName>BrailBuilder</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>False</Optimize>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>True</Optimize>
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release64|AnyCPU'">
<OutputPath>bin\Release64\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisLogFile>..\..\MatterControl\bin\Release\BrailBuilder.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug64|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug64\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release64|x64'">
<OutputPath>bin\x64\Release64\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisLogFile>..\..\MatterControl\bin\Release\BrailBuilder.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug64|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug64\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Submodules\agg-sharp\PlatformWin32\OpenTK.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="BrailleBuilderMainWindow.cs" />
<Compile Include="BrailleBuilder.cs" />
<Compile Include="View3DBrailleBuilder.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Submodules\agg-sharp\agg\Agg.csproj">
<Project>{657DBC6D-C3EA-4398-A3FA-DDB73C14F71B}</Project>
<Name>Agg</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\clipper_library\clipper_library.csproj">
<Project>{9B062971-A88E-4A3D-B3C9-12B78D15FA66}</Project>
<Name>clipper_library</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\examples\MeshViewer\MeshViewer.csproj">
<Project>{A737BC76-165B-46C6-82B7-8871C7C92942}</Project>
<Name>MeshViewer</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\Gui\Gui.csproj">
<Project>{74F6BB6C-9D02-4512-A59A-21940E35C532}</Project>
<Name>Gui</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\ImageProcessing\ImageProcessing.csproj">
<Project>{036BCCBA-52D8-457C-84AE-8821F209FE4A}</Project>
<Name>ImageProcessing</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\MarchingSquares\MarchingSquares.csproj">
<Project>{DF6845CD-64C6-4263-8357-DA8066855739}</Project>
<Name>MarchingSquares</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\OpenGlGui\OpenGlGui.csproj">
<Project>{C958F745-156E-4BDC-A24A-3721C7BE7B8A}</Project>
<Name>OpenGlGui</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\PlatformAbstract\PlatformAbstract.csproj">
<Project>{3E4AABA8-D85F-4922-88C6-5C1B2D2308FB}</Project>
<Name>PlatformAbstract</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\PolygonMesh\PolygonMesh.csproj">
<Project>{86F6AAF2-9B50-40B8-A427-1897D76471C5}</Project>
<Name>PolygonMesh</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\RayTracer\RayTracer.csproj">
<Project>{1E01ABE0-B494-4FE4-B0D6-540133286887}</Project>
<Name>RayTracer</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\RenderOpenGl\RenderOpenGl.csproj">
<Project>{545B6912-77FF-4B34-BA76-6C3D6A32BE6A}</Project>
<Name>RenderOpenGl</Name>
</ProjectReference>
<ProjectReference Include="..\Submodules\agg-sharp\VectorMath\VectorMath.csproj">
<Project>{D3E41B4E-BFBB-44CA-94C8-95C00F754FDD}</Project>
<Name>VectorMath</Name>
</ProjectReference>
<ProjectReference Include="..\MatterControl.csproj">
<Project>{0B8D6F56-BD7F-4426-B858-D9292B084656}</Project>
<Name>MatterControl</Name>
</ProjectReference>
<ProjectReference Include="..\PluginSystem\MatterControlPluginSystem.csproj">
<Project>{865172A0-A1A9-49C2-9386-F2FDB4E141B7}</Project>
<Name>MatterControlPluginSystem</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,74 @@
/*
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.UI;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.Plugins.BrailleBuilder
{
public class BrailleBuilderMainWindow : SystemWindow
{
private View3DBrailleBuilder part3DView;
public BrailleBuilderMainWindow()
: base(690, 340)
{
Title = "MatterControl: Braille Builder";
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
double buildHeight = ActiveSliceSettings.Instance.BuildHeight;
part3DView = new View3DBrailleBuilder(
new Vector3(ActiveSliceSettings.Instance.BedSize, buildHeight),
ActiveSliceSettings.Instance.BedCenter,
ActiveSliceSettings.Instance.BedShape);
#if __ANDROID__
this.AddChild(new SoftKeyboardContentOffset(part3DView, SoftKeyboardContentOffset.AndroidKeyboardOffset));
#else
this.AddChild(part3DView);
#endif
this.AnchorAll();
part3DView.Closed += (sender, e) =>
{
Close();
};
Width = 640;
Height = 480;
ShowAsSystemWindow();
MinimumSize = new Vector2(400, 300);
}
}
}

View file

@ -0,0 +1,965 @@
/*
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;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PrintLibrary;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MeshVisualizer;
using MatterHackers.PolygonMesh;
using MatterHackers.PolygonMesh.Csg;
using MatterHackers.PolygonMesh.Processors;
using MatterHackers.RayTracer;
using MatterHackers.RayTracer.Traceable;
using MatterHackers.RenderOpenGl;
using MatterHackers.VectorMath;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MatterHackers.MatterControl.Plugins.BrailleBuilder
{
public class View3DBrailleBuilder : PartPreview3DWidget
{
MHTextEditWidget textToAddWidget;
private SolidSlider wrappingSizeScrollBar;
private SolidSlider sizeScrollBar;
private SolidSlider heightScrollBar;
private double lastHeightValue = 1;
private double lastSizeValue = 1;
private ProgressControl processingProgressControl;
private FlowLayoutWidget editPlateButtonsContainer;
private Button saveButton;
private Button saveAndExitButton;
private Button closeButton;
private String word;
private List<MeshGroup> asynchMeshGroups = new List<MeshGroup>();
private List<ScaleRotateTranslate> asynchMeshGroupTransforms = new List<ScaleRotateTranslate>();
private List<PlatingMeshGroupData> asynchPlatingDatas = new List<PlatingMeshGroupData>();
private List<PlatingMeshGroupData> MeshGroupExtraData;
public ScaleRotateTranslate SelectedMeshTransform
{
get { return meshViewerWidget.SelectedMeshGroupTransform; }
set { meshViewerWidget.SelectedMeshGroupTransform = value; }
}
public MeshGroup SelectedMeshGroup
{
get
{
return meshViewerWidget.SelectedMeshGroup;
}
}
public int SelectedMeshGroupIndex
{
get
{
return meshViewerWidget.SelectedMeshGroupIndex;
}
set
{
meshViewerWidget.SelectedMeshGroupIndex = value;
}
}
public List<MeshGroup> MeshGroups
{
get
{
return meshViewerWidget.MeshGroups;
}
}
public List<ScaleRotateTranslate> MeshGroupTransforms
{
get { return meshViewerWidget.MeshGroupTransforms; }
}
internal struct MeshSelectInfo
{
internal bool downOnPart;
internal PlaneShape hitPlane;
internal Vector3 planeDownHitPos;
internal Vector3 lastMoveDelta;
}
private TypeFace boldTypeFace;
public View3DBrailleBuilder(Vector3 viewerVolume, Vector2 bedCenter, MeshViewerWidget.BedShape bedShape)
{
boldTypeFace = TypeFace.LoadFrom(StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationSans-Bold.svg")));
MeshGroupExtraData = new List<PlatingMeshGroupData>();
FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;
FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
centerPartPreviewAndControls.AnchorAll();
GuiWidget viewArea = new GuiWidget();
viewArea.AnchorAll();
{
meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape);
meshViewerWidget.AllowBedRenderingWhenEmpty = true;
meshViewerWidget.AnchorAll();
}
viewArea.AddChild(meshViewerWidget);
centerPartPreviewAndControls.AddChild(viewArea);
mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);
FlowLayoutWidget buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight;
buttonBottomPanel.Padding = new BorderDouble(3, 3);
buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
buttonRightPanel = CreateRightButtonPanel(viewerVolume.y);
// add in the plater tools
{
FlowLayoutWidget editToolBar = new FlowLayoutWidget();
processingProgressControl = new ProgressControl("Finding Parts:".Localize(), ActiveTheme.Instance.PrimaryTextColor, ActiveTheme.Instance.PrimaryAccentColor);
processingProgressControl.VAnchor = Agg.UI.VAnchor.ParentCenter;
editToolBar.AddChild(processingProgressControl);
editToolBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
editPlateButtonsContainer = new FlowLayoutWidget();
textToAddWidget = new MHTextEditWidget("", pixelWidth: 300, messageWhenEmptyAndNotSelected: "Enter Text Here".Localize());
textToAddWidget.VAnchor = VAnchor.ParentCenter;
textToAddWidget.Margin = new BorderDouble(5);
editPlateButtonsContainer.AddChild(textToAddWidget);
textToAddWidget.ActualTextEditWidget.EnterPressed += (object sender, KeyEventArgs keyEvent) =>
{
InsertTextNow(textToAddWidget.Text);
};
Button insertTextButton = textImageButtonFactory.Generate("Insert".Localize());
editPlateButtonsContainer.AddChild(insertTextButton);
insertTextButton.Click += (sender, e) =>
{
InsertTextNow(textToAddWidget.Text);
};
KeyDown += (sender, e) =>
{
KeyEventArgs keyEvent = e as KeyEventArgs;
if (keyEvent != null && !keyEvent.Handled)
{
if (keyEvent.KeyCode == Keys.Escape)
{
if (meshSelectInfo.downOnPart)
{
meshSelectInfo.downOnPart = false;
ScaleRotateTranslate translated = SelectedMeshTransform;
translated.translation *= transformOnMouseDown;
SelectedMeshTransform = translated;
Invalidate();
}
}
}
};
editToolBar.AddChild(editPlateButtonsContainer);
buttonBottomPanel.AddChild(editToolBar);
}
GuiWidget buttonRightPanelHolder = new GuiWidget(HAnchor.FitToChildren, VAnchor.ParentBottomTop);
centerPartPreviewAndControls.AddChild(buttonRightPanelHolder);
buttonRightPanelHolder.AddChild(buttonRightPanel);
viewControls3D = new ViewControls3D(meshViewerWidget);
buttonRightPanelDisabledCover = new Cover(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
buttonRightPanelDisabledCover.BackgroundColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryBackgroundColor, 150);
buttonRightPanelHolder.AddChild(buttonRightPanelDisabledCover);
LockEditControls();
GuiWidget leftRightSpacer = new GuiWidget();
leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
buttonBottomPanel.AddChild(leftRightSpacer);
closeButton = textImageButtonFactory.Generate("Close".Localize());
buttonBottomPanel.AddChild(closeButton);
mainContainerTopToBottom.AddChild(buttonBottomPanel);
this.AddChild(mainContainerTopToBottom);
this.AnchorAll();
meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;
AddChild(viewControls3D);
// set the view to be a good angle and distance
meshViewerWidget.TrackballTumbleWidget.TrackBallController.Scale = .06;
meshViewerWidget.TrackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .02, 0, 0)));
meshViewerWidget.TrackballTumbleWidget.TrackBallController.Translate(-new Vector3(bedCenter));
AddHandlers();
UnlockEditControls();
// but make sure we can't use the right panel yet
buttonRightPanelDisabledCover.Visible = true;
meshViewerWidget.RenderType = RenderTypes.Outlines;
}
private async void InsertTextNow(string text)
{
if (text.Length > 0)
{
this.word = text;
ResetWordLayoutSettings();
processingProgressControl.ProcessType = "Inserting Text".Localize();
processingProgressControl.Visible = true;
processingProgressControl.PercentComplete = 0;
LockEditControls();
EnglishTextWrapping wrapper = new EnglishTextWrapping(12);
string wrappedMessage = wrapper.InsertCRs(text, wrappingSizeScrollBar.Value);
await Task.Run(() => InsertTextDoWork(wrappedMessage));
UnlockEditControls();
PullMeshDataFromAsynchLists();
saveButton.Visible = true;
saveAndExitButton.Visible = true;
// now set the selection to the new copy
SelectedMeshGroupIndex = 0;
}
}
private void ResetWordLayoutSettings()
{
wrappingSizeScrollBar.Value = 200;
sizeScrollBar.Value = 1;
heightScrollBar.Value = .25;
lastHeightValue = 1;
lastSizeValue = 1;
}
private bool FindMeshGroupHitPosition(Vector2 screenPosition, out int meshHitIndex)
{
meshHitIndex = 0;
if (MeshGroupExtraData.Count == 0 || MeshGroupExtraData[0].meshTraceableData == null)
{
return false;
}
List<IPrimitive> mesheTraceables = new List<IPrimitive>();
for (int i = 0; i < MeshGroupExtraData.Count; i++)
{
foreach (IPrimitive traceData in MeshGroupExtraData[i].meshTraceableData)
{
mesheTraceables.Add(new Transform(traceData, MeshGroupTransforms[i].TotalTransform));
}
}
IPrimitive allObjects = BoundingVolumeHierarchy.CreateNewHierachy(mesheTraceables);
Vector2 meshViewerWidgetScreenPosition = meshViewerWidget.TransformFromParentSpace(this, screenPosition);
Ray ray = meshViewerWidget.TrackballTumbleWidget.GetRayFromScreen(meshViewerWidgetScreenPosition);
IntersectInfo info = allObjects.GetClosestIntersection(ray);
if (info != null)
{
meshSelectInfo.planeDownHitPos = info.hitPosition;
meshSelectInfo.lastMoveDelta = new Vector3();
for (int i = 0; i < MeshGroupExtraData.Count; i++)
{
List<IPrimitive> insideBounds = new List<IPrimitive>();
foreach (IPrimitive traceData in MeshGroupExtraData[i].meshTraceableData)
{
traceData.GetContained(insideBounds, info.closestHitObject.GetAxisAlignedBoundingBox());
}
if (insideBounds.Contains(info.closestHitObject))
{
meshHitIndex = i;
return true;
}
}
}
return false;
}
private Matrix4X4 transformOnMouseDown = Matrix4X4.Identity;
private MeshSelectInfo meshSelectInfo;
public override void OnMouseDown(MouseEventArgs mouseEvent)
{
base.OnMouseDown(mouseEvent);
if (meshViewerWidget.TrackballTumbleWidget.UnderMouseState == Agg.UI.UnderMouseState.FirstUnderMouse)
{
if (meshViewerWidget.TrackballTumbleWidget.TransformState == TrackBallController.MouseDownType.None)
{
viewControls3D.ActiveButton = ViewControls3DButtons.PartSelect;
int meshHitIndex;
if (FindMeshGroupHitPosition(mouseEvent.Position, out meshHitIndex))
{
meshSelectInfo.hitPlane = new PlaneShape(Vector3.UnitZ, meshSelectInfo.planeDownHitPos.z, null);
SelectedMeshGroupIndex = meshHitIndex;
transformOnMouseDown = SelectedMeshTransform.translation;
Invalidate();
meshSelectInfo.downOnPart = true;
}
}
}
}
bool firstDraw = true;
public override void OnDraw(Graphics2D graphics2D)
{
//DoCsgTest();
if (firstDraw)
{
textToAddWidget.Focus();
textToAddWidget.Text = "This is some nice long text to work with. Thanks for coming.";
firstDraw = false;
}
base.OnDraw(graphics2D);
}
public override void OnMouseMove(MouseEventArgs mouseEvent)
{
if (meshViewerWidget.TrackballTumbleWidget.TransformState == TrackBallController.MouseDownType.None && meshSelectInfo.downOnPart)
{
Vector2 meshViewerWidgetScreenPosition = meshViewerWidget.TransformFromParentSpace(this, new Vector2(mouseEvent.X, mouseEvent.Y));
Ray ray = meshViewerWidget.TrackballTumbleWidget.GetRayFromScreen(meshViewerWidgetScreenPosition);
IntersectInfo info = meshSelectInfo.hitPlane.GetClosestIntersection(ray);
if (info != null)
{
Vector3 delta = info.hitPosition - meshSelectInfo.planeDownHitPos;
Matrix4X4 totalTransform = Matrix4X4.CreateTranslation(new Vector3(-meshSelectInfo.lastMoveDelta));
totalTransform *= Matrix4X4.CreateTranslation(new Vector3(delta));
meshSelectInfo.lastMoveDelta = delta;
ScaleRotateTranslate translated = SelectedMeshTransform;
translated.translation *= totalTransform;
SelectedMeshTransform = translated;
Invalidate();
}
}
base.OnMouseMove(mouseEvent);
}
public override void OnMouseUp(MouseEventArgs mouseEvent)
{
if (meshViewerWidget.TrackballTumbleWidget.TransformState == TrackBallController.MouseDownType.None
&& meshSelectInfo.downOnPart
&& meshSelectInfo.lastMoveDelta != Vector3.Zero)
{
saveButton.Visible = true;
saveAndExitButton.Visible = true;
}
meshSelectInfo.downOnPart = false;
base.OnMouseUp(mouseEvent);
}
private void InsertTextDoWork(string currentText)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
asynchMeshGroups.Clear();
asynchMeshGroupTransforms.Clear();
asynchPlatingDatas.Clear();
TypeFacePrinter printer = new TypeFacePrinter(currentText, new StyledTypeFace(boldTypeFace, 12));
Vector2 size = printer.GetSize(currentText);
Vector2 centerOffset = -size / 2;
double ratioPerMeshGroup = 1.0 / currentText.Length;
double currentRatioDone = 0;
for (int i = 0; i < currentText.Length; i++)
{
int newIndex = asynchMeshGroups.Count;
TypeFacePrinter letterPrinter = new TypeFacePrinter(currentText[i].ToString(), new StyledTypeFace(boldTypeFace, 12));
Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, 10);
if (textMesh.Faces.Count > 0)
{
asynchMeshGroups.Add(new MeshGroup(textMesh));
PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();
newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i) + centerOffset;
asynchPlatingDatas.Add(newMeshInfo);
asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
{
continueProcessing = true;
int nextPercent = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
processingProgressControl.PercentComplete = nextPercent;
});
currentRatioDone += ratioPerMeshGroup;
PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, newIndex);
}
processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
}
SetWordSpacing(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
SetWordSize(asynchMeshGroups, asynchMeshGroupTransforms);
SetWordHeight(asynchMeshGroups, asynchMeshGroupTransforms);
CreateBase(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
processingProgressControl.PercentComplete = 95;
}
private void CreateBase(List<MeshGroup> meshesList, List<ScaleRotateTranslate> meshTransforms, List<PlatingMeshGroupData> platingDataList)
{
if (meshesList.Count > 0)
{
AxisAlignedBoundingBox bounds = meshesList[0].GetAxisAlignedBoundingBox(meshTransforms[0].TotalTransform);
for (int i = 1; i < meshesList.Count; i++)
{
bounds = AxisAlignedBoundingBox.Union(bounds, meshesList[i].GetAxisAlignedBoundingBox(meshTransforms[i].TotalTransform));
}
double xSize = bounds.XSize;
double ySize = bounds.YSize;
double zSize = bounds.ZSize / 2;
double roundingScale = 20;
RectangleDouble baseRect = new RectangleDouble(bounds.minXYZ.x, bounds.minXYZ.y, bounds.maxXYZ.x, bounds.maxXYZ.y);
baseRect.Inflate(2);
baseRect *= roundingScale;
RoundedRect baseRoundedRect = new RoundedRect(baseRect, 20);
Mesh baseMeshResult = VertexSourceToMesh.Extrude(baseRoundedRect, zSize * roundingScale);
baseMeshResult.Transform(Matrix4X4.CreateScale(1 / roundingScale));
meshesList.Add(new MeshGroup(baseMeshResult));
platingDataList.Add(new PlatingMeshGroupData());
meshTransforms.Add(ScaleRotateTranslate.CreateTranslation(0, 0, 0));
PlatingHelper.CreateITraceableForMeshGroup(platingDataList, meshesList, meshesList.Count - 1, null);
}
}
private void PushMeshGroupDataToAsynchLists(bool copyTraceInfo)
{
asynchMeshGroups.Clear();
asynchMeshGroupTransforms.Clear();
for (int meshGroupIndex = 0; meshGroupIndex < MeshGroups.Count; meshGroupIndex++)
{
MeshGroup meshGroup = MeshGroups[meshGroupIndex];
MeshGroup newMeshGroup = new MeshGroup();
for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++)
{
Mesh mesh = meshGroup.Meshes[meshIndex];
newMeshGroup.Meshes.Add(Mesh.Copy(mesh));
asynchMeshGroupTransforms.Add(MeshGroupTransforms[meshGroupIndex]);
}
asynchMeshGroups.Add(newMeshGroup);
}
asynchPlatingDatas.Clear();
for (int meshGroupIndex = 0; meshGroupIndex < MeshGroupExtraData.Count; meshGroupIndex++)
{
PlatingMeshGroupData meshData = new PlatingMeshGroupData();
meshData.currentScale = MeshGroupExtraData[meshGroupIndex].currentScale;
MeshGroup meshGroup = MeshGroups[meshGroupIndex];
for (int meshIndex = 0; meshIndex < meshGroup.Meshes.Count; meshIndex++)
{
if (copyTraceInfo)
{
meshData.meshTraceableData.AddRange(MeshGroupExtraData[meshGroupIndex].meshTraceableData);
}
}
asynchPlatingDatas.Add(meshData);
}
}
private void arrangePartsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
UnlockEditControls();
saveButton.Visible = true;
saveAndExitButton.Visible = true;
viewControls3D.ActiveButton = ViewControls3DButtons.PartSelect;
PullMeshDataFromAsynchLists();
}
private void PullMeshDataFromAsynchLists()
{
MeshGroups.Clear();
foreach (MeshGroup mesh in asynchMeshGroups)
{
MeshGroups.Add(mesh);
}
MeshGroupTransforms.Clear();
foreach (ScaleRotateTranslate transform in asynchMeshGroupTransforms)
{
MeshGroupTransforms.Add(transform);
}
MeshGroupExtraData.Clear();
foreach (PlatingMeshGroupData meshData in asynchPlatingDatas)
{
MeshGroupExtraData.Add(meshData);
}
}
private void meshViewerWidget_LoadDone(object sender, EventArgs e)
{
UnlockEditControls();
}
private void LockEditControls()
{
editPlateButtonsContainer.Visible = false;
buttonRightPanelDisabledCover.Visible = true;
viewControls3D.PartSelectVisible = false;
if (meshViewerWidget.TrackballTumbleWidget.TransformState == TrackBallController.MouseDownType.None)
{
viewControls3D.ActiveButton = ViewControls3DButtons.Rotate;
}
}
private void UnlockEditControls()
{
buttonRightPanelDisabledCover.Visible = false;
processingProgressControl.Visible = false;
viewControls3D.PartSelectVisible = true;
editPlateButtonsContainer.Visible = true;
}
private void DeleteSelectedMesh()
{
// don't ever delet the last mesh
if (MeshGroups.Count > 1)
{
MeshGroups.RemoveAt(SelectedMeshGroupIndex);
MeshGroupExtraData.RemoveAt(SelectedMeshGroupIndex);
MeshGroupTransforms.RemoveAt(SelectedMeshGroupIndex);
SelectedMeshGroupIndex = Math.Min(SelectedMeshGroupIndex, MeshGroups.Count - 1);
saveButton.Visible = true;
saveAndExitButton.Visible = true;
Invalidate();
}
}
private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
processingProgressControl.PercentComplete = e.ProgressPercentage;
}
private FlowLayoutWidget CreateRightButtonPanel(double buildHeight)
{
FlowLayoutWidget buttonRightPanel = new FlowLayoutWidget(FlowDirection.TopToBottom);
buttonRightPanel.Width = 200;
{
BorderDouble buttonMargin = new BorderDouble(top: 3);
// put in the word editing menu
{
CheckBox expandWordOptions = expandMenuOptionFactory.GenerateCheckBoxButton("Word Edit".Localize(), "icon_arrow_right_no_border_32x32.png", "icon_arrow_down_no_border_32x32.png");
expandWordOptions.Margin = new BorderDouble(bottom: 2);
buttonRightPanel.AddChild(expandWordOptions);
FlowLayoutWidget wordOptionContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
wordOptionContainer.HAnchor = HAnchor.ParentLeftRight;
wordOptionContainer.Visible = false;
buttonRightPanel.AddChild(wordOptionContainer);
wrappingSizeScrollBar = InsertUiForSlider(wordOptionContainer, "Spacing:".Localize(), 20, 200);
{
wrappingSizeScrollBar.ValueChanged += (sender, e) =>
{
SetWordSpacing(MeshGroups, MeshGroupTransforms, MeshGroupExtraData);
RebuildUnderline();
};
}
sizeScrollBar = InsertUiForSlider(wordOptionContainer, "Size:".Localize(), .3, 2);
{
sizeScrollBar.ValueChanged += (sender, e) =>
{
SetWordSize(MeshGroups, MeshGroupTransforms);
//SetWordSpacing(MeshGroups, MeshGroupTransforms, MeshGroupExtraData);
RebuildUnderline();
};
}
heightScrollBar = InsertUiForSlider(wordOptionContainer, "Height:".Localize(), .05, 1);
{
heightScrollBar.ValueChanged += (sender, e) =>
{
SetWordHeight(MeshGroups, MeshGroupTransforms);
RebuildUnderline();
};
}
expandWordOptions.CheckedStateChanged += (sender, e) =>
{
wordOptionContainer.Visible = expandWordOptions.Checked;
};
expandWordOptions.Checked = true;
}
// put in the letter editing menu
{
CheckBox expandLetterOptions = expandMenuOptionFactory.GenerateCheckBoxButton("Letter", "icon_arrow_right_no_border_32x32.png", "icon_arrow_down_no_border_32x32.png");
expandLetterOptions.Margin = new BorderDouble(bottom: 2);
//buttonRightPanel.AddChild(expandLetterOptions);
FlowLayoutWidget letterOptionContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
letterOptionContainer.HAnchor = HAnchor.ParentLeftRight;
letterOptionContainer.Visible = false;
buttonRightPanel.AddChild(letterOptionContainer);
SolidSlider sizeScrollBar = InsertUiForSlider(letterOptionContainer, "Size:".Localize());
SolidSlider heightScrollBar = InsertUiForSlider(letterOptionContainer, "Height:".Localize());
SolidSlider rotationScrollBar = InsertUiForSlider(letterOptionContainer, "Rotation:".Localize());
expandLetterOptions.CheckedStateChanged += (sender, e) =>
{
letterOptionContainer.Visible = expandLetterOptions.Checked;
};
}
GuiWidget verticalSpacer = new GuiWidget();
verticalSpacer.VAnchor = VAnchor.ParentBottomTop;
buttonRightPanel.AddChild(verticalSpacer);
saveButton = whiteButtonFactory.Generate("Save".Localize(), centerText: true);
saveButton.Visible = false;
saveButton.Cursor = Cursors.Hand;
saveAndExitButton = whiteButtonFactory.Generate("Save & Exit".Localize(), centerText: true);
saveAndExitButton.Visible = false;
saveAndExitButton.Cursor = Cursors.Hand;
//buttonRightPanel.AddChild(saveButton);
buttonRightPanel.AddChild(saveAndExitButton);
}
buttonRightPanel.Padding = new BorderDouble(6, 6);
buttonRightPanel.Margin = new BorderDouble(0, 1);
buttonRightPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
buttonRightPanel.VAnchor = VAnchor.ParentBottomTop;
return buttonRightPanel;
}
private void RebuildUnderline()
{
// we need to remove the underline
if (MeshGroups.Count > 1)
{
int oldIndex = SelectedMeshGroupIndex;
SelectedMeshGroupIndex = MeshGroups.Count - 1;
DeleteSelectedMesh();
// we need to add the underline
CreateBase(MeshGroups, MeshGroupTransforms, MeshGroupExtraData);
SelectedMeshGroupIndex = oldIndex;
}
}
private void SetWordSpacing(List<MeshGroup> meshesList, List<ScaleRotateTranslate> meshTransforms, List<PlatingMeshGroupData> platingDataList)
{
if (meshesList.Count > 0)
{
EnglishTextWrapping wrapper = new EnglishTextWrapping(12);
string currentText = wrapper.InsertCRs(this.word, wrappingSizeScrollBar.Value);
TypeFacePrinter printer = new TypeFacePrinter(currentText, new StyledTypeFace(boldTypeFace, 12));
Vector2 size = printer.GetSize(currentText);
Vector2 centerOffset = -size / 2;
int meshIndex2 = 0;
for (int i = 0; i < currentText.Length; i++)
{
int newIndex = asynchMeshGroups.Count;
TypeFacePrinter letterPrinter = new TypeFacePrinter(currentText[i].ToString(), new StyledTypeFace(boldTypeFace, 12));
if (letterPrinter.LocalBounds.Width > 0 && meshIndex2 < meshesList.Count-1)
{
PlatingMeshGroupData newMeshInfo = platingDataList[meshIndex2];
newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i) + centerOffset;
meshIndex2++;
}
}
for (int meshIndex = 0; meshIndex < meshesList.Count; meshIndex++)
{
Vector3 startPosition = Vector3.Transform(Vector3.Zero, meshTransforms[meshIndex].translation);
//EnglishTextWrapping wrapper = new EnglishTextWrapping(12);
//string wrappedMessage = wrapper.InsertCRs(text, wrappingSizeScrollBar.Value);
ScaleRotateTranslate translation = meshTransforms[meshIndex];
translation.translation *= Matrix4X4.CreateTranslation(-startPosition);
double newX = platingDataList[meshIndex].spacing.x * lastSizeValue;
double newY = platingDataList[meshIndex].spacing.y * lastSizeValue;
translation.translation *= Matrix4X4.CreateTranslation(new Vector3(newX, newY, 0) + new Vector3(MeshViewerWidget.BedCenter));
meshTransforms[meshIndex] = translation;
}
}
}
private void SetWordSize(List<MeshGroup> meshesList, List<ScaleRotateTranslate> meshTransforms)
{
Vector3 bedCenter = new Vector3(MeshViewerWidget.BedCenter);
if (meshesList.Count > 0)
{
for (int meshIndex = 0; meshIndex < meshesList.Count; meshIndex++)
{
Vector3 startPositionRelCenter = Vector3.Transform(Vector3.Zero, meshTransforms[meshIndex].translation) - bedCenter;
// take out the last scale
double oldSize = 1.0 / lastSizeValue;
Vector3 unscaledStartPositionRelCenter = startPositionRelCenter * oldSize;
double newSize = sizeScrollBar.Value;
Vector3 endPositionRelCenter = unscaledStartPositionRelCenter * newSize;
Vector3 deltaPosition = endPositionRelCenter - startPositionRelCenter;
// move the part to keep it in the same relative position
ScaleRotateTranslate scale = meshTransforms[meshIndex];
scale.scale *= Matrix4X4.CreateScale(new Vector3(oldSize, oldSize, oldSize));
scale.scale *= Matrix4X4.CreateScale(new Vector3(newSize, newSize, newSize));
scale.translation *= Matrix4X4.CreateTranslation(deltaPosition);
meshTransforms[meshIndex] = scale;
}
lastSizeValue = sizeScrollBar.Value;
}
}
private void SetWordHeight(List<MeshGroup> meshesList, List<ScaleRotateTranslate> meshTransforms)
{
if (meshesList.Count > 0)
{
for (int meshIndex = 0; meshIndex < meshesList.Count; meshIndex++)
{
// take out the last scale
double oldHeight = lastHeightValue;
ScaleRotateTranslate scale = meshTransforms[meshIndex];
scale.scale *= Matrix4X4.CreateScale(new Vector3(1, 1, 1 / oldHeight));
double newHeight = heightScrollBar.Value;
scale.scale *= Matrix4X4.CreateScale(new Vector3(1, 1, newHeight));
meshTransforms[meshIndex] = scale;
}
lastHeightValue = heightScrollBar.Value;
}
}
private void AddLetterControls(FlowLayoutWidget buttonPanel)
{
textImageButtonFactory.FixedWidth = 44 * TextWidget.GlobalPointSizeScaleRatio;
FlowLayoutWidget degreesContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
degreesContainer.HAnchor = HAnchor.ParentLeftRight;
degreesContainer.Padding = new BorderDouble(5);
GuiWidget horizontalSpacer = new GuiWidget();
horizontalSpacer.HAnchor = HAnchor.ParentLeftRight;
TextWidget degreesLabel = new TextWidget("Degrees:".Localize(), textColor: ActiveTheme.Instance.PrimaryTextColor);
degreesContainer.AddChild(degreesLabel);
degreesContainer.AddChild(horizontalSpacer);
MHNumberEdit degreesControl = new MHNumberEdit(45, pixelWidth: 40, allowNegatives: true, increment: 5, minValue: -360, maxValue: 360);
degreesControl.VAnchor = Agg.UI.VAnchor.ParentTop;
degreesContainer.AddChild(degreesControl);
buttonPanel.AddChild(degreesContainer);
FlowLayoutWidget rotateButtonContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
rotateButtonContainer.HAnchor = HAnchor.ParentLeftRight;
buttonPanel.AddChild(rotateButtonContainer);
buttonPanel.AddChild(generateHorizontalRule());
textImageButtonFactory.FixedWidth = 0;
}
private GuiWidget generateHorizontalRule()
{
GuiWidget horizontalRule = new GuiWidget();
horizontalRule.Height = 1;
horizontalRule.Margin = new BorderDouble(0, 1, 0, 3);
horizontalRule.HAnchor = HAnchor.ParentLeftRight;
horizontalRule.BackgroundColor = new RGBA_Bytes(255, 255, 255, 200);
return horizontalRule;
}
private void AddHandlers()
{
closeButton.Click += new EventHandler(onCloseButton_Click);
saveButton.Click += (sender, e) =>
{
MergeAndSavePartsToStl();
};
saveAndExitButton.Click += (sender, e) =>
{
MergeAndSavePartsToStl();
};
}
private bool partSelectButtonWasClicked = false;
private async void MergeAndSavePartsToStl()
{
if (MeshGroups.Count > 0)
{
partSelectButtonWasClicked = viewControls3D.ActiveButton == ViewControls3DButtons.PartSelect;
processingProgressControl.ProcessType = "Saving Parts:".Localize();
processingProgressControl.Visible = true;
processingProgressControl.PercentComplete = 0;
LockEditControls();
// we sent the data to the asynch lists but we will not pull it back out (only use it as a temp holder).
PushMeshGroupDataToAsynchLists(true);
string fileName = "BrailleBuilder_{0}".FormatWith(Path.ChangeExtension(Path.GetRandomFileName(), ".amf"));
string filePath = Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, fileName);
processingProgressControl.RatioComplete = 0;
await Task.Run(() => mergeAndSavePartsBackgroundWorker_DoWork(filePath));
PrintItem printItem = new PrintItem();
printItem.Name = string.Format("{0}", word);
printItem.FileLocation = Path.GetFullPath(filePath);
PrintItemWrapper printItemWrapper = new PrintItemWrapper(printItem);
// and save to the queue
QueueData.Instance.AddItem(printItemWrapper);
//Exit after save
UiThread.RunOnIdle(CloseOnIdle);
}
}
private void mergeAndSavePartsBackgroundWorker_DoWork(string filePath)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
try
{
// push all the transforms into the meshes
for (int i = 0; i < asynchMeshGroups.Count; i++)
{
asynchMeshGroups[i].Transform(MeshGroupTransforms[i].TotalTransform);
processingProgressControl.RatioComplete = (double)i / asynchMeshGroups.Count * .1;
}
List<MeshGroup> mergResults = new List<MeshGroup>();
mergResults.Add(new MeshGroup());
mergResults[0].Meshes.Add(new Mesh());
double meshGroupIndex = 0;
foreach (MeshGroup meshGroup in asynchMeshGroups)
{
foreach (Mesh mesh in meshGroup.Meshes)
{
processingProgressControl.RatioComplete = .1 + (double)meshGroupIndex / asynchMeshGroups.Count;
mergResults[0].Meshes[0] = CsgOperations.Union(mergResults[0].Meshes[0], mesh);
}
meshGroupIndex++;
}
MeshFileIo.Save(mergResults, filePath);
}
catch (System.UnauthorizedAccessException)
{
//Do something special when unauthorized?
StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.".Localize(), "Unable to save".Localize());
}
catch
{
StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.".Localize(), "Unable to save".Localize());
}
}
private bool scaleQueueMenu_Click()
{
return true;
}
private bool rotateQueueMenu_Click()
{
return true;
}
private void onCloseButton_Click(object sender, EventArgs e)
{
UiThread.RunOnIdle(Close);
}
}
}

11
BrailleBuilder/app.config Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="OpenTK" publicKeyToken="bad199fe84eb3df4" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View file

@ -124,6 +124,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GuiAutomation", "Submodules
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudServices.Tests", "..\CloudServicesPlugin\CloudServices.Tests\CloudServices.Tests.csproj", "{66BAFF8D-3079-4912-B100-41140BAF4DDD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrailleBuilder", "BrailleBuilder\BrailleBuilder.csproj", "{70FBB82C-558D-4B5F-BE75-A922D392E650}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -1133,6 +1135,34 @@ Global
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|Mixed Platforms.Build.0 = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|x64.ActiveCfg = Release|Any CPU
{66BAFF8D-3079-4912-B100-41140BAF4DDD}.Release64|x86.ActiveCfg = Release|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug|x64.ActiveCfg = Debug|x64
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug|x64.Build.0 = Debug|x64
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug|x86.ActiveCfg = Debug|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug64|Any CPU.ActiveCfg = Debug64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug64|Any CPU.Build.0 = Debug64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug64|Mixed Platforms.ActiveCfg = Debug64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug64|Mixed Platforms.Build.0 = Debug64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug64|x64.ActiveCfg = Debug64|x64
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug64|x64.Build.0 = Debug64|x64
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Debug64|x86.ActiveCfg = Debug64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release|Any CPU.Build.0 = Release|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release|x64.ActiveCfg = Release|x64
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release|x64.Build.0 = Release|x64
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release|x86.ActiveCfg = Release|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release64|Any CPU.ActiveCfg = Release64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release64|Any CPU.Build.0 = Release64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release64|Mixed Platforms.ActiveCfg = Release64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release64|Mixed Platforms.Build.0 = Release64|Any CPU
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release64|x64.ActiveCfg = Release64|x64
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release64|x64.Build.0 = Release64|x64
{70FBB82C-558D-4B5F-BE75-A922D392E650}.Release64|x86.ActiveCfg = Release64|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1170,6 +1200,7 @@ Global
{F5D74163-145F-47BF-83DC-D0E07249C6CA} = {4E79BE4E-275E-4901-9173-E9096B7318F0}
{E9102310-0029-4D8F-B1E9-88FBA6147D45} = {2AB9B589-5C98-4C05-BBEA-F97DAE168EAB}
{66BAFF8D-3079-4912-B100-41140BAF4DDD} = {4E79BE4E-275E-4901-9173-E9096B7318F0}
{70FBB82C-558D-4B5F-BE75-A922D392E650} = {32E5B656-D6DF-415E-9E7E-D03F1D8C3A8A}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = MatterControl.csproj

View file

@ -46,7 +46,7 @@ namespace MatterHackers.MatterControl
public class PlatingMeshGroupData
{
public Vector3 currentScale = new Vector3(1, 1, 1);
public double xSpacing;
public Vector2 spacing;
public List<IPrimitive> meshTraceableData = new List<IPrimitive>();
}

View file

@ -423,7 +423,7 @@ namespace MatterHackers.MatterControl.Plugins.TextCreator
PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();
newMeshInfo.xSpacing = printer.GetOffsetLeftOfCharacterIndex(i).x + centerOffset;
newMeshInfo.spacing.x = printer.GetOffsetLeftOfCharacterIndex(i).x + centerOffset;
asynchPlatingDatas.Add(newMeshInfo);
asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());
@ -736,7 +736,7 @@ namespace MatterHackers.MatterControl.Plugins.TextCreator
ScaleRotateTranslate translation = meshTransforms[meshIndex];
translation.translation *= Matrix4X4.CreateTranslation(-startPosition);
double newX = platingDataList[meshIndex].xSpacing * spacingScrollBar.Value * lastSizeValue;
double newX = platingDataList[meshIndex].spacing.x * spacingScrollBar.Value * lastSizeValue;
translation.translation *= Matrix4X4.CreateTranslation(new Vector3(newX, 0, 0) + new Vector3(MeshViewerWidget.BedCenter));
meshTransforms[meshIndex] = translation;
}