private void ScaleMeshToView(List<MeshGroup> loadedMeshGroups) { if (loadedMeshGroups != null) { AxisAlignedBoundingBox meshBounds = GetAxisAlignedBoundingBox(loadedMeshGroups); bool done = false; double scallFraction = .1; RectangleDouble goalBounds = new RectangleDouble(0, 0, size.x, size.y); goalBounds.Inflate(-10); while (!done) { RectangleDouble partScreenBounds = GetScreenBounds(meshBounds); if (!NeedsToBeSmaller(partScreenBounds, goalBounds)) { trackballTumbleWidget.TrackBallController.Scale *= (1 + scallFraction); partScreenBounds = GetScreenBounds(meshBounds); // If it crossed over the goal reduct the amount we are adjusting by. if (NeedsToBeSmaller(partScreenBounds, goalBounds)) { scallFraction /= 2; } } else { trackballTumbleWidget.TrackBallController.Scale *= (1 - scallFraction); partScreenBounds = GetScreenBounds(meshBounds); // If it crossed over the goal reduct the amount we are adjusting by. if (!NeedsToBeSmaller(partScreenBounds, goalBounds)) { scallFraction /= 2; if (scallFraction < .001) { done = true; } } } } } }
public void SavingFunction() { currentlySaving = true; countThatHaveBeenSaved = 0; // first create images for all the parts foreach (FileNameAndPresentationName stlFileNames in stlFilesToPrint) { Mesh loadedMesh = StlProcessing.Load(stlFileNames.fileName); if (loadedMesh != null) { AxisAlignedBoundingBox aabb = loadedMesh.GetAxisAlignedBoundingBox(); RectangleDouble bounds2D = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y); double widthInMM = bounds2D.Width + PartMarginMM * 2; double textSpaceMM = 5; double heightMM = textSpaceMM + bounds2D.Height + PartMarginMM * 2; TypeFacePrinter typeFacePrinter = new TypeFacePrinter(stlFileNames.presentationName, 28, Vector2.Zero, Justification.Center, Baseline.BoundsCenter); double sizeOfNameX = typeFacePrinter.GetSize().x + PartMarginPixels * 2; Vector2 sizeOfRender = new Vector2(widthInMM * PixelPerMM, heightMM * PixelPerMM); ImageBuffer imageOfPart = new ImageBuffer((int)(Math.Max(sizeOfNameX, sizeOfRender.x)), (int)(sizeOfRender.y), 32, new BlenderBGRA()); typeFacePrinter.Origin = new Vector2(imageOfPart.Width / 2, (textSpaceMM / 2) * PixelPerMM); Graphics2D partGraphics2D = imageOfPart.NewGraphics2D(); RectangleDouble rectBounds = new RectangleDouble(0, 0, imageOfPart.Width, imageOfPart.Height); double strokeWidth = .5 * PixelPerMM; rectBounds.Inflate(-strokeWidth / 2); RoundedRect rect = new RoundedRect(rectBounds, PartMarginMM * PixelPerMM); partGraphics2D.Render(rect, RGBA_Bytes.LightGray); Stroke rectOutline = new Stroke(rect, strokeWidth); partGraphics2D.Render(rectOutline, RGBA_Bytes.DarkGray); PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh, new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, RGBA_Bytes.Black); partGraphics2D.Render(typeFacePrinter, RGBA_Bytes.Black); partImagesToPrint.Add(new PartImage(imageOfPart)); } countThatHaveBeenSaved++; if (UpdateRemainingItems != null) { UpdateRemainingItems(this, new StringEventArgs(Path.GetFileName(stlFileNames.presentationName))); } } partImagesToPrint.Sort(BiggestToLittlestImages); PdfDocument document = new PdfDocument(); document.Info.Title = "MatterHackers Parts Sheet"; document.Info.Author = "MatterHackers Inc."; document.Info.Subject = "This is a list of the parts that are in a queue from MatterControl."; document.Info.Keywords = "MatterControl, STL, 3D Printing"; int nextPartToPrintIndex = 0; int plateNumber = 1; bool done = false; while (!done && nextPartToPrintIndex < partImagesToPrint.Count) { PdfPage pdfPage = document.AddPage(); CreateOnePage(plateNumber++, ref nextPartToPrintIndex, pdfPage); } try { // save the final document document.Save(pathAndFileToSaveTo); // Now try and open the document. This will lanch whatever PDF viewer is on the system and ask it // to show the file (at least on Windows). Process.Start(pathAndFileToSaveTo); } catch (Exception) { } OnDoneSaving(); currentlySaving = false; }
private void CreateBase(List<MeshGroup> meshesList, List<Matrix4X4> meshTransforms, List<PlatingMeshGroupData> platingDataList) { if (meshesList.Count > 0) { AxisAlignedBoundingBox bounds = meshesList[0].GetAxisAlignedBoundingBox(meshTransforms[0]); for (int i = 1; i < meshesList.Count; i++) { bounds = AxisAlignedBoundingBox.Union(bounds, meshesList[i].GetAxisAlignedBoundingBox(meshTransforms[i])); } 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, 1 * roundingScale); Mesh baseMeshResult = VertexSourceToMesh.Extrude(baseRoundedRect, unscaledBaseHeight / 2 * roundingScale * sizeScrollBar.Value * heightScrollBar.Value); baseMeshResult.Transform(Matrix4X4.CreateScale(1 / roundingScale)); meshesList.Add(new MeshGroup(baseMeshResult)); platingDataList.Add(new PlatingMeshGroupData()); meshTransforms.Add(Matrix4X4.CreateTranslation(0, 0, 0)); PlatingHelper.CreateITraceableForMeshGroup(platingDataList, meshesList, meshesList.Count - 1, null); } }