using System;
using System.Collections.Generic;
using System.Linq;
namespace UPImage.FileFormat
{
/// <summary>
/// ///
/// </summary>
public class UPCOORD
{
/* coord */
/* from UNIPEN.DEF................ */
/* X, Y, T, P, Z, B, RHO, THETA, PHI, including at least X and Y. */
public int NrOfCoords;
public List<String> Coords;
public int cur_level;
public int has_z; /* -1=no, > -1=yes, indicating position */
public int has_p; /* -1=no, > -1=yes, indicating position */
public int has_t; /* -1=no, > -1=yes, indicating position */
public int has_b; /* -1=no, > -1=yes, indicating position */
public int has_rho; /* -1=no, > -1=yes, indicating position */
public int has_theta; /* -1=no, > -1=yes, indicating position */
public int has_phi; /* -1=no, > -1=yes, indicating position */
public UPCOORD()
{
NrOfCoords = 0;
Coords = new List<string>();
cur_level = 0;
has_b = -1;
has_p = -1;
has_phi = -1;
has_rho = -1;
has_t = -1;
has_theta = -1;
has_z = -1;
}
};
public class UPHIERACHY
{
public int nrOfHierachies;
public List<String> hieachies;
public UPHIERACHY()
{
nrOfHierachies = 0;
hieachies = new List<string>();
}
};
//
public class UPMandatoryDeclarations
{
protected UPHIERACHY hierachy;
protected UPCOORD coord;
public String m_version;
public String m_datasource;
public String m_dataID;
public UPCOORD m_coord
{
get
{
return coord;
}
}
public UPHIERACHY m_hierachy
{
get
{
return hierachy;
}
}
public UPMandatoryDeclarations()
{
coord = new UPCOORD();
hierachy = new UPHIERACHY();
}
/// <summary>
/// GetMandatoryDeclarations
/// </summary>
/// <param name="kw"></param>
protected void SetMandatoryDeclarations(UPKEYWORD kw)
{
switch (kw.keyName)
{
case ".VERSION":
//manDec.version = kw;
break;
case ".DATA_SOURCE":
//manDec.datasource = kw;
break;
case ".DATA_ID":
//manDec.dataID = kw;
break;
case ".COORD":
SetCoord(kw);
break;
case ".HIERARCHY":
SetHierachies(kw);
break;
}
}
//private functions
private void SetHierachies(UPKEYWORD kw)
{
//get hierachies
if (kw.keyName == UPImage.Common.UpCommonLib.keyHierarchy)
{
foreach (var s in kw.content_list)
{
String tempSt;
if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, UPImage.Common.UpCommonLib.keyHierarchy))
{
tempSt = s.Substring(s.IndexOf(" ")).Trim();
}
else
{
tempSt = s.Trim();
}
//check parameters
if (!String.IsNullOrWhiteSpace(tempSt))
{
UPImage.Common.UpCommonLib.GetWordsFromString(null, tempSt, out hierachy.hieachies);
}
}
hierachy.nrOfHierachies = hierachy.hieachies.Count;
}
}
private void SetCoord(UPKEYWORD kw)
{
//Get coords
if (kw.keyName == UPImage.Common.UpCommonLib.keyCoord)
{
foreach (var s in kw.content_list)
{
String tempSt;
if (UPImage.Common.UpCommonLib.SubStringSearch(null, s, UPImage.Common.UpCommonLib.keyCoord))
{
tempSt = s.Substring(s.IndexOf(" ")).Trim();
}
else
{
tempSt = s.Trim();
}
//check parameters
if (!String.IsNullOrWhiteSpace(tempSt))
{
UPImage.Common.UpCommonLib.GetWordsFromString(null, tempSt, out coord.Coords);
}
}
}
//
coord.NrOfCoords = coord.Coords.Count;
if (coord.NrOfCoords > 2)
{
foreach (var st in coord.Coords)
{
switch (st)
{
case "T":
coord.has_t = 1;
break;
case "P":
coord.has_p = 1;
break;
case "Z":
coord.has_z = 1;
break;
case "B":
coord.has_b = 1;
break;
case "RHO":
coord.has_rho = 1;
break;
case "THETA":
coord.has_theta = 1;
break;
case "PHI":
coord.has_phi = 1;
break;
}
}
}
}
}
}