Merge branch 'development' of https://github.com/MatterHackers/MatterControl into color_gradient_work

This commit is contained in:
Gregory Diaz 2015-05-04 09:35:27 -07:00
commit 567899e0c6
25 changed files with 605 additions and 286 deletions

View file

@ -106,7 +106,7 @@ namespace MatterHackers.MatterControl
public static void PlaceMeshGroupOnBed(List<MeshGroup> meshesGroupList, List<ScaleRotateTranslate> meshTransforms, int index)
{
AxisAlignedBoundingBox bounds = meshesGroupList[index].GetAxisAlignedBoundingBox(meshTransforms[index].TotalTransform);
AxisAlignedBoundingBox bounds = GetAxisAlignedBoundingBox(meshesGroupList[index], meshTransforms[index].TotalTransform);
Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2;
ScaleRotateTranslate moved = meshTransforms[index];
@ -116,7 +116,7 @@ namespace MatterHackers.MatterControl
public static void CenterMeshGroupXY(List<MeshGroup> meshesGroupList, List<ScaleRotateTranslate> meshTransforms, int index)
{
AxisAlignedBoundingBox bounds = meshesGroupList[index].GetAxisAlignedBoundingBox(meshTransforms[index].TotalTransform);
AxisAlignedBoundingBox bounds = GetAxisAlignedBoundingBox(meshesGroupList[index], meshTransforms[index].TotalTransform);
Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2;
ScaleRotateTranslate moved = meshTransforms[index];
@ -131,6 +131,14 @@ namespace MatterHackers.MatterControl
return;
}
// first find the bounds of what is already here.
AxisAlignedBoundingBox allPlacedMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[0], meshTransforms[0].TotalTransform);
for (int i = 1; i < meshesGroupsToAvoid.Count; i++)
{
AxisAlignedBoundingBox nextMeshBounds = GetAxisAlignedBoundingBox(meshesGroupsToAvoid[i], meshTransforms[i].TotalTransform);
allPlacedMeshBounds = AxisAlignedBoundingBox.Union(allPlacedMeshBounds, nextMeshBounds);
}
meshesGroupsToAvoid.Add(meshGroupToAdd);
PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();
@ -140,61 +148,83 @@ namespace MatterHackers.MatterControl
int meshGroupIndex = meshesGroupsToAvoid.Count - 1;
// now actually center the part we are going to finde a position for
CenterMeshGroupXY(meshesGroupsToAvoid, meshTransforms, meshGroupIndex);
// move the part to the total bounds lower left side
MeshGroup meshGroup = meshesGroupsToAvoid[meshGroupIndex];
Vector3 meshLowerLeft = GetAxisAlignedBoundingBox(meshGroup, meshTransforms[meshGroupIndex].TotalTransform).minXYZ;
ScaleRotateTranslate atLowerLeft = meshTransforms[meshGroupIndex];
atLowerLeft.translation *= Matrix4X4.CreateTranslation(-meshLowerLeft + allPlacedMeshBounds.minXYZ);
meshTransforms[meshGroupIndex] = atLowerLeft;
MoveMeshGroupToOpenPosition(meshGroupIndex, perMeshInfo, meshesGroupsToAvoid, meshTransforms);
PlaceMeshGroupOnBed(meshesGroupsToAvoid, meshTransforms, meshGroupIndex);
}
static AxisAlignedBoundingBox GetAxisAlignedBoundingBox(MeshGroup meshGroup, Matrix4X4 transform)
{
return meshGroup.GetAxisAlignedBoundingBox(transform);
}
public static void MoveMeshGroupToOpenPosition(int meshGroupToMoveIndex, List<PlatingMeshGroupData> perMeshInfo, List<MeshGroup> allMeshGroups, List<ScaleRotateTranslate> meshTransforms)
{
AxisAlignedBoundingBox allPlacedMeshBounds = GetAxisAlignedBoundingBox(allMeshGroups[0], meshTransforms[0].TotalTransform);
for (int i = 1; i < meshGroupToMoveIndex; i++)
{
AxisAlignedBoundingBox nextMeshBounds = GetAxisAlignedBoundingBox(allMeshGroups[i], meshTransforms[i].TotalTransform);
allPlacedMeshBounds = AxisAlignedBoundingBox.Union(allPlacedMeshBounds, nextMeshBounds);
}
double xStart = allPlacedMeshBounds.minXYZ.x;
double yStart = allPlacedMeshBounds.minXYZ.y;
MeshGroup meshGroupToMove = allMeshGroups[meshGroupToMoveIndex];
// find a place to put it that doesn't hit anything
AxisAlignedBoundingBox meshToMoveBounds = meshGroupToMove.GetAxisAlignedBoundingBox(meshTransforms[meshGroupToMoveIndex].TotalTransform);
AxisAlignedBoundingBox meshToMoveBounds = GetAxisAlignedBoundingBox(meshGroupToMove, meshTransforms[meshGroupToMoveIndex].TotalTransform);
// add in a few mm so that it will not be touching
meshToMoveBounds.minXYZ -= new Vector3(2, 2, 0);
meshToMoveBounds.maxXYZ += new Vector3(2, 2, 0);
double ringDist = Math.Min(meshToMoveBounds.XSize, meshToMoveBounds.YSize);
double currentDist = 0;
double angle = 0;
double angleIncrement = MathHelper.Tau / 64;
Matrix4X4 transform;
while (true)
Matrix4X4 transform = Matrix4X4.Identity;
int currentSize = 1;
bool partPlaced = false;
while (!partPlaced && meshGroupToMoveIndex > 0)
{
Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(currentDist, 0, 0);
positionTransform *= Matrix4X4.CreateRotationZ(angle);
Vector3 newPosition = Vector3.Transform(Vector3.Zero, positionTransform);
transform = Matrix4X4.CreateTranslation(newPosition);
AxisAlignedBoundingBox testBounds = meshToMoveBounds.NewTransformed(transform);
bool foundHit = false;
for (int i = 0; i < allMeshGroups.Count; i++)
int yStep = 0;
int xStep = currentSize;
// check far right edge
for (yStep = 0; yStep < currentSize; yStep++)
{
MeshGroup meshToTest = allMeshGroups[i];
if (meshToTest != meshGroupToMove)
partPlaced = CheckPosition(meshGroupToMoveIndex, allMeshGroups, meshTransforms, meshGroupToMove, meshToMoveBounds, yStep, xStep, ref transform);
if (partPlaced)
{
AxisAlignedBoundingBox existingMeshBounds = meshToTest.GetAxisAlignedBoundingBox(meshTransforms[i].TotalTransform);
AxisAlignedBoundingBox intersection = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds);
if (intersection.XSize > 0 && intersection.YSize > 0)
{
foundHit = true;
break;
}
break;
}
}
if (!foundHit)
if (!partPlaced)
{
break;
yStep = currentSize;
// check top edeg
for (xStep = 0; xStep < currentSize; xStep++)
{
partPlaced = CheckPosition(meshGroupToMoveIndex, allMeshGroups, meshTransforms, meshGroupToMove, meshToMoveBounds, yStep, xStep, ref transform);
if (partPlaced)
{
break;
}
}
if (!partPlaced)
{
xStep = currentSize;
// check top right point
partPlaced = CheckPosition(meshGroupToMoveIndex, allMeshGroups, meshTransforms, meshGroupToMove, meshToMoveBounds, yStep, xStep, ref transform);
}
}
angle += angleIncrement;
if (angle >= MathHelper.Tau)
{
angle = 0;
currentDist += ringDist;
}
currentSize++;
}
ScaleRotateTranslate moved = meshTransforms[meshGroupToMoveIndex];
@ -202,6 +232,39 @@ namespace MatterHackers.MatterControl
meshTransforms[meshGroupToMoveIndex] = moved;
}
private static bool CheckPosition(int meshGroupToMoveIndex, List<MeshGroup> allMeshGroups, List<ScaleRotateTranslate> meshTransforms, MeshGroup meshGroupToMove, AxisAlignedBoundingBox meshToMoveBounds, int yStep, int xStep, ref Matrix4X4 transform)
{
double xStepAmount = 5;
double yStepAmount = 5;
Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(xStep * xStepAmount, yStep * yStepAmount, 0);
Vector3 newPosition = Vector3.Transform(Vector3.Zero, positionTransform);
transform = Matrix4X4.CreateTranslation(newPosition);
AxisAlignedBoundingBox testBounds = meshToMoveBounds.NewTransformed(transform);
bool foundHit = false;
for (int i = 0; i < meshGroupToMoveIndex; i++)
{
MeshGroup meshToTest = allMeshGroups[i];
if (meshToTest != meshGroupToMove)
{
AxisAlignedBoundingBox existingMeshBounds = GetAxisAlignedBoundingBox(meshToTest, meshTransforms[i].TotalTransform);
AxisAlignedBoundingBox intersection = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds);
if (intersection.XSize > 0 && intersection.YSize > 0)
{
foundHit = true;
break;
}
}
}
if (!foundHit)
{
return true;
}
return false;
}
public static void CreateITraceableForMeshGroup(List<PlatingMeshGroupData> perMeshGroupInfo, List<MeshGroup> meshGroups, int meshGroupIndex, ReportProgressRatio reportProgress)
{
if (meshGroups != null)

View file

@ -71,7 +71,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
for (int i = 0; i < asynchMeshGroups.Count; i++)
{
ScaleRotateTranslate translate = asynchMeshGroupTransforms[i];
translate.translation *= Matrix4X4.CreateTranslation(1000, 1000, 0);
translate.translation *= Matrix4X4.CreateTranslation(10000, 10000, 0);
asynchMeshGroupTransforms[i] = translate;
}
@ -111,18 +111,22 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// put them onto the plate (try the center) starting with the biggest and moving down
for (int meshGroupIndex = 0; meshGroupIndex < asynchMeshGroups.Count; meshGroupIndex++)
{
bool continueProcessing2 = true;
BackgroundWorker_ProgressChanged(currentRatioDone, "Calculating Positions...".Localize(), out continueProcessing2);
MeshGroup meshGroup = asynchMeshGroups[meshGroupIndex];
Vector3 meshCenter = meshGroup.GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[meshGroupIndex].translation).Center;
Vector3 meshLowerLeft = meshGroup.GetAxisAlignedBoundingBox(asynchMeshGroupTransforms[meshGroupIndex].TotalTransform).minXYZ;
ScaleRotateTranslate atZero = asynchMeshGroupTransforms[meshGroupIndex];
atZero.translation = Matrix4X4.Identity;
atZero.translation *= Matrix4X4.CreateTranslation(-meshLowerLeft);
asynchMeshGroupTransforms[meshGroupIndex] = atZero;
PlatingHelper.MoveMeshGroupToOpenPosition(meshGroupIndex, asynchPlatingDatas, asynchMeshGroups, asynchMeshGroupTransforms);
// and create the trace info so we can select it
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, meshGroupIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
if (asynchPlatingDatas[meshGroupIndex].meshTraceableData.Count == 0)
{
BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
});
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, meshGroupIndex, null);
}
currentRatioDone += ratioPerMeshGroup;

