Example #1
0
        private static void EnhanceNullStyleInIfc(SchemaModel model, DomainStructure structure)
        {
            var nullStyle = model.Get <EnumerationType>(n => n.Name == "IfcNullStyle").FirstOrDefault();

            if (nullStyle == null)
            {
                return;
            }
            nullStyle.Name            = "IfcNullStyleEnum";
            nullStyle.PersistanceName = "IfcNullStyleEnum";

            var defType = model.New <DefinedType>(nullStyle.ParentSchema, d =>
            {
                d.Name            = "IfcNullStyle";
                d.PersistanceName = "IfcNullStyle";
                d.Domain          = nullStyle;
            });

            var selects = model.Get <SelectType>(s => s.Selections.Contains(nullStyle));

            foreach (var @select in selects)
            {
                select.Selections.Remove(nullStyle);
                select.Selections.Add(defType);
            }

            //adjust namespace
            var domain = structure.GetDomainForType("IfcNullStyle");

            domain.Types.Add("IfcNullStyleEnum");
        }
        protected string GetFullNamespace(BaseType type, string mainNamespace, DomainStructure structure)
        {
            while (true)
            {
                if (structure == null)
                {
                    return(mainNamespace);
                }

                if (type is SimpleType)
                {
                    return("System");
                }

                if (type is NamedType namedType)
                {
                    var domain = structure.GetDomainForType(namedType.Name);
                    return(domain != null ?
                           $"{mainNamespace}.{domain.Name}"
                        :
                           mainNamespace);
                }
                if (type is AggregationType aggr)
                {
                    type = aggr.ElementType;
                    continue;
                }
                throw new Exception("Unexpected type");
            }
        }
Example #3
0
        private static void FixEnumerationSelect(SchemaModel model, DomainStructure namespaces)
        {
            // predefined type is defined as a select between two enumerations. We implement selects as interfaces and enumerations
            // in C# can not implement interfaces
            var transportElement     = model.Get <EntityDefinition>(e => e.Name == "IfcTransportElement").First();
            var transportElementType = model.Get <EntityDefinition>(e => e.Name == "IfcTransportElementType").First();
            var predefinedType       = transportElement.Attributes.First(a => a.Name == "PredefinedType") as ExplicitAttribute;
            var typePredefinedType   = transportElementType.Attributes.First(a => a.Name == "PredefinedType") as ExplicitAttribute;

            var select = predefinedType.Domain as SelectType;
            var enums  = select.Selections.OfType <EnumerationType>().ToList();
            var ns     = namespaces.Domains.FirstOrDefault(d => d.Types.Any(t => t == enums[0].Name));

            var singleEnum = model.New <EnumerationType>(transportElement.ParentSchema, e => {
                e.Name            = "IfcTransportElementTypeEnum";
                e.PersistanceName = e.Name;
                e.TypeId          = model.LastTypeId + 1;
                e.Elements        = new List <ExpressId>(
                    enums.SelectMany(en => en.Elements).Distinct()
                    );
            });

            predefinedType.Domain     = singleEnum;
            typePredefinedType.Domain = singleEnum;
            ns.Types.Add(singleEnum.Name);

            // remove select and enumerations not used
            model.Remove(select);
            enums.ForEach(e => model.Remove(e));
        }
