Skip to content

Commit

Permalink
Merge pull request #24 from RyugaRyuzaki/develop
Browse files Browse the repository at this point in the history
add export ifc
  • Loading branch information
RyugaRyuzaki committed Jun 14, 2024
2 parents 6dceb89 + b180c7a commit a5488d6
Show file tree
Hide file tree
Showing 98 changed files with 1,874 additions and 547 deletions.
35 changes: 35 additions & 0 deletions packages/clay/src/base/IfcInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {IFC4X3 as IFC} from "web-ifc";
import {IfcUnit} from "./IfcUnit";
import {Model} from "./model";
const version = "0.0.1";
const application = "Web application Bim-modeling";
export class IfcInfo {
Expand Down Expand Up @@ -144,4 +145,38 @@ export class IfcInfo {
this.IfcAxis2PlacementGlobal3D,
this.IfcDirectionTrueNorth3D
);
get IfcUnitAssignment() {
return this.ifcUnit.IfcUnitAssignment;
}
/**
*
*/
constructor(private model: Model) {}
export() {
this.model.set(this.IfcActorRole);
this.model.set(this.IfcAddress);
this.model.set(this.IfcOrganization);
this.model.set(this.IfcPerson);
this.model.set(this.IfcPersonAndOrganization);
this.model.set(this.IfcApplication);
this.model.set(this.IfcOwnerHistory);
this.model.set(this.IfcCartesianPointGlobal2D);
this.model.set(this.IfcCartesianPointGlobal3D);
this.model.set(this.IfcDirectionGlobal2D);
this.model.set(this.IfcDirectionGlobal3D);
this.model.set(this.IfcDirectionLocal3D);
this.model.set(this.IfcDirectionTrueNorth3D);
this.model.set(this.IfcAxisXPositive);
this.model.set(this.IfcAxisXNegative);
this.model.set(this.IfcAxisYPositive);
this.model.set(this.IfcAxisYNegative);
this.model.set(this.IfcAxisZPositive);
this.model.set(this.IfcAxisZNegative);
this.model.set(this.IfcAxis2PlacementGlobal3D);
this.model.set(this.IfcAxis2PlacementGlobal);
this.model.set(this.IfcBuildingAddress);
this.model.set(this.IfcSiteAddress);

this.ifcUnit.export(this.model);
}
}
168 changes: 97 additions & 71 deletions packages/clay/src/base/IfcUnit.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
import {IFC4X3 as IFC} from "web-ifc";
import {Model} from "./model";

