Skip to content

Commit 4737a35

Browse files
committed
* fixes w.r.t. to the AsciiDoc
generation
1 parent 5d7a6c0 commit 4737a35

10 files changed

+160
-20
lines changed

src/AasxCsharpLibrary/Extensions/ExtendReference.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@ public static Key GetAsExactlyOneKey(this IReference reference)
270270
public static string ToStringExtended(this IReference reference, int format = 1, string delimiter = ",")
271271
{
272272
if (reference.Keys == null)
273-
{
274-
throw new NullValueException("Keys");
275-
}
273+
return "";
276274

277275
return reference.Keys.ToStringExtended(format, delimiter);
278276
}

src/AasxCsharpLibrary/Extensions/ExtendReferenceList.cs

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ public static bool MatchesAnyWithExactlyOneKey(this List<IReference> reflist, IK
3030

3131
return found;
3232
}
33+
34+
/// <summary>
35+
/// Formats: 1 = [key, value] 2 = value
36+
/// </summary>
37+
public static string ToStringExtended(this List<IReference> reflist, int format = 1, string separator = ",")
38+
{
39+
if (reflist == null)
40+
return "";
41+
42+
return string.Join(separator,
43+
reflist.Select((rf) => rf.ToStringExtended(format)));
44+
}
3345
}
3446

3547
}

