Ejemplo n.º 1
0
 /// <summary>Check if provided instance has the same values, 
 /// except comments</summary>
 /// <param name="E">Model to compare</param>
 public Boolean Equals(Model E)
 {
     if (E.Id != this.Id) return false;
     if (E.Amount != this.Amount) return false;
     if (! E.ModelParts.Equals(this.ModelParts)) return false;
     return true;
 }
Ejemplo n.º 2
0
 /// <summary>Load a Mesh file from a text filestream
 /// <remarks>Use first the constructor</remarks>
 /// </summary>
 /// <param name="amount">Amount of Models</param>
 /// <param name="fs">FileStream to read from</param>
 /// <returns>Amount of models read</returns>
 public UInt32 LoadTxt(UInt32 amount, FileStream fs)
 {
     UInt32 modelsRead = 0;      // Only for debug
     Int32 lineCount = 0;        // Only for debug
     String commentLines = null;
     String line = null;
     List<String> comments = new List<String>();
     List<String> currentModel = new List<String>();
     PARSE_COMMENTS_STATE commentsState = PARSE_COMMENTS_STATE.NotCommentLine;
     // Simplified Chinese encoding
     using (StreamReader sr = new StreamReader(fs, Common.enc, false)) lock (Data)
     {
         while ((line = sr.ReadLine()) != null)
         {
             lineCount++;
             // Check if comments or empty line
             if ((commentsState = IniCommon.ParseLineComments(line, commentsState)) >= 0)
             {
                 // Add to comments if not inside a model (or skip)
                 if (currentModel.Count == 0)
                 {
                     comments.Add(line);
                 }
             }
             // Check if starting to read a new model
             else if (line.StartsWith("["))
             {
                 // If we already have a model read
                 if (currentModel.Count != 0)
                 {
                     // Join with "\r\n" all comment lines until
                     //   last not empty, as last empty was just a
                     //   separator between models
                     // TODO: improve this method
                     commentLines = Common.ConcatenateAllUntilLastNotEmpty(comments);
                     // current model + comments -> add to collection
                     Model m = new Model(currentModel.ToArray());
                     m.AddComments(commentLines);
                     Data.Add(m.Id, m);
                     modelsRead++;
                     // reset comments
                     comments.Clear();
                 }
                 // new model
                 currentModel.Clear();
                 // add line to model
                 currentModel.Add(line);
             }
             else
             {
                 // Add data to the current model
                 currentModel.Add(line);
             }
         }
         // EOF: Check if pending to save current model
         if (currentModel.Count != 0)
         {
             Model m = new Model(currentModel.ToArray());
             m.AddComments(commentLines);
             Data.Add(m.Id, m);
             modelsRead++;
         }
     }
     return modelsRead;
 }