View file

@ -45,8 +45,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
enterEditButtonsContainer.Visible = false;
}
autoArrangeButton.Visible = true;
if (MeshGroups.Count > 0)
{
processingProgressControl.Visible = true;

View file

@ -107,7 +107,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private CheckBox expandMirrorOptions;
private CheckBox expandMaterialOptions;
private Button autoArrangeButton;
private SplitButton saveButtons;
private Button applyScaleButton;
@ -317,12 +316,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
Vector3 delta = info.hitPosition - meshSelectInfo.planeDownHitPos;
Matrix4X4 totalTransfrom = Matrix4X4.CreateTranslation(new Vector3(-meshSelectInfo.lastMoveDelta));
totalTransfrom *= Matrix4X4.CreateTranslation(new Vector3(delta));
Matrix4X4 totalTransform = Matrix4X4.CreateTranslation(new Vector3(-meshSelectInfo.lastMoveDelta));
totalTransform *= Matrix4X4.CreateTranslation(new Vector3(delta));
meshSelectInfo.lastMoveDelta = delta;
ScaleRotateTranslate translated = SelectedMeshGroupTransform;
translated.translation *= totalTransfrom;
translated.translation *= totalTransform;
SelectedMeshGroupTransform = translated;
Invalidate();
@ -497,6 +496,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
AlignToSelectedMeshGroup();
};
Button arrangeButton = textImageButtonFactory.Generate("Arrange".Localize());
doEdittingButtonsContainer.AddChild(arrangeButton);
arrangeButton.Click += (sender, e) =>
{
AutoArrangePartsInBackground();
};
GuiWidget separatorTwo = new GuiWidget(1, 2);
separatorTwo.BackgroundColor = ActiveTheme.Instance.PrimaryTextColor;
separatorTwo.Margin = new BorderDouble(4, 2);
@ -752,7 +758,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (!enterEditButtonsContainer.Visible)
{
enterEditButtonsContainer.Visible = true;
autoArrangeButton.Visible = false;
processingProgressControl.Visible = false;
buttonRightPanel.Visible = false;
doEdittingButtonsContainer.Visible = false;
@ -986,6 +991,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
string progressMessage = "Loading Parts...".Localize();
double ratioPerFile = 1.0 / filesToLoad.Count;
double currentRatioDone = 0;
for (int i = 0; i < filesToLoad.Count; i++)
@ -996,7 +1002,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
continueProcessing = !this.WidgetHasBeenClosed;
double ratioAvailable = (ratioPerFile * .5);
double currentRatio = currentRatioDone + progress0To1 * ratioAvailable;
BackgroundWorker_ProgressChanged(currentRatio, processingState, out continueProcessing);
BackgroundWorker_ProgressChanged(currentRatio, progressMessage, out continueProcessing);
});
if (WidgetHasBeenClosed)
@ -1005,8 +1011,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
if (loadedMeshGroups != null)
{
double ratioPerSubMesh = 1.0 / loadedMeshGroups.Count;
double currentPlatingRatioDone = 0;
double ratioPerSubMesh = ratioPerFile / loadedMeshGroups.Count;
double subMeshRatioDone = 0;
for (int subMeshIndex = 0; subMeshIndex < loadedMeshGroups.Count; subMeshIndex++)
{
@ -1021,16 +1027,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
continueProcessing = !this.WidgetHasBeenClosed;
double ratioAvailable = (ratioPerFile * .5);
double currentRatio = currentRatioDone + currentPlatingRatioDone + ratioAvailable + progress0To1 * ratioAvailable;
BackgroundWorker_ProgressChanged(currentRatio, processingState, out continueProcessing);
// done outer loop + done this loop +first 1/2 (load)+ this part * ratioAvailable
double currentRatio = currentRatioDone + subMeshRatioDone + ratioAvailable + progress0To1 * ratioPerSubMesh;
BackgroundWorker_ProgressChanged(currentRatio, progressMessage, out continueProcessing);
});
currentPlatingRatioDone += ratioPerSubMesh;
subMeshRatioDone += ratioPerSubMesh;
}
}
}
currentRatioDone += ratioPerFile;
currentRatioDone += ratioPerFile;
}
}
}
@ -1281,15 +1288,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
buttonRightPanel.AddChild(viewOptionContainer);
}
autoArrangeButton = whiteButtonFactory.Generate(LocalizedString.Get("Auto-Arrange"), centerText: true);
autoArrangeButton.Cursor = Cursors.Hand;
buttonRightPanel.AddChild(autoArrangeButton);
autoArrangeButton.Visible = false;
autoArrangeButton.Click += (sender, e) =>
{
AutoArrangePartsInBackground();
};
GuiWidget verticalSpacer = new GuiWidget();
verticalSpacer.VAnchor = VAnchor.ParentBottomTop;
buttonRightPanel.AddChild(verticalSpacer);