2014-03-04 13:47:43 +00:00
|
|
|
#include "worldspacewidget.hpp"
|
|
|
|
|
2014-09-06 14:11:06 +00:00
|
|
|
#include <algorithm>
|
2015-09-18 16:31:33 +00:00
|
|
|
#include <iostream>
|
2014-09-06 14:11:06 +00:00
|
|
|
|
2015-06-12 13:10:12 +00:00
|
|
|
#include <QEvent>
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QDragMoveEvent>
|
|
|
|
#include <QDropEvent>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QKeyEvent>
|
2014-05-01 13:09:47 +00:00
|
|
|
|
2015-03-25 23:55:58 +00:00
|
|
|
#include <osgGA/TrackballManipulator>
|
|
|
|
#include <osgGA/FirstPersonManipulator>
|
|
|
|
|
2015-09-18 16:31:33 +00:00
|
|
|
#include <osgUtil/LineSegmentIntersector>
|
|
|
|
|
2014-07-08 10:39:12 +00:00
|
|
|
#include "../../model/world/universalid.hpp"
|
2014-09-06 14:11:06 +00:00
|
|
|
#include "../../model/world/idtable.hpp"
|
2014-07-08 10:39:12 +00:00
|
|
|
|
2015-09-25 11:11:40 +00:00
|
|
|
#include "../../model/settings/usersettings.hpp"
|
|
|
|
|
2014-07-08 10:39:12 +00:00
|
|
|
#include "../widget/scenetoolmode.hpp"
|
2014-11-28 08:14:02 +00:00
|
|
|
#include "../widget/scenetooltoggle2.hpp"
|
2014-09-06 14:11:06 +00:00
|
|
|
#include "../widget/scenetoolrun.hpp"
|
2014-07-31 12:05:27 +00:00
|
|
|
|
2015-09-18 16:31:33 +00:00
|
|
|
#include "object.hpp"
|
2014-07-31 12:05:27 +00:00
|
|
|
#include "elements.hpp"
|
2014-11-13 10:12:20 +00:00
|
|
|
#include "editmode.hpp"
|
2014-03-06 09:01:23 +00:00
|
|
|
|
2015-09-25 11:11:40 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
static const char * const sMappingSettings[] =
|
|
|
|
{
|
|
|
|
"p-navi", "s-navi",
|
|
|
|
"p-edit", "s-edit",
|
|
|
|
"select",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-06-29 12:19:10 +00:00
|
|
|
CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent)
|
2015-07-18 01:52:38 +00:00
|
|
|
: SceneWidget (document.getData().getResourceSystem(), parent), mSceneElements(0), mRun(0), mDocument(document),
|
2014-11-13 10:12:20 +00:00
|
|
|
mInteractionMask (0)
|
2014-03-10 17:35:49 +00:00
|
|
|
{
|
2014-06-29 12:19:10 +00:00
|
|
|
setAcceptDrops(true);
|
2014-03-10 17:35:49 +00:00
|
|
|
|
2014-06-29 12:19:10 +00:00
|
|
|
QAbstractItemModel *referenceables =
|
|
|
|
document.getData().getTableModel (CSMWorld::UniversalId::Type_Referenceables);
|
2014-05-01 13:09:47 +00:00
|
|
|
|
2014-06-29 12:19:10 +00:00
|
|
|
connect (referenceables, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
|
|
|
|
this, SLOT (referenceableDataChanged (const QModelIndex&, const QModelIndex&)));
|
|
|
|
connect (referenceables, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
|
|
|
this, SLOT (referenceableAboutToBeRemoved (const QModelIndex&, int, int)));
|
|
|
|
connect (referenceables, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
|
|
|
this, SLOT (referenceableAdded (const QModelIndex&, int, int)));
|
|
|
|
|
|
|
|
QAbstractItemModel *references =
|
|
|
|
document.getData().getTableModel (CSMWorld::UniversalId::Type_References);
|
|
|
|
|
|
|
|
connect (references, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
|
|
|
|
this, SLOT (referenceDataChanged (const QModelIndex&, const QModelIndex&)));
|
|
|
|
connect (references, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
|
|
|
this, SLOT (referenceAboutToBeRemoved (const QModelIndex&, int, int)));
|
|
|
|
connect (references, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
|
|
|
this, SLOT (referenceAdded (const QModelIndex&, int, int)));
|
2014-09-07 10:55:52 +00:00
|
|
|
|
|
|
|
QAbstractItemModel *debugProfiles =
|
|
|
|
document.getData().getTableModel (CSMWorld::UniversalId::Type_DebugProfiles);
|
|
|
|
|
|
|
|
connect (debugProfiles, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
|
|
|
|
this, SLOT (debugProfileDataChanged (const QModelIndex&, const QModelIndex&)));
|
|
|
|
connect (debugProfiles, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
|
|
|
this, SLOT (debugProfileAboutToBeRemoved (const QModelIndex&, int, int)));
|
2015-09-25 11:11:40 +00:00
|
|
|
|
|
|
|
for (int i=0; sMappingSettings[i]; ++i)
|
|
|
|
{
|
|
|
|
QString key ("scene-input/");
|
|
|
|
key += sMappingSettings[i];
|
|
|
|
storeMappingSetting (key, CSMSettings::UserSettings::instance().settingValue (key));
|
|
|
|
}
|
2014-10-28 13:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSVRender::WorldspaceWidget::~WorldspaceWidget ()
|
|
|
|
{
|
2014-03-10 17:35:49 +00:00
|
|
|
}
|
2014-03-06 09:01:23 +00:00
|
|
|
|
|
|
|
void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode)
|
|
|
|
{
|
|
|
|
if (mode=="1st")
|
2015-03-25 23:55:58 +00:00
|
|
|
mView->setCameraManipulator(new osgGA::FirstPersonManipulator);
|
2014-03-06 09:01:23 +00:00
|
|
|
else if (mode=="free")
|
2015-03-25 23:55:58 +00:00
|
|
|
mView->setCameraManipulator(new osgGA::FirstPersonManipulator);
|
2014-03-06 09:01:23 +00:00
|
|
|
else if (mode=="orbit")
|
2015-03-25 23:55:58 +00:00
|
|
|
mView->setCameraManipulator(new osgGA::OrbitManipulator);
|
2014-03-06 09:01:23 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 08:04:14 +00:00
|
|
|
void CSVRender::WorldspaceWidget::useViewHint (const std::string& hint) {}
|
|
|
|
|
2014-03-06 09:01:23 +00:00
|
|
|
void CSVRender::WorldspaceWidget::selectDefaultNavigationMode()
|
|
|
|
{
|
2015-03-25 23:55:58 +00:00
|
|
|
mView->setCameraManipulator(new osgGA::FirstPersonManipulator);
|
2014-03-06 09:01:23 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 10:39:12 +00:00
|
|
|
CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
|
|
|
|
CSVWidget::SceneToolbar *parent)
|
2014-03-06 09:01:23 +00:00
|
|
|
{
|
2014-07-13 12:21:50 +00:00
|
|
|
CSVWidget::SceneToolMode *tool = new CSVWidget::SceneToolMode (parent, "Camera Mode");
|
2014-03-06 09:01:23 +00:00
|
|
|
|
2014-07-13 10:15:05 +00:00
|
|
|
/// \todo replace icons
|
|
|
|
/// \todo consider user-defined button-mapping
|
2014-07-30 15:02:23 +00:00
|
|
|
tool->addButton (":scenetoolbar/1st-person", "1st",
|
2014-07-13 10:15:05 +00:00
|
|
|
"First Person"
|
|
|
|
"<ul><li>Mouse-Look while holding the left button</li>"
|
|
|
|
"<li>WASD movement keys</li>"
|
|
|
|
"<li>Mouse wheel moves the camera forawrd/backward</li>"
|
|
|
|
"<li>Stafing (also vertically) by holding the left mouse button and control</li>"
|
|
|
|
"<li>Camera is held upright</li>"
|
|
|
|
"<li>Hold shift to speed up movement</li>"
|
|
|
|
"</ul>");
|
2014-07-30 15:02:23 +00:00
|
|
|
tool->addButton (":scenetoolbar/free-camera", "free",
|
2014-07-13 10:15:05 +00:00
|
|
|
"Free Camera"
|
|
|
|
"<ul><li>Mouse-Look while holding the left button</li>"
|
|
|
|
"<li>Stafing (also vertically) via WASD or by holding the left mouse button and control</li>"
|
|
|
|
"<li>Mouse wheel moves the camera forawrd/backward</li>"
|
|
|
|
"<li>Roll camera with Q and E keys</li>"
|
|
|
|
"<li>Hold shift to speed up movement</li>"
|
|
|
|
"</ul>");
|
2014-07-30 15:02:23 +00:00
|
|
|
tool->addButton (":scenetoolbar/orbiting-camera", "orbit",
|
2014-07-13 10:15:05 +00:00
|
|
|
"Orbiting Camera"
|
|
|
|
"<ul><li>Always facing the centre point</li>"
|
|
|
|
"<li>Rotate around the centre point via WASD or by moving the mouse while holding the left button</li>"
|
|
|
|
"<li>Mouse wheel moves camera away or towards centre point but can not pass through it</li>"
|
|
|
|
"<li>Roll camera with Q and E keys</li>"
|
|
|
|
"<li>Stafing (also vertically) by holding the left mouse button and control (includes relocation of the centre point)</li>"
|
|
|
|
"<li>Hold shift to speed up movement</li>"
|
|
|
|
"</ul>");
|
2014-03-06 09:01:23 +00:00
|
|
|
|
|
|
|
connect (tool, SIGNAL (modeChanged (const std::string&)),
|
|
|
|
this, SLOT (selectNavigationMode (const std::string&)));
|
|
|
|
|
|
|
|
return tool;
|
2014-05-01 13:09:47 +00:00
|
|
|
}
|
|
|
|
|
2014-11-28 08:14:02 +00:00
|
|
|
CSVWidget::SceneToolToggle2 *CSVRender::WorldspaceWidget::makeSceneVisibilitySelector (CSVWidget::SceneToolbar *parent)
|
2014-07-31 12:05:27 +00:00
|
|
|
{
|
2014-11-28 08:14:02 +00:00
|
|
|
mSceneElements = new CSVWidget::SceneToolToggle2 (parent,
|
|
|
|
"Scene Element Visibility", ":scenetoolbar/scene-view-c", ":scenetoolbar/scene-view-");
|
2014-07-31 12:05:27 +00:00
|
|
|
|
|
|
|
addVisibilitySelectorButtons (mSceneElements);
|
|
|
|
|
|
|
|
mSceneElements->setSelection (0xffffffff);
|
|
|
|
|
|
|
|
connect (mSceneElements, SIGNAL (selectionChanged()),
|
|
|
|
this, SLOT (elementSelectionChanged()));
|
|
|
|
|
|
|
|
return mSceneElements;
|
|
|
|
}
|
|
|
|
|
2014-09-06 14:11:06 +00:00
|
|
|
CSVWidget::SceneToolRun *CSVRender::WorldspaceWidget::makeRunTool (
|
|
|
|
CSVWidget::SceneToolbar *parent)
|
|
|
|
{
|
|
|
|
CSMWorld::IdTable& debugProfiles = dynamic_cast<CSMWorld::IdTable&> (
|
|
|
|
*mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_DebugProfiles));
|
|
|
|
|
|
|
|
std::vector<std::string> profiles;
|
|
|
|
|
|
|
|
int idColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
|
|
|
int stateColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
|
|
|
|
int defaultColumn = debugProfiles.findColumnIndex (
|
|
|
|
CSMWorld::Columns::ColumnId_DefaultProfile);
|
|
|
|
|
|
|
|
int size = debugProfiles.rowCount();
|
|
|
|
|
|
|
|
for (int i=0; i<size; ++i)
|
|
|
|
{
|
|
|
|
int state = debugProfiles.data (debugProfiles.index (i, stateColumn)).toInt();
|
|
|
|
|
|
|
|
bool default_ = debugProfiles.data (debugProfiles.index (i, defaultColumn)).toInt();
|
|
|
|
|
|
|
|
if (state!=CSMWorld::RecordBase::State_Deleted && default_)
|
|
|
|
profiles.push_back (
|
|
|
|
debugProfiles.data (debugProfiles.index (i, idColumn)).
|
|
|
|
toString().toUtf8().constData());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort (profiles.begin(), profiles.end());
|
|
|
|
|
|
|
|
mRun = new CSVWidget::SceneToolRun (parent, "Run OpenMW from the current camera position",
|
2014-11-27 08:27:29 +00:00
|
|
|
":scenetoolbar/play", profiles);
|
2014-09-06 14:11:06 +00:00
|
|
|
|
|
|
|
connect (mRun, SIGNAL (runRequest (const std::string&)),
|
|
|
|
this, SLOT (runRequest (const std::string&)));
|
|
|
|
|
|
|
|
return mRun;
|
|
|
|
}
|
|
|
|
|
2014-11-11 14:58:22 +00:00
|
|
|
CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeEditModeSelector (
|
|
|
|
CSVWidget::SceneToolbar *parent)
|
|
|
|
{
|
|
|
|
CSVWidget::SceneToolMode *tool = new CSVWidget::SceneToolMode (parent, "Edit Mode");
|
|
|
|
|
|
|
|
addEditModeSelectorButtons (tool);
|
|
|
|
|
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
2014-09-11 09:27:56 +00:00
|
|
|
CSVRender::WorldspaceWidget::DropType CSVRender::WorldspaceWidget::getDropType (
|
2014-05-02 18:15:46 +00:00
|
|
|
const std::vector< CSMWorld::UniversalId >& data)
|
2014-05-01 13:09:47 +00:00
|
|
|
{
|
2014-09-11 09:27:56 +00:00
|
|
|
DropType output = Type_Other;
|
2014-05-01 13:09:47 +00:00
|
|
|
|
2014-09-11 09:27:56 +00:00
|
|
|
for (std::vector<CSMWorld::UniversalId>::const_iterator iter (data.begin());
|
|
|
|
iter!=data.end(); ++iter)
|
2014-05-01 13:09:47 +00:00
|
|
|
{
|
2014-09-11 09:27:56 +00:00
|
|
|
DropType type = Type_Other;
|
|
|
|
|
|
|
|
if (iter->getType()==CSMWorld::UniversalId::Type_Cell ||
|
|
|
|
iter->getType()==CSMWorld::UniversalId::Type_Cell_Missing)
|
2014-05-01 13:09:47 +00:00
|
|
|
{
|
2014-09-11 09:27:56 +00:00
|
|
|
type = iter->getId().substr (0, 1)=="#" ? Type_CellsExterior : Type_CellsInterior;
|
2014-05-01 13:09:47 +00:00
|
|
|
}
|
2014-09-13 16:54:29 +00:00
|
|
|
else if (iter->getType()==CSMWorld::UniversalId::Type_DebugProfile)
|
|
|
|
type = Type_DebugProfile;
|
2014-09-11 09:27:56 +00:00
|
|
|
|
|
|
|
if (iter==data.begin())
|
|
|
|
output = type;
|
|
|
|
else if (output!=type) // mixed types -> ignore
|
|
|
|
return Type_Other;
|
2014-05-01 13:09:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2014-09-11 11:04:20 +00:00
|
|
|
CSVRender::WorldspaceWidget::dropRequirments
|
|
|
|
CSVRender::WorldspaceWidget::getDropRequirements (DropType type) const
|
|
|
|
{
|
2014-09-13 16:54:29 +00:00
|
|
|
if (type==Type_DebugProfile)
|
|
|
|
return canHandle;
|
|
|
|
|
2014-09-11 11:04:20 +00:00
|
|
|
return ignored;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSVRender::WorldspaceWidget::handleDrop (const std::vector<CSMWorld::UniversalId>& data,
|
|
|
|
DropType type)
|
|
|
|
{
|
2014-09-13 16:54:29 +00:00
|
|
|
if (type==Type_DebugProfile)
|
|
|
|
{
|
|
|
|
if (mRun)
|
|
|
|
{
|
|
|
|
for (std::vector<CSMWorld::UniversalId>::const_iterator iter (data.begin());
|
|
|
|
iter!=data.end(); ++iter)
|
|
|
|
mRun->addProfile (iter->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-11 11:04:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-09 10:29:45 +00:00
|
|
|
unsigned int CSVRender::WorldspaceWidget::getVisibilityMask() const
|
2014-07-31 12:05:27 +00:00
|
|
|
{
|
|
|
|
return mSceneElements->getSelection();
|
|
|
|
}
|
|
|
|
|
2014-11-11 14:58:22 +00:00
|
|
|
void CSVRender::WorldspaceWidget::setInteractionMask (unsigned int mask)
|
|
|
|
{
|
|
|
|
mInteractionMask = mask | Element_CellMarker | Element_CellArrow;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CSVRender::WorldspaceWidget::getInteractionMask() const
|
|
|
|
{
|
|
|
|
return mInteractionMask & getVisibilityMask();
|
|
|
|
}
|
|
|
|
|
2015-09-24 13:51:16 +00:00
|
|
|
void CSVRender::WorldspaceWidget::updateUserSetting (const QString& name, const QStringList& value)
|
|
|
|
{
|
2015-09-25 11:11:40 +00:00
|
|
|
if (!value.isEmpty() && storeMappingSetting (name, value.first()))
|
|
|
|
return;
|
2015-09-24 13:51:16 +00:00
|
|
|
}
|
|
|
|
|
2014-07-31 12:05:27 +00:00
|
|
|
void CSVRender::WorldspaceWidget::addVisibilitySelectorButtons (
|
2014-11-28 08:14:02 +00:00
|
|
|
CSVWidget::SceneToolToggle2 *tool)
|
2014-07-31 12:05:27 +00:00
|
|
|
{
|
2015-05-03 14:35:10 +00:00
|
|
|
tool->addButton (Element_Reference, "Instances");
|
2014-11-28 08:14:02 +00:00
|
|
|
tool->addButton (Element_Water, "Water");
|
|
|
|
tool->addButton (Element_Pathgrid, "Pathgrid");
|
2014-07-31 12:05:27 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 14:58:22 +00:00
|
|
|
void CSVRender::WorldspaceWidget::addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool)
|
|
|
|
{
|
|
|
|
/// \todo replace EditMode with suitable subclasses
|
|
|
|
tool->addButton (
|
2015-05-03 14:35:10 +00:00
|
|
|
new EditMode (this, QIcon (":placeholder"), Element_Reference, "Instance editing"),
|
2014-11-11 14:58:22 +00:00
|
|
|
"object");
|
|
|
|
tool->addButton (
|
2014-11-13 11:09:10 +00:00
|
|
|
new EditMode (this, QIcon (":placeholder"), Element_Pathgrid, "Pathgrid editing"),
|
2014-11-11 14:58:22 +00:00
|
|
|
"pathgrid");
|
|
|
|
}
|
|
|
|
|
2014-09-11 11:07:28 +00:00
|
|
|
CSMDoc::Document& CSVRender::WorldspaceWidget::getDocument()
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
2014-05-01 13:09:47 +00:00
|
|
|
void CSVRender::WorldspaceWidget::dragEnterEvent (QDragEnterEvent* event)
|
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event)
|
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
}
|
2014-05-03 12:00:30 +00:00
|
|
|
|
2015-09-25 11:11:40 +00:00
|
|
|
|
|
|
|
bool CSVRender::WorldspaceWidget::storeMappingSetting (const QString& key, const QString& value)
|
|
|
|
{
|
|
|
|
const QString prefix = "scene-input/";
|
|
|
|
|
|
|
|
if (key.startsWith (prefix))
|
|
|
|
{
|
|
|
|
QString key2 (key.mid (prefix.length()));
|
|
|
|
|
|
|
|
for (int i=0; sMappingSettings[i]; ++i)
|
|
|
|
if (key2==sMappingSettings[i])
|
|
|
|
{
|
|
|
|
Qt::MouseButton button = Qt::NoButton;
|
|
|
|
|
|
|
|
if (value.endsWith ("Left Mouse-Button"))
|
|
|
|
button = Qt::LeftButton;
|
|
|
|
else if (value.endsWith ("Right Mouse-Button"))
|
|
|
|
button = Qt::RightButton;
|
|
|
|
else if (value.endsWith ("Middle Mouse-Button"))
|
|
|
|
button = Qt::MiddleButton;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool ctrl = value.startsWith ("Ctrl-");
|
|
|
|
|
|
|
|
mButtonMapping[std::make_pair (button, ctrl)] = sMappingSettings[i];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-03 12:00:30 +00:00
|
|
|
void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
|
|
|
|
{
|
|
|
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
2014-06-26 18:49:22 +00:00
|
|
|
if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped
|
|
|
|
return;
|
2014-05-03 12:00:30 +00:00
|
|
|
|
|
|
|
if (mime->fromDocument (mDocument))
|
|
|
|
{
|
|
|
|
emit dataDropped(mime->getData());
|
|
|
|
} //not handling drops from different documents at the moment
|
2014-06-26 18:49:22 +00:00
|
|
|
}
|
2014-07-31 12:05:27 +00:00
|
|
|
|
2014-09-06 14:11:06 +00:00
|
|
|
void CSVRender::WorldspaceWidget::runRequest (const std::string& profile)
|
|
|
|
{
|
|
|
|
mDocument.startRunning (profile, getStartupInstruction());
|
|
|
|
}
|
|
|
|
|
2014-09-07 10:55:52 +00:00
|
|
|
void CSVRender::WorldspaceWidget::debugProfileDataChanged (const QModelIndex& topLeft,
|
|
|
|
const QModelIndex& bottomRight)
|
|
|
|
{
|
|
|
|
if (!mRun)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CSMWorld::IdTable& debugProfiles = dynamic_cast<CSMWorld::IdTable&> (
|
|
|
|
*mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_DebugProfiles));
|
|
|
|
|
|
|
|
int idColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
|
|
|
int stateColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
|
|
|
|
|
|
|
|
for (int i=topLeft.row(); i<=bottomRight.row(); ++i)
|
|
|
|
{
|
|
|
|
int state = debugProfiles.data (debugProfiles.index (i, stateColumn)).toInt();
|
|
|
|
|
|
|
|
// As of version 0.33 this case can not happen because debug profiles exist only in
|
|
|
|
// project or session scope, which means they will never be in deleted state. But we
|
|
|
|
// are adding the code for the sake of completeness and to avoid surprises if debug
|
|
|
|
// profile ever get extended to content scope.
|
|
|
|
if (state==CSMWorld::RecordBase::State_Deleted)
|
|
|
|
mRun->removeProfile (debugProfiles.data (
|
|
|
|
debugProfiles.index (i, idColumn)).toString().toUtf8().constData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVRender::WorldspaceWidget::debugProfileAboutToBeRemoved (const QModelIndex& parent,
|
|
|
|
int start, int end)
|
|
|
|
{
|
|
|
|
if (parent.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!mRun)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CSMWorld::IdTable& debugProfiles = dynamic_cast<CSMWorld::IdTable&> (
|
|
|
|
*mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_DebugProfiles));
|
|
|
|
|
|
|
|
int idColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
|
|
|
|
|
|
|
for (int i=start; i<=end; ++i)
|
|
|
|
{
|
|
|
|
mRun->removeProfile (debugProfiles.data (
|
|
|
|
debugProfiles.index (i, idColumn)).toString().toUtf8().constData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-31 12:05:27 +00:00
|
|
|
void CSVRender::WorldspaceWidget::elementSelectionChanged()
|
|
|
|
{
|
2015-03-25 23:27:39 +00:00
|
|
|
setVisibilityMask (getVisibilityMask());
|
2014-07-31 12:29:52 +00:00
|
|
|
flagAsModified();
|
2014-10-08 18:56:44 +00:00
|
|
|
updateOverlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVRender::WorldspaceWidget::updateOverlay()
|
|
|
|
{
|
2014-07-31 12:34:25 +00:00
|
|
|
}
|
2014-10-28 13:50:48 +00:00
|
|
|
|
2014-10-28 23:43:55 +00:00
|
|
|
void CSVRender::WorldspaceWidget::mouseMoveEvent (QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if(event->buttons() & Qt::RightButton)
|
|
|
|
{
|
2015-03-25 18:08:09 +00:00
|
|
|
//mMouse->mouseMoveEvent(event);
|
2014-10-28 23:43:55 +00:00
|
|
|
}
|
2015-03-28 19:15:17 +00:00
|
|
|
RenderWidget::mouseMoveEvent(event);
|
2014-10-28 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVRender::WorldspaceWidget::mousePressEvent (QMouseEvent *event)
|
|
|
|
{
|
2015-09-18 16:31:33 +00:00
|
|
|
if (event->button() != Qt::RightButton)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// (0,0) is considered the lower left corner of an OpenGL window
|
|
|
|
int x = event->x();
|
|
|
|
int y = height() - event->y();
|
|
|
|
|
|
|
|
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector (new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, x, y));
|
|
|
|
|
|
|
|
intersector->setIntersectionLimit(osgUtil::LineSegmentIntersector::NO_LIMIT);
|
|
|
|
osgUtil::IntersectionVisitor visitor(intersector);
|
|
|
|
|
|
|
|
visitor.setTraversalMask(getInteractionMask() << 1);
|
|
|
|
|
|
|
|
mView->getCamera()->accept(visitor);
|
|
|
|
|
|
|
|
for (osgUtil::LineSegmentIntersector::Intersections::iterator it = intersector->getIntersections().begin();
|
|
|
|
it != intersector->getIntersections().end(); ++it)
|
2014-11-02 21:10:28 +00:00
|
|
|
{
|
2015-09-18 16:31:33 +00:00
|
|
|
osgUtil::LineSegmentIntersector::Intersection intersection = *it;
|
|
|
|
|
|
|
|
// reject back-facing polygons
|
|
|
|
osg::Vec3f normal = intersection.getWorldIntersectNormal();
|
|
|
|
normal = osg::Matrix::transform3x3(normal, mView->getCamera()->getViewMatrix());
|
|
|
|
if (normal.z() < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (std::vector<osg::Node*>::iterator it = intersection.nodePath.begin(); it != intersection.nodePath.end(); ++it)
|
|
|
|
{
|
|
|
|
osg::Node* node = *it;
|
2015-09-26 10:24:41 +00:00
|
|
|
if (CSVRender::TagBase* tag = dynamic_cast<CSVRender::TagBase *>(node->getUserData()))
|
2015-09-18 16:31:33 +00:00
|
|
|
{
|
2015-09-26 15:39:55 +00:00
|
|
|
if (!(tag->getElement() & mInteractionMask))
|
2015-09-26 10:24:41 +00:00
|
|
|
break; // not interested -> continue looking
|
|
|
|
|
|
|
|
// hit something marked with a tag
|
|
|
|
if (CSVRender::ObjectTag *objectTag = dynamic_cast<CSVRender::ObjectTag *> (tag))
|
|
|
|
{
|
|
|
|
// hit an Object, toggle its selection state
|
|
|
|
CSVRender::Object* object = objectTag->mObject;
|
|
|
|
object->setSelected (!object->getSelected());
|
|
|
|
}
|
|
|
|
|
2015-09-18 16:31:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-26 10:24:41 +00:00
|
|
|
// ignoring terrain for now
|
2015-09-18 16:31:33 +00:00
|
|
|
// must be terrain, report coordinates
|
2015-09-26 10:24:41 +00:00
|
|
|
// std::cout << "Terrain hit at " << intersection.getWorldIntersectPoint().x() << " " << intersection.getWorldIntersectPoint().y() << std::endl;
|
|
|
|
// return;
|
2014-11-02 21:10:28 +00:00
|
|
|
}
|
2014-10-28 23:43:55 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 13:50:48 +00:00
|
|
|
void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if(event->button() == Qt::RightButton)
|
|
|
|
{
|
2015-03-19 22:27:14 +00:00
|
|
|
/*
|
2014-11-01 21:22:27 +00:00
|
|
|
if(!getViewport())
|
2014-10-28 23:43:55 +00:00
|
|
|
{
|
|
|
|
SceneWidget::mouseReleaseEvent(event);
|
2014-10-28 13:50:48 +00:00
|
|
|
return;
|
2014-10-28 23:43:55 +00:00
|
|
|
}
|
2015-03-19 22:27:14 +00:00
|
|
|
*/
|
2015-03-25 18:08:09 +00:00
|
|
|
//mMouse->mouseReleaseEvent(event);
|
2014-10-28 13:50:48 +00:00
|
|
|
}
|
2015-03-28 19:15:17 +00:00
|
|
|
RenderWidget::mouseReleaseEvent(event);
|
2014-10-28 13:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVRender::WorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if(event->button() == Qt::RightButton)
|
|
|
|
{
|
2015-03-25 18:08:09 +00:00
|
|
|
//mMouse->mouseDoubleClickEvent(event);
|
2014-10-28 13:50:48 +00:00
|
|
|
}
|
|
|
|
//SceneWidget::mouseDoubleClickEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-10-28 23:43:55 +00:00
|
|
|
void CSVRender::WorldspaceWidget::wheelEvent (QWheelEvent *event)
|
|
|
|
{
|
2015-03-25 18:08:09 +00:00
|
|
|
//if(!mMouse->wheelEvent(event))
|
2015-03-28 19:15:17 +00:00
|
|
|
RenderWidget::wheelEvent(event);
|
2014-10-29 12:02:38 +00:00
|
|
|
}
|
2014-11-03 10:24:47 +00:00
|
|
|
|
|
|
|
void CSVRender::WorldspaceWidget::keyPressEvent (QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if(event->key() == Qt::Key_Escape)
|
|
|
|
{
|
2015-03-25 18:08:09 +00:00
|
|
|
//mMouse->cancelDrag();
|
2014-11-03 10:24:47 +00:00
|
|
|
}
|
|
|
|
else
|
2015-03-28 19:15:17 +00:00
|
|
|
RenderWidget::keyPressEvent(event);
|
2014-11-03 10:24:47 +00:00
|
|
|
}
|