Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/b71e170354f3
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:21:37 2012
Кодировка:

# HG changeset patch
# User boris
# Date 1284571503 -14400
# Node ID b71e170354f341694d52c5256c8d6941e361ba47
# Parent e1c94228fe1034fc10af0a2ab3cbafb00f6ee171
view and download links

diff -r e1c94228fe10 -r b71e170354f3 blocks3d-wt-widget.C
--- a/blocks3d-wt-widget.C Wed Sep 15 19:36:36 2010 +0400
+++ b/blocks3d-wt-widget.C Wed Sep 15 21:25:03 2010 +0400
@@ -10,6 +10,8 @@
#include
#include
#include
+#include
+#include

#include
#include
@@ -17,238 +19,249 @@
#include

Blocks3DWidget::Blocks3DWidget(Wt::WContainerWidget *parent) :
- Wt::WContainerWidget(parent)
+ Wt::WContainerWidget(parent)
{
- alignment_upload = new Wt::WFileUpload();
- alignment_textarea = new Wt::WTextArea();
- alignment_textarea->setColumns(40);
- conformity_upload = new Wt::WFileUpload();
- conformity_textarea = new Wt::WTextArea();
- conformity_textarea->setColumns(40);
-
- Wt::WLabel *alignment_label = new Wt::WLabel("Alignment:");
- alignment_label->setBuddy(alignment_textarea);
-
- Wt::WLabel *conformity_label = new Wt::WLabel("Confiomity file:");
- conformity_label->setBuddy(alignment_textarea);
-
- Wt::WTable *table = new Wt::WTable(this);
-
- table->elementAt(0, 0)->addWidget(alignment_label);
- table->elementAt(1, 0)->addWidget(alignment_textarea);
- table->elementAt(2, 0)->addWidget(alignment_upload);
-
- table->elementAt(0, 1)->addWidget(conformity_label);
- table->elementAt(1, 1)->addWidget(conformity_textarea);
- table->elementAt(2, 1)->addWidget(conformity_upload);
-
- new Wt::WBreak(this);
- delta_input = new Wt::WLineEdit(Malakite::defaults::delta, this);
- delta_validator = new Wt::WDoubleValidator(0.0, 10.0); // FIXME: not to allow empty
- delta_input->setValidator(delta_validator);
- Wt::WLabel *delta_label = new Wt::WLabel("Distance spreading", this);
- delta_label->setBuddy(delta_input);
-
- new Wt::WBreak(this);
- min_block_width_input = new Wt::WLineEdit(Malakite::defaults::min_block_width, this);
- min_block_width_validator = new Wt::WIntValidator(3, 9999);
- min_block_width_input->setValidator(min_block_width_validator);
- Wt::WLabel *min_block_width_label = new Wt::WLabel("Min block width", this);
- min_block_width_label->setBuddy(min_block_width_input);
-
- new Wt::WBreak(this);
- timeout_input = new Wt::WLineEdit(Malakite::defaults::timeout, this);
- timeout_validator = new Wt::WIntValidator(-1, 30*24*3600);
- timeout_input->setValidator(timeout_validator);
- Wt::WLabel *timeout_label = new Wt::WLabel(
- "Bron-Kerbosh (couple cores) timeout", this);
- timeout_label->setBuddy(timeout_input);
-
- new Wt::WBreak(this);
- timeout2_input = new Wt::WLineEdit(Malakite::defaults::timeout2, this);
- timeout2_validator = new Wt::WIntValidator(-1, 30*24*3600);
- timeout2_input->setValidator(timeout2_validator);
- Wt::WLabel *timeout2_label = new Wt::WLabel(
- "Bron-Kerbosh (blocks) timeout", this);
- timeout2_label->setBuddy(timeout2_input);
-
-
- new Wt::WBreak(this);
- Wt::WPushButton *go_button = new Wt::WPushButton("Run", this);
-
- new Wt::WBreak(this);
- results_panel = new Wt::WContainerWidget(this);
-
- go_button->clicked().connect(this, &Blocks3DWidget::go_button_click);
- alignment_upload->uploaded().connect(this, &Blocks3DWidget::alignment_uploaded);
- conformity_upload->uploaded().connect(this, &Blocks3DWidget::conformity_uploaded);
- alignment_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge);
- conformity_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge);
-
- alignment_upload->changed().connect(alignment_upload, &Wt::WFileUpload::upload);
- conformity_upload->changed().connect(conformity_upload, &Wt::WFileUpload::upload);
-
- timer = new Wt::WTimer(this);
- timer->timeout().connect(this, &Blocks3DWidget::timeout);
- timer->setInterval(Malakite::refresh_period);
+ alignment_upload = new Wt::WFileUpload();
+ alignment_textarea = new Wt::WTextArea();
+ alignment_textarea->setColumns(40);
+ conformity_upload = new Wt::WFileUpload();
+ conformity_textarea = new Wt::WTextArea();
+ conformity_textarea->setColumns(40);
+
+ Wt::WLabel *alignment_label = new Wt::WLabel("Alignment:");
+ alignment_label->setBuddy(alignment_textarea);
+
+ Wt::WLabel *conformity_label = new Wt::WLabel("Confiomity file:");
+ conformity_label->setBuddy(alignment_textarea);
+
+ Wt::WTable *table = new Wt::WTable(this);
+
+ table->elementAt(0, 0)->addWidget(alignment_label);
+ table->elementAt(1, 0)->addWidget(alignment_textarea);
+ table->elementAt(2, 0)->addWidget(alignment_upload);
+
+ table->elementAt(0, 1)->addWidget(conformity_label);
+ table->elementAt(1, 1)->addWidget(conformity_textarea);
+ table->elementAt(2, 1)->addWidget(conformity_upload);
+
+ new Wt::WBreak(this);
+ delta_input = new Wt::WLineEdit(Malakite::defaults::delta, this);
+ delta_validator = new Wt::WDoubleValidator(0.0, 10.0); // FIXME: not to allow empty
+ delta_input->setValidator(delta_validator);
+ Wt::WLabel *delta_label = new Wt::WLabel("Distance spreading", this);
+ delta_label->setBuddy(delta_input);
+
+ new Wt::WBreak(this);
+ min_block_width_input = new Wt::WLineEdit(Malakite::defaults::min_block_width, this);
+ min_block_width_validator = new Wt::WIntValidator(3, 9999);
+ min_block_width_input->setValidator(min_block_width_validator);
+ Wt::WLabel *min_block_width_label = new Wt::WLabel("Min block width", this);
+ min_block_width_label->setBuddy(min_block_width_input);
+
+ new Wt::WBreak(this);
+ timeout_input = new Wt::WLineEdit(Malakite::defaults::timeout, this);
+ timeout_validator = new Wt::WIntValidator(-1, 30*24*3600);
+ timeout_input->setValidator(timeout_validator);
+ Wt::WLabel *timeout_label = new Wt::WLabel(
+ "Bron-Kerbosh (couple cores) timeout", this);
+ timeout_label->setBuddy(timeout_input);
+
+ new Wt::WBreak(this);
+ timeout2_input = new Wt::WLineEdit(Malakite::defaults::timeout2, this);
+ timeout2_validator = new Wt::WIntValidator(-1, 30*24*3600);
+ timeout2_input->setValidator(timeout2_validator);
+ Wt::WLabel *timeout2_label = new Wt::WLabel(
+ "Bron-Kerbosh (blocks) timeout", this);
+ timeout2_label->setBuddy(timeout2_input);
+
+
+ new Wt::WBreak(this);
+ Wt::WPushButton *go_button = new Wt::WPushButton("Run", this);
+
+ new Wt::WBreak(this);
+ results_panel = new Wt::WContainerWidget(this);
+
+ go_button->clicked().connect(this, &Blocks3DWidget::go_button_click);
+ alignment_upload->uploaded().connect(this, &Blocks3DWidget::alignment_uploaded);
+ conformity_upload->uploaded().connect(this, &Blocks3DWidget::conformity_uploaded);
+ alignment_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge);
+ conformity_upload->fileTooLarge().connect(this, &Blocks3DWidget::fileTooLarge);
+
+ alignment_upload->changed().connect(alignment_upload, &Wt::WFileUpload::upload);
+ conformity_upload->changed().connect(conformity_upload, &Wt::WFileUpload::upload);
+
+ timer = new Wt::WTimer(this);
+ timer->timeout().connect(this, &Blocks3DWidget::timeout);
+ timer->setInterval(Malakite::refresh_period);
}

