delegated editing and selection functions to mode objects

sceneinput
Marc Zinnschlag 9 years ago
parent 9bf27c7e37
commit 981a8a2cc2

@ -85,7 +85,7 @@ opencs_units (view/widget
opencs_units (view/render
scenewidget worldspacewidget pagedworldspacewidget unpagedworldspacewidget
previewwidget editmode
previewwidget editmode instancemode
)
opencs_units_noqt (view/render

@ -26,3 +26,9 @@ void CSVRender::EditMode::setEditLock (bool locked)
{
}
void CSVRender::EditMode::primaryEditPressed (osg::ref_ptr<TagBase> tag) {}
void CSVRender::EditMode::secondaryEditPressed (osg::ref_ptr<TagBase> tag) {}
void CSVRender::EditMode::selectPressed (osg::ref_ptr<TagBase> tag) {}

@ -1,11 +1,14 @@
#ifndef CSV_RENDER_EDITMODE_H
#define CSV_RENDER_EDITMODE_H
#include <osg/ref_ptr>
#include "../widget/modebutton.hpp"
namespace CSVRender
{
class WorldspaceWidget;
class TagBase;
class EditMode : public CSVWidget::ModeButton
{
@ -28,6 +31,15 @@ namespace CSVRender
/// Default-implementation: Ignored.
virtual void setEditLock (bool locked);
/// Default-implementation: Ignored.
virtual void primaryEditPressed (osg::ref_ptr<TagBase> tag);
/// Default-implementation: Ignored.
virtual void secondaryEditPressed (osg::ref_ptr<TagBase> tag);
/// Default-implementation: Ignored.
virtual void selectPressed (osg::ref_ptr<TagBase> tag);
};
}

@ -0,0 +1,35 @@
#include "instancemode.hpp"
#include "elements.hpp"
#include "object.hpp"
CSVRender::InstanceMode::InstanceMode (WorldspaceWidget *worldspaceWidget, QWidget *parent)
: EditMode (worldspaceWidget, QIcon (":placeholder"), Element_Reference, "Instance editing",
parent)
{
}
void CSVRender::InstanceMode::primaryEditPressed (osg::ref_ptr<TagBase> tag)
{
}
void CSVRender::InstanceMode::secondaryEditPressed (osg::ref_ptr<TagBase> tag)
{
}
void CSVRender::InstanceMode::selectPressed (osg::ref_ptr<TagBase> tag)
{
if (tag)
{
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get()))
{
// hit an Object, toggle its selection state
CSVRender::Object* object = objectTag->mObject;
object->setSelected (!object->getSelected());
}
}
}

@ -0,0 +1,24 @@
#ifndef CSV_RENDER_INSTANCEMODE_H
#define CSV_RENDER_INSTANCEMODE_H
#include "editmode.hpp"
namespace CSVRender
{
class InstanceMode : public EditMode
{
Q_OBJECT
public:
InstanceMode (WorldspaceWidget *worldspaceWidget, QWidget *parent = 0);
virtual void primaryEditPressed (osg::ref_ptr<TagBase> tag);
virtual void secondaryEditPressed (osg::ref_ptr<TagBase> tag);
virtual void selectPressed (osg::ref_ptr<TagBase> tag);
};
}
#endif

@ -28,6 +28,7 @@
#include "object.hpp"
#include "elements.hpp"
#include "editmode.hpp"
#include "instancemode.hpp"
namespace
{
@ -302,9 +303,7 @@ void CSVRender::WorldspaceWidget::addVisibilitySelectorButtons (
void CSVRender::WorldspaceWidget::addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool)
{
/// \todo replace EditMode with suitable subclasses
tool->addButton (
new EditMode (this, QIcon (":placeholder"), Element_Reference, "Instance editing"),
"object");
tool->addButton (new InstanceMode (this, tool), "object");
tool->addButton (
new EditMode (this, QIcon (":placeholder"), Element_Pathgrid, "Pathgrid editing"),
"pathgrid");
@ -515,15 +514,14 @@ void CSVRender::WorldspaceWidget::mousePressEvent (QMouseEvent *event)
{
osg::ref_ptr<TagBase> tag = mousePick (event);
if (tag)
{
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag.get()))
{
// hit an Object, toggle its selection state
CSVRender::Object* object = objectTag->mObject;
object->setSelected (!object->getSelected());
}
}
EditMode& editMode = dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent());
if (button=="p-edit")
editMode.primaryEditPressed (tag);
else if (button=="s-edit")
editMode.secondaryEditPressed (tag);
else if (button=="select")
editMode.selectPressed (tag);
}
}

Loading…
Cancel
Save