} // End Sub FixDoubleLines public static void FixModel(DxfModel model) { #if COMPENSATE_TEIGHA_BUG FixLayerEncoding(model); #endif //foreach (WW.Cad.Model.Objects.DxfGroup thisGroup in model.Groups) //{ //} // Next thisGroup //foreach (WW.Cad.Model.Entities.DxfEntity ent in model.ModelLayout.Entities) //{ // if (!ls.Contains(ent.Layer.Name)) // ls.Add(ent.Layer.Name); //} // Next ent //for (int i = 0; i < model.Layouts.Count; ++i) //{ // foreach (WW.Cad.Model.Entities.DxfEntity ent in model.Layouts[i].Entities) // { // if (!ls.Contains(ent.Layer.Name)) // ls.Add(ent.Layer.Name); // } //} // Next i //foreach (WW.Cad.Model.Tables.DxfBlock thisAnonymousBlock in model.AnonymousBlocks) //{ // for (int i = 0; i < thisAnonymousBlock.Entities.Count; ++i) // { // DoubleLineFix(thisAnonymousBlock.Entities[i]); // } //} // Next thisBlock //foreach (WW.Cad.Model.Tables.DxfBlock thisBlock in model.Blocks) //{ // for (int i = 0; i < thisBlock.Entities.Count; ++i) // { // DoubleLineFix(thisBlock.Entities[i]); // } //} // Next thisBlock // Use recursion instead of multiple loops WW.Cad.Model.DrawingCodePage drawingCodePage = model.Header.DrawingCodePage; for (int i = 0; i < model.Entities.Count; ++i) { FixDoubleLines(drawingCodePage, model.Entities[i]); } // Next i } // End Sub FixModel
} // End Function Latinize public static bool FixTextWithWrongEncoding(WW.Cad.Model.DrawingCodePage drawingCodePage, string text, ref string correctedText) { string normalizedText = HandleAllowedAccentCharacters(text); string latinText = Latinize(text); if (!System.StringComparer.OrdinalIgnoreCase.Equals(latinText, normalizedText)) { System.Console.WriteLine("Invalid characters in text '" + text + "'"); System.Console.WriteLine(" - Latin: " + latinText); byte[] encoded = System.Text.Encoding.GetEncoding((int)drawingCodePage).GetBytes(text); correctedText = System.Text.Encoding.GetEncoding("iso-8859-1").GetString(encoded); System.Console.WriteLine(" - Actual: " + correctedText); System.Console.WriteLine("fixed"); return(true); } // End if (!System.StringComparer.OrdinalIgnoreCase.Equals(latin, layerName)) // else System.Console.WriteLine(text); return(false); } // End Function FixTextWithWrongEncoding
public static void FixDoubleLines(WW.Cad.Model.DrawingCodePage drawingCodePage, WW.Cad.Model.Entities.DxfEntity entity) { //if (System.StringComparer.OrdinalIgnoreCase.Equals("FM_OBJEKT_RAUM", model.Entities[i].Layer.Name)) //{ // //System.Console.WriteLine(model.Entities[i].AcClass); // //System.Console.WriteLine(model.Entities[i].LineWeight); // //System.Console.WriteLine(model.Entities[i].EntityType); // //System.Console.WriteLine(model.Entities[i].LineType); // //System.Console.WriteLine(model.Entities[i].LineTypeScale); // //System.Console.WriteLine(model.Entities[i].Layer.Name); //} //End if (System.StringComparer.OrdinalIgnoreCase.Equals("FM_OBJEKT_RAUM", model.Entities[i].Layer.Name)) if (entity is WW.Cad.Model.Entities.DxfInsert) { WW.Cad.Model.Entities.DxfInsert ins = (WW.Cad.Model.Entities.DxfInsert)entity; for (int i = 0; i < ins.Block.Entities.Count; ++i) { FixDoubleLines(drawingCodePage, ins.Block.Entities[i]); } // Next i } // End if (entity is WW.Cad.Model.Entities.DxfInsert) // https://www.woutware.com/Forum/Topic/1388/svg-export-path-goes-2x-around?returnUrl=%2FForum%2FBoard%2F2%2Fquestions-and-general-support&page=1 else if (entity is WW.Cad.Model.Entities.DxfPolyline2D) { WW.Cad.Model.Entities.DxfPolyline2D dxfPolyline = (WW.Cad.Model.Entities.DxfPolyline2D)entity; dxfPolyline.DefaultStartWidth = 0.0; dxfPolyline.DefaultEndWidth = 0.0; foreach (WW.Cad.Model.Entities.DxfVertex2D thisVertex in dxfPolyline.Vertices) { thisVertex.StartWidth = 0.0; thisVertex.EndWidth = 0.0; } // Next thisVertex } else if (entity is WW.Cad.Model.Entities.DxfLwPolyline) { WW.Cad.Model.Entities.DxfLwPolyline dwgPolyLine = (WW.Cad.Model.Entities.DxfLwPolyline)entity; // https://www.woutware.com/Forum/Topic/20/generating-thick-lines?returnUrl=%2FForum%2FUserPosts%3FuserId%3D743420688 // set the property ConstantWidth. Don't confuse it with property Thickness though: the thickness is the extrusion along its z-axis dwgPolyLine.ConstantWidth = 0.0; dwgPolyLine.LineWeight = 0; dwgPolyLine.Thickness = 0.0; foreach (WW.Cad.Model.Entities.DxfLwPolyline.Vertex thisVertex in dwgPolyLine.Vertices) { thisVertex.StartWidth = 0.0; thisVertex.EndWidth = 0.0; } // Next tVertex } // End else if (entity is WW.Cad.Model.Entities.DxfLwPolyline) #if COMPENSATE_TEIGHA_BUG else if (entity is WW.Cad.Model.Entities.DxfText) { WW.Cad.Model.Entities.DxfText dxtext = (WW.Cad.Model.Entities.DxfText)entity; string corrected = null; if (FixTextWithWrongEncoding(drawingCodePage, dxtext.Text, ref corrected)) { dxtext.Text = corrected; } // End if (FixBrokenText(drawingCodePage, dxtext.Text, ref corrected)) } // End else if (entity is WW.Cad.Model.Entities.DxfText) #endif } // End Sub FixDoubleLines