1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 10:53:53 +00:00
openmw/apps/opencs/view/render/instancemode.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

164 lines
4.9 KiB
C++
Raw Normal View History

#ifndef CSV_RENDER_INSTANCEMODE_H
#define CSV_RENDER_INSTANCEMODE_H
#include <QString>
2022-10-19 17:02:00 +00:00
#include <string>
#include <vector>
2020-02-27 09:54:11 +00:00
#include <osg/Group>
2022-10-19 17:02:00 +00:00
#include <osg/Node>
2016-08-10 23:31:34 +00:00
#include <osg/Quat>
2022-11-04 22:04:42 +00:00
#include <osg/Vec3>
2016-08-12 21:11:37 +00:00
#include <osg/ref_ptr>
2016-08-10 23:31:34 +00:00
#include "editmode.hpp"
#include "instancedragmodes.hpp"
#include <apps/opencs/model/world/idtable.hpp>
#include <components/esm3/selectiongroup.hpp>
2022-10-19 17:02:00 +00:00
class QDragEnterEvent;
class QDropEvent;
class QObject;
class QPoint;
class QWidget;
2016-01-15 11:07:25 +00:00
namespace CSVWidget
{
class SceneToolMode;
2022-10-19 17:02:00 +00:00
class SceneToolbar;
2016-01-15 11:07:25 +00:00
}
namespace CSVRender
{
2016-08-12 21:11:37 +00:00
class TagBase;
2016-01-19 11:17:13 +00:00
class InstanceSelectionMode;
2020-02-27 09:54:11 +00:00
class Object;
2022-10-19 17:02:00 +00:00
class WorldspaceWidget;
struct WorldspaceHitResult;
2016-01-19 11:17:13 +00:00
class InstanceMode : public EditMode
{
Q_OBJECT
2020-02-27 09:54:11 +00:00
enum DropMode
2022-09-22 18:26:05 +00:00
{
Separate = 0b1,
Collision = 0b10,
Terrain = 0b100,
2020-02-27 09:54:11 +00:00
2016-01-19 11:17:13 +00:00
CollisionSep = Collision | Separate,
2021-08-31 21:24:50 +00:00
TerrainSep = Terrain | Separate,
};
2016-03-01 14:48:34 +00:00
CSVWidget::SceneToolMode* mSubMode;
std::string mSubModeId;
InstanceSelectionMode* mSelectionMode;
2016-02-16 15:02:29 +00:00
DragMode mDragMode;
2016-03-01 14:48:34 +00:00
int mDragAxis;
bool mLocked;
2016-03-01 14:48:34 +00:00
float mUnitScaleDist;
osg::ref_ptr<osg::Group> mParentNode;
2022-11-04 22:04:42 +00:00
osg::Vec3 mDragStart;
std::vector<osg::Vec3> mObjectsAtDragStart;
CSMWorld::IdTable* mSelectionGroups;
2016-03-01 14:48:34 +00:00
2016-08-10 23:31:34 +00:00
int getSubModeFromId(const std::string& id) const;
2022-11-04 22:04:42 +00:00
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;
2016-08-12 21:11:37 +00:00
2022-11-04 22:04:42 +00:00
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);
2021-01-28 22:47:38 +00:00
void dropInstance(CSVRender::Object* object, float dropHeight);
float calculateDropHeight(DropMode dropMode, CSVRender::Object* object, float objectHeight);
2022-11-04 22:04:42 +00:00
osg::Vec3 calculateSnapPositionRelativeToTarget(osg::Vec3 initalPosition, osg::Vec3 targetPosition,
osg::Vec3 targetRotation, osg::Vec3 translation, double snap) const;
2022-09-22 18:26:05 +00:00
public:
2020-11-13 07:39:47 +00:00
InstanceMode(
WorldspaceWidget* worldspaceWidget, osg::ref_ptr<osg::Group> parentNode, QWidget* parent = nullptr);
void activate(CSVWidget::SceneToolbar* toolbar) override;
2016-01-15 11:07:25 +00:00
void deactivate(CSVWidget::SceneToolbar* toolbar) override;
2016-01-15 11:07:25 +00:00
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;
2022-11-04 22:04:42 +00:00
void tertiarySelectPressed(const WorldspaceHitResult& hit) override;
bool primaryEditStartDrag(const QPoint& pos) override;
2016-02-16 15:02:29 +00:00
bool secondaryEditStartDrag(const QPoint& pos) override;
2016-02-16 15:02:29 +00:00
bool primarySelectStartDrag(const QPoint& pos) override;
bool secondarySelectStartDrag(const QPoint& pos) override;
void drag(const QPoint& pos, int diffX, int diffY, double speedFactor) override;
2016-02-16 15:02:29 +00:00
void dragCompleted(const QPoint& pos) override;
2016-02-16 15:02:29 +00:00
2016-03-04 14:19:26 +00:00
/// \note dragAborted will not be called, if the drag is aborted via changing
/// editing mode
void dragAborted() override;
2016-03-04 14:19:26 +00:00
void dragWheel(int diff, double speedFactor) override;
2016-02-16 15:02:29 +00:00
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
2016-03-01 14:48:34 +00:00
int getSubMode() const override;
2016-03-01 14:48:34 +00:00
signals:
void requestFocus(const std::string& id);
2016-03-01 14:48:34 +00:00
private slots:
void setDragAxis(const char axis);
2016-03-01 14:48:34 +00:00
void subModeChanged(const std::string& id);
void deleteSelectedInstances();
2023-12-13 21:59:49 +00:00
void cloneSelectedInstances();
void getSelectionGroup(const int group);
void saveSelectionGroup(const int group);
void dropSelectedInstancesToCollision();
void dropSelectedInstancesToTerrain();
void dropSelectedInstancesToCollisionSeparately();
void dropSelectedInstancesToTerrainSeparately();
void handleDropMethod(DropMode dropMode, QString commandMsg);
};
/// \brief Helper class to handle object mask data in safe way
class DropObjectHeightHandler
{
public:
DropObjectHeightHandler(WorldspaceWidget* worldspacewidget);
~DropObjectHeightHandler();
std::vector<float> mObjectHeights;
2022-09-22 18:26:05 +00:00
private:
WorldspaceWidget* mWorldspaceWidget;
std::vector<osg::Node::NodeMask> mOldMasks;
};
}
#endif