Compare commits
36 Commits
2.14.0-rc2
...
2.14.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 966f7aaed5 | |||
| 51b59fa995 | |||
| 0b713736bd | |||
| 9e33581c66 | |||
| b97792b596 | |||
| c0746f8eff | |||
| a826a9d692 | |||
| 6d04203d37 | |||
| 33b2ed8a94 | |||
| 4f16da7ad0 | |||
| 36f92c7655 | |||
| 1d4f5a759e | |||
| 28af9bc811 | |||
| cf04cd4094 | |||
| 23e9efb28a | |||
| 57322df29c | |||
| fff82d34c6 | |||
| 7211860c21 | |||
| 9fc69044f8 | |||
| 76467c3e81 | |||
| 4cfc04e2f3 | |||
| 6bfc7771d0 | |||
| 7055135257 | |||
| 85312cf20d | |||
| 4051cae5b0 | |||
| c64bb6dedf | |||
| 7bb17ae0db | |||
| 3244eb9b15 | |||
| 6e173847ba | |||
| 8cbc1f763d | |||
| 2d45abeb28 | |||
| 2fd0ad77bc | |||
| 53c1167831 | |||
| 48d4a1d7bb | |||
| 4bbbba6e89 | |||
| 0a13575325 |
@@ -21,6 +21,11 @@ module SpeckleConnector
|
||||
flat_entities.each do |entity|
|
||||
next unless entity_ids.include?(entity.persistent_id)
|
||||
|
||||
if entity.is_a?(Sketchup::ComponentDefinition)
|
||||
entity.instances.each do |instance|
|
||||
instance.hidden = true
|
||||
end
|
||||
end
|
||||
entity.hidden = true
|
||||
end
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ module SpeckleConnector
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
# @return [States::State] the new updated state object
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def self.update_state(state, data)
|
||||
@@ -24,14 +25,15 @@ module SpeckleConnector
|
||||
# Flat entities to isolate mappings
|
||||
flat_entities = SketchupModel::Query::Entity.flat_entities(sketchup_model.entities)
|
||||
|
||||
comp_flat_entities = flat_entities.grep(Sketchup::ComponentInstance) + flat_entities.grep(Sketchup::Group)
|
||||
comp_flat_entities = flat_entities.grep(Sketchup::ComponentInstance) + flat_entities.grep(Sketchup::Group) +
|
||||
flat_entities.grep(Sketchup::ComponentDefinition)
|
||||
face_edge_flat_entities = flat_entities.grep(Sketchup::Face) + flat_entities.grep(Sketchup::Edge)
|
||||
|
||||
# Collect entity ids to clear mappings
|
||||
selected_elements = data.collect { |_, entities| entities['selectedElements'] }.flatten
|
||||
|
||||
comps_or_groups, faces_or_edges = selected_elements.partition do |e|
|
||||
e['entityType'] == 'Component' || e['entityType'] == 'Group'
|
||||
e['entityType'] == 'Component' || e['entityType'] == 'Definition' || e['entityType'] == 'Group'
|
||||
end
|
||||
|
||||
faces_or_edges_ids = faces_or_edges.collect { |e| e['entityId'] }
|
||||
@@ -43,12 +45,18 @@ module SpeckleConnector
|
||||
comps_or_groups_ids = comps_or_groups.collect { |e| e['entityId'] }
|
||||
|
||||
comp_flat_entities.select { |e| comps_or_groups_ids.include?(e.persistent_id) }.each do |entity|
|
||||
if entity.is_a?(Sketchup::ComponentDefinition)
|
||||
entity.instances.each do |instance|
|
||||
instance.hidden = false
|
||||
end
|
||||
end
|
||||
entity.hidden = false
|
||||
end
|
||||
|
||||
Events::SelectionEventAction.update_state(state, { clear: true })
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
end
|
||||
|
||||
@@ -24,6 +24,9 @@ module SpeckleConnector
|
||||
flat_entities.each do |entity|
|
||||
next unless entity_ids.include?(entity.persistent_id)
|
||||
|
||||
if entity.is_a?(Sketchup::ComponentDefinition)
|
||||
state.sketchup_state.sketchup_model.selection.add(entity.instances)
|
||||
end
|
||||
state.sketchup_state.sketchup_model.selection.add(entity)
|
||||
end
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ module SpeckleConnector
|
||||
OBJECTS_GIS_POLYGONELEMENT = 'Objects.GIS.PolygonElement'
|
||||
|
||||
OBJECTS_BUILTELEMENTS_VIEW3D = 'Objects.BuiltElements.View:Objects.BuiltElements.View3D'
|
||||
OBJECTS_BUILTELEMENTS_NETWORK = 'Objects.BuiltElements.Network'
|
||||
OBJECTS_BUILTELEMENTS_REVIT_DIRECTSHAPE = 'Objects.BuiltElements.Revit.DirectShape'
|
||||
OBJECTS_BUILTELEMENTS_REVIT_LEVEL = 'Objects.BuiltElements.Level:Objects.BuiltElements.Revit.RevitLevel'
|
||||
|
||||
@@ -20,4 +21,7 @@ module SpeckleConnector
|
||||
OBJECTS_OTHER_REVIT_REVITINSTANCE = 'Objects.Other.Revit.RevitInstance'
|
||||
OBJECTS_OTHER_BLOCKDEFINITION = 'Objects.Other.BlockDefinition'
|
||||
OBJECTS_OTHER_RENDERMATERIAL = 'Objects.Other.RenderMaterial'
|
||||
OBJECTS_OTHER_DISPLAYSTYLE = 'Objects.Other.DisplayStyle'
|
||||
|
||||
SPECKLE_CORE_MODELS_COLLECTION = 'Speckle.Core.Models.Collection'
|
||||
end
|
||||
|
||||
@@ -13,6 +13,8 @@ require_relative '../speckle_objects/geometry/point'
|
||||
require_relative '../speckle_objects/geometry/line'
|
||||
require_relative '../speckle_objects/geometry/mesh'
|
||||
require_relative '../speckle_objects/built_elements/view3d'
|
||||
require_relative '../speckle_objects/built_elements/network'
|
||||
require_relative '../speckle_objects/speckle/core/models/collection'
|
||||
require_relative '../sketchup_model/dictionary/speckle_entity_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
@@ -51,6 +53,7 @@ module SpeckleConnector
|
||||
DISPLAY_VALUE = OTHER::DisplayValue
|
||||
VIEW3D = BUILTELEMENTS::View3d
|
||||
POLYGON_ELEMENT = GIS::PolygonElement
|
||||
COLLECTION = SpeckleObjects::Speckle::Core::Models::Collection
|
||||
|
||||
BASE_OBJECT_PROPS = %w[applicationId id speckle_type totalChildrenCount].freeze
|
||||
CONVERTABLE_SPECKLE_TYPES = %w[
|
||||
@@ -64,7 +67,9 @@ module SpeckleConnector
|
||||
Objects.Other.RenderMaterial
|
||||
Objects.Other.Instance:Objects.Other.BlockInstance
|
||||
Objects.BuiltElements.View:Objects.BuiltElements.View3D
|
||||
Objects.BuiltElements.Network
|
||||
Objects.GIS.PolygonElement
|
||||
Speckle.Core.Models.Collection
|
||||
].freeze
|
||||
|
||||
def from_revit
|
||||
@@ -86,10 +91,13 @@ module SpeckleConnector
|
||||
def receive_commit_object(obj)
|
||||
# First create layers on the sketchup before starting traversing
|
||||
# @Named Views are exception here. It does not mean a layer. But it is anti-pattern for now.
|
||||
layers_relation = obj['layers_relation']
|
||||
# layers_relation = obj['layers_relation']
|
||||
|
||||
# Create layers and it's folders from layers relation on the model collection.
|
||||
SpeckleObjects::Relations::Layers.to_native(layers_relation, sketchup_model) if layers_relation && !from_revit
|
||||
unless from_revit
|
||||
layers_relation = SpeckleObjects::Relations::Layers.extract_relations(obj)
|
||||
# Create layers and it's folders from layers relation on the model collection.
|
||||
SpeckleObjects::Relations::Layers.to_native(layers_relation, sketchup_model) if layers_relation
|
||||
end
|
||||
|
||||
# By default entities to fill is sketchup model's entities.
|
||||
@entities_to_fill = sketchup_model.entities
|
||||
@@ -100,7 +108,9 @@ module SpeckleConnector
|
||||
@entities_to_fill = @branch_definition.entities
|
||||
end
|
||||
|
||||
traverse_commit_object(obj, @entities_to_fill)
|
||||
default_commit_layer = sketchup_model.layers.layers.find { |layer| layer.display_name == '@Untagged' }
|
||||
|
||||
traverse_commit_object(obj, default_commit_layer, @entities_to_fill)
|
||||
create_levels_from_section_planes
|
||||
check_hiding_layers_needed
|
||||
try_create_instance
|
||||
@@ -230,9 +240,9 @@ module SpeckleConnector
|
||||
# self-caller method means that call itself according to conditions inside of it.
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
def traverse_commit_object(obj, entities)
|
||||
def traverse_commit_object(obj, layer, entities)
|
||||
if convertible_to_native?(obj)
|
||||
@state = convert_to_native(@state, obj, entities)
|
||||
@state = convert_to_native(@state, obj, layer, entities)
|
||||
elsif obj.is_a?(Hash) && obj.key?('speckle_type')
|
||||
return if ignored_speckle_type?(obj)
|
||||
|
||||
@@ -240,23 +250,23 @@ module SpeckleConnector
|
||||
# puts(">>> Found #{obj['speckle_type']}: #{obj['id']}. Continuing traversal.")
|
||||
props = obj.keys.filter_map { |key| key unless key.start_with?('_') }
|
||||
props.each do |prop|
|
||||
traverse_commit_object(obj[prop], entities)
|
||||
traverse_commit_object(obj[prop], layer, entities)
|
||||
end
|
||||
else
|
||||
# puts(">>> Found #{obj['speckle_type']}: #{obj['id']} with displayValue.")
|
||||
@state = convert_to_native(@state, obj, entities)
|
||||
@state = convert_to_native(@state, obj, layer, entities)
|
||||
end
|
||||
elsif obj.is_a?(Hash)
|
||||
obj.each_value { |value| traverse_commit_object(value, entities) }
|
||||
obj.each_value { |value| traverse_commit_object(value, layer, entities) }
|
||||
elsif obj.is_a?(Array)
|
||||
obj.each { |value| traverse_commit_object(value, entities) }
|
||||
obj.each { |value| traverse_commit_object(value, layer, entities) }
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
def speckle_object_to_native(obj)
|
||||
return DISPLAY_VALUE.method(:to_native) unless obj['displayValue'].nil?
|
||||
return DISPLAY_VALUE.method(:to_native) unless obj['displayValue'].nil? && obj['@displayValue'].nil?
|
||||
|
||||
SPECKLE_OBJECT_TO_NATIVE[obj['speckle_type']]
|
||||
end
|
||||
@@ -272,18 +282,21 @@ module SpeckleConnector
|
||||
OBJECTS_OTHER_REVIT_REVITINSTANCE => REVIT_INSTANCE.method(:to_native),
|
||||
OBJECTS_OTHER_RENDERMATERIAL => RENDER_MATERIAL.method(:to_native),
|
||||
OBJECTS_BUILTELEMENTS_VIEW3D => VIEW3D.method(:to_native),
|
||||
OBJECTS_GIS_POLYGONELEMENT => POLYGON_ELEMENT.method(:to_native)
|
||||
OBJECTS_BUILTELEMENTS_REVIT_DIRECTSHAPE => BUILTELEMENTS::Revit::DirectShape.method(:to_native),
|
||||
OBJECTS_BUILTELEMENTS_NETWORK => BUILTELEMENTS::Network.method(:to_native),
|
||||
OBJECTS_GIS_POLYGONELEMENT => POLYGON_ELEMENT.method(:to_native),
|
||||
SPECKLE_CORE_MODELS_COLLECTION => COLLECTION.method(:to_native)
|
||||
}.freeze
|
||||
|
||||
# @param state [States::State] state of the speckle application
|
||||
def convert_to_native(state, obj, entities = sketchup_model.entities)
|
||||
def convert_to_native(state, obj, layer, entities = sketchup_model.entities)
|
||||
# store this method as parameter to re-call it inner callstack
|
||||
convert_to_native = method(:convert_to_native)
|
||||
# Get 'to_native' method to convert upcoming speckle object to native sketchup entity
|
||||
to_native_method = speckle_object_to_native(obj)
|
||||
# Call 'to_native' method by passing this method itself to handle nested 'to_native' conversions.
|
||||
# It returns updated state and converted entities.
|
||||
state, converted_entities = to_native_method.call(state, obj, entities, &convert_to_native)
|
||||
state, converted_entities = to_native_method.call(state, obj, layer, entities, &convert_to_native)
|
||||
if from_revit
|
||||
# Create levels as section planes if they exists
|
||||
create_levels(state, obj)
|
||||
|
||||
@@ -33,8 +33,6 @@ module SpeckleConnector
|
||||
new_speckle_state, model_collection = MODEL_COLLECTION.from_sketchup_model(sketchup_model, speckle_state,
|
||||
@units, preferences, &convert)
|
||||
|
||||
# send only layers that have any object
|
||||
model_collection[:layers_relation] = SpeckleObjects::Relations::Layers.from_model(sketchup_model)
|
||||
return new_speckle_state, model_collection
|
||||
end
|
||||
|
||||
|
||||
@@ -18,6 +18,25 @@ module SpeckleConnector
|
||||
end
|
||||
parent_folders.reverse
|
||||
end
|
||||
|
||||
# @param entity [Sketchup::Entity] entity to find path.
|
||||
def entity_path(entity, separation = '::')
|
||||
path = path(entity.layer)
|
||||
full_path = path.append(entity.layer)
|
||||
full_path_string = ''
|
||||
full_path.each_with_index do |layer, i|
|
||||
full_path_string += layer.display_name
|
||||
full_path_string += separation unless i == full_path.length - 1
|
||||
end
|
||||
full_path_string
|
||||
end
|
||||
|
||||
# @param string_layer_path [String] string layer path to split.
|
||||
def entity_layer_from_path(string_layer_path, separation = '::')
|
||||
return string_layer_path if string_layer_path.nil?
|
||||
|
||||
string_layer_path.split(separation).last
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -100,23 +100,30 @@ module SpeckleConnector
|
||||
}
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
def self.mapped_entity_details(entities)
|
||||
reverse_category_dictionary = Mapping::Category::RevitCategory.reverse_dictionary
|
||||
entities.collect do |entity|
|
||||
speckle_schema = get_schema(entity)
|
||||
speckle_schema_definition = entity.respond_to?(:definition) ? get_schema(entity.definition) : nil
|
||||
entity_type = entity.class.name.split('::').last.gsub(/(?<=[a-z])(?=[A-Z])/, ' ').split.first
|
||||
{
|
||||
name: speckle_schema['name'],
|
||||
category: speckle_schema['category'],
|
||||
categoryName: reverse_category_dictionary[speckle_schema['category']],
|
||||
method: speckle_schema['method'],
|
||||
name: speckle_schema['name'] || speckle_schema_definition['name'],
|
||||
category: speckle_schema['category'] || speckle_schema_definition['category'],
|
||||
categoryName: reverse_category_dictionary[speckle_schema['category']] ||
|
||||
reverse_category_dictionary[speckle_schema_definition['category']],
|
||||
method: speckle_schema['method'] || speckle_schema_definition['method'],
|
||||
entityName: entity.respond_to?(:name) ? entity.name : '',
|
||||
entityId: entity.persistent_id,
|
||||
entityType: entity.class.name.split('::').last.gsub(/(?<=[a-z])(?=[A-Z])/, ' ').split.first,
|
||||
entityType: entity.is_a?(Sketchup::ComponentDefinition) ? 'Definition' : entity_type,
|
||||
schema: speckle_schema,
|
||||
definitionSchema: entity.respond_to?(:definition) ? get_schema(entity.definition) : nil
|
||||
definitionSchema: speckle_schema_definition
|
||||
}
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module SpeckleConnector
|
||||
# Operations related to {SketchupModel}.
|
||||
module SketchupModel
|
||||
# Works directly with/on SketchUp Entities of different kinds (Groups, Faces, Edges, ...).
|
||||
module Utils
|
||||
# Static methods to do plane calculations with sketchup geom objects like Point3d and Vector3d.
|
||||
class Plane
|
||||
LENGTH_TOLERANCE = 1e-8
|
||||
|
||||
# Create plane from 3 points
|
||||
# @param origin [Geom::Point3d] the point on the plane that wil become the origin of the local coordinate system
|
||||
# @param point_1 [Geom::Point3d] the point that defines first direction
|
||||
# @param point_2 [Geom::Point3d] the third point on the plane
|
||||
# @return [Plane] the parametrization of the plane that goes through the given points
|
||||
def self.from_points(origin, point_1, point_2)
|
||||
direction_x = origin.vector_to(point_1).normalize
|
||||
direction_x = direction_x.normalize
|
||||
normal = direction_x.cross(origin.vector_to(point_2))
|
||||
direction_y = direction_x.cross(normal.normalize)
|
||||
new(origin: origin, direction_u: direction_x, direction_v: direction_y)
|
||||
end
|
||||
|
||||
# @return [Geom::Vector3d] the direction of the u-axis on the plane
|
||||
attr_reader :direction_u
|
||||
|
||||
# @return [Geom::Vector3d] the direction of the v-axis on the plane
|
||||
attr_reader :direction_v
|
||||
|
||||
# @return [Geom::Point3d] the origin of the local coordinate system on the plane
|
||||
attr_reader :origin
|
||||
|
||||
# @param origin [Geom::Point3d] the origin of the coordinate system on the plane
|
||||
# @param direction_u [Geom::Vector3d] the direction of the x-axis
|
||||
# @param direction_v [Geom::Vector3d] the direction of the y-axis
|
||||
def initialize(origin:, direction_u:, direction_v:)
|
||||
@origin = origin
|
||||
@direction_u = direction_u
|
||||
@direction_v = direction_v
|
||||
end
|
||||
|
||||
# Get the point object in global coordinates for the point on the plane with local coordinates (u,v).
|
||||
# @param coordinate_u [Float] the u-coordinate on the plane
|
||||
# @param coordinate_v [Float] the v-coordinate on the plane
|
||||
# @return [Geom::Point3d] the point in space that corresponds to the given (u, v) coordinates
|
||||
def point_at(coordinate_u, coordinate_v)
|
||||
scaled_direction_u = Geom::Vector3d.new(direction_u.x * coordinate_u,
|
||||
direction_u.y * coordinate_u,
|
||||
direction_u.z * coordinate_u)
|
||||
scaled_direction_v = Geom::Vector3d.new(direction_v.x * coordinate_v,
|
||||
direction_v.y * coordinate_v,
|
||||
direction_v.z * coordinate_v)
|
||||
origin + scaled_direction_u + scaled_direction_v
|
||||
end
|
||||
|
||||
# Find local (u, v) coordinates of the projection of the given point to the plane
|
||||
# @param point [Geom::Point3d] the point that will be projected to the plane
|
||||
# @return [(Float, Float)] the local coordinates on the plane that correspond to the projected point
|
||||
def plane_coordinates(point)
|
||||
origin_to_point = origin.vector_to(point)
|
||||
coordinate_u = origin_to_point.dot(direction_u)
|
||||
coordinate_v = origin_to_point.dot(direction_v)
|
||||
[coordinate_u, coordinate_v]
|
||||
end
|
||||
|
||||
# Project a given point to the plane
|
||||
# @param point [Geom::Point3d] the point that will be projected to the plane
|
||||
# @return [Geom::Point3d] the projected point on the plane
|
||||
def project_to_plane(point)
|
||||
coordinate_u, coordinate_v = plane_coordinates(point)
|
||||
point_at(coordinate_u, coordinate_v)
|
||||
end
|
||||
|
||||
# Check if the given point lies on the plane
|
||||
# @param point [Geom::Point3d] the point to check
|
||||
# @return [Boolean] whether the point lies on the plane
|
||||
def on_plane?(point)
|
||||
point.distance(project_to_plane(point)).to_m < LENGTH_TOLERANCE
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../../constants/type_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module BuiltElements
|
||||
# Network object represents scenes on Sketchup.
|
||||
class Network < Base
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_NETWORK
|
||||
|
||||
def self.to_native(state, network, layer, entities, &convert_to_native)
|
||||
network['elements'].each do |element|
|
||||
state = convert_to_native.call(state, element['elements'], layer, entities)
|
||||
end
|
||||
|
||||
return state, []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
require_relative '../../base'
|
||||
require_relative '../../other/render_material'
|
||||
require_relative '../../other/block_instance'
|
||||
require_relative '../../other/block_definition'
|
||||
require_relative '../../other/transform'
|
||||
require_relative '../../../constants/type_constants'
|
||||
require_relative '../../../sketchup_model/query/entity'
|
||||
require_relative '../../../sketchup_model/reader/speckle_entities_reader'
|
||||
require_relative '../../../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
@@ -30,6 +34,41 @@ module SpeckleConnector
|
||||
self[:baseGeometries] = base_geometries
|
||||
end
|
||||
|
||||
def self.get_direct_shape_name(direct_shape)
|
||||
if direct_shape['name'] == ''
|
||||
direct_shape['applicationId'].to_s
|
||||
else
|
||||
"#{direct_shape['name']}::#{direct_shape['applicationId']}"
|
||||
end
|
||||
end
|
||||
|
||||
# @param state [States::State] state of the application.
|
||||
def self.to_native(state, direct_shape, layer, entities, &convert_to_native)
|
||||
direct_shape['geometry'] = direct_shape['baseGeometries']
|
||||
direct_shape['name'] = get_direct_shape_name(direct_shape)
|
||||
|
||||
state, _definitions = Other::BlockDefinition.to_native(
|
||||
state, direct_shape, layer, entities, &convert_to_native
|
||||
)
|
||||
|
||||
definition = state.sketchup_state.sketchup_model
|
||||
.definitions[Other::BlockDefinition.get_definition_name(direct_shape)]
|
||||
|
||||
instance = entities.add_instance(definition, Geom::Transformation.new)
|
||||
instance.name = direct_shape['name'] unless direct_shape['name'].nil?
|
||||
DICTIONARY::SpeckleSchemaDictionaryHandler.set_hash(
|
||||
instance,
|
||||
{
|
||||
name: direct_shape['name'], category: direct_shape['category'], method: 'Direct Shape'
|
||||
}
|
||||
)
|
||||
new_speckle_state = state.speckle_state.with_mapped_entity(instance)
|
||||
state = state.with_speckle_state(new_speckle_state)
|
||||
instance.layer = layer unless layer.nil?
|
||||
|
||||
return state, [instance, definition]
|
||||
end
|
||||
|
||||
# Collects direct shapes on selection as flat list.
|
||||
def self.direct_shapes_on_selection(sketchup_model)
|
||||
flat_selection_with_path = QUERY::Entity.flat_entities_with_path(
|
||||
|
||||
@@ -60,7 +60,7 @@ module SpeckleConnector
|
||||
target = get_camera_target(cam, units)
|
||||
direction = get_camera_direction(cam, units)
|
||||
update_properties = get_scene_update_properties(page)
|
||||
rendering_options = SpeckleObjects::Others::RenderingOptions.to_speckle(page.rendering_options)
|
||||
rendering_options = SpeckleObjects::Other::RenderingOptions.to_speckle(page.rendering_options)
|
||||
View3d.new(
|
||||
page.name, origin, target, direction, SpeckleObjects::Geometry::Vector.new(0, 0, 1, units),
|
||||
cam.perspective?, cam.fov, units, page.name, update_properties, rendering_options
|
||||
@@ -71,7 +71,8 @@ module SpeckleConnector
|
||||
# @param obj [Hash] commit object.
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def self.to_native(state, view, _entities, &_convert_to_native)
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
def self.to_native(state, view, _layer, _entities, &_convert_to_native)
|
||||
sketchup_model = state.sketchup_state.sketchup_model
|
||||
|
||||
return state, [] unless view['speckle_type'] == 'Objects.BuiltElements.View:Objects.BuiltElements.View3D'
|
||||
@@ -84,8 +85,10 @@ module SpeckleConnector
|
||||
lens = view['lens'] || 50
|
||||
origin = SpeckleObjects::Geometry::Point.to_native(origin['x'], origin['y'], origin['z'], origin['units'])
|
||||
target = SpeckleObjects::Geometry::Point.to_native(target['x'], target['y'], target['z'], target['units'])
|
||||
view_direction = (origin - target).normalize
|
||||
up = view_direction.parallel?([0, 0, 1]) ? [0, 1, 0] : [0, 0, 1]
|
||||
# Set camera position before creating scene on it.
|
||||
my_camera = Sketchup::Camera.new(origin, target, [0, 0, 1], !view['isOrthogonal'], lens)
|
||||
my_camera = Sketchup::Camera.new(origin, target, up, !view['isOrthogonal'], lens)
|
||||
sketchup_model.active_view.camera = my_camera
|
||||
sketchup_model.pages.add(name)
|
||||
page = sketchup_model.pages[name]
|
||||
@@ -95,6 +98,7 @@ module SpeckleConnector
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
# @param page [Sketchup::Page] scene to update -update properties-
|
||||
def self.set_page_update_properties(page, update_properties)
|
||||
@@ -109,7 +113,7 @@ module SpeckleConnector
|
||||
next if rendering_options[prop].nil?
|
||||
|
||||
rendering_options[prop] = if value.is_a?(Hash)
|
||||
SpeckleObjects::Others::Color.to_native(value)
|
||||
SpeckleObjects::Other::Color.to_native(value)
|
||||
else
|
||||
value
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ module SpeckleConnector
|
||||
end_pt: end_pt,
|
||||
domain: domain,
|
||||
units: units,
|
||||
layer: edge.layer.display_name,
|
||||
layer: SketchupModel::Query::Layer.entity_path(edge),
|
||||
sketchup_attributes: att,
|
||||
speckle_schema: speckle_schema,
|
||||
application_id: edge.persistent_id.to_s
|
||||
@@ -65,7 +65,9 @@ module SpeckleConnector
|
||||
# @param layer [Sketchup::Layer] layer to add {Sketchup::Edge} into it.
|
||||
# @param entities [Sketchup::Entities] entities collection to add {Sketchup::Edge} into it.
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def self.to_native(state, line, entities, &_convert_to_native)
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def self.to_native(state, line, layer, entities, &_convert_to_native)
|
||||
if line.key?('value')
|
||||
values = line['value']
|
||||
points = values.each_slice(3).to_a.map { |pt| Point.to_native(pt[0], pt[1], pt[2], line['units']) }
|
||||
@@ -76,9 +78,10 @@ module SpeckleConnector
|
||||
end_pt = Point.to_native(line['end']['x'], line['end']['y'], line['end']['z'], line['units'])
|
||||
edges = entities.add_edges(start_pt, end_pt)
|
||||
end
|
||||
line_layer = state.sketchup_state.sketchup_model.layers.to_a.find { |l| l.display_name == line['layer'] }
|
||||
line_layer_name = SketchupModel::Query::Layer.entity_layer_from_path(line['layer'])
|
||||
line_layer = state.sketchup_state.sketchup_model.layers.to_a.find { |l| l.display_name == line_layer_name }
|
||||
edges.each do |edge|
|
||||
edge.layer = line_layer unless line_layer.nil?
|
||||
edge.layer = line_layer.nil? ? layer : line_layer
|
||||
unless line['sketchup_attributes'].nil?
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(edge, line['sketchup_attributes']['dictionaries'])
|
||||
@@ -87,6 +90,8 @@ module SpeckleConnector
|
||||
return state, edges
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
|
||||
def self.test_line(start_point, end_point, units)
|
||||
domain = Primitive::Interval.from_numeric(0, 5, units)
|
||||
@@ -94,6 +99,7 @@ module SpeckleConnector
|
||||
start_pt: start_point,
|
||||
end_pt: end_point,
|
||||
domain: domain,
|
||||
layer: 'test',
|
||||
application_id: '',
|
||||
units: units
|
||||
)
|
||||
|
||||
@@ -7,6 +7,9 @@ require_relative '../../sketchup_model/query/entity'
|
||||
require_relative '../../convertors/clean_up'
|
||||
require_relative '../../sketchup_model/dictionary/base_dictionary_handler'
|
||||
require_relative '../../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
require_relative '../../sketchup_model/dictionary/dictionary_handler'
|
||||
require_relative '../../sketchup_model/utils/plane_utils'
|
||||
require_relative '../../sketchup_model/query/layer'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
@@ -52,12 +55,32 @@ module SpeckleConnector
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
# Checks 4 points are planar or not.
|
||||
def self.check_4_points_planar(points)
|
||||
plane = SketchupModel::Utils::Plane.from_points(points[0], points[1], points[2])
|
||||
plane.on_plane?(points[3])
|
||||
end
|
||||
|
||||
# Add quad mesh to sketchup native mesh by checking planarity.
|
||||
# @param native_mesh [Geom::Mesh] sketchup mesh to convert them later faces.
|
||||
# @param polygon_points [Array<Geom::Point3d>] sketchup points to add them with polygon to mesh.
|
||||
def self.add_quad_mesh(native_mesh, polygon_points)
|
||||
is_planar = check_4_points_planar(polygon_points)
|
||||
if is_planar
|
||||
native_mesh.add_polygon(polygon_points)
|
||||
else
|
||||
native_mesh.add_polygon([polygon_points[0], polygon_points[1], polygon_points[2]])
|
||||
native_mesh.add_polygon([polygon_points[0], polygon_points[2], polygon_points[3]])
|
||||
end
|
||||
is_planar
|
||||
end
|
||||
|
||||
# @param entities [Sketchup::Entities] entities to add
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity:
|
||||
def self.to_native(state, mesh, entities, &convert_to_native)
|
||||
def self.to_native(state, mesh, layer, entities, &convert_to_native)
|
||||
model_preferences = state.user_state.preferences[:model]
|
||||
# Get soft? flag of {Sketchup::Edge} object to understand smoothness of edge.
|
||||
is_soften = get_soften_setting(mesh, entities)
|
||||
@@ -67,14 +90,22 @@ module SpeckleConnector
|
||||
# Initialize native PolygonMesh object later to add polygon inside it.
|
||||
native_mesh = Geom::PolygonMesh.new(mesh['vertices'].count / 3)
|
||||
faces = mesh['faces']
|
||||
has_any_non_planar_quad_mesh = false
|
||||
while faces.count > 0
|
||||
num_pts = faces.shift
|
||||
# 0 -> 3, 1 -> 4 to preserve backwards compatibility
|
||||
num_pts += 3 if num_pts < 3
|
||||
indices = faces.shift(num_pts)
|
||||
native_mesh.add_polygon(indices.map { |index| points[index] })
|
||||
polygon_points = indices.map { |index| points[index] }
|
||||
# Quad mesh
|
||||
if num_pts == 4
|
||||
is_planar = add_quad_mesh(native_mesh, polygon_points)
|
||||
has_any_non_planar_quad_mesh = true unless is_planar
|
||||
else
|
||||
native_mesh.add_polygon(polygon_points)
|
||||
end
|
||||
end
|
||||
state, _materials = Other::RenderMaterial.to_native(state, mesh['renderMaterial'],
|
||||
state, _materials = Other::RenderMaterial.to_native(state, mesh['renderMaterial'], layer,
|
||||
entities, &convert_to_native)
|
||||
# Find and assign material if exist
|
||||
unless mesh['renderMaterial'].nil?
|
||||
@@ -86,9 +117,13 @@ module SpeckleConnector
|
||||
# Add faces from mesh with material and smooth setting
|
||||
entities.add_faces_from_mesh(native_mesh, smooth_flags, material, material)
|
||||
added_faces = entities.grep(Sketchup::Face).last(native_mesh.polygons.length)
|
||||
mesh_layer = state.sketchup_state.sketchup_model.layers.to_a.find { |l| l.display_name == mesh['layer'] }
|
||||
mesh_layer_name = SketchupModel::Query::Layer.entity_layer_from_path(mesh['layer'])
|
||||
mesh_layer = state.sketchup_state.sketchup_model.layers.to_a.find { |l| l.display_name == mesh_layer_name }
|
||||
added_faces.each do |face|
|
||||
face.layer = mesh_layer unless mesh_layer.nil?
|
||||
# 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?
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_native(face, mesh['sketchup_attributes']['dictionaries'])
|
||||
@@ -122,10 +157,8 @@ module SpeckleConnector
|
||||
speckle_mesh = Mesh.new(
|
||||
units: units,
|
||||
render_material: material.nil? ? nil : Other::RenderMaterial.from_material(material),
|
||||
vertices: [],
|
||||
faces: [],
|
||||
sketchup_attributes: att,
|
||||
layer: face.layer.display_name,
|
||||
vertices: [], faces: [], sketchup_attributes: att,
|
||||
layer: SketchupModel::Query::Layer.entity_path(face),
|
||||
speckle_schema: speckle_schema,
|
||||
application_id: face.persistent_id
|
||||
)
|
||||
|
||||
@@ -30,16 +30,13 @@ module SpeckleConnector
|
||||
end
|
||||
|
||||
# Handles polygon element differently from display value.
|
||||
def self.to_native(state, obj, entities, &convert_to_native)
|
||||
def self.to_native(state, obj, layer, entities, &convert_to_native)
|
||||
attributes = get_qgis_attributes(obj)
|
||||
obj = collect_definition_geometries(obj)
|
||||
obj['name'] = get_definition_name(obj, attributes)
|
||||
|
||||
state, _definitions = Other::BlockDefinition.to_native(
|
||||
state,
|
||||
obj,
|
||||
entities,
|
||||
&convert_to_native
|
||||
state, obj, layer, entities, &convert_to_native
|
||||
)
|
||||
|
||||
definition = state.sketchup_state.sketchup_model
|
||||
@@ -85,4 +82,3 @@ module SpeckleConnector
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ module SpeckleConnector
|
||||
block_definition = BlockDefinition.new(
|
||||
units: units,
|
||||
name: definition.name,
|
||||
geometry: geometry,
|
||||
geometry: geometry.compact,
|
||||
always_face_camera: definition.behavior.always_face_camera?,
|
||||
sketchup_attributes: att,
|
||||
speckle_schema: speckle_schema,
|
||||
@@ -98,7 +98,7 @@ module SpeckleConnector
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def self.to_native(state, definition_obj, _entities, &convert_to_native)
|
||||
def self.to_native(state, definition_obj, layer, _entities, &convert_to_native)
|
||||
sketchup_model = state.sketchup_state.sketchup_model
|
||||
|
||||
# FIXME: Check later this is a valid check or not. Maybe unnecessary? If necessary document it!
|
||||
@@ -124,11 +124,11 @@ module SpeckleConnector
|
||||
|
||||
if geometry.is_a?(Array)
|
||||
geometry.each do |obj|
|
||||
state = convert_to_native.call(state, obj, definition.entities)
|
||||
state = convert_to_native.call(state, obj, layer, definition.entities)
|
||||
end
|
||||
end
|
||||
if geometry.is_a?(Hash) && !definition_obj['speckle_type'].nil?
|
||||
state = convert_to_native.call(state, geometry, definition.entities)
|
||||
state = convert_to_native.call(state, geometry, layer, definition.entities)
|
||||
end
|
||||
# puts("definition finished: #{name} (#{application_id})")
|
||||
# puts(" entity count: #{definition.entities.count}")
|
||||
|
||||
@@ -7,6 +7,7 @@ require_relative '../base'
|
||||
require_relative '../geometry/bounding_box'
|
||||
require_relative '../../sketchup_model/dictionary/base_dictionary_handler'
|
||||
require_relative '../../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
require_relative '../../sketchup_model/query/layer'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
@@ -61,7 +62,7 @@ module SpeckleConnector
|
||||
render_material: group.material.nil? ? nil : RenderMaterial.from_material(group.material),
|
||||
transform: Other::Transform.from_transformation(group.transformation, units),
|
||||
block_definition: block_definition,
|
||||
layer: group.layer.display_name,
|
||||
layer: SketchupModel::Query::Layer.entity_path(group),
|
||||
sketchup_attributes: att,
|
||||
speckle_schema: speckle_schema,
|
||||
application_id: group.guid
|
||||
@@ -97,7 +98,7 @@ module SpeckleConnector
|
||||
end,
|
||||
transform: Other::Transform.from_transformation(component_instance.transformation, units),
|
||||
block_definition: block_definition,
|
||||
layer: component_instance.layer.display_name,
|
||||
layer: SketchupModel::Query::Layer.entity_path(component_instance),
|
||||
sketchup_attributes: att,
|
||||
speckle_schema: speckle_schema,
|
||||
application_id: component_instance.persistent_id.to_s
|
||||
@@ -111,7 +112,7 @@ module SpeckleConnector
|
||||
# @param block [Object] block object that represents Speckle block.
|
||||
# @param layer [Sketchup::Layer] layer to add {Sketchup::Edge} into it.
|
||||
# @param entities [Sketchup::Entities] entities collection to add {Sketchup::Edge} into it.
|
||||
def self.to_native(state, block, entities, &convert_to_native)
|
||||
def self.to_native(state, block, layer, entities, &convert_to_native)
|
||||
# is_group = block.key?("is_sketchup_group") && block["is_sketchup_group"]
|
||||
# something about this conversion is freaking out if nested block geo is a group
|
||||
# so this is set to false always until I can figure this out
|
||||
@@ -123,6 +124,7 @@ module SpeckleConnector
|
||||
state, _definitions = BlockDefinition.to_native(
|
||||
state,
|
||||
block_definition,
|
||||
layer,
|
||||
entities,
|
||||
&convert_to_native
|
||||
)
|
||||
@@ -130,8 +132,10 @@ module SpeckleConnector
|
||||
definition = state.sketchup_state.sketchup_model
|
||||
.definitions[BlockDefinition.get_definition_name(block_definition)]
|
||||
|
||||
block_layer = state.sketchup_state.sketchup_model.layers.to_a.find { |l| l.display_name == block['layer'] }
|
||||
return add_instance_from_definition(state, block, block_layer, entities, definition, is_group, &convert_to_native)
|
||||
block_layer_name = SketchupModel::Query::Layer.entity_layer_from_path(block['layer'])
|
||||
block_layer = state.sketchup_state.sketchup_model.layers.to_a.find { |l| l.display_name == block_layer_name }
|
||||
return add_instance_from_definition(state, block, block_layer, layer, entities, definition, is_group,
|
||||
&convert_to_native)
|
||||
end
|
||||
|
||||
def self.get_transform_matrix(block)
|
||||
@@ -166,18 +170,19 @@ module SpeckleConnector
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def self.add_instance_from_definition(state, block, layer, entities, definition, is_group, &convert_to_native)
|
||||
def self.add_instance_from_definition(state, block, block_layer, layer, entities, definition, is_group,
|
||||
&convert_to_native)
|
||||
t_arr = get_transform_matrix(block)
|
||||
transform = Other::Transform.to_native(t_arr, block['units'])
|
||||
instance = if is_group
|
||||
# rubocop:disable SketchupSuggestions/AddGroup
|
||||
group = entities.add_group(definition.entities.to_a)
|
||||
group.layer = layer unless layer.nil?
|
||||
group.layer = block_layer.nil? ? layer : block_layer
|
||||
group
|
||||
# rubocop:enable SketchupSuggestions/AddGroup
|
||||
else
|
||||
instance = entities.add_instance(definition, transform)
|
||||
instance.layer = layer unless layer.nil?
|
||||
instance.layer = block_layer.nil? ? layer : block_layer
|
||||
instance
|
||||
end
|
||||
|
||||
@@ -187,7 +192,7 @@ module SpeckleConnector
|
||||
puts("Failed to create instance for speckle block instance #{block['id']}") if instance.nil?
|
||||
# Transform already applied to instance unless is group
|
||||
instance.transformation = transform if is_group
|
||||
state, _materials = Other::RenderMaterial.to_native(state, block['renderMaterial'],
|
||||
state, _materials = Other::RenderMaterial.to_native(state, block['renderMaterial'], layer,
|
||||
entities, &convert_to_native)
|
||||
|
||||
# Retrieve material from state
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Others
|
||||
module Other
|
||||
# Color object transformations between sketchup and speckle.
|
||||
class Color
|
||||
# @param color [Sketchup::Color] color to convert speckle object
|
||||
@@ -16,9 +16,24 @@ module SpeckleConnector
|
||||
end
|
||||
|
||||
def self.to_native(speckle_color)
|
||||
return from_int(speckle_color) if speckle_color.is_a?(Numeric)
|
||||
|
||||
Sketchup::Color.new(speckle_color['red'], speckle_color['green'],
|
||||
speckle_color['blue'], speckle_color['alpha'])
|
||||
end
|
||||
|
||||
# @param color [Sketchup::Color] color to convert speckle object
|
||||
# @return [Numeric] int value of the color
|
||||
def self.to_int(color)
|
||||
rgba = color.to_a
|
||||
[rgba[3] << 24 | rgba[0] << 16 | rgba[1] << 8 | rgba[2]].pack('l').unpack1('l').to_i
|
||||
end
|
||||
|
||||
# @param argb [Numeric] int value of the corresponding color
|
||||
# @return [Sketchup::Color] sketchup color
|
||||
def self.from_int(argb)
|
||||
Sketchup::Color.new((argb >> 16) & 255, (argb >> 8) & 255, argb & 255, (argb >> 24) & 255)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'color'
|
||||
require_relative '../base'
|
||||
require_relative '../../constants/type_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Other
|
||||
# DisplayStyle object for layer.
|
||||
class DisplayStyle < Base
|
||||
|
||||
def initialize(name:, color:, line_type:)
|
||||
super(
|
||||
speckle_type: OBJECTS_OTHER_DISPLAYSTYLE,
|
||||
total_children_count: 0,
|
||||
application_id: nil,
|
||||
id: nil
|
||||
)
|
||||
self[:name] = name
|
||||
self[:color] = color
|
||||
self[:linetype] = line_type unless line_type.nil?
|
||||
end
|
||||
|
||||
# @param layer [Sketchup::Layer] layer to get display style.
|
||||
def self.from_layer(layer)
|
||||
DisplayStyle.new(
|
||||
name: '',
|
||||
color: Color.to_int(layer.color),
|
||||
line_type: layer.line_style.nil? ? nil : layer.line_style.name
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -43,7 +43,7 @@ module SpeckleConnector
|
||||
|
||||
# Creates a component definition and instance from a speckle object with a display value
|
||||
# @param state [States::State] state of the application.
|
||||
def self.to_native(state, obj, entities, &convert_to_native)
|
||||
def self.to_native(state, obj, layer, entities, &convert_to_native)
|
||||
# Switch displayValue with geometry
|
||||
obj = collect_definition_geometries(obj)
|
||||
obj['name'] = get_definition_name(obj)
|
||||
@@ -51,6 +51,7 @@ module SpeckleConnector
|
||||
state, _definitions = BlockDefinition.to_native(
|
||||
state,
|
||||
obj,
|
||||
layer,
|
||||
entities,
|
||||
&convert_to_native
|
||||
)
|
||||
@@ -59,19 +60,22 @@ module SpeckleConnector
|
||||
|
||||
BlockInstance.find_and_erase_existing_instance(definition, obj['id'], obj['applicationId'])
|
||||
t_arr = obj['transform']
|
||||
transform = t_arr.nil? ? Geom::Transformation.new : OTHER::Transform.to_native(t_arr, obj['units'])
|
||||
transform = t_arr.nil? ? Geom::Transformation.new : Other::Transform.to_native(t_arr, obj['units'])
|
||||
instance = entities.add_instance(definition, transform)
|
||||
instance.name = obj['name'] unless obj['name'].nil?
|
||||
instance.layer = layer unless layer.nil?
|
||||
# Align instance axes that created from display value. (without any transform)
|
||||
# BlockInstance.align_instance_axes(instance)
|
||||
return state, [instance, definition]
|
||||
end
|
||||
|
||||
def self.collect_definition_geometries(obj)
|
||||
obj['geometry'] = obj['displayValue']
|
||||
obj['geometry'] = obj['displayValue'] || obj['@displayValue']
|
||||
|
||||
if !obj['elements'].nil? && obj['elements'].is_a?(Array)
|
||||
obj['elements'].each do |element|
|
||||
elements = obj['elements'] || obj['@elements']
|
||||
|
||||
if !elements.nil? && elements.is_a?(Array)
|
||||
elements.each do |element|
|
||||
# Mullions is a special case here, they are extracted as base object with @displayValue from revit..
|
||||
if element['@displayValue'].nil?
|
||||
obj['geometry'].append(element)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'color'
|
||||
require_relative '../base'
|
||||
|
||||
module SpeckleConnector
|
||||
@@ -38,10 +39,9 @@ module SpeckleConnector
|
||||
|
||||
# @param material [Sketchup::Material] material on the Sketchup.
|
||||
def self.from_material(material)
|
||||
rgba = material.color.to_a
|
||||
RenderMaterial.new(
|
||||
name: material.name,
|
||||
diffuse: [rgba[3] << 24 | rgba[0] << 16 | rgba[1] << 8 | rgba[2]].pack('l').unpack1('l'),
|
||||
diffuse: Other::Color.to_int(material.color),
|
||||
opacity: material.alpha,
|
||||
emissive: -16_777_216,
|
||||
metalness: 0,
|
||||
@@ -50,7 +50,7 @@ module SpeckleConnector
|
||||
end
|
||||
|
||||
# @param state [States::State] state of the application.
|
||||
def self.to_native(state, render_material, _entities, &_convert_to_native)
|
||||
def self.to_native(state, render_material, _layer, _entities, &_convert_to_native)
|
||||
return state, [] if render_material.nil?
|
||||
|
||||
sketchup_model = state.sketchup_state.sketchup_model
|
||||
@@ -65,7 +65,7 @@ module SpeckleConnector
|
||||
material = sketchup_model.materials.add(name)
|
||||
material.alpha = render_material['opacity']
|
||||
argb = render_material['diffuse']
|
||||
material.color = Sketchup::Color.new((argb >> 16) & 255, (argb >> 8) & 255, argb & 255, (argb >> 24) & 255)
|
||||
material.color = Color.from_int(argb)
|
||||
new_sketchup_state = state.sketchup_state.with_materials(materials.add_material(name, material))
|
||||
return state.with_sketchup_state(new_sketchup_state), [material]
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ require_relative 'color'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Others
|
||||
module Other
|
||||
# Rendering options for scenes.
|
||||
class RenderingOptions
|
||||
# @param options [Sketchup::RenderingOptions] rendering options to convert speckle object
|
||||
|
||||
@@ -10,7 +10,9 @@ module SpeckleConnector
|
||||
class Layer < Base
|
||||
SPECKLE_TYPE = 'Speckle.Core.Models.Collection'
|
||||
|
||||
def initialize(name:, visible:, is_folder:, color: nil, layers_and_folders: [], application_id: nil)
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def initialize(name:, visible:, is_folder:, line_style: nil, color: nil, layers_and_folders: [],
|
||||
application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
@@ -21,31 +23,38 @@ module SpeckleConnector
|
||||
self[:color] = color
|
||||
self[:visible] = visible
|
||||
self[:is_folder] = is_folder
|
||||
self[:line_style] = line_style unless line_style.nil?
|
||||
self[:collectionType] = 'layer'
|
||||
self[:elements] = layers_and_folders if layers_and_folders.any?
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
# @param speckle_layer [Object] speckle layer object.
|
||||
# @param folder [Sketchup::Layers, Sketchup::LayerFolder] folder to create layers in it.
|
||||
# @param sketchup_model [Sketchup::Model] sketchup active model.
|
||||
def self.to_native_layer(speckle_layer, folder, sketchup_model)
|
||||
layer = sketchup_model.layers.add_layer(speckle_layer['name'])
|
||||
layer.visible = speckle_layer['visible'] unless speckle_layer['visible'].nil?
|
||||
layer.color = SpeckleObjects::Others::Color.to_native(speckle_layer['color']) if speckle_layer['color']
|
||||
layer = sketchup_model.layers.add_layer(speckle_layer[:name])
|
||||
layer.visible = speckle_layer[:visible] unless speckle_layer[:visible].nil?
|
||||
layer.color = SpeckleObjects::Other::Color.to_native(speckle_layer[:color]) if speckle_layer[:color]
|
||||
if speckle_layer[:line_style]
|
||||
line_style = sketchup_model.line_styles.find { |ls| ls.name == speckle_layer[:line_style] }
|
||||
layer.line_style = line_style unless line_style.nil?
|
||||
end
|
||||
folder.add_layer(layer) if folder.is_a?(Sketchup::LayerFolder)
|
||||
end
|
||||
|
||||
def self.to_native_layer_folder(speckle_layer_folder, folder, sketchup_model)
|
||||
speckle_layers = speckle_layer_folder['elements'].select { |layer_or_fol| layer_or_fol['elements'].nil? }
|
||||
speckle_layers = speckle_layer_folder[:elements].select { |layer_or_fol| layer_or_fol[:elements].nil? }
|
||||
|
||||
speckle_layers.each do |speckle_layer|
|
||||
to_native_layer(speckle_layer, folder, sketchup_model)
|
||||
end
|
||||
|
||||
speckle_folders = speckle_layer_folder['elements'].reject { |layer_or_fol| layer_or_fol['elements'].nil? }
|
||||
speckle_folders = speckle_layer_folder[:elements].reject { |layer_or_fol| layer_or_fol[:elements].nil? }
|
||||
|
||||
speckle_folders.each do |speckle_folder|
|
||||
sub_folder = folder.add_folder(speckle_folder['name'])
|
||||
sub_folder.visible = speckle_folder['visible'] unless speckle_folder['visible'].nil?
|
||||
sub_folder = folder.add_folder(speckle_folder[:name])
|
||||
sub_folder.visible = speckle_folder[:visible] unless speckle_folder[:visible].nil?
|
||||
to_native_layer_folder(speckle_folder, sub_folder, sketchup_model)
|
||||
end
|
||||
end
|
||||
@@ -69,7 +78,8 @@ module SpeckleConnector
|
||||
name: layer.display_name,
|
||||
visible: layer.visible?,
|
||||
is_folder: false,
|
||||
color: SpeckleObjects::Others::Color.to_speckle(layer.color),
|
||||
line_style: layer.line_style.nil? ? nil : layer.line_style.name,
|
||||
color: SpeckleObjects::Other::Color.to_speckle(layer.color),
|
||||
application_id: layer.persistent_id
|
||||
)
|
||||
end
|
||||
|
||||
@@ -22,6 +22,33 @@ module SpeckleConnector
|
||||
self[:elements] = layers
|
||||
end
|
||||
|
||||
def self.element_to_relation(elements)
|
||||
elements.collect do |element|
|
||||
next unless element['speckle_type'] == SPECKLE_CORE_MODELS_COLLECTION
|
||||
|
||||
is_folder = element['elements'].any? { |e| e['speckle_type'] == SPECKLE_CORE_MODELS_COLLECTION }
|
||||
color = element['color'] || element['displayStyle']['color'] unless element['displayStyle'].nil?
|
||||
Layer.new(
|
||||
name: element['name'],
|
||||
visible: element['visible'],
|
||||
is_folder: is_folder,
|
||||
color: color,
|
||||
layers_and_folders: element_to_relation(element['elements'])
|
||||
)
|
||||
end.compact
|
||||
end
|
||||
|
||||
def self.extract_relations(commit_obj)
|
||||
return nil unless commit_obj['speckle_type'] == SPECKLE_CORE_MODELS_COLLECTION
|
||||
|
||||
elements = element_to_relation(commit_obj['elements'])
|
||||
|
||||
Layers.new(
|
||||
active: commit_obj['active_layer'],
|
||||
layers: elements
|
||||
)
|
||||
end
|
||||
|
||||
def self.to_native(layers_relation, sketchup_model)
|
||||
folder = sketchup_model.layers
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ module SpeckleConnector
|
||||
return "#{family}-#{type}-#{category}-#{def_obj['elementId']}"
|
||||
end
|
||||
|
||||
def self.to_native(state, definition, entities, &convert_to_native)
|
||||
def self.to_native(state, definition, layer, entities, &convert_to_native)
|
||||
definition_name = get_definition_name(definition)
|
||||
definition['name'] = definition_name
|
||||
definition['displayValue'] += definition['elements'] unless definition['elements'].nil?
|
||||
SpeckleObjects::Other::BlockDefinition.to_native(state, definition, entities, &convert_to_native)
|
||||
SpeckleObjects::Other::BlockDefinition.to_native(state, definition, layer, entities, &convert_to_native)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,12 +16,13 @@ module SpeckleConnector
|
||||
# @param block [Object] block object that represents Speckle block.
|
||||
# @param layer [Sketchup::Layer] layer to add {Sketchup::Edge} into it.
|
||||
# @param entities [Sketchup::Entities] entities collection to add {Sketchup::Edge} into it.
|
||||
def self.to_native(state, block, entities, &convert_to_native)
|
||||
def self.to_native(state, block, layer, entities, &convert_to_native)
|
||||
block_definition = block['definition']
|
||||
|
||||
state, _definitions = RevitDefinition.to_native(
|
||||
state,
|
||||
block_definition,
|
||||
layer,
|
||||
entities,
|
||||
&convert_to_native
|
||||
)
|
||||
@@ -29,10 +30,11 @@ module SpeckleConnector
|
||||
definition = state.sketchup_state.sketchup_model
|
||||
.definitions[RevitDefinition.get_definition_name(block_definition)]
|
||||
|
||||
layer = state.sketchup_state.sketchup_model.layers.to_a.find { |l| l.display_name == block['category'] }
|
||||
block_layer = state.sketchup_state.sketchup_model.layers.to_a
|
||||
.find { |l| l.display_name == block['category'] }
|
||||
|
||||
return SpeckleObjects::Other::BlockInstance.add_instance_from_definition(
|
||||
state, block, layer, entities, definition, false, &convert_to_native
|
||||
state, block, block_layer, layer, entities, definition, false, &convert_to_native
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../../base'
|
||||
|
||||
require_relative '../../../../constants/type_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
@@ -10,15 +10,13 @@ module SpeckleConnector
|
||||
module Models
|
||||
# Collection object that collect other speckle objects under it's elements.
|
||||
class Collection < Base
|
||||
SPECKLE_TYPE = 'Speckle.Core.Models.Collection'
|
||||
|
||||
# @param name [String] name of the collection.
|
||||
# @param collection_type [String] type of the collection like, layers, categories etc..
|
||||
# @param elements [Array<Object>] elements of the collection.
|
||||
# @param application_id [String, nil] id of the collection on the model.
|
||||
def initialize(name:, collection_type:, elements: [], application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
speckle_type: SPECKLE_CORE_MODELS_COLLECTION,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: nil
|
||||
@@ -27,6 +25,16 @@ module SpeckleConnector
|
||||
self[:collectionType] = collection_type
|
||||
self[:elements] = elements
|
||||
end
|
||||
|
||||
def self.to_native(state, collection, layer, entities, &convert_to_native)
|
||||
collection_type = collection['collectionType']
|
||||
|
||||
if collection_type.include?('model')
|
||||
ModelCollection.to_native(state, collection, layer, entities, &convert_to_native)
|
||||
else
|
||||
LayerCollection.to_native(state, collection, layer, entities, &convert_to_native)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
require_relative 'collection'
|
||||
require_relative '../../../../sketchup_model/query/layer'
|
||||
require_relative '../../../other/color'
|
||||
require_relative '../../../other/display_style'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
@@ -12,7 +13,9 @@ module SpeckleConnector
|
||||
# LayerCollection object that collect other speckle objects under it's elements.
|
||||
class LayerCollection < Collection
|
||||
SPECKLE_TYPE = 'Speckle.Core.Models.Collection'
|
||||
def initialize(name:, visible:, is_folder:, color: nil, elements: [], application_id: nil)
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def initialize(name:, visible:, is_folder:, display_style: nil, color: nil, elements: [],
|
||||
application_id: nil)
|
||||
super(
|
||||
name: name,
|
||||
collection_type: 'layer',
|
||||
@@ -22,7 +25,9 @@ module SpeckleConnector
|
||||
self[:visible] = visible
|
||||
self[:is_folder] = is_folder
|
||||
self[:color] = color unless color.nil?
|
||||
self[:displayStyle] = display_style unless display_style.nil?
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
def self.create_layer_collections(sketchup_model)
|
||||
headless_layers = sketchup_model.layers.layers.collect do |layer|
|
||||
@@ -55,13 +60,14 @@ module SpeckleConnector
|
||||
name: layer.display_name,
|
||||
visible: layer.visible?,
|
||||
is_folder: false,
|
||||
color: SpeckleObjects::Others::Color.to_speckle(layer.color),
|
||||
display_style: Other::DisplayStyle.from_layer(layer),
|
||||
application_id: layer.persistent_id
|
||||
)
|
||||
end
|
||||
|
||||
# @param entity_layer [Sketchup::Layer] entity layer.
|
||||
# @param collection [Array] collection to search elements for entity's layer.
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def self.get_or_create_layer_collection(entity_layer, collection)
|
||||
folder_path = SpeckleConnector::SketchupModel::Query::Layer.path(entity_layer)
|
||||
entity_layer_path = folder_path + [entity_layer]
|
||||
@@ -73,12 +79,10 @@ module SpeckleConnector
|
||||
el[:name] == folder.display_name
|
||||
end
|
||||
if collection_candidate.nil?
|
||||
color = folder.respond_to?(:color) ? SpeckleObjects::Others::Color.to_speckle(folder.color) : nil
|
||||
color = folder.respond_to?(:color) ? SpeckleObjects::Other::Color.to_speckle(folder.color) : nil
|
||||
collection_candidate = LayerCollection.new(
|
||||
name: folder.display_name,
|
||||
visible: folder.visible?,
|
||||
is_folder: folder.is_a?(Sketchup::LayerFolder),
|
||||
color: color
|
||||
name: folder.display_name, visible: folder.visible?,
|
||||
is_folder: folder.is_a?(Sketchup::LayerFolder), color: color
|
||||
)
|
||||
# Before switching collection with the new one, we should add it to current collection's elements
|
||||
collection[:elements].append(collection_candidate)
|
||||
@@ -88,6 +92,24 @@ module SpeckleConnector
|
||||
|
||||
collection
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
|
||||
# @param state [States::State] state of the Speckle application.
|
||||
def self.to_native(state, layer_collection, layer_or_folder, entities, &convert_to_native)
|
||||
sketchup_model = state.sketchup_state.sketchup_model
|
||||
elements = layer_collection['elements']
|
||||
name = layer_collection['name']
|
||||
|
||||
layer = sketchup_model.layers.find { |l| l.display_name == name }
|
||||
layer_or_folder = layer if layer
|
||||
|
||||
elements.each do |element|
|
||||
new_state = convert_to_native.call(state, element, layer_or_folder, entities)
|
||||
state = new_state
|
||||
end
|
||||
|
||||
return state, []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,6 +61,20 @@ module SpeckleConnector
|
||||
[direct_shape, [entity]]
|
||||
end
|
||||
end
|
||||
|
||||
def self.to_native(state, model_collection, layer, entities, &convert_to_native)
|
||||
elements = model_collection['elements']
|
||||
|
||||
elements.each do |element|
|
||||
new_state = convert_to_native.call(state, element, layer, entities)
|
||||
state = new_state
|
||||
end
|
||||
|
||||
active_layer = model_collection['active_layer']
|
||||
state.sketchup_state.sketchup_model.active_layer = active_layer unless active_layer.nil?
|
||||
|
||||
return state, []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -165,6 +165,7 @@ export default {
|
||||
return {
|
||||
isIsolated: false,
|
||||
elementSelection: {},
|
||||
categorySelection: [],
|
||||
mappedEntities: [],
|
||||
mappedEntityCount: 0,
|
||||
// Expanded indexes for mapped element table (Categories)
|
||||
@@ -181,9 +182,9 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
categorySelection() {
|
||||
return Object.keys(this.elementSelection)
|
||||
},
|
||||
// categorySelection() {
|
||||
// return Object.keys(this.elementSelection)
|
||||
// },
|
||||
},
|
||||
mounted() {
|
||||
sketchup.exec({name: "collect_mapped_entities", data: {}})
|
||||
@@ -248,9 +249,14 @@ export default {
|
||||
selectMappedElementsOnSketchup(){
|
||||
sketchup.exec({ name: "select_mappings_from_table", data: this.elementSelection })
|
||||
},
|
||||
// Update mapped elements table whenever mapped elements has changed.
|
||||
getMappedElementsTableData(){
|
||||
let groupByCategoryName = groupBy('categoryName')
|
||||
let groupedByCategoryName = groupByCategoryName(this.mappedEntities)
|
||||
// Reset selected categories and elements whenever mapped elements states has changed
|
||||
this.elementSelection = {}
|
||||
this.categorySelection = []
|
||||
this.mappedElementsExpandedIndexes = []
|
||||
this.mappedEntitiesTableData = Object.entries(groupedByCategoryName).map(
|
||||
(entry) => {
|
||||
const [categoryName, entities] = entry
|
||||
|
||||
@@ -26,9 +26,11 @@ const SpeckleMetrics = {
|
||||
.digest('hex')
|
||||
.toUpperCase()
|
||||
|
||||
let serverUrl = new URL(localStorage.getItem('serverUrl'))
|
||||
|
||||
let serverId = crypto
|
||||
.createHash('md5')
|
||||
.update(localStorage.getItem('serverUrl').toLowerCase())
|
||||
.update(serverUrl.hostname.toLowerCase())
|
||||
.digest('hex')
|
||||
.toUpperCase()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user