void Blocks3DWidget::go_button_click()
{
- try_to_run();
+ try_to_run();
}

void Blocks3DWidget::fileTooLarge()
{
- Wt::WMessageBox::show("Error", "File too large", Wt::Ok);
+ Wt::WMessageBox::show("Error", "File too large", Wt::Ok);
}

void Blocks3DWidget::textarea_from_file(Wt::WTextArea* ta, const char* file)
{
- std::string temp("");
- std::string total("");
- std::ifstream uploaded_file;
+ std::string temp("");
+ std::string total("");
+ std::ifstream uploaded_file;

- uploaded_file.open(file);
- if (!uploaded_file)
- {
- return;
- }
- while (uploaded_file >> temp)
- {
- total += temp + "\n";
- }
- uploaded_file.close();
-
- ta->setText(total);
+ uploaded_file.open(file);
+ if (!uploaded_file)
+ {
+ return;
+ }
+ while (uploaded_file >> temp)
+ {
+ total += temp + "\n";
+ }
+ uploaded_file.close();
+
+ ta->setText(total);
}

void Blocks3DWidget::alignment_uploaded()
{
- textarea_from_file(alignment_textarea, alignment_upload->spoolFileName().c_str());
+ textarea_from_file(alignment_textarea, alignment_upload->spoolFileName().c_str());
}

