Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "submitpage.h"
Toshihiro Shimizu 890ddd
#include "dependedlist.h"
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tw/mainshell.h"
Toshihiro Shimizu 890ddd
#include "tw/textfield.h"
Toshihiro Shimizu 890ddd
#include "tw/label.h"
Toshihiro Shimizu 890ddd
#include "tw/optionmenu.h"
Toshihiro Shimizu 890ddd
#include "tw/button.h"
Toshihiro Shimizu 890ddd
#include "tw/checkbox.h"
Toshihiro Shimizu 890ddd
#include "tw/keycodes.h"
Toshihiro Shimizu 890ddd
#include "tw/event.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "filebrowserpopup.h"
Toshihiro Shimizu 890ddd
#include "casmconfigpanel2.h"
Toshihiro Shimizu 890ddd
#include "scriptconfigpanel.h"
Toshihiro Shimizu 890ddd
#include "casmfileinfo.h"
Toshihiro Shimizu 890ddd
#include "tfarmcontroller.h"
Toshihiro Shimizu 890ddd
#include "application.h"
Toshihiro Shimizu 890ddd
#include "util.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tw/message.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef ZCOMP
Toshihiro Shimizu 890ddd
#include "zrenderconfigpanel.h"
Toshihiro Shimizu 890ddd
#include "zrendertask.h"
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <map></map>
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __sgi
Toshihiro Shimizu 890ddd
#define TERMINAL "xwsh"
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define TERMINAL "xterm"
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace TwConsts;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TextFieldChanger : public TTextField::Action {
Shinya Kitaoka 120a6e
  SubmitPage *m_submit;
Shinya Kitaoka 120a6e
  bool m_isName;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TextFieldChanger(SubmitPage *submit, bool isName)
Shinya Kitaoka 120a6e
      : m_submit(submit), m_isName(isName) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void sendCommand(wstring name) {
Shinya Kitaoka 120a6e
    m_submit->onTextField(toString(name), m_isName);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class SubmitPage::Data {
Shinya Kitaoka 120a6e
  class FilePathField : public TTextField {
Shinya Kitaoka 120a6e
    SubmitPage::Data *m_data;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    FilePathField(SubmitPage::Data *data, TWidget *parent, string name = "")
Shinya Kitaoka 120a6e
        : TTextField(parent, name), m_data(data) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    void onFocusChange(bool on) {
Shinya Kitaoka 120a6e
      if (!on) close();
Shinya Kitaoka 120a6e
      TWidget::onFocusChange(on);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    void close() {
Shinya Kitaoka 120a6e
      static wstring oldText;
Shinya Kitaoka 120a6e
      if (oldText != m_text) {
Shinya Kitaoka 120a6e
        TFilePath fp(m_text);
Shinya Kitaoka 120a6e
        try {
Shinya Kitaoka 120a6e
          wstring uncString;
Shinya Kitaoka 120a6e
          try {
Shinya Kitaoka 120a6e
            uncString = toWideString(convertToUncString(fp));
Shinya Kitaoka 120a6e
            m_text    = uncString;
Shinya Kitaoka 120a6e
            m_data->load(fp);
Shinya Kitaoka 120a6e
          } catch (TException &) {
Shinya Kitaoka 120a6e
            TFileStatus fs(fp);
Shinya Kitaoka 120a6e
            if (fs.doesExist() && !fs.isDirectory())
Shinya Kitaoka 120a6e
              m_data->load(fp);
Shinya Kitaoka 120a6e
            else if (m_data->m_task)
Shinya Kitaoka 120a6e
              m_data->m_task->setFilePath(toString(m_text));
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
          oldText = m_text;
Shinya Kitaoka 120a6e
        } catch (...) {
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      invalidate();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    void keyDown(int key, unsigned long flags, const TPoint &p) {
Shinya Kitaoka 120a6e
      if (key == TK_Return)
Shinya Kitaoka 120a6e
        close();
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        TTextField::keyDown(key, flags, p);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Data(SubmitPage *page);
Shinya Kitaoka 120a6e
  ~Data();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void configureNotify(const TDimension &size);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void browseCasmFiles();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void submit();
Shinya Kitaoka 120a6e
  void submitCasm(CasmTask2 *casm);
Shinya Kitaoka 120a6e
  void submitScript(ScriptTask *script);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void load(const TFilePath &fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void onTaskType(string type);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  SubmitPage *m_page;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TLabel *m_taskTypeLbl;
Shinya Kitaoka 120a6e
  TOptionMenu *m_taskType;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TLabel *m_taskNameLbl;
Shinya Kitaoka 120a6e
  TTextField *m_taskNameTextField;
Shinya Kitaoka 120a6e
  TCheckBox *m_submitAsSuspended;
Shinya Kitaoka 120a6e
  TButton *m_submit;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TLabel *m_filepathLbl;
Shinya Kitaoka 120a6e
  FilePathField *m_filepathTextField;
Shinya Kitaoka 120a6e
  TButton *m_casmBrowseBtn;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TLabel *m_priorityLbl;
Shinya Kitaoka 120a6e
  TNumField *m_priority;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TLabel *m_depListLbl;
Shinya Kitaoka 120a6e
  DependedList *m_depList;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  SubmitPageTask *m_task;
Shinya Kitaoka 120a6e
  std::map<string, *="" submitpagetask=""> m_tasks;</string,>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TaskConfigPanel *m_configPanel;
Shinya Kitaoka 120a6e
  std::map<string, *="" taskconfigpanel=""> m_configPanels;</string,>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SubmitPage::Data::Data(SubmitPage *page) : m_page(page), m_task(0) {
Shinya Kitaoka 120a6e
  m_taskTypeLbl = new TLabel(page);
Shinya Kitaoka 120a6e
  m_taskTypeLbl->setText("Task type:");
Shinya Kitaoka 120a6e
  m_taskType = new TOptionMenu(page);
Shinya Kitaoka 120a6e
  m_taskType->addOption("Casm");
Shinya Kitaoka 120a6e
  m_taskType->addOption("Script");
Shinya Kitaoka 120a6e
  m_taskType->setAction(new TOptionMenuAction<submitpage::data>(</submitpage::data>
Shinya Kitaoka 120a6e
      this, &SubmitPage::Data::onTaskType));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_configPanel = new CasmConfigPanel2(page);
Shinya Kitaoka 120a6e
  m_configPanels.insert(make_pair(string("Casm"), m_configPanel));
Shinya Kitaoka 120a6e
  m_configPanels.insert(
Shinya Kitaoka 120a6e
      make_pair(string("Script"), new ScriptConfigPanel(page)));
Shinya Kitaoka 120a6e
  std::map<string, *="" taskconfigpanel="">::iterator it = m_configPanels.begin();</string,>
Shinya Kitaoka 120a6e
  for (; it != m_configPanels.end(); ++it) {
Shinya Kitaoka 120a6e
    TaskConfigPanel *configPanel = it->second;
Shinya Kitaoka 120a6e
    if (configPanel != m_configPanel) configPanel->hide();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_taskNameLbl = new TLabel(page);
Shinya Kitaoka 120a6e
  m_taskNameLbl->setText("Task Name:");
Shinya Kitaoka 120a6e
  m_taskNameTextField = new TTextField(page);
Shinya Kitaoka 120a6e
  m_taskNameTextField->addAction(new TextFieldChanger(page, true));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_submitAsSuspended = new TCheckBox(page, "Submit as Suspended");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_filepathLbl = new TLabel(page);
Shinya Kitaoka 120a6e
  m_filepathLbl->setText("File Path:");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_filepathTextField = new FilePathField(this, page);
Shinya Kitaoka 120a6e
  // m_filepathTextField->addAction(new TextFieldChanger(page, false));
Shinya Kitaoka 120a6e
  m_casmBrowseBtn = new TButton(page);
Shinya Kitaoka 120a6e
  m_casmBrowseBtn->setTitle("...");
Shinya Kitaoka 120a6e
  tconnect(*m_casmBrowseBtn, this, &SubmitPage::Data::browseCasmFiles);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_submit = new TButton(page);
Shinya Kitaoka 120a6e
  m_submit->setTitle("Submit");
Shinya Kitaoka 120a6e
  tconnect(*m_submit, this, &SubmitPage::Data::submit);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_priorityLbl = new TLabel(page);
Shinya Kitaoka 120a6e
  m_priorityLbl->setText("Priority:");
Shinya Kitaoka 120a6e
  m_priority = new TNumField(page);
Shinya Kitaoka 120a6e
  m_priority->setIsInteger(true);
Shinya Kitaoka 120a6e
  m_priority->setRange(1, 100);
Shinya Kitaoka 120a6e
  m_priority->setValue(50);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_depListLbl = new TLabel(page);
Shinya Kitaoka 120a6e
  m_depListLbl->setText("Task Dependencies:");
Shinya Kitaoka 120a6e
  m_depList = new DependedList(page);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SubmitPage::Data::~Data() {
Shinya Kitaoka 120a6e
  std::map<string, *="" submitpagetask="">::iterator it = m_tasks.begin();</string,>
Shinya Kitaoka 120a6e
  while (it != m_tasks.end()) {
Shinya Kitaoka 120a6e
    delete it->second;
Shinya Kitaoka 120a6e
    ++it;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  std::map<string, *="" taskconfigpanel="">::iterator it1 = m_configPanels.begin();</string,>
Shinya Kitaoka 120a6e
  while (it1 != m_configPanels.end()) {
Shinya Kitaoka 120a6e
    delete it1->second;
Shinya Kitaoka 120a6e
    ++it1;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::Data::configureNotify(const TDimension &size) {
Shinya Kitaoka 120a6e
  int x0 = 20;
Shinya Kitaoka 120a6e
  int y  = size.ly - 1 - 10;
Shinya Kitaoka 120a6e
  int x  = x0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_taskTypeLbl->setGeometry(x, y - 15, x + 100, y);
Shinya Kitaoka 120a6e
  m_taskType->setGeometry(x + 104, y - 15, x + 200, y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  x = x0;
Shinya Kitaoka 120a6e
  y -= 40;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_taskNameLbl->setGeometry(x, y - 15, x + 100, y);
Shinya Kitaoka 120a6e
  m_taskNameTextField->setGeometry(x + 104, y - 15, x + 250, y);
Shinya Kitaoka 120a6e
  x += 280;
Shinya Kitaoka 120a6e
  m_priorityLbl->setGeometry(x, y - 15, x + 50, y);
Shinya Kitaoka 120a6e
  m_priority->setGeometry(x + 54, y - 15, x + 100, y);
Shinya Kitaoka 120a6e
  m_submitAsSuspended->setGeometry(x + 130, y - 15, x + 280, y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  x += 310;
Shinya Kitaoka 120a6e
  m_submit->setGeometry(x, y - 15, x + 80, y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  x = x0;
Shinya Kitaoka 120a6e
  y -= 40;
Shinya Kitaoka 120a6e
  m_filepathLbl->setGeometry(x, y - 15, x + 100, y);
Shinya Kitaoka 120a6e
  m_filepathTextField->setGeometry(x + 104, y - 15, x + 650, y);
Shinya Kitaoka 120a6e
  m_casmBrowseBtn->setGeometry(x + 660, y - 15, x + 680, y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  y -= 40;
Shinya Kitaoka 120a6e
  x = x0;
Shinya Kitaoka 120a6e
  m_depListLbl->setGeometry(x, y - 15, x + 160, y);
Shinya Kitaoka 120a6e
  y -= 20;
Shinya Kitaoka 120a6e
  m_depList->setGeometry(x + 10, y - 80, size.lx - 1, y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  x = x0;
Shinya Kitaoka 120a6e
  y -= 90;
Shinya Kitaoka 120a6e
  // m_configPanel->setGeometry(0,0,size.lx-1,y);
Shinya Kitaoka 120a6e
  std::map<string, *="" taskconfigpanel="">::iterator it;</string,>
Shinya Kitaoka 120a6e
  it = m_configPanels.begin();
Shinya Kitaoka 120a6e
  for (; it != m_configPanels.end(); ++it)
Shinya Kitaoka 120a6e
    it->second->setGeometry(0, 0, size.lx - 1, y);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::Data::browseCasmFiles() {
Shinya Kitaoka 120a6e
  static FileBrowserPopup *puCasm   = 0L;
Shinya Kitaoka 120a6e
  static FileBrowserPopup *puScript = 0L;
Shinya Kitaoka 120a6e
  FileBrowserPopup *popup;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_taskType->getText() == "Casm") {
Shinya Kitaoka 120a6e
    if (!puCasm) {
Shinya Kitaoka 120a6e
      vector<string> fileTypes;</string>
Shinya Kitaoka 120a6e
      fileTypes.push_back("casm");
Shinya Kitaoka 120a6e
      puCasm = new FileBrowserPopup(m_page, fileTypes);
Shinya Kitaoka 120a6e
      puCasm->setOkAction(new TFileBrowserPopupAction<submitpage::data>(</submitpage::data>
Shinya Kitaoka 120a6e
          this, &SubmitPage::Data::load));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    popup = puCasm;
Shinya Kitaoka 120a6e
  } else if (m_taskType->getText() == "Script") {
Shinya Kitaoka 120a6e
    if (!puScript) {
Shinya Kitaoka 120a6e
      vector<string> fileTypes;</string>
Toshihiro Shimizu 890ddd
#ifdef WIN32
Shinya Kitaoka 120a6e
      fileTypes.push_back("bat");
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
      fileTypes.push_back("csh");
Shinya Kitaoka 120a6e
      fileTypes.push_back("sh");
Shinya Kitaoka 120a6e
      fileTypes.push_back("tcsh");
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
      puScript = new FileBrowserPopup(m_page, fileTypes);
Shinya Kitaoka 120a6e
      puScript->setOkAction(new TFileBrowserPopupAction<submitpage::data>(</submitpage::data>
Shinya Kitaoka 120a6e
          this, &SubmitPage::Data::load));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    popup = puScript;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!popup) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TFilePath fp = Application::instance()->getCurrentFolder();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
E'stato necessario fare questo controllo perche' il popup non e' in grado
Shinya Kitaoka 120a6e
di impostare opportunamente le cose
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  wstring path = fp.getWideString();
Shinya Kitaoka 120a6e
  if (fp != TFilePath() && (path[0] != '\\')) popup->setCurrentDir(fp);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDimension d = TMainshell::getMainshell()->getSize();
Toshihiro Shimizu 890ddd
#ifdef WIN32
Shinya Kitaoka 120a6e
  HDC hdc = GetDC(0);
Shinya Kitaoka 120a6e
  d.lx    = GetDeviceCaps(hdc, HORZRES);
Shinya Kitaoka 120a6e
  d.ly    = GetDeviceCaps(hdc, VERTRES);
Shinya Kitaoka 120a6e
  ReleaseDC(0, hdc);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  d -= popup->getSize();
Shinya Kitaoka 120a6e
  // TDimension d = TMainshell::getMainshell()->getSize() - popup->getSize();
Shinya Kitaoka 120a6e
  popup->popup(TPoint(d.lx / 2, d.ly / 2));
Shinya Kitaoka 120a6e
  popup->setCaption("Load " + m_taskType->getText());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::Data::load(const TFilePath &fp) {
Shinya Kitaoka 120a6e
  if (!TFileStatus(fp).doesExist()) {
Shinya Kitaoka 120a6e
    string msg = toString(fp.getWideString()) + "\n";
Shinya Kitaoka 120a6e
    msg += "File not found\n";
Shinya Kitaoka 120a6e
    msg += "Please verify that the path and file name are correct";
Shinya Kitaoka 120a6e
    m_filepathTextField->setText(toString(fp.getWideString()));
Shinya Kitaoka 120a6e
    TMessage::error(msg);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  string uncString = toString(fp.getWideString());
Shinya Kitaoka 120a6e
  if (toString(m_filepathTextField->getText()) != uncString) try {
Shinya Kitaoka 120a6e
      uncString = convertToUncString(fp);
Shinya Kitaoka 120a6e
    } catch (TException &e) {
Shinya Kitaoka 120a6e
      if (!TFileStatus(fp).doesExist()) {
Shinya Kitaoka 120a6e
        TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      uncString = toString(fp.getWideString());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  Application::instance()->setCurrentFolder(fp.getParentDir());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_filepathTextField->setText(uncString);
Shinya Kitaoka 120a6e
  m_taskNameTextField->setText(TFilePath(uncString).getName());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  string type = m_taskType->getText();
Toshihiro Shimizu 890ddd
#ifdef WIN32
Shinya Kitaoka 120a6e
  if (type == "Casm") {
Shinya Kitaoka 120a6e
    int x = uncString.find("\\", 2);
Shinya Kitaoka 120a6e
    while (x != string::npos) {
Shinya Kitaoka 120a6e
      uncString.replace(x, 1, "/", 0, 1);
Shinya Kitaoka 120a6e
      x = uncString.find("\\", x + 1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (type == "Casm")
Shinya Kitaoka 120a6e
    m_task = new CasmTask2;
Shinya Kitaoka 120a6e
  else if (type == "Script")
Shinya Kitaoka 120a6e
    m_task = new ScriptTask;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::map<string, *="" submitpagetask="">::iterator it = m_tasks.find(type);</string,>
Shinya Kitaoka 120a6e
  if (it != m_tasks.end()) {
Shinya Kitaoka 120a6e
    delete it->second;
Shinya Kitaoka 120a6e
    it->second = m_task;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    m_tasks.insert(std::make_pair(type, m_task));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_task->setFileArg(uncString);
Shinya Kitaoka 120a6e
  m_depList->clearAll();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_configPanel->setTask(m_task);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::Data::submit() {
Shinya Kitaoka 120a6e
  if (toString(m_filepathTextField->getText()) == "") {
Shinya Kitaoka 120a6e
    TMessage::error("You must load a file");
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    CasmTask2 *casm    = dynamic_cast<casmtask2 *="">(m_task);</casmtask2>
Shinya Kitaoka 120a6e
    ScriptTask *script = dynamic_cast<scripttask *="">(m_task);</scripttask>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef ZCOMP
Shinya Kitaoka 120a6e
    ZRenderTask *zrender = dynamic_cast<zrendertask *="">(m_task);</zrendertask>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (casm) {
Shinya Kitaoka 120a6e
      casm->checkNameUnc();
Shinya Kitaoka 120a6e
      submitCasm(casm);
Shinya Kitaoka 120a6e
    } else if (script) {
Shinya Kitaoka 120a6e
      script->checkNameUnc();
Shinya Kitaoka 120a6e
      submitScript(script);
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
#ifdef ZCOMP
Shinya Kitaoka 120a6e
    else if (zrender) {
Shinya Kitaoka 120a6e
      zrender->checkNameUnc();
Shinya Kitaoka 120a6e
      submitZRender(zrender);
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      TMessage::error("Verify if " + toString(m_filepathTextField->getText()) +
Shinya Kitaoka 120a6e
                      " is correct");
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (TException &e) {
Shinya Kitaoka 120a6e
    TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::Data::submitCasm(CasmTask2 *casm) {
Shinya Kitaoka 120a6e
  TFarmController *controller = Application::instance()->getController();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string nativeCmdLine("runcasm ");
Shinya Kitaoka 120a6e
  nativeCmdLine += casm->getFilePath();
Shinya Kitaoka 120a6e
  nativeCmdLine += " ";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (casm->m_setupFile != "") {
Shinya Kitaoka 120a6e
    nativeCmdLine += "-setup ";
Shinya Kitaoka 120a6e
    nativeCmdLine += casm->m_setupFile;
Shinya Kitaoka 120a6e
    nativeCmdLine += " ";
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  nativeCmdLine += casm->getCommandLine();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string casmName = casm->getName();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string user   = TSystem::getUserName();
Shinya Kitaoka 120a6e
  string host   = TSystem::getHostName();
Shinya Kitaoka 120a6e
  int stepCount = casm->m_end - casm->m_start + 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TFarmTaskGroup task(casmName, nativeCmdLine, user, host, stepCount,
Shinya Kitaoka 120a6e
                      (int)m_priority->getValue());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  map<string, string=""> dep             = casm->getDependencies();</string,>
Shinya Kitaoka 120a6e
  map<string, string="">::iterator itDep = dep.begin();</string,>
Shinya Kitaoka 120a6e
  for (; itDep != dep.end(); ++itDep) task.m_dependencies->add((*itDep).first);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int ra = casm->m_start;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int subCount = casm->m_end / casm->m_taskChunksize;
Shinya Kitaoka 120a6e
  if (casm->m_end % casm->m_taskChunksize) subCount++;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (subCount != 1)
Shinya Kitaoka 120a6e
    for (;;) {
Shinya Kitaoka 120a6e
      CasmTask2 subcasm(*casm);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      string cmdLine("runcasm ");
Shinya Kitaoka 120a6e
      int rb = tmin(ra + casm->m_taskChunksize - 1, casm->m_end);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      subcasm.m_start = ra;
Shinya Kitaoka 120a6e
      subcasm.m_end   = rb;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      cmdLine += subcasm.getFilePath();
Shinya Kitaoka 120a6e
      cmdLine += " ";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (subcasm.m_setupFile != "") {
Shinya Kitaoka 120a6e
        cmdLine += "-setup ";
Shinya Kitaoka 120a6e
        cmdLine += subcasm.m_setupFile;
Shinya Kitaoka 120a6e
        cmdLine += " ";
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      cmdLine += subcasm.getCommandLine();
Shinya Kitaoka 120a6e
      cmdLine += " -nowait ";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      try {
Shinya Kitaoka 120a6e
        string name = casmName + " " + toString(ra) + "-" + toString(rb);
Shinya Kitaoka 120a6e
        stepCount   = rb - ra + 1;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        TFarmTask *subTask = new TFarmTask(name, cmdLine, user, host, stepCount,
Shinya Kitaoka 120a6e
                                           (int)m_priority->getValue());
Shinya Kitaoka 120a6e
        subTask->m_dependencies =
Shinya Kitaoka 120a6e
            new TFarmTask::Dependencies(*task.m_dependencies);
Shinya Kitaoka 120a6e
        task.addTask(subTask);
Shinya Kitaoka 120a6e
      } catch (TException &e) {
Shinya Kitaoka 120a6e
        TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (rb == casm->m_end) break;
Shinya Kitaoka 120a6e
      ra = rb + 1;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    controller->addTask(task, m_submitAsSuspended->isSelected());
Shinya Kitaoka 120a6e
  } catch (TException &e) {
Shinya Kitaoka 120a6e
    TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::Data::submitScript(ScriptTask *script) {
Shinya Kitaoka 120a6e
  TFarmController *controller = Application::instance()->getController();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string nativeCmdLine = script->getCommandLine();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  string scriptName = script->getName();
Shinya Kitaoka 120a6e
  string user       = TSystem::getUserName();
Shinya Kitaoka 120a6e
  string host       = TSystem::getHostName();
Shinya Kitaoka 120a6e
  TFarmTask task(scriptName, nativeCmdLine, user, host, 1,
Shinya Kitaoka 120a6e
                 (int)m_priority->getValue());
Shinya Kitaoka 120a6e
  map<string, string=""> dep             = script->getDependencies();</string,>
Shinya Kitaoka 120a6e
  map<string, string="">::iterator itDep = dep.begin();</string,>
Shinya Kitaoka 120a6e
  for (; itDep != dep.end(); ++itDep) task.m_dependencies->add((*itDep).first);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Shinya Kitaoka 120a6e
  task.m_platform = Windows;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  task.m_platform = Irix;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    controller->addTask(task, m_submitAsSuspended->isSelected());
Shinya Kitaoka 120a6e
  } catch (TException &e) {
Shinya Kitaoka 120a6e
    TMessage::error(toString(e.getMessage()));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::Data::onTaskType(string type) {
Shinya Kitaoka 120a6e
  std::map<string, *="" taskconfigpanel="">::iterator it;</string,>
Shinya Kitaoka 120a6e
  it = m_configPanels.find(type);
Shinya Kitaoka 120a6e
  if (it != m_configPanels.end()) {
Shinya Kitaoka 120a6e
    m_configPanel->hide();
Shinya Kitaoka 120a6e
    TaskConfigPanel *configPanel = it->second;
Shinya Kitaoka 120a6e
    m_configPanel                = configPanel;
Shinya Kitaoka 120a6e
    m_configPanel->show();
Shinya Kitaoka 120a6e
    std::map<string, *="" submitpagetask="">::iterator it1 = m_tasks.find(type);</string,>
Shinya Kitaoka 120a6e
    if (it1 != m_tasks.end()) {
Shinya Kitaoka 120a6e
      m_task = it1->second;
Shinya Kitaoka 120a6e
      m_depList->setList(m_task->getDependencies());
Shinya Kitaoka 120a6e
      m_filepathTextField->setText(m_task->getFilePath());
Shinya Kitaoka 120a6e
      m_taskNameTextField->setText(m_task->getName());
Shinya Kitaoka 120a6e
      m_configPanel->setTask(m_task);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      std::map<string, string=""> tasks;</string,>
Shinya Kitaoka 120a6e
      m_depList->setList(tasks);
Shinya Kitaoka 120a6e
      m_taskNameTextField->setText("");
Shinya Kitaoka 120a6e
      m_filepathTextField->setText("");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SubmitPage::SubmitPage(TWidget *parent) : TabPage(parent, "Submit Task") {
Shinya Kitaoka 120a6e
  m_data = new SubmitPage::Data(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SubmitPage::~SubmitPage() { delete m_data; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::configureNotify(const TDimension &size) {
Shinya Kitaoka 120a6e
  m_data->configureNotify(size);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::onActivate() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::onDeactivate() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SubmitPageTask *SubmitPage::getTask() const { return m_data->m_task; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::setTask(SubmitPageTask *task) {
Shinya Kitaoka 120a6e
  string type        = "Casm";
Shinya Kitaoka 120a6e
  CasmTask2 *casm    = dynamic_cast<casmtask2 *="">(task);</casmtask2>
Shinya Kitaoka 120a6e
  ScriptTask *script = dynamic_cast<scripttask *="">(task);</scripttask>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef ZCOMP
Shinya Kitaoka 120a6e
  ZRenderTask *zrender = dynamic_cast<zrendertask *="">(task);</zrendertask>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (casm)
Shinya Kitaoka 120a6e
    m_data->m_task = casm;
Shinya Kitaoka 120a6e
  else if (script) {
Shinya Kitaoka 120a6e
    m_data->m_task = script;
Shinya Kitaoka 120a6e
    type           = "Script";
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#ifdef ZCOMP
Shinya Kitaoka 120a6e
  else if (zrender) {
Shinya Kitaoka 120a6e
    m_data->m_task = zrender;
Shinya Kitaoka 120a6e
    type           = "ZComp";
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::map<string, *="" submitpagetask="">::iterator it = m_data->m_tasks.find(type);</string,>
Shinya Kitaoka 120a6e
  if (it == m_data->m_tasks.end()) {
Shinya Kitaoka 120a6e
    m_data->m_tasks.insert(std::make_pair(type, m_data->m_task));
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    it->second = m_data->m_task;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::map<string, *="" taskconfigpanel="">::iterator it1 =</string,>
Shinya Kitaoka 120a6e
      m_data->m_configPanels.find(type);
Shinya Kitaoka 120a6e
  if (it1 != m_data->m_configPanels.end()) {
Shinya Kitaoka 120a6e
    it1->second->setTask(task);
Shinya Kitaoka 120a6e
    m_data->m_configPanel = it1->second;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void SubmitPage::onTextField(const string &name, bool isName) {
Shinya Kitaoka 120a6e
  if (!m_data->m_task) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (isName)
Shinya Kitaoka 120a6e
    m_data->m_task->setName(name);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    m_data->m_task->setFilePath(name);
Toshihiro Shimizu 890ddd
}