37 auto panel = this->addNew<Wt::WPanel>();
38 panel->setTitle(
"Save File");
39 panel->setCollapsible(
false);
42 auto container = panel->setCentralWidget(std::make_unique<Wt::WContainerWidget>());
43 mSaveLayout = container->setLayout(std::make_unique<Wt::WVBoxLayout>());
45 auto saveFileText =
mSaveLayout->addWidget(std::make_unique<Wt::WText>(
"Please Input File Name:"));
47 auto saveFileNameEdit =
mSaveLayout->addWidget(std::make_unique<Wt::WLineEdit>());
48 saveFileNameEdit->setMaxLength(256);
49 saveFileNameEdit->setMargin(10, Wt::Side::Right);
52 auto downloadButton =
mSaveLayout->addWidget(std::make_unique< Wt::WPushButton>(
"Generated"));
53 downloadButton->setMargin(10, Wt::Side::Top);
54 downloadButton->setStyleClass(
"btn-primary");
58 downloadButton->clicked().connect([=]
61 std::string fileName = saveFileNameEdit->text().toUTF8();
62 std::cout << fileName << std::endl;
63 if (!fileName.empty())
68 mSaveOut->setText(
"Generating Successfully, Click Download!");
69 saveFileNameEdit->setText(
"");
73 mSaveOut->setText(
"File Name is InValid!");
74 saveFileNameEdit->setText(
"");
81 std::cout << fileName << std::endl;
82 mSaveOut->setText(
"File Name Cannot Be Empty!");
83 saveFileNameEdit->setText(
"");
90 auto panel = this->addNew<Wt::WPanel>();
91 panel->setTitle(
"Upload File");
92 panel->setCollapsible(
false);
95 auto container = panel->setCentralWidget(std::make_unique<Wt::WContainerWidget>());
96 auto layout = container->setLayout(std::make_unique<Wt::WVBoxLayout>());
98 Wt::WFileUpload* fu = layout->addWidget(std::make_unique<Wt::WFileUpload>());
99 fu->setProgressBar(std::make_unique<Wt::WProgressBar>());
100 fu->setMargin(10, Wt::Side::Right);
101 fu->setMultiple(
false);
104 Wt::WPushButton* uploadButton = layout->addWidget(std::make_unique<Wt::WPushButton>(
"Send"));
105 uploadButton->setMargin(10, Wt::Side::Top);
106 uploadButton->setStyleClass(
"btn-primary");
108 mUploadOut = layout->addWidget(std::make_unique<Wt::WText>());
111 uploadButton->clicked().connect([=] {
112 if (uploadButton->text() ==
"Send")
117 uploadButton->setText(
"ReUpload");
125 else if (uploadButton->text() ==
"ReUpload")
132 fu->uploaded().connect([=] {
135 if (!filePath.empty())
139 auto result = scnLoader->
load(filePath);
141 if (std::holds_alternative<std::string>(result))
143 std::string error = std::get<std::string>(result);
144 if (error.compare(
"Error Load") == 0)
146 Wt::WMessageBox::show(
"Error",
"Error Load!", Wt::StandardButton::Ok);
148 else if (error.compare(
"Error Version") == 0)
150 Wt::WMessageBox::show(
"Error",
"Version Error detected!", Wt::StandardButton::Ok);
154 Wt::WMessageBox::show(
"Error",
"Unknown Error!", Wt::StandardButton::Ok);
157 else if (std::holds_alternative<std::shared_ptr<dyno::SceneGraph>>(result))
159 mParent->setScene(std::get<std::shared_ptr<dyno::SceneGraph>>(result));
161 mUploadOut->setText(
"File upload is finished.");
171 fu->fileTooLarge().connect([=] {
184 if (std::filesystem::exists(filePath))
186 auto xmlResource = std::make_shared<downloadResource>(filePath);
188 Wt::WLink link = Wt::WLink(xmlResource);
189 link.setTarget(Wt::LinkTarget::NewWindow);
190 auto anchor =
mSaveLayout->addWidget(std::make_unique<Wt::WAnchor>(link,
"Download File"));
192 anchor->clicked().connect([=] {
194 std::filesystem::remove(filePath);
200 mSaveOut->setText(
"Failed To Generate File!");
235 if (upload->uploadedFiles().size() > 0)
237 for (
const auto& file : upload->uploadedFiles())
239 std::string savePath = file.clientFileName();
240 std::string tempFilePath = file.spoolFileName();
241 std::ifstream src(tempFilePath, std::ios::binary);
242 std::ofstream dst(savePath, std::ios::binary);
255 Wt::WMessageBox::show(
"Error",
"File save failure.", Wt::StandardButton::Ok);