Example #1
0
        }//--------------------------------------------------------------------------------------------------------------------

        public void EvalSelectNode(FieldInfo field, XmlNode n)//------------------------------------------------------------------
        {
//EvalEntityNodeName();
#if (TRACE)
//Console.ReadLine(); // Typ von n.Name ermiiiteln => field.FieldType
#endif
            foreach (XmlNode n2 in n.ChildNodes)
            {//Console.WriteLine("               "+n2.Name);
                try{ object[] TypeCtorArgs = new object[1];
                     string   TypeName     = n2.Name.Substring(3); if (TypeName.EndsWith("-wrapper"))
                     {
                         TypeName = TypeName.Substring(0, TypeName.Length - 8);
                     }
                     Type t = Type.GetType(typeName: "ifc." + TypeName, throwOnError: true, ignoreCase: true);// 2. true: ignoreCase
                     if (t.IsSubclassOf(typeof(ENTITY)))
                     {
                         TypeCtorArgs[0] = EvalEntityNode(Model.CurrentModel, n2);
                     }
                     else if (t.IsSubclassOf(typeof(TypeBase)))
                     {
                         TypeCtorArgs[0] = ENTITY.Parse2TYPE(n2.InnerText, t);
                     }
                     //else if (t.IsSubclassOf(typeof(SELECT))) {TypeCtorArgs[0]=ENTITY.EvalSelectNode(n2); }  noch Fallunterscheidungen vgl. [ifcSQL].[ifcSchemaTool].[SelectTypesAndSelectedTypeGroupsWithDifferentSelectedTypes]
                     else
                     {
                         Console.WriteLine("no TypeInstance createtd for SELECTed-Type=" + "ifc." + n2.Name.Substring(3));
                     }

                     field.SetValue(this, Activator.CreateInstance(field.FieldType, TypeCtorArgs)); }catch (Exception e) { throw new Exception("EvalSelectNode:" + field.FieldType.ToString() + ": " + e.Message); } //   Console.WriteLine("SELECT="+n.Name+" of "+xml.Name);Console.ReadLine();
            }
        }                                                                                                                                                                                                            //--------------------------------------------------------------------------------------------------------------------
Example #2
0
//public partial class LIST<T> {
        public void ToÍfcXml(XmlWriter xml)
        {
            foreach (T t in this)
            {
                ENTITY.IfcXmlOut(t, t.GetType().ToString(), xml);                                          //hier noch Exluding Attribute
            }
        }
Example #3
0
        public void EvalTypeString(FieldInfo field, string Value)//------------------------------------------------------------------
        {
#if (TRACE)
            Console.WriteLine("  EvalTypeString=" + field.Name + ":" + Value);
#endif
            try{ field.SetValue(this, ENTITY.Parse2TYPE(Value, field.FieldType)); }
            catch (Exception e) { throw new Exception("EvalTypeString:" + field.Name + ": " + field.FieldType.ToString() + ": " + e.Message); }
        }//--------------------------------------------------------------------------------------------------------------------
        public static string HtmlRefOut(FieldInfo field, string IfcId, ENTITY e)
        {
            string RefClassName = "ref"; if (NameKeywDict.ContainsKey(e.ShortTypeName()))

            {
                RefClassName += " keyw" + NameKeywDict[e.ShortTypeName()];
            }
            return("<a href=\"" + IfcId + "\" class=\"" + RefClassName + "\">" + IfcId + "</a>");
        }
Example #5
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
Example #6
0
        }                                                                                                                                                                                                            //--------------------------------------------------------------------------------------------------------------------

        public void EvalListNode(FieldInfo field, XmlNode n)//------------------------------------------------------------------
        {
#if (TRACE)
            Console.WriteLine("  LIST=" + field.Name + ":" + n.Name);  //Console.ReadLine(); // Typ von n.Name ermiiiteln => field.FieldType
#endif
            Type GenericType = ENTITY.GetGenericType(field.FieldType); //Console.WriteLine("xml.Name="+xml.Name); //Console.WriteLine("n.Name="+n.Name+" fieldTypeName="+field.FieldType.Name);
            try {                                                      //Console.WriteLine("EvalListNode:"+field.FieldType.Name+" # "+n.Name+" GenericType="+GenericType.Name);
                object[] o = GetFieldCtorArgsFromXml(GenericType, n);
//     Console.WriteLine("XXXXXXXX:"+o.Length+" for ListType "+field.FieldType.Name);
//     if (o.Length>0) Console.WriteLine("YYYYYYYYY:"+o[0].ToString()+":"+o[0].GetType().Name);
                field.SetValue(this, Activator.CreateInstance(field.FieldType, o));//ifc.TableColumn tc=new TableColumn(); //tc.ReferencePath.InnerReference.ListPositions.li
            }catch (Exception e) { throw new Exception("EvalListNode:" + field.FieldType.ToString() + ": " + e.Message); }
        }//--------------------------------------------------------------------------------------------------------------------
