private void LoadFile(string filename)
{
this.SetCurrentFile(filename);
this.m_lastid = 0;
this.m_instances.Clear();
this.m_mapTree.Clear();
this.m_clipboard = null;
this.m_project = null;
List<DocChangeAction> listChange = new List<DocChangeAction>(); //temp
string ext = System.IO.Path.GetExtension(this.m_file).ToLower();
try
{
switch (ext)
{
case ".ifcdoc":
using (FormatSPF format = new FormatSPF(this.m_file, SchemaDOC.Types, this.m_instances))
{
format.Load();
}
break;
#if MDB
case ".mdb":
using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances))
{
format.Load();
}
break;
#endif
}
}
catch (Exception x)
{
MessageBox.Show(this, x.Message, "Error", MessageBoxButtons.OK);
// force new as state is now invalid
this.m_modified = false;
this.toolStripMenuItemFileNew_Click(this, EventArgs.Empty);
return;
}
List<SEntity> listDelete = new List<SEntity>();
List<DocTemplateDefinition> listTemplate = new List<DocTemplateDefinition>();
// get the project, determine the next OID to use
foreach (SEntity o in this.m_instances.Values)
{
if (o is DocProject)
{
this.m_project = (DocProject)o;
}
else if (o is DocEntity)
{
DocEntity docent = (DocEntity)o;
#if false
// files before V5.3 had Description field; no longer needed so use regular Documentation field again.
if (docent._Description != null)
{
docent.Documentation = docent._Description;
docent._Description = null;
}
#endif
}
else if(o is DocAttribute)
{
#if false
// files before V8.7 didn't have nullable tagless
DocAttribute docAttr = (DocAttribute)o;
if (docAttr.XsdTagless == false)
{
docAttr.XsdTagless = null;
}
#endif
}
else if(o is DocSchema)
{
DocSchema docSchema = (DocSchema)o;
// renumber page references
foreach (DocPageTarget docTarget in docSchema.PageTargets)
{
int page = docSchema.GetDefinitionPageNumber(docTarget);
int item = docSchema.GetPageTargetItemNumber(docTarget);
docTarget.Name = page + "," + item + " " + docTarget.Definition.Name;
foreach(DocPageSource docSource in docTarget.Sources)
{
docSource.Name = docTarget.Name;
}
}
}
else if (o is DocExchangeDefinition)
{
// files before V4.9 had Description field; no longer needed so use regular Documentation field again.
DocExchangeDefinition docexchange = (DocExchangeDefinition)o;
if (docexchange._Description != null)
{
docexchange.Documentation = docexchange._Description;
docexchange._Description = null;
}
}
else if (o is DocTemplateDefinition)
{
// files before V5.0 had Description field; no longer needed so use regular Documentation field again.
DocTemplateDefinition doctemplate = (DocTemplateDefinition)o;
if (doctemplate._Description != null)
{
doctemplate.Documentation = doctemplate._Description;
doctemplate._Description = null;
}
listTemplate.Add((DocTemplateDefinition)o);
}
else if(o is DocChangeAction)
{
// tempdebug -- delete old change actions -- need to clean up
//o.Delete();
listChange.Add((DocChangeAction)o);
}
// ensure all objects have valid guid
if (o is DocObject)
{
DocObject docobj = (DocObject)o;
if (docobj.Uuid == Guid.Empty)
{
docobj.Uuid = Guid.NewGuid();
}
#if false
// ensure any image references are in lowercase
if(docobj.Documentation != null && docobj.Documentation.Length > 0)
{
int i = 0;
while (i != -1)
{
i = docobj.Documentation.IndexOf("../figures/", i + 1);
if(i != -1)
{
int start = i + 11;
int end = docobj.Documentation.IndexOf('"', start);
if(end > start)
{
string strold = docobj.Documentation.Substring(start, end - start);
string strnew = strold.ToLower();
docobj.Documentation = docobj.Documentation.Substring(0, start) + strnew + docobj.Documentation.Substring(end);
System.Diagnostics.Debug.WriteLine(strnew);
}
}
}
}
#endif
}
if (o.OID > this.m_lastid)
{
this.m_lastid = o.OID;
}
}
if (this.m_project == null)
{
MessageBox.Show(this, "File is invalid; no project is defined.", "Error", MessageBoxButtons.OK);
return;
}
//tempcleanip
//for (int i = listChange.Count - 1; i >= 0;i-- )
{
//listChange[i].Delete();
}
// now capture any template definitions (upgrade in V3.5)
foreach (DocModelView docModelView in this.m_project.ModelViews)
{
if (docModelView.ConceptRoots == null)
{
// must convert to new format
docModelView.ConceptRoots = new List<DocConceptRoot>();
foreach (DocSection docSection in this.m_project.Sections)
{
foreach (DocSchema docSchema in docSection.Schemas)
{
foreach (DocEntity docEntity in docSchema.Entities)
{
if (docEntity.__Templates != null)
{
foreach (DocTemplateUsage docTemplateUsage in docEntity.__Templates)
{
// must generate or use existing concept root
DocConceptRoot docConceptRoot = null;
foreach (DocConceptRoot eachConceptRoot in docModelView.ConceptRoots)
{
if (eachConceptRoot.ApplicableEntity == docEntity)
{
docConceptRoot = eachConceptRoot;
break;
}
}
if (docConceptRoot == null)
{
docConceptRoot = new DocConceptRoot();
docConceptRoot.ApplicableEntity = docEntity;
docModelView.ConceptRoots.Add(docConceptRoot);
}
docConceptRoot.Concepts.Add(docTemplateUsage);
}
}
}
}
}
}
}
// upgrade to Publications (V9.6)
if (this.m_project.Annotations.Count == 4)
{
this.m_project.Publications.Clear();
DocAnnotation docCover = this.m_project.Annotations[0];
DocAnnotation docContents = this.m_project.Annotations[1];
DocAnnotation docForeword = this.m_project.Annotations[2];
DocAnnotation docIntro = this.m_project.Annotations[3];
DocPublication docPub = new DocPublication();
docPub.Name = "Default";
docPub.Documentation = docCover.Documentation;
docPub.Owner = docCover.Owner;
docPub.Author = docCover.Author;
docPub.Code = docCover.Code;
docPub.Copyright = docCover.Copyright;
docPub.Status = docCover.Status;
docPub.Version = docCover.Version;
docPub.Annotations.Add(docForeword);
docPub.Annotations.Add(docIntro);
this.m_project.Publications.Add(docPub);
docCover.Delete();
docContents.Delete();
this.m_project.Annotations.Clear();
}
LoadTree();
}