Clickling cancel during Send emits "triggerCancelSend" event in JS UI

This commit is contained in:
Ralph Wessel
2024-11-08 15:13:55 +00:00
parent 38a5254b30
commit ca52be3c48
6 changed files with 71 additions and 5 deletions
@@ -5,6 +5,7 @@
#include "Active/Utility/BufferOut.h"
#include "Speckle/Interface/Browser/Bridge/BrowserBridge.h"
#include "Speckle/Record/Element/ModelElement.h"
#include "Speckle/Utility/UserCancel.h"
#include <utility>
@@ -45,7 +46,15 @@ std::unique_ptr<WrappedResultArg> GetCallResult::getResult(const WrappedResultAr
if (!item)
return nullptr;
String jsonOutput;
JSONTransport().send(std::forward<Cargo&&>(*item), Identity{}, jsonOutput);
try {
JSONTransport().send(std::forward<Cargo&&>(*item), Identity{}, jsonOutput);
} catch(const UserCancel& userCancel) {
//If the user cancels and we have a model card ID, notify the JS UI that the operation is cancelled
if (userCancel.getModelCardID())
getBridge()->sendEvent("triggerCancelSend",
std::make_unique<CargoHold<ValueWrap<String>, String>>(String{*userCancel.getModelCardID()}));
return nullptr;
}
record::element::ModelElement::resetCache();
return std::make_unique<WrappedResultArg>(jsonOutput);
} //GetCallResult::getResult
@@ -1,5 +1,6 @@
#include "Speckle/Record/Element/Element.h"
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Management/Management.h"
#include "Speckle/Database/BIMElementDatabase.h"
#include "Speckle/Environment/Addon.h"
@@ -8,7 +9,7 @@
#include "Speckle/Record/Element/Setting/TypeSetting.h"
#include "Speckle/Serialise/Collection/ConversionReporter.h"
#include "Speckle/SpeckleResource.h"
#include "Active/Serialise/CargoHold.h"
#include "Speckle/Utility/UserCancel.h"
using namespace active::serialise;
using namespace speckle::database;
@@ -263,8 +264,10 @@ void Element::setDefault() {
void Element::useManagement(Management* management) const {
if (management != nullptr) {
//If a conversion report is collected, add this record to the report (also updates progress display in the UI)
if (auto reporter = management->get<ConversionReporter>(); reporter != nullptr)
reporter->logRecord(getBIMID(), {ConversionReporter::Data::Status::success, getTypeName(), getSpeckleType()});
if (auto reporter = management->get<ConversionReporter>(); reporter != nullptr) {
if (!reporter->logRecord(getBIMID(), {ConversionReporter::Data::Status::success, getTypeName(), getSpeckleType()}))
throw UserCancel{reporter->getModelCardID()};
}
}
} //Element::useManagement
@@ -2,6 +2,7 @@
#define SPECKLE_SERIALISE_CONVERSION_REPORTER
#include "Active/Serialise/Management/Manager.h"
#include "Speckle/Database/Identity/RecordID.h"
#include "Speckle/Database/Identity/BIMRecordID.h"
namespace speckle::interfac {
@@ -46,6 +47,11 @@ namespace speckle::serialise {
// MARK: - Functions (const)
/*!
Get the conversion report model card ID
@return The model card ID
*/
const database::RecordID& getModelCardID() const { return m_modelCardID; }
/*!
Get the conversion log
@return The conversion log
@@ -54,6 +60,11 @@ namespace speckle::serialise {
// MARK: - Functions (mutating)
/*!
Set the conversion report model card ID
@param cardID The model card ID
*/
void setModelCardID(const database::RecordID& cardID) { m_modelCardID = cardID; }
/*!
Increment the number of projected records to be logged
*/
@@ -77,6 +88,8 @@ namespace speckle::serialise {
private:
///The reporter log
Log m_log;
///The ID of the conversion model card
database::RecordID m_modelCardID;
///The conversion progress UI display
std::shared_ptr<interfac::Progress> m_progress;
///Projected number of records to be logged (used to calculate UI progress components)
+1 -1
View File
@@ -8,7 +8,7 @@
namespace speckle::utility {
/*!
Record index class
Speckle exception base
*/
class Exception : public std::runtime_error {
public:
+37
View File
@@ -0,0 +1,37 @@
#ifndef SPECKLE_UTILITY_USER_CANCEL
#define SPECKLE_UTILITY_USER_CANCEL
#include "Speckle/Database/Identity/RecordID.h"
#include "Speckle/Utility/Exception.h"
namespace speckle::utility {
/*!
Exception thrown to signal the user has cancelled a process
*/
class UserCancel : public Exception {
public:
/*!
Default constructor
*/
UserCancel() : Exception{{}} {}
/*!
Constructor
@param modelCardID The model card ID associated with the cancelled process
*/
UserCancel(const database::RecordID& modelCardID) : Exception{{}}, m_modelCardID{modelCardID} {}
/*!
Get the ID of the model card associated with the cancelled process
@return The model card ID (nullopt = process not associated with a model card)
*/
const database::RecordID::Option getModelCardID() const { return m_modelCardID; }
private:
///The model card ID associated with the cancelled process (nullopt = process not associated with a model card)
database::RecordID::Option m_modelCardID;
};
}
#endif //SPECKLE_UTILITY_USER_CANCEL
@@ -80,6 +80,7 @@
2199BB6F2CDC2B2500A4BEEC /* ConversionReporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2199BB6E2CDC2B2500A4BEEC /* ConversionReporter.cpp */; };
2199BB732CDCB0D500A4BEEC /* Progress.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2199BB702CDCB0D500A4BEEC /* Progress.cpp */; };
2199BB742CDCB0D500A4BEEC /* Progress.h in Headers */ = {isa = PBXBuildFile; fileRef = 2199BB712CDCB0D500A4BEEC /* Progress.h */; };
2199BB842CDE508800A4BEEC /* UserCancel.h in Headers */ = {isa = PBXBuildFile; fileRef = 2199BB812CDE508800A4BEEC /* UserCancel.h */; };
21A0FBA42CB880690023F24E /* FinishCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = 21A0FB9F2CB880690023F24E /* FinishCollector.h */; };
21A0FBB52CBA5E380023F24E /* Str256.h in Headers */ = {isa = PBXBuildFile; fileRef = 21A0FBB42CBA5E380023F24E /* Str256.h */; };
21A0FBBC2CBBC04C0023F24E /* ArchicadRGB.h in Headers */ = {isa = PBXBuildFile; fileRef = 21A0FBB92CBBC04C0023F24E /* ArchicadRGB.h */; };
@@ -312,6 +313,7 @@
2199BB6E2CDC2B2500A4BEEC /* ConversionReporter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConversionReporter.cpp; sourceTree = "<group>"; };
2199BB702CDCB0D500A4BEEC /* Progress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Progress.cpp; sourceTree = "<group>"; };
2199BB712CDCB0D500A4BEEC /* Progress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Progress.h; sourceTree = "<group>"; };
2199BB812CDE508800A4BEEC /* UserCancel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserCancel.h; sourceTree = "<group>"; };
21A0FB9F2CB880690023F24E /* FinishCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FinishCollector.h; sourceTree = "<group>"; };
21A0FBA92CB9324A0023F24E /* FinishProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FinishProxy.h; sourceTree = "<group>"; };
21A0FBB42CBA5E380023F24E /* Str256.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Str256.h; sourceTree = "<group>"; };
@@ -672,6 +674,7 @@
210CC88D2C81A98500610F58 /* Guid64.h */,
219351AE2C62CC1A00E5A69C /* String.cpp */,
219351AF2C62CC1A00E5A69C /* String.h */,
2199BB812CDE508800A4BEEC /* UserCancel.h */,
);
path = Utility;
sourceTree = "<group>";
@@ -1082,6 +1085,7 @@
21A0FBA42CB880690023F24E /* FinishCollector.h in Headers */,
21384C192CD585A600D4602B /* Roof.h in Headers */,
21AE19802CC7D265004DBCFC /* PropertiedWrapper.h in Headers */,
2199BB842CDE508800A4BEEC /* UserCancel.h in Headers */,
21A0FC0B2CBE5E220023F24E /* Segment.h in Headers */,
215F088D2CA195EC00CD343B /* ArchicadElementDBaseEngine.h in Headers */,
21384BC82CD24ADC00D4602B /* ElementEvent.h in Headers */,