private void DrawIntersectionInWindow() { var selected = models.Where(x => x.IsSelected && x is GeometryModels.CuttingCurve).ToList(); if (selected.Count != 1) { var sampleMessageDialog = new MessageHost { Message = { Text = "Select one curve to draw." } }; DialogHost.Show(sampleMessageDialog, "RootDialog"); } else { var bufferBitmap = new WriteableBitmap(400, 200, 96, 96, PixelFormats.Pbgra32, null); var curve = selected[0] as GeometryModels.CuttingCurve; curve?.Draw(bufferBitmap); var sampleMessageDialog = new ImageHost(); sampleMessageDialog.SetImage(bufferBitmap); var oldWidth = Host.Width; var oldHeigth = Host.Height; Host.Height = 350; Host.Width = 400; DialogHost.Show(sampleMessageDialog, "RootDialog"); Host.Width = oldWidth; Host.Height = oldHeigth; } }
/// <summary> /// Processes the specified exception specified /// </summary> /// <param name="Item">The exception to process</param> /// <returns>The transformed exception</returns> private Exception ResolveException(Exception Item) { if (Item == null) { return(Item); } string lowTypeName = Item.GetType().FullName.ToLower(); if (MessageHost.ExceptionTransforms.ContainsKey(lowTypeName)) { try { return((Exception)InvokeCommand.InvokeScript(false, ScriptBlock.Create(MessageHost.ExceptionTransforms[lowTypeName].ToString()), null, Item)[0].BaseObject); } catch (Exception e) { MessageHost.WriteTransformError(new ErrorRecord(e, "Write-PSFMessage", ErrorCategory.OperationStopped, null), FunctionName, ModuleName, Item, TransformType.Exception, System.Management.Automation.Runspaces.Runspace.DefaultRunspace.InstanceId); return(Item); } } TransformCondition transform = MessageHost.ExceptionTransformList.Get(lowTypeName, ModuleName, FunctionName); if (transform != null) { try { return((Exception)InvokeCommand.InvokeScript(false, ScriptBlock.Create(transform.ScriptBlock.ToString()), null, Item)[0].BaseObject); } catch (Exception e) { MessageHost.WriteTransformError(new ErrorRecord(e, "Write-PSFMessage", ErrorCategory.OperationStopped, null), FunctionName, ModuleName, Item, TransformType.Exception, System.Management.Automation.Runspaces.Runspace.DefaultRunspace.InstanceId); return(Item); } } return(Item); }
private void CreateBSplineInterpolator() { if (GetFilteredSelected().Count() < 2) { var sampleMessageDialog = new MessageHost { Message = { Text = "Not enough points for BSpline interpolation (at least 2)." } }; DialogHost.Show(sampleMessageDialog, "RootDialog"); } else { AddNewModel(new BsplineInterpolator(GetFilteredSelected(), this)); } }
private void CreateBezierC2() { if (GetFilteredSelected().Count() < 4) { var sampleMessageDialog = new MessageHost { Message = { Text = "Not enough points for C2 Bezier Curve (at least 4)." } }; DialogHost.Show(sampleMessageDialog, "RootDialog"); } else { AddNewModel(new BezierC2(GetFilteredSelected(), this)); } }
private void CreateGregoryPatch() { var selectedPoints = GetPoints().Where(x => x.IsSelected).ToList(); var patches = Models.Where(x => x is BezierPatch).Cast <BezierPatch>().Where(x => x.ContainsTwoInCorners(selectedPoints)).ToList(); var pts = selectedPoints.Where(x => { int counter = 0; patches.ForEach(y => { if (y.ContainsInCorner(x)) { counter++; } }); return(counter >= 2); }) .ToList(); PatchCycle cycle; try { cycle = CreatePatchCycle(pts, patches); } catch (Exception) { cycle = null; } if (cycle == null) { var sampleMessageDialog = new MessageHost { Message = { Text = "Selected points and their patches does not create proper cycle." } }; DialogHost.Show(sampleMessageDialog, "RootDialog"); } else { AddNewModel(new GregoryPatch(cycle, this)); } }
private void IntersectSurfaces() { List <Vector4> intersection = null; IIntersectable first = null; IIntersectable second = null; bool cyclic = false; try { var selected = models.Where(x => x.IsSelected).ToList(); var sel = selected.Select(x => x as IIntersectable).Distinct().ToList(); if (sel.Count == 2) { first = sel[0]; second = sel[1]; if (first != null && second != null) { intersection = Intersection.Intersect(sel[0], sel[1], this, NewtonStep, out cyclic); } } } catch (Exception e) { intersection = null; } if (intersection != null && intersection.Count > 2) { //intersection.ForEach(x => CreateHiddenCatPoint(sel[0].GetPosition(x.X, x.Y))); var curv = new GeometryModels.CuttingCurve(intersection, first, second, this, cyclic, CuttingCurveApproximation); AddNewModel(curv); first.SetCuttingCurve(curv); second.SetCuttingCurve(curv); } else { var sampleMessageDialog = new MessageHost { Message = { Text = "Proper intersection could not be found." } }; DialogHost.Show(sampleMessageDialog, "RootDialog"); } }