/// <summary> /// 构造函数 /// </summary> private Color(byte r, byte g, byte b) { _colorMethod = ColorMethod.ByColor; _r = r; _g = g; _b = b; }
// Colors ability animation tiles public void ColorTiles(List <Vector3Int> tiles, ColorMethod method) { if (method == ColorMethod.Cast) { sequence += 1; foreach (Vector3Int tile in tiles) { CastTile(tile); } } }
// Colors a single tile if the area is clear, and returns false if there is an obstruction in the way // Used for Movement Range, Collision with Players, Collision with Water public bool ColorTile(Vector3Int tile, ColorMethod method) { if (method == ColorMethod.Movement) { return(ColorMovementTile(tile)); } else { Debug.LogError("enum ColorMethod not set"); return(false); } }
internal static bool TryParse(string str, out CADColor result) { string[] arr = str.Split(':'); if (arr.Length != 2) { result = CADColor.ByLayer; return(false); } // ColorMethod colorMethod = (ColorMethod)Enum.Parse(typeof(ColorMethod), arr[0], true); // string[] rgb = arr[1].Split(','); if (rgb.Length != 3) { result = CADColor.ByLayer; return(false); } byte red = 0; byte green = 0; byte blue = 0; if (byte.TryParse(rgb[0], out red) && byte.TryParse(rgb[1], out green) && byte.TryParse(rgb[2], out blue)) { result = new CADColor(); result.colorMethod = colorMethod; result.r = red; result.g = green; result.b = blue; return(true); } else { result = CADColor.ByLayer; return(false); } }
public ObjectId CreateALayer(string name, ColorMethod method, short indexColor, LineWeight?lineWeight, string description = null) { var objectId = ObjectId.Null; using (var database = Application.DocumentManager.MdiActiveDocument.Database) { using (var transaction = database.TransactionManager.StartTransaction()) { try { var lyTbl = transaction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable; var sLayerName = name; if (lyTbl != null && !lyTbl.Has(sLayerName)) { using (var lyTblRec = new LayerTableRecord()) { lyTblRec.Color = Color.FromColorIndex(method, indexColor); lyTblRec.Name = sLayerName; lyTblRec.LineWeight = lineWeight ?? LineWeight.LineWeight000; lyTblRec.Description = description ?? ""; transaction.GetObject(database.LayerTableId, OpenMode.ForWrite); lyTbl.Add(lyTblRec); transaction.AddNewlyCreatedDBObject(lyTblRec, true); objectId = lyTblRec.ObjectId; } } transaction.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception) { transaction.Abort(); throw; } } } return(objectId); }
public static ObjectId AddLayer(Database db, string layerName, short LayerColorIndex, string LineTypeName, string Description)//封装添加图层方法 { LayerTable layerTable = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead); if (!layerTable.Has(layerName)) { LayerTableRecord layer = new LayerTableRecord(); layer.Name = layerName; ColorMethod method = ColorMethod.ByLayer; layer.Color = Color.FromColorIndex(method, LayerColorIndex); var lt = (LinetypeTable)db.LinetypeTableId.GetObject(OpenMode.ForRead); LoadLineType(); var id = lt[LineTypeName]; layer.LinetypeObjectId = id; layer.Description = Description; layerTable.UpgradeOpen(); layerTable.Add(layer); db.TransactionManager.AddNewlyCreatedDBObject(layer, true); layer.DowngradeOpen(); } return(layerTable[layerName]); }
/// <summary> /// Команда выводит список точек построения объекта /// </summary> public static string ConvertToSVG(ObjectId[] objIds, double indent, bool isSquareTrimming) { /* "корень" SVG-файла */ XmlDocument document = new XmlDocument(); string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); XmlElement root = CreateSVGRoot(document); /* группа, в которой будут записаны все контуры */ XmlElement group = CreateSVGGroup("g", root, document); /* максимальные и минимальные координаты (для определения размеров отображаемой области) */ double maxX = double.MinValue; double maxY = double.MinValue; double minX = double.MaxValue; double minY = double.MaxValue; /* Запись контура */ for (int i = 0; i < objIds.Length; i++) { StringBuilder sb = new StringBuilder("M"); System.Drawing.Color color; LayerTableRecord layer; /* ПОЛИЛИНИЯ */ if (objIds[i].ObjectClass.DxfName.Equals("LWPOLYLINE")) { XmlElement pathElem = document.CreateElement("path"); using (Transaction transaction = MyPlugin.doc.Database.TransactionManager.StartTransaction()) { Polyline polyline; polyline = transaction.GetObject(objIds[i], OpenMode.ForRead) as Polyline; /* цвет по слою */ ColorMethod colorMethod = polyline.Color.ColorMethod; if (colorMethod == ColorMethod.ByLayer) { layer = transaction.GetObject(polyline.LayerId, OpenMode.ForRead) as LayerTableRecord; color = layer.Color.ColorValue; } else { color = polyline.Color.ColorValue; } int isClockWise = 1; int isLargeArc = 1; double b = polyline.GetBulgeAt(0); double x0 = polyline.GetPoint3dAt(0).X; double y0 = polyline.GetPoint3dAt(0).Y; if (x0 < minX) { minX = x0; } else if (x0 > maxX) { maxX = x0; } if (y0 < minY) { minY = y0; } else if (y0 > maxY) { maxY = y0; } double x1; double y1; sb.Append(" " + x0.ToString() + "," + y0.ToString()); for (int j = 1; j < polyline.NumberOfVertices; j++) { x1 = polyline.GetPoint3dAt(j).X; y1 = polyline.GetPoint3dAt(j).Y; if (b == 0) { sb.Append(" L " + x1.ToString() + "," + y1.ToString()); } else { if (b < 0) { isClockWise = 0; b = b * (-1); } else { isClockWise = 1; } if (b < 1) { isLargeArc = 0; } else { isLargeArc = 1; } double angle = 4 * Math.Atan(b); double d = Math.Sqrt(Math.Pow(x1 - x0, 2) + Math.Pow(y1 - y0, 2)) / 2; double r = d / Math.Sin(angle / 2); sb.Append(" A " + r.ToString() + "," + r.ToString() + " " + (angle * 180 / Math.PI).ToString() + " " + isLargeArc.ToString() + "," + isClockWise.ToString() + " " + x1 + "," + y1); } b = polyline.GetBulgeAt(j); if (x1 < minX) { minX = x1; } else if (x1 > maxX) { maxX = x1; } if (y1 < minY) { minY = y1; } else if (y1 > maxY) { maxY = y1; } x0 = x1; y0 = y1; } if (b != 0) { x1 = polyline.GetPoint3dAt(0).X; y1 = polyline.GetPoint3dAt(0).Y; if (b < 0) { isClockWise = 0; b = b * (-1); } double angle = 4 * Math.Atan(b); double d = Math.Sqrt(Math.Pow(x1 - x0, 2) + Math.Pow(y1 - y0, 2)) / 2; double r = d / Math.Sin(angle / 2); sb.Append(" A " + r.ToString() + "," + r.ToString() + " " + (angle * 180 / Math.PI).ToString() + " 0," + isClockWise.ToString() + " " + x1 + "," + y1); } if (polyline.Closed) { sb.Append(" z"); } } XmlAttribute strokeAttr = document.CreateAttribute("stroke"); StringBuilder strokeString = new StringBuilder("#"); /* Определение цвета контура */ string colorString = color.Name; string RGB = colorString.Substring(2, 6); strokeString.Append(RGB); XmlText strokeText = document.CreateTextNode(strokeString.ToString()); strokeAttr.AppendChild(strokeText); pathElem.Attributes.Append(strokeAttr); XmlAttribute dAttr = document.CreateAttribute("d"); XmlText dText = document.CreateTextNode(sb.ToString()); dAttr.AppendChild(dText); pathElem.Attributes.Append(dAttr); group.AppendChild(pathElem); } /* ЛИНИЯ */ if (objIds[i].ObjectClass.DxfName.Equals("LINE")) { XmlElement pathElem = document.CreateElement("path"); using (Transaction transaction = MyPlugin.doc.Database.TransactionManager.StartTransaction()) { Line line; line = transaction.GetObject(objIds[i], OpenMode.ForRead) as Line; /* цвет по слою */ ColorMethod colorMethod = line.Color.ColorMethod; if (colorMethod == ColorMethod.ByLayer) { layer = transaction.GetObject(line.LayerId, OpenMode.ForRead) as LayerTableRecord; color = layer.Color.ColorValue; } else { color = line.Color.ColorValue; } sb.Append(" " + line.StartPoint.X.ToString() + "," + line.StartPoint.Y.ToString() + " L " + line.EndPoint.X.ToString() + "," + line.EndPoint.Y.ToString()); } XmlAttribute strokeAttr = document.CreateAttribute("stroke"); StringBuilder strokeString = new StringBuilder("#"); byte R = color.R; byte G = color.G; byte B = color.B; if (R < 16) { strokeString.Append("0"); } strokeString.Append(R.ToString("X")); if (G < 16) { strokeString.Append("0"); } strokeString.Append(G.ToString("X")); if (B < 16) { strokeString.Append("0"); } strokeString.Append(B.ToString("X")); XmlText strokeText = document.CreateTextNode(strokeString.ToString()); strokeAttr.AppendChild(strokeText); pathElem.Attributes.Append(strokeAttr); XmlAttribute dAttr = document.CreateAttribute("d"); XmlText dText = document.CreateTextNode(sb.ToString()); dAttr.AppendChild(dText); pathElem.Attributes.Append(dAttr); group.AppendChild(pathElem); } /* КРУГ */ if (objIds[i].ObjectClass.DxfName.Equals("CIRCLE")) { XmlElement pathElem = document.CreateElement("circle"); using (Transaction transaction = MyPlugin.doc.Database.TransactionManager.StartTransaction()) { Circle circle; circle = transaction.GetObject(objIds[i], OpenMode.ForRead) as Circle; /* цвет по слою */ ColorMethod colorMethod = circle.Color.ColorMethod; if (colorMethod == ColorMethod.ByLayer) { layer = transaction.GetObject(circle.LayerId, OpenMode.ForRead) as LayerTableRecord; color = layer.Color.ColorValue; } else { color = circle.Color.ColorValue; } XmlAttribute strokeAttr = document.CreateAttribute("stroke"); StringBuilder strokeString = new StringBuilder("#"); byte R = color.R; byte G = color.G; byte B = color.B; if (R < 16) { strokeString.Append("0"); } strokeString.Append(R.ToString("X")); if (G < 16) { strokeString.Append("0"); } strokeString.Append(G.ToString("X")); if (B < 16) { strokeString.Append("0"); } strokeString.Append(B.ToString("X")); XmlText strokeText = document.CreateTextNode(strokeString.ToString()); strokeAttr.AppendChild(strokeText); pathElem.Attributes.Append(strokeAttr); XmlAttribute rAttr = document.CreateAttribute("r"); XmlText rText = document.CreateTextNode(circle.Radius.ToString()); rAttr.AppendChild(rText); pathElem.Attributes.Append(rAttr); XmlAttribute cxAttr = document.CreateAttribute("cx"); XmlText cxText = document.CreateTextNode(circle.Center.X.ToString()); cxAttr.AppendChild(cxText); pathElem.Attributes.Append(cxAttr); XmlAttribute cyAttr = document.CreateAttribute("cy"); XmlText cyText = document.CreateTextNode(circle.Center.Y.ToString()); cyAttr.AppendChild(cyText); pathElem.Attributes.Append(cyAttr); } group.AppendChild(pathElem); } } double indentX = 0; // отступ по X double indentY = 0; // отступ по Y double width = Math.Round(maxX - minX); // ширина видимой области double height = Math.Round(maxY - minY); // высота видимой области /* Определение формы видимой области */ if (isSquareTrimming) { if (width > height) { indentY = (width - height) / 2; height = width; } else if (height > width) { indentX = (height - width) / 2; width = height; } } AddDimensions(root, document, width + indent * 2, height + indent * 2); XmlAttribute svgAttr = document.CreateAttribute("transform"); XmlText svgText = document.CreateTextNode("translate(" + (indent - minX + indentX).ToString() + ", " + (indent - minY + indentY).ToString() + ")"); svgAttr.AppendChild(svgText); group.Attributes.Append(svgAttr); document.AppendChild(root); string fullName = Path.Combine(dir, (Path.GetFileNameWithoutExtension(MyPlugin.doc.Name) + ".svg")); document.Save(fullName); return(fullName); }
public static void MyCreateLayer(this Database acdb, string layerName, short colorIndex, ColorMethod corlorMethod, bool needPrint) { using (Transaction trans = acdb.TransactionManager.StartTransaction()) { LayerTable layerTable = trans.GetObject(acdb.LayerTableId, OpenMode.ForRead) as LayerTable; if (!layerTable.Has(layerName)) { LayerTableRecord ltr = new LayerTableRecord() { Name = layerName, Color = Color.FromColorIndex(corlorMethod, colorIndex) }; ltr.IsPlottable = needPrint; layerTable.UpgradeOpen(); layerTable.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); } else { layerTable.UpgradeOpen(); LayerTableRecord ltr = trans.GetObject(layerTable[layerName], OpenMode.ForWrite) as LayerTableRecord; ltr.Color = Color.FromColorIndex(corlorMethod, colorIndex); ltr.IsPlottable = needPrint; } trans.Commit(); } }