public RequirementsSetUnitTests()
        {
            _requirements = new RequirementsSet();

            _requirements.AddRequirement(101, 4.8, 0.2, true, new int[38]
            {
                3, 1, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
                5, 5, 5,
            });

            _requirements.AddRequirement(102, 3.2, 0.0, false, new int[38]
            {
                3, 1, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
                5, 5, 5,
            });

            _requirements.AddRequirement(103, 1.0, 0.0, false, new int[3]
            {
                5, 4, 1
            });

            _requirements.AddRequirement(104, 1.0, 0.0, false, new int[3]
            {
                3, 4, 1
            });

            _requirements.AddRequirement(105, 1.0, 0.0, true, new int[3]
            {
                3, 3, 1
            });
        }
예제 #2
0
        private Model(IfcStore model)
        {
            _model = model;

            if (_model.Instances.Count == 0)
            {
                return;
            }

            // use all means of caching to get the initial structures quickly
            using (var entities = model.BeginEntityCaching())
                using (var cache = model.BeginInverseCaching())
                {
                    // breakdown items
                    _breakdownStructure = BreakdownItem.GetBreakdownStructure(this).ToList();

                    // milestones
                    _milestones = Milestone.GetMilestones(this).ToList();

                    // reasons
                    _reasons = Reason.GetReasons(this).ToList();

                    // actors
                    _actors = Actor.GetActors(this).ToList();

                    // all requirements in project libraries
                    _requirements = RequirementsSet.GetRequirements(this).ToList();
                }
        }
예제 #3
0
        public static RiskPlanningPDS CreateRPpds()
        {
            RequirementsSet requirements = new RequirementsSet();

            requirements.AddRequirement(101, 4.8, 0.2, true, new int[38]
            {
                3, 1, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
                5, 5, 5,
            });

            requirements.AddRequirement(102, 3.2, 0.0, false, new int[38]
            {
                3, 1, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
                5, 5, 5,
            });

            requirements.AddRequirement(103, 1.0, 0.0, false, new int[3]
            {
                5, 4, 1
            });

            requirements.AddRequirement(104, 1.0, 0.0, false, new int[3]
            {
                3, 4, 1
            });

            requirements.AddRequirement(105, 1.0, 0.0, true, new int[3]
            {
                3, 3, 1
            });

            return(new RiskPlanningPDS(requirements));
        }
예제 #4
0
        protected override RiskPlanningPDS CreateRPpds()
        {
            RequirementsSet requirements = new RequirementsSet();

            requirements.AddRequirement(101, 5.0, 0.0, false, new int[3]
            {
                1, 5, 2,
            });

            requirements.AddRequirement(102, 5.0, 1.0, false, new int[3]
            {
                1, 5, 1,
            });

            requirements.AddRequirement(103, 1.0, 0.0, true, new int[3]
            {
                5, 4, 1,
            });

            requirements.AddRequirement(104, 1.0, 0.0, true, new int[3]
            {
                3, 4, 1,
            });

            requirements.AddRequirement(105, 1.0, 0.0, true, new int[3]
            {
                2, 2, 5,
            });

            return(new RiskPlanningPDS(requirements));
        }
예제 #5
0
        public RiskPlanningPDS(RequirementsSet requirements)
        {
            if (requirements == null)
            {
                throw new InvalidNullArgumentException();
            }

            requirements.CalculateRisk();

            _requirements = requirements;
        }
예제 #6
0
        public RequirementsSet CreateRequirementSet(string name, string description)
        {
            var i            = Internal.Instances;
            var requirements = i.New <IfcProjectLibrary>(a => {
                a.Name        = name;
                a.Description = description;
            });

            var proxy = new RequirementsSet(requirements, this, new List <IfcRelDeclares>());

            _requirements.Add(proxy);

            return(proxy);
        }
