This commit is contained in:
oguzhankoral
2023-06-08 18:37:33 +03:00
parent ac3ac24272
commit 3e5faa6e57
6 changed files with 59 additions and 5 deletions
@@ -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
@@ -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
@@ -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)
+4
View File
@@ -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
+3 -1
View File
@@ -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
+18
View File
@@ -40,6 +40,14 @@
<v-img v-if="$vuetify.theme.dark" src="@/assets/SenderWhite.png" max-width="30" />
<v-img v-else src="@/assets/Sender.png" max-width="30" />
</v-btn>
<v-btn
v-tooltip="'Stop'"
icon
class="mr-3 elevation-2"
@click="cancel"
>
STOP
</v-btn>
<v-btn
v-tooltip="'Receive'"
icon
@@ -163,6 +171,10 @@ import streamQuery from '../graphql/stream.gql'
import ObjectLoader from '@speckle/objectloader'
import {HostApplications} from '@/utils/hostApplications'
global.sendOperationCancelled = function (streamId) {
bus.$emit(`send-operation-cancelled-${streamId}`)
}
global.convertedFromSketchup = function (streamId, batches, commitId, totalChildrenCount) {
bus.$emit(`sketchup-objects-${streamId}`, batches, commitId, totalChildrenCount)
}
@@ -314,6 +326,9 @@ export default {
await this.createCommit(batches, commitId, totalChildrenCount)
})
bus.$on(`send-operation-cancelled-${this.streamId}`, () => {
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