Feat(dui3): add properties (#402)
* rename sketchup_attributes with properties for send * receive properties * handle send receive properties
This commit is contained in:
@@ -153,6 +153,11 @@ module SpeckleConnector3
|
||||
|
||||
definition_name = proxy['name']
|
||||
definition = state.sketchup_state.sketchup_model.definitions.add(definition_name)
|
||||
properties = proxy['properties'] || proxy['sketchup_attributes']
|
||||
unless properties.nil?
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(definition, properties['dictionaries'])
|
||||
end
|
||||
definition.behavior.always_face_camera = proxy['alwaysFaceCamera'] if proxy['alwaysFaceCamera']
|
||||
@definition_proxies[proxy['applicationId']] = SpeckleObjects::InstanceDefinitionProxy.new(
|
||||
definition,
|
||||
|
||||
@@ -46,11 +46,16 @@ module SpeckleConnector3
|
||||
instance_id = entity.persistent_id.to_s
|
||||
definition_id = entity.definition.persistent_id.to_s
|
||||
|
||||
instance_dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_speckle(entity)
|
||||
instance_att = instance_dictionaries.any? ? { dictionaries: instance_dictionaries } : {}
|
||||
|
||||
instance_proxies[instance_id] = SpeckleObjects::InstanceProxy.new(
|
||||
definition_id,
|
||||
SpeckleObjects::Other::Transform.from_transformation(entity.transformation, @units).value,
|
||||
depth,
|
||||
@units,
|
||||
sketchup_attributes: instance_att,
|
||||
application_id: instance_id
|
||||
)
|
||||
|
||||
@@ -70,7 +75,17 @@ module SpeckleConnector3
|
||||
return
|
||||
end
|
||||
|
||||
definition_proxy = SpeckleObjects::InstanceDefinitionProxy.new(entity.definition, [], depth, application_id: definition_id)
|
||||
definition_dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_speckle(entity.definition)
|
||||
definition_att = definition_dictionaries.any? ? { dictionaries: definition_dictionaries } : {}
|
||||
|
||||
definition_proxy = SpeckleObjects::InstanceDefinitionProxy.new(
|
||||
entity.definition,
|
||||
[],
|
||||
depth,
|
||||
sketchup_attributes: definition_att,
|
||||
application_id: definition_id
|
||||
)
|
||||
definition_proxy[:name] = entity.definition.name
|
||||
definition_proxy[:description] = entity.definition.description
|
||||
|
||||
|
||||
@@ -16,7 +16,20 @@ module SpeckleConnector3
|
||||
].freeze
|
||||
|
||||
# @param entity [Sketchup::Entity] entity to get attribute dictionaries
|
||||
def self.attribute_dictionaries_to_speckle(entity, model_preferences)
|
||||
def self.attribute_dictionaries_to_speckle(entity)
|
||||
dictionaries = {}
|
||||
return dictionaries if entity.attribute_dictionaries.nil?
|
||||
|
||||
entity.attribute_dictionaries.each do |att_dict|
|
||||
dict_name = att_dict == '' ? 'empty_dictionary_name' : att_dict.name
|
||||
dictionaries[dict_name] = att_dict.to_h unless IGNORED_DICTIONARY_NAMES.include?(att_dict.name)
|
||||
end
|
||||
dictionaries
|
||||
end
|
||||
|
||||
# @param entity [Sketchup::Entity] entity to get attribute dictionaries
|
||||
# @note v2 logic
|
||||
def self.attribute_dictionaries_to_speckle_by_settings(entity, model_preferences)
|
||||
dictionaries = {}
|
||||
return dictionaries unless model_preferences[INCLUDE_ENTITY_ATTRIBUTES]
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ module SpeckleConnector3
|
||||
self[:units] = units
|
||||
self[:layer] = layer unless layer.nil?
|
||||
self['@SpeckleSchema'] = speckle_schema if speckle_schema.any?
|
||||
self[:sketchup_attributes] = sketchup_attributes if sketchup_attributes.any?
|
||||
self[:properties] = sketchup_attributes if sketchup_attributes.any?
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
@@ -59,7 +59,7 @@ module SpeckleConnector3
|
||||
# @param edge [Sketchup::Edge] edge to convert line.
|
||||
def self.from_edge(speckle_state:, edge:, units:, model_preferences:, global_transformation: nil)
|
||||
dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_speckle(edge, model_preferences)
|
||||
.attribute_dictionaries_to_speckle_by_settings(edge, model_preferences)
|
||||
att = dictionaries.any? ? { dictionaries: dictionaries } : {}
|
||||
speckle_schema = Mapper.to_speckle(speckle_state, edge, units, global_transformation: global_transformation)
|
||||
start_pt = Geometry::Point.from_vertex(edge.start.position, units)
|
||||
@@ -141,7 +141,10 @@ module SpeckleConnector3
|
||||
edges.each do |edge|
|
||||
edge.layer = layer
|
||||
# edge.layer = line_layer.nil? ? layer : line_layer
|
||||
unless line['sketchup_attributes'].nil?
|
||||
if !line['properties'].nil?
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(edge, line['properties']['dictionaries'])
|
||||
elsif !line['sketchup_attributes'].nil? # backward compatibility
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(edge, line['sketchup_attributes']['dictionaries'])
|
||||
end
|
||||
|
||||
@@ -49,7 +49,7 @@ module SpeckleConnector3
|
||||
# self[:renderMaterial] = render_material
|
||||
self[:'@(31250)vertices'] = vertices
|
||||
self[:'@(62500)faces'] = faces
|
||||
self[:sketchup_attributes] = sketchup_attributes if sketchup_attributes.any?
|
||||
self[:properties] = sketchup_attributes if sketchup_attributes.any?
|
||||
self['@SpeckleSchema'] = speckle_schema if speckle_schema.any?
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
@@ -129,7 +129,10 @@ module SpeckleConnector3
|
||||
# Smooth edges if they already soft
|
||||
# FIXME: Below line should be reconsidered. It might be a good to know here mesh comes from NURBS or not.
|
||||
face.edges.each { |edge| edge.smooth = true if edge.soft? } if has_any_non_planar_quad_mesh
|
||||
unless mesh['sketchup_attributes'].nil?
|
||||
if !mesh['properties'].nil?
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(face, mesh['properties']['dictionaries'])
|
||||
elsif !mesh['sketchup_attributes'].nil? # backward compatibility
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(face, mesh['sketchup_attributes']['dictionaries'])
|
||||
end
|
||||
@@ -151,7 +154,7 @@ module SpeckleConnector3
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def self.from_face(speckle_state:, face:, units:, model_preferences:, global_transform: nil, parent_material: nil)
|
||||
dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_speckle(face, model_preferences)
|
||||
.attribute_dictionaries_to_speckle_by_settings(face, model_preferences)
|
||||
has_any_soften_edge = face.edges.any?(&:soft?)
|
||||
att = dictionaries.any? ? { is_soften: has_any_soften_edge, dictionaries: dictionaries }
|
||||
: { is_soften: has_any_soften_edge }
|
||||
@@ -278,7 +281,9 @@ module SpeckleConnector3
|
||||
# @param mesh [Object] speckle mesh object
|
||||
# @param entities [Sketchup::Entities] sketchup entities that mesh will be created in it as face.
|
||||
def self.get_soften_setting(mesh, entities)
|
||||
unless mesh['sketchup_attributes'].nil?
|
||||
if !mesh['properties'].nil?
|
||||
return mesh['properties']['is_soften'].nil? ? true : mesh['properties']['is_soften']
|
||||
elsif !mesh['sketchup_attributes'].nil? # backward compatibility
|
||||
return mesh['sketchup_attributes']['is_soften'].nil? ? true : mesh['sketchup_attributes']['is_soften']
|
||||
end
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ module SpeckleConnector3
|
||||
|
||||
geometries.each do |geo|
|
||||
if geo['speckle_type'] && geo['speckle_type'] == OBJECTS_GEOMETRY_MESH
|
||||
geo['sketchup_attributes'] = { 'is_soften' => false }
|
||||
geo['properties'] = { 'is_soften' => false }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ module SpeckleConnector3
|
||||
|
||||
geometries.each do |geo|
|
||||
if geo['speckle_type'] && geo['speckle_type'] == OBJECTS_GEOMETRY_MESH
|
||||
geo['sketchup_attributes'] = { 'is_soften' => false }
|
||||
geo['properties'] = { 'is_soften' => false }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ module SpeckleConnector3
|
||||
# @param object_ids [Array<String>]
|
||||
# @param max_depth [Integer]
|
||||
# @param application_id [String | NilClass]
|
||||
def initialize(definition, object_ids, max_depth, application_id: nil)
|
||||
def initialize(definition, object_ids, max_depth, sketchup_attributes: {}, application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
application_id: application_id,
|
||||
@@ -31,6 +31,7 @@ module SpeckleConnector3
|
||||
self[:objects] = object_ids
|
||||
self[:maxDepth] = max_depth
|
||||
self[:alwaysFaceCamera] = definition.behavior.always_face_camera?
|
||||
self[:properties] = sketchup_attributes if sketchup_attributes.any?
|
||||
end
|
||||
|
||||
def add_object_id(object_id)
|
||||
|
||||
@@ -8,7 +8,7 @@ module SpeckleConnector3
|
||||
module SpeckleObjects
|
||||
class InstanceProxy < Base
|
||||
SPECKLE_TYPE = SPECKLE_CORE_MODELS_INSTANCES_INSTANCE_PROXY
|
||||
def initialize(definition_id, transform, max_depth, units, application_id: nil)
|
||||
def initialize(definition_id, transform, max_depth, units, sketchup_attributes: {}, application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
application_id: application_id,
|
||||
@@ -18,6 +18,7 @@ module SpeckleConnector3
|
||||
self[:definitionId] = definition_id
|
||||
self[:maxDepth] = max_depth
|
||||
self[:transform] = transform
|
||||
self[:properties] = sketchup_attributes if sketchup_attributes.any?
|
||||
end
|
||||
|
||||
def self.to_native(state, instance_proxy, layer, entities, definition_proxies, &_convert_to_native)
|
||||
@@ -26,6 +27,13 @@ module SpeckleConnector3
|
||||
transform = Other::Transform.to_native(proxy_transform, instance_proxy['units'])
|
||||
definition = definition_proxies[definition_id].definition
|
||||
instance = entities.add_instance(definition, transform)
|
||||
|
||||
unless instance_proxy['properties'].nil?
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(instance, instance_proxy['properties']['dictionaries'])
|
||||
end
|
||||
|
||||
|
||||
instance.layer = layer if layer # TODO: CONVERTER_V2 check
|
||||
# TODO: CONVERTER_V2 handle groups
|
||||
return state, [instance, definition]
|
||||
|
||||
@@ -32,7 +32,7 @@ module SpeckleConnector3
|
||||
self[:units] = units
|
||||
self[:name] = name
|
||||
self[:always_face_camera] = always_face_camera
|
||||
self[:sketchup_attributes] = sketchup_attributes if sketchup_attributes.any?
|
||||
self[:properties] = sketchup_attributes if sketchup_attributes.any?
|
||||
self[:SpeckleSchema] = speckle_schema if speckle_schema.any?
|
||||
# '@@' means that it is a detached property.
|
||||
self['@@geometry'] = geometry
|
||||
@@ -47,7 +47,7 @@ module SpeckleConnector3
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def self.from_definition(definition, units, preferences, speckle_state, parent, &convert)
|
||||
dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_speckle(definition, preferences[:model])
|
||||
.attribute_dictionaries_to_speckle_by_settings(definition, preferences[:model])
|
||||
att = dictionaries.any? ? { dictionaries: dictionaries } : {}
|
||||
speckle_schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler
|
||||
.speckle_schema_to_speckle(definition)
|
||||
@@ -118,7 +118,7 @@ module SpeckleConnector3
|
||||
geometry = definition_obj['geometry'] || definition_obj['@geometry'] || definition_obj['displayValue']
|
||||
|
||||
always_face_camera = definition_obj['always_face_camera'].nil? ? false : definition_obj['always_face_camera']
|
||||
sketchup_attributes = definition_obj['sketchup_attributes']
|
||||
properties = definition_obj['properties'] || definition_obj['sketchup_attributes']
|
||||
definition&.entities&.clear!
|
||||
definition ||= sketchup_model.definitions.add(definition_name)
|
||||
|
||||
@@ -143,9 +143,9 @@ module SpeckleConnector3
|
||||
# puts("definition finished: #{name} (#{application_id})")
|
||||
# puts(" entity count: #{definition.entities.count}")
|
||||
definition.behavior.always_face_camera = always_face_camera
|
||||
unless sketchup_attributes.nil?
|
||||
unless properties.nil?
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(definition, sketchup_attributes['dictionaries'])
|
||||
.attribute_dictionaries_to_native(definition, properties['dictionaries'])
|
||||
end
|
||||
return state, [definition]
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ module SpeckleConnector3
|
||||
self[:is_sketchup_group] = is_sketchup_group
|
||||
# self[:renderMaterial] = render_material
|
||||
self[:transform] = transform
|
||||
self[:sketchup_attributes] = sketchup_attributes if sketchup_attributes.any?
|
||||
self[:properties] = sketchup_attributes if sketchup_attributes.any?
|
||||
self[:speckle_schema] = speckle_schema if speckle_schema.any?
|
||||
# FIXME: Since blockDefinition sends with @ as detached, block basePlane renders on viewer.
|
||||
self['@@definition'] = block_definition
|
||||
@@ -53,7 +53,7 @@ module SpeckleConnector3
|
||||
group.persistent_id.to_s)
|
||||
speckle_state = new_speckle_state
|
||||
dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_speckle(group, preferences[:model])
|
||||
.attribute_dictionaries_to_speckle_by_settings(group, preferences[:model])
|
||||
att = dictionaries.any? ? { dictionaries: dictionaries } : {}
|
||||
speckle_schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.speckle_schema_to_speckle(group)
|
||||
block_instance = BlockInstance.new(
|
||||
@@ -83,7 +83,7 @@ module SpeckleConnector3
|
||||
speckle_state = new_speckle_state
|
||||
|
||||
dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_speckle(component_instance, preferences[:model])
|
||||
.attribute_dictionaries_to_speckle_by_settings(component_instance, preferences[:model])
|
||||
att = dictionaries.any? ? { dictionaries: dictionaries } : {}
|
||||
speckle_schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler
|
||||
.speckle_schema_to_speckle(component_instance)
|
||||
@@ -245,10 +245,15 @@ module SpeckleConnector3
|
||||
end
|
||||
|
||||
instance.name = block['name'] unless block['name'].nil?
|
||||
unless block['sketchup_attributes'].nil?
|
||||
|
||||
if !block['properties'].nil?
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(instance, block['properties']['dictionaries'])
|
||||
elsif !block['sketchup_attributes'].nil? # backward compatibility
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(instance, block['sketchup_attributes']['dictionaries'])
|
||||
end
|
||||
|
||||
return state, [instance, definition]
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
@@ -32,7 +32,7 @@ module SpeckleConnector3
|
||||
self[:emissive] = emissive
|
||||
self[:metalness] = metalness
|
||||
self[:roughness] = roughness
|
||||
self[:sketchup_attributes] = sketchup_attributes
|
||||
self[:properties] = sketchup_attributes
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
|
||||
Reference in New Issue
Block a user