private Material SetMaterial(PartColors materialColor) { PartColor pc = KnownPartColors.GetColor(materialColor); //SolidColorBrush sb = new SolidColorBrush(color.Color); //if (color.Alpha > 0) // sb.Opacity = color.Alpha / 255.0; return(new DiffuseMaterial(pc.Color)); }
private void ChangePartColor(object color) { PartColors pc = LDrawPartLib.PartColors.Blue; try { pc = (PartColors)Enum.Parse(typeof(PartColors), color.ToString()); } catch { } CurrentColor = KnownPartColors.GetColor(pc); MainWindowVM.Dome3DVM.ChangePartColor(pc); }
public static PartColor GetColor(PartColors color) { PartColor c; try { c = Colors[(int)color]; } catch (Exception) { c = GetColor(PartColors.Black); } return(c); }
public PartUI(string partNumber, string description, PartColors color) { Id = Guid.NewGuid(); ParentId = Guid.Empty; PartColor = color; // Get the instance of Visual3DCollection //_children = (Visual3DCollection)typeof(Visual3DCollection).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, // new[] { typeof(Visual3D) }, null).Invoke(new object[] { this }); PartDescription = description; PartNumber = partNumber.Trim(); }
public static PartColor GetColor(PartColors color) { PartColor c = null; try { c = KnownPartColors.Colors[(int)color]; } catch (Exception) { c = KnownPartColors.GetColor(PartColors.Black); } return(c); }
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; } }
private void CreateSubpart(bool invertNext, string line, Matrix3D matrix, Model3DGroup partModels, PartColors currentColor) { SubfileCommand s = new SubfileCommand(line); Matrix3D subMat = s.Matrix; subMat.Scale(new Vector3D(matrix.M11, matrix.M22, matrix.M33)); subMat.Translate(new Vector3D(matrix.OffsetX, matrix.OffsetY, matrix.OffsetZ)); PartColors color = (s.Color == PartColors.Current) ? currentColor : s.Color; GeneratePartMesh(s.FileName, invertNext, subMat, partModels, color); //if (s.Color == PartColors.Current) // GeneratePartMesh(s.FileName, invertNext, subMat, partModels, currentColor); //else // GeneratePartMesh(s.FileName, invertNext, subMat, partModels, s.Color); // Reset in invert for the next sub file. //invertNext = false; }
private void GeneratePartMesh(string fileName, bool invertNext, Matrix3D matrix, Model3DGroup partModels, PartColors currentColor) { MeshGeometry3D mesh; Winding direction = Winding.CCW; // If the part color is the same as the main color then re-use the mesh other wise create a new one. // This will happen only if the part has two colors like windows & doors with glasses. if (currentColor != PartColor) { mesh = new MeshGeometry3D(); } else { mesh = (MeshGeometry3D)((GeometryModel3D)partModels.Children[0]).Geometry; } string[] info = LDrawHelper.ReadFile(fileName); foreach (string currentLine in info) { string line = currentLine.Trim(); // if line is blank then ignore. if (line.Length == 0) { continue; } char startsWith = line[0]; switch (startsWith) { case '0': // Comment/Meta Commands MetaCommand cmd = new MetaCommand(line); if (cmd.Type == MetaCommandType.BFC) { if (cmd.Commands[1] != null) { direction = (Winding)Enum.Parse(typeof(Winding), cmd.Commands[1]); } if (!invertNext) { Boolean.TryParse(cmd.Commands[3], out invertNext); } } break; case '1': // Sub Part CreateSubpart(invertNext, line, matrix, partModels, currentColor); break; case '2': // Line CreateLine(matrix, line); break; case '3': // Triangle CreateTriangle(invertNext, direction, line, matrix, mesh); break; case '4': // Quadlilateral CreateQuad(invertNext, direction, line, matrix, mesh); break; } } if (currentColor != PartColor && mesh.Positions.Count > 0) { Material material = SetMaterial(currentColor); GeometryModel3D model = new GeometryModel3D(mesh, material); model.BackMaterial = material; partModels.Children.Add(model); } }
private void SaveXML(bool noReload = false) { XMLView.EndEdit(); //https://stackoverflow.com/questions/37145086/datagridview-remove-empty-rows-button for (int i = XMLView.Rows.Count - 1; i > -1; i--) { DataGridViewRow row = XMLView.Rows[i]; if (!row.IsNewRow && row.Cells[0].Value == null) { XMLView.Rows.RemoveAt(i); } } List <Provider> providerList = new List <Provider>(); List <PartColor> partColorList = new List <PartColor>(); foreach (DataGridViewRow data in XMLView.Rows) { if (data.IsNewRow) { continue; } switch (ListType) { case XMLContentType.ContentProviders: Provider pro = new Provider(); pro.Name = data.Cells[0].Value.ToString(); pro.URL = data.Cells[1].Value.ToString(); pro.Icon = data.Cells[2].Value.ToString(); providerList.Add(pro); break; case XMLContentType.PartColors: PartColor pc = new PartColor(); pc.ColorRawName = data.Cells[0].Value.ToString(); pc.ColorID = Convert.ToInt32(data.Cells[1].Value); pc.ColorRGB = data.Cells[2].Value.ToString(); partColorList.Add(pc); break; default: break; } } //https://stackoverflow.com/questions/2129414/how-to-insert-xml-comments-in-xml-serialization switch (ListType) { case XMLContentType.ContentProviders: ContentProviders providers = new ContentProviders(); providers.Providers = providerList.ToArray(); XmlSerializer ser = new XmlSerializer(typeof(ContentProviders)); using (FileStream fs = new FileStream(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ContentProviderXMLName, FileMode.Create)) { XmlWriter writer = XmlWriter.Create(fs, new XmlWriterSettings { Indent = true }); writer.WriteStartDocument(); writer.WriteComment(GenerateComment("content providers")); ser.Serialize(writer, providers); writer.WriteEndDocument(); writer.Flush(); } break; case XMLContentType.PartColors: PartColors partColors = new PartColors(); partColors.ColorList = partColorList.ToArray(); XmlSerializer ser2 = new XmlSerializer(typeof(PartColors)); using (FileStream fs = new FileStream(GlobalPaths.ConfigDir + "\\" + GlobalPaths.PartColorXMLName, FileMode.Create)) { XmlWriter writer = XmlWriter.Create(fs, new XmlWriterSettings { Indent = true }); writer.WriteStartDocument(); writer.WriteComment(GenerateComment("part colors")); ser2.Serialize(writer, partColors); writer.WriteEndDocument(); writer.Flush(); } break; default: break; } providerList.Clear(); partColorList.Clear(); string fileName = ""; switch (ListType) { case XMLContentType.ContentProviders: fileName = GlobalPaths.ContentProviderXMLName; break; case XMLContentType.PartColors: fileName = GlobalPaths.PartColorXMLName; break; default: break; } if (!noReload) { MessageBox.Show(fileName + " has been saved! The list will now reload.", "XML Content Editor - File Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadXML(ListType); } else { MessageBox.Show(fileName + " has been saved!", "XML Content Editor - File Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//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); } } } }