Commit 6c117e42 authored by Locatelli's avatar Locatelli
Browse files

Changes

parent e98cbf2a
......@@ -46,7 +46,8 @@ public:
std::vector<std::string> keys; //! keys of data
std::vector<std::string> legendKeys; //! keys of legend
std::vector<std::string> colors; //! colors string of data
std::string title; //! Title of plot
std::string windowTitle; //! Title of plot
std::string plotTitle; //! Title of plot
std::string xaxisTitle; //! X axis of title
std::string yaxisTitle; //! Y axis of title
......
......@@ -96,11 +96,11 @@ PropertyPlotDataContainer::PropertyPlotDataContainer(const proto::PlotPropertyDa
for (bool errorbar: plotMessage.error_bars()) {
errorBars.push_back(errorbar);
}
numorId = plotMessage.numor_id();
titleId = plotMessage.title_id();
xaxisTitleId = plotMessage.xaxis_title_id();
yaxisTitleId = plotMessage.yaxis_title_id();
title = plotMessage.title();
windowTitle = plotMessage.windowtitle();
plotTitle = plotMessage.plottitle();
xaxisTitle = plotMessage.xaxis_title();
yaxisTitle = plotMessage.yaxis_title();
for (int32 id : plotMessage.optimization_result_found_id()) {
......
......@@ -65,7 +65,6 @@ public:
std::vector<float64> xPhysicalSizeIds; //! X physical size
std::vector<float64> yPhysicalSizeIds; //! X physical size
std::vector<bool> errorBars; //! Plot using error bar
int32 numorId; //! Property Id of numor
int32 titleId; //! Property Id of title
int32 xaxisTitleId; //! Property Id of x axis title
int32 yaxisTitleId; //! Property Id of y axis title
......
......@@ -208,6 +208,7 @@ int32 main(int32 argc, char* argv[]) {
}
exit:
manager::mpl::MplEventManager::resetInstance();
app->quit();
delete app;
delete mpl;
......
......@@ -135,6 +135,7 @@ void OffScreenPlotManager::savePlot(string pbfilename, string path) {
ostringstream plotkey;
plotkey << pbfilename;
if ((data.xdata_size() > 0) && (data.ydata_size() > 0) && (data.zdata_size() > 0)) {
// 2D
for (int32 i = 0; i < data.xdata_size(); ++i) {
......@@ -142,6 +143,7 @@ void OffScreenPlotManager::savePlot(string pbfilename, string path) {
plot::offscreen::OffScreenPlot2D plot(m_Figure, plotkey.str(), m_Mpl, i, &data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string());
m_Figure->clear();
} catch (Error& e) {
Error("OffScreenPlotManager", "savePlot", "Failed create 2d plot", plotkey.str());
}
......@@ -153,6 +155,7 @@ void OffScreenPlotManager::savePlot(string pbfilename, string path) {
plot::offscreen::OffScreenPlot1D plot(m_Figure, plotkey.str(), m_Mpl, i, &data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string());
m_Figure->clear();
} catch (Error& e) {
Error("OffScreenPlotManager", "savePlot", "Failed create 1d plot", plotkey.str());
}
......@@ -162,15 +165,16 @@ void OffScreenPlotManager::savePlot(string pbfilename, string path) {
plot::offscreen::OffScreenEmptyPlot plot(m_Figure, plotkey.str(), m_Mpl, 0, &data);
plot.display();
plot.save(pbfile.parent_path().parent_path().string());
m_Figure->clear();
} catch (Error& e) {
Error("OffScreenPlotManager", "savePlot", "Failed create empty plot", plotkey.str());
}
}
// delete file
boost::filesystem::remove(pbfile);
if (data.type() == buffer::Data::Log) {
// delete file
boost::filesystem::remove(pbfile);
// Send image to log database system
json::LogSender sender(&data);
sender.postMessage();
......
......@@ -53,7 +53,7 @@ public:
/*!
* \brief reset instance
*/
void resetInstance();
static void resetInstance();
static const char MODULE_EVENT_NAME[]; //! Module event name to load
......
......@@ -48,14 +48,19 @@ void EmptyPlot::display() throw (Error) {
///////////////////////////////////////////////////////////////////////////////////////
//// Set Title
////
string title = getTitle();
string title = getPlotTitle();
try {
m_Mpl->title(title);
if (m_PlotWindow != nullptr) {
m_PlotWindow->setWindowTitle("Nomad plot");
}
} catch (Error &e) {
Warning("EmptyPlot", "display", "Failed to set window title", title);
Warning("EmptyPlot", "display", "Failed to set plot title", title);
}
if (m_PlotWindow != nullptr) {
title = getWindowTitle();
try {
m_PlotWindow->setWindowTitle(title);
} catch (Error &e) {
Warning("EmptyPlot", "display", "Failed to set window title", title);
}
}
}
......
......@@ -128,11 +128,17 @@ public:
protected:
/*!
* \brief Get title to give for the plot window
* \return The title string
*/
virtual std::string getWindowTitle() = 0;
/*!
* \brief Get title to give for the plot
* \return The title string
*/
virtual std::string getTitle() = 0;
virtual std::string getPlotTitle() = 0;
std::string m_PlotKey; //! Unique Plot key
......
......@@ -98,31 +98,31 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = int32array , y = int32array");
Error("Plot1D", "localplot", "Failed to plot data", "x = int32array , y = int32array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "float64array") && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = float64array , y = float64array");
Error("Plot1D", "localplot", "Failed to plot data", "x = float64array , y = float64array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "int32array") && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = int32array , y = float64array");
Error("Plot1D", "localplot", "Failed to plot data", "x = int32array , y = float64array");
}
} else if ((m_PlotXPropertyTypes[numplot] == "float64array") && (m_PlotYPropertyTypes[numplot] == "int32array")) {
try {
plot(numplot, m_PlotXArrays[numplot], m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "x = float64array , y = int32array");
Error("Plot1D", "localplot", "Failed to plot data", "x = float64array , y = int32array");
}
} else if ((m_PlotXPropertyTypes[numplot].empty() == true) && (m_PlotYPropertyTypes[numplot] == "float64array")) {
try {
plot(numplot, m_PlotYArrays[numplot], keywords);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot data", "y = float64array");
Error("Plot1D", "localplot", "Failed to plot data", "y = float64array");
}
}
......@@ -132,25 +132,30 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
try {
optimizationPlot(numplot);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot optimization y");
Error("Plot1D", "localplot", "Failed to plot optimization y");
}
try {
optimizationResult(numplot);
} catch (Error& e) {
Error("Plot1D", "display", "Failed to plot optimization result");
Error("Plot1D", "localplot", "Failed to plot optimization result");
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set Title
////
string title = getTitle();
string title = getPlotTitle();
try {
m_MplPlot1D.title(title);
if (m_PlotWindow != nullptr) {
} catch (Error &e) {
Warning("Plot1D", "localplot", "Failed to set plot title", title);
}
if (m_PlotWindow != nullptr) {
title = getWindowTitle();
try {
m_PlotWindow->setWindowTitle(title);
} catch (Error &e) {
Warning("Plot1D", "localplot", "Failed to set window title", title);
}
} catch (Error &e) {
Warning("Plot1D", "display", "Failed to set window title", title);
}
///////////////////////////////////////////////////////////////////////////////////////
......@@ -160,7 +165,7 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
try {
m_MplPlot1D.xlabel(xlabel);
} catch (Error& e) {
Warning("Plot1D", "display", "Failed to set x label", xlabel);
Warning("Plot1D", "localplot", "Failed to set x label", xlabel);
}
///////////////////////////////////////////////////////////////////////////////////////
......@@ -170,7 +175,7 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
try {
m_MplPlot1D.ylabel(ylabel);
} catch (Error& e) {
Warning("Plot1D", "display", "Failed to set y label", ylabel);
Warning("Plot1D", "localplot", "Failed to set y label", ylabel);
}
///////////////////////////////////////////////////////////////////////////////////////
......@@ -182,7 +187,7 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
keywordslegend["loc"] = "upper right";
m_MplPlot1D.legend(keywordslegend);
} catch (Error& e) {
Warning("Plot1D", "display", "Failed to create plot legend");
Warning("Plot1D", "localplot", "Failed to create plot legend");
}
///////////////////////////////////////////////////////////////////////////////////////
......@@ -193,7 +198,7 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
grid(m_PlotWindow->gridActivated());
}
} catch (Error& e) {
Warning("Plot1D", "display", "Failed to show plot grid");
Warning("Plot1D", "localplot", "Failed to show plot grid");
}
///////////////////////////////////////////////////////////////////////////////////////
......@@ -204,7 +209,7 @@ void Plot1D::localplot(uint32 numplot) throw (Error) {
log(m_PlotWindow->logActivated());
}
} catch (Error& e) {
Warning("Plot1D", "display", "Failed to activate log");
Warning("Plot1D", "localplot", "Failed to activate log");
}
}
......
......@@ -36,21 +36,24 @@ namespace plot {
/*
* constructor
*/
Plot2D::Plot2D(const std::string& plotkey, view::mpl::Mpl* mpl, PlotWindow* plotwindow, view::mpl::MplFigure* figure) :
Plot(plotkey, mpl, plotwindow), m_MplPlot2D(mpl, figure) {
Plot2D::Plot2D(const std::string& plotkey, view::mpl::Mpl* mpl, PlotWindow* plotwindow, view::mpl::MplFigure* figure, bool doProjections) :
Plot(plotkey, mpl, plotwindow), m_MplPlot2D(mpl, figure), m_DoProjections(doProjections) {
m_MinColorLim = 100.;
m_MaxColorLim = 100.;
m_XPhysicalSize = 1.;
m_YPhysicalSize = 1.;
m_Space = 0.1;
}
/*
* destructor
*/
Plot2D::~Plot2D() {
// Unsubscribe limits changed events
manager::mpl::MplEventManager::getInstance()->unsubscribeXLimChanged(&m_MplPlot2D.getMainAxis());
manager::mpl::MplEventManager::getInstance()->unsubscribeYLimChanged(&m_MplPlot2D.getMainAxis());
if (m_PlotWindow != nullptr) {
// Unsubscribe limits changed events
manager::mpl::MplEventManager::getInstance()->unsubscribeXLimChanged(&m_MplPlot2D.getMainAxis());
manager::mpl::MplEventManager::getInstance()->unsubscribeYLimChanged(&m_MplPlot2D.getMainAxis());
}
}
/*
......@@ -61,10 +64,16 @@ void Plot2D::display() throw (Error) {
//// Create spec grid
////
try {
//gs = GridSpec(2, 3, height_ratios=[10,1], width_ratios=[3,30,1], wspace=0.1, hspace=0.1)
vector<int32> hrs = {PLOT2D_HEIGHT_RATIO , PROJX_HEIGHT_RATIO};
vector<int32> wrs = {PROJY_WIDTH_RATIO, PLOT2D_WIDTH_RATIO, COLORBAR_WIDTH_RATIO};
m_MplPlot2D.gridSpec(2, 3, hrs, wrs, 0.1, 0.1);
if (m_DoProjections == true) {
vector<int32> hrs = {PLOT2D_HEIGHT_RATIO , PROJX_HEIGHT_RATIO};
vector<int32> wrs = {PROJY_WIDTH_RATIO, PLOT2D_WIDTH_RATIO, COLORBAR_WIDTH_RATIO};
m_MplPlot2D.gridSpec(2, 3, hrs, wrs, m_Space, m_Space);
}
else {
vector<int32> hrs;
vector<int32> wrs;
m_MplPlot2D.gridSpec(1, 1 , hrs, wrs, m_Space, m_Space);
}
} catch (Error& e) {
throw Error("Plot2D", "display", "Failed to do gridSpec");
}
......@@ -73,7 +82,12 @@ void Plot2D::display() throw (Error) {
//// Creat subplot
////
try {
m_MplPlot2D.subplots(m_PlotWindow, 1, 4, 0, 2);
if (m_DoProjections == true) {
m_MplPlot2D.subplots(m_PlotWindow, 1, 4, 0, 2);
}
else {
m_MplPlot2D.subplots(m_PlotWindow, 0);
}
} catch (Error& e) {
throw Error("Plot2D", "display", "Failed to do subplots");
}
......@@ -81,14 +95,19 @@ void Plot2D::display() throw (Error) {
///////////////////////////////////////////////////////////////////////////////////////
//// Set Title
////
string title = getTitle();
string title = getPlotTitle();
try {
m_MplPlot2D.title(title);
if (m_PlotWindow != nullptr) {
} catch (Error &e) {
Warning("Plot2D", "display", "Failed to set plot title", title);
}
if (m_PlotWindow != nullptr) {
title = getWindowTitle();
try {
m_PlotWindow->setWindowTitle(title);
} catch (Error &e) {
Warning("Plot2D", "display", "Failed to set window title", title);
}
} catch (Error &e) {
Warning("Plot2D", "display", "Failed to set window title", title);
}
///////////////////////////////////////////////////////////////////////////////////////
......@@ -99,8 +118,10 @@ void Plot2D::display() throw (Error) {
getXData();
getYData();
getZData();
vector<int32> lims = {0, m_datax.size() - 1, 0 , m_datay.size() - 1};
computeProjections(lims);
if (m_DoProjections == true) {
vector<int32> lims = {0, m_datax.size() - 1, 0 , m_datay.size() - 1};
computeProjections(lims);
}
}
catch(Error& e) {
throw Error("Plot2D", "display", "Failed to load server data");
......@@ -110,29 +131,36 @@ void Plot2D::display() throw (Error) {
//// Create plots
////
try {
m_MplPlot2D.plot((int32) m_datax.size(), (int32) m_datay.size(), m_dataz ,m_datax, m_datay, m_dataprojx, m_dataprojy);
if (m_DoProjections == true) {
m_MplPlot2D.plot((int32) m_datax.size(), (int32) m_datay.size(), m_dataz ,m_datax, m_datay, m_dataprojx, m_dataprojy);
}
else {
m_MplPlot2D.plot((int32) m_datax.size(), (int32) m_datay.size(), m_dataz ,m_datax, m_datay);
}
} catch (Error& e) {
throw Error("Plot2D", "display", "Failed to do plot");
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set x label
////
string xlabel = getXLabel();
try {
m_MplPlot2D.xlabel(xlabel);
} catch (Error& e) {
Warning("Plot2D", "display", "Failed to set x label", xlabel);
}
if (m_DoProjections == true) {
///////////////////////////////////////////////////////////////////////////////////////
//// Set x label
////
string xlabel = getXLabel();
try {
m_MplPlot2D.xlabel(xlabel);
} catch (Error& e) {
Warning("Plot2D", "display", "Failed to set x label", xlabel);
}
///////////////////////////////////////////////////////////////////////////////////////
//// Set y label
////
string ylabel = getYLabel();
try {
m_MplPlot2D.ylabel(ylabel);
} catch (Error& e) {
Warning("Plot2D", "display", "Failed to set y label", ylabel);
///////////////////////////////////////////////////////////////////////////////////////
//// Set y label
////
string ylabel = getYLabel();
try {
m_MplPlot2D.ylabel(ylabel);
} catch (Error& e) {
Warning("Plot2D", "display", "Failed to set y label", ylabel);
}
}
if (m_PlotWindow != nullptr) {
......@@ -223,17 +251,19 @@ void Plot2D::resetLimits() throw (Error) {
float64 ymax = *std::max_element(m_datay.begin(), m_datay.end());
m_MplPlot2D.set_imagelim(xmin, xmax, ymax, ymin); // Invert y axis
// Reset projection X limits
if (m_dataprojx.empty() == false) {
float64 projymin = *std::min_element(m_dataprojx.begin(), m_dataprojx.end());
float64 projymax = *std::max_element(m_dataprojx.begin(), m_dataprojx.end());
m_MplPlot2D.set_projxlim(xmin, xmax, projymin, projymax);
}
// Reset projection Y limits
if (m_dataprojy.empty() == false) {
float64 projxmin = *std::min_element(m_dataprojy.begin(), m_dataprojy.end());
float64 projxmax = *std::max_element(m_dataprojy.begin(), m_dataprojy.end());
m_MplPlot2D.set_projylim(projxmin, projxmax, ymin, ymax);
if (m_DoProjections == true) {
// Reset projection X limits
if (m_dataprojx.empty() == false) {
float64 projymin = *std::min_element(m_dataprojx.begin(), m_dataprojx.end());
float64 projymax = *std::max_element(m_dataprojx.begin(), m_dataprojx.end());
m_MplPlot2D.set_projxlim(xmin, xmax, projymin, projymax);
}
// Reset projection Y limits
if (m_dataprojy.empty() == false) {
float64 projxmin = *std::min_element(m_dataprojy.begin(), m_dataprojy.end());
float64 projxmax = *std::max_element(m_dataprojy.begin(), m_dataprojy.end());
m_MplPlot2D.set_projylim(projxmin, projxmax, ymin, ymax);
}
}
}
......@@ -362,7 +392,9 @@ void Plot2D::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
*/
void Plot2D::treatEvent(EventType type) throw (Error) {
if ((type == MplEventSubscriber::XLIM_CHANGED) || (type == MplEventSubscriber::YLIM_CHANGED)) {
updateProjections();
if (m_DoProjections == true) {
updateProjections();
}
}
}
......
......@@ -39,7 +39,7 @@ public:
* \param[in] plotwindow The plot window object which containing this plot
* \param[in] figure The mpl figure object
*/
Plot2D(const std::string& plotkey, view::mpl::Mpl* mpl, PlotWindow* plotwindow, view::mpl::MplFigure* figure);
Plot2D(const std::string& plotkey, view::mpl::Mpl* mpl, PlotWindow* plotwindow, view::mpl::MplFigure* figure, bool doProjections);
/*!
* \brief destructor
......@@ -196,6 +196,9 @@ protected:
float64 m_XPhysicalSize; //
float64 m_YPhysicalSize; //
bool m_DoProjections;
float64 m_Space;
//! Ratio of spec grid constants
static const int32 PLOT2D_WIDTH_RATIO = 30;
static const int32 PROJY_WIDTH_RATIO = 3;
......
......@@ -51,6 +51,8 @@ PlotWindow::PlotWindow(view::mpl::Mpl* mpl, const proto::PlotPropertyDataMessage
* destructor
*/
PlotWindow::~PlotWindow() {
m_MplFigure->clear();
delete m_Plot;
delete m_PropertyPlotDataContainer;
delete m_QtWindow;
delete m_MplFigure;
......
......@@ -46,24 +46,30 @@ OffScreenEmptyPlot::~OffScreenEmptyPlot() {
}
/*
* getTitle
* display
*/
string OffScreenEmptyPlot::getTitle() {
ostringstream title;
if (m_Data->has_numor() == true) {
title << m_Data->numor();
} else if (m_Data->has_imageid() != 0) {
title << m_Data->imageid();
} else {
title << m_PlotKey;
void OffScreenEmptyPlot::display() throw (Error) {
EmptyPlot::display();
if (m_Data->type() == buffer::Data::Spy) {
try {
m_Mpl->title("");
m_Mpl->tightLayout(0);
}
catch(Error &e) {
Error("OffScreenEmptyPlot", "display", "Error when executing the title and tight layout method");
}
}
if (m_Data->has_extratitle() == true) {
if (m_Data->extratitle().empty() == false) {
title << " - " << m_Data->extratitle();
else {
try {
m_Mpl->tightLayout(1.08);
}
catch(Error &e) {
Error("OffScreenEmptyPlot", "display", "Error when executing the title and tight layout method");
}
}
title << " - Empty Data";
return title.str();
}
/*
......
......@@ -47,17 +47,35 @@ public:
*/
~OffScreenEmptyPlot();
/*!
* \brief Display plot
* \throws Error
*/
virtual void display() throw (Error);
/*!
* \brief Display plot
* \throws Error
*/
virtual void save(const std::string& imagepath) throw (Error);
private:
/*!
* \brief Get title to give for the plot window
* \return The title string
*/
virtual std::string getWindowTitle() {
return OffScreenPlot::getWindowTitle();
}
/*!
* \brief Get title to give for the plot
* \return The title string
*/
virtual std::string getTitle();
virtual std::string getPlotTitle() {
return OffScreenPlot::getPlotTitle();
}
};
......
......@@ -17,6 +17,7 @@
*/
#include "OffScreenPlot.h"
#include <sstream>
using namespace std;
......@@ -36,5 +37,20 @@ OffScreenPlot::OffScreenPlot(view::mpl::MplFigure* figure, int32 index, buffer::
OffScreenPlot::~OffScreenPlot() {
}
/*
* getTitle
*/
string OffScreenPlot::getPlotTitle() {
ostringstream title;
title << m_Data->title();
if (m_Data->has_extratitle() == true) {
if (m_Data->extratitle().empty() == false) {
title << " - " << m_Data->extratitle();
}
}
title << " - Empty Data";
return title.str();
}
}
}
......@@ -60,6 +60,20 @@ public:
protected:
/*!
* \brief Get title to give for the plot window
* \return The title string
*/
std::string getWindowTitle() {
return std::string("");
}
/*!