public ScaleMatrixEdgeControl(IObject3DControlContext context, int edgeIndex) : base(context) { theme = MatterControl.AppContext.Theme; xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), }; xValueDisplayInfo.EditComplete += EditComplete; xValueDisplayInfo.VisibleChanged += (s, e) => { if (!xValueDisplayInfo.Visible) { hadClickOnControl = false; } }; yValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; yValueDisplayInfo.EditComplete += EditComplete; yValueDisplayInfo.VisibleChanged += (s, e) => { if (!yValueDisplayInfo.Visible) { hadClickOnControl = false; } }; if (edgeIndex % 2 == 1) { Object3DControlContext.GuiSurface.AddChild(xValueDisplayInfo); } else { Object3DControlContext.GuiSurface.AddChild(yValueDisplayInfo); } this.edgeIndex = edgeIndex; DrawOnTop = true; minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize); CollisionVolume = minXminYMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public SliceLayerSelector(PrinterConfig printer, BedConfig sceneContext) { var theme = ApplicationController.Instance.Theme; this.sceneContext = sceneContext; this.AddChild(layerScrollbar = new LayerScrollbar(printer, sceneContext) { VAnchor = VAnchor.Stretch, HAnchor = HAnchor.Right }); layerSlider = layerScrollbar.layerSlider; var tagContainer = new HorizontalTag() { HAnchor = HAnchor.Fit | HAnchor.Right, VAnchor = VAnchor.Fit, Padding = new BorderDouble(6, 4, 10, 4), Margin = new BorderDouble(right: layerScrollbar.Width + layerScrollbar.Margin.Width), TagColor = (theme.Colors.IsDarkTheme) ? theme.Shade : theme.SlightShade }; currentLayerInfo = new InlineEditControl("1000") { Name = "currentLayerInfo", TextColor = theme.Colors.PrimaryTextColor, GetDisplayString = (value) => $"{value}", HAnchor = HAnchor.Right | HAnchor.Fit, VAnchor = VAnchor.Absolute | VAnchor.Fit, }; currentLayerInfo.EditComplete += (s, e) => { layerScrollbar.Value = currentLayerInfo.Value - 1; }; tagContainer.AddChild(currentLayerInfo); this.AddChild(tagContainer); currentLayerInfo.Visible = true; layerInfoHalfHeight = currentLayerInfo.Height / 2; currentLayerInfo.Visible = false; layerSlider.ValueChanged += (s, e) => { currentLayerInfo.StopEditing(); currentLayerInfo.Position = new Vector2(0, (double)(layerSlider.Position.Y + layerSlider.PositionPixelsFromFirstValue - layerInfoHalfHeight)); }; // Set initial position currentLayerInfo.Position = new Vector2(0, (double)(layerSlider.Position.Y + layerSlider.PositionPixelsFromFirstValue - layerInfoHalfHeight)); sceneContext.ActiveLayerChanged += SetPositionAndValue; layerScrollbar.MouseEnter += SetPositionAndValue; }
public ScaleCornerControl(IInteractionVolumeContext context, int cornerIndex) : base(context) { theme = MatterControl.AppContext.Theme; xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}mm".FormatWith(value), }; xValueDisplayInfo.EditComplete += EditComplete; xValueDisplayInfo.VisibleChanged += (s, e) => { if (!xValueDisplayInfo.Visible) { HadClickOnControl = false; } }; yValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}mm".FormatWith(value) }; yValueDisplayInfo.EditComplete += EditComplete; yValueDisplayInfo.VisibleChanged += (s, e) => { if (!yValueDisplayInfo.Visible) { HadClickOnControl = false; } }; InteractionContext.GuiSurface.AddChild(xValueDisplayInfo); InteractionContext.GuiSurface.AddChild(yValueDisplayInfo); this.quadrantIndex = cornerIndex; DrawOnTop = true; minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize); CollisionVolume = minXminYMesh.CreateBVHData(); InteractionContext.GuiSurface.AfterDraw += InteractionLayer_AfterDraw; }
public MoveInZControl(IInteractionVolumeContext context) : base(context) { theme = AppContext.Theme; Name = "MoveInZControl"; zHeightDisplayInfo = new InlineEditControl() { ForceHide = () => { var selectedItem = RootSelection; // if the selection changes if (selectedItem != ActiveSelectedItem) { return(true); } // if another control gets a hover if (InteractionContext.HoveredInteractionVolume != this && InteractionContext.HoveredInteractionVolume != null) { return(true); } // if we clicked on the control if (HadClickOnControl) { return(false); } return(false); } , GetDisplayString = (value) => "{0:0.0#}mm".FormatWith(value) }; zHeightDisplayInfo.VisibleChanged += (s, e) => { if (!zHeightDisplayInfo.Visible) { HadClickOnControl = false; } }; zHeightDisplayInfo.EditComplete += (s, e) => { var selectedItem = RootSelection; Matrix4X4 startingTransform = selectedItem.Matrix; var newZPosition = zHeightDisplayInfo.Value; if (InteractionContext.SnapGridDistance > 0) { // snap this position to the grid double snapGridDistance = InteractionContext.SnapGridDistance; // snap this position to the grid newZPosition = ((int)((newZPosition / snapGridDistance) + .5)) * snapGridDistance; } AxisAlignedBoundingBox originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(); var moveAmount = newZPosition - originalSelectedBounds.MinXYZ.Z; if (moveAmount != 0) { selectedItem.Matrix = selectedItem.Matrix * Matrix4X4.CreateTranslation(0, 0, moveAmount); Invalidate(); } context.Scene.AddTransformSnapshot(startingTransform); }; InteractionContext.GuiSurface.AddChild(zHeightDisplayInfo); DrawOnTop = true; using (Stream arrowStream = AggContext.StaticData.OpenStream(Path.Combine("Stls", "up_pointer.stl"))) { upArrowMesh = StlProcessing.Load(arrowStream, CancellationToken.None); } CollisionVolume = upArrowMesh.CreateBVHData(); InteractionContext.GuiSurface.AfterDraw += InteractionLayer_AfterDraw; }
public ScaleWidthDepthCornerControl(IObject3DControlContext object3DControlContext, Func <double> getWidth, Action <double> setWidth, Func <double> getDepth, Action <double> setDepth, Func <double> getHeight, Action <double> setHeight, int quadrant) : base(object3DControlContext) { theme = MatterControl.AppContext.Theme; this.getWidth = getWidth; this.setWidth = setWidth; this.getDepth = getDepth; this.setDepth = setDepth; this.getHeight = getHeight; this.setHeight = setHeight; scaleController = new ScaleController(object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight); xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), }; xValueDisplayInfo.EditComplete += EditComplete; xValueDisplayInfo.VisibleChanged += (s, e) => { if (!xValueDisplayInfo.Visible) { hadClickOnControl = false; } }; yValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; yValueDisplayInfo.EditComplete += EditComplete; yValueDisplayInfo.VisibleChanged += (s, e) => { if (!yValueDisplayInfo.Visible) { hadClickOnControl = false; } }; Object3DControlContext.GuiSurface.AddChild(xValueDisplayInfo); Object3DControlContext.GuiSurface.AddChild(yValueDisplayInfo); this.quadrantIndex = quadrant; DrawOnTop = true; minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize); CollisionVolume = minXminYMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public RotateCornerControl(IInteractionVolumeContext context, int axisIndex) : base(context) { angleTextControl = new InlineEditControl() { ForceHide = ForceHideAngle, GetDisplayString = (value) => "{0:0.0#}°".FormatWith(value) }; angleTextControl.VisibleChanged += (s, e) => { mouseDownInfo = null; Invalidate(); }; InteractionContext.GuiSurface.AddChild(angleTextControl); angleTextControl.Visible = false; angleTextControl.EditComplete += (s, e) => { var selectedItem = RootSelection; if (selectedItem != null && mouseDownInfo != null) { if (mouseMoveInfo != null) { SnappedRotationAngle = MathHelper.DegreesToRadians(angleTextControl.Value); mouseMoveInfo.AngleOfHit = mouseDownInfo.AngleOfHit + SnappedRotationAngle; rotatingCW = DeltaAngle(0, SnappedRotationAngle) < 0; // undo the last rotation RotateAroundAxis(selectedItem, -lastSnappedRotation); // rotate it RotateAroundAxis(selectedItem, SnappedRotationAngle); Invalidate(); lastSnappedRotation = SnappedRotationAngle; } InteractionContext.Scene.AddTransformSnapshot(mouseDownInfo.SelectedObjectTransform); } }; this.RotationAxis = axisIndex; DrawOnTop = true; rotationHandle = PlatonicSolids.CreateCube(selectCubeSize); RectangleDouble bounds = arrows.GetBounds(); if (rotationImageWhite == null) { rotationImageWhite = new ImageBuffer(64, 64, 32, new BlenderBGRA()); } VertexSourceApplyTransform arrows2 = new VertexSourceApplyTransform(arrows, Affine.NewTranslation(-bounds.Center) * Affine.NewScaling(rotationImageWhite.Width / bounds.Width, rotationImageWhite.Height / bounds.Height) * Affine.NewTranslation(rotationImageWhite.Width / 2, rotationImageWhite.Height / 2)); Graphics2D imageGraphics = rotationImageWhite.NewGraphics2D(); imageGraphics.Clear(new Color(Color.White, 0)); imageGraphics.Render(new FlattenCurves(arrows2), Color.White); ImageBuffer clearImage = new ImageBuffer(2, 2, 32, new BlenderBGRA()); for (int i = 0; i < rotationHandle.Faces.Count; i++) { if (i == 0 || i == 1) { rotationHandle.PlaceTextureOnFace(i, rotationImageWhite); } else { rotationHandle.PlaceTextureOnFace(i, clearImage); } } CollisionVolume = rotationHandle.CreateTraceData(); InteractionContext.GuiSurface.AfterDraw += InteractionLayer_AfterDraw; }
public ScaleTopControl(IInteractionVolumeContext context) : base(context) { zValueDisplayInfo = new InlineEditControl() { ForceHide = () => { // if the selection changes if (RootSelection != ActiveSelectedItem) { return(true); } // if another control gets a hover if (InteractionContext.HoveredInteractionVolume != this && InteractionContext.HoveredInteractionVolume != null) { return(true); } // if we clicked on the control if (HadClickOnControl) { return(false); } return(false); } , GetDisplayString = (value) => "{0:0.0}mm".FormatWith(value) }; zValueDisplayInfo.VisibleChanged += (s, e) => { if (!zValueDisplayInfo.Visible) { HadClickOnControl = false; } }; zValueDisplayInfo.EditComplete += (s, e) => { var selectedItem = ActiveSelectedItem; Matrix4X4 startingTransform = selectedItem.Matrix; var originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); Vector3 topPosition = GetTopPosition(selectedItem); Vector3 lockedBottom = new Vector3(topPosition.X, topPosition.Y, originalSelectedBounds.MinXYZ.Z); Vector3 newSize = Vector3.Zero; newSize.Z = zValueDisplayInfo.Value; Vector3 scaleAmount = ScaleCornerControl.GetScalingConsideringShiftKey(originalSelectedBounds, mouseDownSelectedBounds, newSize, InteractionContext.GuiSurface.ModifierKeys); Matrix4X4 scale = Matrix4X4.CreateScale(scaleAmount); selectedItem.Matrix = selectedItem.ApplyAtBoundsCenter(scale); // and keep the locked edge in place AxisAlignedBoundingBox scaledSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity); Vector3 newLockedBottom = new Vector3(topPosition.X, topPosition.Y, scaledSelectedBounds.MinXYZ.Z); selectedItem.Matrix *= Matrix4X4.CreateTranslation(lockedBottom - newLockedBottom); Invalidate(); InteractionContext.Scene.AddTransformSnapshot(startingTransform); }; InteractionContext.GuiSurface.AddChild(zValueDisplayInfo); DrawOnTop = true; topScaleMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize); CollisionVolume = topScaleMesh.CreateTraceData(); InteractionContext.GuiSurface.AfterDraw += InteractionLayer_AfterDraw; }
public ScaleHeightControl(IObject3DControlContext context, Func <double> getWidth, Action <double> setWidth, Func <double> getDepth, Action <double> setDepth, Func <double> getHeight, Action <double> setHeight, List <Func <double> > getDiameters = null, List <Action <double> > setDiameters = null) : base(context) { theme = MatterControl.AppContext.Theme; this.getWidth = getWidth; this.setWidth = setWidth; this.getDepth = getDepth; this.setDepth = setDepth; this.getHeight = getHeight; this.setHeight = setHeight; this.getDiameters = getDiameters; this.setDiameters = setDiameters; scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, getDiameters, setDiameters); heightValueDisplayInfo = new InlineEditControl() { ForceHide = () => { // if the selection changes if (RootSelection != activeSelectedItem) { return(true); } // if another control gets a hover if (Object3DControlContext.HoveredObject3DControl != this && Object3DControlContext.HoveredObject3DControl != null) { return(true); } // if we clicked on the control if (hadClickOnControl) { return(false); } return(false); }, GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; heightValueDisplayInfo.VisibleChanged += (s, e) => { if (!heightValueDisplayInfo.Visible) { hadClickOnControl = false; } }; heightValueDisplayInfo.EditComplete += async(s, e) => { if (heightValueDisplayInfo.Value == scaleController.FinalState.Height) { return; } var selectedItem = activeSelectedItem; var bottom = GetBottomPosition(selectedItem); scaleController.ScaleHeight(heightValueDisplayInfo.Value); await selectedItem.Rebuild(); var postScaleBottom = GetBottomPosition(selectedItem); selectedItem.Translate(bottom - postScaleBottom); scaleController.EditComplete(); scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight, getDiameters, setDiameters); }; Object3DControlContext.GuiSurface.AddChild(heightValueDisplayInfo); DrawOnTop = true; topScaleMesh = PlatonicSolids.CreateCube(arrowSize, arrowSize, arrowSize); CollisionVolume = topScaleMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public ScaleHeightControl(IObject3DControlContext context) : base(context) { theme = AppContext.Theme; heightValueDisplayInfo = new InlineEditControl() { ForceHide = () => { // if the selection changes if (RootSelection != activeSelectedItem) { return(true); } // if another control gets a hover if (Object3DControlContext.HoveredObject3DControl != this && Object3DControlContext.HoveredObject3DControl != null) { return(true); } // if we clicked on the control if (hadClickOnControl) { return(false); } return(false); }, GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; heightValueDisplayInfo.VisibleChanged += (s, e) => { if (!heightValueDisplayInfo.Visible) { hadClickOnControl = false; } }; heightValueDisplayInfo.EditComplete += async(s, e) => { var selectedItem = activeSelectedItem; if (selectedItem is IObjectWithHeight heightObject && heightValueDisplayInfo.Value != heightObject.Height) { await selectedItem.Rebuild(); Invalidate(); SetHeightUndo(heightValueDisplayInfo.Value, heightObject.Height); } }; Object3DControlContext.GuiSurface.AddChild(heightValueDisplayInfo); DrawOnTop = true; topScaleMesh = PlatonicSolids.CreateCube(arrowSize, arrowSize, arrowSize); CollisionVolume = topScaleMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public ScaleHeightControl(IObject3DControlContext context) : base(context) { theme = AppContext.Theme; zValueDisplayInfo = new InlineEditControl() { ForceHide = () => { // if the selection changes if (RootSelection != activeSelectedItem) { return(true); } // if another control gets a hover if (Object3DControlContext.HoveredObject3DControl != this && Object3DControlContext.HoveredObject3DControl != null) { return(true); } // if we clicked on the control if (hadClickOnControl) { return(false); } return(false); }, GetDisplayString = (value) => "{0:0.0}".FormatWith(value) }; zValueDisplayInfo.VisibleChanged += (s, e) => { if (!zValueDisplayInfo.Visible) { hadClickOnControl = false; } }; zValueDisplayInfo.EditComplete += (s, e) => { var selectedItem = activeSelectedItem; if (selectedItem is IObjectWithHeight heightObject) { var startingHeight = heightObject.Height; var originalSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(); Vector3 topPosition = GetTopPosition(selectedItem); var lockedBottom = GetBottomPosition(selectedItem); Vector3 newSize = Vector3.Zero; newSize.Z = zValueDisplayInfo.Value; Vector3 scaleAmount = ScaleCornerControl.GetScalingConsideringShiftKey(originalSelectedBounds, mouseDownSelectedBounds, newSize, Object3DControlContext.GuiSurface.ModifierKeys); heightObject.Height *= scaleAmount.Z; var scale = Matrix4X4.CreateScale(scaleAmount); Invalidate(); SetHeightUndo(startingHeight); } }; Object3DControlContext.GuiSurface.AddChild(zValueDisplayInfo); DrawOnTop = true; topScaleMesh = PlatonicSolids.CreateCube(arrowSize, arrowSize, arrowSize); CollisionVolume = topScaleMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public ScaleDiameterControl(IObject3DControlContext context, Func <double> getHeight, Action <double> setHeight, List <Func <double> > getDiameters, List <Action <double> > setDiameters, int diameterIndex, ObjectSpace.Placement placement = ObjectSpace.Placement.Bottom, Func <bool> controlVisible = null, double angleOffset = 0) : base(context) { this.getHeight = getHeight; this.setHeight = setHeight; this.getDiameters = getDiameters; this.setDiameters = setDiameters; this.controlVisible = controlVisible; this.placement = placement; this.diameterIndex = diameterIndex; this.angleOffset = angleOffset; theme = MatterControl.AppContext.Theme; scaleController = new ScaleController(Object3DControlContext, null, null, null, null, getHeight, setHeight, getDiameters, setDiameters); diameterValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), }; diameterValueDisplayInfo.EditComplete += async(s, e) => { var newDiameter = diameterValueDisplayInfo.Value != 0 ? diameterValueDisplayInfo.Value : getDiameters[diameterIndex](); if (newDiameter == scaleController.FinalState.Diameters[diameterIndex]) { return; } Vector3 lockedEdge = ObjectSpace.GetCenterPosition(ActiveSelectedItem, placement); scaleController.ScaleDiameter(newDiameter, diameterIndex); await ActiveSelectedItem.Rebuild(); // and keep the locked edge in place Vector3 newLockedEdge = ObjectSpace.GetCenterPosition(ActiveSelectedItem, placement); ActiveSelectedItem.Translate(lockedEdge - newLockedEdge); scaleController.EditComplete(); scaleController = new ScaleController(Object3DControlContext, null, null, null, null, getHeight, setHeight, getDiameters, setDiameters); }; diameterValueDisplayInfo.VisibleChanged += (s, e) => { if (!diameterValueDisplayInfo.Visible) { hadClickOnControl = false; } }; Object3DControlContext.GuiSurface.AddChild(diameterValueDisplayInfo); DrawOnTop = true; grabControlMesh = SphereObject3D.CreateSphere(grabControlSize, 15, 10); CollisionVolume = grabControlMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }
public ScaleWidthDepthEdgeControl(IObject3DControlContext context, Func <double> getWidth, Action <double> setWidth, Func <double> getDepth, Action <double> setDepth, Func <double> getHeight, Action <double> setHeight, int edgeIndex) : base(context) { theme = MatterControl.AppContext.Theme; switch (edgeIndex) { case 0: Name = "ScaleDepthBack"; break; case 1: Name = "ScaleWidthLeft"; break; case 2: Name = "ScaleDepthFront"; break; case 3: Name = "ScaleWidthRight"; break; } this.getWidth = getWidth; this.setWidth = setWidth; this.getDepth = getDepth; this.setDepth = setDepth; this.getHeight = getHeight; this.setHeight = setHeight; scaleController = new ScaleController(Object3DControlContext, getWidth, setWidth, getDepth, setDepth, getHeight, setHeight); xValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), Name = "XValueDisplay", }; xValueDisplayInfo.EditComplete += EditComplete; xValueDisplayInfo.VisibleChanged += (s, e) => { if (!xValueDisplayInfo.Visible) { hadClickOnControl = false; } }; yValueDisplayInfo = new InlineEditControl() { ForceHide = ForceHideScale, GetDisplayString = (value) => "{0:0.0}".FormatWith(value), Name = "YValueDisplay", }; yValueDisplayInfo.EditComplete += EditComplete; yValueDisplayInfo.VisibleChanged += (s, e) => { if (!yValueDisplayInfo.Visible) { hadClickOnControl = false; } }; if (edgeIndex % 2 == 1) { Object3DControlContext.GuiSurface.AddChild(xValueDisplayInfo); } else { Object3DControlContext.GuiSurface.AddChild(yValueDisplayInfo); } this.edgeIndex = edgeIndex; DrawOnTop = true; minXminYMesh = PlatonicSolids.CreateCube(selectCubeSize, selectCubeSize, selectCubeSize); CollisionVolume = minXminYMesh.CreateBVHData(); Object3DControlContext.GuiSurface.BeforeDraw += Object3DControl_BeforeDraw; }