From a56913c69ba28b8cd210e26a44d6e2084be5ead7 Mon Sep 17 00:00:00 2001 From: joern274 Date: Sat, 2 Mar 2024 14:18:03 +0100 Subject: [PATCH] Base class for component frames added --- .../gatelibrary_component_frame.h | 53 ++++++ .../gatelibrary_frame_ff.h} | 8 +- .../gatelibrary_label.h | 44 +++++ .../gatelibrary_manager.h | 15 +- .../gatelibrary_pages/flipflop_wizardpage.h | 1 - .../gatelibrary_pages/pins_wizardpage.h | 2 +- .../gatelibrary_tab_general.h | 47 +++-- ...nction.h => gatelibrary_tab_truth_table.h} | 6 +- .../gatelibrary_component_frame.cpp | 14 ++ .../gatelibrary_frame_ff.cpp | 53 ++++++ .../gatelibrary_label.cpp | 9 + .../gatelibrary_manager.cpp | 32 ++-- .../gatelibrary_pages/flipflop_wizardpage.cpp | 2 - .../gatelibrary_tab_flip_flop.cpp | 74 -------- .../gatelibrary_tab_general.cpp | 176 +++++++----------- ...on.cpp => gatelibrary_tab_truth_table.cpp} | 47 +++-- 16 files changed, 332 insertions(+), 251 deletions(-) create mode 100644 plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h rename plugins/gui/include/gui/gatelibrary_management/{gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.h => gatelibrary_frames/gatelibrary_frame_ff.h} (90%) create mode 100644 plugins/gui/include/gui/gatelibrary_management/gatelibrary_label.h rename plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/{gatelibrary_tab_boolean_function.h => gatelibrary_tab_truth_table.h} (94%) create mode 100644 plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.cpp create mode 100644 plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.cpp create mode 100644 plugins/gui/src/gatelibrary_management/gatelibrary_label.cpp delete mode 100644 plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.cpp rename plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/{gatelibrary_tab_boolean_function.cpp => gatelibrary_tab_truth_table.cpp} (70%) diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h new file mode 100644 index 00000000000..9a95e85efae --- /dev/null +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.h @@ -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 +#include +#include + +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; + }; +} + diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h similarity index 90% rename from plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.h rename to plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h index 42b4b2a1db4..90c15c08ce8 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.h @@ -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" @@ -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: diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_label.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_label.h new file mode 100644 index 00000000000..109a7a3d8d1 --- /dev/null +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_label.h @@ -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 +#include + +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; } + }; +} diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h index 0f7bd6ea4e8..fe60031decb 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_manager.h @@ -25,7 +25,6 @@ #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" @@ -33,13 +32,14 @@ #include "hal_core/netlist/gate_library/gate_type.h" #include -#include +#include #include #include class QGridLayout; class QPushButton; class QTabWidget; +class QSplitter; namespace hal { @@ -49,6 +49,8 @@ namespace hal { Q_OBJECT + protected: + void resizeEvent(QResizeEvent* evt) override; public: /** * Constructor. @@ -93,8 +95,8 @@ namespace hal private: - - GateType* getSelectedGate(); + QSplitter* mSplitter; + int mFrameWidth; QTabWidget* mTabWidget; QGridLayout* mLayout; @@ -105,9 +107,8 @@ namespace hal QPushButton* mOkBtn; QPushButton* mCancelBtn; - GateLibraryTabFlipFlop* mFlipFlopTab; GateLibraryTabGeneral* mGeneralTab; - GateLibraryTabBooleanFunction* mBooleanFunctionTab; + GateLibraryTabTruthTable* mBooleanFunctionTab; GateLibraryTabPin* mPinTab; const GateLibrary* mNonEditableGateLibrary; @@ -115,5 +116,7 @@ namespace hal std::unique_ptr mDemoNetlist; bool mReadOnly = false; + + GateType* getSelectedGate(); }; } diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/flipflop_wizardpage.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/flipflop_wizardpage.h index 8e14bd5977a..611fc243198 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/flipflop_wizardpage.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/flipflop_wizardpage.h @@ -44,7 +44,6 @@ namespace hal { private: QGridLayout* mLayout; QTabWidget* mTabWidget; - //GateLibraryTabFlipFlop* mFlipFlopTab; QLineEdit* mClock; QLineEdit* mNextState; diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/pins_wizardpage.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/pins_wizardpage.h index 41bbbf9306f..add00bbac28 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/pins_wizardpage.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/pins_wizardpage.h @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h index 19844655469..1ac31e15aa7 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h @@ -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 #include #include 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; }; /** @@ -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; }; } diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_boolean_function.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.h similarity index 94% rename from plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_boolean_function.h rename to plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.h index 53f514db193..ca4ca313e2a 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_boolean_function.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.h @@ -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; @@ -72,7 +72,7 @@ namespace hal QGridLayout* mLayout; QTableWidget* mTableWidget; QHeaderView* mHeaderView; - + QLabel* mDisclaimer; }; } diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.cpp new file mode 100644 index 00000000000..a1a3eafa1c6 --- /dev/null +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_component_frame.cpp @@ -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)); + } +} diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.cpp new file mode 100644 index 00000000000..490ffd5aab4 --- /dev/null +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_frames/gatelibrary_frame_ff.cpp @@ -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([](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 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(); + } +} diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_label.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_label.cpp new file mode 100644 index 00000000000..dd480bb53e6 --- /dev/null +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_label.cpp @@ -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; + } +} diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp index 29a18a21851..d017dd50a79 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp @@ -29,23 +29,22 @@ namespace hal { GateLibraryManager::GateLibraryManager(MainWindow *parent) - : QFrame(parent), mLayout(new QGridLayout()), mNonEditableGateLibrary(nullptr), mEditableGatelibrary(nullptr) + : QFrame(parent), mFrameWidth(0), mLayout(new QGridLayout()), mNonEditableGateLibrary(nullptr), mEditableGatelibrary(nullptr) { //TODO: GateLibrarymanager will stay in readOnly mode even if closing project and opening a new gateLibrary - QSplitter* split = new QSplitter(this); - QWidget* rightWindow = new QWidget(split); + mSplitter = new QSplitter(this); + QWidget* rightWindow = new QWidget(mSplitter); QGridLayout* rlay = new QGridLayout(rightWindow); QDialogButtonBox* bbox = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok, Qt::Horizontal, rightWindow); mTableModel = new GatelibraryTableModel(this); - mContentWidget = new GatelibraryContentWidget(mTableModel,split); + mContentWidget = new GatelibraryContentWidget(mTableModel,mSplitter); //pages for the tab widget mGeneralTab = new GateLibraryTabGeneral(this); mPinTab = new GateLibraryTabPin(this); - mFlipFlopTab = new GateLibraryTabFlipFlop(this); - mBooleanFunctionTab = new GateLibraryTabBooleanFunction(this); + mBooleanFunctionTab = new GateLibraryTabTruthTable(this); //buttons @@ -58,7 +57,6 @@ namespace hal mTabWidget = new QTabWidget(this); mTabWidget->addTab(mGeneralTab, "Gate Type"); mTabWidget->addTab(mPinTab, "Pins"); -// mTabWidget->addTab(mFlipFlopTab, "Flip Flops"); mTabWidget->addTab(mBooleanFunctionTab, "Truth Table"); // TODO : implement truth table mGraphicsView = new GatelibraryGraphicsView(this); @@ -71,10 +69,10 @@ namespace hal rlay->addWidget(bbox,1,0,1,2); // Add widgets to the layout - split->addWidget(mContentWidget); - split->addWidget(rightWindow); + mSplitter->addWidget(mContentWidget); + mSplitter->addWidget(rightWindow); - mLayout->addWidget(split); + mLayout->addWidget(mSplitter); //signal - slots // connect(mAddBtn, &QPushButton::clicked, this, &GateLibraryManager::handleAddWizard); @@ -236,9 +234,21 @@ namespace hal void GateLibraryManager::updateTabs(GateType* gateType) { - mFlipFlopTab->update(gateType); mGeneralTab->update(gateType); mBooleanFunctionTab->update(gateType); mPinTab->update(gateType); } + + void GateLibraryManager::resizeEvent(QResizeEvent* evt) + { + QFrame::resizeEvent(evt); + if (evt->size().width() != mFrameWidth) + { + mFrameWidth = evt->size().width(); + QList splitSizes; + // divide available size in percent + splitSizes << mFrameWidth * 27 / 100 << mFrameWidth * 73 / 100; + mSplitter->setSizes(splitSizes); + } + } } diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/flipflop_wizardpage.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/flipflop_wizardpage.cpp index 51314b331e7..386ca0e1dd8 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/flipflop_wizardpage.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/flipflop_wizardpage.cpp @@ -11,8 +11,6 @@ namespace hal setSubTitle("TODO: subtitle"); mLayout = new QGridLayout(this); mTabWidget = new QTabWidget(this); - //mFlipFlopTab = new GateLibraryTabFlipFlop(this); - //mTabWidget->addTab(mFlipFlopTab, "Flip Flop"); //TODO: //mTabWidget->addTab(mStateTableTab, "State Table"); diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.cpp deleted file mode 100644 index fe96d1e7d4d..00000000000 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.cpp +++ /dev/null @@ -1,74 +0,0 @@ - -#include "gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.h" - -#include "gui/gui_globals.h" -#include "hal_core/netlist/gate_library/gate_type_component/ff_component.h" - -namespace hal -{ - - GateLibraryTabFlipFlop::GateLibraryTabFlipFlop(QWidget* parent) : GateLibraryTabInterface(parent) - { - mFormLayout = new QFormLayout(parent); - - mClockLabel = new QLabel("Clock", parent); - mNextStateLabel = new QLabel("Next state", parent); - mAsynchronousResetLabel = new QLabel("Asynchronous reset", parent); - mInternalStateLabel = new QLabel("Internal state", parent); - mNegatedInternalStateLabel = new QLabel("Negated internal state", parent); - - mClockPropertyLabel = new QLabel(" - ", parent); - mNextStatePropertyLabel = new QLabel(" - ", parent); - mAsynchronousResetPropertyLabel = new QLabel(" - ", parent); - mInternalStatePropertyLabel = new QLabel(" - ", parent); - mNegatedInternalStatePropertyLabel = new QLabel(" - ", parent); - - mFormLayout->addRow(mClockLabel, mClockPropertyLabel); - mFormLayout->addRow( mNextStateLabel, mNextStatePropertyLabel); - mFormLayout->addRow(mAsynchronousResetLabel, mAsynchronousResetPropertyLabel); - mFormLayout->addRow(mInternalStateLabel, mInternalStatePropertyLabel); - mFormLayout->addRow(mNegatedInternalStateLabel, mNegatedInternalStatePropertyLabel); - - setLayout(mFormLayout); - - } - - void GateLibraryTabFlipFlop::update(GateType* gate) - { - if(!gate || !gate->has_component_of_type(GateTypeComponent::ComponentType::ff)){ - //TODO make default look - mClockPropertyLabel->setText("-"); - mNextStatePropertyLabel->setText("-"); - mAsynchronousResetPropertyLabel->setText("-"); - mInternalStatePropertyLabel->setText("-"); - mNegatedInternalStatePropertyLabel->setText("-"); - - return; - } - - auto ff = gate->get_component_as([](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(gate->get_boolean_function().to_string())); - - Result result = BooleanFunction::Not(gate->get_boolean_function(), gate->get_boolean_function().size()); - if(result.is_ok()) - mNegatedInternalStatePropertyLabel->setText(QString::fromStdString(result.get().to_string())); - else{ - mNegatedInternalStatePropertyLabel->setText("ERROR"); - } - - } - else{ - qDebug() << "could not cast component to FFComponent"; - return; - } - - } - -} diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp index 43846ed9611..a2e3e3f94f1 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.cpp @@ -1,91 +1,44 @@ #include "gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h" - +#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" #include +#include namespace hal { - GateLibraryLabel::GateLibraryLabel(bool isVal, const QString& txt, QWidget *parent) - : QLabel(txt,parent) - { - mValue = isVal; - } - - GateLibraryTabGeneral::GateLibraryTabGeneral(QWidget* parent) : GateLibraryTabInterface(parent) + //--------------------- general frame --------------------------- + GatelibraryFrameGeneral::GatelibraryFrameGeneral(QWidget* parent) + : GatelibraryComponentFrame("General", parent) { - QVBoxLayout* layout = new QVBoxLayout(this); - mGeneralFrame = new QFrame(this); - mGeneralFrame->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); - mGeneralFrame->setFrameStyle(QFrame::Sunken | QFrame::Panel); - mGeneralFrame->setLineWidth(2); - QFormLayout* generalLayout = new QFormLayout(mGeneralFrame); - - mNamePropertyLabel = new GateLibraryLabel(true, " - ", mGeneralFrame); - mIdPropertyLabel = new GateLibraryLabel(true, " - ", mGeneralFrame); - mComponentPropertyLabel = new GateLibraryLabel(true, " - ", mGeneralFrame); - - generalLayout->addRow(new GateLibraryLabel(false, "General", mGeneralFrame)); - generalLayout->addRow(new GateLibraryLabel(false, "Name:", mGeneralFrame), mNamePropertyLabel); - generalLayout->addRow(new GateLibraryLabel(false, "ID:", mGeneralFrame), mIdPropertyLabel); - generalLayout->addRow(new GateLibraryLabel(false, "Component:", mGeneralFrame), mComponentPropertyLabel); - layout->addWidget(mGeneralFrame); + mNameLabel = new GateLibraryLabel(true, " - ", this); + mIdLabel = new GateLibraryLabel(true, " - ", this); + mPropertiesLabel = new GateLibraryLabel(true, " - ", this); - mFlipflopFrame = new QFrame(this); - mFlipflopFrame->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); - mFlipflopFrame->setFrameStyle(QFrame::Sunken | QFrame::Panel); - mFlipflopFrame->setLineWidth(2); - QFormLayout* flipflopLayout = new QFormLayout(mFlipflopFrame); - - mClockPropertyLabel = new GateLibraryLabel(true, " - ", mFlipflopFrame); - mNextStatePropertyLabel = new GateLibraryLabel(true, " - ", mFlipflopFrame); - mAsynchronousResetPropertyLabel = new GateLibraryLabel(true, " - ", mFlipflopFrame); - mInternalStatePropertyLabel = new GateLibraryLabel(true, " - ", mFlipflopFrame); - mNegatedInternalStatePropertyLabel = new GateLibraryLabel(true, " - ", mFlipflopFrame); - - flipflopLayout->addRow(new GateLibraryLabel(false, "Flip Flops", mFlipflopFrame)); - flipflopLayout->addRow(new GateLibraryLabel(false, "Clock:", parent), mClockPropertyLabel); - flipflopLayout->addRow(new GateLibraryLabel(false, "Next state:", parent), mNextStatePropertyLabel); - flipflopLayout->addRow(new GateLibraryLabel(false, "Asynchronous reset:", parent), mAsynchronousResetPropertyLabel); - flipflopLayout->addRow(new GateLibraryLabel(false, "Internal state:", parent), mInternalStatePropertyLabel); - flipflopLayout->addRow(new GateLibraryLabel(false, "Negated internal state:", parent), mNegatedInternalStatePropertyLabel); - layout->addWidget(mFlipflopFrame); - mFlipflopFrame->hide(); - - mBooleanFrame = new QFrame(this); - mBooleanFrame->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); - mBooleanFrame->setFrameStyle(QFrame::Sunken | QFrame::Panel); - mBooleanFrame->setLineWidth(2); - mBooleanLayout = new QFormLayout(mBooleanFrame); - mBooleanLayout->addRow(new GateLibraryLabel(false, "Boolean Functions", mBooleanFrame)); - //mBooleanLayout->addRow(new GateLibraryLabel(false, "O:", mBooleanFrame), mBooleanFunctionPropertyLabel); - layout->addWidget(mBooleanFrame); - mBooleanFrame->hide(); + mLayout->addRow(new GateLibraryLabel(false, "Name:", this), mNameLabel); + mLayout->addRow(new GateLibraryLabel(false, "ID:", this), mIdLabel); + mLayout->addRow(new GateLibraryLabel(false, "Properties:", this), mPropertiesLabel); } - void GateLibraryTabGeneral::update(GateType* gate) + void GatelibraryFrameGeneral::update(GateType *gt) { - - if(!gate){ - //TODO make default look - mNamePropertyLabel->setText("-"); - mIdPropertyLabel->setText("-"); - mComponentPropertyLabel->setText("-"); - mFlipflopFrame->hide(); - mBooleanFrame->hide(); - + if(!gt) + { + mNameLabel->setText("-"); + mIdLabel->setText("-"); + mPropertiesLabel->setText("-"); return; } - mNamePropertyLabel->setText(QString::fromStdString(gate->get_name())); - mIdPropertyLabel->setText(QString::number(gate->get_id())); + mNameLabel->setText(QString::fromStdString(gt->get_name())); + mIdLabel->setText(QString::number(gt->get_id())); // add properties QString properties = ""; bool first = true; - for (GateTypeProperty p : gate->get_property_list()) { + for (GateTypeProperty p : gt->get_property_list()) { //add \n before each property except the first if(first) first = false; @@ -94,71 +47,72 @@ namespace hal properties.append(QString::fromStdString(enum_to_string(p))); } - mComponentPropertyLabel->setText(properties); + mPropertiesLabel->setText(properties); + } - // add boolean functions for each output + //--------------------- boolean function frame ------------------ + GatelibraryFrameBoolean::GatelibraryFrameBoolean(QWidget* parent) + : GatelibraryComponentFrame("Boolean Functions", parent) + {;} + void GatelibraryFrameBoolean::update(GateType *gt) + { // Clear existing labels QLayoutItem* item; - while ((item = mBooleanLayout->takeAt(0)) != nullptr) { + while ((item = mLayout->takeAt(0)) != nullptr) { delete item->widget(); delete item; } - mBooleanLayout->insertRow(0, new GateLibraryLabel(false, "Boolean Functions", mBooleanFrame)); + mLayout->insertRow(0, new GateLibraryLabel(false, "Boolean Functions", this)); //add label and corresponding boolean function to the layout - auto boolFunctions = gate->get_boolean_functions(); + auto boolFunctions = gt->get_boolean_functions(); auto list = QList>(); + // add boolean functions for each output for(std::pair, BooleanFunction> bf : boolFunctions){ - GateLibraryLabel* label = new GateLibraryLabel(true, QString::fromStdString(bf.second.to_string()), mBooleanFrame); - mBooleanLayout->insertRow(1, new GateLibraryLabel(false, QString::fromStdString(bf.first), mBooleanFrame), label); + GateLibraryLabel* label = new GateLibraryLabel(true, QString::fromStdString(bf.second.to_string()), this); + mLayout->insertRow(1, new GateLibraryLabel(false, QString::fromStdString(bf.first), this), label); } if (boolFunctions.empty()) - mBooleanFrame->hide(); + hide(); else - mBooleanFrame->show(); + show(); + } - if (gate->has_component_of_type(GateTypeComponent::ComponentType::ff)) - { - auto ff = gate->get_component_as([](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(gate->get_boolean_function().to_string())); - - Result result = BooleanFunction::Not(gate->get_boolean_function(), gate->get_boolean_function().size()); - if(result.is_ok()) - mNegatedInternalStatePropertyLabel->setText(QString::fromStdString(result.get().to_string())); - else{ - mNegatedInternalStatePropertyLabel->setText("ERROR"); - } - mFlipflopFrame->show(); - } - else - mFlipflopFrame->hide(); - } - else - mFlipflopFrame->hide(); + //--------------------- tab widget with all component frames ---- + GateLibraryTabGeneral::GateLibraryTabGeneral(QWidget* parent) : GateLibraryTabInterface(parent) + { + QVBoxLayout* topLayout = new QVBoxLayout(this); + QScrollArea* scroll = new QScrollArea(this); // add scrollbar if needed + QVBoxLayout* layout = new QVBoxLayout(scroll); - QString in = " "; - QString out = " "; + mGeneralFrame = new GatelibraryFrameGeneral(this); + layout->addWidget(mGeneralFrame); - for(auto const& pin : gate->get_input_pin_names()){ - in += QString::fromStdString(pin) + "\n "; - } + mFlipflopFrame = new GatelibraryFrameFF(this); + layout->addWidget(mFlipflopFrame); + mFlipflopFrame->hide(); - for(auto const& pin : gate->get_output_pin_names()){ - out += QString::fromStdString(pin) + "\n "; - } + mBooleanFrame = new GatelibraryFrameBoolean(this); + layout->addWidget(mBooleanFrame); + mBooleanFrame->hide(); + topLayout->addWidget(scroll); } + void GateLibraryTabGeneral::update(GateType* gt) + { + mGeneralFrame->update(gt); + if(!gt){ + //TODO make default look + mFlipflopFrame->hide(); + mBooleanFrame->hide(); + return; + } - + mFlipflopFrame->update(gt); + mBooleanFrame->update(gt); + } } diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_boolean_function.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.cpp similarity index 70% rename from plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_boolean_function.cpp rename to plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.cpp index 195542d45f8..41f674dc7b2 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_boolean_function.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.cpp @@ -1,5 +1,5 @@ -#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/gui_globals.h" @@ -7,25 +7,26 @@ namespace hal { - GateLibraryTabBooleanFunction::GateLibraryTabBooleanFunction(QWidget* parent) : GateLibraryTabInterface(parent) + GateLibraryTabTruthTable::GateLibraryTabTruthTable(QWidget* parent) : GateLibraryTabInterface(parent) { - mLayout = new QGridLayout(parent); + mLayout = new QGridLayout(this); mTableWidget = new QTableWidget(); + mDisclaimer = new QLabel(this); + mDisclaimer->setAlignment(Qt::AlignCenter); + mLayout->addWidget(mDisclaimer); + mDisclaimer->hide(); mLayout->addWidget(mTableWidget); //mHeaderView = new QHeaderView(Qt::Horizontal); //mTableWidget->setHorizontalHeader(mHeaderView); - - - setLayout(mLayout); - } - void GateLibraryTabBooleanFunction::update(GateType* gate) + void GateLibraryTabTruthTable::update(GateType* gate) { if(gate) { + bool undefinedResult = false; if (getColumnNumber(gate)-1 > 8) { @@ -44,21 +45,21 @@ namespace hal std::vector outputs = gate->get_output_pin_names(); auto truthTable = boolFunc.compute_truth_table(inputs, false).get().at(0); - for (int column = 0; column < inputs.size(); column++) { + for (uint column = 0; column < inputs.size(); column++) { QTableWidgetItem* item = new QTableWidgetItem(QString::fromStdString(inputs[column])); mTableWidget->setItem(0, column, item); } - for (int column = inputs.size(); column < outputs.size()+inputs.size(); column++) { + for (uint column = inputs.size(); column < outputs.size()+inputs.size(); column++) { QTableWidgetItem* item = new QTableWidgetItem(QString::fromStdString(outputs[column-inputs.size()])); mTableWidget->setItem(0, column, item); } - for (int truthTableIdx = 0; truthTableIdx < truthTable.size(); truthTableIdx++) + for (uint truthTableIdx = 0; truthTableIdx < truthTable.size(); truthTableIdx++) { //iterate from 0..0 to 1..1 - for (int i = 0; i < gate->get_input_pins().size(); i++) + for (uint i = 0; i < gate->get_input_pins().size(); i++) { u32 shift = gate->get_input_pins().size() - i - 1; u8 inputBit = u8((truthTableIdx >> shift) & 1); @@ -98,18 +99,36 @@ namespace hal { QTableWidgetItem* item = new QTableWidgetItem("X"); mTableWidget->setItem(truthTableIdx+1, i, item); + undefinedResult = true; } } } + if (undefinedResult) + { + mDisclaimer->setText("Truth table calculation\nfor gate type <" + QString::fromStdString(gate->get_name()) + ">\nnot implemented so far"); + mDisclaimer->show(); + mTableWidget->hide(); + } + else + { + mDisclaimer->hide(); + mTableWidget->show(); + } + } + else + { + mDisclaimer->setText("No gate type selected"); + mDisclaimer->show(); + mTableWidget->hide(); } } - int GateLibraryTabBooleanFunction::getRowNumber(GateType* gate) + int GateLibraryTabTruthTable::getRowNumber(GateType* gate) { return pow(2, gate->get_input_pins().size())+1; //iterate from 0..0 to 2^n } - int GateLibraryTabBooleanFunction::getColumnNumber(GateType* gate) + int GateLibraryTabTruthTable::getColumnNumber(GateType* gate) { if(gate) {