Commit eb3c26c3 authored by Locatelli's avatar Locatelli
Browse files

Add web offscreen plots

Clean Process finishing
parent 8a5bd42a
......@@ -141,9 +141,6 @@ int main(int32 argc, char* argv[]) {
serverLogSubscriberThread.join();
plotRequestThread.join();
// Reset
logsubscriber.reset();
requesterplot.reset();
}
exit:
......
......@@ -59,8 +59,8 @@ int32 main(int32 argc, char* argv[]) {
DBGMSG(argv[i]);
}
if (argc < 4) {
Error("mainoffscreenplot", "Missing arguments need 5 got", argc);
if (argc < 5) {
Error("mainoffscreenplot", "Missing arguments need 6 got", argc);
return EXIT_FAILURE;
}
......@@ -69,7 +69,7 @@ int32 main(int32 argc, char* argv[]) {
// Init cameo application
int32 err = EXIT_SUCCESS;
application::This::init(1, &argv[3]);
application::This::init(1, &argv[4]);
{
// Get nomad server instance
nomadserver = getNomadInstance(application::This::getServer());
......@@ -102,9 +102,8 @@ int32 main(int32 argc, char* argv[]) {
// Set cameo application running
application::This::setRunning();
boost::filesystem::path pbfile = getenv("HOME");
pbfile += "/offscreenImages/log/pb/";
pbfile += argv[2];
boost::filesystem::path pbfile = argv[3];
pbfile /= argv[2];
pbfile.replace_extension("pb");
DBGMSG("file : " << pbfile.string().c_str());
ifstream inputMessage(pbfile.string().c_str(), fstream::binary);
......@@ -118,6 +117,7 @@ int32 main(int32 argc, char* argv[]) {
buffer::Data data;
data.ParseFromArray(buffer, size);
DBGMSG("type = " << data.type());
DBGMSG("buffer = " << size);
DBGMSG("numor = " << data.numor());
DBGMSG("dataxArray = " << data.xdata_size());
......@@ -135,7 +135,7 @@ int32 main(int32 argc, char* argv[]) {
try {
plot::offscreen::OffScreenPlot2D plot(figure, plotkey.str(), mpl, i, &data);
plot.display();
plot.save();
plot.save(pbfile.parent_path().parent_path().string());
} catch (Error& e) {
Error("mainoffscreenplot", "Failed create 2d plot", plotkey.str());
}
......@@ -146,7 +146,7 @@ int32 main(int32 argc, char* argv[]) {
try {
plot::offscreen::OffScreenPlot1D plot(figure, plotkey.str(), mpl, i, &data);
plot.display();
plot.save();
plot.save(pbfile.parent_path().parent_path().string());
} catch (Error& e) {
Error("mainoffscreenplot", "Failed create 1d plot", plotkey.str());
}
......@@ -155,18 +155,27 @@ int32 main(int32 argc, char* argv[]) {
try {
plot::offscreen::OffScreenEmptyPlot plot(figure, plotkey.str(), mpl, 0, &data);
plot.display();
plot.save();
plot.save(pbfile.parent_path().parent_path().string());
} catch (Error& e) {
Error("mainoffscreenplot", "Failed create empty plot", plotkey.str());
}
}
delete figure;
// delete file
boost::filesystem::remove(pbfile);
// Send image to log database system
json::LogSender sender(&data);
sender.postMessage();
if (data.type() == buffer::Data::Log) {
// Send image to log database system
json::LogSender sender(&data);
sender.postMessage();
boost::filesystem::path pngfile = argv[3];
pngfile = pngfile.parent_path().parent_path();
pngfile /= argv[2];
DBGMSG("remove -> " << pngfile.string());
// delete image file
boost::filesystem::remove(pngfile);
}
}
DBGMSG("ServerRequester::resetInstance");
......@@ -174,7 +183,9 @@ int32 main(int32 argc, char* argv[]) {
manager::ServerRequesterManager::resetInstance();
}
exit: delete mpl;
exit:
// delete mpl;
// Terminate cameo application
application::This::terminate();
return err;
......
......@@ -202,14 +202,9 @@ int32 main(int32 argc, char* argv[]) {
DBGMSG("datachangesubscriber->cancel");
// Cancel subscriber
datachangesubscriber->cancel();
DBGMSG("datachangesubscriber reset");
// Reset subscriber
datachangesubscriber.reset();
}
exit:
DBGMSG("delete mpl");
app->quit();
delete app;
delete mpl;
......
......@@ -82,14 +82,19 @@ OffScreenPlotManager* OffScreenPlotManager::getInstance() {
void OffScreenPlotManager::loop(application::Subscriber* subscriber) {
string data1, data2;
while (subscriber->receiveTwoBinaryParts(data1, data2)) {
notification::Message messageType;
messageType.ParseFromString(data1);
if (messageType.type() == notification::Message::ImageDataReady) {
notification::ImageDataReady messageImageReady;
messageImageReady.ParseFromString(data2);
DBGMSG("Receive image name -> " << messageImageReady.imagename());
savePlot(messageImageReady.imagename());
if (subscriber->hasEnded() == false) {
notification::Message messageType;
messageType.ParseFromString(data1);
if (messageType.type() == notification::Message::ImageDataReady) {
notification::ImageDataReady messageImageReady;
messageImageReady.ParseFromString(data2);
DBGMSG("Receive image name -> " << messageImageReady.imagename() << " ,path " << messageImageReady.imagepath());
savePlot(messageImageReady.imagename(), messageImageReady.imagepath());
}
}
else {
break;
}
}
}
......@@ -97,11 +102,12 @@ void OffScreenPlotManager::loop(application::Subscriber* subscriber) {
/*
* savePlot
*/
void OffScreenPlotManager::savePlot(const string& pbfilename) {
void OffScreenPlotManager::savePlot(const string& pbfilename, const std::string& path) {
// Start mplplot process with files name as arguments
vector<string> args;
args.push_back(pbfilename);
args.push_back(path);
shared_ptr<cameo::application::Instance> offplot = application::This::getServer().start("offmplplot", args);
if (!offplot->exists()) {
Error("OffScreenPlotManager","savePlot", "unable to start offmplplot cameo instance", *offplot);
......
......@@ -46,7 +46,7 @@ public:
*/
void loop(cameo::application::Subscriber* subscriber);
void savePlot(const std::string& pbfilename);
void savePlot(const std::string& pbfilename, const std::string& path);
private:
......
......@@ -57,33 +57,33 @@ void RequestDealerManager::loop(application::Responder* responder) {
// Wait for a new request.
unique_ptr<application::Request> request = responder->receive();
// Stop the loop if cancel is called.
if (request.get() == 0) {
break;
}
// Get the request type.
string firstPart = request->getBinary();
proto::Message message;
message.ParseFromString(firstPart);
DBGMSG("receive : " << message.type());
// Property plot
if (message.type() == proto::Message::PlotPropertyData) {
string secondPart = request->getSecondBinaryPart();
proto::PlotPropertyDataMessage dataMessage;
dataMessage.ParseFromString(secondPart);
PlotManager::getInstance()->displayPropertyPlot(message, dataMessage);
}
// Close plots message
else if (message.type() == proto::Message::ClosePlots) {
PlotManager::getInstance()->reset();
}
// Restore plots message
else if (message.type() == proto::Message::RestorePlots) {
PlotManager::getInstance()->restore();
if (responder->hasEnded() == false) {
// Get the request type.
string firstPart = request->getBinary();
proto::Message message;
message.ParseFromString(firstPart);
DBGMSG("receive : " << message.type());
// Property plot
if (message.type() == proto::Message::PlotPropertyData) {
string secondPart = request->getSecondBinaryPart();
proto::PlotPropertyDataMessage dataMessage;
dataMessage.ParseFromString(secondPart);
PlotManager::getInstance()->displayPropertyPlot(message, dataMessage);
}
// Close plots message
else if (message.type() == proto::Message::ClosePlots) {
PlotManager::getInstance()->reset();
}
// Restore plots message
else if (message.type() == proto::Message::RestorePlots) {
PlotManager::getInstance()->restore();
}
else {
Error("RequestDealerManager", "loop", "Receive bad plot type request");
}
}
else {
Error("RequestDealerManager", "loop", "Receive bad plot type request");
break;
}
}
}
......
......@@ -84,28 +84,30 @@ int32 ServerSubscriberManager::loop() {
string data1, data2;
try {
m_Subscriber->receiveTwoBinaryParts(data1, data2);
notification::Message messageType;
messageType.ParseFromString(data1);
// Check for property changes
if (messageType.type() == notification::Message::PropertyChanged) {
notification::PropertyChanged messagePropertyChanged;
messagePropertyChanged.ParseFromString(data2);
if (messagePropertyChanged.databaseid() == 0) {
unique_lock<mutex> lock(m_UpdatersMutex);
int32 id = messagePropertyChanged.propertyid();
vector<int32>::iterator it;
// std::map<plot::Plot*, std::vector<int32> > localmap;
// {
// localmap = m_Updaters;
// }
// Look on all ids
for (auto iter : m_Updaters) {
it = find(iter.second.begin(), iter.second.end(), id);
if (it != iter.second.end()) {
// DBGMSG("--> " << messagePropertyChanged.databaseid() << " " << messagePropertyChanged.propertyid() << " : " << iter.first);
return id;
if (m_Subscriber->hasEnded() == false) {
notification::Message messageType;
messageType.ParseFromString(data1);
// Check for property changes
if (messageType.type() == notification::Message::PropertyChanged) {
notification::PropertyChanged messagePropertyChanged;
messagePropertyChanged.ParseFromString(data2);
if (messagePropertyChanged.databaseid() == 0) {
unique_lock<mutex> lock(m_UpdatersMutex);
int32 id = messagePropertyChanged.propertyid();
vector<int32>::iterator it;
// std::map<plot::Plot*, std::vector<int32> > localmap;
// {
// localmap = m_Updaters;
// }
// Look on all ids
for (auto iter : m_Updaters) {
it = find(iter.second.begin(), iter.second.end(), id);
if (it != iter.second.end()) {
// DBGMSG("--> " << messagePropertyChanged.databaseid() << " " << messagePropertyChanged.propertyid() << " : " << iter.first);
return id;
}
}
}
}
......
......@@ -35,8 +35,8 @@ namespace plot {
/*
* constructor
*/
Plot2D::Plot2D(const std::string& plotkey, view::mpl::Mpl* mpl, PlotWindow* plotwindow) :
Plot(plotkey, mpl, plotwindow), m_MplPlot2D(mpl) {
Plot2D::Plot2D(const std::string& plotkey, view::mpl::Mpl* mpl, PlotWindow* plotwindow, view::mpl::MplFigure* figure) :
Plot(plotkey, mpl, plotwindow), m_MplPlot2D(mpl, figure) {
m_MinColorLim = 100.;
m_MaxColorLim = 100.;
m_XPhysicalSize = 1.;
......
......@@ -36,8 +36,9 @@ public:
* \param[in] plotkey The unique plot key string
* \param[in] mpl The mpl object
* \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);
Plot2D(const std::string& plotkey, view::mpl::Mpl* mpl, PlotWindow* plotwindow, view::mpl::MplFigure* figure);
/*!
* \brief destructor
......
......@@ -88,7 +88,7 @@ void PlotWindow::display() throw (Error) {
// 2d plot
try {
m_Plot = new property::PropertyPlot2D(m_PropertyPlotDataContainer->plotKey, m_PropertyPlotDataContainer, m_Mpl,
this);
this, getMplFigure());
m_Plot->display();
} catch (Error& e) {
Error("PlotWindow", "display", "Failed create 2d plot", m_PropertyPlotDataContainer->plotKey);
......
......@@ -58,7 +58,9 @@ string OffScreenEmptyPlot::getTitle() {
title << m_PlotKey;
}
if (m_Data->has_extratitle() == true) {
title << " - " << m_Data->extratitle();
if (m_Data->extratitle().empty() == false) {
title << " - " << m_Data->extratitle();
}
}
title << " - Empty Data";
return title.str();
......@@ -67,9 +69,9 @@ string OffScreenEmptyPlot::getTitle() {
/*
* save
*/
void OffScreenEmptyPlot::save() throw (Error) {
void OffScreenEmptyPlot::save(const std::string& imagepath) throw (Error) {
ostringstream filename;
filename << getenv("HOME") << "/offscreenImages/log/" << m_PlotKey;
filename << imagepath << "/" << m_PlotKey;
m_Mpl->savefig(m_Figure->getFigure(), filename.str());
}
......
......@@ -51,7 +51,7 @@ public:
* \brief Display plot
* \throws Error
*/
virtual void save() throw (Error);
virtual void save(const std::string& imagepath) throw (Error);
/*!
* \brief Get title to give for the plot
......
......@@ -56,7 +56,7 @@ public:
* \brief Display plot
* \throws Error
*/
virtual void save() throw (Error) = 0;
virtual void save(const std::string& imagepath) throw (Error) = 0;
protected:
......
......@@ -43,9 +43,9 @@ OffScreenPlot1D::~OffScreenPlot1D() {
/*
* save
*/
void OffScreenPlot1D::save() throw (Error) {
void OffScreenPlot1D::save(const std::string& imagepath) throw (Error) {
ostringstream filename;
filename << getenv("HOME") << "/offscreenImages/log/" << m_PlotKey;
filename << imagepath << "/" << m_PlotKey;
m_Mpl->savefig(m_Figure->getFigure(), filename.str());
}
......@@ -62,7 +62,9 @@ string OffScreenPlot1D::getTitle() {
title << m_PlotKey;
}
if (m_Data->extratitle().empty() == false) {
title << " - " << m_Data->extratitle();
if (m_Data->extratitle().empty() == false) {
title << " - " << m_Data->extratitle();
}
}
return title.str();
}
......
......@@ -47,7 +47,7 @@ public:
*/
~OffScreenPlot1D();
virtual void save() throw (Error);
virtual void save(const std::string& imagepath) throw (Error);
private:
......
......@@ -31,7 +31,7 @@ namespace offscreen {
* constructor
*/
OffScreenPlot2D::OffScreenPlot2D(view::mpl::MplFigure* figure, const std::string& plotkey, view::mpl::Mpl* mpl,int32 index, buffer::Data* data) :
Plot2D(plotkey, mpl, nullptr), OffScreenPlot(figure, index, data) {
Plot2D(plotkey, mpl, nullptr, figure), OffScreenPlot(figure, index, data) {
}
/*
......@@ -61,9 +61,9 @@ void OffScreenPlot2D::display() throw (Error) {
/*
* save
*/
void OffScreenPlot2D::save() throw (Error) {
void OffScreenPlot2D::save(const std::string& imagepath) throw (Error) {
ostringstream filename;
filename << getenv("HOME") << "/offscreenImages/log/" << m_PlotKey;
filename << imagepath << "/" << m_PlotKey;
m_Mpl->savefig(m_Figure->getFigure(), filename.str());
}
......@@ -80,7 +80,9 @@ string OffScreenPlot2D::getTitle() {
title << m_PlotKey;
}
if (m_Data->has_extratitle() == true) {
title << " - " << m_Data->extratitle();
if (m_Data->extratitle().empty() == false) {
title << " - " << m_Data->extratitle();
}
}
return title.str();
}
......
......@@ -57,7 +57,7 @@ public:
* \brief Display plot
* \throws Error
*/
virtual void save() throw (Error);
virtual void save(const std::string& imagepath) throw (Error);
private:
......
......@@ -34,8 +34,8 @@ namespace property {
/*
* constructor
*/
PropertyPlot2D::PropertyPlot2D(const std::string& plotkey, PropertyPlotDataContainer* plotContainer, view::mpl::Mpl* mpl, PlotWindow* plotwindow) :
Plot2D(plotkey, mpl, plotwindow),
PropertyPlot2D::PropertyPlot2D(const std::string& plotkey, PropertyPlotDataContainer* plotContainer, view::mpl::Mpl* mpl, PlotWindow* plotwindow, view::mpl::MplFigure* figure) :
Plot2D(plotkey, mpl, plotwindow, figure),
PropertyPlot(plotContainer) {
}
......
......@@ -39,9 +39,10 @@ public:
* \param[in] plotContainer The property plot data info container
* \param[in] mpl The mpl object
* \param[in] plotwindow The plot window object which containing this plot
* \param[in] figure The mpl figure object
*/
PropertyPlot2D(const std::string& plotkey, datacontainer::PropertyPlotDataContainer* plotContainer, view::mpl::Mpl* mpl,
PlotWindow* plotwindow);
PlotWindow* plotwindow, view::mpl::MplFigure* figure);
/*!
* \brief destructor
......
......@@ -38,10 +38,9 @@ namespace mpl {
/*
* constructor
*/
MplPlot2D::MplPlot2D(Mpl* mpl) :
m_Mpl(mpl), m_CursorHorizontal(mpl), m_CursorVertical(mpl) {
MplPlot2D::MplPlot2D(Mpl* mpl, MplFigure* figure) :
m_Mpl(mpl), m_MplFigure(figure), m_CursorHorizontal(mpl), m_CursorVertical(mpl) {
MplLock lock;
m_MplFigure = nullptr;
try {
bp::object widgetsModule = bp::import(bp::str("matplotlib.colors"));
m_NormalNorm = widgetsModule.attr("Normalize")();
......@@ -63,8 +62,6 @@ MplPlot2D::~MplPlot2D() {
void MplPlot2D::subplots(plot::PlotWindow* plotwindow, int32 mainindice, int32 projxindice, int32 projyindice, int32 colorbarindice) throw (Error) {
MplLock lock;
m_MplFigure = plotwindow->getMplFigure();
// Main 2d plot
bp::dict kwargs;
m_MainAxis = m_Mpl->subplot(m_GridSpec[mainindice], kwargs);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment