Export object dependencies to graphviz file
This commit is contained in:
parent
6621c00c10
commit
9170bfe045
|
@ -847,6 +847,31 @@ unsigned int Document::getMemSize (void) const
|
|||
return size;
|
||||
}
|
||||
|
||||
void Document::exportGraphviz(std::ostream& out)
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
names.reserve(d->objectMap.size());
|
||||
DependencyList DepList;
|
||||
std::map<DocumentObject*,Vertex> VertexObjectList;
|
||||
|
||||
// Filling up the adjacency List
|
||||
for (std::map<std::string,DocumentObject*>::const_iterator It = d->objectMap.begin(); It != d->objectMap.end();++It) {
|
||||
// add the object as Vertex and remember the index
|
||||
VertexObjectList[It->second] = add_vertex(DepList);
|
||||
names.push_back(It->second->Label.getValue());
|
||||
}
|
||||
// add the edges
|
||||
for (std::map<std::string,DocumentObject*>::const_iterator It = d->objectMap.begin(); It != d->objectMap.end();++It) {
|
||||
std::vector<DocumentObject*> OutList = It->second->getOutList();
|
||||
for (std::vector<DocumentObject*>::const_iterator It2=OutList.begin();It2!=OutList.end();++It2) {
|
||||
if (*It2)
|
||||
add_edge(VertexObjectList[It->second],VertexObjectList[*It2],DepList);
|
||||
}
|
||||
}
|
||||
|
||||
boost::write_graphviz(out, DepList, boost::make_label_writer(&(names[0])));
|
||||
}
|
||||
|
||||
// Save the document under the name it has been opened
|
||||
bool Document::save (void)
|
||||
{
|
||||
|
|
|
@ -114,6 +114,7 @@ public:
|
|||
/// Restore the document from the file in Property Path
|
||||
void restore (void);
|
||||
void exportObjects(const std::vector<App::DocumentObject*>&, std::ostream&);
|
||||
void exportGraphviz(std::ostream&);
|
||||
std::vector<App::DocumentObject*> importObjects(std::istream&);
|
||||
/// Opens the document from its file name
|
||||
//void open (void);
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
<UserDocu>Restore the document from disc</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="exportGraphviz">
|
||||
<Documentation>
|
||||
<UserDocu>Export the dependencies of the objects as graph</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="openTransaction">
|
||||
<Documentation>
|
||||
<UserDocu>Open a new Undo/Redo transaction.</UserDocu>
|
||||
|
|
|
@ -92,6 +92,25 @@ PyObject* DocumentPy::restore(PyObject * args)
|
|||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::exportGraphviz(PyObject * args)
|
||||
{
|
||||
char* fn=0;
|
||||
if (!PyArg_ParseTuple(args, "|s",&fn)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (fn) {
|
||||
Base::FileInfo fi(fn);
|
||||
Base::ofstream str(fi);
|
||||
getDocumentPtr()->exportGraphviz(str);
|
||||
str.close();
|
||||
Py_Return;
|
||||
}
|
||||
else {
|
||||
std::stringstream str;
|
||||
getDocumentPtr()->exportGraphviz(str);
|
||||
return PyString_FromString(str.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::addObject(PyObject *args)
|
||||
{
|
||||
char *sType,*sName=0;
|
||||
|
|
|
@ -24,12 +24,16 @@
|
|||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QClipboard>
|
||||
# include <QEventLoop>
|
||||
# include <QStatusBar>
|
||||
# include <QPointer>
|
||||
# include <QProcess>
|
||||
# include <sstream>
|
||||
#endif
|
||||
#include <algorithm>
|
||||
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <App/Document.h>
|
||||
|
@ -311,6 +315,77 @@ bool StdCmdMergeProjects::isActive(void)
|
|||
return this->hasActiveDocument();
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Std_ExportGraphviz
|
||||
//===========================================================================
|
||||
|
||||
DEF_STD_CMD_A(StdCmdExportGraphviz);
|
||||
|
||||
StdCmdExportGraphviz::StdCmdExportGraphviz()
|
||||
: Command("Std_ExportGraphviz")
|
||||
{
|
||||
// seting the
|
||||
sGroup = QT_TR_NOOP("Tools");
|
||||
sMenuText = QT_TR_NOOP("Dependency graph...");
|
||||
sToolTipText = QT_TR_NOOP("Show the dependency graph of the objects in the active document");
|
||||
sStatusTip = QT_TR_NOOP("Show the dependency graph of the objects in the active document");
|
||||
sWhatsThis = "Std_ExportGraphviz";
|
||||
eType = 0;
|
||||
}
|
||||
|
||||
void StdCmdExportGraphviz::activated(int iMsg)
|
||||
{
|
||||
App::Document* doc = App::GetApplication().getActiveDocument();
|
||||
Base::FileInfo fi(Base::FileInfo::getTempFileName());
|
||||
Base::ofstream str(fi);
|
||||
doc->exportGraphviz(str);
|
||||
str.close();
|
||||
|
||||
Base::FileInfo out(Base::FileInfo::getTempFileName());
|
||||
QProcess proc;
|
||||
QEventLoop loop;
|
||||
QObject::connect(&proc, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
&loop, SLOT(quit()));
|
||||
QStringList args;
|
||||
args << QLatin1String("-Tpng") << QString::fromUtf8(fi.filePath().c_str())
|
||||
<< QLatin1String("-o") << QString::fromUtf8(out.filePath().c_str());
|
||||
QString exe = QLatin1String("dot");
|
||||
QStringList env = QProcess::systemEnvironment();
|
||||
proc.setEnvironment(env);
|
||||
proc.start(exe, args);
|
||||
if (proc.state() == QProcess::Running) {
|
||||
loop.exec();
|
||||
fi.deleteFile();
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(getMainWindow(),
|
||||
qApp->translate("Std_ExportGraphviz","Graphviz not found"),
|
||||
qApp->translate("Std_ExportGraphviz","Graphviz couldn't be found on your system"));
|
||||
fi.deleteFile();
|
||||
return;
|
||||
}
|
||||
|
||||
if (out.exists()) {
|
||||
QPixmap px(QString::fromUtf8(out.filePath().c_str()), "PNG");
|
||||
out.deleteFile();
|
||||
QLabel* label = new QLabel(0);
|
||||
label->setAttribute(Qt::WA_DeleteOnClose);
|
||||
label->setPixmap(px);
|
||||
label->resize(px.size());
|
||||
label->show();
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(getMainWindow(),
|
||||
qApp->translate("Std_ExportGraphviz","Graphviz failed"),
|
||||
qApp->translate("Std_ExportGraphviz","Graphviz failed to create an image file"));
|
||||
}
|
||||
}
|
||||
|
||||
bool StdCmdExportGraphviz::isActive(void)
|
||||
{
|
||||
return (getActiveGuiDocument() ? true : false);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Std_New
|
||||
//===========================================================================
|
||||
|
@ -1126,6 +1201,7 @@ void CreateDocCommands(void)
|
|||
rcCmdMgr.addCommand(new StdCmdImport());
|
||||
rcCmdMgr.addCommand(new StdCmdExport());
|
||||
rcCmdMgr.addCommand(new StdCmdMergeProjects());
|
||||
rcCmdMgr.addCommand(new StdCmdExportGraphviz());
|
||||
|
||||
rcCmdMgr.addCommand(new StdCmdSave());
|
||||
rcCmdMgr.addCommand(new StdCmdSaveAs());
|
||||
|
|
|
@ -490,8 +490,9 @@ MenuItem* StdWorkbench::setupMenuBar() const
|
|||
MenuItem* tool = new MenuItem( menuBar );
|
||||
tool->setCommand("&Tools");
|
||||
*tool << "Std_DlgParameter" << "Separator"
|
||||
<< "Std_ViewScreenShot" << "Std_SceneInspector" << "Std_DemoMode"
|
||||
<< "Separator" << "Std_DlgCustomize";
|
||||
<< "Std_ViewScreenShot" << "Std_SceneInspector"
|
||||
<< "Std_ExportGraphviz" << "Std_ProjectUtil"
|
||||
<< "Std_DemoMode" << "Separator" << "Std_DlgCustomize";
|
||||
|
||||
// Macro
|
||||
MenuItem* macro = new MenuItem( menuBar );
|
||||
|
|
|
@ -183,7 +183,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
|||
<< "Std_DlgMacroRecord" << "Std_MacroStopRecord"
|
||||
<< "Std_DlgMacroExecute" << "Std_DlgMacroExecuteDirect"
|
||||
<< "Separator" << "Std_ViewScreenShot" << "Std_SceneInspector"
|
||||
<< "Std_ProjectUtil" << "Std_DemoMode" << "Separator" << "Std_DlgCustomize";
|
||||
<< "Std_ExportGraphviz" << "Std_ProjectUtil"
|
||||
<< "Std_DemoMode" << "Separator" << "Std_DlgCustomize";
|
||||
|
||||
// Mesh ****************************************************************************************************
|
||||
Gui::MenuItem* mesh = new Gui::MenuItem( menuBar );
|
||||
|
|
Loading…
Reference in New Issue
Block a user