Commit c7b1805e authored by Locatelli's avatar Locatelli
Browse files

Some integrations:

- Use only qt event
- Show x , y and z values
parent 56cc4af5
......@@ -46,7 +46,6 @@ PROTOBUF = \
protobuf/generated/NotificationMessages.pb.cc
DATACONT = \
datacontainer/DataPlotProperties.cpp \
datacontainer/PlotDataContainer.cpp \
datacontainer/PropertyPlotDataContainer.cpp \
datacontainer/UpdateContainer.cpp
......@@ -56,7 +55,6 @@ MPLCPP = \
view/mpl/MplFigure.cpp \
view/mpl/MplPlot1D.cpp \
view/mpl/MplPlot2D.cpp \
view/mpl/MplEventManager.cpp \
view/mpl/widgets/MplCursor.cpp \
view/mpl/widgets/MplLegend.cpp
......
This diff is collapsed.
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "DataPlotProperties.h"
#include "protobuf/generated/DataPlotMessages.pb.h"
namespace datacontainer {
DataPlotProperties::DataPlotProperties() :
plottypeId(0),
xId(0),
yId(0),
channelId(0),
sliceId(0) {
}
/*
* constructor
*/
DataPlotProperties::DataPlotProperties(const proto::DataPlotProperties& dataPlotProperties) :
plottypeId(dataPlotProperties.plottype_id()),
xId(dataPlotProperties.x_id()),
yId(dataPlotProperties.y_id()),
channelId(dataPlotProperties.channel_id()),
sliceId(dataPlotProperties.slice_id()),
maxXId(dataPlotProperties.max_x_id()),
maxYId(dataPlotProperties.max_y_id()),
maxChannelId(dataPlotProperties.max_channel_id()),
maxSliceId(dataPlotProperties.max_slice_id()) {
}
DataPlotProperties::~DataPlotProperties() {
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef PLOTDATAPROPERTIES_H
#define PLOTDATAPROPERTIES_H
#include <common/base/BaseTypes.h>
namespace proto {
class DataPlotProperties;
}
namespace datacontainer {
/*!
* \brief Contains properties id of data plot nomad server controller
*/
class DataPlotProperties {
public:
DataPlotProperties();
/*!
* \brief constructor
* \param[in] dataPlotProperties The plot message container for constructing this one
*/
DataPlotProperties(const proto::DataPlotProperties& dataPlotProperties);
/*!
* \brief destructor
*/
virtual ~DataPlotProperties();
int32 plottypeId; //! Plot type property Id
int32 xId; //! X number property id
int32 yId; //! Y number property id
int32 channelId; //! Channel number property Id
int32 sliceId; //! Slice number property Id
int32 maxXId; //! Maximum X number property Id
int32 maxYId; //! Maximum Y number property Id
int32 maxChannelId; //! Maximum Channel number property Id
int32 maxSliceId; //! Maximum Slice number property Id
};
}
#endif // PLOTDATAPROPERTIES_H
......@@ -60,8 +60,38 @@ PropertyPlotDataContainer::PropertyPlotDataContainer(const proto::PlotPropertyDa
dataZPropertyTypes[id] = ServerRequesterManager::getInstance()->getPropertyType(id);
}
}
for (float64 ratio : plotMessage.aspect_ratios()) {
aspectRatios.push_back(ratio);
for (float64 id : plotMessage.plottype_id()) {
plottypeId.push_back(id);
}
for (float64 id : plotMessage.x_id()) {
xId.push_back(id);
}
for (float64 id : plotMessage.y_id()) {
yId.push_back(id);
}
for (float64 id : plotMessage.channel_id()) {
channelId.push_back(id);
}
for (float64 id : plotMessage.slice_id()) {
sliceId.push_back(id);
}
for (float64 id : plotMessage.max_x_id()) {
maxXId.push_back(id);
}
for (float64 id : plotMessage.max_y_id()) {
maxYId.push_back(id);
}
for (float64 id : plotMessage.max_channel_id()) {
maxChannelId.push_back(id);
}
for (float64 id : plotMessage.max_slice_id()) {
maxSliceId.push_back(id);
}
for (float64 id : plotMessage.xphysical_size_id()) {
xPhysicalSizeIds.push_back(id);
}
for (float64 id : plotMessage.yphysical_size_id()) {
yPhysicalSizeIds.push_back(id);
}
for (bool errorbar: plotMessage.error_bars()) {
errorBars.push_back(errorbar);
......@@ -73,7 +103,6 @@ PropertyPlotDataContainer::PropertyPlotDataContainer(const proto::PlotPropertyDa
title = plotMessage.title();
xaxisTitle = plotMessage.xaxis_title();
yaxisTitle = plotMessage.yaxis_title();
dataPlotProperties = plotMessage.dataplotproperties();
for (int32 id : plotMessage.optimization_result_found_id()) {
if (id != 0) {
optimizationResultFoundId.push_back(id);
......
......@@ -21,7 +21,6 @@
#include <map>
#include "datacontainer/PlotDataContainer.h"
#include "DataPlotProperties.h"
namespace proto {
class PlotPropertyDataMessage;
......@@ -54,13 +53,22 @@ public:
std::map<int32, std::string> dataXPropertyTypes; //! Property types of data x
std::map<int32, std::string> dataYPropertyTypes; //! Property types of data y
std::map<int32, std::string> dataZPropertyTypes; //! Property types of data z
std::vector<float64> aspectRatios; //! X/Y Aspect ratio values
std::vector<int32> plottypeId; //! Plot type property Id
std::vector<int32> xId; //! X number property id
std::vector<int32> yId; //! Y number property id
std::vector<int32> channelId; //! Channel number property Id
std::vector<int32> sliceId; //! Slice number property Id
std::vector<int32> maxXId; //! Maximum X number property Id
std::vector<int32> maxYId; //! Maximum Y number property Id
std::vector<int32> maxChannelId; //! Maximum Channel number property Id
std::vector<int32> maxSliceId; //! Maximum Slice number property Id
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
DataPlotProperties dataPlotProperties; //! Container of properties id for data plot nomad controller
std::vector<int32> optimizationResultFoundId; //! Property id list for optimization result found
std::vector<int32> optimizationResultXId; //! Property id list for optimization result x
std::vector<std::string> optimizationResultColor; //! Color of optimization result
......
......@@ -190,7 +190,10 @@ void PlotManager::displayPropertyPlot(const proto::Message& message, const proto
///////////////////////////////////////////////////////////////////////////////////////
//// Start new mplplot process for displaying, pass info to process using temporary files
////
DBGMSG("plotMessage.plotkey() = " << plotMessage.plotkey()); DBGMSG("plotMessage.aspect_ratios_size() = " << plotMessage.aspect_ratios_size()); DBGMSG("plotMessage.datax_ids_size() = " << plotMessage.datax_ids_size()); DBGMSG("plotMessage.datay_ids_size() = " << plotMessage.datay_ids_size()); DBGMSG("plotMessage.dataz_ids_size() = " << plotMessage.dataz_ids_size());
DBGMSG("plotMessage.plotkey() = " << plotMessage.plotkey());
DBGMSG("plotMessage.datax_ids_size() = " << plotMessage.datax_ids_size());
DBGMSG("plotMessage.datay_ids_size() = " << plotMessage.datay_ids_size());
DBGMSG("plotMessage.dataz_ids_size() = " << plotMessage.dataz_ids_size());
string part1;
message.SerializeToString(&part1);
......
......@@ -87,4 +87,17 @@ void EmptyPlot::aspectRatio(bool state) throw (Error) {
// Does nothing
}
/*
* getLimits
*/
std::vector<float64> EmptyPlot::checkLimits(const std::pair<float64, float64>& coords) throw (Error) {
return vector<float64>{};
}
/*
* checkBoxLegend
*/
void EmptyPlot::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
}
}
......@@ -78,6 +78,32 @@ public:
*/
virtual void aspectRatio(bool state) throw (Error);
/*!
* \brief Check Limits on plot for actual mouse coordinates
* \param[in] coords The mouse coordinates
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) ;
/*!
* \brief Check mouse if in legend box
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) ;
/*!
* \brief Select currect axis plot which is over the mouse
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
}
};
}
......
......@@ -89,6 +89,30 @@ public:
*/
virtual void aspectRatio(bool state) throw (Error) = 0;
/*!
* \brief Check Limits on plot for actual mouse coordinates
* \param[in] coords The mouse coordinates
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) = 0;
/*!
* \brief Check mouse if in legend box
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) = 0;
/*!
* \brief Select currect axis plot which is over the mouse
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) = 0;
/*!
* \brief get Z data for 2d plot using x and y coordinates
* \param[in] axisname The axis name of coordinates
......
......@@ -280,4 +280,44 @@ void Plot1D::aspectRatio(bool state) throw (Error) {
// Does nothing for plot1d
}
/*
* getLimits
*/
std::vector<float64> Plot1D::checkLimits(const std::pair<float64, float64>& coords) throw (Error) {
try {
std::pair<float64, float64> xlims(m_MplPlot1D.get_xlim());
std::pair<float64, float64> ylims(m_MplPlot1D.get_ylim());
float64 coordx = coords.first;
float64 coordy = coords.second;
float64 finalx = std::nanf("");
float64 finaly = std::nanf("");
float64 finalz = std::nanf("");
if ((coordx < xlims.first) || (coordx > xlims.second) || (coordy < ylims.first) || (coordy > ylims.second)) {
// no data
}
else {
finalx = coordx;
finaly = coordy;
finalz = getZDataValue("", finalx, finaly);
}
return vector<float64>{finalx, finaly, finalz};
}
catch(Error& e) {
throw ("Plot1D", "checkLimits", "Failed to check limits of mouse coordinate in the plot axis");
}
}
/*
* checkBoxLegend
*/
void Plot1D::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
try {
m_MplPlot1D.checkBoxLegend(xmouse, ymouse);
}
catch(Error& e) {
throw ("Plot1D", "checkBoxLegend", "Failed to check if the mouse click was into the box legend");
}
}
}
......@@ -80,6 +80,32 @@ public:
*/
virtual void aspectRatio(bool state) throw (Error);
/*!
* \brief Check Limits on plot for actual mouse coordinates
* \param[in] coords The mouse coordinates
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) ;
/*!
* \brief Check mouse if in legend box
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) ;
/*!
* \brief Select currect axis plot which is over the mouse
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
}
protected:
/*!
......
......@@ -39,6 +39,8 @@ Plot2D::Plot2D(const std::string& plotkey, view::mpl::Mpl* mpl, PlotWindow* plot
Plot(plotkey, mpl, plotwindow), m_MplPlot2D(mpl) {
m_MinColorLim = 100.;
m_MaxColorLim = 100.;
m_XPhysicalSize = 1.;
m_YPhysicalSize = 1.;
}
/*
......@@ -282,4 +284,51 @@ void Plot2D::colorLimits(float64 min, float64 max) throw (Error) {
}
}
/*
* checkLimits
*/
std::vector<float64> Plot2D::checkLimits(const std::pair<float64, float64>& coords) throw (Error) {
try {
std::pair<float64, float64> xlims(m_MplPlot2D.get_xlim());
std::pair<float64, float64> ylims(m_MplPlot2D.get_ylim());
float64 coordx = coords.first;
float64 coordy = coords.second;
float64 finalx = std::nanf("");
float64 finaly = std::nanf("");
float64 finalz = std::nanf("");
if ((coordx < xlims.first) || (coordx > xlims.second) || (coordy < ylims.first) || (coordy > ylims.second)) {
// no data
}
else {
finalx = coordx;
finaly = coordy;
finalz = getZDataValue(m_CurrentAxis, coordx, coordy);
}
return vector<float64>{finalx, finaly, finalz};
}
catch(Error& e) {
throw ("Plot2D", "checkLimits", "Failed to check limits of mouse coordinate in the plot axis");
}
}
/*
* selectCurrentAxis
*/
void Plot2D::selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
try {
m_CurrentAxis = m_MplPlot2D.selectCurrentAxis(xmouse, ymouse);
} catch(Error& e) {
Error("Plot2D", "selectCurrentAxis", "Failed to set current axis");
}
}
/*
* checkBoxLegend
*/
void Plot2D::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
// Empty
}
}
......@@ -102,6 +102,30 @@ public:
*/
virtual float64 getZDataValue(const std::string& axisname, float64& x, float64& y) const throw (Error);
/*!
* \brief Check Limits on plot for actual mouse coordinates
* \param[in] coords The mouse coordinates
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) ;
/*!
* \brief Check mouse if in legend box
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) ;
/*!
* \brief Select currect axis plot which is over the mouse
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) ;
protected:
/*!
......@@ -153,6 +177,10 @@ protected:
float64 m_MinColorLim; // Minimum limit of color bar
float64 m_MaxColorLim; // Maximum limit of color bar
std::string m_CurrentAxis;
float64 m_XPhysicalSize; //
float64 m_YPhysicalSize; //
//! Ratio of spec grid constants
static const int32 PLOT2D_WIDTH_RATIO = 30;
static const int32 PROJY_WIDTH_RATIO = 3;
......
......@@ -86,4 +86,18 @@ void PlotHisto::aspectRatio(bool state) throw (Error) {
// Does nothing for histo plot
}
/*
* getLimits
*/
std::vector<float64> PlotHisto::checkLimits(const std::pair<float64, float64>& coords) throw (Error) {
vector<float64> buf;
return buf;
}
/*
* checkBoxLegend
*/
void PlotHisto::checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) {
}
}
......@@ -82,6 +82,32 @@ public:
*/
virtual void aspectRatio(bool state) throw (Error);
/*!
* \brief Check Limits on plot for actual mouse coordinates
* \param[in] coords The mouse coordinates
* \return The coordinates x y z in plot cordinates
* \throws Error
*/
virtual std::vector<float64> checkLimits(const std::pair<float64, float64>& coords) throw (Error) ;
/*!
* \brief Check mouse if in legend box
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void checkBoxLegend(float64 xmouse, float64 ymouse) throw (Error) ;
/*!
* \brief Select currect axis plot which is over the mouse
* \param[in] xmouse The x mouse coordinate
* \param[in] ymouse The y mouse coordinate
* \throws Error
*/
virtual void selectCurrentAxis(float64 xmouse, float64 ymouse) throw (Error) {
}
private:
/*!
......
......@@ -21,7 +21,6 @@
#include <boost/python/object.hpp>
#include "view/mpl/MplFigure.h"
#include "view/mpl/MplEventManager.h"
#include "view/qt/QtWindow.h"
#include "view/mpl/Mpl.h"
#include "view/Sip.h"
......@@ -53,7 +52,6 @@ PlotWindow::PlotWindow(view::mpl::Mpl* mpl, const proto::PlotPropertyDataMessage
*/
PlotWindow::~PlotWindow() {
delete m_PropertyPlotDataContainer;
view::mpl::MplEventManager::getInstance()->unsubscribeMotionNotifyEvent(m_MplFigure->getCanvas());
delete m_QtWindow;
delete m_MplFigure;
}
......@@ -70,8 +68,6 @@ void PlotWindow::create(QApplication& app, cameo::application::Subscriber* subsc
m_QtWindow = new view::qt::QtWindow(view::extract<QWidget>(m_MplFigure->getCanvas()), app, subscriber, this);
view::mpl::MplEventManager::getInstance()->subscribeMotionNotifyEvent(m_MplFigure->getCanvas(), this);
} catch (Error& e) {
throw Error("PlotWindow", "create", "Error creating figure");
}
......@@ -317,10 +313,30 @@ const string& PlotWindow::getColorMapName() const {
}
/*
* treatEvent
* toDataCoord
*/
void PlotWindow::treatEvent(std::string axisname, float64 x, float64 y) throw (Error) {
m_QtWindow->refreshStatusValues(x, y, m_Plot->getZDataValue(axisname, x, y));
vector<float64> PlotWindow::toDataCoord(float64 x, float64 y, int32 devicePixelRatio) throw (Error) {
try {
m_Plot->selectCurrentAxis(x, y);
std::pair<float64, float64> coords = m_MplFigure->toDataCoord(x, y, devicePixelRatio);
return m_Plot->checkLimits(coords);
}
catch(Error& e) {
throw Error("PlotWindow", "toDataCoord", "Error to get plot data coordinate for those mouse one");
}
}
/*
* checkLegendPick
*/
void PlotWindow::checkLegendPick(float64 x, float64 y) throw (Error) {
try {
float64 height = m_MplFigure->getHeight();
m_Plot->checkBoxLegend(x , height - y);
}
catch(...) {
throw Error("PlotWindow", "checkLegendPick", "Error checking legend pick");
}
}
}
......@@ -20,8 +20,9 @@
#define PLOTWINDOW_H
#include "Error.h"
#include <vector>
#include <boost/python/object.hpp>
#include "view/mpl/MplEventSubscriber.h"