public static DbTextModel DbText2Model(DBText dbText, AttributeModel atModel) { DbTextModel dbModel = new DbTextModel(); dbModel.attItemList = new List <AttributeItemModel>(); dbModel.Height = dbText.Height; //dbModel.Position = new System.Drawing.PointF((float)dbText.Position.X, (float)dbText.Position.Y); dbModel.Position = Point3d2Pointf(dbText.Position); dbModel.Rotation = dbText.Rotation; dbModel.ThickNess = dbText.Thickness; dbModel.Text = dbText.TextString.Replace(" ", "").Replace("\n", "").Replace("\r", ""); if (dbText.TextString.Replace(" ", "").Replace("\n", "").Replace("\r", "") == "纬三路") { } dbModel.Color = dbText.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(dbText.LayerId) : System.Drawing.ColorTranslator.ToHtml(dbText.Color.ColorValue); foreach (AttributeItemModel item in atModel.attributeItems) { string attValue = ""; switch (item.AtItemType) { case AttributeItemType.TxtHeight: attValue = dbText.Height.ToString(); break; case AttributeItemType.Color: attValue = dbModel.Color; break; case AttributeItemType.Content: attValue = dbText.TextString.Replace(" ", "").Replace(" ", "").Replace("\n", "").Replace("\r", ""); break; case AttributeItemType.LayerName: attValue = dbText.Layer; break; case AttributeItemType.LineScale: attValue = dbText.LinetypeScale.ToString(); break; case AttributeItemType.LineType: attValue = GetLayerLineTypeByID(dbText); break; } if (!string.IsNullOrEmpty(attValue)) { item.AtValue = attValue; dbModel.attItemList.Add(item); } } return(dbModel); }
public static DbTextModel DbText2Model(MText dbText) { DbTextModel dbModel = new DbTextModel(); dbModel.Height = dbText.ActualHeight; //dbModel.Position = new System.Drawing.PointF((float)dbText.Position.X, (float)dbText.Position.Y); dbModel.Position = Point3d2Pointf(dbText.Location); dbModel.Rotation = dbText.Rotation; // dbModel.ThickNess = dbText.TextHeight; dbModel.Text = dbText.Text; dbModel.Color = dbText.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(dbText.LayerId) : System.Drawing.ColorTranslator.ToHtml(dbText.Color.ColorValue); return(dbModel); }
private void CommanOk_Executed(object sender, ExecutedRoutedEventArgs e) { var DbText = new DbTextModel(); var DbTextContent = new TextBlock(); var Dc = new NewTextViewModel(); var fixName = DateTime.Now.ToString("yyyyMMddHHmmss"); DbTextContent.Text = Dc.LabelContent = NewDbTextVM.SelectedElem.wartosc; DbText.Name = Dc.Name = $"DBT_{fixName}"; DbText.Width = Dc.LabelContent.Count() * 8; DbText.Height = 30; DbText.Id_Pole = NewDbTextVM.SelectedElem.id_pole; DbText.Content = DbTextContent; DbText.DataContext = Dc; NewDbTextEvent?.Invoke(DbText, 5, 5); WindowResult = true; Close(); }
public static DbTextModel DbText2Model(DBText dbText) { DbTextModel dbModel = new DbTextModel(); dbModel.Height = dbText.Height; //dbModel.Position = new System.Drawing.PointF((float)dbText.Position.X, (float)dbText.Position.Y); dbModel.Position = Point3d2Pointf(dbText.Position); dbModel.Rotation = dbText.Rotation; dbModel.ThickNess = dbText.Thickness; dbModel.Text = dbText.TextString; dbModel.Color = dbText.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(dbText.LayerId) : System.Drawing.ColorTranslator.ToHtml(dbText.Color.ColorValue); ////获取文本 //string text = dbModel.Text; ////得到Bitmap(传入Rectangle.Empty自动计算宽高) //Bitmap bmp = TextToBitmap(text, new Font("Arial", 16), Rectangle.Empty, Color.FromName(dbModel.Color), Color.FromName("White")); ////保存到桌面save.jpg //string directory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory); //bmp.Save(directory + "\\save.png", System.Drawing.Imaging.ImageFormat.Png); return(dbModel); }
public override void GetAllAttributeInfo(T model) { foreach (AttributeModel am in model.attributes) { foreach (string layerName in GetRealLayer(am.LayerName)) { // 需要发送的图层 if (layerName != null) { model.selectedLayerList.Add(layerName); } Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; LayerModel lyModel = new LayerModel(); lyModel.IsHaveAttribute = true; List <BlockInfoModel> list = new List <BlockInfoModel>(); lyModel.Name = layerName; // Document doc = Application.DocumentManager.MdiActiveDocument; ObjectIdCollection ids = new ObjectIdCollection(); PromptSelectionResult ProSset = null; TypedValue[] filList = new TypedValue[1] { new TypedValue((int)DxfCode.LayerName, layerName) }; SelectionFilter sfilter = new SelectionFilter(filList); LayoutManager layoutMgr = LayoutManager.Current; string ss = layoutMgr.CurrentLayout; ProSset = doc.Editor.SelectAll(sfilter); // List<ObjectId> idss= GetEntitiesInModelSpace(); // Database db = doc.Database; List <BlockReference> blockTableRecords = new List <BlockReference>(); if (ProSset.Status == PromptStatus.OK) { lyModel.pointFs = new Dictionary <int, List <object> >(); using (Transaction tran = doc.Database.TransactionManager.StartTransaction()) { SelectionSet sst = ProSset.Value; ObjectId[] oids = sst.GetObjectIds(); int ad = 0; List <string> aa = new List <string>(); LayerTable lt = (LayerTable)doc.Database.LayerTableId.GetObject(OpenMode.ForRead); foreach (ObjectId layerId in lt) { LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead); if (ltr.Name == layerName) { lyModel.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue); } } double totalFamily = 0; double totalPeople = 0; int i = 0; foreach (ObjectId lengGemo in oids) { DBObject ob = tran.GetObject(lengGemo, OpenMode.ForRead); BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob, am); foreach (DbTextModel dbTextModel in plModel.DbText) { if (dbTextModel.attItemList != null && dbTextModel.attItemList.Count > 0) { foreach (AttributeItemModel attribute in dbTextModel.attItemList) { if (attribute.AtValue.Contains(":") || attribute.AtValue.Contains(":")) { string[] fmList = attribute.AtValue.Split(new char[2] { ':', ':' }); if (attribute.TargetName == "总户数") { totalFamily += double.Parse(fmList[3]); } else if (attribute.TargetName == "总人数") { totalPeople += double.Parse(System.Text.RegularExpressions.Regex.Replace(fmList[2].Replace("(", "").Replace(")", ""), @"[\u4e00-\u9fa5]", "")); } } } } } if (plModel != null) { List <object> obj = new List <object>() { plModel }; lyModel.pointFs.Add(i, obj); i++; } } foreach (List <object> ptssItem in lyModel.pointFs.Values) { foreach (object ptsItem in ptssItem) { BlockInfoModel tempBlock = new BlockInfoModel(); if (ptsItem is BlockInfoModel) { for (int j = 0; j < (ptsItem as BlockInfoModel).DbText.Count; j++) { DbTextModel dbTextModel = (ptsItem as BlockInfoModel).DbText[j]; List <AttributeItemModel> kk = new List <AttributeItemModel>(); if (dbTextModel.attItemList != null && dbTextModel.attItemList.Count > 0) { foreach (AttributeItemModel attribute in dbTextModel.attItemList) { AttributeItemModel tempModel = attribute; if (attribute.TargetName == "总户数") { tempModel = attribute; tempModel.AtValue = totalFamily.ToString(); kk.Add(tempModel);// dbTextModel.attItemList[attribute] = totalFamily.ToString(); } else if (attribute.TargetName == "总人数") { tempModel = attribute; tempModel.AtValue = totalPeople.ToString(); kk.Add(tempModel); } else { kk.Add(attribute); } } } dbTextModel.attItemList = kk; } } } } if (model.allLines == null) { model.allLines = new List <LayerModel>(); } model.allLines.Add(lyModel); } } } } }
private static void ParseLabel(XElement lbl, Dictionary <UIElement, CanvasPosition> list, string type) { Label newLabel; switch (type) { case "Margin": newLabel = new Label(); break; case "Own": newLabel = new OwnTextModel(); break; case "Db": newLabel = new DbTextModel(); break; default: throw new Exception("Nie rozpoznany typ komponentu tekstowego."); } TextBlock newTextBlock = new TextBlock(); NewTextViewModel newTextViewModel = new NewTextViewModel(); var textBlock = lbl.Descendants(ns + "TextBlock").FirstOrDefault(); if (textBlock != null) { var text = textBlock.Attribute("Text").Value; var fontFamily = textBlock.Attribute("FontFamily")?.Value; var fontStyle = textBlock.Attribute("FontStyle")?.Value; var fontWeight = textBlock.Attribute("FontWeight")?.Value; var fontSize = textBlock.Attribute("FontSize")?.Value; var fontColor = textBlock.Attribute("Foreground")?.Value; var hca = lbl.Attribute("HorizontalContentAlignment")?.Value; var vca = lbl.Attribute("VerticalContentAlignment")?.Value; newTextViewModel.LabelContent = text; newTextViewModel.TbFontFamily = fontFamily != null ? new FontFamily(fontFamily) : new FontFamily("Verdana"); newTextViewModel.TbFontStyle = fontStyle == "Italic" ? FontStyles.Italic : FontStyles.Normal; newTextViewModel.TbFontWeight = fontWeight == "Bold" ? FontWeights.Bold : FontWeights.Regular; newTextViewModel.TbFontSize = fontSize != null ? (float)Convert.ToDouble(StrToDouble(fontSize)) : 10; newTextViewModel.FontColor = fontColor != null ? new BrushConverter().ConvertFromString(fontColor) as SolidColorBrush : Brushes.Black; newTextViewModel.TbHorizontalContentAligment = hca != null?GetHorizontalAligment(hca) : HorizontalAlignment.Left; newTextViewModel.TbVerticalContentAligment = vca != null?GetVerticalAligment(vca) : VerticalAlignment.Top; // UTWORZENIE OKNA DIALOGOWEGO DO WYBIERANIA CZCIONKI System.Drawing.FontStyle fs1 = System.Drawing.FontStyle.Regular; System.Drawing.FontStyle fs2 = System.Drawing.FontStyle.Regular; System.Drawing.FontStyle fs3 = System.Drawing.FontStyle.Regular; System.Drawing.FontStyle fs4 = System.Drawing.FontStyle.Regular; if (fontStyle == "Italic") { fs1 = System.Drawing.FontStyle.Italic; } if (fontWeight == "Bold") { fs2 = System.Drawing.FontStyle.Bold; } var textDecoration = textBlock.Descendants(ns + "TextDecoration").ToList(); if (textDecoration != null) { TextDecorationCollection tdc = new TextDecorationCollection(); foreach (var decoration in textDecoration) { var d = decoration.Attribute("Location").Value; if (d == "Underline") { tdc.Add(TextDecorations.Underline); fs3 = System.Drawing.FontStyle.Underline; } if (d == "Strikethrough") { tdc.Add(TextDecorations.Strikethrough); fs4 = System.Drawing.FontStyle.Strikeout; } } newTextViewModel.TbTextDecorations = tdc; } newTextViewModel.FontDialog = new System.Windows.Forms.FontDialog(); newTextViewModel.FontDialog.Color = System.Drawing.ColorTranslator.FromHtml(fontColor); newTextViewModel.FontDialog.Font = new System.Drawing.Font(newTextViewModel.TbFontFamily.Source.ToString(), (float)Convert.ToDouble(StrToDouble(newTextViewModel.TbFontSize.ToString())), fs1 | fs2 | fs3 | fs4); newLabel.Content = newTextBlock; } var name = lbl.Attribute("Name").Value; newLabel.Name = name; newTextViewModel.Name = name; // POBRANIE WŁAŚCIWOŚCI MARGINESÓW if (!name.Contains("Margin")) { var borderBrush = lbl.Attribute("BorderBrush")?.Value; var borderThick = lbl.Attribute("BorderThickness")?.Value; var thickness = borderThick != null?Convert.ToInt32(borderThick.Split(',')[0]) : 0; newTextViewModel.BorderColor = borderBrush != null ? new BrushConverter().ConvertFromString(borderBrush) as SolidColorBrush : null; newTextViewModel.BorderThickness = thickness; if (thickness > 0) { newTextViewModel.Border = true; } } var width = lbl.Attribute("Width")?.Value; var height = lbl.Attribute("Height")?.Value; newTextViewModel.TbWidth = Convert.ToDouble(StrToDouble(width)); newTextViewModel.TbHeight = Convert.ToDouble(StrToDouble(height)); var left = lbl.Attribute(ns + "Canvas.Left").Value; var top = lbl.Attribute(ns + "Canvas.Top").Value; var canvasLeft = Convert.ToDouble(StrToDouble(left)); var canvasTop = Convert.ToDouble(StrToDouble(top)); newLabel.DataContext = newTextViewModel; AppHandler.BindData(newLabel, newTextBlock); list.Add(newLabel, new CanvasPosition(canvasLeft, canvasTop)); }