Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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);
        }