Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sugu/vimba
1 result
Show changes
Commits on Source (1)
Showing
with 174 additions and 113 deletions
......@@ -105,6 +105,7 @@ extern "C" {
//
typedef enum VmbErrorType
{
VmbErrorNothing = 27, // No error. No Success. Nothing really!
VmbErrorSuccess = 0, // No error
VmbErrorInternalFault = -1, // Unexpected fault in VimbaC or driver
VmbErrorApiNotStarted = -2, // VmbStartup() was not called before the current command
......
......@@ -313,6 +313,9 @@ VmbErrorType ApiController::QueueFrame( FramePtr pFrame )
QObject* ApiController::GetCameraObserver()
{
return SP_DYN_CAST( m_pCameraObserver, CameraObserver ).get();
// so same as
// return SP_ACCESS(SP_DYN_CAST( m_pCameraObserver, CameraObserver );
// ??
}
//
......
......@@ -40,6 +40,8 @@ namespace AVT {
namespace VmbAPI {
namespace Examples {
//Why VIRTUAL inheritance?? https://www.sandordargo.com/blog/2020/12/23/virtual-inheritance
class FrameObserver : public QObject, virtual public IFrameObserver
{
Q_OBJECT
......
......@@ -255,7 +255,7 @@ class OpenCVRecorder: public QThread
// Details: main thread processing function that will run while the object is alife.
//
//
void run()
void run() override
{
while( ! m_StopThread )
{
......
......@@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_MainWindow_t {
const uint offsetsAndSize[14];
char stringdata0[55];
const uint offsetsAndSize[16];
char stringdata0[65];
};
#define QT_MOC_LITERAL(ofs, len) \
uint(offsetof(qt_meta_stringdata_MainWindow_t, stringdata0) + ofs), len
......@@ -35,11 +35,12 @@ QT_MOC_LITERAL(15, 0), // ""
QT_MOC_LITERAL(16, 10), // "VmbError_t"
QT_MOC_LITERAL(27, 3), // "err"
QT_MOC_LITERAL(31, 10), // "updateCams"
QT_MOC_LITERAL(42, 12) // "opencloseCam"
QT_MOC_LITERAL(42, 12), // "openCloseCam"
QT_MOC_LITERAL(55, 9) // "selectCam"
},
"MainWindow\0log\0\0VmbError_t\0err\0"
"updateCams\0opencloseCam"
"updateCams\0openCloseCam\0selectCam"
};
#undef QT_MOC_LITERAL
......@@ -49,7 +50,7 @@ static const uint qt_meta_data_MainWindow[] = {
10, // revision
0, // classname
0, 0, // classinfo
4, 14, // methods
5, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
......@@ -57,15 +58,17 @@ static const uint qt_meta_data_MainWindow[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags, initial metatype offsets
1, 2, 38, 2, 0x0a, 1 /* Public */,
1, 1, 43, 2, 0x2a, 4 /* Public | MethodCloned */,
5, 0, 46, 2, 0x08, 6 /* Private */,
6, 2, 47, 2, 0x08, 7 /* Private */,
1, 2, 44, 2, 0x0a, 1 /* Public */,
1, 1, 49, 2, 0x2a, 4 /* Public | MethodCloned */,
5, 0, 52, 2, 0x08, 6 /* Private */,
6, 0, 53, 2, 0x08, 7 /* Private */,
7, 2, 54, 2, 0x08, 8 /* Private */,
// slots: parameters
QMetaType::Void, QMetaType::QString, 0x80000000 | 3, 2, 4,
QMetaType::Void, QMetaType::QString, 2,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void, QMetaType::Int, QMetaType::Int, 2, 2,
0 // eod
......@@ -80,7 +83,8 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
case 0: _t->log((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1])),(*reinterpret_cast< std::add_pointer_t<VmbError_t>>(_a[2]))); break;
case 1: _t->log((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1]))); break;
case 2: _t->updateCams(); break;
case 3: _t->opencloseCam((*reinterpret_cast< std::add_pointer_t<int>>(_a[1])),(*reinterpret_cast< std::add_pointer_t<int>>(_a[2]))); break;
case 3: _t->openCloseCam(); break;
case 4: _t->selectCam((*reinterpret_cast< std::add_pointer_t<int>>(_a[1])),(*reinterpret_cast< std::add_pointer_t<int>>(_a[2]))); break;
default: ;
}
}
......@@ -94,7 +98,7 @@ const QMetaObject MainWindow::staticMetaObject = { {
nullptr,
qt_incomplete_metaTypeArray<qt_meta_stringdata_MainWindow_t
, QtPrivate::TypeAndForceComplete<MainWindow, std::true_type>
, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<QString, std::false_type>, QtPrivate::TypeAndForceComplete<VmbError_t, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<QString, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<int, std::false_type>, QtPrivate::TypeAndForceComplete<int, std::false_type>
, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<QString, std::false_type>, QtPrivate::TypeAndForceComplete<VmbError_t, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<QString, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<int, std::false_type>, QtPrivate::TypeAndForceComplete<int, std::false_type>
>,
......@@ -121,13 +125,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 4)
if (_id < 5)
qt_static_metacall(this, _c, _id, _a);
_id -= 4;
_id -= 5;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 4)
if (_id < 5)
*reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
_id -= 4;
_id -= 5;
}
return _id;
}
......
......@@ -15,11 +15,17 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, sys(VimbaSystem::GetInstance()) // Create and get Vimba singleton
, curCam(CameraPtr())
, cameras(CameraPtrVector())
, camInfoNames({"name","model","id","serial","interface","state"})
{
ui->setupUi(this);
ui->tw_cams->setColumnCount(camInfoNames.size());
ui->tw_cams->setHorizontalHeaderLabels(camInfoNames);
QObject::connect(ui->b_update, SIGNAL(clicked()), this, SLOT(updateCams()));
QObject::connect(ui->tw_cams, SIGNAL(cellClicked(int,int)), this, SLOT(openCloseCam(int,int)));
QObject::connect(ui->b_openclose, SIGNAL(clicked()), this, SLOT(openCloseCam()));
QObject::connect(ui->tw_cams, SIGNAL(cellClicked(int,int)), this, SLOT(selectCam(int,int)));
log(getVersionString());
......@@ -57,45 +63,56 @@ void MainWindow::keyPressEvent(QKeyEvent *e)
return QWidget::keyPressEvent(e);
}
void MainWindow::opencloseCam(int row,int col)
void MainWindow::selectCam(int row,int )
{
log(QString("%1,%2").arg(row).arg(col));
auto cam = cameras.at(row);
auto item = ui->tw_cams->itemAt(row,col);
if( item->text() == "opened" )
curCam = cameras.at(row);
//display Stream on label (stackedWidget)
//display options in dockwidget-right
}
void MainWindow::openCloseCam()
{
QPushButton* b = ui->b_openclose;
if( b->text() == "open" )
{
//close
auto ret = cam->Close();
log( QString("Close camera %1").arg(row), ret );
auto ret = curCam->Open(VmbAccessModeFull);
if( ret == VmbErrorSuccess )
b->setText("close");
log( QString("Open camera"), ret );
}
else
else if( b->text() == "close" )
{
//open
auto ret = cam->Open(VmbAccessModeFull);
log( QString("Open camera %1").arg(row), ret );
auto ret = curCam->Close();
if( ret == VmbErrorSuccess )
b->setText("open");
log( QString("Close camera"), ret );
}
}
void MainWindow::updateCams()
{
ui->tw_cams->clear();
VmbErrorType err = sys.GetCameras( cameras ); // Fetch all cameras known to Vimba
// clear
ui->tw_cams->setRowCount(0);
ui->tw_cams->clearContents(); //dont remove headers
curCam = CameraPtr();
cameras = CameraPtrVector();
// get new
VmbErrorType err = sys.GetCameras( cameras ); // fetch all cameras known to Vimba
if( VmbErrorSuccess == err )
{
// query and print all _static_ details of all known cams [without opening cams]
auto ncam = cameras.size();
log( QString("Found %1 Camera%2!").arg(ncam).arg(ncam>1?"s":""));
auto mf = std::bind(&MainWindow::printCamInfo, this, std::placeholders::_1); //weird syntax for calling non-static memberfunction in for_each...
auto mf = std::bind(&MainWindow::getCamInfo, this, std::placeholders::_1); //weird syntax for calling non-static memberfunction in for_each...
ui->tw_cams->setRowCount(ncam);
// ui->tw_cams->setRowCount(ncam);
std::for_each( cameras.begin(), cameras.end(), mf );
if( cameras.size() )
{
ui->tw_cams->setCurrentCell(0,0); //XXX select row?
}
ui->tw_cams->setCurrentCell(0,0); //select row
}
else
{
......@@ -103,49 +120,66 @@ void MainWindow::updateCams()
}
}
/// get static cam info and add to listwidget
void MainWindow::printCamInfo( const CameraPtr &camera )
/// get static cam info
void MainWindow::getCamInfo( const CameraPtr &camera )
{
std::string strID, strName, strModelName, strSerialNumber, strInterfaceID, strCaminfo;
std::string str;
QStringList infos;
VmbErrorType err = camera->GetID( strID );
VmbErrorType err = camera->GetID( str );
if( VmbErrorSuccess != err )
strID = errorCodeToMessage(err).toStdString();
str = errorCodeToMessage(err).toStdString();
infos << QString::fromStdString(str);
err = camera->GetName( strName );
err = camera->GetName( str );
if( VmbErrorSuccess != err )
strName = errorCodeToMessage(err).toStdString();
str = errorCodeToMessage(err).toStdString();
infos << QString::fromStdString(str);
err = camera->GetModel( strModelName );
err = camera->GetModel( str );
if( VmbErrorSuccess != err )
strModelName = errorCodeToMessage(err).toStdString();
str = errorCodeToMessage(err).toStdString();
infos << QString::fromStdString(str);
err = camera->GetSerialNumber( strSerialNumber );
err = camera->GetSerialNumber( str );
if( VmbErrorSuccess != err )
strSerialNumber = errorCodeToMessage(err).toStdString();
str = errorCodeToMessage(err).toStdString();
infos << QString::fromStdString(str);
err = camera->GetInterfaceID( strInterfaceID );
err = camera->GetInterfaceID( str );
if( VmbErrorSuccess != err )
strInterfaceID = errorCodeToMessage(err).toStdString();
str = errorCodeToMessage(err).toStdString();
infos << QString::fromStdString(str);
strCaminfo = \
"Name : " + strName +
"\nModel : " + strModelName +
"\nID : " + strID +
"\nSerial : " + strSerialNumber +
"\n@Interface : " + strInterfaceID + "\n\n";
QString caminfo = QString::fromStdString(strCaminfo);
infos << "closed"; //initially cams are closed, right?
//XXX use sth like isClosed() instead??
auto row = ui->tw_cams->rowCount()-1;
//XXX use icon instead of text
//QTableWidgetItem(const QIcon &icon, const QString &text, int type = Type)
ui->tw_cams->setItem( row, 0, new QTableWidgetItem( caminfo ) );
ui->tw_cams->setItem( row, 1, new QTableWidgetItem("closed") ); //XXX setIcon ??
addRow(infos);
QStringList sl= {randomString(),randomString(),randomString(),randomString(),randomString(),randomString()};
addRow(sl);
}
///add row to listwidget
void MainWindow::addRow( QStringList& camInfos )
{
auto row = ui->tw_cams->rowCount();
ui->tw_cams->setRowCount(row+1);
for( auto col=0; col < ui->tw_cams->columnCount(); col++)
{
auto item = new QTableWidgetItem( camInfos.at(col) );
item->setTextAlignment(Qt::AlignCenter);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); //but not editable!
ui->tw_cams->setItem( row, col, item );
}
}
void MainWindow::log(QString msg, VmbError_t err )
{
msg.append(QString("%1" ).arg(errorCodeToMessage(err)));
msg.append(QString("%1").arg(errorCodeToMessage(err)));
//for std::string, use: log(QString::fromStdString(msg))
auto idx = ui->lw_log->count()-1;
......
......@@ -18,20 +18,25 @@ public:
~MainWindow();
public slots:
void log(QString,VmbError_t err = VmbErrorSuccess);
void log(QString,VmbError_t err = VmbErrorNothing);
private slots:
void updateCams();
void opencloseCam(int,int);
void openCloseCam();
void selectCam(int,int);
protected:
void keyPressEvent(QKeyEvent *);
private:
void printCamInfo( const AVT::VmbAPI::CameraPtr &camera );
void getCamInfo( const AVT::VmbAPI::CameraPtr &camera );
void addRow( QStringList& );
Ui::MainWindow *ui;
AVT::VmbAPI::VimbaSystem &sys;
AVT::VmbAPI::CameraPtr curCam;
AVT::VmbAPI::CameraPtrVector cameras;
QStringList camInfoNames;
};
#endif // MAINWINDOW_H
......@@ -6,63 +6,36 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>984</width>
<height>622</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTableWidget" name="tw_cams_2">
<property name="geometry">
<rect>
<x>50</x>
<y>30</y>
<width>311</width>
<height>241</height>
</rect>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="rowCount">
<number>3</number>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<row/>
<row/>
<row/>
<column/>
<column/>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="l_vid">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>984</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QDockWidget" name="dockWidget">
<widget class="QDockWidget" name="dockWidget_down">
<attribute name="dockWidgetArea">
<number>8</number>
</attribute>
......@@ -74,7 +47,7 @@
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="dockWidget_2">
<widget class="QDockWidget" name="dockWidget_left">
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
......@@ -83,20 +56,43 @@
<item>
<widget class="QPushButton" name="b_update">
<property name="text">
<string>update</string>
<string>update (search Cams)</string>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tw_cams">
<property name="columnCount">
<number>2</number>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column/>
<column/>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="dockWidget_right">
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_3">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="b_openclose">
<property name="text">
<string>open</string>
</property>
</widget>
</item>
</layout>
......
#include "opencv2/core/version.hpp"
#include <random>
#include "mainwindow.h"
#include "VimbaCPP/Include/VimbaCPP.h"
#include <QString>
#include <QDebug>
const int APP_VERSION_MAJOR = 0;
......@@ -32,7 +35,8 @@ const QString errorCodeToMessage( VmbError_t err )
switch( err )
{
default: msg += "Unknown"; break;
case VmbErrorSuccess: msg = ""; break;
case VmbErrorNothing: msg = ""; break;
case VmbErrorSuccess: msg = "Success"; break;
case VmbErrorInternalFault: msg += "Unexpected fault in VmbApi or driver."; break;
case VmbErrorApiNotStarted: msg += "API not started."; break;
case VmbErrorNotFound: msg += "Not found."; break;
......@@ -55,3 +59,14 @@ const QString errorCodeToMessage( VmbError_t err )
return msg;
}
QString randomString()
{
QStringList list{"a", "b", "c", "d", "e", "f", "g"};
//, "h", "i", "j", "k", "l", "m"};
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(list.begin(), list.end(), g);
QString randomString = list.join("");
qDebug() << "Random string:" << randomString;
return randomString;
}
......@@ -7,5 +7,6 @@
const QString getVersionString();
const QString errorCodeToMessage( VmbError_t );
QString randomString();
#endif