DependencyGraph: Add unflatten step
This commit is contained in:
@@ -68,14 +68,16 @@ public:
|
||||
: QThread(parent)
|
||||
{
|
||||
#if QT_VERSION < 0x050000
|
||||
proc.moveToThread(this);
|
||||
dotProc.moveToThread(this);
|
||||
unflattenProc.moveToThread(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~GraphvizWorker()
|
||||
{
|
||||
#if QT_VERSION >= 0x050000
|
||||
proc.moveToThread(this);
|
||||
dotProc.moveToThread(this);
|
||||
unflattenProc.moveToThread(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -97,20 +99,31 @@ public:
|
||||
}
|
||||
|
||||
void run() {
|
||||
// Write data to process
|
||||
proc.write(str);
|
||||
proc.closeWriteChannel();
|
||||
if (!proc.waitForFinished()) {
|
||||
// Write data to unflatten process
|
||||
unflattenProc.write(str);
|
||||
unflattenProc.closeWriteChannel();
|
||||
QByteArray preprocessed = str;
|
||||
//no error handling: unflatten is optional
|
||||
unflattenProc.waitForFinished();
|
||||
preprocessed = unflattenProc.readAll();
|
||||
|
||||
dotProc.write(preprocessed);
|
||||
dotProc.closeWriteChannel();
|
||||
if (!dotProc.waitForFinished()) {
|
||||
Q_EMIT error();
|
||||
quit();
|
||||
}
|
||||
|
||||
// Emit result; it will get queued for processing in the main thread
|
||||
Q_EMIT svgFileRead(proc.readAll());
|
||||
Q_EMIT svgFileRead(dotProc.readAll());
|
||||
}
|
||||
|
||||
QProcess * process() {
|
||||
return &proc;
|
||||
QProcess * dotProcess() {
|
||||
return &dotProc;
|
||||
}
|
||||
|
||||
QProcess * unflattenProcess() {
|
||||
return &unflattenProc;
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
@@ -118,8 +131,8 @@ Q_SIGNALS:
|
||||
void error();
|
||||
|
||||
private:
|
||||
QProcess proc;
|
||||
QByteArray str;
|
||||
QProcess dotProc, unflattenProc;
|
||||
QByteArray str, flatStr;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -176,9 +189,12 @@ void GraphvizView::updateSvgItem(const App::Document &doc)
|
||||
return;
|
||||
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Paths");
|
||||
QProcess * proc = thread->process();
|
||||
QStringList args;
|
||||
QProcess * dotProc = thread->dotProcess();
|
||||
QProcess * flatProc = thread->unflattenProcess();
|
||||
QStringList args, flatArgs;
|
||||
args << QLatin1String("-Tsvg");
|
||||
flatArgs << QLatin1String("-c3 -l3");
|
||||
|
||||
#ifdef FC_OS_LINUX
|
||||
QString path = QString::fromUtf8(hGrp->GetASCII("Graphviz", "/usr/bin").c_str());
|
||||
#else
|
||||
@@ -186,14 +202,19 @@ void GraphvizView::updateSvgItem(const App::Document &doc)
|
||||
#endif
|
||||
bool pathChanged = false;
|
||||
#ifdef FC_OS_WIN32
|
||||
QString exe = QString::fromLatin1("\"%1/dot\"").arg(path);
|
||||
QString dot = QString::fromLatin1("\"%1/dot\"").arg(path);
|
||||
QString unflatten = QString::fromLatin1("\"%1/unflatten\"").arg(path);
|
||||
#else
|
||||
QString exe = QString::fromLatin1("%1/dot").arg(path);
|
||||
QString dot = QString::fromLatin1("%1/dot").arg(path);
|
||||
QString unflatten = QString::fromLatin1("%1/unflatten").arg(path);
|
||||
#endif
|
||||
proc->setEnvironment(QProcess::systemEnvironment());
|
||||
dotProc->setEnvironment(QProcess::systemEnvironment());
|
||||
flatProc->setEnvironment(QProcess::systemEnvironment());
|
||||
do {
|
||||
proc->start(exe, args);
|
||||
if (!proc->waitForStarted()) {
|
||||
flatProc->start(unflatten, flatArgs);
|
||||
flatProc->waitForStarted();
|
||||
dotProc->start(dot, args);
|
||||
if (!dotProc->waitForStarted()) {
|
||||
int ret = QMessageBox::warning(Gui::getMainWindow(),
|
||||
qApp->translate("Std_ExportGraphviz","Graphviz not found"),
|
||||
qApp->translate("Std_ExportGraphviz","Graphviz couldn't be found on your system.\n"
|
||||
@@ -211,9 +232,11 @@ void GraphvizView::updateSvgItem(const App::Document &doc)
|
||||
}
|
||||
pathChanged = true;
|
||||
#ifdef FC_OS_WIN32
|
||||
exe = QString::fromLatin1("\"%1/dot\"").arg(path);
|
||||
dot = QString::fromLatin1("\"%1/dot\"").arg(path);
|
||||
unflatten = QString::fromLatin1("\"%1/unflatten\"").arg(path);
|
||||
#else
|
||||
exe = QString::fromLatin1("%1/dot").arg(path);
|
||||
dot = QString::fromLatin1("%1/dot").arg(path);
|
||||
unflatten = QString::fromLatin1("%1/unflatten").arg(path);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
@@ -230,7 +253,6 @@ void GraphvizView::updateSvgItem(const App::Document &doc)
|
||||
graphCode = stream.str();
|
||||
|
||||
// Update worker thread, and start it
|
||||
std::cout<<graphCode<<std::endl;
|
||||
thread->setData(QByteArray(graphCode.c_str(), graphCode.size()));
|
||||
thread->startThread();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user