Skip to content

Commit

Permalink
Move model axes transformation from IfcGeometricRepresentationContext…
Browse files Browse the repository at this point in the history
… into IfcMapConversion
  • Loading branch information
jbrouwerdigibase committed Nov 1, 2024
1 parent 89322d7 commit ef794ae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
12 changes: 3 additions & 9 deletions src/bt_ifcmanager/lib/lib_ifc/geolocation_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ def initialize(ifc_model)
@origin_point = nil
end

def validate
@north_vector ||= Geom::Vector3d.new([0, 1, 0])
@origin_point ||= Geom::Point3d.new([0, 0, 0])
end

def validate
@north_vector ||= Geom::Vector3d.new([0, 1, 0])
@origin_point ||= Geom::Point3d.new([0, 0, 0])
Expand Down Expand Up @@ -83,7 +78,7 @@ def get_true_north(angle)
@ifc::IfcDirection.new(@ifc_model, Geom::Vector3d.new([Math.cos(angle), Math.sin(angle), 0]))
end

def setup_geolocation
def setup_geolocation(world_transformation)
su_model = @ifc_model.su_model
return unless su_model.georeferenced?

Expand All @@ -103,15 +98,14 @@ def setup_geolocation

return unless @ifc_version != 'IFC 2x3'

# utm_point = Geom::LatLong.new([latitude, longitude]).to_utm
utm_point = su_model.point_to_utm(Geom::Point3d.new(0, 0, 0))
utm_point = su_model.point_to_utm(world_transformation.origin)

projected_crs = IfcManager::IfcProjectedCRSBuilder.build(@ifc_model) do |builder|
builder.set_from_utm(utm_point)
end

IfcManager::IfcMapConversionBuilder.build(@ifc_model) do |builder|
builder.set_from_utm(@ifc_model.representationcontext, projected_crs, utm_point)
builder.set_from_utm(@ifc_model.representationcontext, projected_crs, utm_point, world_transformation)
end
# add_additional_ifc_entities(@ifc_model.representationcontext, utm_point)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def initialize(ifc_model)
@ifc_geometric_representation_context = @ifc_module::IfcGeometricRepresentationContext.new(ifc_model)
set_coordinate_space_dimension('3')
# set_precision(1.0e-5)
set_default_world_coordinate_system
set_default_true_north
end

Expand All @@ -64,8 +63,12 @@ def set_precision(precision)
self
end

def set_world_coordinate_system(system)
@ifc_geometric_representation_context.worldcoordinatesystem = system
def set_world_coordinate_system(transformation = nil)
transformation ||= Geom::Transformation.new
@ifc_geometric_representation_context.worldcoordinatesystem = @ifc_module::IfcAxis2Placement3D.new(
@ifc_model,
transformation
)
self
end

Expand All @@ -74,14 +77,6 @@ def set_true_north(direction)
self
end

def set_default_world_coordinate_system
@ifc_geometric_representation_context.worldcoordinatesystem = @ifc_module::IfcAxis2Placement3D.new(@ifc_model)
@ifc_geometric_representation_context.worldcoordinatesystem.location = @ifc_module::IfcCartesianPoint.new(
@ifc_model, Geom::Point3d.new(0, 0, 0)
)
self
end

def set_default_true_north
# Older Sketchup versions don't have Vector2d
if Geom.const_defined?(:Vector2d)
Expand Down
6 changes: 3 additions & 3 deletions src/bt_ifcmanager/lib/lib_ifc/ifc_map_conversion_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def calculate_scale(ifc_model)
length_measure.convert
end

def set_from_utm(representationcontext, projected_crs, utm_point)
def set_from_utm(representationcontext, projected_crs, utm_point, world_transformation)
# Determine the hemisphere based on the zone letter
hemisphere = utm_point.zone_letter >= 'N' ? 'N' : 'S'
y = utm_point.y
Expand All @@ -113,8 +113,8 @@ def set_from_utm(representationcontext, projected_crs, utm_point)
set_eastings(x)
set_northings(y)
set_orthogonalheight(0.0)
set_xaxisabscissa(1.0)
set_xaxisordinate(0.0)
set_xaxisabscissa(world_transformation.xaxis.x)
set_xaxisordinate(world_transformation.xaxis.y)
set_scale(calculate_scale(@ifc_model))
end
end
Expand Down
21 changes: 11 additions & 10 deletions src/bt_ifcmanager/lib/lib_ifc/ifc_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,17 @@ def initialize(su_model, options = {})
builder.creation_date = creation_date
end

# Set root transformation as base for all other transformations
world_transformation = if @options[:model_axes]
su_model.axes.transformation.inverse
else
Geom::Transformation.new
end

# create IfcGeometricRepresentationContext for all IFC geometry objects
@representationcontext = IfcGeometricRepresentationContextBuilder.build(self) do |builder|
builder.set_context_type('Model')
builder.set_world_coordinate_system
end

@representation_sub_context_body = IfcGeometricRepresentationSubContextBuilder.build(self) do |builder|
Expand Down Expand Up @@ -164,22 +172,15 @@ def initialize(su_model, options = {})
# create a hash with all Sketchup ComponentDefinitions and their IfcProductType counterparts
@product_types = {}

# Set root transformation as base for all other transformations
transformation = if @options[:model_axes]
su_model.axes.transformation.inverse
else
Geom::Transformation.new
end

# Add georeference
GeolocationBuilder.new(self).setup_geolocation if @options[:georeference]
GeolocationBuilder.new(self).setup_geolocation(world_transformation.inverse) if @options[:georeference]

# When no entities are given for export, pass all model entities to create ifc objects
# if nested_entities option is false, pass all model entities to create ifc objects to make sure they are all seperately checked
if @options[:root_entities].empty?
create_ifc_objects(su_model.entities, transformation)
create_ifc_objects(su_model.entities, world_transformation)
else
create_ifc_objects(@options[:root_entities], transformation)
create_ifc_objects(@options[:root_entities], world_transformation)
end
end

Expand Down

0 comments on commit ef794ae

Please sign in to comment.