예제 #7
0
        public bool RemoveFromContext(RequirementsSet requirements)
        {
            var lib = requirements.Entity;

            // it is there already
            if (!IsContextFor(requirements))
            {
                return(false);
            }

            foreach (var rel in _relations)
            {
                rel.RelatedObjects.Remove(lib);
            }

            _cache.Remove(lib.EntityLabel);
            return(true);
        }
예제 #8
0
        public bool AddToContext(RequirementsSet requirements)
        {
            // it is there already
            if (IsContextFor(requirements))
            {
                return(false);
            }

            var lib = requirements.Entity;

            if (!_relations.Any())
            {
                var rel = Model.Internal.Instances.New <IfcRelAssociatesClassification>(r => r.RelatingClassification = Entity);
                _relations.Add(rel);
            }

            var relation = _relations.FirstOrDefault();

            relation.RelatedObjects.Add(lib);
            _cache.Add(lib.EntityLabel);
            return(true);
        }
예제 #9
0
        static void Main(string[] args)
        {
            //
            ifcSIUnitMap = new Dictionary <string, IfcSIUnitName>
            {
                { "AMPERE", IfcSIUnitName.AMPERE },
                { "BECQUEREL", IfcSIUnitName.BECQUEREL },
                { "CANDELA", IfcSIUnitName.CANDELA },
                { "COULOMB", IfcSIUnitName.COULOMB },
                { "CUBIC_METRE", IfcSIUnitName.CUBIC_METRE },
                { "DEGREE_CELSIUS", IfcSIUnitName.DEGREE_CELSIUS },
                { "FARAD", IfcSIUnitName.FARAD },
                { "GRAM", IfcSIUnitName.GRAM },
                { "GRAY", IfcSIUnitName.GRAY },
                { "HENRY", IfcSIUnitName.HENRY },
                { "HERTZ", IfcSIUnitName.HERTZ },
                { "JOULE", IfcSIUnitName.JOULE },
                { "KELVIN", IfcSIUnitName.KELVIN },
                { "LUMEN", IfcSIUnitName.LUMEN },
                { "LUX", IfcSIUnitName.LUX },
                { "METRE", IfcSIUnitName.METRE },
                { "MOLE", IfcSIUnitName.MOLE },
                { "NEWTON", IfcSIUnitName.NEWTON },
                { "OHM", IfcSIUnitName.OHM },
                { "PASCAL", IfcSIUnitName.PASCAL },
                { "RADIAN", IfcSIUnitName.RADIAN },
                { "SECOND", IfcSIUnitName.SECOND },
                { "SIEMENS", IfcSIUnitName.SIEMENS },
                { "SIEVERT", IfcSIUnitName.SIEVERT },
                { "SQUARE_METRE", IfcSIUnitName.SQUARE_METRE },
                { "STERADIAN", IfcSIUnitName.STERADIAN },
                { "TESLA", IfcSIUnitName.TESLA },
                { "VOLT", IfcSIUnitName.VOLT },
                { "WATT", IfcSIUnitName.WATT },
                { "WEBER", IfcSIUnitName.WEBER }
            };
            //
            breakedownRootMap = new Dictionary <string, BreakdownItem>();          // prazdna mapa klasifikaci, bude plnena postupne
            //
            breakedownMap     = new Dictionary <int, BreakdownItem>();             // prazdna mapa trid, bude plnena postupne
            ifcPropertyMap    = new Dictionary <int, IfcSimplePropertyTemplate>(); // prazdna mapa vlastnosti, bude plnena postupne
            ifcPropertySetMap = new Dictionary <int, IfcPropertySetTemplate>();    // prazdna mapa skupin vlastnosti, bude plnena postupne
            reasonsMap        = new Dictionary <int, Reason>();                    // prazdna mapa IfcRelAssignsToControl, bude plnena postupne
            actorMap          = new Dictionary <string, Actor>();                  // prazdna mapa IfcRelAssignsToActor, bude plnena postupne
            milestonesCache   = new Dictionary <int, Milestone>();                 // prazdna mapa IfcRelAssignsToProcess, bude plnena postupne

            //using (var reader = new StreamReader("sfdi_export.csv"))
            using (var reader = new StreamReader(Console.OpenStandardInput()))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    var records = new List <RecordLine>();
                    csv.Read(); // CSV header Line 0 - XbimEditorCredentials
                    csv.ReadHeader();

                    csv.Read(); // CSV line 0 - XbimEditorCredentials
                    var record = new RecordLine
                    {
                        Id       = csv.GetField <int>("Id"),
                        Pid      = csv.GetField <int>("Pid"),
                        Lvl      = csv.GetField <int>("Lvl") + 2, // -2..+inf -> 0..+inf
                        Method   = csv.GetField("Method"),
                        GlobalId = csv.GetField("GlobalId"),
                        Par01    = csv.GetField("Par01"),
                        Par02    = csv.GetField("Par02"),
                        Par03    = csv.GetField("Par03"),
                        Par04    = csv.GetField("Par04"),
                        Par05    = csv.GetField("Par05"),
                        Par06    = csv.GetField("Par06"),
                        Par07    = csv.GetField("Par07"),
                        Par08    = csv.GetField("Par08"),
                        Par09    = csv.GetField("Par09")
                    };
                    records.Add(record);

                    //START
                    var ifcFile    = args[0]; // tempfile // "/var/www/html/tmp/DDSS.ifc";
                    var doValidate = "validate";
                    if (args.Length > 1)
                    {
                        doValidate = args[1]; // "novalidate"
                    }
                    var editor = new XbimEditorCredentials
                    {
                        ApplicationFullName       = record.Par01, // "Databáze datového standardu stavebnictví"
                        ApplicationDevelopersName = record.Par02, // "Michal Kopecký"
                        ApplicationIdentifier     = record.Par03, // "DDSS"
                        ApplicationVersion        = record.Par04, // "1.0"
                        EditorsFamilyName         = record.Par05, // "Žák"
                        EditorsGivenName          = record.Par06, // "Josef"
                        EditorsOrganisationName   = record.Par07, // "Česká agentura pro standardizaci"
                    };

                    //IfcStore.ModelProviderFactory.UseMemoryModelProvider(); // OLD VERSION
                    // set up logger to file and console
                    var logFile = Path.ChangeExtension(ifcFile, ".log");
                    Log.Logger = new LoggerConfiguration()
                                 .Enrich.FromLogContext()
                                 .WriteTo.Console()
                                 .WriteTo.File(logFile)
                                 .CreateLogger();
                    XbimLogging.LoggerFactory.AddSerilog();

                    IfcStore.ModelProviderFactory.UseMemoryModelProvider();
                    using (var model = Model.Create(editor))
                    {
                        //var i = model.Internal.Instances;

                        //using (var txn = model.BeginTransaction()) // OLD VERSION
                        using (var txn = model.Internal.BeginTransaction("Model creation"))
                        {
                            // these will keep cache of units and enums
                            // units have to be defined in the source of 'UnitMap' (compile time) while
                            // enumerations are to be defined in runtime based on the values in the DB
                            var units = new UnitMap(model);
                            var enums = new EnumsMap(model);

                            while (csv.Read())
                            {
                                record = new RecordLine
                                {
                                    Id       = csv.GetField <int>("Id"),
                                    Pid      = csv.GetField <int>("Pid"),
                                    Method   = csv.GetField("Method"),
                                    GlobalId = csv.GetField("GlobalId"),
                                    Par01    = csv.GetField("Par01"),
                                    Par02    = csv.GetField("Par02"),
                                    Par03    = csv.GetField("Par03"),
                                    Par04    = csv.GetField("Par04"),
                                    Par05    = csv.GetField("Par05"),
                                    Par06    = csv.GetField("Par06"),
                                    Par07    = csv.GetField("Par07"),
                                    Par08    = csv.GetField("Par08"),
                                    Par09    = csv.GetField("Par09")
                                };
                                records.Add(record);
                                //Console.WriteLine(record.Method);

                                if (record.Method == "IfcClassification")
                                {
                                    var root = model.CreateBreakedownRoot(record.Par01, null); // "Klasifikace DSS, CCI:ET, CCI:CS, CCI:FS"

                                    // set name in default language
                                    root.SetName("en", record.Par01);

                                    // set name in other languages
                                    root.SetName("cs", "");

                                    breakedownRootMap.Add(record.Par01, root);
                                }
                                else if (record.Method == "IfcProjectLibrary")
                                {
                                    currentRequirementsSet = model.CreateRequirementSet(record.Par01, null); // "Level of Information Need"
                                    if (record.GlobalId != "")
                                    {
                                        currentRequirementsSet.Entity.GlobalId = record.GlobalId;
                                    }

                                    // set name in default language
                                    currentRequirementsSet.SetName("en", record.Par01);

                                    // set name in other languages
                                    currentRequirementsSet.SetName("cs", "");
                                }
                                else if (record.Method == "IfcRelAssignsToControl")
                                {
                                    // Purpose of the data requirement/exchange
                                    if (!reasonsMap.TryGetValue(record.Id, out Reason reason))
                                    {
                                        reason = model.CreateReason(record.Par01, record.Par02);
                                        if (record.GlobalId != "")
                                        {
                                            reason.Entity.GlobalId = record.GlobalId;
                                        }
                                        reasonsMap.Add(record.Id, reason);

                                        // set name in default language
                                        reason.SetName("en", record.Par01);

                                        // set name in other languages
                                        reason.SetName("cs", record.Par02);
                                    }
                                    reason.AddToContext(currentRequirementsSet);
                                }
                                else if (record.Method == "IfcRelAssignsToActor")
                                {
                                    // Actor / Role = Who is interested in the data
                                    if (!actorMap.TryGetValue(record.GlobalId, out Actor actor))
                                    {
                                        actor = model.CreateActor(record.Par01, null);
                                        if (record.GlobalId != "")
                                        {
                                            actor.Entity.GlobalId = record.GlobalId;
                                        }
                                        actorMap.Add(record.GlobalId, actor);

                                        // set name in default language
                                        actor.SetName("en", record.Par01);

                                        // set name in other languages
                                        actor.SetName("cs", "");
                                    }
                                    actor.AddToContext(currentRequirementsSet);
                                }
                                else if (record.Method == "IfcRelAssignsToProcess")
                                {
                                    // Milestone = point in time
                                    if (!milestonesCache.TryGetValue(record.Id, out Milestone milestone))
                                    {
                                        milestone = model.CreateMilestone(record.Par02, null);
                                        milestone.Entity.IsMilestone = record.Par03 == "true";

                                        if (record.GlobalId != "")
                                        {
                                            milestone.Entity.GlobalId = record.GlobalId;
                                        }
                                        milestonesCache.Add(record.Id, milestone);

                                        // set name in default language
                                        milestone.SetName("en", record.Par01);

                                        // set name in other languages
                                        milestone.SetName("cs", record.Par02);
                                    }
                                    milestone.AddToContext(currentRequirementsSet);
                                }
                                else if (record.Method == "IfcClassificationReference")
                                {
                                    // Class within classification
                                    // Set parent
                                    BreakdownItem parent = null;
                                    if (record.Par04 == "")
                                    {
                                        //Program.ifcCRS = Program.ifcCL; // classification for root class
                                        parent = breakedownRootMap[record.Par09]; // classification for root class
                                    }
                                    else
                                    {
                                        parent = breakedownMap[record.Pid]; // parent class othewise
                                    }
                                    // Optionally add new class
                                    if (!breakedownMap.ContainsKey(record.Id))
                                    {
                                        var item = model.CreateBreakedownItem(record.Par02, record.Par03, null, parent);
                                        breakedownMap.Add(record.Id, item);

                                        // set name in default language
                                        item.SetName("en", record.Par01);

                                        // set name in other languages
                                        item.SetName("cs", record.Par02);
                                    }
                                    ;
                                }
                                else if (record.Method == "IfcRelAssociatesClassification")
                                {
                                    breakedownMap[record.Id].AddToContext(currentRequirementsSet);
                                }
                                else if (record.Method == "IfcRelDeclares")
                                {
                                    // nothing to do, handled by LOIN library
                                }
                                else if (record.Method == "IfcPropertySetTemplate")
                                {
                                    if (ifcPropertySetMap.ContainsKey(record.Id))
                                    {
                                        PropertySetReused  = true;
                                        currentPropertySet = ifcPropertySetMap[record.Id];
                                    }
                                    else
                                    {
                                        PropertySetReused  = false;
                                        currentPropertySet = model.CreatePropertySetTemplate(record.Par01, null); // "Základní informace o místnostech"

                                        // set name in default language
                                        currentPropertySet.SetName("en", record.Par01);

                                        // set name in other languages
                                        currentPropertySet.SetName("cs", record.Par02);

                                        //ApplicableEntity
                                        //Description
                                        if (record.Par03 != "")
                                        {
                                            currentPropertySet.Description = record.Par03;

                                            // set name in default language
                                            currentPropertySet.SetDescription("en", record.Par03);

                                            // set name in other languages
                                            currentPropertySet.SetDescription("cs", record.Par04);
                                        }
                                        else if (record.Par04 != "")
                                        {
                                            currentPropertySet.Description = record.Par04;

                                            // set name in default language
                                            currentPropertySet.SetDescription("en", "");

                                            // set name in other languages
                                            currentPropertySet.SetDescription("cs", record.Par04);
                                        }
                                        if (record.GlobalId != "")
                                        {
                                            currentPropertySet.GlobalId = record.GlobalId;
                                        }
                                        ifcPropertySetMap.Add(record.Id, currentPropertySet);
                                    };
                                    currentRequirementsSet.Add(currentPropertySet);
                                }
                                else if (record.Method == "IfcSimplePropertyTemplate")
                                {
                                    if (!PropertySetReused)
                                    {
                                        if (!ifcPropertyMap.TryGetValue(record.Id, out IfcSimplePropertyTemplate propertyTemplate))
                                        {
                                            propertyTemplate = model.New <IfcSimplePropertyTemplate>(p =>
                                            {
                                                p.Name = record.Par08; // "Název EN"

                                                // Set description in primary language
                                                p.SetName("en", record.Par08);

                                                // Set description in other languages
                                                p.SetName("cs", record.Par01);
                                            });
                                            if (record.GlobalId != "")
                                            {
                                                propertyTemplate.GlobalId = record.GlobalId;
                                            }
                                            //Description
                                            if (record.Par09 != "")
                                            {
                                                propertyTemplate.Description = record.Par09;

                                                // Set description in primary language
                                                propertyTemplate.SetDescription("en", record.Par09);

                                                // Set description in other languages
                                                propertyTemplate.SetDescription("cs", record.Par02);
                                            }
                                            else if (record.Par02 != "")
                                            {
                                                propertyTemplate.Description = record.Par02;

                                                // Set description in primary language
                                                propertyTemplate.SetDescription("en", "");

                                                // Set description in other languages
                                                propertyTemplate.SetDescription("cs", record.Par02);
                                            }

                                            if (record.Par03 != "") // dataunit
                                            {
                                                propertyTemplate.PrimaryUnit = units[record.Par03];
                                            }
                                            if (record.Par04 != "") // nameof(X) -> "X"
                                            {
                                                propertyTemplate.PrimaryMeasureType = record.Par04;
                                            }
                                            //TemplateType
                                            switch (record.Par05)
                                            {
                                            case "P_SINGLEVALUE":
                                                propertyTemplate.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE;
                                                break;

                                            case "P_ENUMERATEDVALUE":
                                                propertyTemplate.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_ENUMERATEDVALUE;
                                                propertyTemplate.Enumerators  = enums.GetOrAdd(record.Par06, record.Par07.Split(",", StringSplitOptions.RemoveEmptyEntries)); // { "Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota", "Neděle"}
                                                break;

                                            case "P_REFERENCEVALUE":
                                                propertyTemplate.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_REFERENCEVALUE;
                                                break;

                                            case "P_BOUNDEDVALUE":
                                                propertyTemplate.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_BOUNDEDVALUE;
                                                break;

                                            default:
                                                Console.WriteLine("IfcSimplePropertyTemplate: UNKNOWN TEMPLATE TYPE ", record.Par05);
                                                //Program.ifcSPT.TemplateType = ...
                                                break;
                                            }
                                            ;
                                            ifcPropertyMap.Add(record.Id, propertyTemplate);
                                        }
                                        ;

                                        currentPropertySet.HasPropertyTemplates.Add(propertyTemplate);
                                        currentPropertyTemplate = propertyTemplate;
                                    }
                                    ;
                                }
                                else if (record.Method == "IfcSIUnit")
                                {
                                    var unit = model.New <IfcSIUnit>();
                                    //Name
                                    //Program.ifcISU.Name = IfcSIUnitName.SQUARE_METRE;
                                    try
                                    {
                                        unit.Name = ifcSIUnitMap[record.Par01];
                                    }
                                    catch (KeyNotFoundException)
                                    {
                                        Console.WriteLine("IfcSIUnit: UNKNOWN NAME ", record.Par01);
                                        //ifcISU.Name = IfcSIUnitName. ...
                                    }
                                    //UnitType
                                    switch (record.Par02)
                                    {
                                    case "AREAUNIT":
                                        unit.UnitType = IfcUnitEnum.AREAUNIT;
                                        break;

                                    default:
                                        Console.WriteLine("IfcSIUnit: UNKNOWN UNIT TYPE ", record.Par02);
                                        //ifcISU.UnitType = ...
                                        break;
                                    }
                                    ;
                                    currentPropertyTemplate.PrimaryUnit = unit;
                                }
                                else if (record.Method == "IfcDocumentReference")
                                {
                                    // Declared data requirements / templates
                                    model.New <IfcRelAssociatesDocument>(rd => {
                                        rd.RelatedObjects.Add(currentPropertyTemplate);
                                        rd.RelatingDocument = model.New <IfcDocumentReference>(doc => {
                                            doc.Identification = record.Par01; // "Vyhláška č. 441/2013 Sb."
                                            doc.Location       = record.Par02; // "https://www.mfcr.cz/cs/legislativa/legislativni-dokumenty/2013/vyhlaska-c-441-2013-sb-16290"
                                            doc.Name           = record.Par03; // "Vyhláška k provedení zákona o oceňování majetku (oceňovací vyhláška)"
                                        });
                                    });
                                }
                                ;
                            }
                            ; // konec while read
                            txn.Commit();
                        }

                        // validate schema and proper units
                        var validator = new IfcValidator();
                        var valid     = validator.Check(model.Internal);
                        if (doValidate != "novalidate" && !valid)
                        {
                            throw new Exception("Invalid model shouldn't be stored and used for any purposes.");
                        }

                        // this is stdout if you want to use it
                        //var stdout = Console.OpenStandardOutput();

                        // writing to stream (any stream)
                        using (var stream = File.Create(ifcFile))
                        {
                            if (Path.GetExtension(ifcFile) == ".ifcxml")
                            {
                                model.Internal.SaveAsIfcXml(stream);
                            }
                            else
                            {
                                model.Internal.SaveAsIfc(stream);
                            };
                        }

                        //model.SaveAs("DDSS.ifc");
                        //model.SaveAs("DDSS.ifcxml");
                        //model.SaveAs(ifcFile); // args[0]
                    }
                    //STOP
                }// csv
        }
예제 #10
0
 public bool IsContextFor(RequirementsSet requirements) => _cache.Contains(requirements.Entity.EntityLabel);