-
Notifications
You must be signed in to change notification settings - Fork 17
/
Viewer2d.h
152 lines (138 loc) · 4.37 KB
/
Viewer2d.h
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
150
151
#pragma once
#include <GL\glew.h>
#include <QtOpenGL>
#include "Camera\camera.h"
#include "event_handles\Abstract2dEventHandle.h"
#include "cloth\clothManager.h"
#include "cloth\graph\GraphsSewing.h"
#include <stack>
class ClothDesigner;
namespace ldp
{
class ClothPiece;
class AbstractGraphCurve;
class GraphPoint;
}
enum UiSewAddingState
{
UiSewAddingFirst,
UiSewAddingSecond,
UiSewAddingEnd
};
enum UiSewChanges
{
UiSewNoChange,
UiSewAddedToPanel,
UiSewUiTmpChanged,
};
struct UiSewData
{
std::vector<ldp::GraphsSewing::Unit> firsts;
std::vector<ldp::GraphsSewing::Unit> seconds;
ldp::GraphsSewing::Unit f, s;
UiSewAddingState state = UiSewAddingEnd;
};
struct UiCurveData
{
std::vector<std::shared_ptr<ldp::GraphPoint>> points;
std::vector<size_t> renderedIds;
std::shared_ptr<ldp::GraphPoint> tmpPoint;
};
class Viewer2d : public QGLWidget
{
Q_OBJECT
public:
public:
Viewer2d(QWidget *parent);
~Viewer2d();
void init(ldp::ClothManager* clothManager, ClothDesigner* ui);
ldp::ClothManager* getManager() { return m_clothManager; }
ClothDesigner* getMainUI() { return m_mainUI; }
const ldp::Camera& camera()const{ return m_camera; }
ldp::Camera& camera(){ return m_camera; }
void resetCamera();
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
Qt::MouseButtons buttons()const{ return m_buttons; }
QPoint lastMousePos()const{ return m_lastPos; }
const QImage& fboImage()const{ return m_fboImage; }
Abstract2dEventHandle::ProcessorType getEventHandleType()const;
void setEventHandleType(Abstract2dEventHandle::ProcessorType type);
const Abstract2dEventHandle* getEventHandle(Abstract2dEventHandle::ProcessorType type)const;
Abstract2dEventHandle* getEventHandle(Abstract2dEventHandle::ProcessorType type);
int fboRenderedIndex(QPoint p)const;
void getModelBound(ldp::Float3& bmin, ldp::Float3& bmax)const;
// drag box mode
void beginDragBox(QPoint p);
void endDragBox();
bool isDragBoxMode()const { return m_isDragBox; }
// make sew mode
void beginSewingMode();
void endSewingMode();
bool isSewingMode()const { return m_isSewingMode; }
const UiSewData& getUiSewData()const { return m_uiSews; }
void setUiSewData(const UiSewData& data) { m_uiSews = data; }
UiSewChanges makeSewUnit(ldp::AbstractGraphCurve* curve, QPoint pos, bool tmp = false);
UiSewAddingState getSewAddingState()const { return m_uiSews.state; }
UiSewChanges setSewAddingState(UiSewAddingState s);
UiSewChanges setNextSewAddingState();
UiSewChanges deleteCurrentUISew();
// add curve mode
void beginAddCurveMode();
void endAddCurveMode();
bool isAddCurveMode()const { return m_isAddCurveMode; }
const UiCurveData& getUiCurveData()const{ return m_uiCurves; }
void setUiCurveData(const UiCurveData& data) { m_uiCurves = data; }
bool beginNewCurve(QPoint pos);
bool addCurvePoint(QPoint pos, bool tmp);
bool endCurve();
bool giveupCurve();
// edit loop mode
void beginEditLoopMode();
void endEditLoopMode();
bool isEditLoopMode()const { return m_isEditLoopMode; }
protected:
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent*);
void mouseDoubleClickEvent(QMouseEvent *ev);
void wheelEvent(QWheelEvent*);
void keyPressEvent(QKeyEvent*);
void keyReleaseEvent(QKeyEvent*);
void renderDragBox();
void renderSelectionOnFbo();
void renderBackground();
void renderClothsPanels(bool idxMode);
void renderClothsPanels_Edge(const ldp::ClothPiece* piece, bool idxMode);
void renderClothsPanels_KeyPoint(const ldp::ClothPiece* piece, bool idxMode);
void renderClothsPanels_Loop(const ldp::ClothPiece* piece, bool idxMode);
void renderClothsSewing(bool idxMode);
void renderMeshes(bool idxMode);
void renderOneSew(const ldp::GraphsSewing* sew, bool idxMode);
void renderOneSewUnit(const ldp::GraphsSewing::Unit& sew, bool idxMode);
UiSewChanges addCurrentUISew();
void renderUiCurves();
protected:
ldp::Camera m_camera;
QPoint m_lastPos;
int m_showType;
Qt::MouseButtons m_buttons;
QGLFramebufferObject* m_fbo;
QImage m_fboImage;
Abstract2dEventHandle* m_currentEventHandle;
std::vector<std::shared_ptr<Abstract2dEventHandle>> m_eventHandles;
ldp::ClothManager* m_clothManager;
ClothDesigner* m_mainUI;
// drag box mode
bool m_isDragBox;
QPoint m_dragBoxBegin;
// make sew mode
bool m_isSewingMode;
UiSewData m_uiSews;
// add curve mode
bool m_isAddCurveMode;
UiCurveData m_uiCurves;
// edit loop mode
bool m_isEditLoopMode;
};