Example #7
0
        public void EvalXmlNode(XmlNode xml)
        {
//Model.log.WriteLine("EvalXmlNode="+xml.Name);
//Console.WriteLine("BBB: "+xml.Name);
            if (xml.Name.StartsWith("Ifc"))
            {
                if (!xml.Name.EndsWith("-wrapper"))
                {
                    ENTITY.EvalEntityNode(this, xml);
                }
            }
            if (xml.Name == "header")
            {
                EvalHeaderNode(xml);
            }
//foreach (XmlNode n in xml.ChildNodes) EvalXmlNode(n);
//EntityList.Add((ENTITY)CurrentEntity); //Console.WriteLine(((ENTITY)CurrentEntity).ToIfc());
        }
        public void ToSqliteFile()
        {
            AssignEntities();
            string        fullPath      = Header.name + ".sqlite";
            SQLiteDataSet sqliteDataSet = new SQLiteDataSet();

#if EXPORT_COMPLETE_SCHEMA
            BuildIfcDataSet(ref ifcDataSet);
#endif

            Console.WriteLine(string.Format("{0}: Exporting Entities to SQLite-File", NetSystem.DateTime.Now.ToString("HH:mm:ss.ffff")));
            int prevEntityId = 0;
            for (int i = 0; i < ifc.Repository.CurrentModel.EntityList.Count; i++)
            {
                ENTITY e = ifc.Repository.CurrentModel.EntityList[i];
                if (e is ifc.Root)
                {
                    if (((ifc.Root)e).GlobalId == null)
                    {
                        ((ifc.Root)e).GlobalId = ifc.GloballyUniqueId.NewId();
                    }
                }
                e.ToSqliteDataSet(ref sqliteDataSet, true, prevEntityId);
                prevEntityId = e.LocalId;
            }

            //TODO: Check if custom DataSet Class 'SQLiteDataSet' can be omitted and instead use a regular 'DataSet'
            //DataSet dataSet = new DataSet("IfcDataSet");
            //foreach (ENTITY e in ENTITY.EntityList)
            //{
            //    e.ToDataSet(ref dataSet);
            //}

            SQLiteDatabase database = new SQLiteDatabase(fullPath);
            database.FillFromDataSet(sqliteDataSet);

            Console.WriteLine(string.Format("{0}: Finished Export", NetSystem.DateTime.Now.ToString("HH:mm:ss.ffff")));
            Console.WriteLine("======================================================");
        }
Example #9
0
        public void EvalEntityNode(FieldInfo field, XmlNode n)//------------------------------------------------------------------
        {
#if (TRACE)
            Console.WriteLine("  EvalEntityNode=" + field.Name + ":" + n.Name + " typeof " + field.FieldType.Name);
#endif
            if (((XmlElement)n).HasAttribute("href"))
            {
                ENTITY e = (ENTITY)Activator.CreateInstance(field.FieldType); e.XmlRefId = n.Attributes["href"].Value; field.SetValue(this, e); UnassignedEntityFieldList.Add(new EntityField(this, field));
            }
            else if (((XmlElement)n).HasAttribute("ref"))
            {
                ENTITY e = (ENTITY)Activator.CreateInstance(field.FieldType); e.XmlRefId = n.Attributes["ref"].Value; field.SetValue(this, e); UnassignedEntityFieldList.Add(new EntityField(this, field));
            }
            else
            {
                try {
                    string EntityTypeName = (((XmlElement)n).HasAttribute("xsi:type"))?n.Attributes["xsi:type"].Value.Substring(3) : field.FieldType.Name;
//Console.WriteLine(EntityTypeName);
                    field.SetValue(this, EvalEntityNode(Model.CurrentModel, n, EntityTypeName));
                }catch (Exception e) { throw new Exception("EvalEntityNode:" + field.FieldType.ToString() + ": " + e.Message); }
            }
        }//--------------------------------------------------------------------------------------------------------------------