void Blocks3DWidget::conformity_uploaded()
{
- textarea_from_file(conformity_textarea, conformity_upload->spoolFileName().c_str());
+ textarea_from_file(conformity_textarea, conformity_upload->spoolFileName().c_str());
}

void Blocks3DWidget::try_to_run()
{
- std::string alignment = alignment_textarea->text().toUTF8();
- std::string conformity = conformity_textarea->text().toUTF8();
- if (alignment.empty())
- {
- return;
- }
- if (delta_input->validate() != Wt::WValidator::Valid)
- {
- return;
- }
- if (min_block_width_input->validate() != Wt::WValidator::Valid)
- {
- return;
- }
- if (timeout_input->validate() != Wt::WValidator::Valid)
- {
- return;
- }
- if (timeout2_input->validate() != Wt::WValidator::Valid)
- {
- return;
- }
-
- std::string r = generateSalt();
-
- tempfile_alignment =
- str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_alignment);
- tempfile_conformity =
- str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_conformity);
- tempfile_html =
- str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_html);
- tempfile_check =
- str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_check);
- tempfile_sh =
- str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_sh);
-
- std::ofstream alignment_file;
- alignment_file.open(tempfile_alignment.c_str());
- alignment_file << alignment;
- alignment_file.close();
-
- if (!conformity.empty())
- {
- std::ofstream conformity_file;
- conformity_file.open(tempfile_conformity.c_str());
- conformity_file << conformity;
- conformity_file.close();
- }
-
- std::string conformity_option = "";
- if (!conformity.empty())
- {
- conformity_option = str(boost::format("-c %s") % tempfile_conformity);
- }
-
- std::string cmd = str(
- boost::format("cd %s ; %s %s -i %s %s -H %s -d %s -m %s -t %s -T %s; echo 'f' > %s;")
- % Malakite::temp_path
- % Malakite::python_path % Malakite::blocks3d_path
- % tempfile_alignment
- % conformity_option
- % tempfile_html
- % delta_input->text().toUTF8() % min_block_width_input->text().toUTF8()
- % timeout_input->text().toUTF8() % timeout2_input->text().toUTF8()
- % tempfile_check
- );
-
- std::cout << cmd << std::endl;
-
- std::ofstream tempfile_sh_file;
- tempfile_sh_file.open(tempfile_sh.c_str());
- tempfile_sh_file << cmd;
- tempfile_sh_file.close();
-
- // security???
- system(str(boost::format("sh %s &") % tempfile_sh.c_str()).c_str());
- new Wt::WBreak(this);
- new Wt::WText("Task start", results_panel);
-
- timer->start();
-
+ std::string alignment = alignment_textarea->text().toUTF8();
+ std::string conformity = conformity_textarea->text().toUTF8();
+ if (alignment.empty())
+ {
+ new Wt::WBreak(results_panel);
+ new Wt::WText("No alignment provided", results_panel);
+ return;
+ }
+ if (delta_input->validate() != Wt::WValidator::Valid)
+ {
+ return;
+ }
+ if (min_block_width_input->validate() != Wt::WValidator::Valid)
+ {
+ return;
+ }
+ if (timeout_input->validate() != Wt::WValidator::Valid)
+ {
+ return;
+ }
+ if (timeout2_input->validate() != Wt::WValidator::Valid)
+ {
+ return;
+ }
+
+ std::string r = generateSalt();
+
+ tempfile_alignment =
+ str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_alignment);
+ tempfile_conformity =
+ str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_conformity);
+ tempfile_html =
+ str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_html);
+ tempfile_check =
+ str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_check);
+ tempfile_sh =
+ str(boost::format("%s/%s_%s") % Malakite::temp_path % r % Malakite::tempfile_sh);
+
+ std::ofstream alignment_file;
+ alignment_file.open(tempfile_alignment.c_str());
+ alignment_file << alignment;
+ alignment_file.close();
+
+ if (!conformity.empty())
+ {
+ std::ofstream conformity_file;
+ conformity_file.open(tempfile_conformity.c_str());
+ conformity_file << conformity;
+ conformity_file.close();
+ }
+
+ std::string conformity_option = "";
+ if (!conformity.empty())
+ {
+ conformity_option = str(boost::format("-c %s") % tempfile_conformity);
+ }
+
+ std::string cmd = str(
+ boost::format("cd %s ; %s %s -i %s %s -H %s -d %s -m %s -t %s -T %s; echo 'f' > %s;")
+ % Malakite::temp_path
+ % Malakite::python_path % Malakite::blocks3d_path
+ % tempfile_alignment
+ % conformity_option
+ % tempfile_html
+ % delta_input->text().toUTF8() % min_block_width_input->text().toUTF8()
+ % timeout_input->text().toUTF8() % timeout2_input->text().toUTF8()
+ % tempfile_check
+ );
+
+ std::cout << cmd << std::endl;
+
+ std::ofstream tempfile_sh_file;
+ tempfile_sh_file.open(tempfile_sh.c_str());
+ tempfile_sh_file << cmd;
+ tempfile_sh_file.close();
+
+ // security???
+ system(str(boost::format("sh %s &") % tempfile_sh.c_str()).c_str());
+ new Wt::WBreak(results_panel);
+ new Wt::WText("Task start", results_panel);
+
+ timer->start();
+
}

