-
Notifications
You must be signed in to change notification settings - Fork 64
/
FormatIFD.cs
132 lines (112 loc) · 3.98 KB
/
FormatIFD.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
// Name: FormatIFD.cs
// Description: Text file import/export for IFD guids
// Author: Tim Chipman
// Origination: Work performed for BuildingSmart by Constructivity.com LLC.
// Copyright: (c) 2012 BuildingSmart International Ltd.
// License: http://www.buildingsmart-tech.org/legal
using System;
using System.Collections.Generic;
using System.Text;
using IfcDoc.Schema.DOC;
namespace IfcDoc
{
internal class FormatIFD : IDisposable
{
string m_filename;
DocProject m_project;
public FormatIFD(string filename)
{
this.m_filename = filename;
}
public DocProject Instance
{
get
{
return this.m_project;
}
set
{
this.m_project = value;
}
}
public void Load()
{
// prepare map
Dictionary<string, DocPropertySet> map = new Dictionary<string, DocPropertySet>();
foreach (DocSection docSection in this.m_project.Sections)
{
foreach (DocSchema docSchema in docSection.Schemas)
{
foreach (DocPropertySet docEntity in docSchema.PropertySets)
{
map.Add(docEntity.Name, docEntity);
}
}
}
// use commas for simplicity
using (System.IO.StreamReader reader = new System.IO.StreamReader(this.m_filename))
{
string headerline = reader.ReadLine(); // blank
// now rows
while (!reader.EndOfStream)
{
string rowdata = reader.ReadLine();
string[] rowcells = rowdata.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (rowcells.Length > 1)
{
DocPropertySet docObj = null;
string ifdguid = rowcells[0];
string ifdname = rowcells[1];
Guid guid = IfcGloballyUniqueId.Parse(ifdguid);
string[] nameparts = ifdname.Split('.');
string psetname = nameparts[0].Trim();
string propname = null;
if (nameparts.Length == 2)
{
propname = nameparts[1];
}
if (map.TryGetValue(psetname, out docObj))
{
if (propname != null)
{
foreach (DocProperty docprop in docObj.Properties)
{
if (propname.Equals(docprop.Name))
{
// found it
docprop.Uuid = guid;
break;
}
}
}
else
{
docObj.Uuid = guid;
}
}
else
{
System.Diagnostics.Debug.WriteLine("IFD (not found): " + psetname);
}
}
}
}
}
public void Save()
{
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(this.m_filename))
{
// header
writer.WriteLine();
SortedList<string, DocObject> sortlist = new SortedList<string, DocObject>();
// rows
//...
}
}
#region IDisposable Members
public void Dispose()
{
}
#endregion
}
}