Example #10
0
public void AssignEntities()
{
EntityDict.Clear();
foreach (ENTITY e in EntityList) /* if (e.LocalId>0) */ if (!EntityDict.ContainsKey(e.LocalId))  {EntityDict.Add(e.LocalId,e);} else Console.WriteLine("#"+e.LocalId+" already exist! (double Entry)");
foreach (ENTITY e in EntityList) /* if (e.LocalId>0) */
        {//####################################################################################################
         Dictionary<int,FieldInfo> VarDict=new Dictionary<int,FieldInfo>();
         int VarCount=0; foreach (FieldInfo field in e.GetType().GetFields(BindingFlags.Public|BindingFlags.Instance|BindingFlags.FlattenHierarchy)) foreach (Attribute attr in field.GetCustomAttributes(true)) if (attr is ifcAttribute) {VarDict.Add(((ifcAttribute)attr).OrdinalPosition,field);VarCount++;} 
         for (int i=1;i<=VarCount;i++)       
             {//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              FieldInfo field=VarDict[i];

                   if ( field.FieldType.IsSubclassOf(typeof(ENTITY))) 
                      {ENTITY E=(ENTITY)field.GetValue(e);
                       if (E!=null) {if (E.LocalId>0) if (EntityDict.ContainsKey(E.LocalId)) field.SetValue(e,EntityDict[E.LocalId]); /* E=EntityDict[E.Id];*/  
                                     else Console.WriteLine("E.Id="+E.LocalId+" nicht gefunden"); 
                                    } 
                      }
              else if (field.FieldType.IsSubclassOf(typeof(SELECT))) 
                      {
                       SELECT S=(SELECT)field.GetValue(e);
                       if (S!=null)
                          {//...........................................
                           if   (S.Id>0 && EntityDict.ContainsKey(S.Id)) S.SetValueAndType(EntityDict[S.Id],EntityDict[S.Id].GetType()); 
                           else if (!S.IsNull) {ENTITY E=null; if (S!=null)   if ( S.SelectType().IsSubclassOf(typeof(ENTITY)) ) E=(ENTITY)S.SelectValue(); 
                                                if (E!=null) if (E.LocalId>0 && EntityDict.ContainsKey(E.LocalId)) S.SetValueAndType(EntityDict[E.LocalId],EntityDict[E.LocalId].GetType()); 
                                               }
                           }//...........................................

                      }
              else if (typeof(IEnumerable).IsAssignableFrom(field.FieldType)) if (field.GetValue(e)!=null) 
                      {//==================================================================
                       //Console.WriteLine("start list "+i+":"+field.FieldType.Name);
                       Dictionary<int,object> VarDict1=new Dictionary<int,object>();
                       int VarCount1=0;foreach (object item in (IEnumerable)field.GetValue(e)) if (item!=null) VarDict1.Add(VarCount1++,item);
                       object[] FieldCtorArgs=new object[VarCount1];
                       Type GenericType=null;
                       if (field.FieldType.BaseType.GetGenericArguments().Length>0) GenericType=field.FieldType.BaseType.GetGenericArguments()[0]; //LengthMeasure or CartesianPoint
                       else                                                         GenericType=field.FieldType.BaseType.BaseType.GetGenericArguments()[0]; //CompoundPlaneAngleMeasure
                       if ((GenericType!=null) &&  ( (GenericType.IsSubclassOf(typeof(ENTITY))) || GenericType.IsSubclassOf(typeof(SELECT))  ) )
                          {//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           for (int i1=0;i1<VarCount1;i1++)       
                               {//------------------------------------------------------
                                object item=VarDict1[i1]; //Console.Write(field.Name+", "+i+" "+i1);
                                     if (item is SELECT) {//Console.WriteLine("SELECT item "+((SELECT)item).Id +" "+((SELECT)item).SelectType().Name); 

                                                           if (((SELECT)item).Id==0) if ( ((SELECT)item).SelectType().IsSubclassOf(typeof(ENTITY)) ) { ((SELECT)item).Id=((ENTITY)((SELECT)item).SelectValue()).LocalId; } 

                                                           if (((SELECT)item).Id>0) {//SELECT s=new SELECT(); /*((SELECT)item)*/ 
                                                                                      SELECT s=(SELECT)item;
                                                                                       s.SetValueAndType(EntityDict[((SELECT)item).Id],EntityDict[((SELECT)item).Id].GetType()); 
                                                                                       FieldCtorArgs[i1]=s;// Console.WriteLine(GenericType.Name+": ");

                                                                                    }
                                                           
                                                         }
                                else if (item is ENTITY) {//===================
                                                          if (((ENTITY)item).LocalId>0) 
                                                             {ENTITY E=(ENTITY)item; // Console.WriteLine("((ENTITY)item).Id="+((ENTITY)item).Id );
                                                              if (E!=null) if (E.LocalId>0) {//........................
                                                                                        if (EntityDict.ContainsKey(E.LocalId)) E=EntityDict[E.LocalId];  else Console.WriteLine("E.Id="+E.LocalId+" nicht gefunden");}
                                                                                        FieldCtorArgs[i1]=E;       
                                                                                       }//........................
                                                         }//===================
                               }//---------------------------------------------------
                            field.SetValue(e,Activator.CreateInstance(field.FieldType,FieldCtorArgs)); // ERROR !!
 
                          }//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                //       Console.WriteLine("end list");
                      }//==============================================================
             }//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// of foreach field
        }//#################################################################################################### //of foreach Entity
}//of void
public override string ToString(){string s="(";int pos=0; foreach (T item in this) {if (++pos>1) s+=","; s+=ENTITY.StepAttributeOut(item);};s+=")";return s; }
Example #12
0
    public partial class Model {//==========================================================================================
        public void ToXmlFile()
        {
            SortEntities();
            foreach (ENTITY e /* abstract */ in EntityList)
            {
                e.AssignInverseElements();
            }
            ENTITY root = null;

            foreach (ENTITY e /* abstract */ in EntityList)
            {
                if (e is ifc.Project)
                {
                    root = e;
                }
            }
            foreach (ENTITY e in EntityList)
            {
                e.IsAssigned = false;
            }


            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = "  ";     // "\t";
            settings.Encoding    = Encoding.Default;

/*
 * StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
 * sw.AutoFlush = true;
 * Console.SetOut(sw);
 */
            char SaveStringChar = TypeBase.StringChar;

            TypeBase.StringChar = '\0';
            bool SaveHasStringChar = TypeBase.HasStringChar;

            TypeBase.HasStringChar = false;
//XmlWriter       xml = XmlWriter.Create(sw /*Header.name+".ifcXml" */ , settings); // ifcXml
            XmlWriter xml = XmlWriter.Create(Header.name + ".ifcXml", settings);

            xml.WriteProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
            xml.WriteStartElement(prefix: "ifc", localName: "ifcXML", ns: @"http://www.buildingsmart-tech.org/ifc/IFC4x2/final");
            xml.WriteAttributeString(prefix: "xsi", localName: "schemaLocation", ns: @"http://www.w3.org/2001/XMLSchema-instance", value: @"http://www.buildingsmart-tech.org/ifc/IFC4x2/final IFC4x2.xsd");
            xml.WriteAttributeString(localName: "xmlns", value: @"http://www.buildingsmart-tech.org/ifc/IFC4x2/final");

            xml.WriteStartElement("header");
            xml.WriteElementString("name", Header.name);
            xml.WriteElementString("time_stamp", Header.time_stamp);
            xml.WriteElementString("author", Header.author);
            xml.WriteElementString("organization", Header.organization);
            xml.WriteElementString("preprocessor_version", Header.preprocessor_version);
            xml.WriteElementString("originating_system", Header.originating_system);
            xml.WriteElementString("authorization", Header.authorization);
            xml.WriteElementString("documentation", Header.documentation);
            xml.WriteEndElement();          // header


            root.ToIfcXml(xml);

// alle weiteren noch nicht verwendeten Entities

            xml.WriteEndElement();      // ifc.ifcXml

            xml.Close();
            TypeBase.StringChar    = SaveStringChar;
            TypeBase.HasStringChar = SaveHasStringChar;

/*
 * StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
 * standardOutput.AutoFlush = true;
 * Console.SetOut(standardOutput);
 */
        } // of ToIfcXmlFile
Example #13
0
        public void EvalIfcRow(ifcSQL.ifcInstance.Entity_Row e)
        {
            try{
                Type   t             = Type.GetType("ifc." + ifc.ENTITY.TypeDictionary.TypeIdNameDict[e.EntityTypeId], true, true); // 2. true: ignoreCase
                ENTITY CurrentEntity = (ENTITY)Activator.CreateInstance(t);
                CurrentEntity.LocalId        = LocalIdFromGlobalIdDict[e.GlobalEntityInstanceId];                                   // e.LocalId;
                CurrentEntity.ifcSqlGlobalId = e.GlobalEntityInstanceId;

// commment-handling:
                if (CurrentEntity is EntityComment)
                {
                    ((EntityComment)CurrentEntity).CommentLine = ((ifcSQL.ifcInstance.EntityAttributeOfString_Row)e.AttributeValueDict[-1]).Value;
                }
                else if (e.AttributeValueDict.ContainsKey(-1))
                {
                    CurrentEntity.EndOfLineComment = ((ifcSQL.ifcInstance.EntityAttributeOfString_Row)e.AttributeValueDict[-1]).Value;
                }

                object[] TypeCtorArgs            = new object[1];
                int      OrdinalPosition         = 0;
                ENTITY.AttribListType AttribList = ENTITY.TypeDictionary.GetComponents(CurrentEntity.GetType()).AttribList;
                foreach (ENTITY.AttribInfo attrib in AttribList)
                {
                    ++OrdinalPosition;
                    if (e.AttributeValueDict.ContainsKey(OrdinalPosition))//----------------------------------------------------------------------------------------------------------
                    {
                        RowBase rb = e.AttributeValueDict[OrdinalPosition];
                        if (rb is ifcSQL.ifcInstance.EntityAttributeOfVector_Row)
                        {
                            ifcSQL.ifcInstance.EntityAttributeOfVector_Row a = (ifcSQL.ifcInstance.EntityAttributeOfVector_Row)rb;
                            if (a.TypeId == 25)
                            {
                                if (a.Z != null)
                                {
                                    ((ifc.CartesianPoint)CurrentEntity).Coordinates = new List1to3_LengthMeasure((LengthMeasure)a.X, (LengthMeasure)a.Y, (LengthMeasure)(double)a.Z);
                                }
                                else
                                {
                                    ((ifc.CartesianPoint)CurrentEntity).Coordinates = new List1to3_LengthMeasure((LengthMeasure)a.X, (LengthMeasure)a.Y);
                                }
                            }
#if IFC2X3
                            if (a.TypeId == 42)
                            {
                                if (a.Z != null)
                                {
                                    ((ifc.Direction)CurrentEntity).DirectionRatios = new List2to3_double(a.X, a.Y, (double)a.Z);
                                }
                                else
                                {
                                    ((ifc.Direction)CurrentEntity).DirectionRatios = new List2to3_double(a.X, a.Y);
                                }
                            }
#else
                            if (a.TypeId == 42)
                            {
                                if (a.Z != null)
                                {
                                    ((ifc.Direction)CurrentEntity).DirectionRatios = new List2to3_Real((Real)a.X, (Real)a.Y, (Real)(double)a.Z);
                                }
                                else
                                {
                                    ((ifc.Direction)CurrentEntity).DirectionRatios = new List2to3_Real((Real)a.X, (Real)a.Y);
                                }
                            }
#endif
                        }
                        else if (rb is ifcSQL.ifcInstance.EntityAttributeOfString_Row)
                        {
                            ifcSQL.ifcInstance.EntityAttributeOfString_Row a = (ifcSQL.ifcInstance.EntityAttributeOfString_Row)rb;
                            TypeCtorArgs[0] = ifc.IfcString.Decode(a.Value);
                            attrib.field.SetValue(CurrentEntity, Activator.CreateInstance(attrib.field.FieldType, TypeCtorArgs));
                        }
                        else if (rb is ifcSQL.ifcInstance.EntityAttributeOfEnum_Row)
                        {
                            ifcSQL.ifcInstance.EntityAttributeOfEnum_Row a = (ifcSQL.ifcInstance.EntityAttributeOfEnum_Row)rb;
                            Type UnderlyingType = Nullable.GetUnderlyingType(attrib.field.FieldType);
                            if (UnderlyingType != null && UnderlyingType.IsEnum)
                            {
                                attrib.field.SetValue(CurrentEntity, Enum.ToObject(UnderlyingType, a.Value));
                            }
                            else
                            {
                                attrib.field.SetValue(CurrentEntity, a.Value);
                            }
                        }
                        else if (rb is ifcSQL.ifcInstance.EntityAttributeOfInteger_Row)
                        {
                            ifcSQL.ifcInstance.EntityAttributeOfInteger_Row a = (ifcSQL.ifcInstance.EntityAttributeOfInteger_Row)rb;
                            object o = Activator.CreateInstance(ENTITY.TypeDictionary.TypeIdTypeDict[a.TypeId], a.Value);
                            if (attrib.field.FieldType.IsSubclassOf(typeof(SELECT)))
                            {
                                TypeCtorArgs[0] = o; o = Activator.CreateInstance(attrib.field.FieldType, TypeCtorArgs);
                            }
                            attrib.field.SetValue(CurrentEntity, o);
                        }
                        else if (rb is ifcSQL.ifcInstance.EntityAttributeOfFloat_Row)
                        {
                            ifcSQL.ifcInstance.EntityAttributeOfFloat_Row a = (ifcSQL.ifcInstance.EntityAttributeOfFloat_Row)rb;
                            object o = Activator.CreateInstance(ENTITY.TypeDictionary.TypeIdTypeDict[a.TypeId], a.Value);
                            if (attrib.field.FieldType.IsSubclassOf(typeof(SELECT)))
                            {
                                TypeCtorArgs[0] = o; o = Activator.CreateInstance(attrib.field.FieldType, TypeCtorArgs);
                            }
                            attrib.field.SetValue(CurrentEntity, o);
                        }

                        else if (rb is ifcSQL.ifcInstance.EntityAttributeOfEntityRef_Row)
                        {
                            ifcSQL.ifcInstance.EntityAttributeOfEntityRef_Row a = (ifcSQL.ifcInstance.EntityAttributeOfEntityRef_Row)rb;
                            if (a.Value > 0)
                            {
                                Type   AttributeInstanceType = ifc.ENTITY.TypeDictionary.TypeIdTypeDict[a.TypeId];
                                object o = Activator.CreateInstance(AttributeInstanceType); ((ENTITY)o).LocalId = LocalIdFromGlobalIdDict[a.Value];
                                if (attrib.field.FieldType.IsSubclassOf(typeof(SELECT)))
                                {
                                    TypeCtorArgs[0] = o; o = Activator.CreateInstance(attrib.field.FieldType, TypeCtorArgs);
                                }
                                attrib.field.SetValue(CurrentEntity, o);
                            }
                        }

                        else if (rb is ifcSQL.ifcInstance.EntityAttributeOfList_Row)
                        {
                            ifcSQL.ifcInstance.EntityAttributeOfList_Row a = (ifcSQL.ifcInstance.EntityAttributeOfList_Row)rb;
                            Type GenericType = null;
                            if (attrib.field.FieldType.BaseType.GetGenericArguments().Length > 0)
                            {
                                GenericType = attrib.field.FieldType.BaseType.GetGenericArguments()[0];                                                                                                             //LengthMeasure or CartesianPoint
                            }
                            else
                            {
                                GenericType = attrib.field.FieldType.BaseType.BaseType.GetGenericArguments()[0];                                                                                                //CompoundPlaneAngleMeasure
                            }
                            Type     AttributeInstanceType = ifc.ENTITY.TypeDictionary.TypeIdTypeDict[a.TypeId];
                            int      ListDim1Count         = a.AttributeValueDict.Count;
                            object[] FieldCtorArgs         = new object[ListDim1Count];
                            if (ListDim1Count > 0)
                            {
                                if (a.AttributeValueDict[0] is ifcSQL.ifcInstance.EntityAttributeListElementOfEntityRef_Row)
                                {
                                    for (int ListDim1Position = 0; ListDim1Position < ListDim1Count; ListDim1Position++)
                                    {
                                        int      Id = LocalIdFromGlobalIdDict[((ifcSQL.ifcInstance.EntityAttributeListElementOfEntityRef_Row)a.AttributeValueDict[ListDim1Position]).Value];
                                        object[] GenericCtorArgs = new object[1];
                                        FieldCtorArgs[ListDim1Position] = Activator.CreateInstance(GenericType);                                             // Console.WriteLine("GenericType= "+GenericType.ToString());
                                        if (GenericType.IsSubclassOf(typeof(SELECT)))
                                        {
                                            ((SELECT)FieldCtorArgs[ListDim1Position]).Id = Id;
                                        }
                                        else if (GenericType.IsSubclassOf(typeof(ENTITY)))
                                        {
                                            ((ENTITY)FieldCtorArgs[ListDim1Position]).LocalId = Id;
                                        }
                                        else
                                        {
                                            Console.WriteLine("unkown type");
                                        }
                                    }
                                }
                            }
                            attrib.field.SetValue(CurrentEntity, Activator.CreateInstance(attrib.field.FieldType, FieldCtorArgs));
                        }
                    }                                                                         //----------------------------------------------------------------------------------------------------------
                }                                                                             //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                EntityList.Add(CurrentEntity);
            }catch (Exception ex) { Console.WriteLine("ERROR on EvalIfcRow:" + ex.Message); } //Console.ReadLine();}
        }
Example #14
0
        public int SetAssignedEntityForSort()
        {
            int cnt = 0;

            foreach (ENTITY e in EntityList)
            {
                if (!e.IsAssigned)
                {
                    e.IsAssigned = true;
                    //if (e.Id== 103)  Console.WriteLine(e.ToIfc());
                    foreach (FieldInfo field in e.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy))
                    {
                        foreach (NetSystem.Attribute attr in field.GetCustomAttributes(true))
                        {
                            if (attr is ifcAttribute)                                           // nur IFC-Atribute
                            {
                                if (field.FieldType.IsSubclassOf(typeof(ENTITY)))
                                {
                                    ENTITY E = (ENTITY)field.GetValue(e);
                                    // if (E!=null) if (E.Id>0) Console.WriteLine(field.Name+"="+E.Id+" "+E.IsAssigned+" "+AssignedEntityDict.ContainsKey(E.Id));
                                    if (E != null)
                                    {
                                        if (E.LocalId > 0)
                                        {
                                            if (!AssignedEntityDict.ContainsKey(E.LocalId))
                                            {
                                                e.IsAssigned = false;
                                            }
                                        }
                                    }
                                    //  if (e.Id==1) Console.WriteLine(field.Name+" "+e.IsAssigned);
                                }
                                else if (field.FieldType.IsSubclassOf(typeof(SELECT)))
                                {
                                    SELECT E = (SELECT)field.GetValue(e);
                                    if (E != null)
                                    {
                                        if (E.Id > 0)
                                        {
                                            if (!AssignedEntityDict.ContainsKey(E.Id))
                                            {
                                                e.IsAssigned = false;
                                            }
                                        }
                                    }
                                }
                                else if (typeof(IEnumerable).IsAssignableFrom(field.FieldType))
                                {
                                    if (field.GetValue(e) != null)
                                    {
                                        foreach (object item in (IEnumerable)field.GetValue(e))
                                        {
                                            if (item != null)
                                            {
                                                if (item is SELECT)
                                                {
                                                    if (((SELECT)item).Id > 0)
                                                    {
                                                        if (!AssignedEntityDict.ContainsKey(((SELECT)item).Id))
                                                        {
                                                            e.IsAssigned = false;
                                                        }
                                                    }
                                                }
                                                if (item is ENTITY)
                                                {
                                                    if (((ENTITY)item).LocalId > 0)
                                                    {
                                                        if (!AssignedEntityDict.ContainsKey(((ENTITY)item).LocalId))
                                                        {
                                                            e.IsAssigned = false;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }// of foreach field
                        }
                    }
                    //   if (e.Id==1)
                    //   Console.WriteLine(e.Id+" IsAssigned="+e.IsAssigned);
                    if (e.IsAssigned) /* if (!(e is ifc.EntityComment)) */
                    {
                        e.SortPos = ++GlobalSortPos; try{ AssignedEntityDict.Add(e.LocalId, e); }catch (NetSystem.Exception ex) { throw new NetSystem.Exception(ex.Message + e.ToStepLine()); }; cnt++;
                    }                                                                                                                                                                                                                //Console.WriteLine(cnt+": "+e.Id);}
                }//of foreach Entity
            }
//Console.WriteLine("----------------------");
            return(cnt);
        }
Example #15
0
        public static ENTITY EvalEntityNode(Model CurrentModel, XmlNode xml, string TypeName = null)
        {
            ENTITY CurrentEntity = null;

//Console.WriteLine("CCC");
            try{
//ifc.Axis2Placement
//ifc.RelDeclares
//ifc.ConversionBasedUnit u=new ConversionBasedUnit();u.ConversionFactor.ValueComponent=new Value()
#if (TRACE)
                Console.WriteLine("ENTITY= " + xml.Name + ": TypeName=" + ((TypeName != null)?TypeName:xml.Name.Substring(3)));
#endif

//if (TypeName==null) if ( ((XmlElement)xml).HasAttribute("xsi:type") ) Console.WriteLine("xml.Attributes[\"xsi:type\"].Value="+xml.Attributes["xsi:type"].Value);
//if (TypeName!=null) if (xml.Name=="Bound") if ( ((XmlElement)xml).HasAttribute("xsi:type") ) Console.WriteLine("xml.Attributes[\"xsi:type\"].Value="+xml.Attributes["xsi:type"].Value+"#"+TypeName);


                if (TypeName == null)
                {
                    TypeName = (((XmlElement)xml).HasAttribute("xsi:type"))?xml.Attributes["xsi:type"].Value.Substring(3) : xml.Name.Substring(3);
                }

//if (TypeName=="SIUnit") Console.WriteLine("A");

                Type t = Type.GetType(typeName: "ifc." + TypeName, throwOnError: true, ignoreCase: true);// 2. true: ignoreCase

//if (TypeName=="SIUnit") Console.WriteLine("B");

                CurrentEntity = (ENTITY)Activator.CreateInstance(t); CurrentEntity.AddNext(); // in default-Ctor nicht enthalten

//if (TypeName=="SIUnit") Console.WriteLine("C");



                if (xml.Attributes["id"] != null)
                {
                    CurrentEntity.XmlId = xml.Attributes["id"].Value; if (!XmlIdDict.ContainsKey(CurrentEntity.XmlId))
                    {
                        XmlIdDict.Add(CurrentEntity.XmlId, CurrentEntity);
                    }
                    else
                    {
                        throw new Exception("double id=" + xml.Attributes["id"].Value + " in Xml");
                    }
//                                 Model.log.WriteLine(TreeOfParents(xml,xml.Name)+" (id="+xml.Attributes["id"].Value+")"); // ifc.ConversionBasedUnitWithOffset
                }
//else                             Model.log.WriteLine(TreeOfParents(xml,xml.Name));


                if (CurrentEntity is Direction)
                {
                    if (((XmlElement)xml).HasAttribute("DirectionRatios"))
                    {
                        string[] ListElements = xml.Attributes["DirectionRatios"].Value.Split(' ');

#if IFC2X3
                        ((Direction)CurrentEntity).DirectionRatios = new List2to3_double(); foreach (string Element in ListElements)
                        {
                            ((Direction)CurrentEntity).DirectionRatios.Add(double.Parse(Element));
                        }
#else
                        ((Direction)CurrentEntity).DirectionRatios = new List2to3_Real(); foreach (string Element in ListElements)
                        {
                            ((Direction)CurrentEntity).DirectionRatios.Add(new Real(double.Parse(Element)));
                        }
#endif
                        return(CurrentEntity);
                    }
                }                     // andernfalls Ref-Element unter Entity auswerten
                if (CurrentEntity is CartesianPoint)
                {
                    if (((XmlElement)xml).HasAttribute("Coordinates"))
                    {
                        string[] ListElements = xml.Attributes["Coordinates"].Value.Split(' ');
                        ((CartesianPoint)CurrentEntity).Coordinates = new List1to3_LengthMeasure(); foreach (string Element in ListElements)
                        {
                            ((CartesianPoint)CurrentEntity).Coordinates.Add(new LengthMeasure(double.Parse(Element)));
                        }
                        return(CurrentEntity);
                    }
                }                                // andernfalls Ref-Element unter Entity auswerten

                CurrentEntity.AssignXmlFields(); //if (CurrentEntity is ifc.Project) Console.WriteLine(CurrentEntity.XmlTypeInfo.ToString());

                foreach (XmlAttribute a in xml.Attributes)
                {
                    if (CurrentEntity.XmlTypeInfo.XmlAttributeNameIfcTypeAttributeDict.ContainsKey(a.Name))
                    {
                        CurrentEntity.EvalTypeString(CurrentEntity.XmlTypeInfo.XmlAttributeNameIfcTypeAttributeDict[a.Name], a.Value);
                    }
                    else if (CurrentEntity.XmlTypeInfo.XmlAttributeNameIfcEnumAttributeDict.ContainsKey(a.Name))
                    {
                        CurrentEntity.EvalEnumString(CurrentEntity.XmlTypeInfo.XmlAttributeNameIfcEnumAttributeDict[a.Name], a.Value);
                    }
                    else if (CurrentEntity.XmlTypeInfo.XmlAttributeNameIfcNEnmAttributeDict.ContainsKey(a.Name))
                    {
                        CurrentEntity.EvalNEnmString(CurrentEntity.XmlTypeInfo.XmlAttributeNameIfcNEnmAttributeDict[a.Name], a.Value);
                    }
                    else
                    {
                        if ((a.Name != "id") && (a.Name != "href") && (a.Name != "href") && (a.Name != "xsi:nil") && (a.Name != "xsi:type"))
                        {
                            Console.WriteLine("unknown attribute=" + a.Name + " of element " + xml.Name);
                        }
                    }
                }
                foreach (XmlNode n in xml.ChildNodes)
                {
                    if (CurrentEntity.XmlTypeInfo.XmlElementNameIfcEntityAttributeDict.ContainsKey(n.Name))
                    {
                        CurrentEntity.EvalEntityNode(CurrentEntity.XmlTypeInfo.XmlElementNameIfcEntityAttributeDict[n.Name], n);
                    }
                    else if (CurrentEntity.XmlTypeInfo.XmlElementNameIfcSelectAttributeDict.ContainsKey(n.Name))
                    {
                        CurrentEntity.EvalSelectNode(CurrentEntity.XmlTypeInfo.XmlElementNameIfcSelectAttributeDict[n.Name], n);
                    }
                    else if (CurrentEntity.XmlTypeInfo.XmlElementNameIfcListAttributeDict.ContainsKey(n.Name))
                    {
                        CurrentEntity.EvalListNode(CurrentEntity.XmlTypeInfo.XmlElementNameIfcListAttributeDict[n.Name], n);
                    }
                    else if (CurrentEntity.XmlTypeInfo.XmlElementNameIfcInverseEntityDict.ContainsKey(n.Name))
                    {
                        CurrentEntity.EvalInverseEntityNode(CurrentEntity.XmlTypeInfo.XmlElementNameIfcInverseEntityDict[n.Name], n);
                    }
                    else if (CurrentEntity.XmlTypeInfo.XmlElementNameIfcInverseEntityListDict.ContainsKey(n.Name))
                    {
                        CurrentEntity.EvalInverseEntityListNode(CurrentEntity.XmlTypeInfo.XmlElementNameIfcInverseEntityListDict[n.Name], n);
                    }
                    else if (n.Name == "#comment")
                    {
                        CurrentEntity.EndOfLineComment = n.InnerText;
                    }
                    else//try{ }
                    {
                        Console.WriteLine("unknown childNode=" + n.Name + " of parent " + xml.Name + " of type " + TypeName);
                        Console.WriteLine(CurrentEntity.XmlTypeInfo.ToString());
                    } // ifc.ConversionBasedUnit //ifc.GeometricRepresentationContext
                }

//Console.WriteLine("C");
            }catch (Exception e) { Console.WriteLine("ERROR on EvalEntityNode:" + e.Message); Console.WriteLine(xml.Name); }//Console.ReadLine();}

            return(CurrentEntity);
        }
        private bool BuildIfcDataSet(ref SQLiteDataSet ifcDataSet)
        {
            if (ifcDataSet == null)
            {
                return(false);
            }

            SQLiteDataField sqliteField;
            string          paramName;

            foreach (Type t in Assembly.GetAssembly(typeof(ifc.ENTITY)).GetTypes())
            {
                if (t.IsClass)
                {
                    if (!t.IsAbstract)
                    {
                        if (t.IsSubclassOf(typeof(ifc.ENTITY)))
                        {
                            SQLiteDataTable dataTable = new SQLiteDataTable(t.Name);
                            SQLiteDataRow   dataRow   = new SQLiteDataRow();
                            foreach (FieldInfo field in t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy))
                            {
                                foreach (Attribute attr in field.GetCustomAttributes(true))
                                {
                                    if (attr is ifcAttribute ifcAttribute)
                                    {
                                        object[] fieldAttributes = null;
                                        if ((field.FieldType.IsGenericType) && (field.FieldType.GetGenericTypeDefinition() == typeof(Nullable <>)) && (field.FieldType.GetGenericArguments()[0].IsEnum))
                                        {
                                            fieldAttributes = field.FieldType.GetGenericArguments()[0].GetCustomAttributes(true);
                                        }
                                        else
                                        {
                                            fieldAttributes = field.FieldType.GetCustomAttributes(true);
                                        }
                                        if (null != fieldAttributes)
                                        {
                                            foreach (Attribute attr2 in fieldAttributes)
                                            {
                                                if (attr2 is ifc.ifcSqlAttribute sqlAttribute)
                                                {
                                                    paramName   = field.Name.StartsWith("_") ? field.Name.Substring(1) : field.Name;
                                                    sqliteField = new SQLiteDataField(ifcAttribute.OrdinalPosition, paramName, ENTITY.DbTypeFromTableId(sqlAttribute.SqlTableId));
                                                    sqliteField.Parameter.IsNullable = ifcAttribute.optional || ifcAttribute.derived;
                                                    dataRow.Fields.Add(sqliteField);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            dataRow.Fields.Add(new SQLiteDataField(0, "Id", DbType.Int32));
                            dataRow.Fields.Add(new SQLiteDataField(dataRow.Fields.Count, "EndOfLineComment", DbType.String));

                            // before we add the row, we sort the values by their ordinal position
                            dataRow.OrderValuesByOrdinalPosition();

                            dataTable.Rows.Add(dataRow);
                            ifcDataSet.Tables.Add(dataTable);
                        }
                    }
                }
            }
            return(true);
        }
Example #17
0
        }//--------------------------------------------------------------------------------------------------------------------

        public class EntityField { public ENTITY e; public FieldInfo f; public EntityField(ENTITY e, FieldInfo f)
                                   {
                                       this.e = e; this.f = f;
                                   }