Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
Ploty2
Commits
94da3c44
Commit
94da3c44
authored
Nov 26, 2019
by
Locatelli
Browse files
Create custom PythonObject for managing delete
parent
a7fdb7f2
Changes
18
Hide whitespace changes
Inline
Side-by-side
src/manager/mpl/MplEventManager.cpp
View file @
94da3c44
...
...
@@ -49,7 +49,7 @@ MplEventManager::MplEventManager() {
*/
MplEventManager
::~
MplEventManager
()
{
MplLock
lock
;
m_ModuleEvent
=
bp
::
objec
t
();
m_ModuleEvent
.
rese
t
();
}
/*
...
...
@@ -95,31 +95,31 @@ MplEventManager* MplEventManager::getInstance() {
/*
* subscriberXLimChanged
*/
void
MplEventManager
::
subscribeXLimChanged
(
bp
::
o
bject
*
obj
,
MplEventSubscriber
*
subscriber
)
throw
(
Error
)
{
void
MplEventManager
::
subscribeXLimChanged
(
const
view
::
mpl
::
PythonO
bject
&
obj
,
MplEventSubscriber
*
subscriber
)
throw
(
Error
)
{
MplLock
mpllock
;
unique_lock
<
recursive_mutex
>
lock
(
m_XLimChangedMutex
);
if
(
m_XLimChangedSubcribers
.
find
(
obj
)
==
m_XLimChangedSubcribers
.
end
())
{
if
(
m_XLimChangedSubcribers
.
find
(
&
obj
)
==
m_XLimChangedSubcribers
.
end
())
{
// Connect pick event
auto
args
=
bp
::
make_tuple
(
"xlim_changed"
,
m_ModuleEvent
.
attr
(
"xlim_changed"
));
uint32
eventid
=
bp
::
extract
<
uint32
>
(
obj
->
attr
(
"callbacks"
).
attr
(
"connect"
)(
*
args
));
uint32
eventid
=
bp
::
extract
<
uint32
>
(
obj
.
attr
(
"callbacks"
).
attr
(
"connect"
)(
*
args
));
// Add to map
m_XLimChangedSubcribers
[
obj
]
=
subscriber
;
m_XLimChanged
[
obj
]
=
eventid
;
m_XLimChangedSubcribers
[
&
obj
]
=
subscriber
;
m_XLimChanged
[
&
obj
]
=
eventid
;
}
}
/*
* unsubscriberXLimChanged
*/
void
MplEventManager
::
unsubscribeXLimChanged
(
bp
::
o
bject
*
obj
)
throw
(
Error
)
{
void
MplEventManager
::
unsubscribeXLimChanged
(
const
view
::
mpl
::
PythonO
bject
&
obj
)
throw
(
Error
)
{
MplLock
mpllock
;
unique_lock
<
recursive_mutex
>
lock
(
m_XLimChangedMutex
);
// remove subscriber from map
if
(
m_XLimChangedSubcribers
.
find
(
obj
)
!=
m_XLimChangedSubcribers
.
end
())
{
auto
args
=
bp
::
make_tuple
(
m_XLimChanged
[
obj
]);
obj
->
attr
(
"callbacks"
).
attr
(
"disconnect"
)(
*
args
);
m_XLimChangedSubcribers
.
erase
(
obj
);
m_XLimChanged
.
erase
(
obj
);
if
(
m_XLimChangedSubcribers
.
find
(
&
obj
)
!=
m_XLimChangedSubcribers
.
end
())
{
auto
args
=
bp
::
make_tuple
(
m_XLimChanged
[
&
obj
]);
obj
.
attr
(
"callbacks"
).
attr
(
"disconnect"
)(
*
args
);
m_XLimChangedSubcribers
.
erase
(
&
obj
);
m_XLimChanged
.
erase
(
&
obj
);
}
}
...
...
@@ -144,31 +144,31 @@ void MplEventManager::xlimChanged(PyObject *self, PyObject* event) {
/*
* subscriberYLimChanged
*/
void
MplEventManager
::
subscribeYLimChanged
(
bp
::
o
bject
*
obj
,
MplEventSubscriber
*
subscriber
)
throw
(
Error
)
{
void
MplEventManager
::
subscribeYLimChanged
(
const
view
::
mpl
::
PythonO
bject
&
obj
,
MplEventSubscriber
*
subscriber
)
throw
(
Error
)
{
MplLock
mpllock
;
unique_lock
<
recursive_mutex
>
lock
(
m_YLimChangedMutex
);
if
(
m_YLimChangedSubcribers
.
find
(
obj
)
==
m_YLimChangedSubcribers
.
end
())
{
if
(
m_YLimChangedSubcribers
.
find
(
&
obj
)
==
m_YLimChangedSubcribers
.
end
())
{
// Connect pick event
auto
args
=
bp
::
make_tuple
(
"ylim_changed"
,
m_ModuleEvent
.
attr
(
"ylim_changed"
));
int32
eventid
=
bp
::
extract
<
int32
>
(
obj
->
attr
(
"callbacks"
).
attr
(
"connect"
)(
*
args
));
int32
eventid
=
bp
::
extract
<
int32
>
(
obj
.
attr
(
"callbacks"
).
attr
(
"connect"
)(
*
args
));
// Add to map
m_YLimChangedSubcribers
[
obj
]
=
subscriber
;
m_YLimChanged
[
obj
]
=
eventid
;
m_YLimChangedSubcribers
[
&
obj
]
=
subscriber
;
m_YLimChanged
[
&
obj
]
=
eventid
;
}
}
/*
* unsubscriberYLimChanged
*/
void
MplEventManager
::
unsubscribeYLimChanged
(
bp
::
o
bject
*
obj
)
throw
(
Error
)
{
void
MplEventManager
::
unsubscribeYLimChanged
(
const
view
::
mpl
::
PythonO
bject
&
obj
)
throw
(
Error
)
{
MplLock
mpllock
;
unique_lock
<
recursive_mutex
>
lock
(
m_YLimChangedMutex
);
// remove subscriber from map
if
(
m_YLimChangedSubcribers
.
find
(
obj
)
!=
m_YLimChangedSubcribers
.
end
())
{
auto
args
=
bp
::
make_tuple
(
m_YLimChanged
[
obj
]);
obj
->
attr
(
"callbacks"
).
attr
(
"disconnect"
)(
*
args
);
m_YLimChangedSubcribers
.
erase
(
obj
);
m_YLimChanged
.
erase
(
obj
);
if
(
m_YLimChangedSubcribers
.
find
(
&
obj
)
!=
m_YLimChangedSubcribers
.
end
())
{
auto
args
=
bp
::
make_tuple
(
m_YLimChanged
[
&
obj
]);
obj
.
attr
(
"callbacks"
).
attr
(
"disconnect"
)(
*
args
);
m_YLimChangedSubcribers
.
erase
(
&
obj
);
m_YLimChanged
.
erase
(
&
obj
);
}
}
...
...
src/manager/mpl/MplEventManager.h
View file @
94da3c44
...
...
@@ -23,6 +23,7 @@
#include <map>
#include <mutex>
#include "view/mpl/Mpl.h"
#include "view/mpl/PythonObject.h"
#include "MplEventSubscriber.h"
#include "Trace.h"
...
...
@@ -63,13 +64,13 @@ public:
* \param[in] subscriber The subscriber for this event
* \throws Error
*/
void
subscribeXLimChanged
(
bp
::
o
bject
*
obj
,
MplEventSubscriber
*
subscriber
)
throw
(
Error
);
void
subscribeXLimChanged
(
const
view
::
mpl
::
PythonO
bject
&
obj
,
MplEventSubscriber
*
subscriber
)
throw
(
Error
);
/*!
* \brief Unsubscribe to a xlim changed event
* \param[in] obj Python Object reference
*/
void
unsubscribeXLimChanged
(
bp
::
o
bject
*
obj
)
throw
(
Error
);
void
unsubscribeXLimChanged
(
const
view
::
mpl
::
PythonO
bject
&
obj
)
throw
(
Error
);
/*!
* \brief Subscribe to a xlim changed event
...
...
@@ -98,13 +99,13 @@ public:
* \param[in] subscriber The subscriber for this event
* \throws Error
*/
void
subscribeYLimChanged
(
bp
::
o
bject
*
obj
,
MplEventSubscriber
*
subscriber
)
throw
(
Error
);
void
subscribeYLimChanged
(
const
view
::
mpl
::
PythonO
bject
&
obj
,
MplEventSubscriber
*
subscriber
)
throw
(
Error
);
/*!
* \brief Unsubscribe to a ylim changed event
* \param[in] obj Python Object reference
*/
void
unsubscribeYLimChanged
(
bp
::
o
bject
*
obj
)
throw
(
Error
);
void
unsubscribeYLimChanged
(
const
view
::
mpl
::
PythonO
bject
&
obj
)
throw
(
Error
);
/*!
* \brief Subscribe to a ylim changed event
...
...
@@ -148,16 +149,16 @@ private:
std
::
shared_ptr
<
view
::
mpl
::
Mpl
>
m_mpl
;
//! Mpl object (python matplotlib)
bp
::
o
bject
m_ModuleEvent
;
// Custom Ploty2 module for getting mpl gui event
view
::
mpl
::
PythonO
bject
m_ModuleEvent
;
// Custom Ploty2 module for getting mpl gui event
bool
m_BypassXLimChanged
;
//! By pass xlim changed event flag
std
::
map
<
bp
::
o
bject
*
,
MplEventSubscriber
*>
m_XLimChangedSubcribers
;
//! Map of xlim changed event subscriber
std
::
map
<
bp
::
o
bject
*
,
int32
>
m_XLimChanged
;
//! Map of xlim changed event subscriber
std
::
map
<
const
view
::
mpl
::
PythonO
bject
*
,
MplEventSubscriber
*>
m_XLimChangedSubcribers
;
//! Map of xlim changed event subscriber
std
::
map
<
const
view
::
mpl
::
PythonO
bject
*
,
int32
>
m_XLimChanged
;
//! Map of xlim changed event subscriber
std
::
recursive_mutex
m_XLimChangedMutex
;
//! Mutex on the PickEvent Subcribers
bool
m_BypassYLimChanged
;
//! By pass ylim changed event flag
std
::
map
<
bp
::
o
bject
*
,
MplEventSubscriber
*>
m_YLimChangedSubcribers
;
//! Map of ylim changed event subscriber
std
::
map
<
bp
::
o
bject
*
,
int32
>
m_YLimChanged
;
//! Map of ylim changed event subscriber
std
::
map
<
const
view
::
mpl
::
PythonO
bject
*
,
MplEventSubscriber
*>
m_YLimChangedSubcribers
;
//! Map of ylim changed event subscriber
std
::
map
<
const
view
::
mpl
::
PythonO
bject
*
,
int32
>
m_YLimChanged
;
//! Map of ylim changed event subscriber
std
::
recursive_mutex
m_YLimChangedMutex
;
//! Mutex on the PickEvent Subcribers
};
...
...
src/plot/Plot2D.cpp
View file @
94da3c44
...
...
@@ -52,8 +52,8 @@ Plot2D::Plot2D(const std::string& plotkey, view::mpl::Mpl& mpl, PlotWindow* plot
Plot2D
::~
Plot2D
()
{
if
(
m_PlotWindow
!=
nullptr
)
{
// Unsubscribe limits changed events
manager
::
mpl
::
MplEventManager
::
getInstance
()
->
unsubscribeXLimChanged
(
&
m_MplPlot2D
.
getMainAxis
());
manager
::
mpl
::
MplEventManager
::
getInstance
()
->
unsubscribeYLimChanged
(
&
m_MplPlot2D
.
getMainAxis
());
manager
::
mpl
::
MplEventManager
::
getInstance
()
->
unsubscribeXLimChanged
(
m_MplPlot2D
.
getMainAxis
());
manager
::
mpl
::
MplEventManager
::
getInstance
()
->
unsubscribeYLimChanged
(
m_MplPlot2D
.
getMainAxis
());
}
}
...
...
@@ -204,8 +204,8 @@ void Plot2D::display() throw (Error) {
}
// Subscribe for event manager
manager
::
mpl
::
MplEventManager
::
getInstance
()
->
subscribeXLimChanged
(
&
m_MplPlot2D
.
getMainAxis
(),
this
);
manager
::
mpl
::
MplEventManager
::
getInstance
()
->
subscribeYLimChanged
(
&
m_MplPlot2D
.
getMainAxis
(),
this
);
manager
::
mpl
::
MplEventManager
::
getInstance
()
->
subscribeXLimChanged
(
m_MplPlot2D
.
getMainAxis
(),
this
);
manager
::
mpl
::
MplEventManager
::
getInstance
()
->
subscribeYLimChanged
(
m_MplPlot2D
.
getMainAxis
(),
this
);
}
///////////////////////////////////////////////////////////////////////////////////////
...
...
src/plot/PlotWindow.cpp
View file @
94da3c44
...
...
@@ -67,7 +67,7 @@ void PlotWindow::create(QApplication& app, std::shared_ptr<cameo::application::S
try
{
m_MplFigure
=
make_unique
<
view
::
mpl
::
MplFigure
>
(
*
m_Mpl
,
true
);
m_QtWindow
=
make_unique
<
view
::
qt
::
QtWindow
>
(
view
::
extract
<
QWidget
>
(
m_MplFigure
->
getCanvas
()),
app
,
subscriber
);
m_QtWindow
=
make_unique
<
view
::
qt
::
QtWindow
>
(
view
::
extract
<
QWidget
>
(
m_MplFigure
->
getCanvas
()
()
),
app
,
subscriber
);
manager
::
InterfaceManager
::
getInstance
()
->
init
(
m_QtWindow
.
get
());
...
...
src/view/mpl/Mpl.cpp
View file @
94da3c44
...
...
@@ -60,7 +60,7 @@ Mpl::Mpl() throw (Error) {
PyEval_InitThreads
();
// Import the matplotlib module
bp
::
o
bject
matplotlib
;
PythonO
bject
matplotlib
;
try
{
matplotlib
=
bp
::
import
(
bp
::
str
(
"matplotlib"
));
}
catch
(...)
{
...
...
@@ -105,7 +105,7 @@ Mpl::Mpl() throw (Error) {
}
try
{
bp
::
o
bject
widgetsModule
=
bp
::
import
(
bp
::
str
(
"matplotlib.colors"
));
PythonO
bject
widgetsModule
=
bp
::
import
(
bp
::
str
(
"matplotlib.colors"
));
m_NormalNorm
=
widgetsModule
.
attr
(
"Normalize"
)();
m_LogNorm
=
widgetsModule
.
attr
(
"LogNorm"
)();
}
catch
(...)
{
...
...
@@ -151,16 +151,16 @@ Mpl::Mpl() throw (Error) {
*/
Mpl
::~
Mpl
()
{
{
m_PyPlot
=
bp
::
objec
t
();
m_FigureModule
=
bp
::
objec
t
();
m_LinesModule
=
bp
::
objec
t
();
m_TextModule
=
bp
::
objec
t
();
m_NormalNorm
=
bp
::
objec
t
();
m_LogNorm
=
bp
::
objec
t
();
m_BackendsModule
=
bp
::
objec
t
();
m_WidgetsModule
=
bp
::
objec
t
();
m_PatchesModule
=
bp
::
objec
t
();
m_GarbageCollector
=
bp
::
objec
t
();
m_PyPlot
.
rese
t
();
m_FigureModule
.
rese
t
();
m_LinesModule
.
rese
t
();
m_TextModule
.
rese
t
();
m_NormalNorm
.
rese
t
();
m_LogNorm
.
rese
t
();
m_BackendsModule
.
rese
t
();
m_WidgetsModule
.
rese
t
();
m_PatchesModule
.
rese
t
();
m_GarbageCollector
.
rese
t
();
}
Py_Finalize
();
}
...
...
@@ -168,7 +168,7 @@ Mpl::~Mpl() {
/*
* close
*/
void
Mpl
::
close
(
const
bp
::
o
bject
&
figure
)
throw
(
Error
)
{
void
Mpl
::
close
(
const
PythonO
bject
&
figure
)
throw
(
Error
)
{
MplLock
lock
;
// Create matplotlib figure object
...
...
@@ -194,10 +194,10 @@ void Mpl::garbageCollect() throw (Error) {
/*
* xlabel
*/
void
Mpl
::
xlabel
(
const
bp
::
o
bject
&
axis
,
const
std
::
string
&
name
)
throw
(
Error
)
{
void
Mpl
::
xlabel
(
const
PythonO
bject
&
axis
,
const
std
::
string
&
name
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
try
{
bp
::
call_method
<
void
,
const
char
*>
(
axis
.
ptr
(),
"set_xlabel"
,
name
.
c_str
());
bp
::
call_method
<
void
,
const
char
*>
(
axis
()
.
ptr
(),
"set_xlabel"
,
name
.
c_str
());
}
catch
(...)
{
throw
Error
(
"Mpl"
,
"xlabel"
,
"Error when executing xlabel method"
);
}
...
...
@@ -206,10 +206,10 @@ void Mpl::xlabel(const bp::object& axis, const std::string& name) throw (Error)
/*
* ylabel
*/
void
Mpl
::
ylabel
(
const
bp
::
o
bject
&
axis
,
const
std
::
string
&
name
)
throw
(
Error
)
{
void
Mpl
::
ylabel
(
const
PythonO
bject
&
axis
,
const
std
::
string
&
name
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
try
{
bp
::
call_method
<
void
,
const
char
*>
(
axis
.
ptr
(),
"set_ylabel"
,
name
.
c_str
());
bp
::
call_method
<
void
,
const
char
*>
(
axis
()
.
ptr
(),
"set_ylabel"
,
name
.
c_str
());
}
catch
(...)
{
throw
Error
(
"Mpl"
,
"ylabel"
,
"Error when executing ylabel method"
);
}
...
...
@@ -218,7 +218,7 @@ void Mpl::ylabel(const bp::object& axis, const std::string& name) throw (Error)
/*
* grid
*/
void
Mpl
::
grid
(
const
bp
::
o
bject
&
axis
,
bool
show
)
throw
(
Error
)
{
void
Mpl
::
grid
(
const
PythonO
bject
&
axis
,
bool
show
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
bp
::
tuple
args
;
if
(
show
==
true
)
{
...
...
@@ -237,7 +237,7 @@ void Mpl::grid(const bp::object& axis, bool show) throw (Error) {
/*
* savefig
*/
void
Mpl
::
savefig
(
const
bp
::
o
bject
&
figure
,
const
std
::
string
&
filename
,
uint32
dpi
,
float64
pad
)
throw
(
Error
)
{
void
Mpl
::
savefig
(
const
PythonO
bject
&
figure
,
const
std
::
string
&
filename
,
uint32
dpi
,
float64
pad
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
auto
args
=
bp
::
make_tuple
(
filename
);
bp
::
dict
kwargs
;
...
...
@@ -257,7 +257,7 @@ void Mpl::savefig(const bp::object& figure, const std::string& filename, uint32
/*
* get_xlim
*/
std
::
pair
<
float64
,
float64
>
Mpl
::
get_xlim
(
const
bp
::
o
bject
&
axis
)
throw
(
Error
)
{
std
::
pair
<
float64
,
float64
>
Mpl
::
get_xlim
(
const
PythonO
bject
&
axis
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
try
{
bp
::
tuple
res
(
axis
.
attr
(
"get_xlim"
)());
...
...
@@ -272,10 +272,10 @@ std::pair<float64, float64> Mpl::get_xlim(const bp::object& axis) throw (Error)
/*
* get_ylim
*/
std
::
pair
<
float64
,
float64
>
Mpl
::
get_ylim
(
const
bp
::
o
bject
&
axis
)
throw
(
Error
)
{
std
::
pair
<
float64
,
float64
>
Mpl
::
get_ylim
(
const
PythonO
bject
&
axis
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
try
{
bp
::
object
res
=
axis
.
attr
(
"get_ylim"
)();
bp
::
tuple
res
(
axis
.
attr
(
"get_ylim"
)()
)
;
float64
min
=
bp
::
extract
<
float64
>
(
res
[
0
]);
float64
max
=
bp
::
extract
<
float64
>
(
res
[
1
]);
return
std
::
make_pair
(
min
,
max
);
...
...
@@ -287,7 +287,7 @@ std::pair<float64, float64> Mpl::get_ylim(const bp::object& axis) throw (Error)
/*
* set_xdata
*/
void
Mpl
::
set_xdata
(
const
bp
::
o
bject
&
line
,
const
std
::
vector
<
float64
>
&
x
)
throw
(
Error
)
{
void
Mpl
::
set_xdata
(
const
PythonO
bject
&
line
,
const
std
::
vector
<
float64
>
&
x
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
// using numpy arrays
boost
::
python
::
list
xarray
;
...
...
@@ -309,7 +309,7 @@ void Mpl::set_xdata(const bp::object& line, const std::vector<float64> &x) throw
/*
* set_ydata
*/
void
Mpl
::
set_ydata
(
const
bp
::
o
bject
&
line
,
const
std
::
vector
<
float64
>
&
y
)
throw
(
Error
)
{
void
Mpl
::
set_ydata
(
const
PythonO
bject
&
line
,
const
std
::
vector
<
float64
>
&
y
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
// using numpy arrays
boost
::
python
::
list
yarray
;
...
...
@@ -330,7 +330,7 @@ void Mpl::set_ydata(const bp::object& line, const std::vector<float64> &y) throw
/*
* set_xlim
*/
void
Mpl
::
set_xlim
(
const
bp
::
o
bject
&
axis
,
float64
min
,
float64
max
,
float64
marge
)
throw
(
Error
)
{
void
Mpl
::
set_xlim
(
const
PythonO
bject
&
axis
,
float64
min
,
float64
max
,
float64
marge
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
float64
tot
=
max
-
min
;
min
-=
tot
*
marge
;
...
...
@@ -347,7 +347,7 @@ void Mpl::set_xlim(const bp::object& axis, float64 min, float64 max, float64 mar
/*
* set_ylim
*/
void
Mpl
::
set_ylim
(
const
bp
::
o
bject
&
axis
,
float64
min
,
float64
max
,
float64
marge
)
throw
(
Error
)
{
void
Mpl
::
set_ylim
(
const
PythonO
bject
&
axis
,
float64
min
,
float64
max
,
float64
marge
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
float64
tot
=
max
-
min
;
min
-=
tot
*
marge
;
...
...
src/view/mpl/Mpl.h
View file @
94da3c44
...
...
@@ -25,6 +25,7 @@
#include <vector>
#include "Error.h"
#include "Trace.h"
#include "PythonObject.h"
namespace
bp
=
boost
::
python
;
...
...
@@ -52,7 +53,7 @@ public:
* \brief close plot window (figure and a set of subplots)
* \throws Error
*/
void
close
(
const
bp
::
o
bject
&
figure
)
throw
(
Error
);
void
close
(
const
PythonO
bject
&
figure
)
throw
(
Error
);
/*!
* \brief close plot window (figure and a set of subplots)
...
...
@@ -66,7 +67,7 @@ public:
* \param[in] name the label
* \throws Error
*/
void
xlabel
(
const
bp
::
o
bject
&
axis
,
const
std
::
string
&
name
)
throw
(
Error
);
void
xlabel
(
const
PythonO
bject
&
axis
,
const
std
::
string
&
name
)
throw
(
Error
);
/*!
* \brief set title of the y label
...
...
@@ -74,7 +75,7 @@ public:
* \param[in] name the label
* \throws Error
*/
void
ylabel
(
const
bp
::
o
bject
&
axis
,
const
std
::
string
&
name
)
throw
(
Error
);
void
ylabel
(
const
PythonO
bject
&
axis
,
const
std
::
string
&
name
)
throw
(
Error
);
/*!
* \brief refresh x data of the plot
...
...
@@ -82,7 +83,7 @@ public:
* \param[in] x data
* \throws Error
*/
void
set_xdata
(
const
bp
::
o
bject
&
line
,
const
std
::
vector
<
float64
>
&
x
)
throw
(
Error
);
void
set_xdata
(
const
PythonO
bject
&
line
,
const
std
::
vector
<
float64
>
&
x
)
throw
(
Error
);
/*!
* \brief refresh y data of the plot
...
...
@@ -90,7 +91,7 @@ public:
* \param[in] y data
* \throws Error
*/
void
set_ydata
(
const
bp
::
o
bject
&
line
,
const
std
::
vector
<
float64
>
&
y
)
throw
(
Error
);
void
set_ydata
(
const
PythonO
bject
&
line
,
const
std
::
vector
<
float64
>
&
y
)
throw
(
Error
);
/*!
* \brief refresh x limit of the plot
...
...
@@ -98,7 +99,7 @@ public:
* \param[in] max the maximum value
* \throws Error
*/
void
set_xlim
(
const
bp
::
o
bject
&
axis
,
float64
min
,
float64
max
,
float64
marge
)
throw
(
Error
);
void
set_xlim
(
const
PythonO
bject
&
axis
,
float64
min
,
float64
max
,
float64
marge
)
throw
(
Error
);
/*!
* \brief refresh y limit of the plot
...
...
@@ -108,7 +109,7 @@ public:
* \param[in] marge the +/- purcent to set out out those limites
* \throws Error
*/
void
set_ylim
(
const
bp
::
o
bject
&
axis
,
float64
min
,
float64
max
,
float64
marge
)
throw
(
Error
);
void
set_ylim
(
const
PythonO
bject
&
axis
,
float64
min
,
float64
max
,
float64
marge
)
throw
(
Error
);
/*!
* \brief Get the actual X limits
...
...
@@ -116,7 +117,7 @@ public:
* \return The Limits
* \throws Error
*/
std
::
pair
<
float64
,
float64
>
get_xlim
(
const
bp
::
o
bject
&
axis
)
throw
(
Error
);
std
::
pair
<
float64
,
float64
>
get_xlim
(
const
PythonO
bject
&
axis
)
throw
(
Error
);
/*!
* \brief Get the actual Y limits
...
...
@@ -124,7 +125,7 @@ public:
* \return The Limits
* \throws Error
*/
std
::
pair
<
float64
,
float64
>
get_ylim
(
const
bp
::
o
bject
&
axis
)
throw
(
Error
);
std
::
pair
<
float64
,
float64
>
get_ylim
(
const
PythonO
bject
&
axis
)
throw
(
Error
);
/*!
* \brief show the plot grid
...
...
@@ -132,7 +133,7 @@ public:
* \param[in] show the state of grid
* \throws Error
*/
void
grid
(
const
bp
::
o
bject
&
axis
,
bool
show
)
throw
(
Error
);
void
grid
(
const
PythonO
bject
&
axis
,
bool
show
)
throw
(
Error
);
/*!
* \brief Save png image on the disk
...
...
@@ -142,21 +143,21 @@ public:
* \param[in] pad The padding around the edge of each axes
* \throws Error
*/
void
savefig
(
const
bp
::
o
bject
&
figure
,
const
std
::
string
&
filename
,
uint32
dpi
,
float64
pad
)
throw
(
Error
);
void
savefig
(
const
PythonO
bject
&
figure
,
const
std
::
string
&
filename
,
uint32
dpi
,
float64
pad
)
throw
(
Error
);
/*!
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getPyPlot
()
{
return
m_PyPlot
;
}
//
/*!
//
* \brief getter
//
* \return Matplotlib pyplot Python module object
//
*/
//
const
PythonO
bject& getPyPlot() {
//
return m_PyPlot
()
;
//
}
/*!
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getLinesModule
()
{
const
PythonO
bject
&
getLinesModule
()
const
{
return
m_LinesModule
;
}
...
...
@@ -164,7 +165,7 @@ public:
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getFigureModule
()
{
const
PythonO
bject
&
getFigureModule
()
const
{
return
m_FigureModule
;
}
...
...
@@ -172,7 +173,7 @@ public:
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getTextModule
()
{
const
PythonO
bject
&
getTextModule
()
const
{
return
m_TextModule
;
}
...
...
@@ -180,7 +181,7 @@ public:
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getNormalNorm
()
{
const
PythonO
bject
&
getNormalNorm
()
const
{
return
m_NormalNorm
;
}
...
...
@@ -188,7 +189,7 @@ public:
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getLogNorm
()
{
const
PythonO
bject
&
getLogNorm
()
const
{
return
m_LogNorm
;
}
...
...
@@ -196,7 +197,7 @@ public:
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getBackendsModule
()
{
const
PythonO
bject
&
getBackendsModule
()
const
{
return
m_BackendsModule
;
}
...
...
@@ -204,7 +205,7 @@ public:
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getWidgetsModule
()
{
const
PythonO
bject
&
getWidgetsModule
()
const
{
return
m_WidgetsModule
;
}
...
...
@@ -212,7 +213,7 @@ public:
* \brief getter
* \return Matplotlib pyplot Python module object
*/
const
bp
::
o
bject
&
getPatchesModule
()
{
const
PythonO
bject
&
getPatchesModule
()
const
{
return
m_PatchesModule
;
}
...
...
@@ -223,16 +224,16 @@ public:
private:
bp
::
o
bject
m_PyPlot
;
//! Matplotlib pyplot Python module object
bp
::
o
bject
m_FigureModule
;
//! Matplotlib figure module
bp
::
o
bject
m_LinesModule
;
//! Matplotlib lines module
bp
::
o
bject
m_TextModule
;
//! Matplotlib text module
bp
::
o
bject
m_NormalNorm
;
//! Normal normalization object
bp
::
o
bject
m_LogNorm
;
//! Log normalization object
bp
::
o
bject
m_BackendsModule
;
//! Matplotlib Backends module
bp
::
o
bject
m_WidgetsModule
;
//! Matplotlib widgets module
bp
::
o
bject
m_PatchesModule
;
//! Matplotlib patches module
bp
::
o
bject
m_GarbageCollector
;
//! Garbage collector module
PythonO
bject
m_PyPlot
;
//! Matplotlib pyplot Python module object
PythonO
bject
m_FigureModule
;
//! Matplotlib figure module
PythonO
bject
m_LinesModule
;
//! Matplotlib lines module
PythonO
bject
m_TextModule
;
//! Matplotlib text module
PythonO
bject
m_NormalNorm
;
//! Normal normalization object
PythonO
bject
m_LogNorm
;
//! Log normalization object
PythonO
bject
m_BackendsModule
;
//! Matplotlib Backends module
PythonO
bject
m_WidgetsModule
;
//! Matplotlib widgets module
PythonO
bject
m_PatchesModule
;
//! Matplotlib patches module
PythonO
bject
m_GarbageCollector
;
//! Garbage collector module
};
...
...
src/view/mpl/MplFigure.cpp
View file @
94da3c44
...
...
@@ -49,10 +49,10 @@ MplFigure::MplFigure(Mpl& mpl, bool usetoolbar) : m_Mpl(mpl) {
// Get matplotlib BackEnd for qt5
try
{
m_Canvas
=
mpl
.
getBackendsModule
().
attr
(
"FigureCanvas"
)(
m_Figure
);
bp
::
o
bject
parent
;
m_Canvas
=
mpl
.
getBackendsModule
().
attr
(
"FigureCanvas"
)(
m_Figure
()
);
PythonO
bject
parent
;
if
(
usetoolbar
==
true
)
{
auto
args
=
bp
::
make_tuple
(
m_Canvas
,
parent
,
false
);
auto
args
=
bp
::
make_tuple
(
m_Canvas
()
,
parent
()
,
false
);
m_Toolbar
=
mpl
.
getBackendsModule
().
attr
(
"NavigationToolbar2QT"
)(
*
args
);
}
}
catch
(...)
{
...
...
@@ -72,9 +72,9 @@ MplFigure::~MplFigure() {
}
m_Figure
=
bp
::
object
();
m_Canvas
=
bp
::
object
();
m_Toolbar
=
bp
::
object
();
m_Figure
.
reset
();
m_Canvas
.
reset
();
m_Toolbar
.
reset
();
try
{
m_Mpl
.
garbageCollect
();
...
...
@@ -91,7 +91,7 @@ void MplFigure::title(const std::string& name) throw (Error) {
MplLock
lock
;
try
{
bp
::
call_method
<
void
,
const
char
*>
(
m_Figure
.
ptr
(),
"suptitle"
,
name
.
c_str
());
bp
::
call_method
<
void
,
const
char
*>
(
m_Figure
()
.
ptr
(),
"suptitle"
,
name
.
c_str
());
}
catch
(...)
{
throw
Error
(
"MplFigure"
,
"title"
,
"Error when executing set_title method"
);
}
...
...
@@ -100,7 +100,7 @@ void MplFigure::title(const std::string& name) throw (Error) {
/*
* gridSpec
*/
boost
::
p
ython
::
o
bject
MplFigure
::
gridSpec
(
int32
nrows
,
int32
ncols
,
const
std
::
vector
<
int32
>&
height_ratios
,
P
ython
O
bject
MplFigure
::
gridSpec
(
int32
nrows
,
int32
ncols
,
const
std
::
vector
<
int32
>&
height_ratios
,
const
std
::
vector
<
int32
>&
width_ratios
,
float64
wspace
,
float64
hspace
)
throw
(
Error
)
{
mpl
::
MplLock
lock
;
...
...
@@ -122,7 +122,7 @@ boost::python::object MplFigure::gridSpec(int32 nrows, int32 ncols, const std::v
}
kwargs
[
"wspace"
]
=
wspace
;
kwargs
[
"hspace"
]
=
hspace
;
bp
::
o
bject
gs
;
PythonO
bject
gs
;
try
{
gs
=
m_Figure
.
attr
(
"add_gridspec"
)(
*
args
,
**
kwargs
);
}
catch
(...)
{
...
...
@@ -134,10 +134,10 @@ boost::python::object MplFigure::gridSpec(int32 nrows, int32 ncols, const std::v
/*