Example #4
0
        private static void MoveEnumsToInterfaces(DomainStructure domains, SchemaModel model, string dir, string prj)
        {
            const string iName   = "Interfaces";
            var          enums   = model.Get <EnumerationType>();
            var          iDomain = domains.Domains.FirstOrDefault(d => d.Name == iName);

            if (iDomain == null)
            {
                iDomain = new Domain {
                    Name = iName, Types = new List <string>()
                };
                domains.Domains.Add(iDomain);
            }
            foreach (var enumeration in enums)
            {
                var enumName = enumeration.PersistanceName;
                var domain   = domains.GetDomainForType(enumName);
                if (domain != null)
                {
                    //remove from where it is in the documentation
                    domain.Types.Remove(enumName);

                    //remove old files if generated before
                    var path = Path.Combine(dir, prj, domain.Name, enumName + ".cs");
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
                //add to interfaces namespace
                iDomain.Types.Add(enumName);
            }
        }
Example #5
0
        private void ReadDataJsonFile()
        {
            string json = System.IO.File.ReadAllText(_options.FilePath);

            _domainStructure = JsonConvert.DeserializeObject <DomainStructure>(json, new JsonSerializerSettings()
            {
                MissingMemberHandling = MissingMemberHandling.Ignore
            });
            _logger.Information($"Domain: {_domainStructure.Domain}, Structures: {_domainStructure.Structure.Count}");
        }
Example #6
0
        public void GenerateIfc4()
        {
            var settings = new GeneratorSettings
            {
                Structure  = DomainStructure.LoadIfc2X3(),
                OutputPath = "Xbim.Ifc4"
            };
            var schema = SchemaModel.Load(File.ReadAllText("IFC4_ADD2.exp"), "IFC4_ADD2");

            Generator.GenerateSchema(settings, schema);
        }
Example #7
0
        static void Main(string[] args)
        {
            var inputs = new[] {
                // @"c:\IFC_2x3_TC1",
                // @"c:\Users\Martin\Source\IFC4_ADD2\schema"
                // @"c:\Users\Martin\Source\IFC4x3_RC1\RC1\HTML\schema"
                @"c:\Users\Martin\Source\IFC4x3_RC2\html\schema"
            };

            foreach (var input in inputs)
            {
                var schemaName = input.Split('\\').First(s => s.Contains("IFC"));
                var schema     = new DomainStructure()
                {
                    Name = schemaName, Domains = new List <Domain>()
                };

                var dirs = Directory.EnumerateDirectories(input).Where(d => NameContainsIfc(d));
                foreach (var dir in dirs)
                {
                    var contentFile = Path.Combine(dir, "content.htm");
                    var domainName  = GetTitle(contentFile).Substring(3);

                    var domain = new Domain()
                    {
                        Name = domainName, Types = new List <string>()
                    };
                    schema.Domains.Add(domain);
                    var domainTypesDir = Path.Combine(dir, "lexical");

                    foreach (var file in Directory.EnumerateFiles(domainTypesDir))
                    {
                        var typeName = GetTitle(file);
                        domain.Types.Add(typeName);
                    }
                }

                using (var writer = new XmlTextWriter(schemaName + ".xml", Encoding.UTF8)
                {
                    Formatting = Formatting.Indented
                })
                {
                    var serializer = new XmlSerializer(typeof(DomainStructure));
                    serializer.Serialize(writer, schema);
                }
            }
        }
Example #8
0
        private static void Main(string[] args)
        {
            var prjPath = GetDirectory(Settings.OutputDir);
            var project = GetProject(prjPath);

            var rules   = new[] { Properties.Resources.IFC2X3_rules, Properties.Resources.IFC4_rules };
            var domains = new[] { DomainStructure.LoadIfc2X3(), DomainStructure.LoadIfc4Add1() };

            for (var i = 0; i < rules.Length; i++)
            {
                var data = rules[i];
                Settings.Structure = domains[i];
                var schema = new XmlSerializer(typeof(SchemaRules)).Deserialize(new StringReader(data)) as SchemaRules;
                ProcessSchema(schema, project);
            }
            project.Save();
            Console.Beep(400, 1000);
        }
Example #9
0
        private static DomainStructure GetDomain(SchemaDefinition schema)
        {
            switch (schema.Source)
            {
            case SchemaSources.IFC2x3_TC1:
                return(DomainStructure.LoadIfc2X3());

            case SchemaSources.IFC4:
                return(DomainStructure.LoadIfc4());

            case SchemaSources.IFC4_ADD1:
                return(DomainStructure.LoadIfc4Add1());

            case SchemaSources.IFC4_ADD2:
                return(DomainStructure.LoadIfc4Add2());

            case SchemaSources.IFC4X1_FINAL:
                return(DomainStructure.LoadIfc4x1());

            default:
                return(null);
            }
        }
Example #10
0
        public IEnumerable <EntityDomainComparisonResult> Compare(EntityDefinition oldObject, EntityDefinition newObject)
        {
            var results = new List <EntityDomainComparisonResult>();

            if (_oldDomains == null)
            {
                _oldDomains = GetDomain(oldObject.SchemaModel.FirstSchema);
            }
            if (_newDomains == null)
            {
                _newDomains = GetDomain(newObject.SchemaModel.FirstSchema);
            }
            if (_oldDomains == null || _newDomains == null)
            {
                return(results);
            }

            var oldDomain = _oldDomains.GetDomainForType(oldObject.Name);
            var newDomain = _newDomains.GetDomainForType(newObject.Name);

            if (oldDomain.Name.ToLower() == newDomain.Name.ToLower())
            {
                return(results);
            }

            var result = new EntityDomainComparisonResult(oldObject, newObject)
            {
                OldDomain = oldDomain.Name,
                NewDomain = newDomain.Name
            };

            results.Add(result);
            _results.Add(result);

            return(results);
        }
Example #11
0
 public NamedTypeHelper(NamedType type, GeneratorSettings settings)
 {
     Type      = type;
     Structure = settings.Structure;
     _settings = settings;
 }
Example #12
0
        private static void Main()
        {
            var watch = Stopwatch.StartNew();

            //set working directory
            Environment.CurrentDirectory = @"c:\Users\Martin\Source\Repos\XbimEssentials";

            //prepare all schemas
            var ifc2X3        = LoadIfc2x3();
            var ifc2X3Domains = DomainStructure.LoadIfc2X3();

            EnhanceNullStyleInIfc(ifc2X3, ifc2X3Domains);

            var ifc4        = LoadIfc4Add2WithAlignmentExtension();
            var ifc4Domains = DomainStructure.LoadIfc4x1();

            EnhanceNullStyleInIfc(ifc4, ifc4Domains);
            //Move enums into Interfaces namespace in IFC4
            MoveEnumsToInterfaces(ifc4Domains, ifc4, Environment.CurrentDirectory, "Xbim.Ifc4");


            var ifc4x3        = LoadIfc4x3_RC2();
            var ifc4x3Domains = DomainStructure.LoadIfc4x3_RC2();

            EnhanceNullStyleInIfc(ifc4x3, ifc4x3Domains);
            FixEnumerationSelect(ifc4x3, ifc4x3Domains);


            var settings = new GeneratorSettings
            {
                Structure  = ifc2X3Domains,
                OutputPath = "Xbim.Ifc2x3",
                IgnoreDerivedAttributes = GetIgnoreDerivedAttributes(),
                GenerateInterfaces      = false
            };

            // Generator.GenerateSchema(settings, ifc2X3);
            // Console.WriteLine(@"IFC2x3 without interfaces generated");
            //
            // //generate cross schema access
            // settings.CrossAccessProjectPath = "Xbim.Ifc4";
            // settings.CrossAccessStructure = ifc4Domains;
            // settings.SchemaInterfacesNamespace = "Interfaces";
            // Generator.GenerateCrossAccess(settings, ifc2X3, ifc4);
            // Console.WriteLine(@"IFC4 interface access generated for IFC2x3");
            //
            settings.Structure                 = ifc4Domains;
            settings.OutputPath                = "Xbim.Ifc4";
            settings.GenerateInterfaces        = true;
            settings.SchemaInterfacesNamespace = "Xbim.Ifc4.Interfaces";
            Generator.GenerateSchema(settings, ifc4);
            Console.WriteLine(@"IFC4 with interfaces generated");

            settings.Structure          = ifc4x3Domains;
            settings.OutputPath         = "Xbim.Ifc4x3";
            settings.GenerateInterfaces = false;
            Generator.GenerateSchema(settings, ifc4x3);
            Console.WriteLine(@"IFC4x3 RC2 without interfaces generated");

            //generate cross schema access
            settings.CrossAccessProjectPath    = "Xbim.Ifc4";
            settings.CrossAccessStructure      = ifc4Domains;
            settings.SchemaInterfacesNamespace = "Interfaces";
            Generator.GenerateCrossAccess(settings, ifc4x3, ifc4);
            Console.WriteLine(@"IFC4 interface access generated for IFC 4x3");

            // PrintNewRepresentationTypes(ifc4x3, ifc4);

            watch.Stop();
            Console.WriteLine(@"Finished in {0}s.", watch.ElapsedMilliseconds / 1000);
            Console.Beep(440, 500);
            Console.ReadKey();
        }
Example #13
0
        private static void PrintNewTypesInDomains(SchemaModel current, SchemaModel previous, DomainStructure namespaces)
        {
            var newEntities = EntityDefinitionMatch.GetMatches(current, previous)
                              .Where(m => m.MatchType == EntityMatchType.NotFound)
                              .Select(m => {
                var ns = namespaces.Domains.FirstOrDefault(d => d.Types.Any(t => t == m.Source.Name))?.Name ?? "No namespace";
                return(new { Entity = m.Source, Domain = ns });
            })
                              .GroupBy(m => m.Domain);

            foreach (var group in newEntities)
            {
                Console.WriteLine($"Namespace: {group.Key}");
                foreach (var item in group)
                {
                    Console.WriteLine($"    {item.Entity.Name}");
                }
            }
        }