Skip to content
Snippets Groups Projects
Commit 258f190d authored by stefan's avatar stefan
Browse files

Added tmalign Action to SceneWin context menu

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2043 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 568548e7
Branches
Tags
No related merge requests found
......@@ -74,6 +74,7 @@ endif()
set(OST_GUI_PYMOD_MODULES
__init__.py
init_context_menu.py
init_menubar.py
init_spacenav.py
)
......
......@@ -16,20 +16,78 @@
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#include <QAction>
#include <boost/python.hpp>
#include "scene_win_proxy.hh"
#include <ost/gui/scene_win/context_menu.hh>
using namespace boost::python;
using namespace ost;
using namespace ost::gui;
namespace {
void context_menu_add_action(ContextMenu* cm, object action, int types)
{
static object sip_module=import("sip");
static object gui_module=import("ost.gui");
static object pyqt4_module=import("PyQt4.QtCore");
unsigned long addr = extract<unsigned long>(sip_module.attr("unwrapinstance")(action));
QAction* act = reinterpret_cast<QAction*>(addr);
if(act){
ContextActionTypes type = ContextActionTypes(types);
cm->AddAction(act,type);
}
}
object context_menu_get_qobject(ContextMenu* cm)
{
static object sip_module=import("sip");
static object pyqt4_module=import("PyQt4.QtCore");
size_t addr = reinterpret_cast<size_t>(cm);
object obj(addr);
object sip_handle=obj;
object qobject = pyqt4_module.attr("QObject");
object object = sip_module.attr("wrapinstance")(sip_handle, qobject);
return object;
}
}
void export_SceneWin()
{
enum_<ContextActionType>("ContextActionType")
.value("GFX_OBJECT", GFX_OBJECT)
.value("ENTITY", ENTITY)
.value("ENTITY_VIEW", ENTITY_VIEW)
.value("CUSTOM_VIEW", CUSTOM_VIEW)
.value("NOT_VISIBLE", NOT_VISIBLE)
.value("NOT_HIDDEN", NOT_HIDDEN)
.value("NOT_SCENE", NOT_SCENE)
.value("SINGLE", SINGLE)
#if OST_IMG_ENABLED
.value("MAP", MAP)
#endif
.export_values()
;
class_<ContextMenu, boost::noncopyable>("ContextMenu", no_init)
.def("AddAction", &context_menu_add_action)
.def("GetQObject", &context_menu_get_qobject)
.add_property("qobject",&context_menu_get_qobject)
;
class_<SceneWinProxy, bases<SipHandlerBase> >("SceneWin")
.def("Show", &SceneWinProxy::Show)
.def("Hide", &SceneWinProxy::Hide)
.def("GetContextMenu", &SceneWinProxy::GetContextMenu, return_value_policy<reference_existing_object>())
;
}
from PyQt4 import QtCore, QtGui
from ost import geom, gfx, gui
from ost import settings
from ost.bindings import tmtools
class AlignmentContextMenu(QtCore.QObject):
def __init__(self, context_menu):
try:
settings.Locate('tmalign')
QtCore.QObject.__init__(self, context_menu.qobject)
self.action = QtGui.QAction("Align", self)
QtCore.QObject.connect(self.action,QtCore.SIGNAL("triggered()"), self.Align)
context_menu.AddAction(self.action, gui.ContextActionType.ENTITY)
except FileNotFound:
return
def Align(self):
scene_selection = gui.SceneSelection.Instance()
if scene_selection.GetActiveNodeCount() >= 2:
node = scene_selection.GetActiveNode(0)
if isinstance(node, gfx.Entity):
ref = node.view.handle
for i in range(1,scene_selection.GetActiveNodeCount()):
node = scene_selection.GetActiveNode(i)
if isinstance(node, gfx.Entity):
print tmtools.TMAlign(node.view.handle, ref)
node.UpdatePositions()
def _InitContextMenu():
cm=gui.GostyApp.Instance().GetSceneWin().GetContextMenu()
AlignmentContextMenu(cm)
\ No newline at end of file
from PyQt4 import QtCore, QtGui
from PyQt4 import QtCore
from ost import geom, gfx, gui
import sys, random
import sip
from ost import gfx, gui
class SpacenavControl(QtCore.QObject):
def __init__(self, spnav,
......
......@@ -40,6 +40,11 @@ public:
{
return Me()->hide();
}
ContextMenu* GetContextMenu()
{
return Me()->GetContextMenu();
}
};
}}
......
......@@ -122,6 +122,9 @@ void SceneWin::AddView(gfx::EntityP entity, mol::EntityView view){
}
ContextMenu* SceneWin::GetContextMenu(){
return context_menu_;
}
SceneWin::~SceneWin() {
}
......
......@@ -55,6 +55,8 @@ public:
void AddView(gfx::EntityP entity, mol::EntityView view);
ContextMenu* GetContextMenu();
public slots:
void OnSelectionChange(const QItemSelection& sel, const QItemSelection& desel);
......
......@@ -17,6 +17,7 @@ from PyQt4 import QtGui, QtCore
from ost.gui.scene.init_inspector import _InitInspector
from ost.gui.init_menubar import _InitMenuBar
from ost.gui.init_spacenav import _InitSpaceNav
from ost.gui.init_context_menu import _InitContextMenu
def _InitRuleBasedBuilder():
compound_lib_path=os.path.join(ost.GetSharedDataPath(), 'compounds.chemlib')
......@@ -51,6 +52,7 @@ def _InitFrontEnd():
_InitPanels(app, app.perspective.panels)
_InitMenuBar(app.perspective.GetMenuBar())
_InitSpaceNav(app.perspective.panels.qwidget)
_InitContextMenu()
main_area.AddPersistentWidget("3D Scene", "gl_win" , app.gl_win, int(QtCore.Qt.WindowMaximized))
app.perspective.Restore()
additional_modules=getattr(__main__, 'ADDITIONAL_GUI_MODULES', [])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment