Skip to content

Commit

Permalink
Extract utils for line and polygon element
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhankoral committed Nov 30, 2023
1 parent 85e64c5 commit 2befefa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
20 changes: 3 additions & 17 deletions speckle_connector/src/speckle_objects/gis/line_element.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require_relative 'utils'
require_relative '../base'
require_relative '../other/transform'
require_relative '../other/block_definition'
Expand All @@ -14,26 +15,11 @@ module GIS
class LineElement < Base
SPECKLE_TYPE = OBJECTS_GIS_LINEELEMENT

def self.get_definition_name(obj, attributes)
return obj['name'] unless obj['name'].nil?

return attributes['name'] unless attributes['name'].nil?

return "def::#{obj['id']}"
end

def self.get_qgis_attributes(obj)
attributes = obj['attributes'].to_h
speckle_properties = %w[id speckle_type totalChildrenCount units applicationId]
speckle_properties.each { |key| attributes.delete(key) }
attributes
end

# Handles polygon element differently from display value.
def self.to_native(state, obj, layer, entities, &convert_to_native)
attributes = get_qgis_attributes(obj)
attributes = GIS.get_qgis_attributes(obj)
obj = collect_definition_geometries(obj)
obj['name'] = get_definition_name(obj, attributes)
obj['name'] = GIS.get_definition_name(obj, attributes)

state, _definitions = Other::BlockDefinition.to_native(
state, obj, layer, entities, &convert_to_native
Expand Down
20 changes: 3 additions & 17 deletions speckle_connector/src/speckle_objects/gis/polygon_element.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require_relative 'utils'
require_relative '../base'
require_relative '../other/transform'
require_relative '../other/block_definition'
Expand All @@ -14,26 +15,11 @@ module GIS
class PolygonElement < Base
SPECKLE_TYPE = OBJECTS_GIS_POLYGONELEMENT

def self.get_definition_name(obj, attributes)
return obj['name'] unless obj['name'].nil?

return attributes['name'] unless attributes['name'].nil?

return "def::#{obj['id']}"
end

def self.get_qgis_attributes(obj)
attributes = obj['attributes'].to_h
speckle_properties = %w[id speckle_type totalChildrenCount units applicationId]
speckle_properties.each { |key| attributes.delete(key) }
attributes
end

# Handles polygon element differently from display value.
def self.to_native(state, obj, layer, entities, &convert_to_native)
attributes = get_qgis_attributes(obj)
attributes = GIS.get_qgis_attributes(obj)
obj = collect_definition_geometries(obj)
obj['name'] = get_definition_name(obj, attributes)
obj['name'] = GIS.get_definition_name(obj, attributes)

state, _definitions = Other::BlockDefinition.to_native(
state, obj, layer, entities, &convert_to_native
Expand Down
29 changes: 29 additions & 0 deletions speckle_connector/src/speckle_objects/gis/utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require_relative '../base'
require_relative '../other/transform'
require_relative '../other/block_definition'
require_relative '../other/block_instance'
require_relative '../../constants/type_constants'
require_relative '../../sketchup_model/dictionary/dictionary_handler'

module SpeckleConnector
module SpeckleObjects
module GIS
def self.get_definition_name(obj, attributes)
return obj['name'] unless obj['name'].nil?

return attributes['name'] unless attributes['name'].nil?

return "def::#{obj['id']}"
end

def self.get_qgis_attributes(obj)
attributes = obj['attributes'].to_h
speckle_properties = %w[id speckle_type totalChildrenCount units applicationId]
speckle_properties.each { |key| attributes.delete(key) }
attributes
end
end
end
end

0 comments on commit 2befefa

Please sign in to comment.