export class IfcUnit {
private IfcAxis2PlacementGlobal3D!: IFC.IfcAxis2Placement3D;
private IfcDirectionTrueNorth3D!: IFC.IfcDirection;
IfcDimensionalExponents: IFC.IfcDimensionalExponents =
new IFC.IfcDimensionalExponents(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
new IFC.IfcDimensionalExponents(1, 1, 1, 1, 1, 1, 1);
IfcLengthUnit: IFC.IfcSIUnit = new IFC.IfcSIUnit(
this.IfcDimensionalExponents,
IFC.IfcUnitEnum.LENGTHUNIT,
IFC.IfcSIPrefix,
IFC.IfcSIUnitName
"",
IFC.IfcSIUnitName.METRE
);
IfcAreaUnit: IFC.IfcSIUnit = new IFC.IfcSIUnit(
this.IfcDimensionalExponents,
IFC.IfcUnitEnum.AREAUNIT,
IFC.IfcSIPrefix,
IFC.IfcSIUnitName
"",
IFC.IfcSIUnitName.SQUARE_METRE
);
IfcVolumeUnit: IFC.IfcSIUnit = new IFC.IfcSIUnit(
this.IfcDimensionalExponents,
IFC.IfcUnitEnum.VOLUMEUNIT,
IFC.IfcSIPrefix,
IFC.IfcSIUnitName
"",
IFC.IfcSIUnitName.CUBIC_METRE
);
IfcPlaneAngleUnit: IFC.IfcSIUnit = new IFC.IfcSIUnit(
this.IfcDimensionalExponents,
IFC.IfcUnitEnum.PLANEANGLEUNIT,
new IFC.IfcSIPrefix(),
new IFC.IfcSIUnitName()
IFC.IfcSIPrefix.ATTO,
IFC.IfcSIUnitName.RADIAN
);
IfcMassUnit: IFC.IfcSIUnit = new IFC.IfcSIUnit(
this.IfcDimensionalExponents,
IFC.IfcUnitEnum.MASSUNIT,
new IFC.IfcSIPrefix(),
new IFC.IfcSIUnitName()
IFC.IfcSIPrefix.KILO,
IFC.IfcSIUnitName.GRAM
);
IfcTimeUnit: IFC.IfcSIUnit = new IFC.IfcSIUnit(
this.IfcDimensionalExponents,
IFC.IfcUnitEnum.TIMEUNIT,
new IFC.IfcSIPrefix(),
new IFC.IfcSIUnitName()
IFC.IfcSIPrefix.ATTO,
IFC.IfcSIUnitName.SECOND
);
IfcThermoDynamicTemperatureUnit: IFC.IfcSIUnit = new IFC.IfcSIUnit(
this.IfcDimensionalExponents,
IFC.IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT,
new IFC.IfcSIPrefix(),
new IFC.IfcSIUnitName()
IFC.IfcSIPrefix.ATTO,
IFC.IfcSIUnitName.PASCAL
);
IfcLuminousIntensityUnit: IFC.IfcSIUnit = new IFC.IfcSIUnit(
this.IfcDimensionalExponents,
IFC.IfcUnitEnum.LUMINOUSINTENSITYUNIT,
new IFC.IfcSIPrefix(),
new IFC.IfcSIUnitName()
IFC.IfcSIPrefix.ATTO,
IFC.IfcSIUnitName.LUMEN
);

IfcMeasureWithUnit = new IFC.IfcMeasureWithUnit(
Expand All @@ -74,63 +73,90 @@ export class IfcUnit {
this.IfcThermoDynamicTemperatureUnit,
this.IfcLuminousIntensityUnit,
]);
IfcGeometricRepresentationContext = new IFC.IfcGeometricRepresentationContext(
new IFC.IfcLabel("Model"),
new IFC.IfcLabel("0.0"),
new IFC.IfcDimensionCount(0.0),
new IFC.IfcReal(1e-3),
this.IfcAxis2PlacementGlobal3D,
this.IfcDirectionTrueNorth3D
);
IfcGeometricRepresentationSubContext1 =
new IFC.IfcGeometricRepresentationSubContext(
new IFC.IfcLabel("Axis"),
new IFC.IfcLabel("Model"),
this.IfcAxis2PlacementGlobal3D,
this.IfcGeometricRepresentationContext,
new IFC.IfcPositiveRatioMeasure(1e-3),
IFC.IfcGeometricProjectionEnum.GRAPH_VIEW,
new IFC.IfcLabel("")
);
IfcGeometricRepresentationSubContext2 =
new IFC.IfcGeometricRepresentationSubContext(
new IFC.IfcLabel("Body"),
new IFC.IfcLabel("Model"),
this.IfcAxis2PlacementGlobal3D,
this.IfcGeometricRepresentationContext,
new IFC.IfcPositiveRatioMeasure(1e-3),
IFC.IfcGeometricProjectionEnum.MODEL_VIEW,
new IFC.IfcLabel("")
);
IfcGeometricRepresentationSubContext3 =
new IFC.IfcGeometricRepresentationSubContext(
new IFC.IfcLabel("Box"),
new IFC.IfcLabel("Model"),
this.IfcAxis2PlacementGlobal3D,
this.IfcGeometricRepresentationContext,
new IFC.IfcPositiveRatioMeasure(1e-3),
IFC.IfcGeometricProjectionEnum.MODEL_VIEW,
new IFC.IfcLabel("")
);
IfcGeometricRepresentationSubContext4 =
new IFC.IfcGeometricRepresentationSubContext(
new IFC.IfcLabel("Box"),
new IFC.IfcLabel("Model"),
this.IfcAxis2PlacementGlobal3D,
this.IfcGeometricRepresentationContext,
new IFC.IfcPositiveRatioMeasure(1e-3),
IFC.IfcGeometricProjectionEnum.USERDEFINED,
new IFC.IfcLabel("")
);
IfcGeometricRepresentationContext!: IFC.IfcGeometricRepresentationContext;
IfcGeometricRepresentationSubContext1!: IFC.IfcGeometricRepresentationSubContext;
IfcGeometricRepresentationSubContext2!: IFC.IfcGeometricRepresentationSubContext;
IfcGeometricRepresentationSubContext3!: IFC.IfcGeometricRepresentationSubContext;
IfcGeometricRepresentationSubContext4!: IFC.IfcGeometricRepresentationSubContext;

/**
*
*/
constructor(
IfcAxis2PlacementGlobal3D: IFC.IfcAxis2Placement3D,
IfcDirectionTrueNorth3D: IFC.IfcDirection
public IfcAxis2PlacementGlobal3D: IFC.IfcAxis2Placement3D,
public IfcDirectionTrueNorth3D: IFC.IfcDirection
) {
this.IfcAxis2PlacementGlobal3D = IfcAxis2PlacementGlobal3D;
this.IfcDirectionTrueNorth3D = IfcDirectionTrueNorth3D;
this.IfcGeometricRepresentationContext =
new IFC.IfcGeometricRepresentationContext(
new IFC.IfcLabel("Model"),
new IFC.IfcLabel("0.0"),
new IFC.IfcDimensionCount(0.0),
new IFC.IfcReal(1e-3),
this.IfcAxis2PlacementGlobal3D,
this.IfcDirectionTrueNorth3D
);
this.IfcGeometricRepresentationSubContext1 =
new IFC.IfcGeometricRepresentationSubContext(
new IFC.IfcLabel("Axis"),
new IFC.IfcLabel("Model"),
this.IfcAxis2PlacementGlobal3D,
this.IfcGeometricRepresentationContext,
null,
IFC.IfcGeometricProjectionEnum.GRAPH_VIEW,
new IFC.IfcLabel("")
);
this.IfcGeometricRepresentationSubContext2 =
new IFC.IfcGeometricRepresentationSubContext(
new IFC.IfcLabel("Body"),
new IFC.IfcLabel("Model"),
this.IfcAxis2PlacementGlobal3D,
this.IfcGeometricRepresentationContext,
null,

IFC.IfcGeometricProjectionEnum.MODEL_VIEW,
new IFC.IfcLabel("")
);
this.IfcGeometricRepresentationSubContext3 =
new IFC.IfcGeometricRepresentationSubContext(
new IFC.IfcLabel("Box"),
new IFC.IfcLabel("Model"),
this.IfcAxis2PlacementGlobal3D,
this.IfcGeometricRepresentationContext,
null,
IFC.IfcGeometricProjectionEnum.MODEL_VIEW,
new IFC.IfcLabel("")
);
this.IfcGeometricRepresentationSubContext4 =
new IFC.IfcGeometricRepresentationSubContext(
new IFC.IfcLabel("Box"),
new IFC.IfcLabel("Model"),
this.IfcAxis2PlacementGlobal3D,
this.IfcGeometricRepresentationContext,
null,

IFC.IfcGeometricProjectionEnum.USERDEFINED,
new IFC.IfcLabel("")
);
}
export(model: Model) {
model.set(this.IfcAxis2PlacementGlobal3D!);
model.set(this.IfcDirectionTrueNorth3D!);
model.set(this.IfcDimensionalExponents);
model.set(this.IfcLengthUnit);
model.set(this.IfcAreaUnit);
model.set(this.IfcVolumeUnit);
model.set(this.IfcPlaneAngleUnit);
model.set(this.IfcMassUnit);
model.set(this.IfcTimeUnit);
model.set(this.IfcThermoDynamicTemperatureUnit);
model.set(this.IfcLuminousIntensityUnit);
model.set(this.IfcMeasureWithUnit);
model.set(this.IfcConversionBasedUnit);
model.set(this.IfcUnitAssignment);
model.set(this.IfcGeometricRepresentationContext);
model.set(this.IfcGeometricRepresentationSubContext1);
model.set(this.IfcGeometricRepresentationSubContext2);
model.set(this.IfcGeometricRepresentationSubContext3);
model.set(this.IfcGeometricRepresentationSubContext4);
}
}
20 changes: 9 additions & 11 deletions packages/clay/src/base/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {IfcLineObject} from "web-ifc";
import {IfcInfo} from "./IfcInfo";

export class Model {
ifcInfo = new IfcInfo();
ifcInfo = new IfcInfo(this);
get IfcOwnerHistory() {
return this.ifcInfo.IfcOwnerHistory;
}
Expand All @@ -17,7 +17,6 @@ export class Model {

ifcAPI = new WEBIFC.IfcAPI();

private _context?: WEBIFC.IFC4X3.IfcRepresentationContext;
private _modelID?: number;

get modelID() {
Expand All @@ -28,20 +27,13 @@ export class Model {
}

get context() {
if (this._context === undefined) {
throw new Error("Model not initialized! Call the init() method.");
}
return this._context;
return this.ifcInfo.ifcUnit.IfcGeometricRepresentationContext;
}

async init() {
await this.ifcAPI.Init();
this.ifcAPI.SetLogLevel(WEBIFC.LogLevel.LOG_LEVEL_OFF);
this._modelID = this.ifcAPI.CreateModel({schema: WEBIFC.Schemas.IFC4X3});
this._context = new WEBIFC.IFC4X3.IfcRepresentationContext(
new WEBIFC.IFC4X3.IfcLabel("Default"),
new WEBIFC.IFC4X3.IfcLabel("Model")
);
this._modelID = this.ifcAPI.CreateModel({schema: "IFC4X3_ADD2"});
}

set(item: WEBIFC.IfcLineObject) {
Expand Down Expand Up @@ -96,4 +88,10 @@ export class Model {
this._modelID++;
this.ifcAPI.OpenModel(model);
}
export() {
if (this._modelID === undefined) {
throw new Error("Malformed model!");
}
return this.ifcAPI.SaveModel(this._modelID);
}
}
2 changes: 1 addition & 1 deletion packages/clay/src/elements/Beam/SimpleBeam/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class SimpleBeamType extends DynamicElementType<SimpleBeam> {
const {Name, Description, ObjectType} = config;
this.attributes = new IFC.IfcBeamType(
new IFC.IfcGloballyUniqueId(uuidv4()),
this.model.IfcOwnerHistory,
null,
new IFC.IfcLabel(Name),
new IFC.IfcLabel(Description),
new IFC.IfcLabel(ObjectType),
Expand Down
Loading

0 comments on commit a5488d6

Please sign in to comment.