Compare commits
90 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 97309ebb88 | |||
| 556ddc0b6f | |||
| a0dde690ea | |||
| a76dab5be6 | |||
| 2d10bc5bbf | |||
| 4042632e0b | |||
| 7ccf83e1a4 | |||
| 019cd0756f | |||
| 0e5f9f80be | |||
| fc6767860a | |||
| 5b5b4be7b2 | |||
| 45351d082e | |||
| 22ccd07491 | |||
| 2cf9ee647b | |||
| efb567824b | |||
| f0aac39486 | |||
| f278055805 | |||
| 6f2e36fd11 | |||
| 119d80ffc8 | |||
| 771c3df864 | |||
| 7d1963e458 | |||
| dde85972b3 | |||
| 5e061da910 | |||
| 46bea345de | |||
| bc53462ad6 | |||
| 884df40a1d | |||
| b23168c067 | |||
| 5568212f15 | |||
| 79db79d799 | |||
| 18a4008efd | |||
| 83e4abd1ee | |||
| 243bcfba72 | |||
| af2c8c560f | |||
| 6a37f3871c | |||
| 759a388448 | |||
| 360e89d7ce | |||
| 64655a3284 | |||
| c58356bde8 | |||
| f74117632d | |||
| 5f2b8b8e2b | |||
| f0ce7481fd | |||
| 6e7a5c6140 | |||
| 079c18ee19 | |||
| 26ef6a3815 | |||
| cf6dcefe6c | |||
| 35590eb979 | |||
| 583a8b8a76 | |||
| c6e8a664de | |||
| 24a5e0a579 | |||
| a242c197fb | |||
| 08bdd23149 | |||
| c5b35b2d98 | |||
| 5407fecd1f | |||
| 12d2821d26 | |||
| 2e6d58e6a3 | |||
| 0f0c0fd5ae | |||
| ef9ec1c223 | |||
| f4387bae30 | |||
| 49b238a23a | |||
| 4b75c01b28 | |||
| e7f641046b | |||
| 9aaabe0fab | |||
| b6e4b711bf | |||
| 58fcfd210b | |||
| 5868b9c234 | |||
| 0dc6d9cf9d | |||
| 67f50cf2fd | |||
| 8b26a4d49a | |||
| a1d0bb0aa1 | |||
| bfe08560b1 | |||
| ac3ac24272 | |||
| 03e7191d0e | |||
| b3a42f8723 | |||
| 9c4b740300 | |||
| 2a12bdadf2 | |||
| c90e8ad4d2 | |||
| 4a52c51c86 | |||
| 0efc817ddc | |||
| fee54fc98c | |||
| 210f751396 | |||
| 2e2bc3fe29 | |||
| a6f05f86d1 | |||
| fc144e4848 | |||
| cef9531428 | |||
| abd4faefbf | |||
| 966f7aaed5 | |||
| 51b59fa995 | |||
| 0b713736bd | |||
| 9e33581c66 | |||
| b97792b596 |
+116
-2
@@ -76,6 +76,99 @@ jobs:
|
||||
paths:
|
||||
- speckle-sharp-ci-tools/Installers
|
||||
|
||||
build-connector-mac:
|
||||
macos:
|
||||
xcode: 12.5.1
|
||||
parameters:
|
||||
projname:
|
||||
type: string
|
||||
default: ""
|
||||
slug:
|
||||
type: string
|
||||
default: ""
|
||||
installer:
|
||||
type: boolean
|
||||
default: false
|
||||
converter-files:
|
||||
type: string
|
||||
default: ""
|
||||
installername:
|
||||
type: string
|
||||
default: ""
|
||||
build-config:
|
||||
type: string
|
||||
default: Release
|
||||
bundlename:
|
||||
type: string
|
||||
default: ""
|
||||
steps:
|
||||
- checkout
|
||||
- attach_workspace:
|
||||
at: ./
|
||||
- run:
|
||||
name: Install dotnet
|
||||
command: |
|
||||
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel Current
|
||||
|
||||
$HOME/.dotnet/dotnet --version
|
||||
$HOME/.dotnet/dotnet --list-runtimes
|
||||
$HOME/.dotnet/dotnet --list-sdks
|
||||
- run:
|
||||
name: Create installer target dir
|
||||
command: |
|
||||
mkdir -p speckle-sharp-ci-tools/Installers/<< parameters.slug >>
|
||||
- run:
|
||||
name: Set Environment Variable
|
||||
command: |
|
||||
TAG=$(if [ "${CIRCLE_TAG}" ]; then echo $CIRCLE_TAG; else echo "2.0.999"; fi;)
|
||||
SEMVER=$(echo "$TAG" | sed -e 's/\/[a-zA-Z-]*//')
|
||||
VER=$(echo "$SEMVER" | sed -e 's/-.*//')
|
||||
VERSION=$(echo $VER.$WORKFLOW_NUM)
|
||||
python3 patch_version.py $SEMVER
|
||||
environment:
|
||||
WORKFLOW_NUM: << pipeline.number >>
|
||||
- run:
|
||||
name: Zip Connector files
|
||||
command: |
|
||||
zip -r << parameters.slug >>-mac.zip "./speckle_connector" "./speckle_connector.rb"
|
||||
# Copy installer files
|
||||
- run:
|
||||
name: Copy files to installer
|
||||
command: |
|
||||
mkdir -p speckle-sharp-ci-tools/Mac/<< parameters.installername >>/.installationFiles/
|
||||
cp << parameters.slug >>-mac.zip speckle-sharp-ci-tools/Mac/<<parameters.installername>>/.installationFiles
|
||||
# Create installer
|
||||
- run:
|
||||
name: Exit if External PR
|
||||
command: if [ "$CIRCLE_PR_REPONAME" ]; then circleci-agent step halt; fi
|
||||
- run:
|
||||
name: Build Mac installer
|
||||
command: ~/.dotnet/dotnet publish speckle-sharp-ci-tools/Mac/<<parameters.installername>>/<<parameters.installername>>.sln -r osx-x64 -c Release
|
||||
- run:
|
||||
name: Zip installer
|
||||
command: |
|
||||
cd speckle-sharp-ci-tools/Mac/<<parameters.installername>>/bin/Release/net6.0/osx-x64/publish/
|
||||
zip -r <<parameters.slug>>.zip ./
|
||||
- store_artifacts:
|
||||
path: speckle-sharp-ci-tools/Mac/<<parameters.installername>>/bin/Release/net6.0/osx-x64/publish/<<parameters.slug>>.zip
|
||||
- run:
|
||||
name: Copy to installer location
|
||||
command: |
|
||||
TAG=$(if [ "${CIRCLE_TAG}" ]; then echo $CIRCLE_TAG; else echo "2.0.999"; fi;)
|
||||
SEMVER=$(echo "$TAG" | sed -e 's/\/[a-zA-Z-]*//')
|
||||
VER=$(echo "$SEMVER" | sed -e 's/-.*//')
|
||||
VERSION=$(echo $VER.$WORKFLOW_NUM)
|
||||
cp speckle-sharp-ci-tools/Mac/<<parameters.installername>>/bin/Release/net6.0/osx-x64/publish/<<parameters.slug>>.zip speckle-sharp-ci-tools/Installers/<< parameters.slug >>/<<parameters.slug>>-$SEMVER.zip
|
||||
environment:
|
||||
WORKFLOW_NUM: << pipeline.number >>
|
||||
- when:
|
||||
condition: << pipeline.git.tag >>
|
||||
steps:
|
||||
- persist_to_workspace:
|
||||
root: ./
|
||||
paths:
|
||||
- speckle-sharp-ci-tools/Installers
|
||||
|
||||
get-ci-tools: # Clones our ci tools and persists them to the workspace
|
||||
docker:
|
||||
- image: cimg/base:2021.01
|
||||
@@ -99,6 +192,7 @@ jobs:
|
||||
root: ./
|
||||
paths:
|
||||
- speckle-sharp-ci-tools
|
||||
|
||||
deploy-manager2:
|
||||
docker:
|
||||
- image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
@@ -146,17 +240,37 @@ workflows:
|
||||
only: /.*/
|
||||
context: innosetup
|
||||
|
||||
- build-connector-mac:
|
||||
slug: sketchup
|
||||
requires:
|
||||
- get-ci-tools
|
||||
- build-ui
|
||||
filters:
|
||||
tags:
|
||||
only: /.*/
|
||||
installername: SpeckleSketchUpInstall
|
||||
|
||||
- deploy-manager2:
|
||||
context: do-spaces-speckle-releases
|
||||
slug: sketchup
|
||||
os: Win
|
||||
extension: exe
|
||||
requires:
|
||||
- get-ci-tools
|
||||
- build-ui
|
||||
- build-connector
|
||||
filters:
|
||||
tags:
|
||||
only: /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
branches:
|
||||
ignore: /.*/ # For testing only! /ci\/.*/
|
||||
- deploy-manager2:
|
||||
context: do-spaces-speckle-releases
|
||||
slug: sketchup
|
||||
os: OSX
|
||||
extension: zip
|
||||
requires:
|
||||
- build-connector-mac
|
||||
filters:
|
||||
tags:
|
||||
only: /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
|
||||
branches:
|
||||
ignore: /.*/ # For testing only! /ci\/.*/
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
require 'sketchup'
|
||||
require 'pathname'
|
||||
require 'speckle_connector/debug'
|
||||
require_relative 'src/log/log'
|
||||
require_relative 'src/ui/sketchup_ui'
|
||||
require_relative 'src/ui/ui_controller'
|
||||
require_relative 'src/commands/menu_command_handler'
|
||||
|
||||
@@ -9,12 +9,16 @@ module SpeckleConnector
|
||||
module Actions
|
||||
# Apply mappings for selected entities.
|
||||
class ApplyMappings < Action
|
||||
def initialize(entities_to_map, method, category, name, is_definition)
|
||||
def initialize(entities_to_map, method, category, family,
|
||||
family_type, level, name, is_definition)
|
||||
super()
|
||||
@entities_to_map = entities_to_map
|
||||
@method = method
|
||||
@category = category
|
||||
@name = name
|
||||
@family = family
|
||||
@family_type = family_type
|
||||
@level = level
|
||||
@is_definition = is_definition
|
||||
end
|
||||
|
||||
@@ -51,6 +55,9 @@ module SpeckleConnector
|
||||
SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.set_attribute(entity, :category, @category)
|
||||
SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.set_attribute(entity, :name, name)
|
||||
SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.set_attribute(entity, :method, @method)
|
||||
SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.set_attribute(entity, :family, @family)
|
||||
SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.set_attribute(entity, :family_type, @family_type)
|
||||
SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.set_attribute(entity, :level, @level)
|
||||
speckle_state = speckle_state.with_mapped_entity(entity)
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'action'
|
||||
require_relative '../sketchup_model/dictionary/speckle_entity_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
module Actions
|
||||
# Clear mapper source.
|
||||
class ClearMapperSource < Action
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
# @return [States::State] the new updated state object
|
||||
def self.update_state(state, _data)
|
||||
new_speckle_state = state.speckle_state.with_removed_mapper_source
|
||||
erase_levels(state)
|
||||
state.with_speckle_state(new_speckle_state)
|
||||
end
|
||||
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
def self.erase_levels(state)
|
||||
levels = state.sketchup_state.sketchup_model.definitions.select do |definition|
|
||||
SketchupModel::Dictionary::SpeckleEntityDictionaryHandler.get_attribute(definition, :speckle_type) ==
|
||||
OBJECTS_BUILTELEMENTS_REVIT_LEVEL
|
||||
end
|
||||
levels.each do |level|
|
||||
level.entities.clear!
|
||||
level.instances.each(&:erase!)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,31 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'event_action'
|
||||
require_relative '../../mapping/category/revit_category'
|
||||
require_relative '../mapper_selection_changed'
|
||||
require_relative '../../mapper/category/revit_category'
|
||||
require_relative '../../sketchup_model/reader/speckle_entities_reader'
|
||||
require_relative '../../sketchup_model/reader/mapper_reader'
|
||||
require_relative '../../sketchup_model/query/entity'
|
||||
|
||||
module SpeckleConnector
|
||||
module Actions
|
||||
module Events
|
||||
# Update selected speckle objects when the selection changes for mapping tool.
|
||||
# Update selected speckle objects when the selection changes for mapper tool.
|
||||
class SelectionEventAction < EventAction
|
||||
# @param state [States::State] the current state of Speckle application.
|
||||
# @return [States::State] the new updated state object
|
||||
def self.update_state(state, event_data)
|
||||
return state unless event_data&.any?
|
||||
|
||||
# Get sketchup selection
|
||||
sketchup_selection = state.sketchup_state.sketchup_model.selection
|
||||
selection = {
|
||||
selection: SketchupModel::Reader::SpeckleEntitiesReader.entities_schema_details(sketchup_selection),
|
||||
mappingMethods: [
|
||||
'Direct Shape'
|
||||
],
|
||||
categories: Mapping::Category::RevitCategory.to_a
|
||||
}
|
||||
selection = { selection: [], mappingMethods: [], categories: [] } if sketchup_selection.none?
|
||||
|
||||
state.with_selection_queue(selection)
|
||||
# Collect and return mapper selection info.
|
||||
# Later we can add more selection info for different scopes.
|
||||
MapperSelectionChanged.new(sketchup_selection).update_state(state)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
require_relative 'action'
|
||||
require_relative 'initialize_materials'
|
||||
require_relative '../sketchup_model/reader/speckle_entities_reader'
|
||||
require_relative '../sketchup_model/reader/mapper_reader'
|
||||
require_relative '../preferences/preferences'
|
||||
require_relative '../states/state'
|
||||
require_relative '../states/sketchup_state'
|
||||
@@ -29,7 +30,7 @@ module SpeckleConnector
|
||||
new_speckle_entities = SketchupModel::Reader::SpeckleEntitiesReader.read(sketchup_model.entities)
|
||||
new_speckle_state = new_state.speckle_state.with_speckle_entities(Immutable::Hash.new(new_speckle_entities))
|
||||
# Read mapped entities
|
||||
new_mapped_entities = SketchupModel::Reader::SpeckleEntitiesReader.read_mapped_entities(sketchup_model.entities)
|
||||
new_mapped_entities = SketchupModel::Reader::MapperReader.read_mapped_entities(sketchup_model.entities)
|
||||
new_speckle_state = new_speckle_state.with_mapped_entities(Immutable::Hash.new(new_mapped_entities))
|
||||
new_state = new_state.with_speckle_state(new_speckle_state)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'action'
|
||||
require_relative '../sketchup_model/reader/speckle_entities_reader'
|
||||
require_relative '../sketchup_model/reader/mapper_reader'
|
||||
|
||||
module SpeckleConnector
|
||||
module Actions
|
||||
@@ -10,8 +10,8 @@ module SpeckleConnector
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
# @return [States::State] the new updated state object
|
||||
def self.update_state(state, _data = nil)
|
||||
mapped_entities = SketchupModel::Reader::SpeckleEntitiesReader
|
||||
.mapped_entity_details(state.speckle_state.mapped_entities.values.to_a)
|
||||
mapped_entities = SketchupModel::Reader::MapperReader
|
||||
.mapped_entity_details(state.speckle_state.speckle_mapper_state.mapped_entities.values.to_a)
|
||||
|
||||
state.with_mapped_entities_queue(mapped_entities)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'action'
|
||||
require_relative '../mapper/category/revit_category'
|
||||
require_relative '../sketchup_model/reader/mapper_reader'
|
||||
require_relative '../sketchup_model/reader/speckle_entities_reader'
|
||||
require_relative '../sketchup_model/dictionary/speckle_entity_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
module Actions
|
||||
# Collects mapper selection info.
|
||||
class MapperSelectionChanged < Action
|
||||
READER = SketchupModel::Reader
|
||||
DICTIONARY = SketchupModel::Dictionary
|
||||
|
||||
def initialize(selection)
|
||||
super()
|
||||
@selection = selection
|
||||
end
|
||||
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
# @return [States::State] the new updated state object
|
||||
def update_state(state)
|
||||
# Get mapping info from selection.
|
||||
mapping = get_mapping_info(state, @selection)
|
||||
|
||||
state.with_mapper_selection_queue(mapping)
|
||||
end
|
||||
|
||||
def filter_out_levels(selection)
|
||||
selection.reject do |e|
|
||||
DICTIONARY::SpeckleEntityDictionaryHandler
|
||||
.get_attribute(e, :speckle_type) == OBJECTS_BUILTELEMENTS_REVIT_LEVEL
|
||||
end
|
||||
end
|
||||
|
||||
def get_mapping_info(state, selection)
|
||||
selection = filter_out_levels(selection)
|
||||
grouped_by_type = group_by_type(selection)
|
||||
|
||||
supported_entity_count = grouped_by_type.length
|
||||
|
||||
# Return empty method list if there is no supported entity to map.
|
||||
return EMPTY_SELECTION if supported_entity_count == 0
|
||||
|
||||
# Return Direct Shape itself if multiple kinds of element are selected like Edge and Face.
|
||||
# OR single type is equal to only direct shape supports.
|
||||
if supported_entity_count > 1 ||
|
||||
(supported_entity_count == 1 &&
|
||||
MAPPER_DIRECT_SHAPE_SUPPORTED_ENTITY_TYPES.include?(grouped_by_type.keys.first))
|
||||
return direct_shape_selection_info(selection)
|
||||
end
|
||||
|
||||
# Only single type selections remained after this point.
|
||||
return face_selection_info(state, grouped_by_type.values.first) if grouped_by_type.keys.first == Sketchup::Face
|
||||
|
||||
return edge_selection_info(state, grouped_by_type.values.first) if grouped_by_type.keys.first == Sketchup::Edge
|
||||
|
||||
EMPTY_SELECTION
|
||||
end
|
||||
|
||||
MAPPER_SUPPORTED_ENTITY_TYPES = [
|
||||
Sketchup::ComponentInstance,
|
||||
Sketchup::Group,
|
||||
Sketchup::Face,
|
||||
Sketchup::Edge
|
||||
].freeze
|
||||
|
||||
MAPPER_DIRECT_SHAPE_SUPPORTED_ENTITY_TYPES = [
|
||||
Sketchup::ComponentInstance,
|
||||
Sketchup::Group
|
||||
].freeze
|
||||
|
||||
EMPTY_SELECTION = {
|
||||
selection: [],
|
||||
mappingMethods: [],
|
||||
categories: []
|
||||
}.freeze
|
||||
|
||||
def direct_shape_selection_info(selection)
|
||||
{
|
||||
selection: SketchupModel::Reader::MapperReader.entities_schema_details(selection),
|
||||
mappingMethods: ['Direct Shape'],
|
||||
categories: Mapper::Category::RevitCategory.to_a
|
||||
}.freeze
|
||||
end
|
||||
|
||||
def direct_shape_selection_info_with_default(selection, methods)
|
||||
{
|
||||
selection: SketchupModel::Reader::MapperReader.entities_schema_details(selection),
|
||||
mappingMethods: ['Direct Shape'] + methods,
|
||||
categories: Mapper::Category::RevitCategory.to_a
|
||||
}.freeze
|
||||
end
|
||||
|
||||
def direct_shape_selection_info_with_source(state, filtered_selection, methods)
|
||||
types = state.speckle_state.speckle_mapper_state.mapper_source.types
|
||||
levels = state.speckle_state.speckle_mapper_state.mapper_source.levels
|
||||
instances = @selection.grep(Sketchup::ComponentInstance)
|
||||
selected_level = instances.find do |i|
|
||||
DICTIONARY::SpeckleEntityDictionaryHandler
|
||||
.get_attribute(i, :speckle_type) == OBJECTS_BUILTELEMENTS_REVIT_LEVEL
|
||||
end
|
||||
selected_level_name = nil
|
||||
if selected_level
|
||||
selected_level_name = DICTIONARY::SpeckleEntityDictionaryHandler.get_attribute(selected_level, :name)
|
||||
end
|
||||
{
|
||||
selection: READER::MapperReader.entities_schema_details(filtered_selection),
|
||||
mappingMethods: ['Direct Shape'] + methods,
|
||||
categories: Mapper::Category::RevitCategory.to_a,
|
||||
types: types,
|
||||
levels: levels,
|
||||
selectedLevelName: selected_level_name
|
||||
}.freeze
|
||||
end
|
||||
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
def face_selection_info(state, faces)
|
||||
source_exist = !state.speckle_state.speckle_mapper_state.mapper_source.nil?
|
||||
grouped_by_verticality = faces.group_by { |face| face.normal.perpendicular?(VECTOR_Z) }
|
||||
return direct_shape_selection_info(faces) if grouped_by_verticality.length == 2
|
||||
|
||||
if source_exist
|
||||
if grouped_by_verticality.keys.first
|
||||
direct_shape_selection_info_with_source(state, faces, ['Wall'])
|
||||
else
|
||||
direct_shape_selection_info_with_source(state, faces, ['Floor'])
|
||||
end
|
||||
else
|
||||
if grouped_by_verticality.keys.first
|
||||
direct_shape_selection_info_with_default(faces, ['Default Wall'])
|
||||
else
|
||||
direct_shape_selection_info_with_default(faces, ['Default Floor'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edge_selection_info(state, edges)
|
||||
source_exist = !state.speckle_state.speckle_mapper_state.mapper_source.nil?
|
||||
|
||||
if source_exist
|
||||
methods = ['Column', 'Beam', 'Pipe', 'Duct']
|
||||
direct_shape_selection_info_with_source(state, edges, methods)
|
||||
else
|
||||
default_methods = ['Default Column', 'Default Beam', 'Default Pipe', 'Default Duct']
|
||||
direct_shape_selection_info_with_default(edges, default_methods)
|
||||
end
|
||||
end
|
||||
|
||||
def group_by_type_old(selection)
|
||||
selection.group_by(&:class).filter_map do |group|
|
||||
[group.first, group] if MAPPER_SUPPORTED_ENTITY_TYPES.include?(group.first)
|
||||
end.to_h
|
||||
end
|
||||
|
||||
def group_by_type(selection)
|
||||
selection.select { |s| MAPPER_SUPPORTED_ENTITY_TYPES.include?(s.class) }.group_by(&:class)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'action'
|
||||
require_relative '../mapper/mapper_source'
|
||||
require_relative '../speckle_objects/built_elements/revit/revit_element_type'
|
||||
|
||||
module SpeckleConnector
|
||||
module Actions
|
||||
# Action to update mapper source.
|
||||
class MapperSourceUpdated < Action
|
||||
def initialize(base, stream_id, commit_id)
|
||||
super()
|
||||
@base = base
|
||||
@stream_id = stream_id
|
||||
@commit_id = commit_id
|
||||
end
|
||||
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
# @return [States::State] the new updated state object
|
||||
def update_state(state)
|
||||
levels = convert_levels(state, @base['@Levels'])
|
||||
types = convert_types(@base['@Types'])
|
||||
mapper_source = Mapper::MapperSource.new(@stream_id, @commit_id, levels, types)
|
||||
new_speckle_state = state.speckle_state.with_mapper_source(mapper_source)
|
||||
state = state.with_speckle_state(new_speckle_state)
|
||||
|
||||
state.with_add_queue('mapperSourceUpdated', @stream_id, [
|
||||
{ is_string: false, val: levels.to_json },
|
||||
{ is_string: false, val: types.to_json }
|
||||
])
|
||||
end
|
||||
|
||||
def convert_types(types)
|
||||
types.collect do |type, type_elements|
|
||||
next if type_elements.nil? || !type_elements.is_a?(Array) || type == '__closure'
|
||||
|
||||
type = type[1..-1] if type[0] == '@'
|
||||
elements = type_elements.map do |type_element|
|
||||
SpeckleObjects::BuiltElements::Revit::RevitElementType.to_native(type_element)
|
||||
end
|
||||
elements = elements.group_by { |e| e[:family] }
|
||||
[type, elements]
|
||||
end.compact.to_h
|
||||
end
|
||||
|
||||
def convert_levels(state, levels)
|
||||
levels.collect do |level|
|
||||
SpeckleObjects::BuiltElements::Level.to_native(state, level, @stream_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,9 +11,13 @@ module SpeckleConnector
|
||||
entities_to_map = data['entitiesToMap']
|
||||
method = data['method']
|
||||
category = data['category']
|
||||
family = data['family']
|
||||
family_type = data['familyType']
|
||||
level = data['level']
|
||||
name = data['name']
|
||||
is_definition = data['isDefinition']
|
||||
action = Actions::ApplyMappings.new(entities_to_map, method, category, name, is_definition)
|
||||
action = Actions::ApplyMappings.new(entities_to_map, method, category, family,
|
||||
family_type, level, name, is_definition)
|
||||
app.update_state!(action)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'command'
|
||||
require_relative '../actions/mapper_source_updated'
|
||||
|
||||
module SpeckleConnector
|
||||
module Commands
|
||||
# Command to update mapper source.
|
||||
class MapperSourceUpdated < Command
|
||||
def _run(data)
|
||||
base = data['base']
|
||||
stream_id = data['stream_id']
|
||||
commit_id = data['commit_id']
|
||||
action = Actions::MapperSourceUpdated.new(base, stream_id, commit_id)
|
||||
app.update_state!(action)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module SpeckleConnector
|
||||
VECTOR_Z = Geom::Vector3d.new(0, 0, 1)
|
||||
end
|
||||
@@ -14,7 +14,7 @@ module SpeckleConnector
|
||||
path = ENV.fetch('APPDATA')
|
||||
Pathname.new(File.join(path, 'Speckle')).cleanpath.to_s
|
||||
when OS_MAC
|
||||
File.join(Dir.home, 'Library/Application Support/Speckle')
|
||||
File.join(Dir.home, '.config/Speckle')
|
||||
else
|
||||
raise 'Speckle could not determine your Appdata path'
|
||||
end
|
||||
|
||||
@@ -7,11 +7,20 @@ module SpeckleConnector
|
||||
|
||||
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'
|
||||
OBJECTS_BUILTELEMENTS_DEFAULT_FLOOR = 'Objects.BuiltElements.Floor'
|
||||
OBJECTS_BUILTELEMENTS_REVIT_FLOOR = 'Objects.BuiltElements.Floor:Objects.BuiltElements.Revit.RevitFloor'
|
||||
OBJECTS_BUILTELEMENTS_DEFAULT_WALL = 'Objects.BuiltElements.Wall'
|
||||
OBJECTS_BUILTELEMENTS_REVIT_WALL = 'Objects.BuiltElements.Wall:Objects.BuiltElements.Revit.RevitWall'
|
||||
OBJECTS_BUILTELEMENTS_REVIT_DIRECTSHAPE = 'Objects.BuiltElements.Revit.DirectShape'
|
||||
OBJECTS_BUILTELEMENTS_REVIT_PARAMETER = 'Objects.BuiltElements.Revit.Parameter'
|
||||
OBJECTS_BUILTELEMENTS_REVIT_REVITELEMENTTYPE = 'Objects.BuiltElements.Revit.RevitElementType'
|
||||
|
||||
OBJECTS_GEOMETRY_LINE = 'Objects.Geometry.Line'
|
||||
OBJECTS_GEOMETRY_POLYLINE = 'Objects.Geometry.Polyline'
|
||||
OBJECTS_GEOMETRY_POLYCURVE = 'Objects.Geometry.Polycurve'
|
||||
OBJECTS_GEOMETRY_ARC = 'Objects.Geometry.Arc'
|
||||
OBJECTS_GEOMETRY_CIRCLE = 'Objects.Geometry.Circle'
|
||||
OBJECTS_GEOMETRY_MESH = 'Objects.Geometry.Mesh'
|
||||
OBJECTS_GEOMETRY_BREP = 'Objects.Geometry.Brep'
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ module SpeckleConnector
|
||||
faces.each { |face| face.edges.each { |edge| edges << edge } }
|
||||
edges.uniq!
|
||||
edges.each { |edge| remove_edge_have_coplanar_faces(edge, faces, false) }
|
||||
# Remove remaining orphan edges
|
||||
edges.reject(&:deleted?).select { |edge| edge.faces.empty? }.each(&:erase!)
|
||||
merged_faces(faces)
|
||||
end
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
require_relative 'converter'
|
||||
require_relative '../constants/type_constants'
|
||||
require_relative '../speckle_entities/speckle_entity'
|
||||
require_relative '../speckle_objects/gis/polygon_element'
|
||||
require_relative '../speckle_objects/other/transform'
|
||||
require_relative '../speckle_objects/other/render_material'
|
||||
@@ -11,6 +12,9 @@ require_relative '../speckle_objects/other/display_value'
|
||||
require_relative '../speckle_objects/revit/revit_instance'
|
||||
require_relative '../speckle_objects/geometry/point'
|
||||
require_relative '../speckle_objects/geometry/line'
|
||||
require_relative '../speckle_objects/geometry/polycurve'
|
||||
require_relative '../speckle_objects/geometry/arc'
|
||||
require_relative '../speckle_objects/geometry/circle'
|
||||
require_relative '../speckle_objects/geometry/mesh'
|
||||
require_relative '../speckle_objects/built_elements/view3d'
|
||||
require_relative '../speckle_objects/built_elements/network'
|
||||
@@ -45,10 +49,14 @@ module SpeckleConnector
|
||||
# Class aliases
|
||||
POINT = GEOMETRY::Point
|
||||
LINE = GEOMETRY::Line
|
||||
POLYCURVE = GEOMETRY::Polycurve
|
||||
ARC = GEOMETRY::Arc
|
||||
CIRCLE = GEOMETRY::Circle
|
||||
MESH = GEOMETRY::Mesh
|
||||
BLOCK_DEFINITION = OTHER::BlockDefinition
|
||||
BLOCK_INSTANCE = OTHER::BlockInstance
|
||||
REVIT_INSTANCE = REVIT::Other::RevitInstance
|
||||
REVIT_WALL = BUILTELEMENTS::RevitWall
|
||||
RENDER_MATERIAL = OTHER::RenderMaterial
|
||||
DISPLAY_VALUE = OTHER::DisplayValue
|
||||
VIEW3D = BUILTELEMENTS::View3d
|
||||
@@ -59,6 +67,9 @@ module SpeckleConnector
|
||||
CONVERTABLE_SPECKLE_TYPES = %w[
|
||||
Objects.Geometry.Line
|
||||
Objects.Geometry.Polyline
|
||||
Objects.Geometry.Polycurve
|
||||
Objects.Geometry.Arc
|
||||
Objects.Geometry.Circle
|
||||
Objects.Geometry.Mesh
|
||||
Objects.Geometry.Brep
|
||||
Objects.Other.BlockInstance
|
||||
@@ -67,6 +78,7 @@ module SpeckleConnector
|
||||
Objects.Other.RenderMaterial
|
||||
Objects.Other.Instance:Objects.Other.BlockInstance
|
||||
Objects.BuiltElements.View:Objects.BuiltElements.View3D
|
||||
Objects.BuiltElements.Wall:Objects.BuiltElements.Revit.RevitWall
|
||||
Objects.BuiltElements.Network
|
||||
Objects.GIS.PolygonElement
|
||||
Speckle.Core.Models.Collection
|
||||
@@ -76,6 +88,10 @@ module SpeckleConnector
|
||||
@from_revit ||= source_app.include?('revit')
|
||||
end
|
||||
|
||||
def from_rhino
|
||||
@from_rhino ||= source_app.include?('rhino')
|
||||
end
|
||||
|
||||
def from_sketchup
|
||||
@from_sketchup ||= source_app.include?('sketchup')
|
||||
end
|
||||
@@ -89,14 +105,9 @@ module SpeckleConnector
|
||||
# UI is responsible currently to fetch objects from ObjectLoader module by calling getAndConstruct method.
|
||||
# @param obj [Object] speckle commit object.
|
||||
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']
|
||||
|
||||
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
|
||||
SpeckleObjects::Relations::Layers.to_native(obj, source_app, sketchup_model)
|
||||
end
|
||||
|
||||
# By default entities to fill is sketchup model's entities.
|
||||
@@ -242,7 +253,7 @@ module SpeckleConnector
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
def traverse_commit_object(obj, layer, entities)
|
||||
if convertible_to_native?(obj)
|
||||
@state = convert_to_native(@state, obj, layer, entities)
|
||||
@state, _converted_entities = convert_to_native(@state, obj, layer, entities)
|
||||
elsif obj.is_a?(Hash) && obj.key?('speckle_type')
|
||||
return if ignored_speckle_type?(obj)
|
||||
|
||||
@@ -254,7 +265,7 @@ module SpeckleConnector
|
||||
end
|
||||
else
|
||||
# puts(">>> Found #{obj['speckle_type']}: #{obj['id']} with displayValue.")
|
||||
@state = convert_to_native(@state, obj, layer, entities)
|
||||
@state, _converted_entities = convert_to_native(@state, obj, layer, entities)
|
||||
end
|
||||
elsif obj.is_a?(Hash)
|
||||
obj.each_value { |value| traverse_commit_object(value, layer, entities) }
|
||||
@@ -266,7 +277,7 @@ module SpeckleConnector
|
||||
# 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
|
||||
@@ -274,6 +285,9 @@ module SpeckleConnector
|
||||
SPECKLE_OBJECT_TO_NATIVE = {
|
||||
OBJECTS_GEOMETRY_LINE => LINE.method(:to_native),
|
||||
OBJECTS_GEOMETRY_POLYLINE => LINE.method(:to_native),
|
||||
OBJECTS_GEOMETRY_POLYCURVE => POLYCURVE.method(:to_native),
|
||||
OBJECTS_GEOMETRY_ARC => ARC.method(:to_native),
|
||||
OBJECTS_GEOMETRY_CIRCLE => CIRCLE.method(:to_native),
|
||||
OBJECTS_GEOMETRY_MESH => MESH.method(:to_native),
|
||||
OBJECTS_GEOMETRY_BREP => MESH.method(:to_native),
|
||||
OBJECTS_OTHER_BLOCKDEFINITION => BLOCK_DEFINITION.method(:to_native),
|
||||
@@ -282,6 +296,7 @@ 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_BUILTELEMENTS_REVIT_WALL => REVIT_WALL.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),
|
||||
@@ -304,11 +319,11 @@ module SpeckleConnector
|
||||
create_layers_from_categories(state, obj, converted_entities)
|
||||
end
|
||||
# Create speckle entities from sketchup entities to achieve continuous traversal.
|
||||
convert_to_speckle_entities(state, obj, converted_entities)
|
||||
SpeckleEntities::SpeckleEntity.from_speckle_object(state, obj, converted_entities, stream_id)
|
||||
rescue StandardError => e
|
||||
puts("Failed to convert #{obj['speckle_type']} (id: #{obj['id']})")
|
||||
puts(e)
|
||||
return state
|
||||
return state, []
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
@@ -353,30 +368,9 @@ module SpeckleConnector
|
||||
end
|
||||
|
||||
# @param state [States::State] state of the application
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def convert_to_speckle_entities(state, speckle_object, entities)
|
||||
return state if entities.empty?
|
||||
|
||||
speckle_id = speckle_object['id']
|
||||
application_id = speckle_object['applicationId']
|
||||
speckle_type = speckle_object['speckle_type']
|
||||
children = speckle_object['__closure'].nil? ? [] : speckle_object['__closure']
|
||||
speckle_state = state.speckle_state
|
||||
entities.each do |entity|
|
||||
next if entity.is_a?(Sketchup::Material) || entity.is_a?(Sketchup::Page)
|
||||
next if (entity.is_a?(Sketchup::Face) || entity.is_a?(Sketchup::Edge)) &&
|
||||
!state.user_state.user_preferences[:register_speckle_entity]
|
||||
|
||||
ent = SpeckleEntities::SpeckleEntity.new(entity, speckle_id, application_id, speckle_type, children,
|
||||
[stream_id])
|
||||
ent.write_initial_base_data
|
||||
speckle_state = speckle_state.with_speckle_entity(ent)
|
||||
end
|
||||
state.with_speckle_state(speckle_state)
|
||||
def convert_to_speckle_entities(state, speckle_objects_with_entities)
|
||||
return state if speckle_objects_with_entities.empty?
|
||||
end
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
end
|
||||
# rubocop:enable Metrics/ClassLength
|
||||
end
|
||||
|
||||
@@ -15,6 +15,7 @@ require_relative '../speckle_objects/relations/layers'
|
||||
require_relative '../speckle_objects/speckle/core/models/model_collection'
|
||||
require_relative '../constants/path_constants'
|
||||
require_relative '../sketchup_model/reader/speckle_entities_reader'
|
||||
require_relative '../sketchup_model/reader/mapper_reader'
|
||||
require_relative '../sketchup_model/query/entity'
|
||||
|
||||
module SpeckleConnector
|
||||
@@ -63,7 +64,7 @@ module SpeckleConnector
|
||||
def convert(entity, preferences, speckle_state, parent = :base)
|
||||
convert = method(:convert)
|
||||
|
||||
unless SketchupModel::Reader::SpeckleEntitiesReader.mapped_with_schema?(entity)
|
||||
unless SketchupModel::Reader::MapperReader.mapped_with_schema?(entity)
|
||||
return from_native_to_speckle(entity, preferences, speckle_state, parent, &convert)
|
||||
end
|
||||
|
||||
@@ -72,7 +73,7 @@ module SpeckleConnector
|
||||
|
||||
def from_mapped_to_speckle(entity, path, preferences)
|
||||
direct_shape = SpeckleObjects::BuiltElements::Revit::DirectShape
|
||||
.from_entity(entity, path, @units, preferences)
|
||||
.from_entity(speckle_state, entity, path, @units, preferences)
|
||||
return [direct_shape, [entity]]
|
||||
end
|
||||
|
||||
@@ -84,7 +85,7 @@ module SpeckleConnector
|
||||
end
|
||||
|
||||
if entity.is_a?(Sketchup::Face)
|
||||
mesh = SpeckleObjects::Geometry::Mesh.from_face(face: entity, units: @units,
|
||||
mesh = SpeckleObjects::Geometry::Mesh.from_face(speckle_state: speckle_state, face: entity, units: @units,
|
||||
model_preferences: preferences[:model])
|
||||
return speckle_state, [mesh, [entity]]
|
||||
end
|
||||
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module SpeckleConnector
|
||||
# Helper module for logging.
|
||||
module Log
|
||||
def self.write_to_file(text, file_name = 'log', path = "#{ENV['HOME']}/Desktop")
|
||||
file_path = path + "/#{file_name}.json"
|
||||
File.delete(file_path) if File.exist?(file_path)
|
||||
File.write(file_path, text)
|
||||
end
|
||||
end
|
||||
end
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module SpeckleConnector
|
||||
module Mapping
|
||||
module Mapper
|
||||
module Category
|
||||
# Revit categories.
|
||||
class RevitCategory < Hash
|
||||
@@ -0,0 +1,61 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../speckle_objects/built_elements/revit/revit_floor'
|
||||
require_relative '../speckle_objects/built_elements/revit/revit_wall'
|
||||
require_relative '../speckle_objects/built_elements/default_floor'
|
||||
require_relative '../speckle_objects/built_elements/default_wall'
|
||||
require_relative '../sketchup_model/query/entity'
|
||||
require_relative '../sketchup_model/reader/mapper_reader'
|
||||
require_relative '../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
# Mapper is a tool to convert SketchUp entities to other applications' native objects.
|
||||
module Mapper
|
||||
# Collects mapped entities on selection as flat list.
|
||||
def self.mapped_entities_on_selection(sketchup_model)
|
||||
flat_selection_with_path = SketchupModel::Query::Entity.flat_entities_with_path(
|
||||
sketchup_model.selection,
|
||||
[Sketchup::Face, Sketchup::ComponentInstance, Sketchup::Group], [sketchup_model]
|
||||
)
|
||||
mapped_selection = []
|
||||
flat_selection_with_path.each do |entities|
|
||||
entity = entities[0]
|
||||
is_entity_mapped = SketchupModel::Reader::MapperReader.mapped_with_schema?(entity)
|
||||
if entity.respond_to?(:definition)
|
||||
is_definition_mapped = SketchupModel::Reader::MapperReader.mapped_with_schema?(entity.definition)
|
||||
mapped_selection.append(entities) if is_entity_mapped || is_definition_mapped
|
||||
next
|
||||
end
|
||||
mapped_selection.append(entities) if is_entity_mapped
|
||||
end
|
||||
mapped_selection
|
||||
end
|
||||
|
||||
def self.to_speckle(speckle_state, entity, units, global_transformation: nil)
|
||||
speckle_schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.speckle_schema_to_speckle(entity)
|
||||
return speckle_schema if speckle_schema.nil?
|
||||
|
||||
if speckle_schema['method'] == 'Default Floor'
|
||||
return SpeckleObjects::BuiltElements::DefaultFloor
|
||||
.to_speckle_schema(entity, units, global_transformation: global_transformation)
|
||||
end
|
||||
|
||||
if speckle_schema['method'] == 'Floor'
|
||||
return SpeckleObjects::BuiltElements::RevitFloor
|
||||
.to_speckle_schema(speckle_state, entity, units, global_transformation: global_transformation)
|
||||
end
|
||||
|
||||
if speckle_schema['method'] == 'Default Wall'
|
||||
return SpeckleObjects::BuiltElements::DefaultWall
|
||||
.to_speckle_schema(entity, units, global_transformation: global_transformation)
|
||||
end
|
||||
|
||||
if speckle_schema['method'] == 'Wall'
|
||||
return SpeckleObjects::BuiltElements::RevitWall
|
||||
.to_speckle_schema(speckle_state, entity, units, global_transformation: global_transformation)
|
||||
end
|
||||
|
||||
return speckle_schema
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../immutable/immutable'
|
||||
require_relative '../speckle_objects/built_elements/level'
|
||||
require_relative '../speckle_objects/built_elements/revit/revit_element_type'
|
||||
|
||||
module SpeckleConnector
|
||||
# Mapper is a tool to convert SketchUp entities to other applications' native objects.
|
||||
module Mapper
|
||||
# Mapper source object that collects information about stream id and commit id to identify source in the branch,
|
||||
# also contains levels and family types to be able to map objects with them.
|
||||
class MapperSource
|
||||
# @return [String] stream id of the mapper source.
|
||||
attr_reader :stream_id
|
||||
|
||||
# @return [String] commit id of the mapper source.
|
||||
attr_reader :commit_id
|
||||
|
||||
# @return [Array<SpeckleObjects::BuiltElements::Level>] levels in the source branch.
|
||||
attr_reader :levels
|
||||
|
||||
# @return [ImmutableHash{String=>Array<SpeckleObjects::BuiltElements::Revit::RevitElementType>}] revit element
|
||||
# types.
|
||||
attr_reader :types
|
||||
|
||||
def initialize(stream_id, commit_id, levels, types)
|
||||
@stream_id = stream_id
|
||||
@commit_id = commit_id
|
||||
@levels = levels
|
||||
@types = types
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,95 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../dictionary/speckle_schema_dictionary_handler'
|
||||
require_relative '../../speckle_entities/speckle_entity'
|
||||
require_relative '../../mapper/category/revit_category'
|
||||
require_relative '../../constants/dict_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
# Operations related to {SketchupModel}.
|
||||
module SketchupModel
|
||||
# Reader model for sketchup model.
|
||||
module Reader
|
||||
# Reader module for mapper.
|
||||
module MapperReader
|
||||
# @param entities [Sketchup::Entities] entities to collect mapped entities.
|
||||
# @return [Hash{String=>Sketchup::Entity}] mapped entities with persistent id.
|
||||
def self.read_mapped_entities(entities)
|
||||
mapped_entities = {}
|
||||
Query::Entity.flat_entities(entities).each do |entity|
|
||||
mapped_entities[entity.persistent_id] = entity if mapped_with_schema?(entity)
|
||||
end
|
||||
mapped_entities
|
||||
end
|
||||
|
||||
# @param entity [Sketchup::Entity] sketchup entity to check whether mapped with speckle schema or not.
|
||||
def self.mapped_with_schema?(entity)
|
||||
is_entity_mapped = !Dictionary::SpeckleSchemaDictionaryHandler.attribute_dictionary(entity).nil?
|
||||
return is_entity_mapped if is_entity_mapped
|
||||
return is_entity_mapped unless entity.is_a?(Sketchup::ComponentInstance)
|
||||
|
||||
!Dictionary::SpeckleSchemaDictionaryHandler.attribute_dictionary(entity.definition).nil?
|
||||
end
|
||||
|
||||
def self.get_schema(entity)
|
||||
Dictionary::SpeckleSchemaDictionaryHandler.speckle_schema_to_speckle(entity)
|
||||
end
|
||||
|
||||
def self.entities_schema_details(entities)
|
||||
entities.collect do |entity|
|
||||
entity_selection_details = entity_selection_details(entity)
|
||||
if entity.is_a?(Sketchup::ComponentInstance)
|
||||
entity_selection_details = entity_selection_details.merge(
|
||||
{ definition: entity_selection_details(entity.definition) }
|
||||
)
|
||||
end
|
||||
entity_selection_details
|
||||
end
|
||||
end
|
||||
|
||||
def self.entity_selection_details(entity)
|
||||
sanitized_type = entity.class.name.split('::').last.gsub(/(?<=[a-z])(?=[A-Z])/, ' ').split
|
||||
is_definition = entity.is_a?(Sketchup::ComponentDefinition)
|
||||
entity_type = is_definition ? sanitized_type.last : sanitized_type.first
|
||||
speckle_schema = get_schema(entity)
|
||||
{
|
||||
name: speckle_schema['name'],
|
||||
entityName: entity.respond_to?(:name) ? entity.name : '',
|
||||
entityId: entity.persistent_id,
|
||||
entityType: entity_type,
|
||||
schema: speckle_schema,
|
||||
numberOfInstances: is_definition ? entity.instances.length : 1
|
||||
}
|
||||
end
|
||||
|
||||
def self.mapped_entity_details(entities)
|
||||
reverse_category_dictionary = Mapper::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
|
||||
category = get_map_attribute(speckle_schema, speckle_schema_definition, 'category')
|
||||
{
|
||||
name: get_map_attribute(speckle_schema, speckle_schema_definition, 'name'),
|
||||
category: category,
|
||||
categoryName: category.nil? ? '' : reverse_category_dictionary[category],
|
||||
method: get_map_attribute(speckle_schema, speckle_schema_definition, 'method'),
|
||||
entityName: entity.respond_to?(:name) ? entity.name : '',
|
||||
entityId: entity.persistent_id,
|
||||
entityType: entity.is_a?(Sketchup::ComponentDefinition) ? 'Definition' : entity_type,
|
||||
schema: speckle_schema,
|
||||
definitionSchema: speckle_schema_definition
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_map_attribute(schema, definition_schema, attribute)
|
||||
return schema[attribute] if schema[attribute]
|
||||
return definition_schema[attribute] if !definition_schema.nil? && definition_schema[attribute]
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require_relative '../dictionary/speckle_schema_dictionary_handler'
|
||||
require_relative '../../speckle_entities/speckle_entity'
|
||||
require_relative '../../mapping/category/revit_category'
|
||||
require_relative '../../mapper/category/revit_category'
|
||||
require_relative '../../constants/dict_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
@@ -29,16 +29,6 @@ module SpeckleConnector
|
||||
speckle_entities
|
||||
end
|
||||
|
||||
# @param entities [Sketchup::Entities] entities to collect mapped entities.
|
||||
# @return [Hash{String=>Sketchup::Entity}] mapped entities with persistent id.
|
||||
def self.read_mapped_entities(entities)
|
||||
mapped_entities = {}
|
||||
Query::Entity.flat_entities(entities).each do |entity|
|
||||
mapped_entities[entity.persistent_id] = entity if mapped_with_schema?(entity)
|
||||
end
|
||||
mapped_entities
|
||||
end
|
||||
|
||||
# @param entity [Sketchup::Entity] sketchup entity to read from attribute dictionary.
|
||||
def self.read_speckle_entity(entity)
|
||||
dict = entity.attribute_dictionaries.to_a.find { |d| d.name == SPECKLE_BASE_OBJECT }
|
||||
@@ -60,70 +50,7 @@ module SpeckleConnector
|
||||
entity.attribute_dictionaries.to_a.any? { |dict| dict.name == SPECKLE_BASE_OBJECT }
|
||||
end
|
||||
|
||||
# @param entity [Sketchup::Entity] sketchup entity to check whether mapped with speckle schema or not.
|
||||
def self.mapped_with_schema?(entity)
|
||||
is_entity_mapped = !Dictionary::SpeckleSchemaDictionaryHandler.attribute_dictionary(entity).nil?
|
||||
return is_entity_mapped if is_entity_mapped
|
||||
return is_entity_mapped unless entity.is_a?(Sketchup::ComponentInstance)
|
||||
|
||||
!Dictionary::SpeckleSchemaDictionaryHandler.attribute_dictionary(entity.definition).nil?
|
||||
end
|
||||
|
||||
def self.get_schema(entity)
|
||||
Dictionary::SpeckleSchemaDictionaryHandler.speckle_schema_to_speckle(entity)
|
||||
end
|
||||
|
||||
def self.entities_schema_details(entities)
|
||||
entities.collect do |entity|
|
||||
entity_selection_details = entity_selection_details(entity)
|
||||
if entity.is_a?(Sketchup::ComponentInstance)
|
||||
entity_selection_details = entity_selection_details.merge(
|
||||
{ definition: entity_selection_details(entity.definition) }
|
||||
)
|
||||
end
|
||||
entity_selection_details
|
||||
end
|
||||
end
|
||||
|
||||
def self.entity_selection_details(entity)
|
||||
sanitized_type = entity.class.name.split('::').last.gsub(/(?<=[a-z])(?=[A-Z])/, ' ').split
|
||||
is_definition = entity.is_a?(Sketchup::ComponentDefinition)
|
||||
entity_type = is_definition ? sanitized_type.last : sanitized_type.first
|
||||
speckle_schema = get_schema(entity)
|
||||
{
|
||||
name: speckle_schema['name'],
|
||||
entityName: entity.respond_to?(:name) ? entity.name : '',
|
||||
entityId: entity.persistent_id,
|
||||
entityType: entity_type,
|
||||
schema: speckle_schema,
|
||||
numberOfInstances: is_definition ? entity.instances.length : 1
|
||||
}
|
||||
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'] || 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.is_a?(Sketchup::ComponentDefinition) ? 'Definition' : entity_type,
|
||||
schema: speckle_schema,
|
||||
definitionSchema: speckle_schema_definition
|
||||
}
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../constants/geo_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
# Operations related to {SketchupModel}.
|
||||
module SketchupModel
|
||||
@@ -24,6 +26,13 @@ module SpeckleConnector
|
||||
end
|
||||
adj_faces.uniq
|
||||
end
|
||||
|
||||
# @param face [Sketchup::Face] face to get max z distance for all vertices.
|
||||
def self.max_z(face)
|
||||
points = face.vertices.collect(&:position)
|
||||
points_z_values = points.collect(&:z)
|
||||
points_z_values.max - points_z_values.min
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -119,6 +119,32 @@ module SpeckleConnector
|
||||
def valid?
|
||||
sketchup_entity.valid?
|
||||
end
|
||||
|
||||
# @param state [States::State] state of the application
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def self.from_speckle_object(state, speckle_object, entities, stream_id)
|
||||
return state, [] if entities.empty?
|
||||
|
||||
speckle_id = speckle_object['id']
|
||||
application_id = speckle_object['applicationId']
|
||||
speckle_type = speckle_object['speckle_type']
|
||||
children = speckle_object['__closure'].nil? ? [] : speckle_object['__closure']
|
||||
speckle_state = state.speckle_state
|
||||
entities.each do |entity|
|
||||
next if entity.is_a?(Sketchup::Material) || entity.is_a?(Sketchup::Page)
|
||||
next if (entity.is_a?(Sketchup::Face) || entity.is_a?(Sketchup::Edge)) &&
|
||||
!state.user_state.user_preferences[:register_speckle_entity]
|
||||
|
||||
ent = SpeckleEntity.new(entity, speckle_id, application_id, speckle_type, children, [stream_id])
|
||||
ent.write_initial_base_data
|
||||
speckle_state = speckle_state.with_speckle_entity(ent)
|
||||
end
|
||||
new_state = state.with_speckle_state(speckle_state)
|
||||
return new_state, entities
|
||||
end
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../built_elements/revit/parameter'
|
||||
require_relative '../other/render_material'
|
||||
require_relative '../geometry/line'
|
||||
require_relative '../geometry/polyline'
|
||||
require_relative '../../constants/type_constants'
|
||||
require_relative '../../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module BuiltElements
|
||||
# Default Floor object.
|
||||
class DefaultFloor < Base
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_DEFAULT_FLOOR
|
||||
|
||||
def initialize(outline:, voids:, units:, material:, application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: nil
|
||||
)
|
||||
self[:outline] = outline
|
||||
self[:voids] = voids
|
||||
self[:units] = units
|
||||
self[:renderMaterial] = material
|
||||
end
|
||||
|
||||
# @param face [Sketchup::Face] face to get speckle schema for floor.
|
||||
def self.to_speckle_schema(face, units, global_transformation: nil)
|
||||
outline = Geometry::Polyline.from_loop(face.loops.first, units, global_transformation: global_transformation)
|
||||
voids = []
|
||||
if face.loops.length > 1
|
||||
voids = face.loops[1..face.loops.length - 1].collect do |loop|
|
||||
Geometry::Polyline.from_loop(loop, units, global_transformation: global_transformation)
|
||||
end
|
||||
end
|
||||
material = face.material || face.back_material
|
||||
|
||||
DefaultFloor.new(
|
||||
outline: outline,
|
||||
voids: voids,
|
||||
units: units,
|
||||
material: material.nil? ? nil : Other::RenderMaterial.from_material(face.material || face.back_material),
|
||||
application_id: face.persistent_id
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../built_elements/revit/parameter'
|
||||
require_relative '../other/render_material'
|
||||
require_relative '../geometry/length'
|
||||
require_relative '../geometry/line'
|
||||
require_relative '../geometry/polyline'
|
||||
require_relative '../../constants/type_constants'
|
||||
require_relative '../../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
require_relative '../../sketchup_model/utils/face_utils'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module BuiltElements
|
||||
# Default Wall object.
|
||||
class DefaultWall < Base
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_DEFAULT_WALL
|
||||
|
||||
def initialize(base_line:, height:, flipped:, units:, material:, application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: nil
|
||||
)
|
||||
self[:baseLine] = base_line
|
||||
self[:height] = height
|
||||
self[:flipped] = flipped
|
||||
self[:units] = units
|
||||
self[:renderMaterial] = material
|
||||
end
|
||||
|
||||
# @param face [Sketchup::Face] face to get speckle schema for floor.
|
||||
def self.to_speckle_schema(face, units, global_transformation: nil)
|
||||
base_line = Geometry::Line.base_line_from_face(face, units, global_transformation: global_transformation)
|
||||
|
||||
material = face.material || face.back_material
|
||||
|
||||
DefaultWall.new(
|
||||
base_line: base_line,
|
||||
height: Geometry.length_to_speckle(SketchupModel::Utils::FaceUtils.max_z(face), units),
|
||||
flipped: false,
|
||||
units: units,
|
||||
material: material.nil? ? nil : Other::RenderMaterial.from_material(face.material || face.back_material),
|
||||
application_id: face.persistent_id
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,84 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../other/render_material'
|
||||
require_relative '../geometry/line'
|
||||
require_relative '../geometry/length'
|
||||
require_relative '../geometry/polyline'
|
||||
require_relative '../../constants/type_constants'
|
||||
require_relative '../../sketchup_model/dictionary/speckle_entity_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module BuiltElements
|
||||
# Level object.
|
||||
class Level < Base
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_REVIT_LEVEL
|
||||
|
||||
def initialize(name:, elevation:, units:, element_id:, application_id: nil, id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: id
|
||||
)
|
||||
self[:name] = name
|
||||
self[:elevation] = elevation
|
||||
self[:units] = units
|
||||
self[:elementId] = element_id
|
||||
self[:referenceOnly] = true
|
||||
self[:createView] = false
|
||||
end
|
||||
|
||||
# @param state [States::State] state of the application.
|
||||
def self.to_native(state, speckle_level, stream_id)
|
||||
sketchup_model = state.sketchup_state.sketchup_model
|
||||
levels_layer = sketchup_model.layers.layers.find { |layer| layer.display_name == 'Levels' }
|
||||
levels_layer = sketchup_model.layers.add('Levels') if levels_layer.nil?
|
||||
|
||||
name = speckle_level['name']
|
||||
elevation = speckle_level['elevation']
|
||||
units = speckle_level['units']
|
||||
element_id = speckle_level['elementId']
|
||||
application_id = speckle_level['applicationId']
|
||||
id = speckle_level['id']
|
||||
|
||||
skp_elevation = Geometry.length_to_native(elevation, units)
|
||||
|
||||
definition_name = "#{name}-#{application_id}"
|
||||
definition = sketchup_model.definitions.find { |definition| definition.name == definition_name }
|
||||
definition.entities.clear! unless definition.nil?
|
||||
definition = sketchup_model.definitions.add(definition_name) if definition.nil?
|
||||
instance = sketchup_model.entities.add_instance(definition, Geom::Transformation.new)
|
||||
instance.locked = true
|
||||
SketchupModel::Dictionary::SpeckleEntityDictionaryHandler.write_initial_base_data(
|
||||
instance, application_id, id, SPECKLE_TYPE, [], stream_id
|
||||
)
|
||||
SketchupModel::Dictionary::SpeckleEntityDictionaryHandler.set_attribute(instance, :name, name)
|
||||
|
||||
SketchupModel::Dictionary::SpeckleEntityDictionaryHandler.write_initial_base_data(
|
||||
definition, application_id, id, SPECKLE_TYPE, [], stream_id
|
||||
)
|
||||
SketchupModel::Dictionary::SpeckleEntityDictionaryHandler.set_attribute(definition, :name, name)
|
||||
|
||||
c1_e = Geom::Point3d.new(0, 10.m, skp_elevation)
|
||||
c2_e = Geom::Point3d.new(0, 0, skp_elevation)
|
||||
c3_e = Geom::Point3d.new(10.m, 0, skp_elevation)
|
||||
cline_1 = definition.entities.add_cline(c1_e, c2_e)
|
||||
cline_2 = definition.entities.add_cline(c2_e, c3_e)
|
||||
text = definition.entities.add_text(" #{name}", c1_e)
|
||||
[cline_1, cline_2, text, definition, instance].each { |o| o.layer = levels_layer }
|
||||
|
||||
Level.new(
|
||||
name: name,
|
||||
elevation: elevation,
|
||||
units: units,
|
||||
element_id: element_id,
|
||||
application_id: application_id,
|
||||
id: speckle_level['id']
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -12,7 +12,7 @@ module SpeckleConnector
|
||||
|
||||
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)
|
||||
state, _converted_entities = convert_to_native.call(state, element['elements'], layer, entities)
|
||||
end
|
||||
|
||||
return state, []
|
||||
|
||||
@@ -7,7 +7,7 @@ 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/reader/mapper_reader'
|
||||
require_relative '../../../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
@@ -78,9 +78,9 @@ module SpeckleConnector
|
||||
mapped_selection = []
|
||||
flat_selection_with_path.each do |entities|
|
||||
entity = entities[0]
|
||||
is_entity_mapped = READER::SpeckleEntitiesReader.mapped_with_schema?(entity)
|
||||
is_entity_mapped = READER::MapperReader.mapped_with_schema?(entity)
|
||||
if entity.respond_to?(:definition)
|
||||
is_definition_mapped = READER::SpeckleEntitiesReader.mapped_with_schema?(entity.definition)
|
||||
is_definition_mapped = READER::MapperReader.mapped_with_schema?(entity.definition)
|
||||
mapped_selection.append(entities) if is_entity_mapped || is_definition_mapped
|
||||
next
|
||||
end
|
||||
@@ -89,7 +89,7 @@ module SpeckleConnector
|
||||
mapped_selection
|
||||
end
|
||||
|
||||
def self.from_entity(entity, path, units, preferences)
|
||||
def self.from_entity(speckle_state, entity, path, units, preferences)
|
||||
schema = DICTIONARY::SpeckleSchemaDictionaryHandler.attribute_dictionary(entity)
|
||||
if schema.nil? && entity.respond_to?(:definition)
|
||||
schema = DICTIONARY::SpeckleSchemaDictionaryHandler.attribute_dictionary(entity.definition)
|
||||
@@ -103,7 +103,7 @@ module SpeckleConnector
|
||||
entity.definition.entities, [Sketchup::Face], path.append(entity)
|
||||
)
|
||||
end
|
||||
base_geometries = group_faces_under_mesh_by_material(entities_with_path, units, preferences)
|
||||
base_geometries = group_faces_under_mesh_by_material(speckle_state, entities_with_path, units, preferences)
|
||||
DirectShape.new(
|
||||
name: schema[:name], category: schema[:category], units: units,
|
||||
base_geometries: base_geometries, application_id: entity.persistent_id
|
||||
@@ -111,7 +111,7 @@ module SpeckleConnector
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def self.group_faces_under_mesh_by_material(faces_with_path, units, preferences)
|
||||
def self.group_faces_under_mesh_by_material(speckle_state, faces_with_path, units, preferences)
|
||||
mesh_groups = {}
|
||||
faces_with_path.each do |face_with_path|
|
||||
face = face_with_path[0]
|
||||
@@ -125,6 +125,7 @@ module SpeckleConnector
|
||||
mesh_group[1].append(face)
|
||||
else
|
||||
mesh = Geometry::Mesh.from_face(
|
||||
speckle_state: speckle_state,
|
||||
face: face, units: units, model_preferences: preferences[:model],
|
||||
global_transform: QUERY::Entity.global_transformation(face, entity_path),
|
||||
parent_material: parent_material
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../base'
|
||||
require_relative '../../../constants/type_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module BuiltElements
|
||||
module Revit
|
||||
# Revit parameter.
|
||||
class Parameter < Base
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_REVIT_PARAMETER
|
||||
def initialize(name:, application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: id
|
||||
)
|
||||
self[:name] = name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../base'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module BuiltElements
|
||||
module Revit
|
||||
# Revit element type.
|
||||
class RevitElementType < Base
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_REVIT_REVITELEMENTTYPE
|
||||
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def initialize(category:, family:, type:, element_id:, application_id: nil, id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: id
|
||||
)
|
||||
self[:category] = category
|
||||
self[:family] = family
|
||||
self[:type] = type
|
||||
self[:elementId] = element_id
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
def self.to_native(revit_element_type)
|
||||
RevitElementType.new(
|
||||
category: revit_element_type['category'],
|
||||
family: revit_element_type['family'],
|
||||
type: revit_element_type['type'],
|
||||
element_id: revit_element_type['elementId'],
|
||||
application_id: revit_element_type['applicationId'],
|
||||
id: revit_element_type['id']
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,77 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../base'
|
||||
require_relative '../../built_elements/revit/parameter'
|
||||
require_relative '../../other/render_material'
|
||||
require_relative '../../geometry/line'
|
||||
require_relative '../../geometry/polyline'
|
||||
require_relative '../../../constants/type_constants'
|
||||
require_relative '../../../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module BuiltElements
|
||||
# Revit floor object.
|
||||
class RevitFloor < Base
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_REVIT_FLOOR
|
||||
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def initialize(family:, type:, outline:, voids:, level:, units:, material:, parameters:nil, application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: nil
|
||||
)
|
||||
self[:family] = family
|
||||
self[:type] = type
|
||||
self[:level] = level
|
||||
self[:outline] = outline
|
||||
self[:voids] = voids
|
||||
self[:units] = units
|
||||
self[:parameters] = parameters
|
||||
self[:renderMaterial] = material
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
# @param face [Sketchup::Face] face to get speckle schema for floor.
|
||||
def self.to_speckle_schema(speckle_state, face, units, global_transformation: nil)
|
||||
outline = Geometry::Polyline.from_loop(face.loops.first, units, global_transformation: global_transformation)
|
||||
voids = []
|
||||
if face.loops.length > 1
|
||||
voids = face.loops[1..face.loops.length - 1].collect do |loop|
|
||||
Geometry::Polyline.from_loop(loop, units, global_transformation: global_transformation)
|
||||
end
|
||||
end
|
||||
material = face.material || face.back_material
|
||||
schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.speckle_schema_to_speckle(face).to_h
|
||||
source_exist = !speckle_state.speckle_mapper_state.mapper_source.nil?
|
||||
level = nil
|
||||
parameters = nil
|
||||
if source_exist
|
||||
level = speckle_state.speckle_mapper_state.mapper_source.levels.find { |l| l[:name] == schema['level'] }
|
||||
parameters = Base.new
|
||||
offset_parameter = BuiltElements::Revit::Parameter.new(name: 'Height Offset From Level')
|
||||
level_z = Geometry.length_to_native(level[:elevation], level[:units])
|
||||
min_z = face.vertices.collect(&:position).map(&:z).min
|
||||
offset_parameter['value'] = Geometry.length_to_speckle(min_z - level_z, units)
|
||||
offset_parameter['units'] = units
|
||||
parameters['Height Offset From Level'] = offset_parameter
|
||||
end
|
||||
|
||||
RevitFloor.new(
|
||||
family: schema['family'],
|
||||
type: schema['family_type'],
|
||||
outline: outline,
|
||||
voids: voids,
|
||||
level: level,
|
||||
units: units,
|
||||
parameters: parameters,
|
||||
material: material.nil? ? nil : Other::RenderMaterial.from_material(face.material || face.back_material),
|
||||
application_id: face.persistent_id
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,102 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../base'
|
||||
require_relative '../../built_elements/revit/parameter'
|
||||
require_relative '../../other/render_material'
|
||||
require_relative '../../geometry/line'
|
||||
require_relative '../../geometry/length'
|
||||
require_relative '../../../constants/type_constants'
|
||||
require_relative '../../../sketchup_model/dictionary/speckle_schema_dictionary_handler'
|
||||
require_relative '../../../sketchup_model/utils/face_utils'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module BuiltElements
|
||||
# Revit wall object.
|
||||
class RevitWall < Base
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_REVIT_WALL
|
||||
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def initialize(family:, type:, base_line:, height:, flipped:, level:, units:, material:, parameters: nil, application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: nil
|
||||
)
|
||||
self[:family] = family
|
||||
self[:type] = type
|
||||
self[:height] = height
|
||||
self[:flipped] = flipped
|
||||
self[:level] = level
|
||||
self[:baseLine] = base_line
|
||||
self[:units] = units
|
||||
self[:parameters] = parameters
|
||||
self[:renderMaterial] = material
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
def self.to_native(state, wall, layer, entities, &convert_to_native)
|
||||
obj = Other::DisplayValue.collect_definition_geometries(wall)
|
||||
obj['name'] = Other::DisplayValue.get_definition_name(obj)
|
||||
|
||||
state, _definitions = Other::BlockDefinition.to_native(
|
||||
state, obj, layer, entities, &convert_to_native
|
||||
)
|
||||
|
||||
definition = state.sketchup_state.sketchup_model.definitions[Other::BlockDefinition.get_definition_name(obj)]
|
||||
|
||||
Other::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'])
|
||||
instance = entities.add_instance(definition, transform)
|
||||
instance.name = Other::DisplayValue.get_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
|
||||
|
||||
# @param face [Sketchup::Face] face to get speckle schema for wall.
|
||||
def self.to_speckle_schema(speckle_state, face, units, global_transformation: nil)
|
||||
base_line = Geometry::Line.base_line_from_face(face, units, global_transformation: global_transformation)
|
||||
|
||||
material = face.material || face.back_material
|
||||
schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.speckle_schema_to_speckle(face).to_h
|
||||
source_exist = !speckle_state.speckle_mapper_state.mapper_source.nil?
|
||||
level = nil
|
||||
parameters = nil
|
||||
if source_exist
|
||||
level = speckle_state.speckle_mapper_state.mapper_source.levels.find { |l| l[:name] == schema['level'] }
|
||||
parameters = Base.new
|
||||
offset_parameter = BuiltElements::Revit::Parameter.new(name: 'Height Offset From Level')
|
||||
level_z = Geometry.length_to_native(level[:elevation], level[:units])
|
||||
min_z = face.vertices.collect(&:position).map(&:z).min
|
||||
offset_parameter['value'] = Geometry.length_to_speckle(min_z - level_z, units)
|
||||
offset_parameter['units'] = units
|
||||
parameters['Height Offset From Level'] = offset_parameter
|
||||
end
|
||||
|
||||
RevitWall.new(
|
||||
family: schema['family'],
|
||||
type: schema['family_type'],
|
||||
base_line: base_line,
|
||||
height: Geometry.length_to_speckle(SketchupModel::Utils::FaceUtils.max_z(face), units),
|
||||
flipped: false,
|
||||
level: level,
|
||||
units: units,
|
||||
parameters: parameters,
|
||||
material: material.nil? ? nil : Other::RenderMaterial.from_material(face.material || face.back_material),
|
||||
application_id: face.persistent_id
|
||||
)
|
||||
end
|
||||
|
||||
def self.get_wall_height(face, units)
|
||||
points = face.vertices.collect(&:position)
|
||||
points_z_values = points.collect(&:z)
|
||||
Geometry.length_to_speckle(points_z_values.max - points_z_values.min, units)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -19,7 +19,7 @@ module SpeckleConnector
|
||||
# @param direction [SpeckleObjects::Geometry::Vector] direction of the view from eye to target.
|
||||
# @param up_direction [SpeckleObjects::Geometry::Vector] up direction of the view.
|
||||
# @param is_perspective [Boolean] whether view is perspective or not.
|
||||
# @param lens [Boolean] fov value of the view camera.
|
||||
# @param lens [Numeric] focal length value of the view camera.
|
||||
# @param units [String] units of the camera.
|
||||
# @param application_id [String] application_id of the view.
|
||||
# @param update_properties [Hash{Symbol=>boolean}] properties of the view.
|
||||
@@ -63,42 +63,44 @@ module SpeckleConnector
|
||||
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
|
||||
cam.perspective?, cam.perspective? ? cam.focal_length : 35, units, page.name,
|
||||
update_properties, rendering_options
|
||||
)
|
||||
end
|
||||
|
||||
# @param state [States::State] state of the speckle app.
|
||||
# @param obj [Hash] commit object.
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# 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'
|
||||
|
||||
name = view['name'] || view['id']
|
||||
return state, [] if sketchup_model.pages.any? { |page| page.name == name }
|
||||
|
||||
origin = view['origin']
|
||||
target = view['target']
|
||||
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, up, !view['isOrthogonal'], lens)
|
||||
sketchup_model.active_view.camera = my_camera
|
||||
camera = create_camera(view)
|
||||
sketchup_model.active_view.camera = camera
|
||||
sketchup_model.pages.add(name)
|
||||
page = sketchup_model.pages[name]
|
||||
set_page_update_properties(page, view['update_properties']) if view['update_properties']
|
||||
set_rendering_options(page.rendering_options, view['rendering_options']) if view['rendering_options']
|
||||
return state, [page]
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
def self.create_camera(view)
|
||||
origin = view['origin']
|
||||
target = view['target']
|
||||
focal_length = view['lens'] || 35
|
||||
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.
|
||||
is_perspective = !view['isOrthogonal']
|
||||
camera = Sketchup::Camera.new(origin, target, up, is_perspective)
|
||||
camera.focal_length = focal_length if is_perspective
|
||||
camera.height = (origin - target).length * 2 unless is_perspective
|
||||
camera
|
||||
end
|
||||
|
||||
# @param page [Sketchup::Page] scene to update -update properties-
|
||||
def self.set_page_update_properties(page, update_properties)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../../constants/type_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Geometry
|
||||
# Arc object definition for Speckle.
|
||||
class Arc < Base
|
||||
SPECKLE_TYPE = OBJECTS_GEOMETRY_ARC
|
||||
|
||||
# @param [States::State] state of the current application.
|
||||
# @param arc [Object] object represents Speckle Arc.
|
||||
# @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, arc, layer, entities, &_convert_to_native)
|
||||
plane = arc['plane']
|
||||
units = arc['units']
|
||||
origin = Point.to_native(plane['origin']['x'], plane['origin']['y'], plane['origin']['z'], units)
|
||||
normal = Vector.to_native(plane['normal']['x'], plane['normal']['y'], plane['normal']['z'], units)
|
||||
x_axis = Vector.to_native(plane['xdir']['x'], plane['xdir']['y'], plane['xdir']['z'], units)
|
||||
radius = Geometry.length_to_native(arc['radius'], units)
|
||||
edges = entities.add_arc(origin, x_axis, normal, radius, arc['startAngle'], arc['endAngle'])
|
||||
edges.each { |edge| edge.layer = layer }
|
||||
return state, edges
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'point'
|
||||
require_relative 'vector'
|
||||
require_relative 'length'
|
||||
require_relative '../base'
|
||||
require_relative '../../constants/type_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Geometry
|
||||
# Circle object definition for Speckle.
|
||||
class Circle < Base
|
||||
SPECKLE_TYPE = OBJECTS_GEOMETRY_CIRCLE
|
||||
|
||||
# @param [States::State] state of the current application.
|
||||
# @param circle [Object] object represents Speckle Circle.
|
||||
# @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, circle, layer, entities, &_convert_to_native)
|
||||
plane = circle['plane']
|
||||
units = circle['units']
|
||||
origin = Point.to_native(plane['origin']['x'], plane['origin']['y'], plane['origin']['z'], units)
|
||||
normal = Vector.to_native(plane['normal']['x'], plane['normal']['y'], plane['normal']['z'], units)
|
||||
radius = Geometry.length_to_native(circle['radius'], units)
|
||||
edges = entities.add_circle(origin, normal, radius)
|
||||
edges.each { |edge| edge.layer = layer }
|
||||
return state, edges
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -40,7 +40,7 @@ module SpeckleConnector
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
# @param edge [Sketchup::Edge] edge to convert line.
|
||||
def self.from_edge(edge, units, model_preferences)
|
||||
def self.from_edge(edge, units, model_preferences, global_transformation: nil)
|
||||
dictionaries = SketchupModel::Dictionary::BaseDictionaryHandler
|
||||
.attribute_dictionaries_to_speckle(edge, model_preferences)
|
||||
att = dictionaries.any? ? { dictionaries: dictionaries } : {}
|
||||
@@ -60,7 +60,42 @@ module SpeckleConnector
|
||||
)
|
||||
end
|
||||
|
||||
# @param _state [States::State] state of the application.
|
||||
# @param edge [Sketchup::Face] face to get base line from face.
|
||||
def self.base_line_from_face(face, units, global_transformation: nil)
|
||||
points = face.vertices.collect(&:position)
|
||||
points_z_values = points.collect(&:z)
|
||||
height = Geometry.length_to_speckle(points_z_values.max - points_z_values.min, units)
|
||||
min_z = points_z_values.min
|
||||
projected_points = points.map { |p| Geom::Point3d.new(p.x, p.y, min_z) }
|
||||
distance_with_points = Struct.new(:distance, :point_1, :point_2)
|
||||
lines_with_distances = []
|
||||
projected_points.each do |p|
|
||||
projected_points.each do |p_other|
|
||||
next if p_other == p
|
||||
|
||||
lines_with_distances.append(distance_with_points.new(p.distance(p_other), p, p_other))
|
||||
end
|
||||
end
|
||||
lines_with_distances.sort_by!(&:distance).reverse!
|
||||
p_1 = lines_with_distances.first.point_1
|
||||
p_2 = lines_with_distances.first.point_2
|
||||
unless global_transformation.nil?
|
||||
p_1 = p_1.transform!(global_transformation)
|
||||
p_2 = p_2.transform!(global_transformation)
|
||||
end
|
||||
Line.new(
|
||||
start_pt: Geometry::Point.from_vertex(p_1, units),
|
||||
end_pt: Geometry::Point.from_vertex(p_2, units),
|
||||
domain: Primitive::Interval.from_numeric(0, Geometry.length_to_speckle(p_1.distance(p_2), units), units),
|
||||
units: units,
|
||||
layer: SketchupModel::Query::Layer.entity_path(face),
|
||||
sketchup_attributes: {},
|
||||
speckle_schema: {},
|
||||
application_id: face.persistent_id.to_s
|
||||
)
|
||||
end
|
||||
|
||||
# @param state [States::State] state of the application.
|
||||
# @param line [Object] object represents Speckle line.
|
||||
# @param layer [Sketchup::Layer] layer to add {Sketchup::Edge} into it.
|
||||
# @param entities [Sketchup::Entities] entities collection to add {Sketchup::Edge} into it.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
require_relative '../base'
|
||||
require_relative '../geometry/bounding_box'
|
||||
require_relative '../other/render_material'
|
||||
require_relative '../../mapper/mapper'
|
||||
require_relative '../../sketchup_model/query/entity'
|
||||
require_relative '../../convertors/clean_up'
|
||||
require_relative '../../sketchup_model/dictionary/base_dictionary_handler'
|
||||
@@ -51,7 +52,7 @@ module SpeckleConnector
|
||||
self[:'@(31250)vertices'] = vertices
|
||||
self[:'@(62500)faces'] = faces
|
||||
self[:sketchup_attributes] = sketchup_attributes if sketchup_attributes.any?
|
||||
self[:SpeckleSchema] = speckle_schema if speckle_schema.any?
|
||||
self['@SpeckleSchema'] = speckle_schema if speckle_schema.any?
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
@@ -119,6 +120,10 @@ module SpeckleConnector
|
||||
added_faces = entities.grep(Sketchup::Face).last(native_mesh.polygons.length)
|
||||
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 }
|
||||
# Merge only added faces in this scope
|
||||
if model_preferences[:merge_coplanar_faces]
|
||||
added_faces = Converters::CleanUp.merge_coplanar_faces(added_faces)
|
||||
end
|
||||
added_faces.each do |face|
|
||||
face.layer = mesh_layer unless mesh_layer.nil?
|
||||
# Smooth edges if they already soft
|
||||
@@ -129,10 +134,7 @@ module SpeckleConnector
|
||||
.attribute_dictionaries_to_native(face, mesh['sketchup_attributes']['dictionaries'])
|
||||
end
|
||||
end
|
||||
# Merge only added faces in this scope
|
||||
if model_preferences[:merge_coplanar_faces]
|
||||
added_faces = Converters::CleanUp.merge_coplanar_faces(added_faces)
|
||||
end
|
||||
|
||||
return state, added_faces
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
@@ -146,13 +148,13 @@ module SpeckleConnector
|
||||
# @param global_transform [Geom::Transformation, nil] global transformation value of face if it is not included
|
||||
# into any component.
|
||||
# rubocop:disable Style/MultilineTernaryOperator
|
||||
def self.from_face(face:, units:, model_preferences:, global_transform: nil, parent_material: nil)
|
||||
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)
|
||||
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 }
|
||||
speckle_schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler.speckle_schema_to_speckle(face)
|
||||
speckle_schema = Mapper.to_speckle(speckle_state, face, units, global_transformation: global_transform)
|
||||
material = face.material || face.back_material || parent_material
|
||||
speckle_mesh = Mesh.new(
|
||||
units: units,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../../constants/type_constants'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Geometry
|
||||
# Polycurve object definition for Speckle.
|
||||
# It basically groups the lines-curves under it's `segments` property.
|
||||
class Polycurve < Base
|
||||
SPECKLE_TYPE = OBJECTS_GEOMETRY_POLYCURVE
|
||||
|
||||
def self.to_native(state, polycurve, layer, entities, &convert_to_native)
|
||||
polycurve['displayValue'] = polycurve['segments']
|
||||
convert_to_native.call(state, polycurve, layer, entities)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'length'
|
||||
require_relative 'point'
|
||||
require_relative 'bounding_box'
|
||||
require_relative '../base'
|
||||
require_relative '../primitive/interval'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Geometry
|
||||
# Polyline object definition for Speckle.
|
||||
class Polyline < Base
|
||||
SPECKLE_TYPE = OBJECTS_GEOMETRY_POLYLINE
|
||||
|
||||
# @param value [Array<Numeric>] polygon vertex coordinates as flat list.
|
||||
# @param domain [Primitive::Interval] domain of the polyline.
|
||||
# @param length [Numeric] length of the polyline.
|
||||
# @param closed [Boolean] whether polyline is closed or not.
|
||||
# @param units [String] units of the polyline.
|
||||
# @param application_id [String] application id of the polyline which corresponds to persistent_id of the Loop.
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def initialize(value:, domain:, length:, closed:, units:, application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
application_id: application_id,
|
||||
id: nil
|
||||
)
|
||||
self[:value] = value
|
||||
self[:domain] = domain
|
||||
self[:length] = length
|
||||
self[:closed] = closed
|
||||
self[:units] = units
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
# @param loop [Sketchup::Loop] loop to convert closed speckle polyline.
|
||||
def self.from_loop(loop, units, global_transformation: nil)
|
||||
points = loop.vertices.collect do |vertex|
|
||||
position = vertex.position
|
||||
position = vertex.position.transform!(global_transformation) unless global_transformation.nil?
|
||||
position
|
||||
end
|
||||
values = points.collect do |p|
|
||||
[Geometry.length_to_speckle(p.x, units),
|
||||
Geometry.length_to_speckle(p.y, units),
|
||||
Geometry.length_to_speckle(p.z, units)]
|
||||
end.flatten
|
||||
loop_length = loop.edges.sum(&:length)
|
||||
length = Geometry.length_to_speckle(loop_length, units)
|
||||
domain = Primitive::Interval.from_lengths(0, loop_length, units)
|
||||
Polyline.new(
|
||||
value: values,
|
||||
domain: domain,
|
||||
length: length,
|
||||
units: units,
|
||||
closed: true,
|
||||
application_id: loop.persistent_id.to_s
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'length'
|
||||
require_relative '../base'
|
||||
|
||||
module SpeckleConnector
|
||||
@@ -25,6 +26,14 @@ module SpeckleConnector
|
||||
self[:z] = z
|
||||
self[:units] = units
|
||||
end
|
||||
|
||||
def self.to_native(x, y, z, units)
|
||||
Geom::Vector3d.new(
|
||||
Geometry.length_to_native(x, units),
|
||||
Geometry.length_to_native(y, units),
|
||||
Geometry.length_to_native(z, units)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -122,13 +122,23 @@ module SpeckleConnector
|
||||
definition&.entities&.clear!
|
||||
definition ||= sketchup_model.definitions.add(definition_name)
|
||||
|
||||
ngon_faces = []
|
||||
if geometry.is_a?(Array)
|
||||
geometry.each do |obj|
|
||||
state = convert_to_native.call(state, obj, layer, definition.entities)
|
||||
state, added_entities = convert_to_native.call(state, obj, layer, definition.entities)
|
||||
if added_entities.length == 1 && added_entities.first.is_a?(Sketchup::Face)
|
||||
ngon_faces.append(added_entities.first)
|
||||
end
|
||||
end
|
||||
end
|
||||
ngon_faces.each do |f|
|
||||
f.edges.each do |e|
|
||||
e.soft = false
|
||||
e.smooth = false
|
||||
end
|
||||
end
|
||||
if geometry.is_a?(Hash) && !definition_obj['speckle_type'].nil?
|
||||
state = convert_to_native.call(state, geometry, layer, definition.entities)
|
||||
state, _converted_entities = convert_to_native.call(state, geometry, layer, definition.entities)
|
||||
end
|
||||
# puts("definition finished: #{name} (#{application_id})")
|
||||
# puts(" entity count: #{definition.entities.count}")
|
||||
@@ -149,6 +159,7 @@ module SpeckleConnector
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
def self.group_entities_to_speckle(entities, preferences, speckle_state, parent, &convert)
|
||||
entities = entities.reject(&:hidden?)
|
||||
orphan_edges = entities.grep(Sketchup::Edge).filter { |edge| edge.faces.none? }
|
||||
lines = orphan_edges.collect do |orphan_edge|
|
||||
new_speckle_state, converted = convert.call(orphan_edge, preferences, speckle_state, parent)
|
||||
|
||||
@@ -9,7 +9,6 @@ module SpeckleConnector
|
||||
module Other
|
||||
# DisplayStyle object for layer.
|
||||
class DisplayStyle < Base
|
||||
|
||||
def initialize(name:, color:, line_type:)
|
||||
super(
|
||||
speckle_type: OBJECTS_OTHER_DISPLAYSTYLE,
|
||||
|
||||
@@ -22,9 +22,15 @@ module SpeckleConnector
|
||||
|
||||
return format_naming_convention([family, type, category, element_id]) unless element_id.nil?
|
||||
|
||||
return "def::#{def_obj['applicationId']}" unless def_obj['applicationId'].nil?
|
||||
name = def_obj['name']
|
||||
return "#{name}::#{def_obj['applicationId']}" if !name.nil? && !def_obj['applicationId'].nil?
|
||||
|
||||
return "def::#{def_obj['id']}"
|
||||
return "#{name}::#{def_obj['id']}" unless name.nil?
|
||||
|
||||
speckle_type = def_obj['speckle_type'].split('.').last
|
||||
return "#{speckle_type}::#{def_obj['applicationId']}" unless def_obj['applicationId'].nil?
|
||||
|
||||
return "#{speckle_type}::#{def_obj['id']}"
|
||||
end
|
||||
|
||||
def self.format_naming_convention(entries)
|
||||
@@ -41,6 +47,13 @@ module SpeckleConnector
|
||||
name
|
||||
end
|
||||
|
||||
# Get instance name as speckle_type if it is structured as `speckle_type::application_id`
|
||||
def self.get_instance_name(definition_name)
|
||||
return definition_name unless definition_name.include?('::')
|
||||
|
||||
definition_name.split('::').first
|
||||
end
|
||||
|
||||
# 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, layer, entities, &convert_to_native)
|
||||
@@ -49,11 +62,7 @@ module SpeckleConnector
|
||||
obj['name'] = get_definition_name(obj)
|
||||
|
||||
state, _definitions = BlockDefinition.to_native(
|
||||
state,
|
||||
obj,
|
||||
layer,
|
||||
entities,
|
||||
&convert_to_native
|
||||
state, obj, layer, entities, &convert_to_native
|
||||
)
|
||||
|
||||
definition = state.sketchup_state.sketchup_model.definitions[BlockDefinition.get_definition_name(obj)]
|
||||
@@ -62,7 +71,7 @@ module SpeckleConnector
|
||||
t_arr = obj['transform']
|
||||
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.name = get_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)
|
||||
@@ -70,15 +79,23 @@ module SpeckleConnector
|
||||
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|
|
||||
# Mullions is a special case here, they are extracted as base object with @displayValue from revit..
|
||||
if element['@displayValue'].nil?
|
||||
obj['geometry'].append(element)
|
||||
else
|
||||
obj['geometry'] += element['@displayValue']
|
||||
elements = obj['elements'] || obj['@elements']
|
||||
|
||||
# if only elements are there then assign only elements, there are some cases that RevitWalls can only
|
||||
# have elements instead of display value
|
||||
if obj['geometry'].nil? && !elements.nil?
|
||||
obj['geometry'] = elements
|
||||
else
|
||||
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)
|
||||
else
|
||||
obj['geometry'] += element['@displayValue']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ module SpeckleConnector
|
||||
SPECKLE_TYPE = 'Speckle.Core.Models.Collection'
|
||||
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def initialize(name:, visible:, is_folder:, line_style: nil, color: nil, layers_and_folders: [],
|
||||
def initialize(name:, visible:, is_folder:, full_path: nil, line_style: nil, color: nil, layers_and_folders: [],
|
||||
application_id: nil)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
@@ -23,6 +23,7 @@ module SpeckleConnector
|
||||
self[:color] = color
|
||||
self[:visible] = visible
|
||||
self[:is_folder] = is_folder
|
||||
self[:full_path] = full_path unless full_path.nil?
|
||||
self[:line_style] = line_style unless line_style.nil?
|
||||
self[:collectionType] = 'layer'
|
||||
self[:elements] = layers_and_folders if layers_and_folders.any?
|
||||
@@ -43,14 +44,31 @@ module SpeckleConnector
|
||||
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? }
|
||||
# Flat layer conversion.
|
||||
def self.to_native_flat_layers(layers_relation, sketchup_model)
|
||||
speckle_layers = layers_relation[:elements]
|
||||
|
||||
elements_to_layers(speckle_layers, sketchup_model)
|
||||
end
|
||||
|
||||
# Converts elements to layers with it's full path.
|
||||
def self.elements_to_layers(elements, sketchup_model)
|
||||
elements.each do |element|
|
||||
element[:name] = element[:full_path]
|
||||
to_native_layer(element, sketchup_model.layers, sketchup_model)
|
||||
elements_to_layers(element[:elements], sketchup_model) unless element[:elements].nil?
|
||||
end
|
||||
end
|
||||
|
||||
# Nested layer conversion with folders.
|
||||
def self.to_native_layer_folder(layers_relation, folder, sketchup_model)
|
||||
speckle_layers = layers_relation[: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 = layers_relation[:elements].reject { |layer_or_fol| layer_or_fol[:elements].nil? }
|
||||
|
||||
speckle_folders.each do |speckle_folder|
|
||||
sub_folder = folder.add_folder(speckle_folder[:name])
|
||||
|
||||
@@ -22,26 +22,18 @@ 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)
|
||||
# Extract relations from commit obj to create layers in advance.
|
||||
# By doing this, also checks layers will be created as flat list or nested structure according to source app.
|
||||
# @param commit_obj [Hash] commit object to extract layer relations.
|
||||
# @param source_app [String] source application to decide layer creation strategy.
|
||||
# Currently for
|
||||
# - Revit: we don't create layers in advance because we create layers according to categories.
|
||||
# - SketchUp: we create layers in advance as nested.
|
||||
# - Rhino: we create layers in advance as flat list with it's full path.
|
||||
def self.extract_relations(commit_obj, source_app)
|
||||
return nil unless commit_obj['speckle_type'] == SPECKLE_CORE_MODELS_COLLECTION
|
||||
|
||||
elements = element_to_relation(commit_obj['elements'])
|
||||
elements = element_to_relation(commit_obj['elements'], source_app, [])
|
||||
|
||||
Layers.new(
|
||||
active: commit_obj['active_layer'],
|
||||
@@ -49,10 +41,41 @@ module SpeckleConnector
|
||||
)
|
||||
end
|
||||
|
||||
def self.to_native(layers_relation, sketchup_model)
|
||||
folder = sketchup_model.layers
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def self.element_to_relation(elements, source_app, parent_layers)
|
||||
elements.collect do |element|
|
||||
next unless element['speckle_type'] == SPECKLE_CORE_MODELS_COLLECTION
|
||||
|
||||
SpeckleObjects::Relations::Layer.to_native_layer_folder(layers_relation, folder, sketchup_model)
|
||||
layers_tree = parent_layers.dup.append(element['name'])
|
||||
full_path = ''
|
||||
parent_layers.each { |parent| full_path += "#{parent}::" }
|
||||
full_path += element['name']
|
||||
# Add this info to commit object to check later layer_collection conversion
|
||||
element['full_path'] = full_path if source_app.include?('rhino')
|
||||
|
||||
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, full_path: full_path,
|
||||
layers_and_folders: element_to_relation(element['elements'], source_app, layers_tree)
|
||||
)
|
||||
end.compact
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
|
||||
def self.to_native(obj, source_app, sketchup_model)
|
||||
layers_relation = extract_relations(obj, source_app)
|
||||
return if layers_relation.nil?
|
||||
|
||||
folder = sketchup_model.layers
|
||||
is_flat = source_app.include?('rhino')
|
||||
|
||||
if is_flat
|
||||
SpeckleObjects::Relations::Layer.to_native_flat_layers(layers_relation, sketchup_model)
|
||||
else
|
||||
SpeckleObjects::Relations::Layer.to_native_layer_folder(layers_relation, folder, sketchup_model)
|
||||
end
|
||||
|
||||
active_layer = folder.to_a.find { |layer| layer.display_name == layers_relation['active_layer'] }
|
||||
sketchup_model.active_layer = active_layer unless active_layer.nil?
|
||||
|
||||
@@ -15,8 +15,10 @@ module SpeckleConnector
|
||||
family = def_obj['family']
|
||||
type = def_obj['type']
|
||||
category = def_obj['category']
|
||||
element_id = def_obj['elementId']
|
||||
id = def_obj['id']
|
||||
|
||||
return "#{family}-#{type}-#{category}-#{def_obj['elementId']}"
|
||||
return "#{family}-#{type}-#{category}-#{element_id}-#{id}"
|
||||
end
|
||||
|
||||
def self.to_native(state, definition, layer, entities, &convert_to_native)
|
||||
|
||||
@@ -31,10 +31,8 @@ module SpeckleConnector
|
||||
|
||||
if collection_type.include?('model')
|
||||
ModelCollection.to_native(state, collection, layer, entities, &convert_to_native)
|
||||
elsif ['layer', 'Revit Category'].include?(collection_type)
|
||||
LayerCollection.to_native(state, collection, layer, entities, &convert_to_native)
|
||||
else
|
||||
return state, []
|
||||
LayerCollection.to_native(state, collection, layer, entities, &convert_to_native)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,12 +99,13 @@ module SpeckleConnector
|
||||
sketchup_model = state.sketchup_state.sketchup_model
|
||||
elements = layer_collection['elements']
|
||||
name = layer_collection['name']
|
||||
name = layer_collection['full_path'] if layer_collection['full_path']
|
||||
|
||||
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)
|
||||
new_state, _converted_entities = convert_to_native.call(state, element, layer_or_folder, entities)
|
||||
state = new_state
|
||||
end
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ require_relative 'collection'
|
||||
require_relative 'layer_collection'
|
||||
require_relative '../../../built_elements/view3d'
|
||||
require_relative '../../../built_elements/revit/direct_shape'
|
||||
require_relative '../../../../mapper/mapper'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
@@ -13,7 +14,9 @@ module SpeckleConnector
|
||||
# ModelCollection object that collect other speckle objects under it's elements.
|
||||
class ModelCollection < Collection
|
||||
DIRECT_SHAPE = SpeckleObjects::BuiltElements::Revit::DirectShape
|
||||
QUERY = SketchupModel::Query
|
||||
VIEW3D = SpeckleObjects::BuiltElements::View3d
|
||||
SPECKLE_SCHEMA_DICTIONARY_HANDLER = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler
|
||||
def initialize(name:, active_layer:, elements: [], application_id: nil)
|
||||
super(
|
||||
name: name,
|
||||
@@ -31,7 +34,8 @@ module SpeckleConnector
|
||||
)
|
||||
|
||||
# Direct shapes will pass directly to elements which are already flattened with all children
|
||||
model_collection[:elements] += collect_direct_shapes(sketchup_model, units, preferences)
|
||||
model_collection[:elements] += collect_mapped_entities(speckle_state, sketchup_model, units,
|
||||
preferences, &convert)
|
||||
|
||||
# Views will pass directly to elements since they don't have any relation with layers and geometries.
|
||||
model_collection[:elements] += VIEW3D.from_model(sketchup_model, units) if sketchup_model.pages.any?
|
||||
@@ -52,13 +56,11 @@ module SpeckleConnector
|
||||
return speckle_state, model_collection
|
||||
end
|
||||
|
||||
def self.collect_direct_shapes(sketchup_model, units, preferences)
|
||||
DIRECT_SHAPE.direct_shapes_on_selection(sketchup_model).collect do |entities|
|
||||
entity = entities[0]
|
||||
path = entities[1..-1]
|
||||
|
||||
direct_shape = DIRECT_SHAPE.from_entity(entity, path, units, preferences)
|
||||
[direct_shape, [entity]]
|
||||
# @param sketchup_model [Sketchup::Model] active model to retrieve and convert mapped entities.
|
||||
def self.collect_mapped_entities(speckle_state, sketchup_model, units, preferences, &convert)
|
||||
mapped_entities = Mapper.mapped_entities_on_selection(sketchup_model)
|
||||
mapped_entities.collect do |entity_with_path|
|
||||
convert_mapped_entity(speckle_state, entity_with_path, preferences, units)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,7 +68,7 @@ module SpeckleConnector
|
||||
elements = model_collection['elements']
|
||||
|
||||
elements.each do |element|
|
||||
new_state = convert_to_native.call(state, element, layer, entities)
|
||||
new_state, _converted_entities = convert_to_native.call(state, element, layer, entities)
|
||||
state = new_state
|
||||
end
|
||||
|
||||
@@ -75,6 +77,24 @@ module SpeckleConnector
|
||||
|
||||
return state, []
|
||||
end
|
||||
|
||||
def self.convert_mapped_entity(speckle_state, entity_with_path, preferences, units)
|
||||
entity = entity_with_path[0]
|
||||
path = entity_with_path[1..-1]
|
||||
|
||||
method = SPECKLE_SCHEMA_DICTIONARY_HANDLER.get_attribute(entity, 'method')
|
||||
|
||||
if !method.nil? && (method.include?('Floor') || method.include?('Wall')) && entity.is_a?(Sketchup::Face)
|
||||
global_transformation = QUERY::Entity.global_transformation(entity, path)
|
||||
floor = SpeckleObjects::Geometry::Mesh.from_face(speckle_state: speckle_state, face: entity,
|
||||
units: units, model_preferences: preferences,
|
||||
global_transform: global_transformation)
|
||||
return [floor, [entity]]
|
||||
end
|
||||
|
||||
direct_shape = DIRECT_SHAPE.from_entity(speckle_state, entity, path, units, preferences)
|
||||
return [direct_shape, [entity]]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../immutable/immutable'
|
||||
require_relative '../callbacks/callback_message'
|
||||
require_relative '../speckle_entities/speckle_entity'
|
||||
require_relative '../mapper/mapper_source'
|
||||
|
||||
module SpeckleConnector
|
||||
module States
|
||||
# State of the speckle on ruby.
|
||||
class SpeckleMapperState
|
||||
include Immutable::ImmutableUtils
|
||||
|
||||
# @return [ImmutableHash{Integer=>Sketchup::Entity}] persistent_id of the sketchup entity and itself
|
||||
attr_reader :mapped_entities
|
||||
|
||||
# @return [Mapper::MapperSource] source of the mapper.
|
||||
attr_reader :mapper_source
|
||||
|
||||
def initialize
|
||||
@mapped_entities = Immutable::EmptyHash
|
||||
@mapper_source = nil
|
||||
end
|
||||
|
||||
def with_mapped_entity(entity)
|
||||
new_mapped_entities = mapped_entities.put(entity.persistent_id, entity)
|
||||
with_mapped_entities(new_mapped_entities)
|
||||
end
|
||||
|
||||
def with_removed_mapped_entity(entity)
|
||||
new_mapped_entities = mapped_entities.delete(entity.persistent_id)
|
||||
with_mapped_entities(new_mapped_entities)
|
||||
end
|
||||
|
||||
def with_mapped_entities(new_mapped_entities)
|
||||
with(:@mapped_entities => new_mapped_entities)
|
||||
end
|
||||
|
||||
def with_mapper_source(mapper_source)
|
||||
# TODO: Check/Sync here parameters of the mapped entities.
|
||||
with(:@mapper_source => mapper_source)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'speckle_mapper_state'
|
||||
require_relative '../immutable/immutable'
|
||||
require_relative '../callbacks/callback_message'
|
||||
require_relative '../speckle_entities/speckle_entity'
|
||||
@@ -10,13 +11,13 @@ module SpeckleConnector
|
||||
class SpeckleState
|
||||
include Immutable::ImmutableUtils
|
||||
|
||||
# @return [States::SpeckleMapperState] state of the mapper.
|
||||
attr_reader :speckle_mapper_state
|
||||
|
||||
# @return [ImmutableHash{Integer=>SpeckleEntities::SpeckleEntity}] persistent_id of the sketchup entity and
|
||||
# corresponding speckle entity
|
||||
attr_reader :speckle_entities
|
||||
|
||||
# @return [ImmutableHash{Integer=>Sketchup::Entity}] persistent_id of the sketchup entity and itself
|
||||
attr_reader :mapped_entities
|
||||
|
||||
# @return [Array] accounts on appdata.
|
||||
attr_reader :accounts
|
||||
|
||||
@@ -47,10 +48,10 @@ module SpeckleConnector
|
||||
@message_queue = queue
|
||||
@stream_queue = stream_queue
|
||||
@speckle_entities = Immutable::EmptyHash
|
||||
@mapped_entities = Immutable::EmptyHash
|
||||
@render_materials = Immutable::EmptyHash
|
||||
@definitions = Immutable::EmptyHash
|
||||
@relation = Relations::ManyToOneRelation.new
|
||||
@speckle_mapper_state = SpeckleMapperState.new
|
||||
end
|
||||
|
||||
# @param callback_name [String] name of the callback command
|
||||
@@ -68,13 +69,13 @@ module SpeckleConnector
|
||||
with(:@message_queue => new_queue)
|
||||
end
|
||||
|
||||
def with_selection_queue(selection_parameters)
|
||||
def with_mapper_selection_queue(selection_parameters)
|
||||
new_queue = message_queue.merge({ "entitySelected":
|
||||
"entitySelected(#{JSON.generate(selection_parameters)})" })
|
||||
with(:@message_queue => new_queue)
|
||||
end
|
||||
|
||||
def with_deselection_queue
|
||||
def with_mapper_deselection_queue
|
||||
new_queue = message_queue.merge({ "entitiesDeselected": 'entitiesDeselected()' })
|
||||
with(:@message_queue => new_queue)
|
||||
end
|
||||
@@ -95,14 +96,29 @@ module SpeckleConnector
|
||||
with(:@accounts => new_accounts)
|
||||
end
|
||||
|
||||
def with_mapper_source(mapper_source)
|
||||
new_speckle_mapper_state = speckle_mapper_state.with_mapper_source(mapper_source)
|
||||
with(:@speckle_mapper_state => new_speckle_mapper_state)
|
||||
end
|
||||
|
||||
def with_removed_mapper_source
|
||||
new_speckle_mapper_state = speckle_mapper_state.with_mapper_source(nil)
|
||||
with(:@speckle_mapper_state => new_speckle_mapper_state)
|
||||
end
|
||||
|
||||
def with_mapped_entity(entity)
|
||||
new_mapped_entities = mapped_entities.put(entity.persistent_id, entity)
|
||||
with_mapped_entities(new_mapped_entities)
|
||||
new_speckle_mapper_state = speckle_mapper_state.with_mapped_entity(entity)
|
||||
with(:@speckle_mapper_state => new_speckle_mapper_state)
|
||||
end
|
||||
|
||||
def with_removed_mapped_entity(entity)
|
||||
new_mapped_entities = mapped_entities.delete(entity.persistent_id)
|
||||
with_mapped_entities(new_mapped_entities)
|
||||
new_speckle_mapper_state = speckle_mapper_state.with_removed_mapped_entity(entity)
|
||||
with(:@speckle_mapper_state => new_speckle_mapper_state)
|
||||
end
|
||||
|
||||
def with_mapped_entities(new_mapped_entities)
|
||||
new_speckle_mapper_state = speckle_mapper_state.with_mapped_entities(new_mapped_entities)
|
||||
with(:@speckle_mapper_state => new_speckle_mapper_state)
|
||||
end
|
||||
|
||||
def with_speckle_entity(traversed_entity)
|
||||
@@ -114,10 +130,6 @@ module SpeckleConnector
|
||||
with(:@speckle_entities => new_speckle_entities)
|
||||
end
|
||||
|
||||
def with_mapped_entities(new_mapped_entities)
|
||||
with(:@mapped_entities => new_mapped_entities)
|
||||
end
|
||||
|
||||
def with_relation(new_relation)
|
||||
with(:@relation => new_relation)
|
||||
end
|
||||
|
||||
@@ -41,11 +41,11 @@ module SpeckleConnector
|
||||
with(:@speckle_state => new_speckle_state)
|
||||
end
|
||||
|
||||
def with_selection_queue(selection_parameters)
|
||||
def with_mapper_selection_queue(selection_parameters)
|
||||
new_speckle_state = if selection_parameters[:selection].any?
|
||||
speckle_state.with_selection_queue(selection_parameters)
|
||||
speckle_state.with_mapper_selection_queue(selection_parameters)
|
||||
else
|
||||
speckle_state.with_deselection_queue
|
||||
speckle_state.with_mapper_deselection_queue
|
||||
end
|
||||
with(:@speckle_state => new_speckle_state)
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@ require_relative '../commands/model_preferences_updated'
|
||||
require_relative '../commands/activate_diffing'
|
||||
require_relative '../commands/apply_mappings'
|
||||
require_relative '../commands/clear_mappings'
|
||||
require_relative '../commands/mapper_source_updated'
|
||||
|
||||
require_relative '../actions/reload_accounts'
|
||||
require_relative '../actions/load_saved_streams'
|
||||
@@ -29,6 +30,7 @@ require_relative '../actions/isolate_mappings_from_table'
|
||||
require_relative '../actions/hide_mappings_from_table'
|
||||
require_relative '../actions/select_mappings_from_table'
|
||||
require_relative '../actions/show_all_entities'
|
||||
require_relative '../actions/clear_mapper_source'
|
||||
|
||||
module SpeckleConnector
|
||||
module Ui
|
||||
@@ -89,7 +91,9 @@ module SpeckleConnector
|
||||
isolate_mappings_from_table: Commands::ActionCommand.new(@app, Actions::IsolateMappingsFromTable),
|
||||
hide_mappings_from_table: Commands::ActionCommand.new(@app, Actions::HideMappingsFromTable),
|
||||
select_mappings_from_table: Commands::ActionCommand.new(@app, Actions::SelectMappingsFromTable),
|
||||
show_all_entities: Commands::ActionCommand.new(@app, Actions::ShowAllEntities)
|
||||
show_all_entities: Commands::ActionCommand.new(@app, Actions::ShowAllEntities),
|
||||
mapper_source_updated: Commands::MapperSourceUpdated.new(@app),
|
||||
clear_mapper_source: Commands::ActionCommand.new(@app, Actions::ClearMapperSource)
|
||||
}.freeze
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
@@ -232,22 +232,27 @@ export default {
|
||||
// }
|
||||
},
|
||||
clearMappingsFromTableSelection(){
|
||||
sketchup.exec({ name: "clear_mappings_from_table", data: this.elementSelection })
|
||||
sketchup.exec({ name: "clear_mappings_from_table", data: this.elementSelection })
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Clear' })
|
||||
},
|
||||
isolateMappedElementsOnSketchup(){
|
||||
if (this.isIsolated){
|
||||
this.isIsolated = false
|
||||
sketchup.exec({ name: "show_all_entities", data: {} })
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Un-Isolate' })
|
||||
} else {
|
||||
this.isIsolated = true
|
||||
sketchup.exec({ name: "isolate_mappings_from_table", data: this.elementSelection })
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Isolate' })
|
||||
}
|
||||
},
|
||||
hideMappedElementsOnSketchup(){
|
||||
sketchup.exec({ name: "hide_mappings_from_table", data: this.elementSelection })
|
||||
sketchup.exec({ name: "hide_mappings_from_table", data: this.elementSelection })
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Hide' })
|
||||
},
|
||||
selectMappedElementsOnSketchup(){
|
||||
sketchup.exec({ name: "select_mappings_from_table", data: this.elementSelection })
|
||||
sketchup.exec({ name: "select_mappings_from_table", data: this.elementSelection })
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Select Elements' })
|
||||
},
|
||||
// Update mapped elements table whenever mapped elements has changed.
|
||||
getMappedElementsTableData(){
|
||||
|
||||
+343
-25
@@ -58,6 +58,41 @@
|
||||
</v-expansion-panel-content>
|
||||
</v-expansion-panel>
|
||||
|
||||
<v-expansion-panel key="source">
|
||||
<v-expansion-panel-header class="flex">
|
||||
<v-container class="ma-0 pa-0">
|
||||
<v-icon>
|
||||
mdi-source-branch
|
||||
</v-icon>
|
||||
{{ `Source` }}
|
||||
<v-tooltip right>
|
||||
<template #activator="{ on, attrs }">
|
||||
<v-btn
|
||||
class="ma-0 ml-1"
|
||||
height="20px"
|
||||
width="20px"
|
||||
icon
|
||||
x-small
|
||||
:color="getSourceStateIconColor()"
|
||||
v-bind="attrs"
|
||||
v-on="on"
|
||||
@click="refreshSourceBranch"
|
||||
>
|
||||
<v-icon>
|
||||
{{ getSourceStateIcon() }}
|
||||
</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
<span>{{ getSourceStateToolTip() }}</span>
|
||||
</v-tooltip>
|
||||
|
||||
</v-container>
|
||||
</v-expansion-panel-header>
|
||||
<v-expansion-panel-content>
|
||||
<mapper-source :source-state="this.sourceState"/>
|
||||
</v-expansion-panel-content>
|
||||
</v-expansion-panel>
|
||||
|
||||
<v-expansion-panel key="mapping">
|
||||
<v-expansion-panel-header>
|
||||
<div>
|
||||
@@ -124,12 +159,52 @@
|
||||
class="pt-0"
|
||||
label="Mapper Method"
|
||||
:disabled="!entitySelected"
|
||||
:items="enabledMethods"
|
||||
:items="availableMethods"
|
||||
density="compact"
|
||||
clearable
|
||||
@change="onSelectedMethodChange"
|
||||
></v-autocomplete>
|
||||
|
||||
<v-autocomplete
|
||||
v-if="familySelectionActive"
|
||||
v-model="selectedFamily"
|
||||
class="pt-0"
|
||||
label="Family"
|
||||
:disabled="!entitySelected"
|
||||
:items="families"
|
||||
density="compact"
|
||||
clearable
|
||||
@change="onSelectedFamilyChange"
|
||||
></v-autocomplete>
|
||||
|
||||
<v-autocomplete
|
||||
v-if="typeSelectionActive"
|
||||
v-model="selectedFamilyType"
|
||||
class="pt-0"
|
||||
label="Type"
|
||||
:disabled="!entitySelected"
|
||||
item-value="type"
|
||||
item-text="type"
|
||||
:items="familyTypes"
|
||||
density="compact"
|
||||
clearable
|
||||
></v-autocomplete>
|
||||
|
||||
<v-autocomplete
|
||||
v-if="levelSelectionActive"
|
||||
v-model="selectedLevel"
|
||||
class="pt-0"
|
||||
label="Base Level"
|
||||
:disabled="!entitySelected"
|
||||
:items="levels"
|
||||
item-value="name"
|
||||
item-text="name"
|
||||
density="compact"
|
||||
clearable
|
||||
></v-autocomplete>
|
||||
|
||||
<v-autocomplete
|
||||
v-if="categorySelectionActive"
|
||||
v-model="selectedCategory"
|
||||
class="pt-0"
|
||||
label="Category"
|
||||
@@ -142,6 +217,7 @@
|
||||
></v-autocomplete>
|
||||
|
||||
<v-text-field
|
||||
v-if="nameSelectionActive"
|
||||
v-model="name"
|
||||
class="pt-0"
|
||||
label="Name"
|
||||
@@ -153,6 +229,7 @@
|
||||
<v-row justify="center" align="center">
|
||||
<v-col cols="auto" class="pa-1 pb-2">
|
||||
<v-btn
|
||||
small
|
||||
:disabled="!entitySelected"
|
||||
@click="applyMapping"
|
||||
>
|
||||
@@ -163,6 +240,7 @@
|
||||
</v-col>
|
||||
<v-col cols="auto" class="pa-1 pb-2">
|
||||
<v-btn
|
||||
small
|
||||
:disabled="!entitySelected"
|
||||
@click="clearMapping"
|
||||
>
|
||||
@@ -173,10 +251,7 @@
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
|
||||
</v-container>
|
||||
|
||||
|
||||
</v-expansion-panel-content>
|
||||
</v-expansion-panel>
|
||||
|
||||
@@ -204,6 +279,12 @@
|
||||
/*global sketchup*/
|
||||
import {bus} from "@/main";
|
||||
import {groupBy} from "@/utils/groupBy";
|
||||
import MappingSource from "@/components/MapperSource.vue";
|
||||
import {sourceMap} from "@vue/cli-service/lib/config/terserOptions";
|
||||
|
||||
global.mapperSourceUpdated = function (streamId, levels, types) {
|
||||
console.log(`Mapper source updated for ${streamId}.`)
|
||||
}
|
||||
|
||||
global.entitySelected = function (selectionParameters) {
|
||||
bus.$emit('entities-selected', JSON.stringify(selectionParameters))
|
||||
@@ -220,11 +301,24 @@ global.mappedEntitiesUpdated = function (mappedEntities) {
|
||||
export default {
|
||||
name: "Mapper",
|
||||
components: {
|
||||
MapperSource: () => import('@/components/MapperSource.vue'),
|
||||
GlobalToast: () => import('@/components/GlobalToast'),
|
||||
MappedElements: () => import('@/components/MappedElements.vue')
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
nativeFaceMethods: ['Floor', 'Wall'],
|
||||
nativeEdgeMethods: ['Column', 'Beam', 'Brace', 'Pipe', 'Duct'],
|
||||
nativeDefaultFaceMethods: ['Default Floor', 'Default Wall'],
|
||||
nativeDefaultEdgeMethods: ['Default Column', 'Default Beam', 'Default Brace', 'Default Pipe', 'Default Duct'],
|
||||
|
||||
familySelectionActive: false,
|
||||
typeSelectionActive: false,
|
||||
levelSelectionActive: false,
|
||||
categorySelectionActive: false,
|
||||
nameSelectionActive: false,
|
||||
|
||||
sourceState: 'Not Set',
|
||||
// Expanded indexes for selection table (Types)
|
||||
selectionExpandedIndexes: [],
|
||||
// Expanded indexes for mapped element table (Categories)
|
||||
@@ -239,15 +333,26 @@ export default {
|
||||
entitySelected: false,
|
||||
selectedEntityCount: 0,
|
||||
selectedEntities: [],
|
||||
allFamilyTypes: {},
|
||||
familyTypes: [],
|
||||
lastSelectedEntity: null,
|
||||
|
||||
selectedMethod: null,
|
||||
selectedCategory: null,
|
||||
selectedFamily: null,
|
||||
selectedFamilyType: null,
|
||||
selectedLevel: null,
|
||||
name: "",
|
||||
enabledMethods: [],
|
||||
|
||||
availableMethods: [],
|
||||
availableCategories: [],
|
||||
families: [],
|
||||
allTypes: {},
|
||||
levels: [],
|
||||
|
||||
mappedEntityCount: 0,
|
||||
mappedEntities: [],
|
||||
panel: [1],
|
||||
panel: [2],
|
||||
selectionHeaders: [
|
||||
{ text: 'Type', sortable: false, value: 'entityType', width: '60%' },
|
||||
{ text: 'Count', sortable: false, align: 'center', value: 'count', width: '20%' },
|
||||
@@ -354,8 +459,145 @@ export default {
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
getSourceStateIcon(){
|
||||
switch (this.sourceState){
|
||||
case "Not Set":
|
||||
return `mdi-cloud-off-outline`;
|
||||
case "Set":
|
||||
return `mdi-checkbox-marked-circle-outline`;
|
||||
case "Outdated":
|
||||
return `mdi-update`;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
getSourceStateToolTip(){
|
||||
switch (this.sourceState){
|
||||
case "Not Set":
|
||||
return 'Source disconnected.';
|
||||
case "Set":
|
||||
return 'Source connected.';
|
||||
case "Outdated":
|
||||
return 'Source branch is not up-to-date!';
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
getSourceStateIconColor(){
|
||||
switch (this.sourceState){
|
||||
case "Not Set":
|
||||
return `grey`;
|
||||
case "Set":
|
||||
return `green`;
|
||||
case "Outdated":
|
||||
return `red`;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
onSelectedMethodChange(){
|
||||
this.hideOptionalMappingInputs()
|
||||
this.updateMappingInputs()
|
||||
this.getFamiliesFromSelectedMethod()
|
||||
this.getTypesFromSelectedFamily()
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Set', schema: this.selectedMethod })
|
||||
},
|
||||
onSelectedFamilyChange(){
|
||||
this.getTypesFromSelectedFamily();
|
||||
},
|
||||
updateMappingInputs(){
|
||||
if (this.selectedMethod === null){
|
||||
this.typeSelectionActive = false
|
||||
this.familySelectionActive = false
|
||||
this.levelSelectionActive = false
|
||||
this.categorySelectionActive = false
|
||||
this.nameSelectionActive = false
|
||||
return
|
||||
}
|
||||
const nativeDefaultMethods = this.nativeDefaultEdgeMethods.concat(this.nativeDefaultFaceMethods)
|
||||
const nativeMethods = this.nativeEdgeMethods.concat(this.nativeFaceMethods)
|
||||
|
||||
if (this.selectedMethod === 'Direct Shape'){
|
||||
this.categorySelectionActive = true
|
||||
this.nameSelectionActive = true
|
||||
}
|
||||
else if (nativeDefaultMethods.includes(this.selectedMethod)){
|
||||
this.typeSelectionActive = false
|
||||
this.familySelectionActive = false
|
||||
this.levelSelectionActive = false
|
||||
this.categorySelectionActive = false
|
||||
this.nameSelectionActive = false
|
||||
}
|
||||
else if (nativeMethods.includes(this.selectedMethod)){
|
||||
this.typeSelectionActive = true
|
||||
this.familySelectionActive = true
|
||||
this.levelSelectionActive = true
|
||||
}
|
||||
},
|
||||
getTypesFromSelectedFamily(){
|
||||
this.familyTypes = this.allFamilyTypes[this.selectedFamily]
|
||||
this.selectedFamilyType = this.familyTypes[0].type
|
||||
if (this.selectedFamily === null || this.selectedFamily === undefined){
|
||||
this.selectedFamily = this.families[0]
|
||||
}
|
||||
if (this.familyTypes === null ||this.familyTypes === undefined){
|
||||
this.familyTypes = this.allFamilyTypes[this.selectedFamily]
|
||||
}
|
||||
if (this.selectedFamilyType === null || this.selectedFamilyType === undefined){
|
||||
this.selectedFamilyType = this.familyTypes[0].type
|
||||
}
|
||||
},
|
||||
getFamiliesFromSelectedMethod(){
|
||||
switch (this.selectedMethod) {
|
||||
case 'Floor':
|
||||
this.families = Object.keys(this.allTypes['Floors']);
|
||||
this.allFamilyTypes = this.allTypes['Floors']
|
||||
break;
|
||||
case 'Wall':
|
||||
this.families = Object.keys(this.allTypes['Walls']);
|
||||
this.allFamilyTypes = this.allTypes['Walls']
|
||||
break;
|
||||
case 'Column':
|
||||
this.families = Object.keys(this.allTypes['Columns']);
|
||||
this.allFamilyTypes = this.allTypes['Columns']
|
||||
break;
|
||||
case 'Beam':
|
||||
this.families = Object.keys(this.allTypes['Beams']);
|
||||
this.allFamilyTypes = this.allTypes['Beams']
|
||||
break;
|
||||
case 'Pipe':
|
||||
this.families = Object.keys(this.allTypes['Piping System']);
|
||||
this.allFamilyTypes = this.allTypes['Piping System']
|
||||
break;
|
||||
case 'Duct':
|
||||
this.families = Object.keys(this.allTypes['Duct System']);
|
||||
this.allFamilyTypes = this.allTypes['Duct System']
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (this.selectedFamily === null || this.selectedFamily === undefined){
|
||||
this.selectedFamily = this.families[0]
|
||||
}
|
||||
if (this.selectedLevel === null || this.selectedLevel === undefined){
|
||||
this.selectedLevel = this.levels[0].name
|
||||
}
|
||||
},
|
||||
hideOptionalMappingInputs(){
|
||||
this.categorySelectionActive = false
|
||||
this.nameSelectionActive = false
|
||||
this.typeSelectionActive = false
|
||||
this.familySelectionActive = false
|
||||
this.levelSelectionActive = false
|
||||
},
|
||||
refreshSourceBranch(){
|
||||
if (this.sourceState === 'Outdated'){
|
||||
bus.$emit('refresh-source-branch')
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Source Update' })
|
||||
}
|
||||
},
|
||||
clearInputs(){
|
||||
this.enabledMethods = []
|
||||
this.availableMethods = []
|
||||
this.availableCategories = []
|
||||
this.selectedEntities = []
|
||||
this.selectionTableData = []
|
||||
@@ -365,6 +607,11 @@ export default {
|
||||
this.selectedCategory = null
|
||||
this.entityMapped = false
|
||||
this.definitionMapped = false
|
||||
this.selectedLevel = null
|
||||
this.selectedFamily = null
|
||||
this.selectedFamilyType = null
|
||||
this.allTypes = null
|
||||
this.familyTypes = null
|
||||
},
|
||||
getSelectionTableData(){
|
||||
let groupByClass = groupBy('entityType')
|
||||
@@ -403,12 +650,12 @@ export default {
|
||||
return summary
|
||||
},
|
||||
setInputValuesFromSelection(){
|
||||
// Clear all inputs if entity is not selected.
|
||||
if (!this.entitySelected){
|
||||
this.name = ""
|
||||
this.selectedMethod = null
|
||||
this.selectedCategory = null
|
||||
this.clearMappingInputs()
|
||||
return
|
||||
}
|
||||
// Check if definition card is selected and set definition mappings.
|
||||
if (this.definitionSelected) {
|
||||
if (!this.definitionMapped){
|
||||
if (this.selectedEntityCount > 1){
|
||||
@@ -416,7 +663,7 @@ export default {
|
||||
}else{
|
||||
this.name = this.lastSelectedEntity['definition']['entityName']
|
||||
}
|
||||
this.selectedMethod = 'Direct Shape'
|
||||
// this.selectedMethod = 'Direct Shape'
|
||||
this.selectedCategory = 49
|
||||
} else {
|
||||
if (this.selectedEntityCount > 1){
|
||||
@@ -427,14 +674,20 @@ export default {
|
||||
this.selectedMethod = this.lastSelectedEntity['definition']['schema']['method']
|
||||
this.selectedCategory = this.lastSelectedEntity['definition']['schema']['category']
|
||||
}
|
||||
} else {
|
||||
}
|
||||
// Otherwise set entity mappings.
|
||||
else
|
||||
{
|
||||
if (!this.entityMapped){
|
||||
if (this.selectedEntityCount > 1){
|
||||
this.name = '<Mixed>'
|
||||
}else{
|
||||
this.name = this.lastSelectedEntity['entityName']
|
||||
}
|
||||
this.selectedMethod = 'Direct Shape'
|
||||
console.log("entity not mapped")
|
||||
this.updateMappingInputs()
|
||||
this.getFamiliesFromSelectedMethod()
|
||||
this.getTypesFromSelectedFamily()
|
||||
this.selectedCategory = 49
|
||||
} else {
|
||||
if (this.selectedEntityCount > 1){
|
||||
@@ -443,7 +696,14 @@ export default {
|
||||
this.name = this.lastSelectedEntity['schema']['name']
|
||||
}
|
||||
this.selectedMethod = this.lastSelectedEntity['schema']['method']
|
||||
console.log("entity is mapped")
|
||||
this.updateMappingInputs()
|
||||
this.selectedFamily = this.lastSelectedEntity['schema']['family']
|
||||
this.selectedCategory = this.lastSelectedEntity['schema']['category']
|
||||
this.getFamiliesFromSelectedMethod()
|
||||
this.getTypesFromSelectedFamily()
|
||||
this.selectedFamilyType = this.lastSelectedEntity['schema']['family_type']
|
||||
this.selectedLevel = this.lastSelectedEntity['schema']['level']
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -482,10 +742,29 @@ export default {
|
||||
this.mappedElementsExpandedIndexes.push(slotData.item);
|
||||
}
|
||||
},
|
||||
inputsReadyToApply(){
|
||||
if (this.selectedMethod === null || this.selectedMethod === undefined){
|
||||
return false;
|
||||
}
|
||||
|
||||
const nativeMethods = this.nativeEdgeMethods.concat(this.nativeFaceMethods)
|
||||
|
||||
if (this.selectedMethod === 'Direct Shape'){
|
||||
return this.selectedCategory !== null
|
||||
}
|
||||
else if (nativeMethods.includes(this.selectedMethod)){
|
||||
return this.selectedFamily !== null &&
|
||||
this.selectedFamilyType !== null &&
|
||||
this.selectedLevel !== null
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
applyMapping(){
|
||||
if (this.selectedMethod === null || this.selectedCategory === null){
|
||||
if (!this.inputsReadyToApply()){
|
||||
this.$eventHub.$emit('error', {
|
||||
text: 'Method and category are not set.\n'
|
||||
text: 'Some inputs are not set to apply mapping.\n'
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -493,6 +772,9 @@ export default {
|
||||
entitiesToMap: this.selectedEntities.map((entity) => entity['entityId']),
|
||||
method: this.selectedMethod,
|
||||
category: this.selectedCategory,
|
||||
family: this.selectedFamily,
|
||||
familyType: this.selectedFamilyType,
|
||||
level: this.selectedLevel,
|
||||
name: this.name,
|
||||
isDefinition: this.definitionSelected
|
||||
}
|
||||
@@ -500,6 +782,8 @@ export default {
|
||||
this.$eventHub.$emit('success', {
|
||||
text: 'Mapping Applied.\n'
|
||||
})
|
||||
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Applied' })
|
||||
},
|
||||
clearMapping(){
|
||||
const mapping = {
|
||||
@@ -511,32 +795,66 @@ export default {
|
||||
this.$eventHub.$emit('error', {
|
||||
text: 'Mapping Cleared.\n'
|
||||
})
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
sketchup.exec({name: "collect_mapped_entities", data: {}})
|
||||
|
||||
bus.$on('entities-selected', async (selectionParameters) => {
|
||||
const selectionPars = JSON.parse(selectionParameters)
|
||||
this.enabledMethods = selectionPars.mappingMethods
|
||||
this.availableCategories = selectionPars.categories
|
||||
this.selectedEntities = selectionPars.selection
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Clear' })
|
||||
},
|
||||
clearMappingInputs(){
|
||||
this.selectedMethod = null
|
||||
this.selectedCategory = null
|
||||
this.name = ""
|
||||
this.selectedFamily = null
|
||||
this.selectedFamilyType = null
|
||||
this.selectedLevel = null
|
||||
this.familyTypes = null
|
||||
this.levels = null
|
||||
this.availableMethods = null
|
||||
this.availableCategories = null
|
||||
this.allTypes = null
|
||||
},
|
||||
getDataFromSelection(selectionParameters){
|
||||
this.availableMethods = selectionParameters.mappingMethods
|
||||
this.availableCategories = selectionParameters.categories
|
||||
this.selectedEntities = selectionParameters.selection
|
||||
this.allTypes = selectionParameters.types
|
||||
this.levels = selectionParameters.levels
|
||||
this.selectedLevel = selectionParameters.selectedLevelName
|
||||
},
|
||||
updateStatesFromSelectionData(){
|
||||
this.lastSelectedEntity = this.selectedEntities[this.selectedEntities.length - 1]
|
||||
this.entityMapped = this.isEntitiesMapped(this.selectedEntities)
|
||||
this.definitionMapped = this.isEntityDefinitionsMapped(this.selectedEntities)
|
||||
this.definitionSelected = !this.entityMapped && this.definitionMapped
|
||||
this.selectedEntityCount = this.selectedEntities.length
|
||||
this.entitySelected = this.selectedEntityCount !== 0
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
sketchup.exec({name: "collect_mapped_entities", data: {}})
|
||||
|
||||
bus.$on('entities-selected', async (selectionParameters) => {
|
||||
// Parse data to json object
|
||||
const selectionPars = JSON.parse(selectionParameters)
|
||||
// Reset mapping inputs with nulls and empties.
|
||||
this.clearMappingInputs()
|
||||
// Get data from selection into objects and arrays. These data basically constructs the dropdowns.
|
||||
this.getDataFromSelection(selectionPars)
|
||||
// Update inner state of the mapper component according to selection data.
|
||||
this.updateStatesFromSelectionData()
|
||||
// Get selection table data.
|
||||
this.getSelectionTableData()
|
||||
// Set mapping input values from selection data.
|
||||
this.setInputValuesFromSelection()
|
||||
})
|
||||
bus.$on('entities-deselected', async () => {
|
||||
this.entitySelected = false
|
||||
this.clearInputs()
|
||||
this.hideOptionalMappingInputs()
|
||||
})
|
||||
bus.$on('mapped-entities-updated', async (mappedEntities) => {
|
||||
this.mappedEntityCount = mappedEntities.length
|
||||
})
|
||||
bus.$on('set-source-up-to-date', (isUpToDate) => {
|
||||
this.sourceState = isUpToDate
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
<template>
|
||||
<v-container class="pa-0">
|
||||
<v-autocomplete
|
||||
v-model="sourceStreamId"
|
||||
label="Stream"
|
||||
:items="allStreamsList"
|
||||
item-text="name"
|
||||
item-value="id"
|
||||
density="compact"
|
||||
></v-autocomplete>
|
||||
|
||||
<v-autocomplete
|
||||
v-model="sourceBranchId"
|
||||
class="pt-0 mb-n5"
|
||||
label="Branch"
|
||||
:items="allBranchesList"
|
||||
:disabled="sourceStreamId === null"
|
||||
item-text="name"
|
||||
item-value="id"
|
||||
density="compact"
|
||||
></v-autocomplete>
|
||||
|
||||
<v-container class="pa-0 mt-2">
|
||||
<v-row justify="center" align="center">
|
||||
<v-col cols="auto" class="pa-1 pb-2">
|
||||
<v-btn
|
||||
small
|
||||
@click="applySource"
|
||||
>
|
||||
<v-icon dark left>
|
||||
mdi-checkbox-marked-circle
|
||||
</v-icon>Apply
|
||||
</v-btn>
|
||||
</v-col>
|
||||
<v-col cols="auto" class="pa-1 pb-2">
|
||||
<v-btn
|
||||
small
|
||||
:disabled="!sourceApplied"
|
||||
@click="clearSource"
|
||||
>
|
||||
<v-icon dark left>
|
||||
mdi-close-circle
|
||||
</v-icon>Clear
|
||||
</v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
</v-container>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/*global sketchup*/
|
||||
import gql from "graphql-tag";
|
||||
import streamQuery from "@/graphql/stream.gql";
|
||||
import {bus} from "@/main";
|
||||
import ObjectLoader from "@speckle/objectloader";
|
||||
|
||||
const streamLimit = 20
|
||||
|
||||
export default {
|
||||
name: "MappingSource",
|
||||
props: {
|
||||
streamSearchQuery: { type: String, default: null },
|
||||
sourceState: { type: String, default: 'Not Set' },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
sourceApplied: false,
|
||||
sourceStreamId: null,
|
||||
sourceBranchId: null,
|
||||
sourceStreamName: null,
|
||||
sourceBranchName: null
|
||||
}
|
||||
},
|
||||
apollo: {
|
||||
streams: {
|
||||
prefetch: true,
|
||||
debounce: 300,
|
||||
fetchPolicy: 'cache-and-network',
|
||||
query: gql`
|
||||
query Streams($query: String, $limit: Int, $cursor: String) {
|
||||
streams(query: $query, limit: $limit, cursor: $cursor) {
|
||||
totalCount
|
||||
cursor
|
||||
items {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables() {
|
||||
return {
|
||||
query: this.streamSearchQuery,
|
||||
limit: streamLimit,
|
||||
cursor: null
|
||||
}
|
||||
},
|
||||
update(data) {
|
||||
bus.$emit('streams-loaded')
|
||||
this.showMoreEnabled = data.streams?.items.length < data.streams.totalCount
|
||||
return data.streams
|
||||
},
|
||||
},
|
||||
$subscribe: {
|
||||
commitCreated: {
|
||||
query: gql`
|
||||
subscription ($streamId: String!) {
|
||||
commitCreated(streamId: $streamId)
|
||||
}
|
||||
`,
|
||||
variables() {
|
||||
return {
|
||||
streamId: this.sourceStreamId
|
||||
}
|
||||
},
|
||||
result(data) {
|
||||
if (data.data.commitCreated.sourceApplication.includes('Revit')){
|
||||
if (data.data.commitCreated.branchName === this.selectedBranch.name){
|
||||
this.afterCommitCreated()
|
||||
this.$eventHub.$emit('notification', {
|
||||
text: `A new commit was created on Revit!`,
|
||||
})
|
||||
this.$apollo.queries.stream.refetch()
|
||||
}
|
||||
}
|
||||
},
|
||||
skip() {
|
||||
// Return true to skip the initial query execution
|
||||
return this.sourceStreamId === null;
|
||||
},
|
||||
}
|
||||
},
|
||||
stream: {
|
||||
query: streamQuery,
|
||||
prefetch: true,
|
||||
variables() {
|
||||
return {
|
||||
id: this.sourceStreamId
|
||||
}
|
||||
},
|
||||
skip() {
|
||||
// Return true to skip the initial query execution
|
||||
return this.sourceStreamId === null;
|
||||
},
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
selectedBranch() {
|
||||
if (!this.stream) return
|
||||
return this.stream.branches.items.find((branch) => branch.id === this.sourceBranchId)
|
||||
},
|
||||
allStreamsList() {
|
||||
if (this.$apollo.loading) return
|
||||
return this.streams?.items
|
||||
},
|
||||
allBranchesList() {
|
||||
if (this.$apollo.loading) return
|
||||
return this.stream?.branches.items
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
bus.$on('refresh-source-branch', () => {
|
||||
this.onSourceBranchChanged()
|
||||
bus.$emit('set-source-up-to-date', 'Set')
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
applySource(){
|
||||
bus.$emit('set-source-up-to-date', 'Set')
|
||||
this.onSourceBranchChanged()
|
||||
this.$eventHub.$emit('success', {
|
||||
text: 'Mapper source applied.\n'
|
||||
})
|
||||
this.$mixpanel.track('MappingsAction', { name: 'Mappings Source Apply' })
|
||||
},
|
||||
clearSource(){
|
||||
sketchup.exec({name:"clear_mapper_source" , data: {}})
|
||||
bus.$emit('set-source-up-to-date', 'Not Set')
|
||||
this.sourceApplied = false
|
||||
this.sourceBranchName = null
|
||||
this.sourceStreamName = null
|
||||
this.sourceBranchId = null
|
||||
this.sourceStreamId = null
|
||||
this.$eventHub.$emit('error', {
|
||||
text: 'Mapper source cleared.\n'
|
||||
})
|
||||
},
|
||||
afterCommitCreated(){
|
||||
bus.$emit('set-source-up-to-date', 'Outdated')
|
||||
},
|
||||
async onSourceBranchChanged() {
|
||||
const commitRefId = this.selectedBranch.commits.items[0]?.referencedObject
|
||||
if (!commitRefId) { return }
|
||||
|
||||
const loader = new ObjectLoader({
|
||||
serverUrl: localStorage.getItem('serverUrl'),
|
||||
token: localStorage.getItem('SpeckleSketchup.AuthToken'),
|
||||
streamId: this.sourceStreamId,
|
||||
objectId: commitRefId
|
||||
})
|
||||
|
||||
let rootObj = await loader.getAndConstructObject(this.updateLoadingStage)
|
||||
sketchup.exec({name:"mapper_source_updated" , data: {
|
||||
base: rootObj,
|
||||
stream_id: this.sourceStreamId,
|
||||
commit_id: commitRefId
|
||||
}})
|
||||
this.sourceApplied = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user