2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "casmsubmitpage.h"
|
|
|
|
#include "tfilepath.h"
|
|
|
|
#include "tconvert.h"
|
|
|
|
#include "tsystem.h"
|
|
|
|
|
|
|
|
#include "tw/mainshell.h"
|
|
|
|
#include "tw/textfield.h"
|
|
|
|
#include "tw/label.h"
|
|
|
|
#include "tw/optionmenu.h"
|
|
|
|
#include "tw/button.h"
|
|
|
|
#include "tw/checkbox.h"
|
|
|
|
|
|
|
|
#include "filebrowserpopup.h"
|
|
|
|
#include "casmconfigpanel.h"
|
|
|
|
#include "casmfileinfo.h"
|
|
|
|
#include "tfarmcontroller.h"
|
|
|
|
#include "application.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include "tw/message.h"
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class CasmSubmitPage::Data {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
Data(CasmSubmitPage *cspage);
|
|
|
|
~Data() { delete m_casmTask; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void configureNotify(const TDimension &size);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void browseCasmFiles();
|
|
|
|
void submit();
|
|
|
|
void loadCasm(const TFilePath &fp);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
CasmSubmitPage *m_cspage;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TLabel *m_taskNameLabel;
|
|
|
|
TTextField *m_taskNameTextField;
|
|
|
|
TCheckBox *m_submitAsSuspended;
|
|
|
|
TButton *m_submit;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TLabel *m_filepathLabel;
|
|
|
|
TTextField *m_filepathTextField;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TButton *m_casmBrowseBtn;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
CasmConfigPanel *m_configPanel;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
CasmTask *m_casmTask;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
CasmSubmitPage::Data::Data(CasmSubmitPage *cspage)
|
2016-06-15 18:43:10 +12:00
|
|
|
: m_cspage(cspage), m_casmTask(0) {
|
|
|
|
m_taskNameLabel = new TLabel(cspage);
|
|
|
|
m_taskNameLabel->setText("Task Name:");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_submitAsSuspended = new TCheckBox(cspage, "Submit as Suspended");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_taskNameTextField = new TTextField(cspage);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_filepathLabel = new TLabel(cspage);
|
|
|
|
m_filepathLabel->setText("File Path:");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_filepathTextField = new TTextField(cspage);
|
|
|
|
m_casmBrowseBtn = new TButton(cspage);
|
|
|
|
m_casmBrowseBtn->setTitle("...");
|
|
|
|
tconnect(*m_casmBrowseBtn, this, &CasmSubmitPage::Data::browseCasmFiles);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_submit = new TButton(cspage);
|
|
|
|
m_submit->setTitle("Submit");
|
|
|
|
tconnect(*m_submit, this, &CasmSubmitPage::Data::submit);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_configPanel = new CasmConfigPanel(cspage);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CasmSubmitPage::Data::configureNotify(const TDimension &size) {
|
|
|
|
int x0 = 20;
|
|
|
|
int y = size.ly - 1 - 10;
|
|
|
|
int x = x0;
|
|
|
|
|
|
|
|
m_taskNameLabel->setGeometry(x, y - 15, x + 100, y);
|
|
|
|
m_taskNameTextField->setGeometry(x + 104, y - 15, x + 250, y);
|
|
|
|
x += 280;
|
|
|
|
m_submitAsSuspended->setGeometry(x, y - 15, x + 120, y);
|
|
|
|
x += 150;
|
|
|
|
m_submit->setGeometry(x, y - 15, x + 80, y);
|
|
|
|
x = x0;
|
|
|
|
y -= 40;
|
|
|
|
|
|
|
|
m_filepathLabel->setGeometry(x, y - 15, x + 100, y);
|
|
|
|
m_filepathTextField->setGeometry(x + 104, y - 15, x + 650, y);
|
|
|
|
m_casmBrowseBtn->setGeometry(x + 660, y - 15, x + 680, y);
|
|
|
|
x = x0;
|
|
|
|
y -= 40;
|
|
|
|
|
|
|
|
m_configPanel->setGeometry(0, 0, size.lx - 1, y);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CasmSubmitPage::Data::browseCasmFiles() {
|
|
|
|
static FileBrowserPopup *popup = 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!popup) {
|
|
|
|
vector<string> fileTypes;
|
|
|
|
fileTypes.push_back("casm");
|
|
|
|
popup = new FileBrowserPopup(m_cspage, fileTypes);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
popup->setOkAction(new TFileBrowserPopupAction<CasmSubmitPage::Data>(
|
|
|
|
this, &CasmSubmitPage::Data::loadCasm));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (!popup) return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFilePath fp = Application::instance()->getCurrentFolder();
|
|
|
|
if (fp != TFilePath()) popup->setCurrentDir(fp);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TDimension d = TMainshell::getMainshell()->getSize();
|
2016-03-19 06:57:51 +13:00
|
|
|
#ifdef WIN32
|
2016-06-15 18:43:10 +12:00
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
d.lx = GetDeviceCaps(hdc, HORZRES);
|
|
|
|
d.ly = GetDeviceCaps(hdc, VERTRES);
|
|
|
|
ReleaseDC(0, hdc);
|
2016-03-19 06:57:51 +13:00
|
|
|
#endif
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
d -= popup->getSize();
|
|
|
|
// TDimension d = TMainshell::getMainshell()->getSize() - popup->getSize();
|
|
|
|
popup->popup(TPoint(d.lx / 2, d.ly / 2));
|
|
|
|
popup->setCaption("Load Casm");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CasmSubmitPage::Data::submit() {
|
|
|
|
if (m_filepathTextField->getText() == toWideString("")) {
|
|
|
|
TMessage::error("You must load a file");
|
|
|
|
return;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
CasmTask *casm = m_configPanel->getTask();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFarmController *controller = Application::instance()->getController();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
string nativeCmdLine("runcasm ");
|
|
|
|
nativeCmdLine += casm->m_casmFile;
|
|
|
|
nativeCmdLine += " ";
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (casm->m_setupFile != "") {
|
|
|
|
nativeCmdLine += "-setup ";
|
|
|
|
nativeCmdLine += casm->m_setupFile;
|
|
|
|
nativeCmdLine += " ";
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
nativeCmdLine += casm->getCommandLine();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
string casmName = TFilePath(casm->m_casmFile).getName();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int stepCount = casm->m_end - casm->m_start + 1;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFarmTaskGroup task(casmName, nativeCmdLine, TSystem::getUserName(),
|
|
|
|
TSystem::getHostName(), stepCount);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int ra = casm->m_start;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
for (;;) {
|
|
|
|
CasmTask subcasm(*casm);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
string cmdLine("runcasm ");
|
|
|
|
int rb = tmin(ra + casm->m_taskChunksize - 1, casm->m_end);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
subcasm.m_start = ra;
|
|
|
|
subcasm.m_end = rb;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
cmdLine += subcasm.m_casmFile;
|
|
|
|
cmdLine += " ";
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (subcasm.m_setupFile != "") {
|
|
|
|
cmdLine += "-setup ";
|
|
|
|
cmdLine += subcasm.m_setupFile;
|
|
|
|
cmdLine += " ";
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
cmdLine += subcasm.getCommandLine();
|
|
|
|
cmdLine += " -nowait ";
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
try {
|
|
|
|
string name = casmName + " " + toString(ra) + "-" + toString(rb);
|
|
|
|
stepCount = rb - ra + 1;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
task.addTask(new TFarmTask(name, cmdLine, TSystem::getUserName(),
|
|
|
|
TSystem::getHostName(), stepCount));
|
|
|
|
} catch (TException &e) {
|
|
|
|
TMessage::error(toString(e.getMessage()));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (rb == casm->m_end) break;
|
|
|
|
ra = rb + 1;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
try {
|
|
|
|
controller->addTask(task, m_submitAsSuspended->isSelected());
|
|
|
|
} catch (TException &e) {
|
|
|
|
TMessage::error(toString(e.getMessage()));
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void DisplayStruct(LPNETRESOURCE lpnr) {
|
|
|
|
string info;
|
|
|
|
if (lpnr->lpLocalName) {
|
|
|
|
info += lpnr->lpLocalName;
|
|
|
|
info += " = ";
|
|
|
|
}
|
|
|
|
info += lpnr->lpRemoteName;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
MessageBox(NULL, info.c_str(), "Connection info", 0);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
BOOL WINAPI EnumerateFunc(LPNETRESOURCE lpnr) {
|
|
|
|
DWORD dwResult, dwResultEnum;
|
|
|
|
HANDLE hEnum;
|
|
|
|
DWORD cbBuffer = 16384; // 16K is a good size
|
|
|
|
DWORD cEntries = -1; // enumerate all possible entries
|
|
|
|
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
|
|
|
|
DWORD i;
|
|
|
|
//
|
|
|
|
// Call the WNetOpenEnum function to begin the enumeration.
|
|
|
|
//
|
|
|
|
dwResult = WNetOpenEnum(
|
|
|
|
RESOURCE_CONNECTED /*RESOURCE_GLOBALNET*/, // all network resources
|
|
|
|
RESOURCETYPE_ANY, // all resources
|
|
|
|
0, // enumerate all resources
|
|
|
|
lpnr, // NULL first time the function is called
|
|
|
|
&hEnum); // handle to the resource
|
|
|
|
|
|
|
|
if (dwResult != NO_ERROR) {
|
|
|
|
//
|
|
|
|
// Process errors with an application-defined error handler.
|
|
|
|
//
|
|
|
|
// NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetOpenEnum");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Call the GlobalAlloc function to allocate resources.
|
|
|
|
//
|
|
|
|
lpnrLocal = (LPNETRESOURCE)GlobalAlloc(GPTR, cbBuffer);
|
|
|
|
|
|
|
|
do {
|
|
|
|
//
|
|
|
|
// Initialize the buffer.
|
|
|
|
//
|
|
|
|
ZeroMemory(lpnrLocal, cbBuffer);
|
|
|
|
//
|
|
|
|
// Call the WNetEnumResource function to continue
|
|
|
|
// the enumeration.
|
|
|
|
//
|
|
|
|
dwResultEnum = WNetEnumResource(hEnum, // resource handle
|
|
|
|
&cEntries, // defined locally as -1
|
|
|
|
lpnrLocal, // LPNETRESOURCE
|
|
|
|
&cbBuffer); // buffer size
|
|
|
|
//
|
|
|
|
// If the call succeeds, loop through the structures.
|
|
|
|
//
|
|
|
|
if (dwResultEnum == NO_ERROR) {
|
|
|
|
for (i = 0; i < cEntries; i++) {
|
|
|
|
// Call an application-defined function to
|
|
|
|
// display the contents of the NETRESOURCE structures.
|
|
|
|
//
|
|
|
|
DisplayStruct(&lpnrLocal[i]);
|
|
|
|
|
|
|
|
// If the NETRESOURCE structure represents a container resource,
|
|
|
|
// call the EnumerateFunc function recursively.
|
|
|
|
|
|
|
|
if (RESOURCEUSAGE_CONTAINER ==
|
|
|
|
(lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER))
|
|
|
|
if (!EnumerateFunc(&lpnrLocal[i])) return FALSE;
|
|
|
|
// TextOut(hdc, 10, 10, "EnumerateFunc returned FALSE.", 29);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Process errors.
|
|
|
|
//
|
|
|
|
else if (dwResultEnum != ERROR_NO_MORE_ITEMS) {
|
|
|
|
// NetErrorHandler(hwnd, dwResultEnum, (LPSTR)"WNetEnumResource");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// End do.
|
|
|
|
//
|
|
|
|
while (dwResultEnum != ERROR_NO_MORE_ITEMS);
|
|
|
|
//
|
|
|
|
// Call the GlobalFree function to free the memory.
|
|
|
|
//
|
|
|
|
GlobalFree((HGLOBAL)lpnrLocal);
|
|
|
|
//
|
|
|
|
// Call WNetCloseEnum to end the enumeration.
|
|
|
|
//
|
|
|
|
dwResult = WNetCloseEnum(hEnum);
|
|
|
|
|
|
|
|
if (dwResult != NO_ERROR) {
|
|
|
|
//
|
|
|
|
// Process errors.
|
|
|
|
//
|
|
|
|
// NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCloseEnum");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CasmSubmitPage::Data::loadCasm(const TFilePath &fp) {
|
|
|
|
if (!TFileStatus(fp).doesExist()) {
|
|
|
|
string msg = toString(fp.getWideString()) + "\n";
|
|
|
|
msg += "File not found\n";
|
|
|
|
msg += "Please verify that the path and file name are correct";
|
|
|
|
m_filepathTextField->setText("");
|
|
|
|
TMessage::error(msg);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
Application::instance()->setCurrentFolder(fp.getParentDir());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
string uncString = convertToUncString(fp);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_filepathTextField->setText(uncString);
|
|
|
|
m_taskNameTextField->setText(TFilePath(uncString).getName());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2016-06-15 18:43:10 +12:00
|
|
|
int x = uncString.find("\\", 2);
|
|
|
|
while (x != string::npos) {
|
|
|
|
uncString.replace(x, 1, "/", 0, 1);
|
|
|
|
x = uncString.find("\\", x + 1);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
#endif
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFilePath uncFilePath = TFilePath(uncString);
|
|
|
|
CasmFileInfo casmFileInfo(uncFilePath);
|
|
|
|
int start, end;
|
|
|
|
bool interlaced;
|
|
|
|
casmFileInfo.getFrameRange(start, end, interlaced);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (m_casmTask) delete m_casmTask;
|
|
|
|
m_casmTask = new CasmTask;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_casmTask->m_casmFile = uncString;
|
|
|
|
m_casmTask->m_start = start;
|
|
|
|
m_casmTask->m_end = end;
|
|
|
|
m_casmTask->m_step = 1;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
m_configPanel->setTask(m_casmTask);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
CasmSubmitPage::CasmSubmitPage(TWidget *parent)
|
2016-06-15 18:43:10 +12:00
|
|
|
: TabPage(parent, "SubmitCasm") {
|
|
|
|
m_data = new CasmSubmitPage::Data(this);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
CasmSubmitPage::~CasmSubmitPage() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CasmSubmitPage::configureNotify(const TDimension &size) {
|
|
|
|
m_data->configureNotify(size);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CasmSubmitPage::onActivate() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CasmSubmitPage::onDeactivate() {}
|