public void ChangePartColor(PartColors color) { for (int i = Viewport.Children.Count - 1; i >= 0; i--) { Part3D p = Viewport.Children[i] as Part3D; if (p == null) { continue; } p.PartColor = color; } }
public void ShowLines(bool value) { for (int i = Viewport.Children.Count - 1; i >= 0; i--) { Part3D p = Viewport.Children[i] as Part3D; if (p == null) { continue; } p.ShowLines = value; } }
//public void CalculateDomeValues() { // List<Point3D> parts = new List<Point3D>(); // double radius = (MainWindowVM.ParametersVM.DomeDiameter * ScaleWidth) / 2; // double height = MainWindowVM.ParametersVM.DomeHeight * ScaleWidth; // for (double x = -radius; x < radius + 1; x += ScaleWidth) // for (double z = -radius; z <= radius; z += ScaleWidth) { // //Assume height is zero // double y = 0; // //distanceFromOrgin is the distance from the origin // //the distance from the origin to your point is the hypotenuse of a right triangle! // double distanceFromOrgin = Math.Sqrt(x * x + z * z); // //if (rbCircularBase.IsChecked.Value) { // double rEdge = radius; // //} // if (distanceFromOrgin <= rEdge) { // y = CalculateHeight(rEdge, radius, distanceFromOrgin, height); // //y = Convert.ToInt32( Math.Sqrt(radius * radius - distanceFromOrgin * distanceFromOrgin)); // } // if (y <= 0) continue; // // Snap to the closest lego plate. // //if (y % ScaleHeight < ScaleHeight / 2) // // y = y - y % ScaleHeight; // Snap at the lower point // //else // // y = y + (ScaleHeight - y%ScaleHeight); // snap at the higher point as it more that half from the cen // parts.Add(new Point3D(x, y, z)); // } // //DomeValues = parts; //} #region Public Values public void CalculateDomeValues() { // remove all the existing parts. ClearViewport(); DataTable dt = MainWindowVM.Dome2DVM.DomeValues; int diameter = MainWindowVM.ParametersVM.DomeDiameter; //int radius = diameter/2; for (int x = 0; x < diameter; x++) { for (int z = 0; z < diameter; z++) { DataRow drPrev = null, drNext = null; List <int> neighbours = new List <int>(); int noOfPlates; // Get the rows from the datatable. DataRow drCurrent = dt.Rows[x]; if (x > 0) { drPrev = dt.Rows[x - 1]; } if (x < dt.Rows.Count - 1) { drNext = dt.Rows[x + 1]; } int currentHeight = Convert.ToInt16(drCurrent[z]); // Fill all the values from the surrounding neighbours. FillNeighbours(diameter, z, drCurrent, neighbours); if (drPrev != null) { FillNeighbours(dt.Rows.Count, z, drPrev, neighbours); } if (drNext != null) { FillNeighbours(dt.Rows.Count, z, drNext, neighbours); } // Gets the lowest values on the top. neighbours.Sort(); // no of viewable plates. if (drNext == null || drPrev == null || z == 0 || z == (diameter - 1)) // if dome edges then show all the plates. { noOfPlates = currentHeight; } else if (currentHeight == neighbours[0] && currentHeight > 0) // If lowest neighbours is of the current height then add only one plate. { noOfPlates = 1; } else { noOfPlates = currentHeight - neighbours[0]; // no need the show all the plate. Just show the 'viewable' plates. } int y = (currentHeight - noOfPlates) * (int)ScaleHeight; for (int i = 0; i < noOfPlates; i++, y += (int)ScaleHeight) { Point3D pt = new Point3D(x * ScaleWidth, y, z * ScaleWidth); PartColors color = (PartColors)Enum.Parse(typeof(PartColors), MainWindowVM.ColorChooserVM.CurrentColor.Name); Part3D part = new Part3D(PLATE_PART_CODE, PLATE_PART_CODE, color) { Position = pt }; //part.ShowLines = true; Viewport.Children.Add(part); } } } }