public PssgAttributeInfo AddAttributeInfo(string name, PssgNodeInfo nodeInfo)
{
// For each attributeInfo in nodeInfo, the ids have to be consecutive
if (GetAttributeInfo(name).Length > 0)
{
return null;
}
if (attributeInfo == null)
{
attributeInfo = new PssgAttributeInfo[1];
}
else
{
Array.Resize(ref attributeInfo, attributeInfo.Length + 1);
}
int newID = 0;
List<int> currentKeys = new List<int>(nodeInfo.attributeInfo.Keys);
if (currentKeys.Count > 0)
{
foreach (int k in currentKeys)
{
newID = Math.Max(newID, k);
}
newID++;
}
else
{
newID = attributeInfo.Length;
}
PssgAttributeInfo attrInfo = new PssgAttributeInfo(newID, name);
if (newID == attributeInfo.Length)
{
attributeInfo[attrInfo.id - 1] = attrInfo;
this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo);
}
else
{
for (int i = attributeInfo.Length - 2; i >= newID - 1; i--)
{
attributeInfo[i + 1] = attributeInfo[i];
attributeInfo[i + 1].id = i + 2;
}
attributeInfo[attrInfo.id - 1] = attrInfo;
this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo);
// Fix the NodeInfos
foreach (PssgNodeInfo nInfo in this.nodeInfo)
{
List<int> keys = new List<int>(nInfo.attributeInfo.Keys);
//keys.Sort();
if (nInfo != nodeInfo)
{
for (int i = keys.Count - 1; i >= 0; i--)
{
if (keys[i] >= newID)
{
PssgAttributeInfo aInfo = attributeInfo[keys[i]];
nInfo.attributeInfo.Remove(keys[i]);
nInfo.attributeInfo.Add(keys[i] + 1, aInfo);
}
}
}
}
// Edit CNode to fix CAttr.id
rootNode.AddAttributeInfo(newID);
}
return attrInfo;
}