|
2 | 2 | #include "Async/Async.h" |
3 | 3 | #include "CesiumITwinCesiumCuratedContentRasterOverlay.h" |
4 | 4 | #include "CesiumRuntime.h" |
| 5 | +#include <CesiumUtility/ErrorList.h> |
5 | 6 | #include <CesiumUtility/Result.h> |
6 | 7 |
|
| 8 | +namespace { |
| 9 | +TArray<FString> errorListToArray(const CesiumUtility::ErrorList& errors) { |
| 10 | + TArray<FString> Errors; |
| 11 | + for (const std::string& error : errors.errors) { |
| 12 | + Errors.Emplace(UTF8_TO_TCHAR(error.c_str())); |
| 13 | + } |
| 14 | + |
| 15 | + for (const std::string& warning : errors.warnings) { |
| 16 | + Errors.Emplace(UTF8_TO_TCHAR(warning.c_str())); |
| 17 | + } |
| 18 | + |
| 19 | + return Errors; |
| 20 | +} |
| 21 | +} // namespace |
| 22 | + |
7 | 23 | UCesiumITwinAPIAuthorizeAsyncAction* |
8 | 24 | UCesiumITwinAPIAuthorizeAsyncAction::Authorize(const FString& ClientID) { |
9 | 25 | UCesiumITwinAPIAuthorizeAsyncAction* pAsyncAction = |
@@ -40,20 +56,11 @@ void UCesiumITwinAPIAuthorizeAsyncAction::Activate() { |
40 | 56 | } |
41 | 57 |
|
42 | 58 | if (!connection.value) { |
43 | | - TArray<FString> Errors; |
44 | | - for (const std::string& error : connection.errors.errors) { |
45 | | - Errors.Emplace(UTF8_TO_TCHAR(error.c_str())); |
46 | | - } |
47 | | - |
48 | | - for (const std::string& warning : connection.errors.warnings) { |
49 | | - Errors.Emplace(UTF8_TO_TCHAR(warning.c_str())); |
50 | | - } |
51 | | - |
52 | 59 | this->OnAuthorizationEvent.Broadcast( |
53 | 60 | ECesiumITwinAuthorizationDelegateType::Failure, |
54 | 61 | FString(), |
55 | 62 | nullptr, |
56 | | - Errors); |
| 63 | + errorListToArray(connection.errors)); |
57 | 64 | } else { |
58 | 65 | TSharedPtr<CesiumITwinClient::Connection> pInternalConnection = |
59 | 66 | MakeShared<CesiumITwinClient::Connection>( |
@@ -96,25 +103,133 @@ void UCesiumITwinAPIGetProfileAsyncAction::Activate() { |
96 | 103 | LogCesium, |
97 | 104 | Warning, |
98 | 105 | TEXT( |
99 | | - "Authorization finished but authorize async action is no longer valid.")); |
| 106 | + "Get profile finished but get profile async action is no longer valid.")); |
100 | 107 | return; |
101 | 108 | } |
102 | 109 |
|
103 | 110 | if (!result.value) { |
104 | | - TArray<FString> Errors; |
105 | | - for (const std::string& error : result.errors.errors) { |
106 | | - Errors.Emplace(UTF8_TO_TCHAR(error.c_str())); |
107 | | - } |
108 | | - |
109 | | - for (const std::string& warning : result.errors.warnings) { |
110 | | - Errors.Emplace(UTF8_TO_TCHAR(warning.c_str())); |
111 | | - } |
112 | | - |
113 | | - OnProfileResult.Broadcast(nullptr, Errors); |
| 111 | + OnProfileResult.Broadcast(nullptr, errorListToArray(result.errors)); |
114 | 112 | } else { |
115 | 113 | UCesiumITwinUserProfile* pProfile = NewObject<UCesiumITwinUserProfile>(); |
116 | 114 | pProfile->SetProfile(std::move(*result.value)); |
117 | 115 | OnProfileResult.Broadcast(pProfile, TArray<FString>()); |
118 | 116 | } |
119 | 117 | }); |
120 | 118 | } |
| 119 | + |
| 120 | +const int PageSize = 50; |
| 121 | + |
| 122 | +UCesiumITwinAPIGetITwinsAsyncAction* |
| 123 | +UCesiumITwinAPIGetITwinsAsyncAction::GetITwins( |
| 124 | + UCesiumITwinConnection* pConnection, |
| 125 | + int Page) { |
| 126 | + UCesiumITwinAPIGetITwinsAsyncAction* pAsyncAction = |
| 127 | + NewObject<UCesiumITwinAPIGetITwinsAsyncAction>(); |
| 128 | + pAsyncAction->pConnection = pConnection->pConnection; |
| 129 | + pAsyncAction->page = FMath::Max(Page, 1); |
| 130 | + return pAsyncAction; |
| 131 | +} |
| 132 | + |
| 133 | +void UCesiumITwinAPIGetITwinsAsyncAction::Activate() { |
| 134 | + if (!this->pConnection) { |
| 135 | + TArray<FString> Errors; |
| 136 | + Errors.Push("No connection to iTwin."); |
| 137 | + OnITwinsResult.Broadcast(TArray<UCesiumITwin*>(), false, Errors); |
| 138 | + return; |
| 139 | + } |
| 140 | + |
| 141 | + CesiumITwinClient::QueryParameters params; |
| 142 | + params.top = PageSize; |
| 143 | + params.skip = PageSize * (this->page - 1); |
| 144 | + |
| 145 | + this->pConnection->itwins(params).thenInMainThread( |
| 146 | + [this](CesiumUtility::Result< |
| 147 | + CesiumITwinClient::PagedList<CesiumITwinClient::ITwin>>&& result) { |
| 148 | + if (!IsValid(this)) { |
| 149 | + UE_LOG( |
| 150 | + LogCesium, |
| 151 | + Warning, |
| 152 | + TEXT( |
| 153 | + "Get itwins finished but get itwins async action is no longer valid.")); |
| 154 | + return; |
| 155 | + } |
| 156 | + |
| 157 | + if (!result.value) { |
| 158 | + OnITwinsResult.Broadcast( |
| 159 | + TArray<UCesiumITwin*>(), |
| 160 | + false, |
| 161 | + errorListToArray(result.errors)); |
| 162 | + } else { |
| 163 | + TArray<UCesiumITwin*> iTwins; |
| 164 | + iTwins.Reserve(result.value->size()); |
| 165 | + for (CesiumITwinClient::ITwin& iTwin : *result.value) { |
| 166 | + UCesiumITwin* pITwin = NewObject<UCesiumITwin>(); |
| 167 | + pITwin->SetITwin(MoveTemp(iTwin)); |
| 168 | + iTwins.Emplace(pITwin); |
| 169 | + } |
| 170 | + OnITwinsResult.Broadcast( |
| 171 | + iTwins, |
| 172 | + result.value->hasNextUrl(), |
| 173 | + TArray<FString>()); |
| 174 | + } |
| 175 | + }); |
| 176 | +} |
| 177 | + |
| 178 | +UCesiumITwinAPIGetIModelsAsyncAction* |
| 179 | +UCesiumITwinAPIGetIModelsAsyncAction::GetIModels( |
| 180 | + UCesiumITwinConnection* pConnection, |
| 181 | + const FString& iTwinId, |
| 182 | + int Page) { |
| 183 | + UCesiumITwinAPIGetIModelsAsyncAction* pAsyncAction = |
| 184 | + NewObject<UCesiumITwinAPIGetIModelsAsyncAction>(); |
| 185 | + pAsyncAction->pConnection = pConnection->pConnection; |
| 186 | + pAsyncAction->page = FMath::Max(Page, 1); |
| 187 | + pAsyncAction->iTwinId = iTwinId; |
| 188 | + return pAsyncAction; |
| 189 | +} |
| 190 | + |
| 191 | +void UCesiumITwinAPIGetIModelsAsyncAction::Activate() { |
| 192 | + if (!this->pConnection) { |
| 193 | + TArray<FString> Errors; |
| 194 | + Errors.Push("No connection to iTwin."); |
| 195 | + OnIModelsResult.Broadcast(TArray<UCesiumIModel*>(), false, Errors); |
| 196 | + return; |
| 197 | + } |
| 198 | + |
| 199 | + CesiumITwinClient::QueryParameters params; |
| 200 | + params.top = PageSize; |
| 201 | + params.skip = PageSize * (this->page - 1); |
| 202 | + |
| 203 | + this->pConnection->imodels(TCHAR_TO_UTF8(*this->iTwinId), params) |
| 204 | + .thenInMainThread([this]( |
| 205 | + CesiumUtility::Result<CesiumITwinClient::PagedList< |
| 206 | + CesiumITwinClient::IModel>>&& result) { |
| 207 | + if (!IsValid(this)) { |
| 208 | + UE_LOG( |
| 209 | + LogCesium, |
| 210 | + Warning, |
| 211 | + TEXT( |
| 212 | + "Get itwins finished but get itwins async action is no longer valid.")); |
| 213 | + return; |
| 214 | + } |
| 215 | + |
| 216 | + if (!result.value) { |
| 217 | + OnIModelsResult.Broadcast( |
| 218 | + TArray<UCesiumIModel*>(), |
| 219 | + false, |
| 220 | + errorListToArray(result.errors)); |
| 221 | + } else { |
| 222 | + TArray<UCesiumIModel*> iModels; |
| 223 | + iModels.Reserve(result.value->size()); |
| 224 | + for (CesiumITwinClient::IModel& iModel : *result.value) { |
| 225 | + UCesiumIModel* pIModel = NewObject<UCesiumIModel>(); |
| 226 | + pIModel->SetIModel(MoveTemp(iModel)); |
| 227 | + iModels.Emplace(pIModel); |
| 228 | + } |
| 229 | + OnIModelsResult.Broadcast( |
| 230 | + iModels, |
| 231 | + result.value->hasNextUrl(), |
| 232 | + TArray<FString>()); |
| 233 | + } |
| 234 | + }); |
| 235 | +} |
0 commit comments