Skip to content

Commit

Permalink
Base class for component frames added
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Mar 2, 2024
1 parent 09a69cb commit a56913c
Show file tree
Hide file tree
Showing 16 changed files with 332 additions and 251 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// MIT License
//
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#include "hal_core/defines.h"
#include "hal_core/netlist/gate_library/gate_type.h"

#include <QFormLayout>
#include <QLabel>
#include <QFrame>

namespace hal
{
class GatelibraryComponentFrame : public QFrame
{
Q_OBJECT

protected:
QString mTitle;
QFormLayout* mLayout;

public:
GatelibraryComponentFrame(const QString& title, QWidget* parent = nullptr);

virtual ~GatelibraryComponentFrame() {;}

virtual void update(GateType* gt) = 0;
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#pragma once

#include "gatelibrary_tab_interface.h"
#include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h"
#include "hal_core/defines.h"
#include "hal_core/netlist/gate_library/gate_type.h"

Expand All @@ -37,14 +37,14 @@ namespace hal
/**
* Widget which shows information about the flip flop properties of a given gate
*/
class GateLibraryTabFlipFlop : public GateLibraryTabInterface
class GatelibraryFrameFF : public GatelibraryComponentFrame
{
Q_OBJECT

public:
GateLibraryTabFlipFlop(QWidget* parent = nullptr);
GatelibraryFrameFF(QWidget* parent = nullptr);

void update(GateType* gate) override;
void update(GateType* gt) override;

private:

Expand Down
44 changes: 44 additions & 0 deletions plugins/gui/include/gui/gatelibrary_management/gatelibrary_label.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// MIT License
//
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#include <QLabel>
#include <QObject>

namespace hal
{
class GateLibraryLabel : public QLabel
{
Q_OBJECT

Q_PROPERTY(bool isValue READ isValue WRITE setValue) // label or value
bool mValue;
public:
GateLibraryLabel(bool isVal, const QString& txt= QString(), QWidget* parent = nullptr);
bool isValue() const { return mValue; }
void setValue(bool isVal) { mValue = isVal; }
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@

#pragma once

#include "gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.h"
#include "gatelibrary_table_model.h"
#include "gui/gatelibrary_management/gatelibrary_wizard.h"
#include "gui/gatelibrary_management/gatelibrary_content_widget.h"
#include "hal_core/netlist/gate_library/gate_library.h"
#include "hal_core/netlist/gate_library/gate_type.h"

#include <QFrame>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_boolean_function.h>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.h>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_pin.h>

class QGridLayout;
class QPushButton;
class QTabWidget;
class QSplitter;

namespace hal
{
Expand All @@ -49,6 +49,8 @@ namespace hal
{
Q_OBJECT

protected:
void resizeEvent(QResizeEvent* evt) override;
public:
/**
* Constructor.
Expand Down Expand Up @@ -93,8 +95,8 @@ namespace hal


private:

GateType* getSelectedGate();
QSplitter* mSplitter;
int mFrameWidth;

QTabWidget* mTabWidget;
QGridLayout* mLayout;
Expand All @@ -105,15 +107,16 @@ namespace hal
QPushButton* mOkBtn;
QPushButton* mCancelBtn;

GateLibraryTabFlipFlop* mFlipFlopTab;
GateLibraryTabGeneral* mGeneralTab;
GateLibraryTabBooleanFunction* mBooleanFunctionTab;
GateLibraryTabTruthTable* mBooleanFunctionTab;
GateLibraryTabPin* mPinTab;

const GateLibrary* mNonEditableGateLibrary;
GateLibrary* mEditableGatelibrary;
std::unique_ptr<Netlist> mDemoNetlist;

bool mReadOnly = false;

GateType* getSelectedGate();
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ namespace hal {
private:
QGridLayout* mLayout;
QTabWidget* mTabWidget;
//GateLibraryTabFlipFlop* mFlipFlopTab;

QLineEdit* mClock;
QLineEdit* mNextState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <QPushButton>
#include <QTreeView>

#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_boolean_function.h>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.h>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_pin.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,35 @@
#include "gatelibrary_tab_interface.h"
#include "hal_core/defines.h"
#include "hal_core/netlist/gate_library/gate_type.h"

#include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h"
#include <QFormLayout>
#include <QLabel>
#include <QFrame>

namespace hal
{
class GateLibraryLabel : public QLabel
class GateLibraryLabel;
class GatelibraryFrameFF;

class GatelibraryFrameGeneral : public GatelibraryComponentFrame
{
Q_OBJECT
public:
GatelibraryFrameGeneral(QWidget* parent = nullptr);
void update(GateType *gt) override;

private:
GateLibraryLabel* mNameLabel;
GateLibraryLabel* mIdLabel;
GateLibraryLabel* mPropertiesLabel;
};

Q_PROPERTY(bool isValue READ isValue WRITE setValue) // label or value
bool mValue;
class GatelibraryFrameBoolean : public GatelibraryComponentFrame
{
Q_OBJECT
public:
GateLibraryLabel(bool isVal, const QString& txt= QString(), QWidget* parent = nullptr);
bool isValue() const { return mValue; }
void setValue(bool isVal) { mValue = isVal; }
GatelibraryFrameBoolean(QWidget* parent = nullptr);
void update(GateType *gt) override;
};

/**
Expand All @@ -58,26 +70,13 @@ namespace hal
GateLibraryTabGeneral(QWidget* parent = nullptr);


void update(GateType* gate) override;
void update(GateType* gt) override;


private:
QFrame* mGeneralFrame;
QFrame* mBooleanFrame;
QFrame* mFlipflopFrame;

QLabel* mNamePropertyLabel;
QLabel* mIdPropertyLabel;
QLabel* mComponentPropertyLabel;

QLabel* mClockPropertyLabel;
QLabel* mNextStatePropertyLabel;
QLabel* mAsynchronousResetPropertyLabel;
QLabel* mInternalStatePropertyLabel;
QLabel* mNegatedInternalStatePropertyLabel;

QFormLayout* mBooleanLayout;

GatelibraryFrameGeneral* mGeneralFrame;
GatelibraryFrameBoolean* mBooleanFrame;
GatelibraryFrameFF* mFlipflopFrame;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ namespace hal
/**
* Widget which shows information of the boolean functions of a gate
*/
class GateLibraryTabBooleanFunction : public GateLibraryTabInterface
class GateLibraryTabTruthTable : public GateLibraryTabInterface
{
Q_OBJECT

public:
GateLibraryTabBooleanFunction(QWidget* parent = nullptr);
GateLibraryTabTruthTable(QWidget* parent = nullptr);


void update(GateType* gate) override;
Expand All @@ -72,7 +72,7 @@ namespace hal
QGridLayout* mLayout;
QTableWidget* mTableWidget;
QHeaderView* mHeaderView;

QLabel* mDisclaimer;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h"
#include "gui/gatelibrary_management/gatelibrary_label.h"

namespace hal {
GatelibraryComponentFrame::GatelibraryComponentFrame(const QString& title, QWidget* parent)
: QFrame(parent), mTitle(title)
{
setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
setFrameStyle(QFrame::Sunken | QFrame::Panel);
setLineWidth(2);
mLayout = new QFormLayout(this);
mLayout->addRow(new GateLibraryLabel(false, mTitle, this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h"
#include "gui/gatelibrary_management/gatelibrary_label.h"
#include "gui/gui_globals.h"
#include "hal_core/netlist/gate_library/gate_type_component/ff_component.h"

namespace hal
{

GatelibraryFrameFF::GatelibraryFrameFF(QWidget* parent)
: GatelibraryComponentFrame("Flip Flop", parent)
{
mClockPropertyLabel = new GateLibraryLabel(true, " - ", this);
mNextStatePropertyLabel = new GateLibraryLabel(true, " - ", this);
mAsynchronousResetPropertyLabel = new GateLibraryLabel(true, " - ", this);
mInternalStatePropertyLabel = new GateLibraryLabel(true, " - ", this);
mNegatedInternalStatePropertyLabel = new GateLibraryLabel(true, " - ", this);

mLayout->addRow(new GateLibraryLabel(false, "Clock:", parent), mClockPropertyLabel);
mLayout->addRow(new GateLibraryLabel(false, "Next state:", parent), mNextStatePropertyLabel);
mLayout->addRow(new GateLibraryLabel(false, "Asynchronous reset:", parent), mAsynchronousResetPropertyLabel);
mLayout->addRow(new GateLibraryLabel(false, "Internal state:", parent), mInternalStatePropertyLabel);
mLayout->addRow(new GateLibraryLabel(false, "Negated internal state:", parent), mNegatedInternalStatePropertyLabel);
}

void GatelibraryFrameFF::update(GateType* gt)
{
if (gt->has_component_of_type(GateTypeComponent::ComponentType::ff))
{
auto ff = gt->get_component_as<FFComponent>([](const GateTypeComponent* c) { return FFComponent::is_class_of(c); });

if (ff != nullptr)
{
mClockPropertyLabel->setText(QString::fromStdString(ff->get_clock_function().to_string()));
mNextStatePropertyLabel->setText(QString::fromStdString(ff->get_next_state_function().to_string()));
mAsynchronousResetPropertyLabel->setText(QString::fromStdString(ff->get_async_reset_function().to_string()));

mInternalStatePropertyLabel->setText(QString::fromStdString(gt->get_boolean_function().to_string()));

Result<BooleanFunction> result = BooleanFunction::Not(gt->get_boolean_function(), gt->get_boolean_function().size());
if(result.is_ok())
mNegatedInternalStatePropertyLabel->setText(QString::fromStdString(result.get().to_string()));
else{
mNegatedInternalStatePropertyLabel->setText("ERROR");
}
show();
}
else
hide();
}
else
hide();
}
}
9 changes: 9 additions & 0 deletions plugins/gui/src/gatelibrary_management/gatelibrary_label.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "gui/gatelibrary_management/gatelibrary_label.h"

namespace hal {
GateLibraryLabel::GateLibraryLabel(bool isVal, const QString& txt, QWidget *parent)
: QLabel(txt,parent)
{
mValue = isVal;
}
}
Loading

0 comments on commit a56913c

Please sign in to comment.