From 12d2821d26f385bab2343af91ebfd5ad97c4ea4e Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Thu, 15 Jun 2023 12:09:39 +0300 Subject: [PATCH 1/6] Add mapping source selection --- ui/src/components/Mapper.vue | 22 +++++- ui/src/components/MappingSource.vue | 102 ++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 ui/src/components/MappingSource.vue diff --git a/ui/src/components/Mapper.vue b/ui/src/components/Mapper.vue index 354bb70..125325d 100644 --- a/ui/src/components/Mapper.vue +++ b/ui/src/components/Mapper.vue @@ -58,6 +58,20 @@ + + +
+ + mdi-source-branch + + {{ sourceStreamName === null ? `Source` : `Source (${sourceStreamName} - ${sourceStreamName})` }} +
+
+ + + +
+
@@ -204,6 +218,7 @@ /*global sketchup*/ import {bus} from "@/main"; import {groupBy} from "@/utils/groupBy"; +import MappingSource from "@/components/MappingSource.vue"; global.entitySelected = function (selectionParameters) { bus.$emit('entities-selected', JSON.stringify(selectionParameters)) @@ -220,11 +235,16 @@ global.mappedEntitiesUpdated = function (mappedEntities) { export default { name: "Mapper", components: { + MappingSource, GlobalToast: () => import('@/components/GlobalToast'), MappedElements: () => import('@/components/MappedElements.vue') }, data() { return { + sourceStreamId: null, + sourceBranchId: null, + sourceStreamName: null, + sourceBranchName: null, // Expanded indexes for selection table (Types) selectionExpandedIndexes: [], // Expanded indexes for mapped element table (Categories) @@ -247,7 +267,7 @@ export default { availableCategories: [], 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%' }, diff --git a/ui/src/components/MappingSource.vue b/ui/src/components/MappingSource.vue new file mode 100644 index 0000000..ccfc095 --- /dev/null +++ b/ui/src/components/MappingSource.vue @@ -0,0 +1,102 @@ + + + + + \ No newline at end of file From 5407fecd1f9625404d6f5e0ebb23a71535f85b79 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Thu, 15 Jun 2023 16:10:10 +0300 Subject: [PATCH 2/6] Fetch source branch last commit and pass to ruby --- .../src/actions/mapper_source_updated.rb | 30 ++++++++++ .../src/commands/mapper_source_updated.rb | 21 +++++++ speckle_connector/src/ui/vue_view.rb | 4 +- ui/src/components/Mapper.vue | 6 +- .../{MappingSource.vue => MapperSource.vue} | 59 ++++++++++++++++++- 5 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 speckle_connector/src/actions/mapper_source_updated.rb create mode 100644 speckle_connector/src/commands/mapper_source_updated.rb rename ui/src/components/{MappingSource.vue => MapperSource.vue} (54%) diff --git a/speckle_connector/src/actions/mapper_source_updated.rb b/speckle_connector/src/actions/mapper_source_updated.rb new file mode 100644 index 0000000..30cc6da --- /dev/null +++ b/speckle_connector/src/actions/mapper_source_updated.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require_relative 'action' + +module SpeckleConnector + module Actions + # Action to update mapper source. + class MapperSourceUpdated < Action + def initialize(stream_id, base, stream_name, branch_name, branch_id) + super() + @stream_id = stream_id + @base = base + @stream_name = stream_name + @branch_name = branch_name + @branch_id = branch_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 = @base['@Levels'].to_json + types = @base['@Types'].to_json + state.with_add_queue('mapperSourceUpdated', @stream_id, [ + { is_string: false, val: levels }, + { is_string: false, val: types } + ]) + end + end + end +end diff --git a/speckle_connector/src/commands/mapper_source_updated.rb b/speckle_connector/src/commands/mapper_source_updated.rb new file mode 100644 index 0000000..623ef63 --- /dev/null +++ b/speckle_connector/src/commands/mapper_source_updated.rb @@ -0,0 +1,21 @@ +# 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) + stream_id = data['stream_id'] + base = data['base'] + branch_name = data['branch_name'] + branch_id = data['branch_id'] + stream_name = data['stream_name'] + action = Actions::MapperSourceUpdated.new(stream_id, base, stream_name, branch_name, branch_id) + app.update_state!(action) + end + end + end +end diff --git a/speckle_connector/src/ui/vue_view.rb b/speckle_connector/src/ui/vue_view.rb index af48d13..fb7ce2b 100644 --- a/speckle_connector/src/ui/vue_view.rb +++ b/speckle_connector/src/ui/vue_view.rb @@ -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' @@ -89,7 +90,8 @@ 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) }.freeze end # rubocop:enable Metrics/MethodLength diff --git a/ui/src/components/Mapper.vue b/ui/src/components/Mapper.vue index 125325d..7997ef8 100644 --- a/ui/src/components/Mapper.vue +++ b/ui/src/components/Mapper.vue @@ -68,7 +68,7 @@
- +
@@ -218,7 +218,7 @@ /*global sketchup*/ import {bus} from "@/main"; import {groupBy} from "@/utils/groupBy"; -import MappingSource from "@/components/MappingSource.vue"; +import MappingSource from "@/components/MapperSource.vue"; global.entitySelected = function (selectionParameters) { bus.$emit('entities-selected', JSON.stringify(selectionParameters)) @@ -235,7 +235,7 @@ global.mappedEntitiesUpdated = function (mappedEntities) { export default { name: "Mapper", components: { - MappingSource, + MapperSource: () => import('@/components/MapperSource.vue'), GlobalToast: () => import('@/components/GlobalToast'), MappedElements: () => import('@/components/MappedElements.vue') }, diff --git a/ui/src/components/MappingSource.vue b/ui/src/components/MapperSource.vue similarity index 54% rename from ui/src/components/MappingSource.vue rename to ui/src/components/MapperSource.vue index ccfc095..01002f7 100644 --- a/ui/src/components/MappingSource.vue +++ b/ui/src/components/MapperSource.vue @@ -18,6 +18,7 @@ item-text="name" item-value="id" density="compact" + @change="onSourceBranchChanged" > @@ -27,9 +28,15 @@ import gql from "graphql-tag"; import streamQuery from "@/graphql/stream.gql"; import {bus} from "@/main"; +import ObjectLoader from "@speckle/objectloader"; const streamLimit = 20 +global.mapperSourceUpdated = function (streamId, levels, types) { + console.log(JSON.stringify(levels), "levels") + console.log(JSON.stringify(types), "types") +} + export default { name: "MappingSource", props: { @@ -71,19 +78,45 @@ export default { 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() { + // console.log('source branch is not up-to-date!') + this.$apollo.queries.stream.refetch() + } + } } }, stream: { query: streamQuery, - prefetch: false, + 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 @@ -92,6 +125,28 @@ export default { if (this.$apollo.loading) return return this.stream?.branches.items }, + }, + methods: { + 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_name: this.stream.name, + stream_id: this.sourceStreamId, + branch_name: this.selectedBranch.name, + branch_id: this.selectedBranch.id + }}) + } } } From c5b35b2d9894535582de76fa1dd672b8695ef797 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Fri, 16 Jun 2023 00:34:04 +0300 Subject: [PATCH 3/6] Notify user when selected source has new update --- ui/src/components/Mapper.vue | 36 ++++++++++++++++------ ui/src/components/MapperSource.vue | 49 +++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/ui/src/components/Mapper.vue b/ui/src/components/Mapper.vue index 7997ef8..3a5a8c5 100644 --- a/ui/src/components/Mapper.vue +++ b/ui/src/components/Mapper.vue @@ -59,16 +59,30 @@ - -
+ + mdi-source-branch - {{ sourceStreamName === null ? `Source` : `Source (${sourceStreamName} - ${sourceStreamName})` }} -
+ {{ `Source` }} + + + mdi-update + + +
- +
@@ -241,10 +255,7 @@ export default { }, data() { return { - sourceStreamId: null, - sourceBranchId: null, - sourceStreamName: null, - sourceBranchName: null, + sourceUpToDate: true, // Expanded indexes for selection table (Types) selectionExpandedIndexes: [], // Expanded indexes for mapped element table (Categories) @@ -374,6 +385,9 @@ export default { } }, methods:{ + refreshSourceBranch(){ + bus.$emit('refresh-source-branch') + }, clearInputs(){ this.enabledMethods = [] this.availableCategories = [] @@ -557,6 +571,10 @@ export default { bus.$on('mapped-entities-updated', async (mappedEntities) => { this.mappedEntityCount = mappedEntities.length }) + bus.$on('set-source-up-to-date', (isUpToDate) => { + this.sourceUpToDate = isUpToDate + console.log(this.sourceUpToDate) + }) } } diff --git a/ui/src/components/MapperSource.vue b/ui/src/components/MapperSource.vue index 01002f7..8ce6d7a 100644 --- a/ui/src/components/MapperSource.vue +++ b/ui/src/components/MapperSource.vue @@ -40,14 +40,15 @@ global.mapperSourceUpdated = function (streamId, levels, types) { export default { name: "MappingSource", props: { - streamSearchQuery: { type: String, default: null } + streamSearchQuery: { type: String, default: null }, + sourceUpToDate: { type: Boolean }, }, data() { return { sourceStreamId: null, sourceBranchId: null, sourceStreamName: null, - sourceBranchName: null, + sourceBranchName: null } }, apollo: { @@ -79,23 +80,30 @@ export default { this.showMoreEnabled = data.streams?.items.length < data.streams.totalCount return data.streams }, - $subscribe: { - commitCreated: { - query: gql` + }, + $subscribe: { + commitCreated: { + query: gql` subscription ($streamId: String!) { commitCreated(streamId: $streamId) } `, - variables() { - return { - streamId: this.sourceStreamId - } - }, - result() { - // console.log('source branch is not up-to-date!') - this.$apollo.queries.stream.refetch() + variables() { + return { + streamId: this.sourceStreamId } - } + }, + result() { + this.afterCommitCreated() + this.$eventHub.$emit('notification', { + text: `A new commit was created on source stream!`, + }) + this.$apollo.queries.stream.refetch() + }, + skip() { + // Return true to skip the initial query execution + return this.sourceStreamId === null; + }, } }, stream: { @@ -126,9 +134,18 @@ export default { return this.stream?.branches.items }, }, + mounted() { + bus.$on('refresh-source-branch', () => { + this.onSourceBranchChanged() + bus.$emit('set-source-up-to-date', true) + }) + }, methods: { + afterCommitCreated(){ + bus.$emit('set-source-up-to-date', false) + }, async onSourceBranchChanged() { - const commitRefId = this.selectedBranch.commits.items[0]?.referencedObject + const commitRefId = this.selectedBranch.commits.items[0]?.referencedObject if (!commitRefId) { return } const loader = new ObjectLoader({ @@ -138,6 +155,8 @@ export default { objectId: commitRefId }) + console.log(commitRefId) + let rootObj = await loader.getAndConstructObject(this.updateLoadingStage) sketchup.exec({name:"mapper_source_updated" , data: { base: rootObj, From 08bdd2314918f16d2f73fdeca6dae7d2a84dca97 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Fri, 16 Jun 2023 21:57:13 +0300 Subject: [PATCH 4/6] Add state for mapper --- .../src/actions/mapped_entities_updated.rb | 2 +- .../src/states/speckle_mapper_state.rb | 35 +++++++++++++++++++ speckle_connector/src/states/speckle_state.rb | 26 +++++++------- 3 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 speckle_connector/src/states/speckle_mapper_state.rb diff --git a/speckle_connector/src/actions/mapped_entities_updated.rb b/speckle_connector/src/actions/mapped_entities_updated.rb index 63de9c8..c9a0483 100644 --- a/speckle_connector/src/actions/mapped_entities_updated.rb +++ b/speckle_connector/src/actions/mapped_entities_updated.rb @@ -11,7 +11,7 @@ module SpeckleConnector # @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_entity_details(state.speckle_state.speckle_mapper_state.mapped_entities.values.to_a) state.with_mapped_entities_queue(mapped_entities) end diff --git a/speckle_connector/src/states/speckle_mapper_state.rb b/speckle_connector/src/states/speckle_mapper_state.rb new file mode 100644 index 0000000..0ec57c1 --- /dev/null +++ b/speckle_connector/src/states/speckle_mapper_state.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require_relative '../immutable/immutable' +require_relative '../callbacks/callback_message' +require_relative '../speckle_entities/speckle_entity' + +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 + + def initialize + @mapped_entities = Immutable::EmptyHash + 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 + end + end +end diff --git a/speckle_connector/src/states/speckle_state.rb b/speckle_connector/src/states/speckle_state.rb index 1a80eae..e81df79 100644 --- a/speckle_connector/src/states/speckle_state.rb +++ b/speckle_connector/src/states/speckle_state.rb @@ -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 @@ -96,13 +97,18 @@ module SpeckleConnector 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 +120,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 From a242c197fb0c15521bc7df73f8d9e52a41f4e24b Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Fri, 16 Jun 2023 23:10:50 +0300 Subject: [PATCH 5/6] Store mapper source in ruby state --- .../src/actions/mapper_source_updated.rb | 13 +++++--- .../src/commands/mapper_source_updated.rb | 8 ++--- speckle_connector/src/mapper/mapper_source.rb | 32 +++++++++++++++++++ .../speckle_objects/built_elements/level.rb | 23 +++++++++++++ .../revit/revit_element_type.rb | 19 +++++++++++ .../src/states/speckle_mapper_state.rb | 9 ++++++ speckle_connector/src/states/speckle_state.rb | 5 +++ ui/src/components/Mapper.vue | 5 +++ ui/src/components/MapperSource.vue | 11 +------ 9 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 speckle_connector/src/mapper/mapper_source.rb create mode 100644 speckle_connector/src/speckle_objects/built_elements/level.rb create mode 100644 speckle_connector/src/speckle_objects/built_elements/revit/revit_element_type.rb diff --git a/speckle_connector/src/actions/mapper_source_updated.rb b/speckle_connector/src/actions/mapper_source_updated.rb index 30cc6da..d5942c0 100644 --- a/speckle_connector/src/actions/mapper_source_updated.rb +++ b/speckle_connector/src/actions/mapper_source_updated.rb @@ -1,18 +1,17 @@ # frozen_string_literal: true require_relative 'action' +require_relative '../mapper/mapper_source' module SpeckleConnector module Actions # Action to update mapper source. class MapperSourceUpdated < Action - def initialize(stream_id, base, stream_name, branch_name, branch_id) + def initialize(base, stream_id, commit_id) super() - @stream_id = stream_id @base = base - @stream_name = stream_name - @branch_name = branch_name - @branch_id = branch_id + @stream_id = stream_id + @commit_id = commit_id end # @param state [States::State] the current state of the {App::SpeckleConnectorApp} @@ -20,6 +19,10 @@ module SpeckleConnector def update_state(state) levels = @base['@Levels'].to_json types = @base['@Types'].to_json + mapper_source = Mapper::MapperSource.new(@stream_id, @commit_id, @base['@Levels'], @base['@Types'].to_h) + 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 }, { is_string: false, val: types } diff --git a/speckle_connector/src/commands/mapper_source_updated.rb b/speckle_connector/src/commands/mapper_source_updated.rb index 623ef63..9f9599f 100644 --- a/speckle_connector/src/commands/mapper_source_updated.rb +++ b/speckle_connector/src/commands/mapper_source_updated.rb @@ -8,12 +8,10 @@ module SpeckleConnector # Command to update mapper source. class MapperSourceUpdated < Command def _run(data) - stream_id = data['stream_id'] base = data['base'] - branch_name = data['branch_name'] - branch_id = data['branch_id'] - stream_name = data['stream_name'] - action = Actions::MapperSourceUpdated.new(stream_id, base, stream_name, branch_name, branch_id) + 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 diff --git a/speckle_connector/src/mapper/mapper_source.rb b/speckle_connector/src/mapper/mapper_source.rb new file mode 100644 index 0000000..9cec908 --- /dev/null +++ b/speckle_connector/src/mapper/mapper_source.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +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] levels in the source branch. + attr_reader :levels + + # @return [Hash{String=>Array}] 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 diff --git a/speckle_connector/src/speckle_objects/built_elements/level.rb b/speckle_connector/src/speckle_objects/built_elements/level.rb new file mode 100644 index 0000000..9c8d71d --- /dev/null +++ b/speckle_connector/src/speckle_objects/built_elements/level.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require_relative '../base' +require_relative '../other/render_material' +require_relative '../geometry/line' +require_relative '../geometry/polyline' +require_relative '../../constants/type_constants' + +module SpeckleConnector + module SpeckleObjects + module BuiltElements + # Level object. + class Level < Base + SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_REVIT_LEVEL + + # @param state [States::State] state of the application. + def self.to_native(state, speckle_level, layer, entities, &_convert_to_native) + + end + end + end + end +end diff --git a/speckle_connector/src/speckle_objects/built_elements/revit/revit_element_type.rb b/speckle_connector/src/speckle_objects/built_elements/revit/revit_element_type.rb new file mode 100644 index 0000000..c1a5ed5 --- /dev/null +++ b/speckle_connector/src/speckle_objects/built_elements/revit/revit_element_type.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require_relative '../../base' + +module SpeckleConnector + module SpeckleObjects + module BuiltElements + module Revit + # Revit element type. + class RevitElementType < Base + + def self.to_native(state, revit_element_type, _layer, category, &_convert_to_native) + + end + end + end + end + end +end diff --git a/speckle_connector/src/states/speckle_mapper_state.rb b/speckle_connector/src/states/speckle_mapper_state.rb index 0ec57c1..9a2d1ac 100644 --- a/speckle_connector/src/states/speckle_mapper_state.rb +++ b/speckle_connector/src/states/speckle_mapper_state.rb @@ -3,6 +3,7 @@ require_relative '../immutable/immutable' require_relative '../callbacks/callback_message' require_relative '../speckle_entities/speckle_entity' +require_relative '../mapper/mapper_source' module SpeckleConnector module States @@ -13,8 +14,12 @@ module SpeckleConnector # @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) @@ -30,6 +35,10 @@ module SpeckleConnector def with_mapped_entities(new_mapped_entities) with(:@mapped_entities => new_mapped_entities) end + + def with_mapper_source(mapper_source) + with(:@mapper_source => mapper_source) + end end end end diff --git a/speckle_connector/src/states/speckle_state.rb b/speckle_connector/src/states/speckle_state.rb index e81df79..0264080 100644 --- a/speckle_connector/src/states/speckle_state.rb +++ b/speckle_connector/src/states/speckle_state.rb @@ -96,6 +96,11 @@ 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_mapped_entity(entity) new_speckle_mapper_state = speckle_mapper_state.with_mapped_entity(entity) with(:@speckle_mapper_state => new_speckle_mapper_state) diff --git a/ui/src/components/Mapper.vue b/ui/src/components/Mapper.vue index 3a5a8c5..051566f 100644 --- a/ui/src/components/Mapper.vue +++ b/ui/src/components/Mapper.vue @@ -234,6 +234,11 @@ import {bus} from "@/main"; import {groupBy} from "@/utils/groupBy"; import MappingSource from "@/components/MapperSource.vue"; +global.mapperSourceUpdated = function (streamId, levels, types) { + console.log(JSON.stringify(levels), "levels") + console.log(JSON.stringify(types), "types") +} + global.entitySelected = function (selectionParameters) { bus.$emit('entities-selected', JSON.stringify(selectionParameters)) } diff --git a/ui/src/components/MapperSource.vue b/ui/src/components/MapperSource.vue index 8ce6d7a..08ba6dd 100644 --- a/ui/src/components/MapperSource.vue +++ b/ui/src/components/MapperSource.vue @@ -32,11 +32,6 @@ import ObjectLoader from "@speckle/objectloader"; const streamLimit = 20 -global.mapperSourceUpdated = function (streamId, levels, types) { - console.log(JSON.stringify(levels), "levels") - console.log(JSON.stringify(types), "types") -} - export default { name: "MappingSource", props: { @@ -155,15 +150,11 @@ export default { objectId: commitRefId }) - console.log(commitRefId) - let rootObj = await loader.getAndConstructObject(this.updateLoadingStage) sketchup.exec({name:"mapper_source_updated" , data: { base: rootObj, - stream_name: this.stream.name, stream_id: this.sourceStreamId, - branch_name: this.selectedBranch.name, - branch_id: this.selectedBranch.id + commit_id: commitRefId }}) } } From 24a5e0a579c5b16e504349f093872def9e67f2b5 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Mon, 19 Jun 2023 12:57:48 +0300 Subject: [PATCH 6/6] Update levels geometrically when we have new commit --- .../src/actions/mapper_source_updated.rb | 29 +++++++++-- .../src/constants/type_constants.rb | 1 + speckle_connector/src/mapper/mapper_source.rb | 4 +- .../speckle_objects/built_elements/level.rb | 52 ++++++++++++++++++- .../revit/revit_element_type.rb | 25 ++++++++- .../src/states/speckle_mapper_state.rb | 1 + 6 files changed, 103 insertions(+), 9 deletions(-) diff --git a/speckle_connector/src/actions/mapper_source_updated.rb b/speckle_connector/src/actions/mapper_source_updated.rb index d5942c0..bbdbf3d 100644 --- a/speckle_connector/src/actions/mapper_source_updated.rb +++ b/speckle_connector/src/actions/mapper_source_updated.rb @@ -2,6 +2,7 @@ require_relative 'action' require_relative '../mapper/mapper_source' +require_relative '../speckle_objects/built_elements/revit/revit_element_type' module SpeckleConnector module Actions @@ -17,17 +18,35 @@ module SpeckleConnector # @param state [States::State] the current state of the {App::SpeckleConnectorApp} # @return [States::State] the new updated state object def update_state(state) - levels = @base['@Levels'].to_json - types = @base['@Types'].to_json - mapper_source = Mapper::MapperSource.new(@stream_id, @commit_id, @base['@Levels'], @base['@Types'].to_h) + 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 }, - { is_string: false, val: types } + { 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 + [type, elements] + end.compact.to_h + end + + def convert_levels(state, levels) + levels.collect do |level| + SpeckleObjects::BuiltElements::Level.to_native(state, level) + end + end end end end diff --git a/speckle_connector/src/constants/type_constants.rb b/speckle_connector/src/constants/type_constants.rb index e23511b..bfff901 100644 --- a/speckle_connector/src/constants/type_constants.rb +++ b/speckle_connector/src/constants/type_constants.rb @@ -9,6 +9,7 @@ module SpeckleConnector OBJECTS_BUILTELEMENTS_NETWORK = 'Objects.BuiltElements.Network' OBJECTS_BUILTELEMENTS_FLOOR = 'Objects.BuiltElements.Floor' OBJECTS_BUILTELEMENTS_REVIT_DIRECTSHAPE = 'Objects.BuiltElements.Revit.DirectShape' + OBJECTS_BUILTELEMENTS_REVIT_REVITELEMENTTYPE = 'Objects.BuiltElements.Revit.RevitElementType' OBJECTS_BUILTELEMENTS_REVIT_LEVEL = 'Objects.BuiltElements.Level:Objects.BuiltElements.Revit.RevitLevel' OBJECTS_GEOMETRY_LINE = 'Objects.Geometry.Line' diff --git a/speckle_connector/src/mapper/mapper_source.rb b/speckle_connector/src/mapper/mapper_source.rb index 9cec908..4221c1c 100644 --- a/speckle_connector/src/mapper/mapper_source.rb +++ b/speckle_connector/src/mapper/mapper_source.rb @@ -1,5 +1,6 @@ # 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' @@ -18,7 +19,8 @@ module SpeckleConnector # @return [Array] levels in the source branch. attr_reader :levels - # @return [Hash{String=>Array}] revit element types. + # @return [ImmutableHash{String=>Array}] revit element + # types. attr_reader :types def initialize(stream_id, commit_id, levels, types) diff --git a/speckle_connector/src/speckle_objects/built_elements/level.rb b/speckle_connector/src/speckle_objects/built_elements/level.rb index 9c8d71d..1a60b81 100644 --- a/speckle_connector/src/speckle_objects/built_elements/level.rb +++ b/speckle_connector/src/speckle_objects/built_elements/level.rb @@ -3,6 +3,7 @@ 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' @@ -13,9 +14,56 @@ module SpeckleConnector class Level < Base SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_REVIT_LEVEL - # @param state [States::State] state of the application. - def self.to_native(state, speckle_level, layer, entities, &_convert_to_native) + 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 + end + # @param state [States::State] state of the application. + def self.to_native(state, speckle_level) + 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'] + + 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 + + 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 diff --git a/speckle_connector/src/speckle_objects/built_elements/revit/revit_element_type.rb b/speckle_connector/src/speckle_objects/built_elements/revit/revit_element_type.rb index c1a5ed5..32a7f66 100644 --- a/speckle_connector/src/speckle_objects/built_elements/revit/revit_element_type.rb +++ b/speckle_connector/src/speckle_objects/built_elements/revit/revit_element_type.rb @@ -8,9 +8,32 @@ module SpeckleConnector module Revit # Revit element type. class RevitElementType < Base + SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_REVIT_REVITELEMENTTYPE - def self.to_native(state, revit_element_type, _layer, category, &_convert_to_native) + # 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 diff --git a/speckle_connector/src/states/speckle_mapper_state.rb b/speckle_connector/src/states/speckle_mapper_state.rb index 9a2d1ac..28ef2d6 100644 --- a/speckle_connector/src/states/speckle_mapper_state.rb +++ b/speckle_connector/src/states/speckle_mapper_state.rb @@ -37,6 +37,7 @@ module SpeckleConnector end def with_mapper_source(mapper_source) + # TODO: Check/Sync here parameters of the mapped entities. with(:@mapper_source => mapper_source) end end