コード例 #1
0
    public partial class Model {//==========================================================================================
        public static Model FromStepFile(string FileName)
        {
//ifc.Repository.CurrentModel.

            string       FileSchema   = "-";
            Model        CurrentModel = new ifc.Model(FileName.Replace(".ifc", ""));
            StreamReader sr           = new StreamReader(FileName);
            string       line         = "";

            while ((line = sr.ReadLine()) != null && (line.Length > 1) && ((line + ' ')[0] != '#') && (!line.StartsWith("DATA")))
            {
                if (line.StartsWith("FILE_DESCRIPTION"))
                {
                    CurrentModel.Header.description = line.Split('\'')[1 * 2 - 1];
                }
                if (line.StartsWith("FILE_NAME"))
                {
                    string[] HeaderLine = line.Split('\'');
                    CurrentModel.Header.name                 = HeaderLine[1 * 2 - 1];
                    CurrentModel.Header.time_stamp           = HeaderLine[2 * 2 - 1];
                    CurrentModel.Header.author               = HeaderLine[3 * 2 - 1];
                    CurrentModel.Header.organization         = HeaderLine[4 * 2 - 1];
                    CurrentModel.Header.preprocessor_version = HeaderLine[5 * 2 - 1];
                    CurrentModel.Header.originating_system   = HeaderLine[6 * 2 - 1];
                    CurrentModel.Header.authorization        = HeaderLine[7 * 2 - 1];
                }
                if (line.StartsWith("FILE_SCHEMA"))
                {
                    FileSchema = line.Split('\'')[1 * 2 - 1];
                }
            }
            ;
            if (FileSchema != Specification.SchemaName)
            {
                Console.WriteLine("WARNING! Expected schema is '" + Specification.SchemaName + "', detected schema is '" + FileSchema + "'");
            }

//if (line.Length>1) ENTITY.ParseIfcLine(CurrentModel,line);
            while ((line = sr.ReadLine()) != null)
            {
                if (line.Length > 3)
                {
                    line = line.TrimStart(' '); //Console.WriteLine(line);
                    if (line.Length > 3)
                    {
                        if (line[0] == '#' || (line[0] == '/' && line[1] == '*'))
                        {
                            ENTITY.ParseIfcLine(CurrentModel, line);
                        }
                    }
                }
            }
            sr.Close();
            CurrentModel.AssignEntities();
            return(CurrentModel);
        } // of FromStepFile
コード例 #2
0
        public static Model FromSqliteFile(string fullPath)
        {
            SQLiteDatabase database     = new SQLiteDatabase();
            Model          CurrentModel = new ifc.Model(fullPath.Replace(".sqlite", ""));
            DataSet        dataSet      = database.GetContentAsDataSet(fullPath);

#if _DEBUG
            Console.WriteLine(string.Format("Reading SQLite-File: {0}", NetSystem.IO.Path.GetFileName(fullPath)));
            Console.WriteLine("======================================================");
#endif
            foreach (DataTable dt in dataSet.Tables)
            {
#if _DEBUG
                Console.WriteLine("______________________________________________________");
                Console.WriteLine(dt.TableName);
                foreach (DataColumn c in dt.Columns)
                {
                    Console.Write(string.Format("{0} ", c.ColumnName));
                }
                Console.Write("\r\n");
#endif
                foreach (DataRow row in dt.Rows)
                {
                    Type   entityType = Type.GetType("ifc." + dt.TableName);
                    ENTITY entityInstance;
                    if (entityType == typeof(EntityComment))
                    {
                        EntityComment ec = new EntityComment((string)row["Comment"], (int)row["PreviousEntity"]);
                        entityInstance = ec;
                    }
                    else
                    {
                        object[] ctorArgs = GetEntityConstructorArgs(entityType, row);
                        entityInstance = Activator.CreateInstance(entityType, ctorArgs) as ENTITY;
                    }

                    if (row["Id"] != null)
                    {
                        entityInstance.LocalId = (int)row["Id"];
                    }
                    CurrentModel.EntityList.Add(entityInstance);
#if _DEBUG
                    foreach (DataColumn c in dt.Columns)
                    {
                        Console.Write(string.Format("{0} ", row[c] is DBNull ? "NULL" : row[c].ToString()));
                    }
                    Console.Write("\r\n");
#endif
                }
            }
            Console.WriteLine("======================================================");

            // before we assign the entities, we need to order the list according to the Ids
            CurrentModel.EntityList = CurrentModel.EntityList.OrderBy(e => e.LocalId).ToList();

            // then we change the position of all EntityComment´s to match the actual order,
            // since they are being read sequentially
            foreach (EntityComment ec in CurrentModel.EntityList.FindAll(e => e.GetType() == typeof(EntityComment)))
            {
                int oldIndex = CurrentModel.EntityList.FindIndex(e => e.LocalId == ec.LocalId);
                int newIndex = CurrentModel.EntityList.FindIndex(e => e.LocalId == ec.PreviousEntityId) + 1;
                var item     = CurrentModel.EntityList[oldIndex];
                CurrentModel.EntityList.RemoveAt(oldIndex);

                if (newIndex > oldIndex)
                {
                    newIndex--;                      // the actual index could have shifted due to the removal
                }
                CurrentModel.EntityList.Insert(newIndex, item);
            }

            CurrentModel.AssignEntities();
            return(CurrentModel);
        }