1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef VIEW3DSETTINGS_H
18 #define VIEW3DSETTINGS_H
19 
20 #include "TimeDef.h"
21 #include <QWidget>
22 
23 class View3DSettings
24 {
25 public:
26     View3DSettings();
27     ~View3DSettings();
28 
29     // Scaling
30     double spaceScale() const; // xyOpenGL = xyScene * spaceScale
31     void setSpaceScale(double newValue);
32     double timeScale() const; // zOpenGL = t * timeScale
33     void setTimeScale(double newValue);
34     bool isTimeHorizontal() const;
35     void setIsTimeHorizontal(bool newValue);
36     bool freezeSpaceRect() const; // XXX to delete
37     void setFreezeSpaceRect(bool newValue); // XXX to delete
38     bool cameraFollowActiveTime() const;
39     void setCameraFollowActiveTime(bool newValue);
40 
41 
42 
43     bool drawGrid() const; // XXX to delete
44     void setDrawGrid(bool newValue); // XXX to delete
45     bool drawTimePlane() const;
46     void setDrawTimePlane(bool newValue);
47     bool drawCurrentFrame() const;
48     void setDrawCurrentFrame(bool newValue);
49     bool drawAllFrames() const;
50     void setDrawAllFrames(bool newValue);
51     bool drawFramesAsTopology() const;
52     void setDrawFramesAsTopology(bool newValue);
53     bool drawCurrentFrameAsTopology() const;
54     void setDrawCurrentFrameAsTopology(bool newValue);
55     bool drawTopologyFaces() const;
56     void setDrawTopologyFaces(bool newValue);
57     bool drawKeyCells() const;
58     void setDrawKeyCells(bool newValue);
59     bool drawInbetweenCells() const;
60     void setDrawInbetweenCells(bool newValue);
61     bool drawKeyVerticesAsDots() const;
62     void setDrawKeyVerticesAsDots(bool newValue);
63     bool clipToSpaceTimeWindow() const;
64     void setClipToSpaceTimeWindow(bool newValue);
65 
66 
67     int vertexTopologySize() const;
68     void setVertexTopologySize(int newValue);
69 
70     int edgeTopologyWidth() const;
71     void setEdgeTopologyWidth(int newValue);
72 
73 
74     // 3D surface drawing
75     double opacity() const;
76     void setOpacity(double newValue);
77     bool drawAsMesh() const;
78     void setDrawAsMesh(bool newValue);
79     int k1() const;
80     void setK1(int newValue);
81     int k2() const;
82     void setK2(int newValue);
83 
84     // Convert 2D scene coordinate and time to 3D coordinates for View3D
85     // XXX Refactor in one method:
86     //   Eigen::Vector3d to3DCoords(double x2D, double y2D, double time) const;
87     double xFromX2D(double xScene) const;
88     double yFromY2D(double yScene) const;
89     double zFromT(double time) const;
90     double zFromT(int time) const;
91     double zFromT(Time time) const;
92 
93     // Scene settings
94     double xSceneMin() const; // XXX to delete
95     double xSceneMax() const; // XXX to delete
96     double ySceneMin() const; // XXX to delete
97     double ySceneMax() const; // XXX to delete
98 
99     void setXSceneMin(double value); // XXX to delete
100     void setXSceneMax(double value); // XXX to delete
101     void setYSceneMin(double value); // XXX to delete
102     void setYSceneMax(double value); // XXX to delete
103 
104 
105 private:
106     // Display settings
107     double spaceScale_;
108     double timeScale_;
109     bool isTimeHorizontal_;
110     bool freezeSpaceRect_;
111     bool cameraFollowActiveTime_;
112 
113     bool drawGrid_;
114     bool drawTimePlane_;
115     bool drawCurrentFrame_;
116     bool drawAllFrames_;
117     bool drawFramesAsTopology_;
118     bool drawCurrentFrameAsTopology_;
119     bool drawTopologyFaces_;
120     bool drawKeyCells_;
121     bool drawInbetweenCells_;
122     bool drawKeyVerticesAsDots_;
123     bool clipToSpaceTimeWindow_;
124 
125     int vertexTopologySize_;
126     int edgeTopologyWidth_;
127 
128     // 3D
129     double opacity_;
130     bool drawAsMesh_;
131     int k1_;
132     int k2_;
133 
134     // Scene settings
135     double xSceneMin_, xSceneMax_, ySceneMin_, ySceneMax_;
136 };
137 
138 #include <QFormLayout>
139 #include <QCheckBox>
140 #include <QSpinBox>
141 #include <QDoubleSpinBox>
142 
143 class View3DSettingsWidget: public QWidget
144 {
145     Q_OBJECT
146 
147 public:
148     View3DSettingsWidget();
149     ~View3DSettingsWidget();
150 
151     // Set whose settings this widget controls.
152     // The passed viewSettings must outlive this View3DSettingsWidget.
153     void setViewSettings(View3DSettings * viewSettings);
154 
155 signals:
156     void changed();
157     void closed();
158 
159 protected slots:
160     void closeEvent(QCloseEvent * event);
161 
162 private slots:
163     void updateWidgetFromSettings();
164     void updateSettingsFromWidget();
165 
166 private:
167     View3DSettings * viewSettings_;
168 
169     QDoubleSpinBox * spaceScale_;
170     QDoubleSpinBox * timeScale_;
171     QCheckBox * isTimeHorizontal_;
172     QCheckBox * freezeSpaceRect_;
173     QCheckBox * cameraFollowActiveTime_;
174 
175     QCheckBox * drawGrid_;
176     QCheckBox * drawTimePlane_;
177     QCheckBox * drawCurrentFrame_;
178     QCheckBox * drawAllFrames_;
179     QCheckBox * drawFramesAsTopology_;
180     QCheckBox * drawCurrentFrameAsTopology_;
181     QCheckBox * drawTopologyFaces_;
182     QCheckBox * drawKeyCells_;
183     QCheckBox * drawInbetweenCells_;
184     QCheckBox * drawKeyVerticesAsDots_;
185     QCheckBox * clipToSpaceTimeWindow_;
186 
187     QSpinBox * vertexTopologySize_;
188     QSpinBox * edgeTopologyWidth_;
189 
190     QDoubleSpinBox * opacity_;
191     QCheckBox * drawAsMesh_;
192     QSpinBox * k1_;
193     QSpinBox * k2_;
194 
195     bool isUpdatingWidgetFromSettings_;
196 };
197 
198 #endif // VIEW3DSETTINGS_H
199