Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 69bde5539c | |||
| aa12b7b11b | |||
| e0b3b3cca2 | |||
| ea9a5741d7 | |||
| 1fe1c8d5a8 |
@@ -11,5 +11,7 @@ jobs:
|
||||
# Orchestrate our job run sequence
|
||||
workflows:
|
||||
build_and_test:
|
||||
when:
|
||||
false
|
||||
jobs:
|
||||
- build
|
||||
- build
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
require 'JSON'
|
||||
require_relative '../ext/sqlite3'
|
||||
require_relative '../constants/path_constants'
|
||||
require_relative '../preferences/preferences'
|
||||
|
||||
module SpeckleConnector3
|
||||
# Accounts to communicate with models on user's account.
|
||||
@@ -11,11 +12,11 @@ module SpeckleConnector3
|
||||
def self.load_accounts
|
||||
db_path = SPECKLE_ACCOUNTS_DB_PATH
|
||||
unless File.exist?(db_path)
|
||||
raise(
|
||||
IOError,
|
||||
"No Accounts db found. Please read the guide for different options for adding your account:\n
|
||||
https://speckle.guide/user/manager.html#adding-accounts"
|
||||
)
|
||||
File.new(SPECKLE_ACCOUNTS_DB_PATH, "w")
|
||||
db = Sqlite3::Database.new(SPECKLE_ACCOUNTS_DB_PATH)
|
||||
Preferences.create_objects_table(db)
|
||||
db.close
|
||||
return []
|
||||
end
|
||||
|
||||
db = Sqlite3::Database.new(db_path)
|
||||
|
||||
@@ -17,7 +17,9 @@ module SpeckleConnector3
|
||||
def self.update_state(state, resolve_id, data)
|
||||
model_card_id = data['modelCardId']
|
||||
account_id = data['accountId']
|
||||
server_url = data['serverUrl']
|
||||
workspace_id = data['workspaceId']
|
||||
workspace_slug = data['workspaceSlug']
|
||||
project_id = data['projectId']
|
||||
model_id = data['modelId']
|
||||
project_name = data['projectName']
|
||||
@@ -32,7 +34,7 @@ module SpeckleConnector3
|
||||
has_dismissed_update_warning = data['hasDismissedUpdateWarning']
|
||||
baked_object_ids = data['bakedObjectIds'].nil? ? nil : data['bakedObjectIds'].values
|
||||
|
||||
receive_card = Cards::ReceiveCard.new(model_card_id, account_id, workspace_id,
|
||||
receive_card = Cards::ReceiveCard.new(model_card_id, account_id, server_url, workspace_id, workspace_slug,
|
||||
project_id, model_id,
|
||||
project_name, model_name,
|
||||
selected_version_id, selected_version_source_app, selected_version_user_id,
|
||||
|
||||
@@ -22,7 +22,9 @@ module SpeckleConnector3
|
||||
send_card = Cards::SendCard.new(
|
||||
data['modelCardId'],
|
||||
data['accountId'],
|
||||
data['serverUrl'],
|
||||
data['workspaceId'],
|
||||
data['workspaceSlug'],
|
||||
data['projectId'],
|
||||
data['projectName'],
|
||||
data['modelId'],
|
||||
|
||||
@@ -21,7 +21,9 @@ module SpeckleConnector3
|
||||
send_card = Cards::SendCard.new(
|
||||
id,
|
||||
card['account_id'],
|
||||
card['server_url'],
|
||||
card['workspace_id'],
|
||||
card['workspace_slug'],
|
||||
card['project_id'],
|
||||
card['project_name'],
|
||||
card['model_id'],
|
||||
@@ -36,7 +38,9 @@ module SpeckleConnector3
|
||||
{
|
||||
modelCardId: send_card.model_card_id,
|
||||
accountId: send_card.account_id,
|
||||
serverUrl: send_card.server_url,
|
||||
workspaceId: send_card.workspace_id,
|
||||
workspaceSlug: send_card.workspace_slug,
|
||||
projectId: send_card.project_id,
|
||||
modelId: send_card.model_id,
|
||||
sendFilter: send_card.send_filter,
|
||||
@@ -51,7 +55,7 @@ module SpeckleConnector3
|
||||
|
||||
# TODO: CONVERTER_V2: Extract into new actions
|
||||
receive_cards = receive_cards_hash.collect do |id, card|
|
||||
receive_card = Cards::ReceiveCard.new(id, card['account_id'], card['workspace_id'], card['project_id'], card['model_id'],
|
||||
receive_card = Cards::ReceiveCard.new(id, card['account_id'], card['server_url'], card['workspace_id'], card['workspace_slug'], card['project_id'], card['model_id'],
|
||||
card['project_name'], card['model_name'], card['selected_version_id'],
|
||||
card['selected_version_source_app'], card['selected_version_user_id'],
|
||||
card['latest_version_id'], card['latest_version_source_app'],
|
||||
@@ -63,7 +67,9 @@ module SpeckleConnector3
|
||||
{
|
||||
modelCardId: receive_card.model_card_id,
|
||||
accountId: receive_card.account_id,
|
||||
serverUrl: receive_card.server_url,
|
||||
workspaceId: receive_card.workspace_id,
|
||||
workspaceSlug: receive_card.workspace_slug,
|
||||
projectId: receive_card.project_id,
|
||||
modelId: receive_card.model_id,
|
||||
projectName: receive_card.project_name,
|
||||
|
||||
@@ -27,27 +27,37 @@ module SpeckleConnector3
|
||||
# @return [String] workspace id of the card.
|
||||
attr_reader :workspace_id
|
||||
|
||||
# @return [String] workspace slug of the card.
|
||||
attr_reader :workspace_slug
|
||||
|
||||
# @return [String] server url of the card.
|
||||
attr_reader :server_url
|
||||
|
||||
# @return [Boolean] card is valid or not.
|
||||
attr_reader :valid
|
||||
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def initialize(model_card_id, account_id, workspace_id, project_id, project_name, model_id, model_name)
|
||||
def initialize(model_card_id, account_id, server_url, workspace_id, workspace_slug, project_id, project_name, model_id, model_name)
|
||||
super()
|
||||
@model_card_id = model_card_id
|
||||
@account_id = account_id
|
||||
@workspace_id = workspace_id
|
||||
@workspace_slug = workspace_slug
|
||||
@project_id = project_id
|
||||
@project_name = project_name
|
||||
@model_id = model_id
|
||||
@model_name = model_name
|
||||
@server_url = server_url
|
||||
@valid = true
|
||||
self[:model_card_id] = model_card_id
|
||||
self[:account_id] = account_id
|
||||
self[:workspace_id] = workspace_id
|
||||
self[:workspace_slug] = workspace_slug
|
||||
self[:project_id] = project_id
|
||||
self[:project_name] = project_name
|
||||
self[:model_id] = model_id
|
||||
self[:model_name] = model_name
|
||||
self[:server_url] = server_url
|
||||
self[:valid] = @valid
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
@@ -48,7 +48,9 @@ module SpeckleConnector3
|
||||
def initialize(
|
||||
model_card_id,
|
||||
account_id,
|
||||
server_url,
|
||||
workspace_id,
|
||||
workspace_slug,
|
||||
project_id,
|
||||
model_id,
|
||||
project_name,
|
||||
@@ -63,7 +65,7 @@ module SpeckleConnector3
|
||||
expired,
|
||||
baked_object_ids = nil
|
||||
)
|
||||
super(model_card_id, account_id, workspace_id, project_id, project_name, model_id, model_name)
|
||||
super(model_card_id, account_id, server_url, workspace_id, workspace_slug, project_id, project_name, model_id, model_name)
|
||||
@selected_version_id = selected_version_id
|
||||
@selected_version_source_app = selected_version_source_app
|
||||
@selected_version_user_id = selected_version_user_id
|
||||
|
||||
@@ -26,7 +26,9 @@ module SpeckleConnector3
|
||||
def initialize(
|
||||
model_card_id,
|
||||
account_id,
|
||||
server_url,
|
||||
workspace_id,
|
||||
workspace_slug,
|
||||
project_id,
|
||||
project_name,
|
||||
model_id,
|
||||
@@ -35,7 +37,7 @@ module SpeckleConnector3
|
||||
send_filter,
|
||||
send_settings
|
||||
)
|
||||
super(model_card_id, account_id, workspace_id, project_id, project_name, model_id, model_name)
|
||||
super(model_card_id, account_id, server_url, workspace_id, workspace_slug, project_id, project_name, model_id, model_name)
|
||||
@send_filter = send_filter
|
||||
@send_settings = send_settings
|
||||
@latest_created_version_id = latest_created_version_id
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'card'
|
||||
|
||||
module SpeckleConnector3
|
||||
module Cards
|
||||
# Send card for sketchup connector to communicate speckle.
|
||||
class SendCardMultipleFilters < Card
|
||||
# @return [Hash{String=>Filter}] filters of the card.
|
||||
attr_reader :filters
|
||||
|
||||
def initialize(card_id, account_id, project_id, model_id, filters)
|
||||
super(card_id, account_id, project_id, model_id)
|
||||
@filters = filters
|
||||
self[:filters] = filters
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# # frozen_string_literal: true
|
||||
#
|
||||
# require_relative 'card'
|
||||
#
|
||||
# module SpeckleConnector3
|
||||
# module Cards
|
||||
# # Send card for sketchup connector to communicate speckle.
|
||||
# class SendCardMultipleFilters < Card
|
||||
# # @return [Hash{String=>Filter}] filters of the card.
|
||||
# attr_reader :filters
|
||||
#
|
||||
# def initialize(card_id, account_id, project_id, model_id, filters)
|
||||
# super(card_id, account_id, project_id, model_id)
|
||||
# @filters = filters
|
||||
# self[:filters] = filters
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
@@ -54,4 +54,8 @@ module SpeckleConnector3
|
||||
SPECKLE_CORE_MODELS_INSTANCES_INSTANCE_DEFINITION_PROXY = 'Speckle.Core.Models.Instances.InstanceDefinitionProxy'
|
||||
SPECKLE_CORE_OTHER_RENDER_MATERIAL_PROXY = 'Objects.Other.RenderMaterialProxy'
|
||||
SPECKLE_CORE_OTHER_COLOR_PROXY = 'Speckle.Core.Models.Proxies.ColorProxy'
|
||||
|
||||
# DATA OBJECTS
|
||||
SPECKLE_OBJECT_DATA_OBJECT = 'Objects.Data.DataObject'
|
||||
SPECKLE_OBJECT_DATA_OBJECT_REVIT = 'Objects.Data.DataObject:Objects.Data.RevitObject'
|
||||
end
|
||||
|
||||
@@ -22,6 +22,7 @@ require_relative '../speckle_objects/built_elements/network'
|
||||
require_relative '../speckle_objects/speckle/core/models/collection'
|
||||
require_relative '../speckle_objects/speckle/core/models/gis_layer_collection'
|
||||
require_relative '../speckle_objects/instance_definition_proxy'
|
||||
require_relative '../speckle_objects/data/revit_data_object'
|
||||
require_relative '../sketchup_model/dictionary/speckle_entity_dictionary_handler'
|
||||
require_relative '../ui_data/report/conversion_result'
|
||||
require_relative '../convertors/conversion_error'
|
||||
@@ -94,6 +95,8 @@ module SpeckleConnector3
|
||||
LAYER_COLLECTION = SpeckleObjects::Speckle::Core::Models::LayerCollection
|
||||
GIS_LAYER_COLLECTION = SpeckleObjects::Speckle::Core::Models::GisLayerCollection
|
||||
|
||||
REVIT_DATA_OBJECT = SpeckleObjects::RevitDataObject
|
||||
|
||||
BASE_OBJECT_PROPS = %w[applicationId id speckle_type].freeze
|
||||
CONVERTABLE_SPECKLE_TYPES = %w[
|
||||
Objects.Geometry.Line
|
||||
@@ -117,6 +120,7 @@ module SpeckleConnector3
|
||||
Speckle.Core.Models.Collections.Collection:Speckle.Core.Models.Collections.Layer
|
||||
Speckle.Core.Models.Collections.Collection:Objects.GIS.RasterLayer
|
||||
Speckle.Core.Models.Collections.Collection:Objects.GIS.VectorLayer
|
||||
Objects.Data.DataObject:Objects.Data.RevitObject
|
||||
].freeze
|
||||
|
||||
def from_revit
|
||||
@@ -377,6 +381,10 @@ module SpeckleConnector3
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
def speckle_object_to_native(obj)
|
||||
if SPECKLE_OBJECTS_WITH_NATIVE_CONVERSION[obj['speckle_type']]
|
||||
return SPECKLE_OBJECTS_WITH_NATIVE_CONVERSION[obj['speckle_type']]
|
||||
end
|
||||
|
||||
return DISPLAY_VALUE.method(:to_native) unless obj['displayValue'].nil? && obj['@displayValue'].nil?
|
||||
|
||||
SPECKLE_OBJECT_TO_NATIVE[obj['speckle_type']]
|
||||
@@ -409,6 +417,10 @@ module SpeckleConnector3
|
||||
SPECKLE_CORE_MODELS_COLLECTION_VECTOR_LAYER => GIS_LAYER_COLLECTION.method(:to_native)
|
||||
}.freeze
|
||||
|
||||
SPECKLE_OBJECTS_WITH_NATIVE_CONVERSION = {
|
||||
SPECKLE_OBJECT_DATA_OBJECT_REVIT => REVIT_DATA_OBJECT.method(:to_native)
|
||||
}
|
||||
|
||||
def entities_to_bake(obj, entities)
|
||||
entities_to_bake = entities
|
||||
object_id = obj['applicationId'].to_s # TODO: CONVERTER_V2: faces have integer application id..!!?
|
||||
@@ -452,14 +464,25 @@ module SpeckleConnector3
|
||||
faces = converted_entities.select { |e| e.is_a?(Sketchup::Face) }
|
||||
@converted_faces += faces if faces.any?
|
||||
if from_revit
|
||||
# Create levels as section planes if they exists
|
||||
create_levels(state, obj)
|
||||
# Create layers from category of object and place object in it
|
||||
# create_layers_from_categories(state, obj, converted_entities)
|
||||
begin
|
||||
# Create levels as section planes if they exists
|
||||
create_levels(state, obj)
|
||||
# Create layers from category of object and place object in it
|
||||
# create_layers_from_categories(state, obj, converted_entities)
|
||||
rescue StandardError => e
|
||||
puts "Level could not be created: #{e.message}"
|
||||
end
|
||||
|
||||
end
|
||||
# Create speckle entities from sketchup entities to achieve continuous traversal.
|
||||
|
||||
converted_entities.each do |converted|
|
||||
if converted.is_a?(Sketchup::ComponentDefinition)
|
||||
next # no need to report definitions
|
||||
end
|
||||
if !from_sketchup && converted.is_a?(Sketchup::Face)
|
||||
next # Otherwise we have many noise in report and causing delay post-receive
|
||||
end
|
||||
@conversion_results.push(UiData::Report::ConversionResult.new(UiData::Report::ConversionStatus::SUCCESS,
|
||||
obj['id'],
|
||||
obj['speckle_type'],
|
||||
|
||||
@@ -72,6 +72,22 @@ module SpeckleConnector3
|
||||
hash
|
||||
end
|
||||
|
||||
# @param obj [Object] object to write
|
||||
# @param dict [Sketchup::AttributeDictionary] attribute dictionary to write data.
|
||||
def self.hash_to_dict(dict_name, obj, dict)
|
||||
dict_to_write = dict.attribute_dictionary(dict_name, true)
|
||||
|
||||
obj.each do |key, value|
|
||||
# value = obj.instance_variable_get(var)
|
||||
# var_name = var.to_s[1..-1]
|
||||
if value.is_a?(Hash) # FIXME or not, depends:-> This doesn't cover arrays that has objects in it.
|
||||
hash_to_dict(key.to_s, value, dict_to_write)
|
||||
else
|
||||
dict_to_write[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# @return [String] the name of the dictionary to read from
|
||||
def self.dictionary_name
|
||||
raise NotImplementedError 'Implement this in subclass'
|
||||
|
||||
@@ -13,30 +13,14 @@ module SpeckleConnector3
|
||||
# @param sketchup_model [Sketchup::Model] sketchup model to save cards into it's attribute dictionary
|
||||
def self.save_send_card_to_model(send_card, sketchup_model)
|
||||
send_cards_dict = send_cards_dict(sketchup_model)
|
||||
serialize_obj_to_dict(send_card.model_card_id, send_card, send_cards_dict)
|
||||
hash_to_dict(send_card.model_card_id, send_card, send_cards_dict)
|
||||
end
|
||||
|
||||
# @param receive_card [Cards::ReceiveCard] card to save model
|
||||
# @param sketchup_model [Sketchup::Model] sketchup model to save cards into it's attribute dictionary
|
||||
def self.save_receive_card_to_model(receive_card, sketchup_model)
|
||||
receive_cards_dict = receive_cards_dict(sketchup_model)
|
||||
serialize_obj_to_dict(receive_card.model_card_id, receive_card, receive_cards_dict)
|
||||
end
|
||||
|
||||
# @param obj [Object] object to write
|
||||
# @param dict [Sketchup::AttributeDictionary] attribute dictionary to write data.
|
||||
def self.serialize_obj_to_dict(dict_name, obj, dict)
|
||||
dict_to_write = dict.attribute_dictionary(dict_name, true)
|
||||
|
||||
obj.each do |key, value|
|
||||
# value = obj.instance_variable_get(var)
|
||||
# var_name = var.to_s[1..-1]
|
||||
if value.is_a?(Hash) # FIXME or not depends: This doesn't cover arrays that has objects in it.
|
||||
serialize_obj_to_dict(key.to_s, value, dict_to_write)
|
||||
else
|
||||
dict_to_write[key] = value
|
||||
end
|
||||
end
|
||||
hash_to_dict(receive_card.model_card_id, receive_card, receive_cards_dict)
|
||||
end
|
||||
|
||||
def self.remove_card_dict(sketchup_model, data)
|
||||
@@ -101,7 +85,7 @@ module SpeckleConnector3
|
||||
dict_to_write = dict_to_write.attribute_dictionary(dict_name, true)
|
||||
dict_to_write = dict_to_write.attribute_dictionary(var_name, true)
|
||||
value.each do |key, hash_value|
|
||||
serialize_obj_to_dict(key.to_s, hash_value, dict_to_write)
|
||||
hash_to_dict(key.to_s, hash_value, dict_to_write)
|
||||
end
|
||||
else
|
||||
dict_to_write.set_attribute(dict_name, var_name, value)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../../constants/type_constants'
|
||||
|
||||
module SpeckleConnector3
|
||||
module SpeckleObjects
|
||||
class DataObject < Base
|
||||
SPECKLE_TYPE = SPECKLE_OBJECT_DATA_OBJECT
|
||||
|
||||
def self.to_native(state, data_object, layer, _entities, &convert_to_native)
|
||||
properties = data_object['properties']
|
||||
return state
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../../constants/type_constants'
|
||||
require_relative '../other/display_value'
|
||||
require_relative '../../sketchup_model/dictionary/base_dictionary_handler'
|
||||
|
||||
module SpeckleConnector3
|
||||
module SpeckleObjects
|
||||
class RevitDataObject < Base
|
||||
SPECKLE_TYPE = SPECKLE_OBJECT_DATA_OBJECT_REVIT
|
||||
|
||||
def self.to_native(state, revit_data_object, layer, entities, &convert_to_native)
|
||||
properties = revit_data_object['properties']
|
||||
|
||||
new_state, instance_and_definition = SpeckleObjects::Other::DisplayValue.to_native(state, revit_data_object, layer, entities, &convert_to_native)
|
||||
instance, _definition = instance_and_definition
|
||||
attr = instance.attribute_dictionary('Speckle', true)
|
||||
|
||||
SketchupModel::Dictionary::BaseDictionaryHandler.hash_to_dict('Revit Parameters', properties, attr) if properties
|
||||
return new_state, instance_and_definition
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user