diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-12-31 20:59:28 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-01-29 08:09:30 +0100 |
commit | 2d6e556abd2128ead3832ac880fb60317b0ee415 (patch) | |
tree | 8b716ef19bef05a6754e8cf41d9a403f4210f461 | |
parent | 46574ef1a2b3911678cc3a714c65394961682fe5 (diff) |
first try at implementing time based updates in new chart implementation
Change-Id: I3d03e44a415023ca12548ea99a3732cba49c8074
-rw-r--r-- | chart2/Library_chartcore.mk | 1 | ||||
-rw-r--r-- | chart2/inc/ChartView.hxx | 18 | ||||
-rw-r--r-- | chart2/source/model/main/ChartModel.cxx | 2 | ||||
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 49 |
4 files changed, 67 insertions, 3 deletions
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk index bcad947a0725..de4c8886a539 100644 --- a/chart2/Library_chartcore.mk +++ b/chart2/Library_chartcore.mk @@ -46,6 +46,7 @@ $(eval $(call gb_Library_use_libraries,chartcore,\ fwe \ i18nlangtag \ sal \ + salhelper \ sfx \ svl \ svt \ diff --git a/chart2/inc/ChartView.hxx b/chart2/inc/ChartView.hxx index 66925ab89c16..b1c6b5f3eb25 100644 --- a/chart2/inc/ChartView.hxx +++ b/chart2/inc/ChartView.hxx @@ -45,6 +45,8 @@ #include <boost/shared_ptr.hpp> #include <boost/ptr_container/ptr_vector.hpp> +#include <salhelper/thread.hxx> + class SdrPage; namespace chart { @@ -54,14 +56,25 @@ class DrawModelWrapper; class SeriesPlotterContainer; class VDataSeries; +enum TimeBasedMode +{ + MANUAL, + AUTOMATIC, + AUTOMATIC_WRAP +}; + struct TimeBasedInfo { TimeBasedInfo(): bTimeBased(false), - nFrame(0) {} + nFrame(0), + eMode(AUTOMATIC), + mpThread(NULL) {} bool bTimeBased; size_t nFrame; + TimeBasedMode eMode; + salhelper::Thread* mpThread; // only valid when we are in the time based mode ::std::vector< std::vector< VDataSeries* > > m_aDataSeriesList; @@ -181,6 +194,8 @@ public: virtual OUString SAL_CALL dump() throw(::com::sun::star::uno::RuntimeException); + void setViewDirty(); + private: //methods ChartView(); @@ -254,6 +269,7 @@ private: //member ::com::sun::star::awt::Rectangle m_aResultingDiagramRectangleExcludingAxes; TimeBasedInfo maTimeBased; + osl::Mutex maTimeMutex; }; } diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx index 4e6d245e5766..d65ab67ddf3c 100644 --- a/chart2/source/model/main/ChartModel.cxx +++ b/chart2/source/model/main/ChartModel.cxx @@ -93,6 +93,7 @@ ChartModel::ChartModel(uno::Reference<uno::XComponentContext > const & xContext) , m_bModified( sal_False ) , m_nInLoad(0) , m_bUpdateNotificationsPending(false) + , mbTimeBased(true) , mpChartView(NULL) , m_pUndoManager( NULL ) , m_aControllers( m_aModelMutex ) @@ -131,6 +132,7 @@ ChartModel::ChartModel( const ChartModel & rOther ) , m_bModified( rOther.m_bModified ) , m_nInLoad(0) , m_bUpdateNotificationsPending(false) + , mbTimeBased(rOther.mbTimeBased) , mpChartView(NULL) , m_aResource( rOther.m_aResource ) , m_aMediaDescriptor( rOther.m_aMediaDescriptor ) diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index a01bffdd20eb..30eeb5531bd0 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -108,6 +108,9 @@ #include <rtl/strbuf.hxx> #include <rtl/ustring.hxx> +#include <osl/conditn.hxx> +#include <osl/time.h> + #include <boost/shared_ptr.hpp> namespace chart { @@ -121,6 +124,30 @@ using ::com::sun::star::uno::Any; namespace { class theExplicitValueProviderUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theExplicitValueProviderUnoTunnelId > {}; + +class UpdateTimeBasedThread : public salhelper::Thread +{ +public: + UpdateTimeBasedThread(ChartView& rChartView, TimeBasedInfo& rTimeBasedInfo): + salhelper::Thread("ChartUpdate"), + mrChartView(rChartView), + mrTimeBasedInfo(rTimeBasedInfo) {} +private: + virtual void execute() + { + TimeValue const aTime = { 0, 100 }; + for(size_t i = 0; i < 60; ++i) + { + mrChartView.setViewDirty(); + mrChartView.update(); + wait(aTime); + } + } + + ChartView& mrChartView; + TimeBasedInfo& mrTimeBasedInfo; +}; + } const uno::Sequence<sal_Int8>& ExplicitValueProvider::getUnoTunnelId() @@ -2369,9 +2396,20 @@ void ChartView::createShapes() clock_t nStart = clock(); OSL_TRACE( "\nPPPPPPPPP>>>>>>>>>>>> chart view :: createShapes()" ); #endif + + osl::ResettableMutexGuard aTimedGuard(maTimeMutex); if(mrChartModel.isTimeBased()) + { maTimeBased.bTimeBased = true; + if(!maTimeBased.mpThread) + { + maTimeBased.mpThread = new UpdateTimeBasedThread(*this, maTimeBased); + maTimeBased.mpThread->launch(); + } + + } + //make sure add-in is refreshed after creating the shapes const ::comphelper::ScopeGuard aGuard( boost::bind( &ChartView::impl_refreshAddIn, this ) ); if( impl_AddInDrawsAllByItself() ) @@ -2444,7 +2482,7 @@ void ChartView::createShapes() SeriesPlotterContainer aSeriesPlotterContainer( m_aVCooSysList ); aSeriesPlotterContainer.initializeCooSysAndSeriesPlotter( mrChartModel ); - if(maTimeBased.bTimeBased) + if(maTimeBased.bTimeBased && maTimeBased.nFrame != 0) { std::vector<VSeriesPlotter*>& rSeriesPlotter = aSeriesPlotterContainer.getSeriesPlotterList(); @@ -2549,6 +2587,8 @@ void ChartView::createShapes() //cleanup: remove all empty group shapes to avoid grey border lines: lcl_removeEmptyGroupShapes( mxRootShape ); + pShapeFactory->render( mxRootShape ); + if(maTimeBased.bTimeBased && maTimeBased.nFrame % 60 == 0) { // create copy of the data for next frame @@ -2582,7 +2622,6 @@ void ChartView::createShapes() m_pDrawModelWrapper->getSdrModel().EnableUndo( true ); } - pShapeFactory->render( mxRootShape ); if(maTimeBased.bTimeBased) { @@ -3007,6 +3046,12 @@ OUString ChartView::dump() throw (uno::RuntimeException) } +void ChartView::setViewDirty() +{ + osl::ResettableMutexGuard aGuard(maTimeMutex); + m_bViewDirty = true; +} + } //namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |