We Written a program to open a *.XML file format. Can anyone help me how to write a program to import a Parasolid/ IGES File Format in my C# Application.
I have given my program to open a xml file format.
#region Open
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
string filename;
try
{
filename = getOpenFilename(Program.settings.workingDirectory);
}
catch { filename = ""; }
if (filename != "" && filename != null)
{
XmlDocument doc = new XmlDocument();
doc.Load(filename);
XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
if (doc.SelectNodes("/grammarRule", nsMgr).Count > 0)
{
grammarRule rule = grammarRule.openRuleFromXml(filename);
grammarDisplays.Add(new grammarRuleDisplay(rule, Path.GetFileName(filename)));
grammarDisplays[grammarChildCount].Show();
}
else if (doc.SelectNodes("/ruleSet", nsMgr).Count > 0)
{
ruleSet rs = ruleSet.openRuleSetFromXml(filename, Program.settings.defaultGenSteps);
ruleSetDisplays.Add(new ruleSetDisplay(rs, Path.GetFileName(filename)));
ruleSetDisplays[ruleSetChildCount].Show();
}
else if (doc.SelectNodes("/designGraph", nsMgr).Count > 0)
{
designGraph graph = designGraph.openGraphFromXml(filename);
addAndShowGraphDisplay(graph, Path.GetFileName(filename));
}
else if (doc.SelectNodes("/candidate", nsMgr).Count > 0)
{
string tempString = "";
candidate c = candidate.openCandidateFromXml(filename);
SearchIO.output("The candidate found in " + filename, 0);
if (c.performanceParams.Count > 0)
{
tempString = "has the following performance parameters";
foreach (double a in c.performanceParams)
tempString += ": " + a.ToString();
SearchIO.output(tempString, 0);
}
if (c.age > 0)
SearchIO.output("The candidate has existed for " + c.age.ToString() + " iterations.", 0);
SearchIO.output("It's generation ended in RuleSet #" + c.activeRuleSetIndex.ToString(), 0);
tempString = "Generation terminated with";
foreach (GenerationStatuses a in c.GenerationStatus)
tempString += ": " + a.ToString();
SearchIO.output(tempString, 0);
addAndShowGraphDisplay(c.graph, "Candidate in " + Path.GetFileName(filename));
}
else
{
MessageBox.Show("The XML files that you have attempted to open contains an unknown" +
"type (not designGraph, grammarRule, ruleSet, or candidate).", "XML Serialization Error",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
public string getOpenFilename(string dir)
{
try
{
OpenFileDialog fileChooser = new OpenFileDialog();
fileChooser.Title = "Open a graph, rule, or rule set from ...";
fileChooser.InitialDirectory = dir;
fileChooser.Filter = "(xml files)|*.xml";
DialogResult result = fileChooser.ShowDialog();
if (result == DialogResult.Cancel) return "";
return fileChooser.FileName;
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return "";
}
}
#endregion