src/AasxPackageExplorer/debug.MIHO.script

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ Select("Submodel", "First");
2222
// Tool("sammaspectexport", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\samm-test\\out.ttl");
2323
// Tool("submodelinstancefromsammaspect");
2424
// Tool("importtable", "Format", "Excel", "Preset", "Submodel templ. spec. import", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\bugfix\\test-import.xlsx");
25-
Tool("WinMaximize");
25+
// Tool("WinMaximize");
26+
Tool("ExportTable", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\new.adoc", "Preset", "AsciiDoc");

src/AasxPackageExplorer/options-debug.MIHO.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\Test1.aasx",
3333
// "AasxToLoad": "C:\\HOMI\\Develop\\Aasx\\repo\\samm-test\\SMT_and_SAMM_Showcase_v02.aasx",
3434
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\SMT_TechData_Work\\IDTA 02003-1-2_SubmodelTemplate_TechnicalData_v1.3_workingFile_MIHO.aasx",
35-
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\f.aasx",
35+
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\g.aasx",
36+
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\IDTA 02006-3-0_Template_Digital Nameplate_AsciiDoc_Draft_v13_Test_a.aasx",
3637
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\SMT_and_SAMM_Showcase_v02.aasx",
37-
"AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\nearnull.aasx",
38+
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\nearnull.aasx",
39+
"AasxToLoad": "C:\\Users\\homi0002\\Desktop\\SMT_TechData_Work\\IDTA 02003-1-2_SubmodelTemplate_TechnicalData_v1.2__with_Draft_1_3_and_AsciiDoc_v01.aasx",
3840
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\SMT_ProductChangeNotification_Draft_v19_spiel.aasx",
3941
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\00_FestoDemoBox-Module-2-Kopie.aasx",
4042
// "AasxToLoad": "C:\\Users\\homi0002\\Desktop\\tmp\\8001203_SPAU-P10R-T-R18M-L-PNLK-PNVBA-M8D_060ff64f-9fd2-422d-81ce-b17e49f007c5_work_spiel.aasx",

src/AasxPackageLogic/DispEditHelperEntities.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3574,7 +3574,7 @@ public void DisplayOrEditAasEntitySubmodelElement(
35743574
if (cd.IdShort == null || cd.IdShort.Trim() == "")
35753575
cd.IdShort = sme.IdShort;
35763576

3577-
var ds = cd.EmbeddedDataSpecifications.GetIEC61360Content();
3577+
var ds = cd.EmbeddedDataSpecifications?.GetIEC61360Content();
35783578
if (ds != null && (ds.ShortName == null || ds.ShortName.Count < 1))
35793579
{
35803580
ds.ShortName = new List<Aas.ILangStringShortNameTypeIec61360>

src/AasxPluginExportTable/AasxPluginExportTable.options.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
"",
226226
"",
227227
"%font=bold%Explanation: %bg=#0029cc% %fg=white%",
228-
"%Parent.description% %colspan=3%",
228+
"%Parent.description@en% %colspan=3%",
229229
"",
230230
"",
231231
"",
@@ -247,7 +247,7 @@
247247
"",
248248
"",
249249
"[%SME.elementShort%]\r\n%brpost%%SME.idShort%",
250-
"%SME.semanticId[0].value%\r\n%brpost%%CD.definition@en%\r\n%SME.description@en%",
250+
"%SME.semanticId[0].value%\r\n%brpost%%SME.supplSemIds[br-label=supplementalSemanticId]%%CD.definition@en%\r\n%SME.description@en%",
251251
"[%Property.valueType%]\r\n%brpost%%SME.value%",
252252
"%SME.multiplicity%"
253253
]

src/AasxPluginExportTable/Smt/ExportSmt.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ protected void ProcessTextBlob(string header, Aas.IBlob blob)
6969
_adoc.AppendLine(header + text);
7070
}
7171

72+
protected static string EscapeAdText(string input)
73+
{
74+
if (input == null)
75+
return null;
76+
input = input.Replace(@"""", @"\""");
77+
return input;
78+
}
79+
7280
protected string EvalLinkArguments(ExportSmtArguments args, Aas.ISubmodelElement sme)
7381
{
7482
var astr = "";
@@ -78,7 +86,7 @@ protected string EvalLinkArguments(ExportSmtArguments args, Aas.ISubmodelElement
7886

7987
var titStr = sme?.Description?.GetDefaultString();
8088
if (titStr?.HasContent() == true)
81-
astr += $",title=\"{titStr}\"";
89+
astr += $",title=\"{EscapeAdText(titStr)}\"";
8290

8391
astr = astr.Trim(',');
8492

@@ -168,13 +176,14 @@ protected void ProcessImageLink(Aas.ISubmodelElement sme)
168176
_log?.Info("Image data with {0} bytes writen to {1}.", data.Length, absFn);
169177

170178
// create link arguments
179+
var imgId = AdminShellUtil.FilterFriendlyName(sme.IdShort);
171180
var astr = EvalLinkArguments(args, sme);
172181

173182
// create link text
174183
if (doLink)
175184
{
176185
_adoc.AppendLine("");
177-
_adoc.AppendLine($"image::{fn}[{astr}]");
186+
_adoc.AppendLine($"image::{fn}[id=\"{imgId}\", {astr}]");
178187
_adoc.AppendLine("");
179188
}
180189
}
@@ -289,7 +298,7 @@ protected void ProcessTables(Aas.IReferenceElement refel)
289298
_optionsAll, optionsTable, absTableFn,
290299
target, _package?.AasEnv, ticket, _log, maxDepth: processDepth,
291300
idOfElem: refel.IdShort,
292-
titleOfTable: refel.Description?.GetDefaultString());
301+
titleOfTable: EscapeAdText(refel.Description?.GetDefaultString()));
293302

294303
// include file into AsciiDoc
295304
if (_optionsSmt.IncludeTables)

src/AasxPluginExportTable/Table/ExportTableProcessor.cs

+117-7
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ public CellRecord GetBodyCell(int row, int col)
149149
// Processors
150150
//
151151

152+
public class AdvancedMatch
153+
{
154+
public string Trigger;
155+
public string Pattern;
156+
public string Replace;
157+
}
158+
152159
public class ItemProcessor
153160
{
154161
//
@@ -177,8 +184,20 @@ public ItemProcessor(ImportExportTableRecord record, ExportTableAasEntitiesItem
177184
private Regex regexReplacements = null;
178185
private Regex regexStop = null;
179186
private Regex regexCommands = null;
187+
180188
private Dictionary<string, string> repDict = null;
181189

190+
private List<AdvancedMatch> _advancedMatches = new List<AdvancedMatch>();
191+
192+
private void advancedRep(string trigger, string pattern, string replace)
193+
{
194+
_advancedMatches.Add(new AdvancedMatch() {
195+
Trigger = trigger?.Trim().ToLower(),
196+
Pattern = pattern,
197+
Replace = replace
198+
});
199+
}
200+
182201
private void rep(string tag, string value)
183202
{
184203
tag = tag?.Trim().ToLower();
@@ -283,12 +302,31 @@ private void repListOfLangStr(string head, List<Aas.ILangStringPreferredNameType
283302
repLangStr(head, ls);
284303
}
285304

305+
protected string escapeLiteralsToFormat(string input)
306+
{
307+
// access
308+
if (Record == null)
309+
return input;
310+
311+
// switch
312+
var fmt = (ImportExportTableRecord.FormatEnum)Record.Format;
313+
if (fmt == ImportExportTableRecord.FormatEnum.MarkdownGH ||
314+
fmt == ImportExportTableRecord.FormatEnum.AsciiDoc)
315+
{
316+
// escape __00__
317+
input = input.Replace(@"__00__", @"\__00__");
318+
input = input.Replace(@"__000__", @"\__000__");
319+
}
320+
321+
return input;
322+
}
323+
286324
private void repReferable(string head, Aas.IReferable rf)
287325
{
288326
//-9- {Referable}.{idShort, category, description, description[@en..], elementName,
289327
// elementAbbreviation, parent}
290328
if (rf.IdShort != null)
291-
rep(head + "idShort", rf.IdShort);
329+
rep(head + "idShort", escapeLiteralsToFormat(rf.IdShort));
292330
if (rf.Category != null)
293331
rep(head + "category", rf.Category);
294332

@@ -310,7 +348,8 @@ private void repReferable(string head, Aas.IReferable rf)
310348
rf.GetSelfDescription()?.ElementAbbreviation);
311349
}
312350
if (rf is Aas.IReferable rfpar)
313-
rep(head + "parent", "" + (rfpar.IdShort != null ? rfpar.IdShort : "-"));
351+
rep(head + "parent", escapeLiteralsToFormat(
352+
"" + (rfpar.IdShort != null ? rfpar.IdShort : "-")));
314353

315354
// further details
316355
List<string> details = new List<string>();
@@ -413,11 +452,33 @@ private void repReference(string head, string refName, Aas.IReference rid)
413452
}
414453
}
415454

455+
private void repReferenceList(string head, string refName, List<Aas.IReference> rids)
456+
{
457+
if (refName == null)
458+
return;
459+
460+
rep(head + refName + "", "" + rids?.ToStringExtended(2, ", "));
461+
rep(head + refName + "[br]", "" + rids?.ToStringExtended(2, "\r\n%BRPOST%%BRPOST%"));
462+
463+
advancedRep(
464+
trigger: "" + head + refName,
465+
pattern: head + refName + @"\[label=([^]]*)\]",
466+
replace: (rids?.IsValid() != true) ? ""
467+
: "%GROUP1%: " + rids?.ToStringExtended(2, ", ") + "");
468+
469+
advancedRep(
470+
trigger: "" + head + refName,
471+
pattern: head + refName + @"\[br-label=([^]]*)\]",
472+
replace: (rids?.IsValid() != true) ? ""
473+
: "%GROUP1%: " + rids?.ToStringExtended(2, ", ") + "%BRPOST%%BRPOST%");
474+
}
475+
416476
public void Start()
417477
{
418478
// init Regex
419479
// nice tester: http://regexstorm.net/tester
420-
regexReplacements = new Regex(@"%([a-zA-Z0-9.@\[\]]+)%", RegexOptions.IgnoreCase);
480+
// MIHO 2024-06-12: added "=-" to first regex!
481+
regexReplacements = new Regex(@"%([a-zA-Z0-9.@\[\]=-]+)%", RegexOptions.IgnoreCase);
421482
regexStop = new Regex(@"^(.*?)%stop%(.*)$", RegexOptions.IgnoreCase);
422483
regexCommands = new Regex(@"(%([A-Za-z0-9-_]+)=(.*?)%)", RegexOptions.IgnoreCase);
423484

@@ -464,6 +525,7 @@ public void Start()
464525
repMultiplicty(head, parsme.Qualifiers);
465526
//-1- {Reference} = {semanticId, isCaseOf, unitId}
466527
repReference(head, "semanticId", parsme.SemanticId);
528+
repReferenceList(head, "supplSemIds", parsme.SupplementalSemanticIds);
467529
}
468530

469531
//-1- {Referable} = {SM, SME, CD}
@@ -477,6 +539,7 @@ public void Start()
477539
repIdentifiable(head, sm);
478540
//-1- {Reference} = {semanticId, isCaseOf, unitId}
479541
repReference(head, "semanticId", sm.SemanticId);
542+
repReferenceList(head, "supplSemIds", sm.SupplementalSemanticIds);
480543
}
481544

482545
if (sme != null)
@@ -486,6 +549,7 @@ public void Start()
486549
repQualifiable(head, sme.Qualifiers);
487550
repMultiplicty(head, sme.Qualifiers);
488551
repReference(head, "semanticId", sme.SemanticId);
552+
repReferenceList(head, "supplSemIds", sme.SupplementalSemanticIds);
489553

490554
//-2- SME.value
491555

@@ -631,6 +695,16 @@ public void Start()
631695
}
632696
}
633697

698+
private static bool IsRegexMatchOne(string input, string pattern, out string matchOne)
699+
{
700+
var m = Regex.Match(input, pattern);
701+
matchOne = "";
702+
if (!m.Success || m.Groups.Count < 2)
703+
return false;
704+
matchOne = m.Groups[1].ToString();
705+
return true;
706+
}
707+
634708
// see: https://codereview.stackexchange.com/questions/119519/
635709
// regex-to-first-match-then-replace-found-matches
636710
public static string Replace(string s, int index, int length, string replacement)
@@ -668,15 +742,51 @@ public void ProcessCellRecord(CellRecord cr)
668742
continue;
669743

670744
// OK, found a placeholder-tag to replace
671-
var tag = "" + match.Groups[1].Value.Trim().ToLower();
745+
var tag = "" + match.Groups[1].Value.Trim();
746+
var tagLC = tag.ToLower();
747+
748+
// try match advanced
749+
string advancedReplace = null;
750+
foreach (var am in _advancedMatches)
751+
// fast condition
752+
if (tagLC.Contains(am.Trigger))
753+
{
754+
// sufficient condition
755+
// it is important to do the matching (for the group) on
756+
// upper-/ lowercase
757+
var m = Regex.Match(tag, am.Pattern, RegexOptions.IgnoreCase);
758+
if (m.Success && m.Groups.Count >= 2)
759+
{
760+
// do the replace
761+
advancedReplace = am.Replace;
762+
763+
// debug
764+
if (am.Replace != "")
765+
;
766+
767+
// now care for regognized groups
768+
for (int i = 1; i < m.Groups.Count; i++)
769+
advancedReplace = advancedReplace
770+
.Replace($"%GROUP{i}%", m.Groups[i].ToString());
771+
}
772+
}
672773

673-
if (repDict.ContainsKey(tag))
774+
// further matching and actual replace of input
775+
if (advancedReplace != null)
674776
{
675-
input = Replace(input, match.Index, match.Length, repDict[tag]);
777+
// already prepared
778+
input = Replace(input, match.Index, match.Length, advancedReplace);
676779
NumberReplacements++;
677780
}
678781
else
679-
if (tag == "stop")
782+
if (repDict.ContainsKey(tagLC))
783+
{
784+
// use dictionary value
785+
input = Replace(input, match.Index, match.Length, repDict[tagLC]);
786+
NumberReplacements++;
787+
}
788+
else
789+
if (tagLC == "stop")
680790
{
681791
// do nothing! see below!
682792
;

src/AasxPluginExportTable/Table/ImportExportPlaceholders.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public static string GetHelp()
4242
@"All placeholders delimited by %{..}%, {} = set arithmetics, [] = optional
4343
{Referable}.{idShort, category, description[@en..], elementName, elementShort, elementShort2, elementAbbreviation, kind, parent, details}, {Referable|Identifiable} = {SM, SME, CD}, depth, indent}
4444
Identifiable.id, administration.{ version, revision}}, {Qualifiable}.qualifiers, {Qualifiable}.multiplicity
45-
{Aas.Reference}, {Aas.Reference}[0..n], {Aas.Reference}[0..n].{type, local, idType, value}, {Aas.Reference} = {semanticId, isCaseOf, unitId}
45+
{Aas.Reference}, {Aas.Reference}[0..n], {Aas.Reference}[0..n].{type, local, idType, value}, {Aas.Reference} = {semanticId, isCaseOf, unitId}
46+
{Aas.RefList}, {Aas.RefList}[br], {Aas.RefList}[label={label}], {Aas.RefList}[br-label={label}] {Aas.ReferenceList} = {supplSemIds}
4647
SME.value, Property.{value, valueType, valueId}, MultiLanguageProperty.{value, vlaueId}, Range.{valueType, min, max}, Blob.{mimeType, value}, File.{mimeType, value}, ReferenceElement.value,
4748
RelationshipElement.{first, second}, SubmodelElementCollection.{value = #elements, ordered, allowDuplicates}, Entity.{entityType, asset}
4849
CD.{preferredName[@en..], shortName[@en..], unit, unitId, sourceOfDefinition, symbol, dataType, definition[@en..], valueFormat}

src/Notes_V3.md

+7
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,10 @@ These projects are not migrated or integrated, yet:
445445
(\w+)\.(AssetAdministrationShells|Submodels|ConceptDescriptions)
446446
```
447447

448+
# TODO (starting from 2024-06-17)
449+
450+
* Open Aux (Ctrl-X) keyboard shortcut not working
451+
* "Move down" of Submodels does not visually update
452+
* Copy an Submodel from aux while already having an SM with the *same* ID does not throw an error but is hard to recoginze.
453+
(DispEditHelperEntities.cs:1429)
454+
* exporting Markdown/ AsciiDoc: text in cells from idShort shall not interpreted as markdown (__Marking_00__)

0 commit comments

Comments
 (0)