-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathFormSelectTemplate.cs
142 lines (124 loc) · 4.31 KB
/
FormSelectTemplate.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
// Name: FormSelectTemplate.cs
// Description: Dialog box for selecting template
// Author: Tim Chipman
// Origination: Work performed for BuildingSmart by Constructivity.com LLC.
// Copyright: (c) 2011 BuildingSmart International Ltd.
// License: http://www.buildingsmart-tech.org/legal
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IfcDoc.Schema.DOC;
namespace IfcDoc
{
public partial class FormSelectTemplate : Form
{
DocTemplateDefinition m_selection;
DocProject m_project;
public FormSelectTemplate()
{
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="selection">Selected template.</param>
/// <param name="project">Projet containing templates.</param>
/// <param name="entity">The entity for which templates are filtered.</param>
public FormSelectTemplate(DocTemplateDefinition selection, DocProject project, DocEntity entity)
: this()
{
this.m_selection = selection;
this.m_project = project;
// build map
Dictionary<string, DocObject> map = new Dictionary<string, DocObject>();
foreach (DocSection docSection in this.m_project.Sections)
{
foreach (DocSchema docSchema in docSection.Schemas)
{
foreach (DocEntity docEntity in docSchema.Entities)
{
map.Add(docEntity.Name, docEntity);
}
foreach (DocType docType in docSchema.Types)
{
map.Add(docType.Name, docType);
}
}
}
foreach (DocTemplateDefinition docTemplate in project.Templates)
{
bool include = false;
// check for inheritance
DocObject docApplicableEntity = null;
if (entity == null)
{
include = true;
}
else if (docTemplate.Type != null && map.TryGetValue(docTemplate.Type, out docApplicableEntity) && docApplicableEntity is DocEntity)
{
// check for inheritance
DocEntity docBase = entity;
while (docBase != null)
{
if (docBase == docApplicableEntity)
{
include = true;
break;
}
if (docBase.BaseDefinition == null)
break;
DocObject docEach = null;
if (map.TryGetValue(docBase.BaseDefinition, out docEach))
{
docBase = (DocEntity)docEach;
}
else
{
docBase = null;
}
}
}
if (include)
{
LoadTemplate(null, docTemplate);
}
}
}
private void LoadTemplate(TreeNode tnParent, DocTemplateDefinition template)
{
// add entity
TreeNode tn = new TreeNode();
tn.Tag = template;
tn.Text = template.Name;
if (tnParent != null)
{
tnParent.Nodes.Add(tn);
}
else
{
this.treeView.Nodes.Add(tn);
}
if (this.m_selection == template)
{
this.treeView.SelectedNode = tn;
}
foreach (DocTemplateDefinition sub in template.Templates)
{
LoadTemplate(tn, sub);
}
}
public DocTemplateDefinition SelectedTemplate
{
get
{
if (this.treeView.SelectedNode == null)
return null;
return this.treeView.SelectedNode.Tag as DocTemplateDefinition;
}
}
}
}