add initial code for creating 3D bar shapes

Change-Id: I55489fad8723f204003fe502eea5e02de4c8d6ef
This commit is contained in:
Markus Mohrhard 2014-03-31 00:28:14 +02:00
parent e7b79ef045
commit dfb2ab0cee
9 changed files with 323 additions and 8 deletions

View file

@ -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 \

View file

@ -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();

View file

@ -30,7 +30,7 @@
typeid( ex ).name() << ", Message: " << \
ex.Message )
#define ENABLE_GL3D_BARCHART 0
#define ENABLE_GL3D_BARCHART 1
#endif

View file

@ -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: */

View file

@ -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: */

View file

@ -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: */

View file

@ -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: */

View file

@ -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;

View file

@ -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: */