chart2/source/view/charttypes/GL3DBarChart.cxx | 108 ++++++++++++++++++++++--- chart2/source/view/inc/3DChartObjects.hxx | 15 +++ chart2/source/view/inc/GL3DBarChart.hxx | 19 ++-- chart2/source/view/main/3DChartObjects.cxx | 55 ++++++++++++ chart2/source/view/main/ChartView.cxx | 63 ++++++++------ 5 files changed, 213 insertions(+), 47 deletions(-)
New commits: commit 715ee7e3576066ea285244ff32d7f31ea58da381 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Fri May 9 10:52:32 2014 -0400 Best effort of blindly placing axes and background objects. Change-Id: I3a7c77ee8d9c6ff033b112158daec3923ed27034 diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index b1b29a5..3775d04 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -55,6 +55,7 @@ void GL3DBarChart::create3DShapes() const float nBarDistanceY = nBarSizeY / 2; sal_uInt32 nId = 1; + float nXEnd = 0.0; float nYPos = 0.0; maShapes.clear(); @@ -98,11 +99,46 @@ void GL3DBarChart::create3DShapes() maShapes.push_back(new opengl3D::Bar(mpRenderer.get(), aBarPosition, nColor, nId++)); } + float nThisXEnd = nPointCount * (nBarSizeX + nBarDistanceX); + if (nXEnd < nThisXEnd) + nXEnd = nThisXEnd; + ++nSeriesIndex; } nYPos += nBarSizeY + nBarDistanceY; + // X axis + maShapes.push_back(new opengl3D::Line(mpRenderer.get(), nId++)); + opengl3D::Line* pAxis = static_cast<opengl3D::Line*>(&maShapes.back()); + glm::vec3 aBegin; + aBegin.y = nYPos; + glm::vec3 aEnd = aBegin; + aEnd.x = nXEnd; + pAxis->setPosition(aBegin, aEnd); + pAxis->setLineColor(COL_WHITE); + + // Y axis + maShapes.push_back(new opengl3D::Line(mpRenderer.get(), nId++)); + pAxis = static_cast<opengl3D::Line*>(&maShapes.back()); + aBegin.x = aBegin.y = 0; + aEnd = aBegin; + aEnd.y = nYPos; + pAxis->setPosition(aBegin, aEnd); + pAxis->setLineColor(COL_WHITE); + + // Chart background. + maShapes.push_back(new opengl3D::Rectangle(mpRenderer.get(), nId++)); + opengl3D::Rectangle* pRect = static_cast<opengl3D::Rectangle*>(&maShapes.back()); + glm::vec3 aTopLeft; + glm::vec3 aTopRight = aTopLeft; + aTopRight.x = nXEnd; + glm::vec3 aBottomRight = aTopRight; + aBottomRight.y = nYPos; + pRect->setPosition(aTopLeft, aTopRight, aBottomRight); + pRect->setFillColor(COL_BLACK); + pRect->setLineColor(COL_WHITE); + // Create category texts along X-axis at the bottom. uno::Sequence<OUString> aCats = mrCatProvider.getSimpleCategories(); for (sal_Int32 i = 0; i < aCats.getLength(); ++i) @@ -112,12 +148,11 @@ void GL3DBarChart::create3DShapes() maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++)); opengl3D::Text* p = static_cast<opengl3D::Text*>(&maShapes.back()); Size aTextSize = p->getSize(); - glm::vec3 aTopLeft; aTopLeft.x = nXPos; aTopLeft.y = nYPos; - glm::vec3 aTopRight = aTopLeft; + aTopRight = aTopLeft; aTopRight.x += aTextSize.getWidth(); - glm::vec3 aBottomRight = aTopRight; + aBottomRight = aTopRight; aBottomRight.y += aTextSize.getHeight(); p->setPosition(aTopLeft, aTopRight, aBottomRight); } diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index e93d656..8571fd8 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -53,6 +53,9 @@ public: virtual void render() SAL_OVERRIDE; + void setPosition(const glm::vec3& rBegin, const glm::vec3& rEnd); + void setLineColor(const Color& rColor); + private: glm::vec3 maPosBegin; glm::vec3 maPosEnd; @@ -81,6 +84,11 @@ class Rectangle : public Renderable3DObject public: Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId); virtual void render() SAL_OVERRIDE; + + void setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight); + void setFillColor(const Color& rColor); + void setLineColor(const Color& rColor); + private: glm::vec3 maTopLeft; glm::vec3 maTopRight; diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index 820e79d..6cad265 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -53,6 +53,17 @@ void Line::render() mpRenderer->EndAddShapePolygon3DObject(); } +void Line::setPosition(const glm::vec3& rBegin, const glm::vec3& rEnd) +{ + maPosBegin = rBegin; + maPosEnd = rEnd; +} + +void Line::setLineColor(const Color& rColor) +{ + maLineColor = rColor; +} + Text::Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId): Renderable3DObject(pRenderer, nId) { @@ -124,6 +135,23 @@ void Rectangle::render() mpRenderer->EndAddShapePolygon3DObject(); } +void Rectangle::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight) +{ + maTopLeft = rTopLeft; + maTopRight = rTopRight; + maBottomRight = rBottomRight; +} + +void Rectangle::setFillColor(const Color& rColor) +{ + maColor = rColor; +} + +void Rectangle::setLineColor(const Color& rColor) +{ + maLineColor = rColor; +} + Camera::Camera(OpenGL3DRenderer* pRenderer): Renderable3DObject(pRenderer, 0), maPos(10,10,-10), commit 3e684f09c5f53c9c5a25ee15f809d40c1f3d4c9c Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Fri May 9 10:09:24 2014 -0400 No need to store these text objects separately. Change-Id: I0ee63480fa0f15f42c81818d89ff5b5a3407ece4 diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 15fe291..b1b29a5 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -55,9 +55,6 @@ void GL3DBarChart::create3DShapes() const float nBarDistanceY = nBarSizeY / 2; sal_uInt32 nId = 1; - - std::vector<opengl3D::Text*> aYAxisTexts; - float nYPos = 0.0; maShapes.clear(); @@ -76,8 +73,8 @@ void GL3DBarChart::create3DShapes() DataSeriesHelper::getDataSeriesLabel( rDataSeries.getModel(), mxChartType->getRoleOfSequenceForSeriesLabel()); - aYAxisTexts.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); - opengl3D::Text* p = aYAxisTexts.back(); + maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); + opengl3D::Text* p = static_cast<opengl3D::Text*>(&maShapes.back()); Size aTextSize = p->getSize(); glm::vec3 aTopLeft, aTopRight, aBottomRight; aTopLeft.x = aTextSize.getWidth() * -1.0; @@ -124,15 +121,6 @@ void GL3DBarChart::create3DShapes() aBottomRight.y += aTextSize.getHeight(); p->setPosition(aTopLeft, aTopRight, aBottomRight); } - - { - // Transfer all Y-axis text objects to the shape collection. - std::vector<opengl3D::Text*>::iterator itText = aYAxisTexts.begin(), itTextEnd = aYAxisTexts.end(); - for (; itText != itTextEnd; ++itText) - maShapes.push_back(*itText); - } - - aYAxisTexts.clear(); } void GL3DBarChart::render() commit 0d095ee5995e9e8938b1302c6efe7c818a1ed055 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu May 8 16:13:42 2014 -0400 Try without std::back_inserter. Some tinderboxes don't like that. Change-Id: I37b5da446abe123d0e0526b5556014df606e6156 diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 6a96ecb..15fe291 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -125,8 +125,13 @@ void GL3DBarChart::create3DShapes() p->setPosition(aTopLeft, aTopRight, aBottomRight); } - // Transfer all Y-axis text objects to the shape collection. - std::copy(aYAxisTexts.begin(), aYAxisTexts.end(), std::back_inserter(maShapes)); + { + // Transfer all Y-axis text objects to the shape collection. + std::vector<opengl3D::Text*>::iterator itText = aYAxisTexts.begin(), itTextEnd = aYAxisTexts.end(); + for (; itText != itTextEnd; ++itText) + maShapes.push_back(*itText); + } + aYAxisTexts.clear(); } commit eb1cc0205b720699817a7caf4c19b8471d2798cd Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu May 8 16:03:10 2014 -0400 My best attempt at positioning text objects. Change-Id: I390b6d09558b7f2dea46cfd4e5db5ed6f2162b5f diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 761d4b2..6a96ecb 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -41,6 +41,14 @@ GL3DBarChart::~GL3DBarChart() void GL3DBarChart::create3DShapes() { + // Each series of data flows from left to right, and multiple series are + // stacked vertically along y axis. + + // NOTE: These objects are created and positioned in a totally blind + // fashion since we don't even have a way to see them on screen. So, no + // guarantee they are positioned correctly. In fact, they are guaranteed + // to be positioned incorrectly. + const float nBarSizeX = 10; const float nBarSizeY = 10; const float nBarDistanceX = nBarSizeX / 2; @@ -48,10 +56,9 @@ void GL3DBarChart::create3DShapes() sal_uInt32 nId = 1; - uno::Sequence<OUString> aCats = mrCatProvider.getSimpleCategories(); - for (sal_Int32 i = 0; i < aCats.getLength(); ++i) - // Category name text object. - maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++)); + std::vector<opengl3D::Text*> aYAxisTexts; + + float nYPos = 0.0; maShapes.clear(); maShapes.push_back(new opengl3D::Camera(mpRenderer.get())); @@ -59,6 +66,8 @@ void GL3DBarChart::create3DShapes() for (boost::ptr_vector<VDataSeries>::const_iterator itr = maDataSeries.begin(), itrEnd = maDataSeries.end(); itr != itrEnd; ++itr) { + nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY); + const VDataSeries& rDataSeries = *itr; sal_Int32 nPointCount = rDataSeries.getTotalPointCount(); @@ -67,13 +76,21 @@ void GL3DBarChart::create3DShapes() DataSeriesHelper::getDataSeriesLabel( rDataSeries.getModel(), mxChartType->getRoleOfSequenceForSeriesLabel()); - maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); + aYAxisTexts.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); + opengl3D::Text* p = aYAxisTexts.back(); + Size aTextSize = p->getSize(); + glm::vec3 aTopLeft, aTopRight, aBottomRight; + aTopLeft.x = aTextSize.getWidth() * -1.0; + aTopLeft.y = nYPos; + aTopRight.y = nYPos; + aBottomRight = aTopRight; + aBottomRight.y += aTextSize.getHeight(); + p->setPosition(aTopLeft, aTopRight, aBottomRight); for(sal_Int32 nIndex = 0; nIndex < nPointCount; ++nIndex) { float nVal = rDataSeries.getYValue(nIndex); float nXPos = nIndex * (nBarSizeX + nBarDistanceX); - float nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY); sal_Int32 nColor = COL_RED; @@ -86,6 +103,31 @@ void GL3DBarChart::create3DShapes() ++nSeriesIndex; } + + nYPos += nBarSizeY + nBarDistanceY; + + // Create category texts along X-axis at the bottom. + uno::Sequence<OUString> aCats = mrCatProvider.getSimpleCategories(); + for (sal_Int32 i = 0; i < aCats.getLength(); ++i) + { + float nXPos = i * (nBarSizeX + nBarDistanceX); + + maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++)); + opengl3D::Text* p = static_cast<opengl3D::Text*>(&maShapes.back()); + Size aTextSize = p->getSize(); + glm::vec3 aTopLeft; + aTopLeft.x = nXPos; + aTopLeft.y = nYPos; + glm::vec3 aTopRight = aTopLeft; + aTopRight.x += aTextSize.getWidth(); + glm::vec3 aBottomRight = aTopRight; + aBottomRight.y += aTextSize.getHeight(); + p->setPosition(aTopLeft, aTopRight, aBottomRight); + } + + // Transfer all Y-axis text objects to the shape collection. + std::copy(aYAxisTexts.begin(), aYAxisTexts.end(), std::back_inserter(maShapes)); + aYAxisTexts.clear(); } void GL3DBarChart::render() diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index ca56580..e93d656 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -64,6 +64,11 @@ class Text : public Renderable3DObject public: Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId); virtual void render() SAL_OVERRIDE; + + Size getSize() const; + + void setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight); + private: BitmapEx maText; glm::vec3 maTopLeft; diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index daa5eca..820e79d 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -8,6 +8,8 @@ */ #include "3DChartObjects.hxx" +#include <vcl/virdev.hxx> +#include <vcl/svapp.hxx> namespace chart { @@ -51,10 +53,20 @@ void Line::render() mpRenderer->EndAddShapePolygon3DObject(); } -Text::Text(OpenGL3DRenderer* pRenderer, const OUString& /*rStr*/, sal_uInt32 nId): +Text::Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId): Renderable3DObject(pRenderer, nId) { - // TODO : convert OUString to BitmapEx. + // Convert OUString to BitmapEx. + VirtualDevice aDevice(*Application::GetDefaultDevice(), 0, 0); + Font aFont = aDevice.GetFont(); + aFont.SetColor(COL_WHITE); + aDevice.SetFont(aFont); + aDevice.Erase(); + aDevice.SetOutputSizePixel(Size(20,12)); + aDevice.SetBackground(Wallpaper(COL_TRANSPARENT)); + aDevice.DrawText(Point(0,0), rStr); + + maText = BitmapEx(aDevice.GetBitmapEx(Point(0,0), Size(20,12))); } void Text::render() @@ -64,6 +76,18 @@ void Text::render() mpRenderer->CreateTextTexture(maText, maTopLeft, maTopRight, maBottomRight, bottomLeft); } +Size Text::getSize() const +{ + return maText.GetSizePixel(); +} + +void Text::setPosition(const glm::vec3& rTopLeft, const glm::vec3& rTopRight, const glm::vec3& rBottomRight) +{ + maTopLeft = rTopLeft; + maTopRight = rTopRight; + maBottomRight = rBottomRight; +} + Rectangle::Rectangle(OpenGL3DRenderer* pRenderer, sal_uInt32 nId): Renderable3DObject(pRenderer, nId) { commit dc91bc9ab349f7487ab1dbff6357c682321e63d5 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu May 8 13:25:27 2014 -0400 TemporaryContext is no more. Change-Id: I9cf0f5db276c5837921c132d98032cf2331362fd diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx index 8237805..86115de 100644 --- a/chart2/source/view/inc/GL3DBarChart.hxx +++ b/chart2/source/view/inc/GL3DBarChart.hxx @@ -25,11 +25,7 @@ namespace opengl3D { class Renderable3DObject; class OpenGL3DRenderer; -namespace temporary { - -class TemporaryContext; - -} } +} class GL3DBarChart { commit 4d00c32252b726340b76661adb68ffbe94077271 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu May 8 13:10:45 2014 -0400 Stop the leak of VDataSeries instances. Change-Id: I36cfa84e4fb19c3da584672d510e8b35f9343950 diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 51cfcbe..761d4b2 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -25,7 +25,7 @@ namespace chart { GL3DBarChart::GL3DBarChart( const css::uno::Reference<css::chart2::XChartType>& xChartType, - const std::vector<VDataSeries*>& rDataSeries, + const boost::ptr_vector<VDataSeries>& rDataSeries, OpenGLWindow& rWindow, ExplicitCategoriesProvider& rCatProvider ) : mxChartType(xChartType), maDataSeries(rDataSeries), @@ -56,22 +56,22 @@ void GL3DBarChart::create3DShapes() maShapes.clear(); maShapes.push_back(new opengl3D::Camera(mpRenderer.get())); sal_Int32 nSeriesIndex = 0; - for(std::vector<VDataSeries*>::const_iterator itr = maDataSeries.begin(), + for (boost::ptr_vector<VDataSeries>::const_iterator itr = maDataSeries.begin(), itrEnd = maDataSeries.end(); itr != itrEnd; ++itr) { - VDataSeries* pDataSeries = *itr; - sal_Int32 nPointCount = pDataSeries->getTotalPointCount(); + const VDataSeries& rDataSeries = *itr; + sal_Int32 nPointCount = rDataSeries.getTotalPointCount(); // Create series name text object. OUString aSeriesName = DataSeriesHelper::getDataSeriesLabel( - pDataSeries->getModel(), mxChartType->getRoleOfSequenceForSeriesLabel()); + rDataSeries.getModel(), mxChartType->getRoleOfSequenceForSeriesLabel()); maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); for(sal_Int32 nIndex = 0; nIndex < nPointCount; ++nIndex) { - float nVal = pDataSeries->getYValue(nIndex); + float nVal = rDataSeries.getYValue(nIndex); float nXPos = nIndex * (nBarSizeX + nBarDistanceX); float nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY); diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx index f3e225f..8237805 100644 --- a/chart2/source/view/inc/GL3DBarChart.hxx +++ b/chart2/source/view/inc/GL3DBarChart.hxx @@ -36,7 +36,7 @@ class GL3DBarChart public: GL3DBarChart( const css::uno::Reference<css::chart2::XChartType>& xChartType, - const std::vector<VDataSeries*>& rDataSeries, OpenGLWindow& rContext, + const boost::ptr_vector<VDataSeries>& rDataSeries, OpenGLWindow& rContext, ExplicitCategoriesProvider& rCatProvider ); ~GL3DBarChart(); @@ -47,7 +47,7 @@ public: private: css::uno::Reference<css::chart2::XChartType> mxChartType; - std::vector<VDataSeries*> maDataSeries; + const boost::ptr_vector<VDataSeries>& maDataSeries; boost::ptr_vector<opengl3D::Renderable3DObject> maShapes; boost::scoped_ptr<opengl3D::OpenGL3DRenderer> mpRenderer; diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 0c23d05..13f4bf7 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -3120,7 +3120,7 @@ void ChartView::createShapes3D() return; uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); - std::vector<VDataSeries*> aDataSeries; + boost::ptr_vector<VDataSeries> aDataSeries; if (aCooSysList.getLength() != 1) // Supporting multiple coordinates in a truly 3D chart (which implies @@ -3155,8 +3155,7 @@ void ChartView::createShapes3D() if(!xDataSeries.is()) continue; - VDataSeries* pSeries = new VDataSeries( xDataSeries ); - aDataSeries.push_back(pSeries); + aDataSeries.push_back(new VDataSeries(xDataSeries)); } OpenGLWindow* pWindow = mrChartModel.getOpenGLWindow(); commit ef52afb234ef9f7ad19e2595f5ab0c7e0d9a5352 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu May 8 11:26:48 2014 -0400 Put category and data series names into the shape collection. Their positions are yet to be calculated. Change-Id: Ibb1f2498eb2af3305c2afb6d41be99eaf279daaf diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index 525b4fc..51cfcbe 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -16,16 +16,22 @@ #include "3DChartObjects.hxx" #include "GL3DRenderer.hxx" +#include <ExplicitCategoriesProvider.hxx> +#include <DataSeriesHelper.hxx> using namespace com::sun::star; namespace chart { -GL3DBarChart::GL3DBarChart(const std::vector<VDataSeries*>& rDataSeries, - OpenGLWindow& rWindow): +GL3DBarChart::GL3DBarChart( + const css::uno::Reference<css::chart2::XChartType>& xChartType, + const std::vector<VDataSeries*>& rDataSeries, + OpenGLWindow& rWindow, ExplicitCategoriesProvider& rCatProvider ) : + mxChartType(xChartType), maDataSeries(rDataSeries), mpRenderer(new opengl3D::OpenGL3DRenderer()), - mrWindow(rWindow) + mrWindow(rWindow), + mrCatProvider(rCatProvider) { } @@ -40,15 +46,29 @@ void GL3DBarChart::create3DShapes() const float nBarDistanceX = nBarSizeX / 2; const float nBarDistanceY = nBarSizeY / 2; + sal_uInt32 nId = 1; + + uno::Sequence<OUString> aCats = mrCatProvider.getSimpleCategories(); + for (sal_Int32 i = 0; i < aCats.getLength(); ++i) + // Category name text object. + maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aCats[i], nId++)); + maShapes.clear(); maShapes.push_back(new opengl3D::Camera(mpRenderer.get())); sal_Int32 nSeriesIndex = 0; - sal_uInt32 nId = 1; for(std::vector<VDataSeries*>::const_iterator itr = maDataSeries.begin(), itrEnd = maDataSeries.end(); itr != itrEnd; ++itr) { VDataSeries* pDataSeries = *itr; sal_Int32 nPointCount = pDataSeries->getTotalPointCount(); + + // Create series name text object. + OUString aSeriesName = + DataSeriesHelper::getDataSeriesLabel( + pDataSeries->getModel(), mxChartType->getRoleOfSequenceForSeriesLabel()); + + maShapes.push_back(new opengl3D::Text(mpRenderer.get(), aSeriesName, nId++)); + for(sal_Int32 nIndex = 0; nIndex < nPointCount; ++nIndex) { float nVal = pDataSeries->getYValue(nIndex); diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index 05c2f5b..ca56580 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -62,7 +62,7 @@ private: class Text : public Renderable3DObject { public: - Text(OpenGL3DRenderer* pRenderer, sal_uInt32 nId); + Text(OpenGL3DRenderer* pRenderer, const OUString& rStr, sal_uInt32 nId); virtual void render() SAL_OVERRIDE; private: BitmapEx maText; diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx index 06b1be5..f3e225f 100644 --- a/chart2/source/view/inc/GL3DBarChart.hxx +++ b/chart2/source/view/inc/GL3DBarChart.hxx @@ -18,6 +18,8 @@ namespace chart { +class ExplicitCategoriesProvider; + namespace opengl3D { class Renderable3DObject; @@ -32,7 +34,11 @@ class TemporaryContext; class GL3DBarChart { public: - GL3DBarChart(const std::vector<VDataSeries*>& rDataSeries, OpenGLWindow& rContext); + GL3DBarChart( + const css::uno::Reference<css::chart2::XChartType>& xChartType, + const std::vector<VDataSeries*>& rDataSeries, OpenGLWindow& rContext, + ExplicitCategoriesProvider& rCatProvider ); + ~GL3DBarChart(); void create3DShapes(); @@ -40,12 +46,13 @@ public: void render(); private: - + css::uno::Reference<css::chart2::XChartType> mxChartType; std::vector<VDataSeries*> maDataSeries; boost::ptr_vector<opengl3D::Renderable3DObject> maShapes; boost::scoped_ptr<opengl3D::OpenGL3DRenderer> mpRenderer; OpenGLWindow& mrWindow; + ExplicitCategoriesProvider& mrCatProvider; }; } diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index b4ca2c4..daa5eca 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -51,9 +51,10 @@ void Line::render() mpRenderer->EndAddShapePolygon3DObject(); } -Text::Text(OpenGL3DRenderer* pRenderer, sal_uInt32 nId): +Text::Text(OpenGL3DRenderer* pRenderer, const OUString& /*rStr*/, sal_uInt32 nId): Renderable3DObject(pRenderer, nId) { + // TODO : convert OUString to BitmapEx. } void Text::render() diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 93d4133..0c23d05 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -3121,45 +3121,53 @@ void ChartView::createShapes3D() uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); 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] ); + if (aCooSysList.getLength() != 1) + // Supporting multiple coordinates in a truly 3D chart (which implies + // it's a Cartesian coordinate system) is a bit of a challenge, if not + // impossible. + return; - uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY ); - OSL_ASSERT( xDataSeriesContainer.is()); - if( !xDataSeriesContainer.is() ) - continue; + uno::Reference<XCoordinateSystem> xCooSys( aCooSysList[0] ); - 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; + //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() ) + return; - VDataSeries* pSeries = new VDataSeries( xDataSeries ); - aDataSeries.push_back(pSeries); - } - } + uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() ); + if (aChartTypeList.getLength() != 1) + // Likewise, we can't really support multiple chart types here. + return; + + uno::Reference< XChartType > xChartType( aChartTypeList[0] ); + + uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY ); + OSL_ASSERT( xDataSeriesContainer.is()); + if( !xDataSeriesContainer.is() ) + return; + + 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); } OpenGLWindow* pWindow = mrChartModel.getOpenGLWindow(); if(!pWindow) return; + boost::scoped_ptr<ExplicitCategoriesProvider> pCatProvider(new ExplicitCategoriesProvider(xCooSys, mrChartModel)); + pWindow->Show(); - GL3DBarChart aBarChart(aDataSeries, *pWindow); + GL3DBarChart aBarChart(xChartType, aDataSeries, *pWindow, *pCatProvider); aBarChart.create3DShapes(); aBarChart.render(); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits