-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathFormatHTM.cs
2317 lines (2010 loc) · 91.9 KB
/
FormatHTM.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Name: FormatHtm.cs
// Description: HTML document generation
// Author: Tim Chipman
// Origination: Work performed for BuildingSmart by Constructivity.com LLC.
// Copyright: (c) 2010 BuildingSmart International Ltd.
// License: http://www.buildingsmart-tech.org/legal
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using IfcDoc.Schema.DOC;
namespace IfcDoc.Format.HTM
{
public class FormatHTM :
IDisposable,
IComparer<string>
{
Stream m_stream;
StreamWriter m_writer;
Dictionary<string, DocObject> m_mapEntity;
Dictionary<string, string> m_mapSchema;
bool m_anchors; // if true, hyperlinks are anchors within same page; if false, hyperlinks go to documentation
Dictionary<DocObject, bool> m_included;
const string BEGIN_KEYWORD = "<span class=\"keyword\">";
const string END_KEYWORD = "</span>";
public FormatHTM(string path, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, Dictionary<DocObject, bool> included)
{
string dirpath = System.IO.Path.GetDirectoryName(path);
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
this.m_stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
this.m_writer = new StreamWriter(this.m_stream, Encoding.UTF8);
this.m_mapEntity = mapEntity;
this.m_mapSchema = mapSchema;
this.m_included = included;
}
public bool UseAnchors
{
get
{
return this.m_anchors;
}
set
{
this.m_anchors = value;
}
}
public Dictionary<DocObject, bool> Included
{
get
{
return this.m_included;
}
}
#region IDisposable Members
public void Dispose()
{
if (this.m_writer != null)
{
this.m_writer.Flush();
this.m_writer.Close();
}
if (this.m_stream != null)
{
this.m_stream.Close();
this.m_stream = null;
}
}
#endregion
/// <summary>
/// Writes opening HTML
/// </summary>
/// <param name="title">Caption</param>
/// <param name="level">Number of levels deep (for referencing style sheet)</param>
public void WriteHeader(string title, int level)
{
string style = "";
for (int i = 0; i < level; i++)
{
style += "../";
}
style += "ifc-styles.css";
this.m_writer.WriteLine("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n");
this.m_writer.WriteLine("<html>");
this.m_writer.WriteLine(" <head>");
this.m_writer.WriteLine(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\r\n");
this.m_writer.WriteLine(" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + style + "\">\r\n");
this.m_writer.WriteLine(" <title>" + title + "</title>\r\n");
this.m_writer.WriteLine(" </head>\r\n");
this.m_writer.WriteLine(" <body>\r\n");
if (!String.IsNullOrEmpty(Properties.Settings.Default.Header))
{
this.m_writer.WriteLine("<p>" + Properties.Settings.Default.Header + "</p>");
}
}
/// <summary>
/// Old function for compatibility
/// </summary>
/// <param name="title"></param>
/// <param name="section"></param>
/// <param name="schema"></param>
/// <param name="definition"></param>
/// <param name="header"></param>
public void WriteHeader(string title, int section, int schema, int definition, string header)
{
int level = 0;
if (section == 0)
{
// toc page
// same
}
else if (schema == 0)
{
// section page
level = 1;
}
else if (section < 0)
{
// annex
if (section == -2 || section == -3)
{
level = 2;
}
else
{
level = 3;
}
}
else if (section == 1)
{
// views
level = 3;
}
else if (section == 4)
{
level = 2;
}
else if (definition > 0)
{
level = 3;
}
else if (schema > 0)
{
level = 2;
}
else if (section > 0)
{
}
else if (title != "Table of Contents" && title != "Index")
{
level = 2;
}
WriteHeader(title, level);
}
/// <summary>
/// Writes closing tags
/// </summary>
public void WriteFooter(string footer)
{
if (footer != null)
{
this.m_writer.WriteLine("<p>" + footer + "</p>");
}
this.m_writer.WriteLine(" </body>");
this.m_writer.WriteLine("</html>");
}
public void Write(string content)
{
this.m_writer.Write(content);
}
public void WriteLine(string content)
{
this.m_writer.WriteLine(content);
}
public void WriteDefinition(string definition)
{
string format = FormatDefinition(definition);
WriteLine(format);
}
/// <summary>
/// Encodes HTML, preserves tabs and new lines, and generates hyperlinks for IFC references
/// </summary>
/// <param name="rawtext"></param>
public void WriteFormatted(string rawtext)
{
string html = System.Web.HttpUtility.HtmlEncode(rawtext.ToString());
html = html.Replace("\r\n", "<br/>\r\n");
html = html.Replace("\t", " ");
StringBuilder sb = new StringBuilder();
int p = 0; // previous
int i = html.IndexOf(":Ifc", StringComparison.Ordinal);
while (i != -1)
{
int j = html.IndexOf('&', i + 1); // end-quote converted to "
// j should always be valid here
string def = html.Substring(i + 1, j - i - 1);
string fmt = FormatDefinition(def);
sb.Append(html, p, i - p + 1);
sb.Append(fmt);
p = j;
i = html.IndexOf(":Ifc", i + 1, StringComparison.Ordinal);
}
sb.Append(html, p, html.Length - p);
this.Write(sb.ToString());
}
/// <summary>
/// Writes definition, using hyperlink for IFC-defined type (e.g. IfcCartesianPoint) or bold for primitive type (e.g. INTEGER)
/// </summary>
/// <param name="definition"></param>
private string FormatDefinition(string definition)
{
DocObject ent = null;
string schema = null;
if (definition != null && definition.StartsWith("Ifc") &&
this.m_mapEntity.TryGetValue(definition, out ent) &&
this.m_mapSchema.TryGetValue(definition, out schema))
{
if (this.m_included == null || this.m_included.ContainsKey(ent))
{
if (this.m_anchors)
{
return "<a href=\"#" + definition.ToLower() + "\">" + definition + "</a>";
}
else
{
if (this.m_stream is FileStream && ((FileStream)this.m_stream).Name.EndsWith(".xsd.htm"))
{
string hyperlink = @"../../../schema/" + schema.ToLower() + @"/lexical/" + definition.ToLower() + ".htm";
return "<a href=\"" + hyperlink + "\">" + definition + "</a>";
}
else
{
string hyperlink = @"../../" + schema.ToLower() + @"/lexical/" + definition.ToLower() + ".htm";
return "<a href=\"" + hyperlink + "\">" + definition + "</a>";
}
}
}
else
{
return "<span class=\"self-ref\">IfcStrippedOptional</span>";
}
}
else
{
return "<span class=\"self-ref\">" + definition + "</span>";
}
}
public void WriteTOC(int indent, string content)
{
for (int i = 0; i < indent; i++)
{
// ISO document is incorrect - there is no such "&sp5;" symbol
this.m_writer.Write(" ");
}
this.m_writer.Write(content);
this.m_writer.Write("<br />");
this.m_writer.WriteLine();
}
private void WriteExpressHeader(int indent)
{
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
this.m_writer.WriteLine(" <tr valign=\"top\">");
if (indent > 0)
{
this.m_writer.WriteLine(" <td width=\"" + indent.ToString() + "%\">");
}
this.m_writer.WriteLine(" <td>");
}
private void WriteExpressFooter()
{
this.m_writer.WriteLine(" </td>");
this.m_writer.WriteLine(" </tr>");
this.m_writer.WriteLine("</table>");
}
public void WriteExpressLine(int indent, string content)
{
WriteExpressHeader(indent);
WriteLine(content);
WriteExpressFooter();
}
/// <summary>
/// Writes EXPRESS attributes for entity definition or as part of inheritance graph
/// </summary>
/// <param name="entity">The entity to reflect attributes.</param>
/// <param name="treeleaf">Optional leaf entity for inheritance diagram; any overridden attributes will be suppressed.</param>
public void WriteExpressAttributes(DocEntity entity, DocEntity treeleaf)
{
bool bInverse = false;
bool bDerived = false;
bool bExplicit = false;
// count attributes first to avoid generating tables unnecessarily (W3C validation)
if (entity.Attributes != null && entity.Attributes.Count > 0)
{
foreach (DocAttribute attr in entity.Attributes)
{
if (attr.Derived != null)
{
// inverse may also be indicated to hold class
bDerived = true;
}
else if (attr.Inverse != null)
{
bInverse = true;
}
else
{
bExplicit = true;
}
}
}
// explicit attributes, plus detect any inverse or derived
if (bExplicit)
{
this.WriteExpressHeader(2);
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocAttribute attr in entity.Attributes)
{
bool bInclude = true;
// suppress any attribute that is overridden on leaf class
if (treeleaf != null && treeleaf != entity)
{
foreach (DocAttribute derivedattr in treeleaf.Attributes)
{
if (derivedattr.Name.Equals(attr.Name))
{
bInclude = false;
}
}
}
if (bInclude)
{
if (attr.Inverse == null && attr.Derived == null)
{
this.m_writer.Write("<tr valign=\"top\"><td width=\"20%\">");
this.m_writer.Write(attr.Name);
this.m_writer.Write("</td><td width=\"1%\"> : </td><td>");
if ((attr.AttributeFlags & 1) != 0)
{
this.m_writer.Write(BEGIN_KEYWORD + "OPTIONAL" + END_KEYWORD + " ");
}
this.WriteExpressAggregation(attr);
if (this.m_included == null || this.m_included.ContainsKey(attr))
{
this.m_writer.Write(FormatDefinition(attr.DefinedType));
}
else
{
this.m_writer.Write("<span class=\"self-ref\">IfcStrippedOptional</span>");
}
this.m_writer.WriteLine(";</td></tr>");
}
}
}
this.m_writer.WriteLine("</table>");
this.WriteExpressFooter();
}
// inverse attributes
if (bInverse)
{
this.WriteExpressLine(1, BEGIN_KEYWORD + "INVERSE" + END_KEYWORD);
this.WriteExpressHeader(2);
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocAttribute attr in entity.Attributes)
{
DocObject docinvtype = null;
if (attr.Inverse != null && attr.Derived == null && this.m_mapEntity.TryGetValue(attr.DefinedType, out docinvtype))
{
if (this.m_included == null || this.m_included.ContainsKey(docinvtype))
{
this.m_writer.Write("<tr valign=\"top\"><td width=\"20%\">");
this.m_writer.Write(attr.Name);
this.m_writer.Write("</td><td width=\"1%\"> : </td><td>");
this.WriteExpressAggregation(attr);
this.m_writer.Write(FormatDefinition(attr.DefinedType));
this.m_writer.Write(" " + BEGIN_KEYWORD + "FOR" + END_KEYWORD + " ");
this.m_writer.Write(attr.Inverse);
this.m_writer.WriteLine(";</td></tr>");
}
}
}
this.m_writer.WriteLine("</table>");
this.WriteExpressFooter();
}
// derived attributes
if (bDerived)
{
this.WriteExpressLine(1, BEGIN_KEYWORD + "DERIVE" + END_KEYWORD);
this.WriteExpressHeader(2);
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocAttribute attr in entity.Attributes)
{
if (attr.Derived != null)
{
// determine the superclass having the attribute
DocEntity found = null;
if (treeleaf == null)
{
DocEntity super = entity;
while (super != null && found == null && super.BaseDefinition != null)
{
super = this.m_mapEntity[super.BaseDefinition] as DocEntity;
if (super != null)
{
foreach (DocAttribute docattr in super.Attributes)
{
if (docattr.Name.Equals(attr.Name))
{
// found class
found = super;
break;
}
}
}
}
}
if (found != null)
{
// overridden attribute
this.m_writer.Write("<tr valign=\"top\"><td width=\"20%\">" + BEGIN_KEYWORD + "SELF" + END_KEYWORD + "\\" + found.Name + "." + attr.Name + "</td><td width=\"1%\"> : </td><td>");
}
else
{
// non-overridden
this.m_writer.Write("<tr valign=\"top\"><td width=\"20%\">" + attr.Name + "</td><td width=\"1%\"> : </td><td>");
}
this.WriteExpressAggregation(attr);
this.m_writer.Write(FormatDefinition(attr.DefinedType));
this.m_writer.Write(" := ");
this.m_writer.Write(attr.Derived);
this.m_writer.WriteLine(";</td></tr>");
}
}
this.m_writer.WriteLine("</table>");
this.WriteExpressFooter();
}
}
private void WriteExpressAggregation(DocAttribute attr)
{
if (attr.AggregationType == 0)
return;
DocAttribute docAggregation = attr;
while (docAggregation != null)
{
switch (docAggregation.AggregationType)
{
case 1:
this.m_writer.Write(BEGIN_KEYWORD + "LIST" + END_KEYWORD + " ");
break;
case 2:
this.m_writer.Write(BEGIN_KEYWORD + "ARRAY" + END_KEYWORD + " ");
break;
case 3:
this.m_writer.Write(BEGIN_KEYWORD + "SET" + END_KEYWORD + " ");
break;
case 4:
this.m_writer.Write(BEGIN_KEYWORD + "BAG" + END_KEYWORD + " ");
break;
}
if (docAggregation.AggregationUpper != null && docAggregation.AggregationUpper != "0")
{
this.m_writer.Write("[" + docAggregation.AggregationLower + ":" + docAggregation.AggregationUpper + "] OF ");
}
else if (docAggregation.AggregationLower != null)
{
this.m_writer.Write("[" + docAggregation.AggregationLower + ":?] " + BEGIN_KEYWORD + "OF" + END_KEYWORD + " ");
}
else
{
this.m_writer.Write(BEGIN_KEYWORD + "OF" + END_KEYWORD + " ");
}
if ((docAggregation.AggregationFlag & 2) != 0)
{
// unique
this.m_writer.Write(BEGIN_KEYWORD + "UNIQUE" + END_KEYWORD + " ");
}
// drill in
docAggregation = docAggregation.AggregationAttribute;
}
}
public void WriteExpressEntityAndDocumentation(DocEntity entity, bool suppresshistory, bool isoformat)
{
this.m_writer.WriteLine("<p class=\"spec-head\">EXPRESS Specification:</p>");
this.m_writer.WriteLine("<span class=\"express\">");
// new: comment tag
if (isoformat)
{
this.WriteExpressLine(0, "*)");
}
this.WriteExpressEntity(entity);
// Comment tag for ISO STEP documentation requirements
if (isoformat)
{
this.WriteExpressLine(0, "(*");
}
this.m_writer.WriteLine("</span>");
// link to EXPRESS-G
WriteExpressDiagram(entity);
if (entity.Attributes != null && entity.Attributes.Count > 0)
{
// avoid attributes without descriptions
int cDescs = 0;
foreach (DocAttribute docAttr in entity.Attributes)
{
if (docAttr.Documentation != null)
{
cDescs++;
}
}
if (cDescs > 0)
{
// attributes
this.m_writer.WriteLine("<p class=\"spec-head\">Attribute Definitions:</p>");
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocAttribute docAttr in entity.Attributes)
{
DocObject docref = null;
if (!this.m_mapEntity.TryGetValue(docAttr.DefinedType, out docref) || (this.m_included == null || this.m_included.ContainsKey(docref)))
{
if (docAttr.Documentation != null)
{
this.m_writer.Write("<tr valign=\"top\"><td width=\"21%\"><span class=\"attr-name\">");
this.m_writer.Write(docAttr.Name);
this.m_writer.Write("</span></td><td width=\"1%\"> : </td><td>");
this.WriteDocumentationForISO(docAttr.Documentation, entity, suppresshistory);
this.m_writer.WriteLine("</td></tr>");
}
}
}
this.m_writer.WriteLine("</table>");
}
}
if (entity.WhereRules != null && entity.WhereRules.Count > 0)
{
// avoid attributes without descriptions
int cDescs = 0;
foreach (DocWhereRule docAttr in entity.WhereRules)
{
if (docAttr.Documentation != null)
{
cDescs++;
}
}
if (cDescs > 0)
{
// formal propositions
this.m_writer.WriteLine("<p class=\"spec-head\">Formal Propositions:</p>");
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocWhereRule docAttr in entity.WhereRules)
{
this.m_writer.Write("<tr valign=\"top\"><td width=\"21%\"><span class=\"attr-name\">");
this.m_writer.Write(docAttr.Name);
this.m_writer.Write("</span></td><td width=\"1%\"> : </td><td>");
if (docAttr.Documentation != null)
{
this.WriteDocumentationForISO(docAttr.Documentation, entity, suppresshistory);
}
this.m_writer.WriteLine("</td></tr>");
}
this.m_writer.WriteLine("</table>\r\n");
}
}
// inheritance
this.m_writer.WriteLine();
this.m_writer.WriteLine("<p class=\"spec-head\">Inheritance Graph:</p>");
this.m_writer.WriteLine("<span class=\"express\">");
this.WriteExpressLine(0, BEGIN_KEYWORD + "ENTITY" + END_KEYWORD + " " + entity.Name);
WriteExpressInheritance(entity, entity);
this.WriteExpressLine(0, BEGIN_KEYWORD + "END_ENTITY;" + END_KEYWORD);
this.m_writer.WriteLine("</span>");
}
public void WriteExpressEntity(DocEntity entity)
{
// build up list of subtypes from other schemas
SortedList<string, DocEntity> subtypes = new SortedList<string, DocEntity>(this); // use custom comparer to match with Visual Express ordering
// include from other schemas
foreach (DocObject eachdoc in this.m_mapEntity.Values)
{
if (eachdoc is DocEntity)
{
DocEntity eachent = (DocEntity)eachdoc;
if (eachent.BaseDefinition != null && eachent.BaseDefinition.Equals(entity.Name))
{
subtypes.Add(eachent.Name, eachent);
}
}
}
string noteAbstract = null;
string termEntity = "<b>;</b>";
string termSuper = "<b>;</b>";
if ((entity.EntityFlags & 0x20) == 0)
{
noteAbstract = BEGIN_KEYWORD + "ABSTRACT" + END_KEYWORD + " ";
termEntity = null;
}
if (subtypes.Count > 0 || (entity.Subtypes != null && entity.Subtypes.Count > 0))
{
termEntity = null;
}
if (entity.BaseDefinition != null)
{
termEntity = null;
termSuper = null;
}
this.WriteExpressLine(0, BEGIN_KEYWORD + "ENTITY" + END_KEYWORD + " " + entity.Name + termEntity);
if((entity.EntityFlags & 0x20) == 0 || subtypes.Count > 0 || (entity.Subtypes != null && entity.Subtypes.Count > 0))
{
if (subtypes.Count > 0)
{
StringBuilder sb = new StringBuilder();
// Capture all subtypes, not just those within schema
int countsub = 0;
foreach (string ds in subtypes.Keys)
{
DocEntity refent = subtypes[ds];
if (this.m_included == null || this.m_included.ContainsKey(refent))
{
countsub++;
if (sb.Length != 0)
{
sb.Append(", ");
}
sb.Append(this.FormatDefinition(ds));
}
}
if (countsub > 1)
{
this.WriteExpressLine(1, noteAbstract + BEGIN_KEYWORD + "SUPERTYPE OF" + END_KEYWORD + "(" + BEGIN_KEYWORD + "ONEOF" + END_KEYWORD + "(" + sb.ToString() + "))" + termSuper);
}
else if(countsub == 1)
{
this.WriteExpressLine(1, noteAbstract + BEGIN_KEYWORD + "SUPERTYPE OF" + END_KEYWORD + "(" + sb.ToString() + ")" + termSuper);
}
}
else
{
this.WriteExpressLine(1, noteAbstract + BEGIN_KEYWORD + "SUPERTYPE" + END_KEYWORD + termSuper);
}
}
if(entity.BaseDefinition != null)
{
this.WriteExpressLine(1, BEGIN_KEYWORD + "SUBTYPE OF" + END_KEYWORD + " (" + FormatDefinition(entity.BaseDefinition) + ")<b>;</b>");
}
WriteExpressAttributes(entity, null);
if (entity.UniqueRules != null && entity.UniqueRules.Count > 0)
{
this.WriteExpressLine(1, BEGIN_KEYWORD + "UNIQUE" + END_KEYWORD);
this.WriteExpressHeader(2);
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocUniqueRule docWhere in entity.UniqueRules)
{
this.m_writer.Write(" <tr valign=\"top\"><td width=\"20%\">");
this.m_writer.Write(docWhere.Name);
this.m_writer.Write("</td><td width=\"1%\"> : </td><td>");
foreach (DocUniqueRuleItem item in docWhere.Items)
{
if (item != docWhere.Items[0])
{
this.m_writer.Write(", ");
}
this.m_writer.Write(item.Name);
}
this.m_writer.Write(";</td></tr>");
}
this.m_writer.WriteLine("</table>");
this.WriteExpressFooter();
}
if (entity.WhereRules != null && entity.WhereRules.Count > 0)
{
this.WriteExpressLine(1, BEGIN_KEYWORD + "WHERE" + END_KEYWORD);
this.WriteExpressHeader(2);
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocWhereRule docWhere in entity.WhereRules)
{
string escaped = System.Security.SecurityElement.Escape(docWhere.Expression);
escaped = escaped.Replace("'", "'");
this.m_writer.Write(" <tr valign=\"top\"><td width=\"20%\">");
this.m_writer.Write(docWhere.Name);
this.m_writer.Write("</td><td width=\"1%\"> : </td><td>" + escaped + ";</td></tr>");
}
this.m_writer.WriteLine("</table>");
this.WriteExpressFooter();
}
WriteExpressLine(0, BEGIN_KEYWORD + "END_ENTITY;" + END_KEYWORD);
}
public void WriteExpressDiagram(DocDefinition docDef)
{
int diagramnumber = docDef.DiagramNumber;
string schema = null;
if (this.m_mapSchema.TryGetValue(docDef.Name, out schema))
{
if (Properties.Settings.Default.ExpressG)
{
// Per ISO doc requirement, use icon to link to diagram
this.m_writer.WriteLine(
"<p class=\"std\">" +
"<a href=\"../../../annex/annex-d/" + schema.ToLower() + "/diagram_" + diagramnumber.ToString("D4") +
".htm\" ><img src=\"../../../img/diagram.png\" style=\"border: 0px\" title=\"Link to EXPRESS-G diagram\" alt=\"Link to EXPRESS-G diagram\"> EXPRESS-G diagram</a>" +
"</p>");
}
}
}
// recurses up inheritance chain
private void WriteExpressInheritance(DocEntity entity, DocEntity treeleaf)
{
if (entity.BaseDefinition != null)
{
if (this.m_mapEntity.ContainsKey(entity.BaseDefinition))
{
DocEntity baseEntity = (DocEntity)this.m_mapEntity[entity.BaseDefinition];
WriteExpressInheritance(baseEntity, treeleaf);
}
}
WriteExpressLine(1, BEGIN_KEYWORD + "ENTITY" + END_KEYWORD + " " + FormatDefinition(entity.Name));
WriteExpressAttributes(entity, treeleaf);
}
public void WriteExpressTypeAndDocumentation(DocType type, bool suppresshistory, bool isoformat)
{
this.m_writer.WriteLine("<p class=\"spec-head\">EXPRESS Specification:</p>");
this.m_writer.WriteLine("<span class=\"express\">");
this.WriteExpressHeader(2);
// Per ISO doc requirement, comment tag
if (isoformat)
{
this.WriteExpressLine(0, "*)");
}
WriteExpressType(type);
if (isoformat)
{
this.WriteExpressLine(0, "(*");
}
WriteExpressFooter();
this.m_writer.WriteLine("</p>");
// link to EXPRESS-G
WriteExpressDiagram(type);
// where rules (for defined types)
if (type is DocDefined && ((DocDefined)type).WhereRules != null && ((DocDefined)type).WhereRules.Count > 0)
{
DocDefined entity = (DocDefined)type;
// formal propositions
this.m_writer.WriteLine("<p class=\"spec-head\">Formal Propositions:</p>");
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocWhereRule docAttr in entity.WhereRules)
{
if (docAttr.Documentation != null)
{
this.m_writer.Write("<tr valign=\"top\"><td width=\"21%\"><span class=\"attr-name\">");
this.m_writer.Write(docAttr.Name);
this.m_writer.Write("</span></td><td width=\"1%\"> : </td><td>");
this.WriteDocumentationForISO(docAttr.Documentation, entity, suppresshistory);
this.m_writer.WriteLine("</td></tr>");
}
}
this.m_writer.WriteLine("</table>");
}
this.m_writer.WriteLine("</span>");
}
public void WriteExpressType(DocType type)
{
if (type is DocEnumeration)
{
DocEnumeration docenum = (DocEnumeration)type;
this.WriteExpressLine(0, BEGIN_KEYWORD + "TYPE" + END_KEYWORD + " " + docenum.Name + " = " + BEGIN_KEYWORD + "ENUMERATION OF" + END_KEYWORD + " (");
this.WriteExpressHeader(2);
if (docenum.Constants != null)
{
foreach (DocConstant docconst in docenum.Constants)
{
this.m_writer.Write(docconst.Name);
if (docconst == docenum.Constants[docenum.Constants.Count - 1])
{
this.m_writer.Write(");");
}
else
{
this.m_writer.Write(", <br/>");
}
}
}
this.WriteExpressFooter();
}
else if (type is DocSelect)
{
DocSelect docenum = (DocSelect)type;
this.WriteExpressLine(0, BEGIN_KEYWORD + "TYPE" + END_KEYWORD + " " + docenum.Name + " = " + BEGIN_KEYWORD + "SELECT" + END_KEYWORD + " (");
this.WriteExpressHeader(2);
if (docenum.Selects != null)
{
bool previtem = false;
foreach (DocSelectItem docconst in docenum.Selects)
{
DocObject docref = null;
if (this.m_mapEntity.TryGetValue(docconst.Name, out docref))
{
if (this.m_included == null || this.m_included.ContainsKey(docref))
{
if (previtem)
{
this.m_writer.Write(", <br/>");
}
this.m_writer.Write(this.FormatDefinition(docconst.Name));
previtem = true;
}
}
}
if (previtem)
{
this.m_writer.Write(");");
}
}
this.WriteExpressFooter();
}
else if (type is DocDefined)
{
DocDefined docenum = (DocDefined)type;
string length = "";
if (docenum.Length > 0)
{
length = " (" + docenum.Length.ToString() + ")";
}
else if (docenum.Length < 0)
{
int len = -docenum.Length;
length = " (" + len.ToString() + ") FIXED";
}
WriteExpressHeader(0);
this.m_writer.Write(BEGIN_KEYWORD + "TYPE" + END_KEYWORD + " " + docenum.Name + " = ");
if (docenum.Aggregation != null)
{
this.WriteExpressAggregation(docenum.Aggregation);
}
this.m_writer.Write(FormatDefinition(docenum.DefinedType) + length + ";");
WriteExpressFooter();
this.WriteExpressHeader(2);
if (docenum.WhereRules != null && docenum.WhereRules.Count > 0)
{
this.WriteExpressLine(1, BEGIN_KEYWORD + "WHERE" + END_KEYWORD);
this.WriteExpressHeader(2);
this.m_writer.WriteLine("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" class=\"express\">");
foreach (DocWhereRule docWhere in docenum.WhereRules)
{
string escaped = System.Security.SecurityElement.Escape(docWhere.Expression);
escaped = escaped.Replace("'", "'");
this.m_writer.Write(" <tr valign=\"top\"><td width=\"20%\">");
this.m_writer.Write(docWhere.Name);
this.m_writer.Write("</td><td width=\"1%\"> : </td><td>" + escaped + "<td/></tr>");
}
this.m_writer.WriteLine("</table>");
this.WriteExpressFooter();
}
this.WriteExpressFooter();
}
WriteExpressLine(0, BEGIN_KEYWORD + "END_TYPE;" + END_KEYWORD);
}
public void WriteExpressFunction(DocFunction entity)
{
this.WriteLine("<p>");
this.WriteLine(BEGIN_KEYWORD + "FUNCTION" + END_KEYWORD + " " + entity.Name + "<br/>\r\n");