Skip to content

Commit

Permalink
Additional cleanup (#4)
Browse files Browse the repository at this point in the history
* Gitignore fix

* Initial Refactor

* Refactor CC

* Added 'this'

* changeEvent & Sort Headers

* Lib version update

* Const ref & Closing ValueInput/MessageAlert

* simulator namespace

* Add m_ prefix

* Enum names upper case

* Folder refactor

* Removed space after std::shared_ptr
Nenad Vuletić authored Dec 25, 2019
1 parent 7c6318b commit 5276c3d
Showing 133 changed files with 3,909 additions and 2,900 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -41,5 +41,7 @@ target_wrapper.*

# QtCreator CMake
CMakeLists.txt.user*

out/
.idea/
dependencies/out/
dependencies/
34 changes: 0 additions & 34 deletions modbus-application/Logs/alarmalert.h

This file was deleted.

136 changes: 0 additions & 136 deletions modbus-application/Logs/alarmalert.ui

This file was deleted.

72 changes: 0 additions & 72 deletions modbus-application/Logs/logs.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions modbus-application/Logs/logs.h

This file was deleted.

44 changes: 0 additions & 44 deletions modbus-application/Logs/logs.ui

This file was deleted.

38 changes: 0 additions & 38 deletions modbus-application/Machine/countlistener.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions modbus-application/Machine/countlistener.h

This file was deleted.

306 changes: 0 additions & 306 deletions modbus-application/Machine/machineview.ui

This file was deleted.

234 changes: 0 additions & 234 deletions modbus-application/Machine/paintstationcontrol.ui

This file was deleted.

34 changes: 0 additions & 34 deletions modbus-application/Machine/ratelistener.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions modbus-application/Machine/ratelistener.h

This file was deleted.

167 changes: 0 additions & 167 deletions modbus-application/Machine/valueinput.ui

This file was deleted.

28 changes: 18 additions & 10 deletions modbus-application/main.cpp → modbus-application/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#include "Logs/logs.h"
#include "Machine/machineview.h"
#include "mainwindow.h"
#include "Settings/settings.h"
#include "simulator.h"
#include "windowmanager.h"
#include "logs/Logs.h"
#include "machine/MachineView.h"
#include "MainWindow.h"
#include "settings/Settings.h"
#include "Simulator.h"
#include "WindowManager.h"

#include <QApplication>
#include <QFontDatabase>

int main(int argc, char *argv[])
{
try {
try
{
QApplication a(argc, argv);

#ifdef QT_DEBUG
qDebug("Application is running in DEBUG mode!");
#endif

Simulator simulator;

QFontDatabase::addApplicationFont(":/Fonts/Roboto-Medium.ttf"); // id 0
@@ -24,7 +30,7 @@ int main(int argc, char *argv[])
ModbusThread modbusThread(simulator);
WindowManager& windowManager = w.getWindowManager();

QFrame * parent = w.frameHolder();
QFrame *parent = w.frameHolder();
windowManager.addFrame(std::make_shared<Logs>(simulator, modbusThread.getMapping(), parent)); // 0
std::shared_ptr<Settings> settingsView = std::make_shared<Settings>(simulator, modbusThread, parent);
windowManager.addFrame(settingsView); // 1
@@ -44,8 +50,10 @@ int main(int argc, char *argv[])
modbusThread.terminate();
modbusThread.wait(5);
return res;
} catch (std::exception &e) {
qDebug("%s", e.what());
}
catch (std::exception& e)
{
qErrnoWarning("%s", e.what());
return -1;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include "Machine/feedercontrol.h"
#include "Logs/logs.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "logs/Logs.h"
#include "machine/FeederControl.h"
#include "MainWindow.h"
#include "ui_MainWindow.h"

#include <QMessageBox>
#include <QTime>
#include <QTimer>
#include <qdatetime.h>
#include <QDateTime>
#include <QFontDatabase>
#include <QPainter>
#include <QTime>
#include <QTimer>

MainWindow::MainWindow(Simulator &simulator, QWidget *parent) :
QMainWindow(parent),
m_windowManager(),
m_simulator(simulator),
ui(new Ui::MainWindow)
MainWindow::MainWindow(const Simulator& simulator, QWidget *parent) :
QMainWindow(parent),
m_simulator(simulator),
m_windowManager(),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

@@ -37,7 +36,7 @@ MainWindow::MainWindow(Simulator &simulator, QWidget *parent) :
ui->welcomeText->setFont(robotoRegular16);

#ifdef QT_DEBUG
// do nothing
qDebug("Starting application in windowed mode.");
#else
QMainWindow::showFullScreen();
#endif
@@ -59,31 +58,30 @@ MainWindow::MainWindow(Simulator &simulator, QWidget *parent) :
startTimer(100);
}

MainWindow::~MainWindow()
WindowManager& MainWindow::getWindowManager()
{
delete ui;
}

WindowManager& MainWindow::getWindowManager() {
return m_windowManager;
}

QFrame * MainWindow::frameHolder() {
QFrame *MainWindow::frameHolder()
{
return ui->displayedWindow;
}

void MainWindow::windowActivationChange(bool oldChange)
{
if (oldChange) {
// not in focus
if (oldChange)
{
ui->fade->show();
} else {
// in focus
}
else
{
ui->fade->hide();
}
}

void MainWindow::timerEvent(QTimerEvent *event) {
void MainWindow::timerEvent(QTimerEvent *)
{
ui->clock->setText(QTime::currentTime().toString("hh:mm"));
ui->date->setText(QDate::currentDate().toString("dd.M.yyyy."));
}
@@ -112,3 +110,8 @@ void MainWindow::on_machineButton_clicked()
{
m_windowManager.showFrame(2);
}

MainWindow::~MainWindow()
{
delete ui;
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "simulator.h"
#include "windowmanager.h"
#include <QMainWindow>
#include "Simulator.h"
#include "WindowManager.h"

#include <QFrame>
#include <QMainWindow>

namespace Ui {
class MainWindow;
namespace Ui
{
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(Simulator &simulator, QWidget *parent = nullptr);
MainWindow(const Simulator& simulator, QWidget *parent = nullptr);

~MainWindow() override;

QFrame *frameHolder();

void windowActivationChange(bool) override;

WindowManager& getWindowManager();

private slots:
@@ -32,10 +39,11 @@ private slots:
void on_machineButton_clicked();

private:
void timerEvent(QTimerEvent *event) override;

const Simulator& m_simulator;
WindowManager m_windowManager;
Simulator &m_simulator;
Ui::MainWindow *ui;
void timerEvent(QTimerEvent *event) override;
};

#endif // MAINWINDOW_H
Original file line number Diff line number Diff line change
@@ -66,7 +66,8 @@
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">border: 0px; border-radius: 4px ; background-color: #00AFFF; color: white;</string>
<string notr="true">border: 0px; border-radius: 4px ; background-color: #00AFFF; color: white;
</string>
</property>
<property name="text">
<string>Start demo</string>
@@ -154,7 +155,8 @@ Click start to see what you can do with our help.</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: #F5F5F5;
color: #323232;</string>
color: #323232;
</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
@@ -311,8 +313,8 @@ color: #323232;</string>
</property>
<property name="styleSheet">
<string notr="true">border-radius: 4px;
background-color: #f5f5f5;
</string>
background-color: #f5f5f5;
</string>
</property>
<property name="text">
<string>Home</string>
@@ -338,8 +340,8 @@ background-color: #f5f5f5;
</property>
<property name="styleSheet">
<string notr="true">border-radius: 4px;
background-color: #f5f5f5;
</string>
background-color: #f5f5f5;
</string>
</property>
<property name="text">
<string>Logs</string>
24 changes: 0 additions & 24 deletions modbus-application/Modbus/bittogglethread.h

This file was deleted.

54 changes: 0 additions & 54 deletions modbus-application/Modbus/modbusthread.h

This file was deleted.

29 changes: 0 additions & 29 deletions modbus-application/Modbus/modbusthread_listeners.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions modbus-application/Modbus/modbusthread_listeners.h

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Icons/ico_back.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Icons/ico_close.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Icons/ico_close_white.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Icons/ico_minus.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Icons/ico_plus.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Icons/ico_settings.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Background.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Black.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Conveyor_Belt.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Cyan.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Delivery.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Dimmer.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Feeder.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Logo_white.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Magenta.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Offset.svg

This file was deleted.

1 change: 0 additions & 1 deletion modbus-application/Resources/Images/Yellow.svg

This file was deleted.

25 changes: 0 additions & 25 deletions modbus-application/Settings/messagealert.h

This file was deleted.

127 changes: 0 additions & 127 deletions modbus-application/Settings/messagealert.ui

This file was deleted.

41 changes: 0 additions & 41 deletions modbus-application/Settings/settings.h

This file was deleted.

526 changes: 0 additions & 526 deletions modbus-application/Settings/settings.ui

This file was deleted.

140 changes: 140 additions & 0 deletions modbus-application/Simulator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#include "machine/ConveyorControl.h"
#include "machine/DeliveryControl.h"
#include "machine/FeederControl.h"
#include "machine/PaintStationControl.h"
#include "Simulator.h"

Simulator::Simulator()
{
m_machine = std::make_shared<simulator::Machine>("Main Machine");
m_feeder = std::make_shared<simulator::Feeder>("Feeder", *m_machine.get(), FEEDER_CAPACITY, FEEDER_START_COUNT);
m_machine->addComponent(m_feeder);
m_cyan = std::make_shared<simulator::PaintStation>("Cyan Paint", *m_machine.get(), PAINT_STATION_CAPACITY,
PAINT_STATION_START_COUNT);
m_machine->addComponent(m_cyan);
m_magenta = std::make_shared<simulator::PaintStation>("Magenta Paint", *m_machine.get(), PAINT_STATION_CAPACITY,
PAINT_STATION_START_COUNT);
m_machine->addComponent(m_magenta);
m_yellow = std::make_shared<simulator::PaintStation>("Yellow Paint", *m_machine.get(), PAINT_STATION_CAPACITY,
PAINT_STATION_START_COUNT);
m_machine->addComponent(m_yellow);
m_black = std::make_shared<simulator::PaintStation>("Black Paint", *m_machine.get(), PAINT_STATION_CAPACITY,
PAINT_STATION_START_COUNT);
m_machine->addComponent(m_black);
m_delivery = std::make_shared<simulator::Delivery>
("Delivery", *m_machine.get(), DELIVERY_CAPACITY, DELIVERY_START_COUNT);
m_machine->addComponent(m_delivery);
m_conveyor = std::make_shared<simulator::Conveyor>
("Conveyor Belt", *m_machine.get(), CONVEYOR_MAX_RATE, CONVEYOR_START_RATE);
m_machine->addComponent(m_conveyor);
}

std::shared_ptr<simulator::Machine> Simulator::getMachine() const
{
return m_machine;
}

std::shared_ptr<simulator::Feeder> Simulator::getFeeder() const
{
return m_feeder;
}

std::shared_ptr<simulator::PaintStation> Simulator::getCyanPaint() const
{
return m_cyan;
}

std::shared_ptr<simulator::PaintStation> Simulator::getMagentaPaint() const
{
return m_magenta;
}

std::shared_ptr<simulator::PaintStation> Simulator::getYellowPaint() const
{
return m_yellow;
}

std::shared_ptr<simulator::PaintStation> Simulator::getBlackPaint() const
{
return m_black;
}

std::shared_ptr<simulator::Delivery> Simulator::getDelivery() const
{
return m_delivery;
}

std::shared_ptr<simulator::Conveyor> Simulator::getConveyor() const
{
return m_conveyor;
}

QWidget *Simulator::getFeederWidget() const
{
return m_feederWidget;
}

void Simulator::setFeederWidget(QWidget *value)
{
m_feederWidget = value;
}

QWidget *Simulator::getDeliveryWidget() const
{
return m_deliveryWidget;
}

void Simulator::setDeliveryWidget(QWidget *value)
{
m_deliveryWidget = value;
}

QWidget *Simulator::getConveyorWidget() const
{
return m_conveyorWidget;
}

void Simulator::setConveyorWidget(QWidget *value)
{
m_conveyorWidget = value;
}

QWidget *Simulator::getCyanWidget() const
{
return m_cyanWidget;
}

void Simulator::setCyanWidget(QWidget *value)
{
m_cyanWidget = value;
}

QWidget *Simulator::getMagentaWidget() const
{
return m_magentaWidget;
}

void Simulator::setMagentaWidget(QWidget *value)
{
m_magentaWidget = value;
}

QWidget *Simulator::getYellowWidget() const
{
return m_yellowWidget;
}

void Simulator::setYellowWidget(QWidget *value)
{
m_yellowWidget = value;
}

QWidget *Simulator::getBlackWidget() const
{
return m_blackWidget;
}

void Simulator::setBlackWidget(QWidget *value)
{
m_blackWidget = value;
}
82 changes: 82 additions & 0 deletions modbus-application/Simulator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef SIMULATOR_H
#define SIMULATOR_H

#include "components/Conveyor.h"
#include "components/Delivery.h"
#include "components/Feeder.h"
#include "components/PaintStation.h"
#include "Machine.h"

#include <QWidget>

#define FEEDER_CAPACITY 17000
#define DELIVERY_CAPACITY 17000
#define PAINT_STATION_CAPACITY 10000

#define FEEDER_START_COUNT 1000
#define DELIVERY_START_COUNT 16950
#define PAINT_STATION_START_COUNT 10000

#define CONVEYOR_MAX_RATE 15000
#define CONVEYOR_START_RATE 14400

class Simulator
{
public:
std::shared_ptr<simulator::Machine> getMachine() const;

std::shared_ptr<simulator::Feeder> getFeeder() const;

std::shared_ptr<simulator::PaintStation> getCyanPaint() const;

std::shared_ptr<simulator::PaintStation> getMagentaPaint() const;

std::shared_ptr<simulator::PaintStation> getYellowPaint() const;

std::shared_ptr<simulator::PaintStation> getBlackPaint() const;

std::shared_ptr<simulator::Delivery> getDelivery() const;

std::shared_ptr<simulator::Conveyor> getConveyor() const;

QWidget *getFeederWidget() const;

void setFeederWidget(QWidget *value);

QWidget *getDeliveryWidget() const;

void setDeliveryWidget(QWidget *value);

QWidget *getConveyorWidget() const;

void setConveyorWidget(QWidget *value);

QWidget *getCyanWidget() const;

void setCyanWidget(QWidget *value);

QWidget *getMagentaWidget() const;

void setMagentaWidget(QWidget *value);

QWidget *getYellowWidget() const;

void setYellowWidget(QWidget *value);

QWidget *getBlackWidget() const;

void setBlackWidget(QWidget *value);

Simulator();

private:
std::shared_ptr<simulator::Machine> m_machine;
std::shared_ptr<simulator::Feeder> m_feeder;
std::shared_ptr<simulator::PaintStation> m_cyan, m_magenta, m_yellow, m_black;
std::shared_ptr<simulator::Delivery> m_delivery;
std::shared_ptr<simulator::Conveyor> m_conveyor;
QWidget *m_feederWidget, *m_deliveryWidget, *m_conveyorWidget;
QWidget *m_cyanWidget, *m_magentaWidget, *m_yellowWidget, *m_blackWidget;
};

#endif // SIMULATOR_H
27 changes: 16 additions & 11 deletions modbus-application/utility.h → modbus-application/Utility.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef UTILITY_H
#define UTILITY_H

#include <QHostAddress>
#include <QString>
#include <qnetworkinterface.h>
#include <regex>
#include <QHostAddress>
#include <QNetworkInterface>

class Utility {
class Utility
{
public:
static QString replaceNumbers(QString source, QString newNumber) {
static QString replaceNumbers(QString source, QString newNumber)
{
std::string exclusionPattern = "h2";
std::string returningPattern = "~";
std::string pattern = "([0-9]+\\.)?[0-9]+(\\%)?";
@@ -21,13 +22,17 @@ class Utility {
result = std::regex_replace(result, returning, exclusionPattern);
return QString::fromStdString(result);
}
static QString getIp() {
const QHostAddress &localhost = QHostAddress(QHostAddress::LocalHost);

static QString getIp()
{
const QHostAddress& localhost = QHostAddress(QHostAddress::LocalHost);
QString addressString;
for (const QHostAddress &address: QNetworkInterface::allAddresses()) {
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != localhost) {
addressString += address.toString();
break;
for (const QHostAddress& address: QNetworkInterface::allAddresses())
{
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != localhost)
{
addressString += address.toString();
break;
}
}
return addressString;
79 changes: 79 additions & 0 deletions modbus-application/WindowManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "WindowManager.h"

std::vector <std::shared_ptr<QFrame>>& WindowManager::getFrames()
{
return m_frames;
}

WindowManager::WindowManager() {}

int WindowManager::addFrame(std::shared_ptr<QFrame> frame)
{
m_frames.push_back(frame);
return m_frames.size() - 1;
}

void WindowManager::showFrame(int index)
{
if (m_frameStack.size() > 0)
{
int m_index = m_frameStack.top();
m_frames[m_index]->hide();
}
if (m_frameStack.size() == 0 || m_frameStack.top() != index)
{
m_frameStack.push(index);
}
m_frames[index]->show();
}

void WindowManager::showFrame(std::shared_ptr<QFrame> frame)
{
for (int i = 0; i < m_frames.size(); i++)
{
if (m_frames[i] == frame)
{
showFrame(i);
}
}
}

void WindowManager::goBack()
{
if (m_frameStack.size() > 0)
{
int topIndex = m_frameStack.top();
m_frames[topIndex]->hide();
m_frameStack.pop();
if (m_frameStack.size() > 0)
{
int backIndex = m_frameStack.top();
m_frames[backIndex]->show();
}
}
}

void WindowManager::hideEverything()
{
if (m_frameStack.size() > 0)
{
int topIndex = m_frameStack.top();
m_frames[topIndex]->hide();
}
}

void WindowManager::clearStack()
{
if (m_frameStack.size() > 0)
{
int topIndex = m_frameStack.top();
m_frames[topIndex]->hide();
m_frames.clear();
}
}

WindowManager::~WindowManager()
{
m_frameStack.empty();
m_frames.clear();
}
Original file line number Diff line number Diff line change
@@ -2,24 +2,32 @@
#define WINDOWMANAGER_H

#include <memory>
#include <vector>
#include <stack>
#include <qframe.h>
#include <vector>
#include <QFrame>

class WindowManager
{
private:
std::vector<std::shared_ptr<QFrame>> frames;
std::stack<int> frameStack;
std::vector<std::shared_ptr<QFrame>> m_frames;
std::stack<int> m_frameStack;
public:
std::vector<std::shared_ptr<QFrame>>& getFrames();

WindowManager();

~WindowManager();
std::vector<std::shared_ptr<QFrame>> &getFrames();

int addFrame(std::shared_ptr<QFrame>);

void showFrame(int);

void showFrame(std::shared_ptr<QFrame>);

void goBack();

void hideEverything();

void clearStack();
};

27 changes: 27 additions & 0 deletions modbus-application/external/BitToggleThread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef BITTOGGLETHREAD_H
#define BITTOGGLETHREAD_H

#include "modbus/modbus.h"

#include <thread>
#include <QThread>

class BitToggleThread : public QThread
{
Q_OBJECT
public:
BitToggleThread(int bit, modbus_mapping_t *mappings) : m_mappings(mappings), m_bit(bit) {}

void run() override
{
m_mappings->tab_input_bits[m_bit] = 1;
std::this_thread::sleep_for(std::chrono::seconds(5));
m_mappings->tab_input_bits[m_bit] = 0;
finished();
}
private:
modbus_mapping_t *m_mappings;
int m_bit;
};

#endif // BITTOGGLETHREAD_H
Loading

0 comments on commit 5276c3d

Please sign in to comment.