-
Notifications
You must be signed in to change notification settings - Fork 19
/
Element.cs
151 lines (144 loc) · 4.21 KB
/
Element.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
using System;
using System.Collections;
namespace DXFLibrary
{
/// <summary>
/// This represent an DXF element in general. "Element" is an abstrat concept introduced by us to
/// describe everything in DXF that contains Data ( and/or other Elements ).
/// Most DXF library classes are derived from this class.
/// Examples of classes derived from this class are SECTION, LINE, TABLE, POLYLINE, VERTEX...
/// </summary>
public abstract class Element
{
internal Data startTag = new Data(-10,0);
internal Data endTag = new Data(-10,0);
protected ArrayList data;
protected ArrayList elements;
protected ArrayList dataAcceptanceList;
protected ArrayList elementAcceptanceList;
internal string s;
protected Element()
{
data = new ArrayList();
elements = new ArrayList();
dataAcceptanceList = new ArrayList();
elementAcceptanceList = new ArrayList();
}
public Element(string s) // Used for createing an element with user dxf code
{
this.s = s;
}
internal int AddElement(Element e)
{
if(this.IsAccepted(e)) return this.elements.Add(e);
else throw new UnexpectedElement();
}
internal void InsertElement(int index, Element e)
{
if(this.IsAccepted(e)) this.elements.Insert(index,e);
else throw new UnexpectedElement();
}
internal void RemoveElementAt(int index)
{
this.elements.RemoveAt(index);
}
internal Element GetElement(int index)
{
return (Element) this.elements[index];
}
internal int ElementCount()
{
return this.elements.Count;
}
internal int AddData(Data e)
{
if(this.IsAccepted(e)) return this.data.Add(e);
else throw new UnexpectedElement();
}
internal void InsertData(int index, Data e)
{
if(this.IsAccepted(e)) this.data.Insert(index,e);
else throw new UnexpectedElement();
}
internal void RemoveDataAt(int index)
{
this.data.RemoveAt(index);
}
internal Data GetData(int index)
{
return (Data) this.data[index];
}
internal int GetIndexFor(int code)
{
foreach(Data d in this.data)
{
if(d.code==code) return this.data.IndexOf(d);
}
return -1;
}
internal Data GetDataFor(int code)
{
foreach(Data d in this.data)
{
if(d.code==code) return d;
}
return new Data(-10,0);
}
internal int DataCount()
{
return this.data.Count;
}
protected bool IsAccepted(Data d) // verifica daca tipul de date ( rep prin cod dxf ) este acceptat de element
{
return (dataAcceptanceList.Contains(d.code)&&this.isCorectData(d));
}
protected bool IsAccepted(Element e)
{
return true; // DEBUG : trebuie modificat
// return elementAcceptanceList.Contains(e);
}
protected bool isCorectData(Data d) // Verifica daca tipul datei corespunde cu codul acesteia
{
if(d.code>=290 && d.code<=299)
if(d.data.GetType().ToString()=="System.Boolean") return true;
else return false;
if((d.code>=60 && d.code<=79)||(d.code>=270 && d.code<=289)||(d.code>=370 && d.code<=389)||(d.code>=170 && d.code<=179))
if(d.data.GetType().ToString()=="System.Int16") return true;
else return false;
if((d.code>=90 && d.code<=99)||(d.code == 1071))
if(d.data.GetType().ToString()=="System.Int32") return true;
else return false;
if((d.code>=10 && d.code<=59)||(d.code>=110 && d.code<=149)||(d.code>=210 && d.code<=239)||(d.code>=1010 && d.code<=1059))
if(d.data.GetType().ToString()=="System.Double") return true;
else return false;
if(d.code==100 || d.code==102 ||d.code==105 || d.code==999 || (d.code>=300 && d.code<=369)||(d.code>=390 && d.code<=399)||(d.code>=410 && d.code<=419))
if((d.data.GetType().ToString()=="System.String")&&((string) d.data).Length <=255) return true;
else return false;
if((d.code>=0 && d.code<=9) || (d.code>=1000 && d.code <=1009))
if(d.data.GetType().ToString()=="System.String") return true;
else return false;
return false;
}
public string Name
{
get
{
return ((Data)this.data[0]).data.ToString();
}
}
public void AddReplace(int cod, object o)
{
int ind = this.GetIndexFor(cod);
if(ind==-1) this.AddData(new Data(cod,o));
else
{
this.data.RemoveAt(ind);
this.InsertData(ind,new Data(cod,o));
}
}
public void AddData(int cod, object o)
{
this.AddData(new Data(cod,o));
}
}
}