Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / view / inc / GL3DBarChart.hxx
blob0c244a335b5a249e8977184df79fbffd1d26b809
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DBARCHART_HXX
11 #define INCLUDED_CHART2_SOURCE_VIEW_INC_GL3DBARCHART_HXX
13 #include "GL3DPlotterBase.hxx"
15 #include <deque>
16 #include <memory>
17 #include <vector>
18 #include "VDataSeries.hxx"
20 #include <glm/glm.hpp>
22 #include <vcl/timer.hxx>
23 #include <vcl/idle.hxx>
24 #include <vcl/openglwin.hxx>
26 #include <rtl/ref.hxx>
27 #include <salhelper/thread.hxx>
28 #include <osl/conditn.hxx>
30 namespace chart {
32 class ExplicitCategoriesProvider;
34 namespace opengl3D {
36 class Renderable3DObject;
37 class OpenGL3DRenderer;
38 class TextCache;
39 class Camera;
43 enum RenderEventType
45 EVENT_NONE,
46 EVENT_CLICK,
47 EVENT_MOVE_TO_DEFAULT,
48 EVENT_DRAG_LEFT,
49 EVENT_DRAG_RIGHT,
50 EVENT_SCROLL,
51 EVENT_SHOW_SCROLL,
52 EVENT_SHOW_SELECT,
53 EVENT_AUTO_FLY,
54 EVENT_SELECTBAR_UPDEDATE
57 class RenderThread;
58 class RenderOneFrameThread;
59 class RenderAnimationThread;
61 class GL3DBarChart : public GL3DPlotterBase, public IRenderer
63 friend class RenderThread;
64 friend class RenderOneFrameThread;
65 friend class RenderAnimationThread;
66 friend class RenderBenchMarkThread;
67 public:
68 GL3DBarChart(
69 const css::uno::Reference<css::chart2::XChartType>& xChartType,
70 OpenGLWindow* pContext);
72 virtual ~GL3DBarChart() override;
74 virtual void create3DShapes(const std::vector<std::unique_ptr<VDataSeries>>& rDataSeries,
75 ExplicitCategoriesProvider& rCatProvider) override;
77 virtual void render() override;
79 /// Render one frame of the 3D bar chart.
80 void renderFrame();
82 virtual void update() override;
84 /// Draw to the framebuffer context, and provide the ID of the bar that the user has clicked.
85 sal_uInt32 barIdAtPosition(const Point& rPos);
86 virtual void clickedAt(const Point& rPos, sal_uInt16 nButtons) override;
88 virtual void mouseDragMove(const Point& rStartPos, const Point& rEndPos, sal_uInt16 nButtons) override;
89 virtual void scroll(long nDelta) override;
90 virtual void contextDestroyed() override;
92 void setOpenGLWindow(OpenGLWindow* pWindow);
94 private:
96 void spawnRenderThread(RenderThread *pThread);
97 void joinRenderThread();
98 void moveToCorner();
99 void moveToDefault();
100 glm::vec3 getCornerPosition(sal_Int8 nCornerId);
101 void updateScreenText();
102 void updateRenderFPS();
103 void updateDataUpdateFPS();
104 DECL_LINK(UpdateTimerHdl, Timer*, void);
105 static int calcTimeInterval(TimeValue const &startTime, TimeValue const &endTime);
106 float addScreenTextShape(OUString &nStr, const glm::vec2& rLeftOrRightTop, float nTextHeight, bool bLeftTopFlag,
107 const glm::vec4& rColor,
108 const glm::vec3& rPos = glm::vec3(0.0f, 0.0f, 0.0f),
109 sal_uInt32 nEvent = 0);
110 void recordBarHistory(sal_uInt32 nBarID, float nVal);
111 void updateClickEvent();
112 void calcDistance(std::vector<sal_uInt32> &vectorNearest);
113 static float calcScrollDistance(const glm::mat4 &mvp, const glm::vec3& rPos);
114 void initDistanceHeap(std::vector<sal_uInt32> &vectorNearest);
115 void keepHeap(std::vector<sal_uInt32> &vectorNearest, int index);
116 static void swapVector(int i, int j, std::vector<sal_uInt32> &vectorNearest);
117 void getNearestBars(std::vector<sal_uInt32> &vectorNearest);
118 void updateScroll();
119 void processAutoFly(sal_uInt32 nId, Color nColor);
120 void getNeighborBarID(sal_uInt32 nSelectBarId, sal_uInt32 *pNeighborBarId);
121 void addMovementScreenText(sal_uInt32 nBarId);
122 css::uno::Reference<css::chart2::XChartType> mxChartType;
123 std::vector<std::unique_ptr<opengl3D::Renderable3DObject> > maShapes;
125 std::unique_ptr<opengl3D::OpenGL3DRenderer> mpRenderer;
126 VclPtr<OpenGLWindow> mpWindow;
128 opengl3D::Camera* mpCamera;
129 bool mbValidContext;
131 std::unique_ptr<opengl3D::TextCache> mpTextCache;
133 glm::vec3 maCameraPosition;
134 glm::vec3 maCameraDirection;
136 glm::vec3 maDefaultCameraPosition;
137 glm::vec3 maDefaultCameraDirection;
139 float mnMaxX;
140 float mnMaxY;
141 float mnDistance;
143 * 0 = corner at (0,0,0);
144 * numbering counter clockwise
146 sal_Int8 mnCornerId;
148 std::vector<OUString> maCategories;
149 std::vector<OUString> maSeriesNames;
150 struct BarInformation
152 glm::vec3 maPos;
153 float mnVal;
155 BarInformation(const glm::vec3& rPos, float nVal);
158 std::map<sal_uInt32, const BarInformation> maBarMap;
159 bool mbNeedsNewRender;
160 bool mbCameraInit;
162 osl::Mutex maMutex;
163 rtl::Reference<RenderThread> mpRenderThread;
164 bool mbRenderDie;
165 ::osl::Condition maClickCond;
166 RenderEventType maRenderEvent;
167 RenderEventType maPreRenderEvent;
168 sal_uInt32 mnSelectBarId;
169 sal_uInt32 mnPreSelectBarId;
170 Point maClickPos;
171 sal_uInt32 miScrollRate;
172 bool mbScrollFlg;
173 Idle maIdle;
174 bool mbScreenTextNewRender;
175 std::vector<std::unique_ptr<opengl3D::Renderable3DObject>> maScreenTextShapes;
176 OUString maFPS;
177 OUString maDataUpdateFPS;
178 sal_uInt32 miFrameCount;
179 sal_uInt32 miDataUpdateCounter;
180 TimeValue maFPSRenderStartTime;
181 TimeValue maFPSRenderEndTime;
182 TimeValue maDataUpdateStartTime;
183 TimeValue maDataUpdateEndTime;
184 std::map<sal_uInt32, std::deque<float> > maBarHistory;
185 std::vector<sal_uInt32> maVectorNearest;
186 std::map<sal_uInt32, float> maDistanceMap;
187 std::map<sal_uInt32, Color> maBarColorMap;
188 int mnColorRate;
189 bool mbBenchMarkMode;
190 sal_uInt32 mnHistoryCounter;
191 sal_uInt32 mnBarsInRow;
192 bool mbAutoFly;
193 sal_Int32 mnUpdateBarId;
195 // these form a pair:
196 // main thread sets condition 1 and waits until it can take the mutex
197 // render thread checks condition 1 before taking the mutex and waits in case it
198 // is set until condition 2 is set
200 // only necessary for the benchmark mode
201 osl::Condition maCond1;
202 osl::Condition maCond2;
207 #endif
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */