From af992cad07676259661fe70585c4fb9a6c4781cb Mon Sep 17 00:00:00 2001 From: Jean-Sylvain Boige Date: Thu, 25 Apr 2024 22:44:36 +0200 Subject: [PATCH] Freeplane format attempt + new properties --- .../Mindmapper/MindMap.cs | 9 +++- .../Mindmapper/MindMapCreatorConfig.cs | 20 ++++--- .../Mindmapper/MindMapDocumentConfig.cs | 54 ++++++++++++++++--- .../Mindmapper/SVGFreemindMap.cs | 7 ++- 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMap.cs b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMap.cs index 08c2de0b..d5b68860 100644 --- a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMap.cs +++ b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMap.cs @@ -165,12 +165,19 @@ static int GetUnixTime(DateTime utcTime) } [XmlRoot(ElementName = "map")] + [XmlInclude(typeof(FreeplaneMap))] public class FreemindMap { [XmlElement(ElementName = "node")] public Node Node { get; set; } [XmlAttribute(AttributeName = "version")] - public string Version { get; set; } = "1.0.1"; + public virtual string Version { get; set; } = "1.0.1"; } + + public class FreeplaneMap : FreemindMap + { + [XmlAttribute(AttributeName = "version")] + public override string Version { get; set; } = "freeplane 1.11.5"; + } } diff --git a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapCreatorConfig.cs b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapCreatorConfig.cs index 351d7f93..3071aef2 100644 --- a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapCreatorConfig.cs +++ b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapCreatorConfig.cs @@ -26,7 +26,7 @@ public class MindMapCreatorConfig : ParallelFallacyDocumentCreatorConfigBase(new[] - { - ("fr", "en"), - ("fr", "ru"), - ("fr", "pt") - }), + //Translations = new List<(string sourceLang, string destLang)>(new[] + //{ + // ("fr", "en"), + // ("fr", "ru"), + // ("fr", "pt") + //}), ImageFormat = MagickFormat.Png, TargetDensity = 0, SVGMaps = new List(new[] @@ -116,6 +119,7 @@ public override string GetLogMessage() Enabled = true, DocumentName = "links.svg", WrapNodeByLink = true, + RemoveImages = true, SetSVGNodeAttributes = false, }, }) diff --git a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapDocumentConfig.cs b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapDocumentConfig.cs index 15344a5a..c4a8b05d 100644 --- a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapDocumentConfig.cs +++ b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/MindMapDocumentConfig.cs @@ -36,6 +36,9 @@ public class MindMapDocumentConfig : FallacyDocumentConfigBase const string DefaultTitleExpression = @"{fallacy.TextFr}"; + + public MindMapFormat Format { get; set; } = MindMapFormat.Freemind; + public string TitleExpression { get; set; } = DefaultTitleExpression; [IgnoreDataMember] @@ -280,7 +283,16 @@ private void CreateFreemindmap(IList fallacies, AssetConverterConfig co else { Logger.Log($"Creating Freemind mind map {DocumentName}"); - var freemindMap = new FreemindMap(); + FreemindMap freemindMap; + if (Format == MindMapFormat.Freeplane) + { + freemindMap = new FreeplaneMap(); + } + else + { + freemindMap = new FreemindMap(); + } + var nodesByPath = new Dictionary(fallacies.Count); CreateFallacyNodes(freemindMap, fallacies, nodesByPath, config, language); @@ -540,12 +552,19 @@ private async Task ProcessSvgFilesAsync(IList fallacies, string fileNam return; } XDocument svgDoc = XDocument.Load(svgFilePath); - - - svgDoc.Root.SetAttributeValue("viewBox", "0 0 8500 20000"); - svgDoc.Root.SetAttributeValue("width", svgFreemindMap.SvgWidth); - svgDoc.Root.SetAttributeValue("height", svgFreemindMap.SvgHeight); + if (!string.IsNullOrEmpty(svgFreemindMap.SvgViewBox)) + { + svgDoc.Root.SetAttributeValue("viewBox", svgFreemindMap.SvgViewBox); + } + if (!string.IsNullOrEmpty(svgFreemindMap.SvgWidth)) + { + svgDoc.Root.SetAttributeValue("width", svgFreemindMap.SvgWidth); + } + if (!string.IsNullOrEmpty(svgFreemindMap.SvgHeight)) + { + svgDoc.Root.SetAttributeValue("height", svgFreemindMap.SvgHeight); + } XNamespace svgNamespace = "http://www.w3.org/2000/svg"; XNamespace xlinkNamespace = "http://www.w3.org/1999/xlink"; @@ -655,8 +674,21 @@ private void UpdateSvgWithFallacies(SVGFreemindMap svgMap, IList fallac // Optionally remove all SVG images if (svgMap.RemoveImages) { - var imageTags = svgDoc.Descendants(svgNamespace + "image").ToList(); - imageTags.Remove(); + switch (this.Format) + { + case MindMapFormat.Freemind: + var imageTags = svgDoc.Descendants(svgNamespace + "image").ToList(); + imageTags = imageTags.Where(i => i.Attributes("width").All(wAttr => wAttr.Value != "60")).ToList(); + imageTags.Remove(); + break; + case MindMapFormat.Freeplane: + var iconGroups = svgDoc.Descendants(svgNamespace + "g").Where(g => g.Elements(svgNamespace + "path").Any(x => x.Attributes("stroke").Any(att => att.Value == "none"))).ToList(); + iconGroups.Remove(); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } } @@ -923,4 +955,10 @@ protected override DocumentConfig GetClone() return CloneMindMap(); } } + + public enum MindMapFormat + { + Freemind, + Freeplane + } } \ No newline at end of file diff --git a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/SVGFreemindMap.cs b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/SVGFreemindMap.cs index b8fba212..9b8ae43a 100644 --- a/Generation/Converters/Argumentum.AssetConverter/Mindmapper/SVGFreemindMap.cs +++ b/Generation/Converters/Argumentum.AssetConverter/Mindmapper/SVGFreemindMap.cs @@ -10,9 +10,12 @@ public class SVGFreemindMap : DocumentConfig, ICloneable public bool SetSVGNodeAttributes { get; set; } - public string SvgWidth { get; set; } = "200vh"; + public string SvgWidth { get; set; } - public string SvgHeight { get; set; } = "450vh"; + public string SvgHeight { get; set; } + + + public string SvgViewBox { get; set; } public bool WrapNodeByLink { get; set; }