Skip to content

Commit

Permalink
Gui: Added entry to Selection View's context menu, to use selected ob…
Browse files Browse the repository at this point in the history
…jects in the python console
  • Loading branch information
yorikvanhavre committed Apr 8, 2015
1 parent 892b7ae commit 5d0bc52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Gui/SelectionView.cpp
Expand Up @@ -225,6 +225,28 @@ void SelectionView::treeSelect(void)
Gui::Command::runCommand(Gui::Command::Gui,"Gui.runCommand(\"Std_TreeSelection\")");
}

void SelectionView::toPython(void)
{
QListWidgetItem *item = selectionView->currentItem();
if (!item)
return;
QStringList elements = item->text().split(QString::fromAscii("."));
// remove possible space from object name followed by label
elements[1] = elements[1].split(QString::fromAscii(" "))[0];

QString cmd = QString::fromAscii("obj = App.getDocument(\"%1\").getObject(\"%2\")").arg(elements[0]).arg(elements[1]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toAscii());
if (elements.length() > 2) {
elements[2] = elements[2].split(QString::fromAscii(" "))[0];
if ( elements[2].contains(QString::fromAscii("Face")) || elements[2].contains(QString::fromAscii("Edge")) ) {
cmd = QString::fromAscii("shp = App.getDocument(\"%1\").getObject(\"%2\").Shape").arg(elements[0]).arg(elements[1]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toAscii());
cmd = QString::fromAscii("elt = App.getDocument(\"%1\").getObject(\"%2\").Shape.%3").arg(elements[0]).arg(elements[1]).arg(elements[2]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toAscii());
}
}
}

void SelectionView::onItemContextMenu(const QPoint& point)
{
QListWidgetItem *item = selectionView->itemAt(point);
Expand All @@ -242,6 +264,9 @@ void SelectionView::onItemContextMenu(const QPoint& point)
zoomAction->setToolTip(tr("Selects and fits this object in the 3D window"));
QAction *gotoAction = menu.addAction(tr("Go to selection"),this,SLOT(treeSelect()));
gotoAction->setToolTip(tr("Selects and locates this object in the tree view"));
QAction *toPythonAction = menu.addAction(tr("To python console"),this,SLOT(toPython()));
toPythonAction->setIcon(QIcon(QString::fromAscii(":/icons/applications-python.svg")));
toPythonAction->setToolTip(tr("Reveals this object and its subelements in the python console."));
menu.exec(selectionView->mapToGlobal(point));
}

Expand Down
1 change: 1 addition & 0 deletions src/Gui/SelectionView.h
Expand Up @@ -78,6 +78,7 @@ public Q_SLOTS:
void deselect(void);
void zoom(void);
void treeSelect(void);
void toPython(void);

};

Expand Down

0 comments on commit 5d0bc52

Please sign in to comment.