2015-09-27 14:18:22 +00:00
|
|
|
#ifndef CSV_RENDER_INSTANCEMODE_H
|
|
|
|
#define CSV_RENDER_INSTANCEMODE_H
|
|
|
|
|
2020-02-28 11:20:57 +00:00
|
|
|
#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
|
|
|
|
2015-09-27 14:18:22 +00:00
|
|
|
#include "editmode.hpp"
|
2021-01-09 21:35:07 +00:00
|
|
|
#include "instancedragmodes.hpp"
|
2023-12-23 19:29:06 +00:00
|
|
|
#include <apps/opencs/model/world/idtable.hpp>
|
2023-12-22 23:23:57 +00:00
|
|
|
#include <components/esm3/selectiongroup.hpp>
|
2015-09-27 14:18:22 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-09-27 14:18:22 +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
|
|
|
|
2015-09-27 14:18:22 +00:00
|
|
|
class InstanceMode : public EditMode
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2021-01-28 21:10:33 +00:00
|
|
|
|
2020-02-27 09:54:11 +00:00
|
|
|
enum DropMode
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2021-01-28 21:10:33 +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,
|
|
|
|
};
|
2015-09-27 14:18:22 +00:00
|
|
|
|
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;
|
2016-03-04 15:24:02 +00:00
|
|
|
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;
|
2023-12-22 23:23:57 +00:00
|
|
|
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;
|
2022-04-03 00:25:57 +00:00
|
|
|
|
2021-01-28 21:10:33 +00:00
|
|
|
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);
|
2021-01-09 21:35:07 +00:00
|
|
|
void handleSelectDrag(const QPoint& pos);
|
2021-01-28 22:47:38 +00:00
|
|
|
void dropInstance(CSVRender::Object* object, float dropHeight);
|
2021-01-28 21:10:33 +00:00
|
|
|
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;
|
2015-09-27 14:18:22 +00:00
|
|
|
|
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);
|
2015-09-27 14:18:22 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void activate(CSVWidget::SceneToolbar* toolbar) override;
|
2016-01-15 11:07:25 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void deactivate(CSVWidget::SceneToolbar* toolbar) override;
|
2016-01-15 11:07:25 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setEditLock(bool locked) override;
|
2016-03-04 15:24:02 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void primaryOpenPressed(const WorldspaceHitResult& hit) override;
|
2019-07-01 23:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void primaryEditPressed(const WorldspaceHitResult& hit) override;
|
2015-09-27 14:18:22 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void secondaryEditPressed(const WorldspaceHitResult& hit) override;
|
2015-09-27 14:18:22 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void primarySelectPressed(const WorldspaceHitResult& hit) override;
|
2015-10-29 10:20:06 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void secondarySelectPressed(const WorldspaceHitResult& hit) override;
|
2016-01-10 07:56:15 +00:00
|
|
|
|
2022-11-04 22:04:42 +00:00
|
|
|
void tertiarySelectPressed(const WorldspaceHitResult& hit) override;
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool primaryEditStartDrag(const QPoint& pos) override;
|
2016-02-16 15:02:29 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool secondaryEditStartDrag(const QPoint& pos) override;
|
2016-02-16 15:02:29 +00:00
|
|
|
|
2021-01-09 21:35:07 +00:00
|
|
|
bool primarySelectStartDrag(const QPoint& pos) override;
|
|
|
|
|
|
|
|
bool secondarySelectStartDrag(const QPoint& pos) override;
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void drag(const QPoint& pos, int diffX, int diffY, double speedFactor) override;
|
2016-02-16 15:02:29 +00:00
|
|
|
|
2020-10-16 18:18:54 +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
|
2020-10-16 18:18:54 +00:00
|
|
|
void dragAborted() override;
|
2016-03-04 14:19:26 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void dragWheel(int diff, double speedFactor) override;
|
2016-02-16 15:02:29 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
2016-01-10 07:56:15 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void dropEvent(QDropEvent* event) override;
|
2016-03-01 14:48:34 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
int getSubMode() const override;
|
2016-03-01 14:48:34 +00:00
|
|
|
|
2019-07-01 23:26:05 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void requestFocus(const std::string& id);
|
|
|
|
|
2016-03-01 14:48:34 +00:00
|
|
|
private slots:
|
|
|
|
|
2023-12-23 00:59:16 +00:00
|
|
|
void setDragAxis(const char axis);
|
2016-03-01 14:48:34 +00:00
|
|
|
void subModeChanged(const std::string& id);
|
2023-12-13 22:06:12 +00:00
|
|
|
void deleteSelectedInstances();
|
2023-12-13 21:59:49 +00:00
|
|
|
void cloneSelectedInstances();
|
2023-12-22 23:23:57 +00:00
|
|
|
void getSelectionGroup(const int group);
|
|
|
|
void saveSelectionGroup(const int group);
|
2020-03-04 14:49:37 +00:00
|
|
|
void dropSelectedInstancesToCollision();
|
|
|
|
void dropSelectedInstancesToTerrain();
|
|
|
|
void dropSelectedInstancesToCollisionSeparately();
|
|
|
|
void dropSelectedInstancesToTerrainSeparately();
|
2020-02-28 11:20:57 +00:00
|
|
|
void handleDropMethod(DropMode dropMode, QString commandMsg);
|
2015-09-27 14:18:22 +00:00
|
|
|
};
|
2020-03-18 09:16:21 +00:00
|
|
|
|
|
|
|
/// \brief Helper class to handle object mask data in safe way
|
2021-01-28 21:10:33 +00:00
|
|
|
class DropObjectHeightHandler
|
2020-03-18 09:16:21 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-01-28 21:10:33 +00:00
|
|
|
DropObjectHeightHandler(WorldspaceWidget* worldspacewidget);
|
|
|
|
~DropObjectHeightHandler();
|
2020-03-18 09:16:21 +00:00
|
|
|
std::vector<float> mObjectHeights;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-03-18 09:16:21 +00:00
|
|
|
private:
|
|
|
|
WorldspaceWidget* mWorldspaceWidget;
|
|
|
|
std::vector<osg::Node::NodeMask> mOldMasks;
|
|
|
|
};
|
2015-09-27 14:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|