1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#ifndef CSV_RENDER_INSTANCEMODE_H
#define CSV_RENDER_INSTANCEMODE_H
#include <QString>
#include <string>
#include <vector>
#include <osg/Group>
#include <osg/Node>
#include <osg/Quat>
#include <osg/Vec3>
#include <osg/ref_ptr>
#include "editmode.hpp"
#include "instancedragmodes.hpp"
#include <apps/opencs/model/world/idtable.hpp>
#include <components/esm3/selectiongroup.hpp>
class QDragEnterEvent;
class QDropEvent;
class QObject;
class QPoint;
class QWidget;
namespace CSVWidget
{
class SceneToolMode;
class SceneToolbar;
}
namespace CSVRender
{
class TagBase;
class InstanceSelectionMode;
class Object;
class WorldspaceWidget;
struct WorldspaceHitResult;
class InstanceMode : public EditMode
{
Q_OBJECT
CSVWidget::SceneToolMode* mSubMode;
std::string mSubModeId;
InstanceSelectionMode* mSelectionMode;
DragMode mDragMode;
int mDragAxis;
bool mLocked;
float mUnitScaleDist;
osg::ref_ptr<osg::Group> mParentNode;
osg::Vec3 mDragStart;
std::vector<osg::Vec3> mObjectsAtDragStart;
CSMWorld::IdTable* mSelectionGroups;
QString getTooltip();
int getSubModeFromId(const std::string& id) const;
osg::Vec3 quatToEuler(const osg::Quat& quat) const;
osg::Quat eulerToQuat(const osg::Vec3& euler) const;
float roundFloatToMult(const float val, const double mult) const;
osg::Vec3 getSelectionCenter(const std::vector<osg::ref_ptr<TagBase>>& selection) const;
osg::Vec3 getScreenCoords(const osg::Vec3& pos);
osg::Vec3 getProjectionSpaceCoords(const osg::Vec3& pos);
osg::Vec3 getMousePlaneCoords(const QPoint& point, const osg::Vec3d& dragStart);
void handleSelectDrag(const QPoint& pos);
void dropInstance(CSVRender::Object* object, float dropHeight);
float calculateDropHeight(CSVRender::Object* object, float objectHeight);
osg::Vec3 calculateSnapPositionRelativeToTarget(osg::Vec3 initalPosition, osg::Vec3 targetPosition,
osg::Vec3 targetRotation, osg::Vec3 translation, double snap) const;
public:
InstanceMode(
WorldspaceWidget* worldspaceWidget, osg::ref_ptr<osg::Group> parentNode, QWidget* parent = nullptr);
void activate(CSVWidget::SceneToolbar* toolbar) override;
void deactivate(CSVWidget::SceneToolbar* toolbar) override;
void setEditLock(bool locked) override;
void primaryOpenPressed(const WorldspaceHitResult& hit) override;
void primaryEditPressed(const WorldspaceHitResult& hit) override;
void secondaryEditPressed(const WorldspaceHitResult& hit) override;
void primarySelectPressed(const WorldspaceHitResult& hit) override;
void secondarySelectPressed(const WorldspaceHitResult& hit) override;
void tertiarySelectPressed(const WorldspaceHitResult& hit) override;
bool primaryEditStartDrag(const QPoint& pos) override;
bool secondaryEditStartDrag(const QPoint& pos) override;
bool primarySelectStartDrag(const QPoint& pos) override;
bool secondarySelectStartDrag(const QPoint& pos) override;
void drag(const QPoint& pos, int diffX, int diffY, double speedFactor) override;
void dragCompleted(const QPoint& pos) override;
/// \note dragAborted will not be called, if the drag is aborted via changing
/// editing mode
void dragAborted() override;
void dragWheel(int diff, double speedFactor) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
int getSubMode() const override;
signals:
void requestFocus(const std::string& id);
private slots:
void setDragAxis(const char axis);
void subModeChanged(const std::string& id);
void deleteSelectedInstances();
void cloneSelectedInstances();
void getSelectionGroup(const int group);
void saveSelectionGroup(const int group);
void dropToCollision();
};
/// \brief Helper class to handle object mask data in safe way
class DropObjectHeightHandler
{
public:
DropObjectHeightHandler(WorldspaceWidget* worldspacewidget);
~DropObjectHeightHandler();
std::vector<float> mObjectHeights;
private:
WorldspaceWidget* mWorldspaceWidget;
std::vector<osg::Node::NodeMask> mOldMasks;
};
}
#endif
|