void Blocks3DWidget::timeout()
{
- // FIXME: check status of task
- std::ifstream check_file;
- check_file.open(tempfile_check.c_str());
- if (!check_file)
- {
- return;
- }
- check_file.close();
-
- timer->stop();
-
- std::ifstream tempfile_html_file;
- tempfile_html_file.open(tempfile_html.c_str());
- if (!tempfile_html_file)
- {
- //~ Wt::WMessageBox::show("Ok", "Ok", Wt::Ok);
- new Wt::WBreak(this);
- new Wt::WText("Task failed. Please contact developer", results_panel);
- return;
- }
- tempfile_html_file.close();
-
- new Wt::WBreak(this);
- new Wt::WText("Task finished", results_panel);
-
-
-
- // FIXME Anchor
-
+ // FIXME: check status of task
+ std::ifstream check_file;
+ check_file.open(tempfile_check.c_str());
+ if (!check_file)
+ {
+ return;
+ }
+ check_file.close();
+
+ timer->stop();
+
+ std::ifstream tempfile_html_file;
+ tempfile_html_file.open(tempfile_html.c_str());
+ if (!tempfile_html_file)
+ {
+ //~ Wt::WMessageBox::show("Ok", "Ok", Wt::Ok);
+ new Wt::WBreak(results_panel);
+ new Wt::WText("Task failed. Please contact developer", results_panel);
+ return;
+ }
+ tempfile_html_file.close();
+
+ new Wt::WBreak(results_panel);
+ new Wt::WText("Task finished", results_panel);
+
+ Wt::WFileResource* html_view =
+ new Wt::WFileResource("text/html", tempfile_html, this);
+ new Wt::WBreak(results_panel);
+ Wt::WAnchor* a_view = new Wt::WAnchor(html_view, "View", results_panel);
+ a_view->setTarget(Wt::TargetNewWindow);
+
+ Wt::WFileResource* html_download =
+ new Wt::WFileResource("application/octet-stream", tempfile_html, this);
+ new Wt::WBreak(results_panel);
+ Wt::WAnchor* a_download = new Wt::WAnchor(html_download, "View", results_panel);
+
+ // FIXME Anchor
+
}