summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-03-31 00:28:14 +0200
committerMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-04-08 04:38:19 +0200
commitdfb2ab0cee2ba04ce8816580447e7db8160ffac4 (patch)
tree777b3c77d6f0f4045dabc5b431108690c7f23df3
parente7b79ef04579c8b5a9957207062fd13a9ca5755c (diff)
add initial code for creating 3D bar shapes
Change-Id: I55489fad8723f204003fe502eea5e02de4c8d6ef
-rw-r--r--chart2/Library_chartcore.mk3
-rw-r--r--chart2/inc/ChartView.hxx2
-rw-r--r--chart2/source/inc/macros.hxx2
-rw-r--r--chart2/source/view/charttypes/3DBarChart.cxx69
-rw-r--r--chart2/source/view/inc/3DBarChart.hxx41
-rw-r--r--chart2/source/view/inc/3DChartObjects.hxx71
-rw-r--r--chart2/source/view/main/3DChartObjects.cxx25
-rw-r--r--chart2/source/view/main/3DChartObjects.hxx30
-rw-r--r--chart2/source/view/main/ChartView.cxx88
9 files changed, 323 insertions, 8 deletions
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk
index 6dafd718fbbe..55aa61038f9b 100644
--- a/chart2/Library_chartcore.mk
+++ b/chart2/Library_chartcore.mk
@@ -28,6 +28,7 @@ $(eval $(call gb_Library_set_precompiled_header,chartcore,$(SRCDIR)/chart2/inc/p
$(eval $(call gb_Library_use_externals,chartcore,\
boost_headers \
mdds_headers \
+ glm_headers \
))
$(eval $(call gb_Library_use_custom_headers,chartcore,\
@@ -81,6 +82,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\
chart2/source/view/axes/VPolarCoordinateSystem \
chart2/source/view/axes/VPolarGrid \
chart2/source/view/axes/VPolarRadiusAxis \
+ chart2/source/view/charttypes/3DBarChart \
chart2/source/view/charttypes/AreaChart \
chart2/source/view/charttypes/BarChart \
chart2/source/view/charttypes/BarPositionHelper \
@@ -93,6 +95,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\
chart2/source/view/charttypes/Splines \
chart2/source/view/charttypes/VSeriesPlotter \
chart2/source/view/diagram/VDiagram \
+ chart2/source/view/main/3DChartObjects \
chart2/source/view/main/ChartItemPool \
chart2/source/view/main/ChartView \
chart2/source/view/main/Clipping \
diff --git a/chart2/inc/ChartView.hxx b/chart2/inc/ChartView.hxx
index 045843a74a42..f6252bc4743e 100644
--- a/chart2/inc/ChartView.hxx
+++ b/chart2/inc/ChartView.hxx
@@ -200,6 +200,8 @@ private: //methods
ChartView();
void createShapes();
+ void createShapes3D();
+ bool isReal3DChart();
void getMetaFile( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream
, bool bUseHighContrast );
SdrPage* getSdrPage();
diff --git a/chart2/source/inc/macros.hxx b/chart2/source/inc/macros.hxx
index 21e59117c79d..2319afe019f8 100644
--- a/chart2/source/inc/macros.hxx
+++ b/chart2/source/inc/macros.hxx
@@ -30,7 +30,7 @@
typeid( ex ).name() << ", Message: " << \
ex.Message )
-#define ENABLE_GL3D_BARCHART 0
+#define ENABLE_GL3D_BARCHART 1
#endif
diff --git a/chart2/source/view/charttypes/3DBarChart.cxx b/chart2/source/view/charttypes/3DBarChart.cxx
new file mode 100644
index 000000000000..2da54aa3ccf9
--- /dev/null
+++ b/chart2/source/view/charttypes/3DBarChart.cxx
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "3DBarChart.hxx"
+
+#include "3DChartObjects.hxx"
+
+#include <glm/glm.hpp>
+#include <glm/gtx/transform.hpp>
+
+namespace chart {
+
+Bar3DChart::Bar3DChart(const std::vector<VDataSeries*>& rDataSeries):
+ maDataSeries(rDataSeries)
+{
+}
+
+Bar3DChart::~Bar3DChart()
+{
+}
+
+void Bar3DChart::create3DShapes()
+{
+ const float nBarSizeX = 10;
+ const float nBarSizeY = 10;
+ const float nBarDistanceX = nBarSizeX / 2;
+ const float nBarDistanceY = nBarSizeY / 2;
+
+ sal_Int32 nSeriesIndex = 0;
+ for(std::vector<VDataSeries*>::const_iterator itr = maDataSeries.begin(),
+ itrEnd = maDataSeries.end(); itr != itrEnd; ++itr)
+ {
+ VDataSeries* pDataSeries = *itr;
+ sal_Int32 nPointCount = pDataSeries->getTotalPointCount();
+ for(sal_Int32 nIndex = 0; nIndex < nPointCount; ++nIndex)
+ {
+ float nVal = pDataSeries->getYValue(nIndex);
+ float nXPos = nIndex * (nBarSizeX + nBarDistanceX);
+ float nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY);
+
+ glm::mat4 aBarPosition;
+ glm::scale(aBarPosition, nBarSizeX, nBarSizeY, nVal);
+ glm::translate(aBarPosition, nXPos, nYPos, nVal/2);
+
+ maShapes.push_back(new opengl3D::Bar(aBarPosition));
+ }
+
+ ++nSeriesIndex;
+ }
+}
+
+void Bar3DChart::render()
+{
+ for(boost::ptr_vector<opengl3D::Renderable3DObject>::iterator itr = maShapes.begin(),
+ itrEnd = maShapes.end(); itr != itrEnd; ++itr)
+ {
+ itr->render();
+ }
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/inc/3DBarChart.hxx b/chart2/source/view/inc/3DBarChart.hxx
new file mode 100644
index 000000000000..6eeea5bb86b0
--- /dev/null
+++ b/chart2/source/view/inc/3DBarChart.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <vector>
+#include <boost/ptr_container/ptr_vector.hpp>
+#include "VDataSeries.hxx"
+
+namespace chart {
+
+namespace opengl3D {
+
+class Renderable3DObject;
+
+}
+
+class Bar3DChart
+{
+public:
+ Bar3DChart(const std::vector<VDataSeries*>& rDataSeries);
+ ~Bar3DChart();
+
+ void create3DShapes();
+
+ void render();
+
+private:
+
+ std::vector<VDataSeries*> maDataSeries;
+ boost::ptr_vector<opengl3D::Renderable3DObject> maShapes;
+
+};
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx
new file mode 100644
index 000000000000..ec56ad82b0cf
--- /dev/null
+++ b/chart2/source/view/inc/3DChartObjects.hxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <glm/glm.hpp>
+
+#include <tools/color.hxx>
+#include <vcl/bitmapex.hxx>
+
+namespace chart {
+
+namespace opengl3D {
+
+class Renderable3DObject
+{
+public:
+
+ virtual ~Renderable3DObject() {};
+
+ virtual void render() {}
+};
+
+class Bar : public Renderable3DObject
+{
+public:
+ Bar( const glm::mat4& rPosition );
+private:
+ bool mbRoundedCorners;
+ glm::mat4 maPos;
+ Color maColor; // RGBA fill color
+ sal_Int32 nUniqueId;
+};
+
+class Line : public Renderable3DObject
+{
+private:
+ glm::vec3 maPosBegin;
+ glm::vec3 maPosEnd;
+ Color maLineColor; // RGBA line color
+ sal_Int32 nUniqueId;
+};
+
+class Text : public Renderable3DObject
+{
+private:
+ BitmapEx maText;
+ glm::vec3 maTopLeft;
+ glm::vec3 maBottomRight;
+ sal_Int32 nUniqueId;
+};
+
+class Rectangle : public Renderable3DObject
+{
+private:
+ glm::vec3 maTopLeft;
+ glm::vec3 maBottomRight;
+ sal_Int32 nUniqueId;
+ Color maColor; // RGBA fill color
+ Color maLineColor; // RGBA line color
+};
+
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
new file mode 100644
index 000000000000..0a0696ab801b
--- /dev/null
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "3DChartObjects.hxx"
+
+namespace chart {
+
+namespace opengl3D {
+
+Bar::Bar(const glm::mat4& rPosition):
+ maPos(rPosition)
+{
+}
+
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/3DChartObjects.hxx b/chart2/source/view/main/3DChartObjects.hxx
index 5851595eff42..ec56ad82b0cf 100644
--- a/chart2/source/view/main/3DChartObjects.hxx
+++ b/chart2/source/view/main/3DChartObjects.hxx
@@ -7,29 +7,45 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <glm/glm.hpp>
+
+#include <tools/color.hxx>
+#include <vcl/bitmapex.hxx>
+
namespace chart {
-namespace 3d {
+namespace opengl3D {
-class Bar
+class Renderable3DObject
{
+public:
+
+ virtual ~Renderable3DObject() {};
+
+ virtual void render() {}
+};
+
+class Bar : public Renderable3DObject
+{
+public:
+ Bar( const glm::mat4& rPosition );
private:
bool mbRoundedCorners;
glm::mat4 maPos;
Color maColor; // RGBA fill color
sal_Int32 nUniqueId;
-}:
+};
-class Line
+class Line : public Renderable3DObject
{
private:
glm::vec3 maPosBegin;
glm::vec3 maPosEnd;
Color maLineColor; // RGBA line color
sal_Int32 nUniqueId;
-}:
+};
-class Text
+class Text : public Renderable3DObject
{
private:
BitmapEx maText;
@@ -38,7 +54,7 @@ private:
sal_Int32 nUniqueId;
};
-class Rectangle
+class Rectangle : public Renderable3DObject
{
private:
glm::vec3 maTopLeft;
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 7200b4e337aa..8b295169f21f 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -48,6 +48,7 @@
#include "DateHelper.hxx"
#include "defines.hxx"
#include <unonames.hxx>
+#include "3DBarChart.hxx"
#include <rtl/uuid.h>
#include <comphelper/scopeguard.hxx>
@@ -2398,6 +2399,40 @@ void ChartView::impl_refreshAddIn()
}
}
+/**
+ * Is it a real 3D chart with a true 3D scene or a 3D chart in a 2D scene.
+ */
+bool ChartView::isReal3DChart()
+{
+ uno::Reference< XDiagram > xDiagram( mrChartModel.getFirstDiagram() );
+ uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
+ if( !xCooSysContainer.is())
+ return false;
+
+ uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
+ for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
+ {
+ uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] );
+ //
+ //iterate through all chart types in the current coordinate system
+ uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
+ OSL_ASSERT( xChartTypeContainer.is());
+ if( !xChartTypeContainer.is() )
+ continue;
+
+ uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
+ for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
+ {
+ uno::Reference< XChartType > xChartType( aChartTypeList[nT] );
+ OUString aChartType = xChartType->getChartType();
+ if( aChartType == "com.sun.star.chart2.GL3DBarChartType" )
+ return true;
+ }
+ }
+
+ return false;
+}
+
void ChartView::createShapes()
{
osl::ResettableMutexGuard aTimedGuard(maTimeMutex);
@@ -2443,6 +2478,12 @@ void ChartView::createShapes()
pShapeFactory->setPageSize(mxRootShape, aPageSize);
pShapeFactory->clearPage(mxRootShape);
+ if(isReal3DChart())
+ {
+ createShapes3D();
+ return;
+ }
+
{
SolarMutexGuard aSolarGuard;
@@ -3067,6 +3108,53 @@ IMPL_LINK_NOARG(ChartView, UpdateTimeBased)
return 0;
}
+void ChartView::createShapes3D()
+{
+ uno::Reference< XDiagram > xDiagram( mrChartModel.getFirstDiagram() );
+ uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
+ if( !xCooSysContainer.is())
+ return;
+
+ uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
+ sal_Int32 nGlobalSeriesIndex = 0;//for automatic symbols
+ std::vector<VDataSeries*> aDataSeries;
+ for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
+ {
+ uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] );
+
+ //iterate through all chart types in the current coordinate system
+ uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
+ OSL_ASSERT( xChartTypeContainer.is());
+ if( !xChartTypeContainer.is() )
+ continue;
+ uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
+ for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
+ {
+ uno::Reference< XChartType > xChartType( aChartTypeList[nT] );
+
+ uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
+ OSL_ASSERT( xDataSeriesContainer.is());
+ if( !xDataSeriesContainer.is() )
+ continue;
+
+ uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
+ for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
+ {
+ uno::Reference< XDataSeries > xDataSeries( aSeriesList[nS], uno::UNO_QUERY );
+ if(!xDataSeries.is())
+ continue;
+
+ VDataSeries* pSeries = new VDataSeries( xDataSeries );
+ aDataSeries.push_back(pSeries);
+ }
+ }
+ }
+
+ Bar3DChart aBarChart(aDataSeries);
+ aBarChart.create3DShapes();
+ aBarChart.render();
+}
+
} //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */