Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a light source to an IfcLampType #123

Closed
KonstantinHamm opened this issue Nov 24, 2017 · 5 comments
Closed

How to add a light source to an IfcLampType #123

KonstantinHamm opened this issue Nov 24, 2017 · 5 comments

Comments

@KonstantinHamm
Copy link

Hi all,
first of all I want to thank you for that awesome piece of software that you are creating. Keep up the good work!

My question is: How do I add a light source like IfcLightSourceGoniometric to an IfcLampType?
I already have the IfcLightDistributionData at hand. Here is the piece that I've tried to implement:

private IfcLightSourceGoniometric CreateLightSourceGoniometric(int luminousFlux)
{
	return _ifcExportModel.IfcStore.Instances.New<IfcLightSourceGoniometric>(l =>
	{
		l.LuminousFlux = luminousFlux;
                // Correct photometric data is present
		l.LightDistributionDataSource = LoadDataSource(_ifcExportModel.IfcStore);
		l.Name = "Photometry xyz";
		l.ColourAppearance = _ifcExportModel.IfcStore.Instances.New<IfcColourRgb>(c =>
		{
			c.Red = 244;
			c.Green = 241;
			c.Blue = 66;
		});
	});
}

private IfcFlowTerminal CreateSingleIfcLamp(ILightSource lightSource)
{
    var lampName = GetLampNameSave(lightSource);
    var lampDescription = GetLampTypeDescriptionSave(lightSource);
    var goniometricShapeDefinition = CreateLightSourceGoniometric
        (lightSource.LightSourceInformation.Value.LampLightFlux.Value);

    var shapeRepresentation = _ifcExportModel.IfcStore.Instances.New<IfcShapeRepresentation>(s =>
    {
        s.ContextOfItems = _ifcExportModel.IfcStore.Instances.OfType<IfcGeometricRepresentationContext>
           ().FirstOrDefault();
        s.Items.Add(goniometricShapeDefinition);
    });

    var productDefinitionShape = _ifcExportModel.IfcStore.Instances.New<IfcProductDefinitionShape>
        (pds =>
    {
        pds.Representations.Add(shapeRepresentation);
    });

    var lampFlowTerminal = _ifcExportModel.IfcStore.Instances.New<IfcFlowTerminal>(lft =>
    {
        Guid lftGuid;
        lft.GlobalId = IfcGloballyUniqueId.FromGuid(Guid.TryParse(lightSource.GlobalId, out lftGuid) ? lftGuid : Guid.NewGuid());
        lft.Representation = productDefinitionShape;
    });

    lampFlowTerminal.IsTypedBy = _ifcExportModel.IfcStore.Instances.New<IfcLampType>(lamp =>
    {
        lamp.Name = lampName;
        lamp.Description = lampDescription;
    });

    return lampFlowTerminal;
	
   // After I've created this IfcFlowTerminal the lamp is connected via ports to an IfcLightFixture. 
}

Am I creating and adding the LightSourceGoniometric the right way? Unfortunately I could not find an Ifc-Viewer / Editor that is able to visualize the light distribution curve.

@martin1cerny
Copy link
Member

Hi @KonstantinHamm ,

there is a facility in xBIM to check if the data you have created is valid IFC according to schema constrains and rules. However, specific implementation should be directed by information requirements of the receiving application.

Martin

@KonstantinHamm
Copy link
Author

Hi @martin1cerny,
can you provide a code snippet how to do a validation on a IfcFlowTerminal/LightFixtureType?

Thank you in advance.

Konstantin

@CBenghi
Copy link
Member

CBenghi commented Dec 7, 2017

@KonstantinHamm,
if you wish to validate without code you can use the feature of XbimXplorer.
It's a bit hidden.

You can download xbimxplorer from here.
To access the validation features you have to enable the developer mode in the settings (In the menu select view->settings).

Then select in the menu View->Developer windows->IFC Validation

image

Press the "Validate model" button and the validation report is presented in the text as shown above.
If you look at Xplorer code you'll see how to do validation programmatically, if interested.

@martin1cerny
Copy link
Member

Or in code, in case you needed automated quality check:

using (var model = IfcStore.Open(file, null, 0))
{
    var v = new IfcValidator
    {
        ValidateLevel = ValidationFlags.All,
        CreateEntityHierarchy = true
    };
    var errors = v.Validate(model);
    foreach (var validationResult in new IfcValidationReporter(errors))
    {
        Console.WriteLine(validationResult);
    }
}

@KonstantinHamm
Copy link
Author

KonstantinHamm commented Dec 7, 2017

I was able to find a problem with my IfcLightSourceGoniometric. (XbimXplorer tells me the IfcLightSourceGoniometric does not have a geometric representation). I guess i'll have to find out why :)
Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants