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>
|
|
|
|
|
2016-08-12 21:11:37 +00:00
|
|
|
#include <osg/ref_ptr>
|
2020-02-27 09:54:11 +00:00
|
|
|
#include <osg/Group>
|
2016-08-10 23:31:34 +00:00
|
|
|
#include <osg/Quat>
|
|
|
|
#include <osg/Vec3f>
|
|
|
|
|
2015-09-27 14:18:22 +00:00
|
|
|
#include "editmode.hpp"
|
2021-01-09 21:35:07 +00:00
|
|
|
#include "instancedragmodes.hpp"
|
2015-09-27 14:18:22 +00:00
|
|
|
|
2016-01-15 11:07:25 +00:00
|
|
|
namespace CSVWidget
|
|
|
|
{
|
|
|
|
class SceneToolMode;
|
|
|
|
}
|
|
|
|
|
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;
|
2016-01-19 11:17:13 +00:00
|
|
|
|
2015-09-27 14:18:22 +00:00
|
|
|
class InstanceMode : public EditMode
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2016-02-16 15:02:29 +00:00
|
|
|
|
2020-02-27 09:54:11 +00:00
|
|
|
enum DropMode
|
|
|
|
{
|
2021-01-28 21:40:44 +00:00
|
|
|
Separate = 0b1,
|
2021-01-28 21:10:33 +00:00
|
|
|
|
|
|
|
Collision = 0b10,
|
|
|
|
Terrain = 0b100,
|
|
|
|
|
|
|
|
CollisionSep = Collision | Separate,
|
|
|
|
TerrainSep = Terrain | Separate,
|
2020-02-27 09:54:11 +00:00
|
|
|
};
|
|
|
|
|
2016-01-15 11:07:25 +00:00
|
|
|
CSVWidget::SceneToolMode *mSubMode;
|
2016-03-05 10:41:42 +00:00
|
|
|
std::string mSubModeId;
|
2016-01-19 11:17:13 +00:00
|
|
|
InstanceSelectionMode *mSelectionMode;
|
2016-02-16 15:02:29 +00:00
|
|
|
DragMode mDragMode;
|
2016-03-04 11:00:05 +00:00
|
|
|
int mDragAxis;
|
2016-03-04 15:24:02 +00:00
|
|
|
bool mLocked;
|
2016-08-10 23:31:34 +00:00
|
|
|
float mUnitScaleDist;
|
2020-02-27 09:54:11 +00:00
|
|
|
osg::ref_ptr<osg::Group> mParentNode;
|
2015-09-27 14:18:22 +00:00
|
|
|
|
2016-03-01 14:48:34 +00:00
|
|
|
int getSubModeFromId (const std::string& id) const;
|
|
|
|
|
2016-08-10 23:31:34 +00:00
|
|
|
osg::Vec3f quatToEuler(const osg::Quat& quat) const;
|
|
|
|
osg::Quat eulerToQuat(const osg::Vec3f& euler) const;
|
|
|
|
|
2016-08-12 21:11:37 +00:00
|
|
|
osg::Vec3f getSelectionCenter(const std::vector<osg::ref_ptr<TagBase> >& selection) const;
|
|
|
|
osg::Vec3f getScreenCoords(const osg::Vec3f& pos);
|
2021-01-09 21:35:07 +00:00
|
|
|
osg::Vec3f getProjectionSpaceCoords(const osg::Vec3f& pos);
|
|
|
|
osg::Vec3f 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);
|
2021-01-28 21:10:33 +00:00
|
|
|
float calculateDropHeight(DropMode dropMode, CSVRender::Object* object, float objectHeight);
|
2016-08-12 21:11:37 +00:00
|
|
|
|
2015-09-27 14:18:22 +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
|
|
|
|
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:
|
|
|
|
|
|
|
|
void subModeChanged (const std::string& id);
|
2020-02-19 09:44:55 +00:00
|
|
|
void deleteSelectedInstances(bool active);
|
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;
|
|
|
|
|
|
|
|
private:
|
|
|
|
WorldspaceWidget* mWorldspaceWidget;
|
|
|
|
std::vector<osg::Node::NodeMask> mOldMasks;
|
|
|
|
};
|
2015-09-27 14:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|