From 3e5faa6e572eaa035ec18a7f009b22b6ebef4894 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Thu, 8 Jun 2023 18:37:33 +0300 Subject: [PATCH] WIP --- .../src/actions/cancel_operation.rb | 20 +++++++++++++++++++ .../src/actions/send_selection.rb | 13 ++++++++---- .../src/convertors/to_speckle.rb | 5 +++++ speckle_connector/src/states/state.rb | 4 ++++ speckle_connector/src/ui/vue_view.rb | 4 +++- ui/src/components/StreamCard.vue | 18 +++++++++++++++++ 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 speckle_connector/src/actions/cancel_operation.rb diff --git a/speckle_connector/src/actions/cancel_operation.rb b/speckle_connector/src/actions/cancel_operation.rb new file mode 100644 index 0000000..7424421 --- /dev/null +++ b/speckle_connector/src/actions/cancel_operation.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require_relative 'action' +require_relative 'deactivate_diffing' +require_relative '../convertors/units' +require_relative '../convertors/to_speckle' + +module SpeckleConnector + module Actions + # Cancel the operation. + class CancelOperation < 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) + state.ready = false + state + end + end + end +end diff --git a/speckle_connector/src/actions/send_selection.rb b/speckle_connector/src/actions/send_selection.rb index 1e61564..cd6a509 100644 --- a/speckle_connector/src/actions/send_selection.rb +++ b/speckle_connector/src/actions/send_selection.rb @@ -20,6 +20,11 @@ module SpeckleConnector state = DeactivateDiffing.update_state(state, {}) converter = Converters::ToSpeckle.new(state, @stream_id) new_speckle_state, base = converter.convert_selection_to_base(state.user_state.preferences) + unless state.ready + state = state.with(:@ready => true) + return state.with_add_queue('sendOperationCancelled', @stream_id, []) + end + id, total_children_count, batches, new_speckle_state = converter.serialize(base, new_speckle_state, state.user_state.preferences) puts("converted #{base.count} objects for stream #{@stream_id}") @@ -30,10 +35,10 @@ module SpeckleConnector new_state = state.with_speckle_state(new_speckle_state) new_state.with_add_queue('convertedFromSketchup', @stream_id, [ - { is_string: false, val: batches }, - { is_string: true, val: id }, - { is_string: false, val: total_children_count } - ]) + { is_string: false, val: batches }, + { is_string: true, val: id }, + { is_string: false, val: total_children_count } + ]) end end end diff --git a/speckle_connector/src/convertors/to_speckle.rb b/speckle_connector/src/convertors/to_speckle.rb index 6d3e0ef..f68e3c6 100644 --- a/speckle_connector/src/convertors/to_speckle.rb +++ b/speckle_connector/src/convertors/to_speckle.rb @@ -61,6 +61,11 @@ module SpeckleConnector # @param speckle_state [States::SpeckleState] the current speckle state of the {States::State} # @param parent [Symbol, String] parent of the Sketchup Entity to be converted. def convert(entity, preferences, speckle_state, parent = :base) + unless state.ready + puts 'Terminating..' + return speckle_state, nil + end + convert = method(:convert) unless SketchupModel::Reader::SpeckleEntitiesReader.mapped_with_schema?(entity) diff --git a/speckle_connector/src/states/state.rb b/speckle_connector/src/states/state.rb index e605d94..68e8037 100644 --- a/speckle_connector/src/states/state.rb +++ b/speckle_connector/src/states/state.rb @@ -8,6 +8,9 @@ module SpeckleConnector class State < InitialState include Immutable::ImmutableUtils + # @return [Boolean] is state ready for updating. + attr_accessor :ready + # @return [States::SketchupState] the state of the Sketchup Application attr_reader :sketchup_state @@ -18,6 +21,7 @@ module SpeckleConnector attr_reader :user_state def initialize(user_state, speckle_state, sketchup_state, is_connected) + @ready = true @speckle_state = speckle_state @is_connected = is_connected @sketchup_state = sketchup_state diff --git a/speckle_connector/src/ui/vue_view.rb b/speckle_connector/src/ui/vue_view.rb index af48d13..07bfeaf 100644 --- a/speckle_connector/src/ui/vue_view.rb +++ b/speckle_connector/src/ui/vue_view.rb @@ -29,6 +29,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/cancel_operation' module SpeckleConnector module Ui @@ -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), + cancel_operation: Commands::ActionCommand.new(@app, Actions::CancelOperation) }.freeze end # rubocop:enable Metrics/MethodLength diff --git a/ui/src/components/StreamCard.vue b/ui/src/components/StreamCard.vue index 7f486e7..64e3c79 100644 --- a/ui/src/components/StreamCard.vue +++ b/ui/src/components/StreamCard.vue @@ -40,6 +40,14 @@ + + STOP + { + this.loadingSend = false + }) bus.$on(`sketchup-received-${this.streamId}`, () => { console.log('>>> SpeckleSketchUp: Finished receiving in sketchup', this.streamId) this.loadingReceive = false @@ -435,6 +450,9 @@ export default { console.log('>>> SpeckleSketchUp: Objects requested from SketchUp') await this.sleep(2000) }, + cancel(){ + sketchup.exec({name:"cancel_operation" , data: {}}) + }, async createCommit(batches, commitId, totalChildrenCount) { if (batches.length === 0) { this.loadingSend = false