Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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.
C#
#region Open
      private void openToolStripMenuItem_Click(object sender, EventArgs e)
      {
          string filename;
          try
          {
              filename = getOpenFilename(Program.settings.workingDirectory);
          }
          catch { filename = ""; }
          if (filename != "" && filename != null)
          {
              /* Load the file. */
              XmlDocument doc = new XmlDocument();
              doc.Load(filename);
              /* create prefix<->namespace mappings (if any)  */
              XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
              /* Query the document */
              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
Posted
Updated 6-May-14 3:01am
v2
Comments
[no name] 6-May-14 9:05am    
And what code, exactly, have you written that attempts to parse a Parasolid/ IGES file? What is the problem that you have with the code that you have written?
gggustafson 6-May-14 12:05pm    
The statement
if (filename != "" && filename != null)
should be replaced by
if ( !String.IsNullOrEmpty ( filename ) )

Where is your code to import a Parasolid/IGES File?
Vinod Kumar 7-May-14 6:48am    
Ya I am Sorry, Now I giving my program what i written to import an IGES / Para-solid file format. But it shows (OpenFileDialog and FCAD image are Errors)

public void importCadModel_Click (object sender, EventArgs e)
if(openFileDialog1.ShowDialog(this) != DialogResult.OK) return;
if (openFileDialog1.FileName != null)
{
FCADImage = new CADImage();
FCADImage.Base.Y = Bottom - 100;
FCADImage.Base.X = 100;
FCADImage.LoadFromFile(openFileDialog1.FileName);
}
this.Invalidate();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900