-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
343 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include "NetworkTransferController.h" | ||
|
||
#include "Base/VersionChecker.h" | ||
#include "EngineInterface/SimulationController.h" | ||
#include "PersisterInterface/TaskProcessor.h" | ||
|
||
#include "MessageDialog.h" | ||
#include "TemporalControlWindow.h" | ||
#include "Viewport.h" | ||
#include "EditorController.h" | ||
#include "GenomeEditorWindow.h" | ||
#include "BrowserWindow.h" | ||
|
||
void NetworkTransferController::init( | ||
SimulationController const& simController, | ||
PersisterController const& persisterController, | ||
TemporalControlWindow const& temporalControlWindow, | ||
EditorController const& editorController, | ||
BrowserWindow const& browserWindow) | ||
{ | ||
_simController = simController; | ||
_persisterController = persisterController; | ||
_temporalControlWindow = temporalControlWindow; | ||
_editorController = editorController; | ||
_browserWindow = browserWindow; | ||
_downloadProcessor = _TaskProcessor::createTaskProcessor(_persisterController); | ||
_uploadProcessor = _TaskProcessor::createTaskProcessor(_persisterController); | ||
} | ||
|
||
void NetworkTransferController::onDownload(DownloadNetworkResourceRequestData const& requestData) | ||
{ | ||
_downloadProcessor->executeTask( | ||
[&](auto const& senderId) { | ||
return _persisterController->scheduleDownloadNetworkResource( | ||
SenderInfo{.senderId = senderId, .wishResultData = true, .wishErrorInfo = true}, requestData); | ||
}, | ||
[&](auto const& requestId) { | ||
auto data = _persisterController->fetchDownloadNetworkResourcesData(requestId); | ||
|
||
if (data.resourceType == NetworkResourceType_Simulation) { | ||
_persisterController->shutdown(); | ||
_simController->closeSimulation(); | ||
std::optional<std::string> errorMessage; | ||
auto const& deserializedSimulation = std::get<DeserializedSimulation>(data.resourceData); | ||
try { | ||
_simController->newSimulation( | ||
requestData.resourceName, | ||
deserializedSimulation.auxiliaryData.timestep, | ||
deserializedSimulation.auxiliaryData.generalSettings, | ||
deserializedSimulation.auxiliaryData.simulationParameters); | ||
_simController->setRealTime(deserializedSimulation.auxiliaryData.realTime); | ||
_simController->setClusteredSimulationData(deserializedSimulation.mainData); | ||
_simController->setStatisticsHistory(deserializedSimulation.statistics); | ||
} catch (CudaMemoryAllocationException const& exception) { | ||
errorMessage = exception.what(); | ||
} catch (...) { | ||
errorMessage = "Failed to load simulation."; | ||
} | ||
if (errorMessage) { | ||
showMessage("Error", *errorMessage); | ||
_simController->closeSimulation(); | ||
_simController->newSimulation( | ||
requestData.resourceName, | ||
deserializedSimulation.auxiliaryData.timestep, | ||
deserializedSimulation.auxiliaryData.generalSettings, | ||
deserializedSimulation.auxiliaryData.simulationParameters); | ||
} | ||
_persisterController->restart(); | ||
|
||
Viewport::setCenterInWorldPos(deserializedSimulation.auxiliaryData.center); | ||
Viewport::setZoomFactor(deserializedSimulation.auxiliaryData.zoom); | ||
_temporalControlWindow->onSnapshot(); | ||
} else { | ||
_editorController->setOn(true); | ||
_editorController->getGenomeEditorWindow()->openTab(std::get<GenomeDescription>(data.resourceData)); | ||
} | ||
if (VersionChecker::isVersionNewer(data.resourceVersion)) { | ||
std::string dataTypeString = data.resourceType == NetworkResourceType_Simulation ? "simulation" : "genome"; | ||
MessageDialog::get().information( | ||
"Warning", | ||
"The download was successful but the " + dataTypeString | ||
+ " was generated using a more recent\n" | ||
"version of ALIEN. Consequently, the " | ||
+ dataTypeString | ||
+ "might not function as expected.\n" | ||
"Please visit\n\nhttps://github.com/chrxh/alien\n\nto obtain the latest version."); | ||
} | ||
}, | ||
[](auto const& errors) { MessageDialog::get().information("Error", errors); }); | ||
} | ||
|
||
void NetworkTransferController::onUpload(UploadNetworkResourceRequestData const& requestData) | ||
{ | ||
_uploadProcessor->executeTask( | ||
[&](auto const& senderId) { | ||
return _persisterController->scheduleUploadNetworkResource( | ||
SenderInfo{.senderId = senderId, .wishResultData = true, .wishErrorInfo = true}, requestData); | ||
}, | ||
[&](auto const& requestId) { | ||
_persisterController->fetchUploadNetworkResourcesData(requestId); | ||
_browserWindow->onRefresh(); | ||
}, | ||
[](auto const& errors) { MessageDialog::get().information("Error", errors); }); | ||
} | ||
|
||
void NetworkTransferController::process() | ||
{ | ||
_downloadProcessor->process(); | ||
_uploadProcessor->process(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "Base/Singleton.h" | ||
|
||
#include "EngineInterface/Definitions.h" | ||
#include "PersisterInterface/Definitions.h" | ||
#include "PersisterInterface/PersisterRequestId.h" | ||
#include "PersisterInterface/DownloadNetworkResourceRequestData.h" | ||
#include "PersisterInterface/UploadNetworkResourceRequestData.h" | ||
|
||
#include "Definitions.h" | ||
|
||
class NetworkTransferController | ||
{ | ||
MAKE_SINGLETON(NetworkTransferController); | ||
|
||
public: | ||
void init( | ||
SimulationController const& simController, | ||
PersisterController const& persisterController, | ||
TemporalControlWindow const& temporalControlWindow, | ||
EditorController const& editorController, | ||
BrowserWindow const& browserWindow); | ||
|
||
void onDownload(DownloadNetworkResourceRequestData const& requestData); | ||
void onUpload(UploadNetworkResourceRequestData const& requestData); | ||
|
||
void process(); | ||
|
||
private: | ||
SimulationController _simController; | ||
PersisterController _persisterController; | ||
TemporalControlWindow _temporalControlWindow; | ||
EditorController _editorController; | ||
BrowserWindow _browserWindow; | ||
|
||
TaskProcessor _downloadProcessor; | ||
TaskProcessor _uploadProcessor; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.