-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentationISO.cs
5914 lines (5099 loc) · 343 KB
/
DocumentationISO.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: DocumentationISO.cs
// Description: Generates documentation
// 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.ComponentModel;
using System.Drawing;
using System.Text;
using System.Xml.Serialization;
using IfcDoc.Schema;
using IfcDoc.Schema.DOC;
using IfcDoc.Schema.PSD;
using IfcDoc.Schema.MVD;
using IfcDoc.Format.EXP;
using IfcDoc.Format.CSC;
using IfcDoc.Format.JAV;
using IfcDoc.Format.JSN;
using IfcDoc.Format.HTM;
using IfcDoc.Format.XSD;
using IfcDoc.Format.XML;
using IfcDoc.Format.SML;
using IfcDoc.Format.SPF;
using IfcDoc.Format.PNG;
namespace IfcDoc
{
public static class DocumentationISO
{
/// <summary>
/// Capture link to table or figure
/// </summary>
public struct ContentRef
{
public string Caption; // caption to be displayed in table of contents
public DocObject Page; // relative link to reference
public ContentRef(string caption, DocObject page)
{
this.Caption = caption;
this.Page = page;
}
}
/// <summary>
/// Exports file according to format.
/// </summary>
/// <param name="filepath">File path to export.</param>
/// <param name="templates">Optional filter of templates to export.</param>
/// <param name="views">Optional filter of views to export, where first one indicates primary view (for defining schema).</param>
/// <param name="schemas">Optional filter of schemas to export.</param>
/// <param name="locales">Optional filter of locales to export.</param>
public static void DoExport(DocProject docProject, DocPublication docPublication, string filepath, DocModelView[] views, string[] locales, DocDefinitionScopeEnum scope, Dictionary<long, SEntity> instances,
Dictionary<string, DocObject> mapEntity)
{
string ext = System.IO.Path.GetExtension(filepath).ToLower();
string xmlns = null;
Dictionary<DocObject, bool> included = null;
if (views != null)
{
included = new Dictionary<DocObject, bool>();
foreach (DocModelView docView in views)
{
docProject.RegisterObjectsInScope(docView, included);
}
xmlns = views[0].XsdUri;
}
// special case for zip files -- determine based on special naming; make configurable in future
Type typeExport = null;
if (filepath.EndsWith("-psd.zip_"))
{
typeExport = typeof(DocPropertySet);
}
else if(filepath.EndsWith("-qto.zip_"))
{
typeExport = typeof(DocQuantitySet);
}
switch (ext)
{
case ".ifc":
Program.t_lastid = 0;
Program.t_instances = new Dictionary<long, SEntity>();
SEntity.EntityCreated += Program.SEntity_EntityCreated;
try
{
using (FormatSPF format = new FormatSPF(filepath, Schema.IFC.SchemaIfc.Types, Program.t_instances))
{
string filename = System.IO.Path.GetFileName(filepath);
format.InitHeaders(filename, docProject.GetSchemaIdentifier());
Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
Program.ExportIfc(ifcProject, docProject, included);
format.Save();
}
}
finally
{
SEntity.EntityCreated -= Program.SEntity_EntityCreated;
}
break;
case ".ifcxml":
using (FormatXML format = new FormatXML(filepath, typeof(Schema.IFC.IfcProject), xmlns))
{
Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
Program.ExportIfc(ifcProject, docProject, included);
format.Instance = ifcProject;
format.Save();
}
break;
case ".mvdxml":
using (FormatXML format = new FormatXML(filepath, typeof(mvdXML), mvdXML.DefaultNamespace))
{
mvdXML mvd = new mvdXML();
Program.ExportMvd(mvd, docProject, mapEntity, included);
format.Instance = mvd;
format.Save();
}
break;
case ".cs":
using (FormatCSC format = new FormatCSC(filepath))
{
format.Instance = docProject;
format.Map = mapEntity;
format.Save();
}
break;
case ".exp":
// use currently visible model view(s)
using (FormatEXP format = new FormatEXP(filepath))
{
format.Instance = docProject;
format.ModelViews = views;
format.Save();
}
break;
case ".xsd":
// use currently visible model view(s)
using (FormatXSD format = new FormatXSD(filepath))
{
format.Project = docProject;
format.Publication = docPublication;
format.ModelViews = views;
format.Save();
}
break;
case ".xml": // Express XSD Configuration
using (FormatXML format = new FormatXML(filepath, typeof(Schema.CNF.configuration), null, Schema.CNF.SchemaCNF.Prefixes))
{
Schema.CNF.configuration config = new Schema.CNF.configuration();
Program.ExportCnf(config, docProject, views, included);
format.Instance = config;
format.Save();
}
break;
case ".txt":
// pick locale
using (FormatCSV format = new FormatCSV(filepath))
{
format.Instance = docProject;
format.Locales = locales;
format.Scope = scope;
format.Save();
}
break;
case ".sch":
using (FormatXML format = new FormatXML(filepath, typeof(Schema.SCH.schema), "http://purl.oclc.org/dsdl/schematron"))
{
Schema.SCH.schema sch = new Schema.SCH.schema();
Program.ExportSch(sch, docProject, included);
format.Instance = sch;
format.Save();
}
break;
case ".zip":
case ".zip_":
using (FormatZIP format = new FormatZIP(new System.IO.FileStream(filepath, System.IO.FileMode.Create), docProject, included, typeExport))
{
format.Save();
}
break;
}
}
/// <summary>
/// Copies files and folders recursively, skipping those that already exist.
/// </summary>
/// <param name="sourcepath">Path of source directory</param>
/// <param name="targetpath">Path of target directory</param>
private static void CopyFiles(string sourcepath, string targetpath)
{
if (!System.IO.Directory.Exists(sourcepath))
return;
string[] arrFiles = System.IO.Directory.GetFiles(sourcepath);
foreach (string sourcefile in arrFiles)
{
string filename = System.IO.Path.GetFileName(sourcefile);
string targetfile = System.IO.Path.Combine(targetpath, filename);
try
{
if (!System.IO.File.Exists(targetfile))
{
System.IO.File.Copy(sourcefile, targetfile);
}
}
catch
{
}
}
string[] arrDirectories = System.IO.Directory.GetDirectories(sourcepath);
foreach (string sourcedir in arrDirectories)
{
string dirname = System.IO.Path.GetFileName(sourcedir);
string targetdir = System.IO.Path.Combine(targetpath, dirname);
try
{
if (!System.IO.Directory.Exists(targetdir))
{
System.IO.Directory.CreateDirectory(targetdir);
}
}
catch
{
}
CopyFiles(sourcedir, targetdir);
}
}
/// <summary>
/// Builds list of items in order, using inherited concepts.
/// </summary>
/// <param name="entity"></param>
/// <param name="template"></param>
/// <param name="view"></param>
private static DocTemplateItem[] FindTemplateItems(DocProject docProject, DocEntity entity, DocTemplateDefinition template, DocModelView view)
{
// inherited concepts first
List<DocTemplateItem> listItems = new List<DocTemplateItem>();
DocEntity basetype = entity;
bool inherit = true;
while (basetype != null)
{
// find templates for base
foreach (DocModelView docView in docProject.ModelViews)
{
if (view == docView || view.BaseView == docView.Name)
{
foreach (DocConceptRoot docRoot in docView.ConceptRoots)
{
if (docRoot.ApplicableEntity == basetype)
{
foreach (DocTemplateUsage eachusage in docRoot.Concepts)
{
if (eachusage.Definition == template)
{
// found it
string[] parameters = template.GetParameterNames();
foreach (DocTemplateItem eachitem in eachusage.Items)
{
string[] values = new string[parameters.Length];
for (int iparam = 0; iparam < parameters.Length; iparam++)
{
values[iparam] = eachitem.GetParameterValue(parameters[iparam]);
}
// new (IfcDoc 4.9d): only add if we don't override by parameters matching exactly
bool include = true;
foreach (DocTemplateItem existitem in listItems)
{
bool samevalues = true;
for (int iparam = 0; iparam < parameters.Length; iparam++)
{
string value = values[iparam];
string match = existitem.GetParameterValue(parameters[iparam]);
if (match != value || (match != null && !match.Equals(value, StringComparison.Ordinal)))
{
samevalues = false;
break;
}
}
if (samevalues)
{
include = false;
break;
}
}
if (include)
{
listItems.Add(eachitem);
}
}
inherit = !eachusage.Override;
}
}
}
}
}
}
// inherit concepts from supertypes unless overriding
if (basetype.BaseDefinition != null && inherit)
{
basetype = docProject.GetDefinition(basetype.BaseDefinition) as DocEntity;
}
else
{
basetype = null;
}
}
return listItems.ToArray();
}
/// <summary>
/// Formats table for single exchange
/// </summary>
/// <param name="def"></param>
/// <returns></returns>
private static string FormatExchange(DocProject docProject, DocModelView docView, DocExchangeDefinition def, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, DocPublication docPublication)
{
// format content
StringBuilder sbMain = new StringBuilder();
if(!String.IsNullOrEmpty(def.ExchangeClass))
{
sbMain.AppendLine("<table class=\"gridtable\">");
sbMain.AppendLine("<tr><th>Process</th><th>Sender</th><th>Receiver</th></tr>");
sbMain.AppendLine("<tr><td>" + def.ExchangeClass + "</td><td>" + def.SenderClass + "</td><td>" + def.ReceiverClass + "</td></tr>");
sbMain.AppendLine("</table>");
}
// 1. manual content
sbMain.Append(def.Documentation);
// 2. map of entities and templates -- Identity | Template | Import | Export
sbMain.AppendLine("<p></p>");//This exchange involves the following entities:</p>");
SortedList<string, DocConceptRoot> sortlist = new SortedList<string, DocConceptRoot>();
foreach (DocConceptRoot docRoot in docView.ConceptRoots)
{
foreach (DocTemplateUsage docUsage in docRoot.Concepts)
{
foreach (DocExchangeItem docReq in docUsage.Exchanges)
{
//if (docReq.Exchange == def && docReq.Requirement != DocExchangeRequirementEnum.NotRelevant && docReq.Requirement != DocExchangeRequirementEnum.Excluded && !sortlist.ContainsKey(docRoot.ApplicableEntity.Name))
if (docReq.Exchange == def && docReq.Requirement != DocExchangeRequirementEnum.NotRelevant && !sortlist.ContainsKey(docRoot.ApplicableEntity.Name))
{
sortlist.Add(docRoot.ApplicableEntity.Name, docRoot);
}
}
}
}
bool externaldataconstraints = false;
// new style - table
StringBuilder sb = new StringBuilder();
sb.AppendLine("<table class=\"exchange\">");
sb.AppendLine("<tr><th colspan=\"5\"><img src=\"../../../img/mvd-" + MakeLinkName(def) + ".png\" /> " + def.Name + "</th></tr>");
sb.AppendLine("<tr><th>Entity/Concept</th><th>Attributes</th><th>Constraints</th><th>I</th><th>E</th></tr>");
foreach (string ent in sortlist.Keys)
{
DocConceptRoot docRoot = sortlist[ent];
sb.Append("<tr><td colspan=\"5\"><b><i>");
sb.Append(docRoot.ApplicableEntity.Name);
sb.AppendLine("</i></b></td></tr>");
// determine schema
string schema = mapSchema[ent];
foreach (DocTemplateUsage docConcept in docRoot.Concepts)
{
if (docConcept.Definition != null)
{
DocExchangeRequirementEnum reqImport = DocExchangeRequirementEnum.NotRelevant;
DocExchangeRequirementEnum reqExport = DocExchangeRequirementEnum.NotRelevant;
foreach (DocExchangeItem docReq in docConcept.Exchanges)
{
if (docReq.Exchange == def)
{
if (docReq.Applicability == DocExchangeApplicabilityEnum.Export)
{
reqExport = docReq.Requirement;
}
else if (docReq.Applicability == DocExchangeApplicabilityEnum.Import)
{
reqImport = docReq.Requirement;
}
}
}
if (reqImport != DocExchangeRequirementEnum.NotRelevant || reqExport != DocExchangeRequirementEnum.NotRelevant)
{
if (docConcept.Definition.Uuid.Equals(DocTemplateDefinition.guidTemplateMapping))// Name.Equals("External Data Constraints"))
{
if(!externaldataconstraints)
{
// show heading for first time
sbMain.Append("<h4>Data Requirements for tabular formats</h4>");
externaldataconstraints = true;
}
// new for GSA: cross-tab report to show mappings between exchanges and applications and vice-versa
List<DocModelView> listViewCross = new List<DocModelView>();
if (true)//docPublication.Comparison)
{
foreach (DocModelView docEachView in docPublication.Views)
{
if (docEachView != docView )
{
listViewCross.Add(docEachView);
}
}
}
// table and description
sbMain.AppendLine("<a id=\"" + MakeLinkName(docConcept) + "\"/>");
sbMain.Append("<h5>" + docConcept.Name + "</h5>");
sbMain.Append(docConcept.Documentation);
sbMain.AppendLine("<table class=\"gridtable\">");
sbMain.Append("<tr><th>Column</th><th>Mapping</th><th>Definition</th><th>Notes</th>");
foreach(DocModelView docViewCross in listViewCross)
{
foreach (DocExchangeDefinition docExchangeCross in docViewCross.Exchanges)
{
sbMain.Append("<th><a href=\"../../views/");
sbMain.Append(MakeLinkName(docViewCross));
sbMain.Append("/");
sbMain.Append(MakeLinkName(docExchangeCross));
sbMain.Append(".htm\"><img width=\"16\" src=\"../../../img/mvd-");
sbMain.Append(MakeLinkName(docExchangeCross));
sbMain.Append(".png\" title=\"");
sbMain.Append(docExchangeCross.Name);
sbMain.Append("\"/></a></th>");
}
}
sbMain.AppendLine("</tr>");
foreach(DocTemplateItem docItem in docConcept.Items)
{
string name = docItem.GetParameterValue("Name");
string refv = docItem.GetParameterValue("Reference");
string disp = "#" + docItem.GetColor().ToArgb().ToString("X8").Substring(2, 6); //docItem.GetParameterValue("Color");
string mapp = FormatReference(docProject, refv);
string desc = "";
CvtValuePath valpath = CvtValuePath.Parse(refv, mapEntity);
if (valpath != null)
{
desc = valpath.GetDescription(mapEntity, docView);
}
//int colorval = 0;
string style = "";
if (!String.IsNullOrEmpty(disp))// && disp.StartsWith("#") && Int32.TryParse(disp.Substring(1), out colorval))
{
// interpret colors as disposition -- todo: migrate to well-defined values
style = " style=\"background-color:" + disp + ";\"";
}
sbMain.Append("<tr><td" + style + ">" + name + "</td><td>" + mapp + "</td><td>" + desc + "</td><td>" + docItem.Documentation + "</td>");
foreach (DocModelView docViewCross in listViewCross)
{
foreach (DocExchangeDefinition docExchangeCross in docViewCross.Exchanges)
{
// find any table in that exchange containing a matching mapping
sbMain.Append("<td>");
foreach (DocConceptRoot docRootCross in docViewCross.ConceptRoots)
{
foreach (DocTemplateUsage docConceptCross in docRootCross.Concepts)
{
if (docConceptCross.Definition != null && docConceptCross.Definition.Uuid.Equals(DocTemplateDefinition.guidTemplateMapping))//Name.Equals("External Data Constraints"))
{
DocExchangeRequirementEnum reqImportCross = DocExchangeRequirementEnum.NotRelevant;
DocExchangeRequirementEnum reqExportCross = DocExchangeRequirementEnum.NotRelevant;
foreach (DocExchangeItem docReq in docConceptCross.Exchanges)
{
if (docReq.Exchange == docExchangeCross)
{
if (docReq.Applicability == DocExchangeApplicabilityEnum.Export)
{
reqExportCross = docReq.Requirement;
}
else if (docReq.Applicability == DocExchangeApplicabilityEnum.Import)
{
reqImportCross = docReq.Requirement;
}
}
}
// found it, now look for any matching data mappings
if (reqImportCross != DocExchangeRequirementEnum.NotRelevant || reqExportCross != DocExchangeRequirementEnum.NotRelevant)
{
foreach (DocTemplateItem docItemCross in docConceptCross.Items)
{
string crossrefv = docItemCross.GetParameterValue("Reference");
if (crossrefv != null && crossrefv.Equals(refv))
{
string crosstabl = docItemCross.GetParameterValue("Table");
string crossname = docItemCross.GetParameterValue("Name");
sbMain.Append("<a href=\"../../views/");
sbMain.Append(MakeLinkName(docViewCross));
sbMain.Append("/");
sbMain.Append(MakeLinkName(docExchangeCross));
sbMain.Append(".htm\"><img width=\"16\" src=\"../../../img/attr-mandatory");
sbMain.Append(".png\" title=\"");
sbMain.Append(docExchangeCross.Name + ": " + crosstabl + "." + crossname);
sbMain.Append("\"/></a>");
//sbMain.Append(crosstabl + "." + crossname); //... use icon to show import or export, with tooltip showing name...
break;
}
}
}
}
}
}
sbMain.Append("</td>");
}
}
sbMain.AppendLine("</tr>");
}
sbMain.AppendLine("</table>");
// bring out separately
//string table = FormatConceptTable(docProject, docView, docRoot.ApplicableEntity, docRoot, docConcept, mapEntity, mapSchema);
//sbMain.Append(table);
}
else
{
sb.Append("<tr><td> <a href=\"../../templates/");
sb.Append(MakeLinkName(docConcept.Definition));
sb.Append(".htm\">");
sb.Append(docConcept.Definition.Name);
sb.Append("</a></td><td>");
bool first = true;
if (docConcept.Definition.Rules != null)
{
foreach (DocModelRule docRule in docConcept.Definition.Rules)
{
if (!first)
{
sb.Append("<br/>");
}
sb.Append(docRule.Name);
first = false;
}
}
sb.Append("</td><td>");
string table = FormatConceptTable(docProject, docView, docRoot.ApplicableEntity, docRoot, docConcept, mapEntity, mapSchema);
sb.Append(table);
sb.Append("</td><td>");
AppendRequirement(sb, reqImport, 3);
sb.Append("</td><td>");
AppendRequirement(sb, reqExport, 3);
sb.AppendLine("</td></tr>");
}
}
}
}
}
sb.AppendLine("</table>");
// then general table for IFC
sbMain.AppendLine("<h4>Data Requirements for IFC formats</h4>");
sbMain.Append(sb.ToString());
return sbMain.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="docTemplate"></param>
/// <param name="path">Path of templates</param>
/// <param name="mapEntity"></param>
/// <param name="mapSchema"></param>
private static void GenerateTemplateLink(List<DocTemplateDefinition> path, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, Dictionary<DocObject, bool> included, DocPublication docPublication, string dirpath)
{
DocTemplateDefinition docTemplateLast = path[path.Count - 1];
if (included != null && !included.ContainsKey(docTemplateLast))
return;
// flat list -- requires unique template names
StringBuilder sbFile = new StringBuilder();
sbFile.Append(dirpath);
sbFile.Append(@"\link\");
sbFile.Append(MakeLinkName(docTemplateLast));
sbFile.Append(".htm");
StringBuilder sbLink = new StringBuilder();
sbLink.Append("../schema/templates/");
sbLink.Append(MakeLinkName(docTemplateLast));
sbLink.Append(".htm");
using (FormatHTM htmLink = new FormatHTM(sbFile.ToString(), mapEntity, mapSchema, included))
{
htmLink.WriteLinkPage(sbLink.ToString(), docPublication);
}
if (docTemplateLast.Templates != null)
{
foreach (DocTemplateDefinition docSub in docTemplateLast.Templates)
{
path.Add(docSub);
GenerateTemplateLink(path, mapEntity, mapSchema, included, docPublication, dirpath);
path.RemoveAt(path.Count - 1);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="docTemplate"></param>
/// <param name="path">Path of templates</param>
/// <param name="mapEntity"></param>
/// <param name="mapSchema"></param>
private static void GenerateExampleLink(List<DocExample> path, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, Dictionary<DocObject, bool> included, DocPublication docPublication, string dirpath)
{
DocExample docTemplateLast = path[path.Count - 1];
if (included != null && !included.ContainsKey(docTemplateLast))
return;
// flat list -- requires unique template names
StringBuilder sbFile = new StringBuilder();
sbFile.Append(dirpath);
sbFile.Append(@"\link\");
sbFile.Append(MakeLinkName(docTemplateLast));
sbFile.Append(".htm");
StringBuilder sbLink = new StringBuilder();
sbLink.Append("../annex/annex-e/");
sbLink.Append(MakeLinkName(docTemplateLast));
sbLink.Append(".htm");
using (FormatHTM htmLink = new FormatHTM(sbFile.ToString(), mapEntity, mapSchema, included))
{
htmLink.WriteLinkPage(sbLink.ToString(), docPublication);
}
if (docTemplateLast.Examples != null)
{
foreach (DocExample docSub in docTemplateLast.Examples)
{
path.Add(docSub);
GenerateExampleLink(path, mapEntity, mapSchema, included, docPublication, dirpath);
path.RemoveAt(path.Count - 1);
}
}
}
private static string FormatDiagram(DocProject docProject, DocObject def, DocModelView docView, List<ContentRef> listFigures, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, string path)
{
// return if nothing to generate
if (def is DocTemplateDefinition)
{
DocTemplateDefinition dtd = (DocTemplateDefinition)def;
if (dtd.Rules == null || dtd.Rules.Count == 0)
return null;
}
else if (def is DocEntity)
{
}
else
{
return null;
}
// create the figure file
string filename = MakeLinkName(def) + ".png";
Dictionary<Rectangle, SEntity> layout = new Dictionary<Rectangle, SEntity>();
{
try
{
if (def is DocTemplateDefinition)
{
System.IO.Directory.CreateDirectory(path + "\\schema\\templates\\diagrams");
using (Image image = IfcDoc.Format.PNG.FormatPNG.CreateTemplateDiagram((DocTemplateDefinition)def, mapEntity, layout, docProject, null))
{
if (image != null)
{
string filepath = path + "\\schema\\templates\\diagrams\\" + filename;
image.Save(filepath, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
else if (def is DocEntity) // no longer used directly; now for each model view in annex D
{
System.IO.Directory.CreateDirectory(path + "\\diagrams\\" + MakeLinkName(docView));
using (Image image = IfcDoc.Format.PNG.FormatPNG.CreateConceptDiagram((DocEntity)def, docView, mapEntity, layout, docProject, null))
{
string filepath = path + "\\diagrams\\" + MakeLinkName(docView) + "\\" + filename;
image.Save(filepath, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
catch
{
}
}
// 2. figure
StringBuilder sb = new StringBuilder();
if (def is DocTemplateDefinition)
{
listFigures.Add(new ContentRef(def.Name + " instance diagram", def));
// Per ISO guidelines, all figures must be referenced from text.
sb.Append("<p class=\"fig-ref\">Figure ");
sb.Append(listFigures.Count);
sb.Append(" illustrates an instance diagram.</p>\r\n");
}
// include the figure with formatting below per ISO
sb.Append("<table><tr><td><img alt=\"");
sb.Append(def.Name);
if (def is DocTemplateDefinition)
{
sb.Append("\" src=\"./diagrams/");
}
else
{
sb.Append("\" src=\"../../../diagrams/");
sb.Append(MakeLinkName(docView));
sb.Append("/");
}
sb.Append(filename);
sb.Append("\" usemap=\"#f");
sb.Append(listFigures.Count.ToString());
sb.Append("\">");
sb.Append("<map name=\"f");
sb.Append(listFigures.Count.ToString());
sb.Append("\">");
foreach (Rectangle rc in layout.Keys)
{
SEntity target = layout[rc];
DocModelRule rule = target as DocModelRule;
DocObject ruleObject = null;
string strschema = null;
string typename = null;
if (rule != null)
{
typename = rule.Name;
}
else if (def is DocTemplateDefinition)
{
DocTemplateDefinition dtd = (DocTemplateDefinition)def;
typename = dtd.Type;
}
else if (def is DocObject)
{
typename = def.Name;
}
string caption = null;
string hyperlink = null;
if (target is DocTemplateDefinition)
{
DocTemplateDefinition dtd = (DocTemplateDefinition)target;
string relative = @"./";
if (def is DocEntity)
{
relative = "../../../schema/templates/";
}
caption = dtd.Name;
hyperlink = relative + MakeLinkName(dtd) + ".htm";
}
else if (typename != null && mapEntity.TryGetValue(typename, out ruleObject) && mapSchema.TryGetValue(typename, out strschema))
{
string relative = @"../";
if (def is DocEntity)
{
relative = "../../../schema/";
}
// hyperlink to IFC entity
// replace it with hyperlink
caption = ruleObject.Name;
hyperlink = relative + strschema.ToLower() + @"/lexical/" + ruleObject.Name.ToLower() + ".htm";
}
if (hyperlink != null)
{
int indent = 0;
sb.Append("<area shape=\"rect\" coords=\"");
sb.Append(rc.Left + indent);
sb.Append(",");
sb.Append(rc.Top + indent);
sb.Append(",");
sb.Append(rc.Right + indent);
sb.Append(",");
sb.Append(rc.Bottom + indent);
sb.Append("\" href=\"");
sb.Append(hyperlink);
sb.Append("\" alt=\"");
sb.Append(caption);
sb.Append("\" />");
}
}
sb.Append("</map>");
// number figures in templates, but not annex
if (def is DocTemplateDefinition)
{
sb.Append("</td></tr>");
sb.Append("<tr><td><p class=\"figure\">Figure ");
sb.Append(listFigures.Count);
sb.Append(" — ");
sb.Append(def.Name);
sb.Append("</p></td></tr>");
}
sb.Append("</table>\r\n");
sb.AppendLine();
return sb.ToString();
}
private static string FormatTemplate(
DocProject docProject,
DocTemplateDefinition def,
List<ContentRef> listFigures,
List<ContentRef> listTables,
Dictionary<string, DocObject> mapEntity,
Dictionary<string, string> mapSchema,
Dictionary<DocObject, bool> included,
string path)
{
// format content
StringBuilder sb = new StringBuilder();
// 1. manual content
sb.Append(def.Documentation);
// 2. instance diagram
sb.Append(FormatDiagram(docProject, def, null, listFigures, mapEntity, mapSchema, path));
// 3. entity list
{
foreach (DocModelView docView in docProject.ModelViews)
{
if ((included == null || included.ContainsKey(docView)) && docView.Exchanges.Count > 0)
{
SortedList<string, DocTemplateUsage> mapUsage = new SortedList<string, DocTemplateUsage>();
foreach (DocConceptRoot docRoot in docView.ConceptRoots)
{
foreach (DocTemplateUsage docUsage in docRoot.Concepts)
{
if (docUsage.Definition == def && !mapUsage.ContainsKey(docRoot.ApplicableEntity.Name))
{
mapUsage.Add(docRoot.ApplicableEntity.Name, docUsage);
}
}
}
if (mapUsage.Count > 0)
{
sb.AppendLine("<hr/>");
sb.AppendLine("<h4>" + docView.Name + "</h4>");
int cExchange = docView.Exchanges.Count;
sb.AppendLine("<table class=\"exchange\">");
sb.Append("<tr><th>Entity</th>");
if (true)//Properties.Settings.Default.Requirement)
{
foreach (DocExchangeDefinition docExchange in docView.Exchanges)
{
sb.Append("<th><a href=\"../views/");
sb.Append(MakeLinkName(docView));
sb.Append("/");
sb.Append(MakeLinkName(docExchange));
sb.Append(".htm\"><img width=\"16\" src=\"../../img/mvd-");
sb.Append(MakeLinkName(docExchange));
sb.Append(".png\" title=\"");
sb.Append(docExchange.Name);
sb.Append("\"/></a></th>");
sb.AppendLine();
}
}
sb.Append("</tr>");
foreach (string entname in mapUsage.Keys)
{
DocTemplateUsage docUsage = mapUsage[entname];
if (docUsage.Definition == def)
{
sb.Append("<tr><td><i>");
sb.Append(entname);
sb.Append("</i></td>");
if (true)//Properties.Settings.Default.Requirement)
{
foreach (DocExchangeDefinition docExchange in docView.Exchanges)
{
sb.Append("<td>");
DocExchangeRequirementEnum reqImport = DocExchangeRequirementEnum.NotRelevant;
DocExchangeRequirementEnum reqExport = DocExchangeRequirementEnum.NotRelevant;
foreach (DocExchangeItem dti in docUsage.Exchanges)
{
if (dti.Exchange == docExchange)
{
if (dti.Applicability == DocExchangeApplicabilityEnum.Import)
{
reqImport = dti.Requirement;
}
else if (dti.Applicability == DocExchangeApplicabilityEnum.Export)
{
reqExport = dti.Requirement;
}
}
}
AppendRequirement(sb, reqImport, 2);
sb.Append("<br/>");
AppendRequirement(sb, reqExport, 2);
sb.Append("</td>");
sb.AppendLine();
}
}
sb.AppendLine("</tr>");
}
}
sb.AppendLine("</table>");
}
}
}
}
return sb.ToString();
}
private static string FormatRequirements(DocTemplateUsage eachusage, DocModelView docModel, bool showexchanges)
{
if (eachusage.Exchanges == null || eachusage.Exchanges.Count == 0 && (eachusage.Items.Count == 0 || eachusage.Definition.Type == ""))
return null; // don't show if no rules or exchanges
//if (!Properties.Settings.Default.Requirement)
// return String.Empty;
StringBuilder sb = new StringBuilder();