Skip to content

Commit

Permalink
[CORRECTIVE] Implemented Uniqueness check for Memory Maps and Design …
Browse files Browse the repository at this point in the history
…Instantiation.
  • Loading branch information
VasiliiFeshchenko committed Aug 1, 2024
1 parent 3270d01 commit c521a21
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 34 deletions.
16 changes: 8 additions & 8 deletions Kactus2.pri
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ HEADERS += ./common/NameGenerationPolicy.h \
./common/widgets/TreeItemSelector/TreeItemEditor.h \
./common/widgets/TreeItemSelector/TreeItemModel.h \
./common/widgets/TreeItemSelector/FramedTreeItemEditor.h \
./common/widgets/GroupBoxWithAlertSign/StyleOptionGroupBoxWithAlertSign.h \
./common/widgets/GroupBoxWithAlertSign/GroupBoxWithAlertSign.h \
./common/widgets/GroupBoxWithAlertSign/StyleGroupBoxWithAlertSign.h \
./common/validators/LibraryPathValidator/librarypathvalidator.h \
./common/layouts/HCollisionLayout.h \
./common/layouts/HStackedLayout.h \
Expand Down Expand Up @@ -895,10 +898,7 @@ HEADERS += ./common/NameGenerationPolicy.h \
./PythonAPI/FileChannel.h \
./PythonAPI/PythonInterpreter.h \
./PythonAPI/StdInputListener.h \
./PythonAPI/extensions/IOCatcher.h \
./common/widgets/GroupBoxWithAlertSign/GroupBoxWithAlertSign.h \
./common/widgets/GroupBoxWithAlertSign/StyleGroupBoxWithAlertSign.h \
./common/widgets/GroupBoxWithAlertSign/StyleOptionGroupBoxWithAlertSign.h
./PythonAPI/extensions/IOCatcher.h
SOURCES += ./editors/ComponentEditor/busInterfaces/general/MasterModeEditor.cpp \
./common/GenericEditProvider.cpp \
./common/NameGenerationPolicy.cpp \
Expand Down Expand Up @@ -971,6 +971,9 @@ SOURCES += ./editors/ComponentEditor/busInterfaces/general/MasterModeEditor.cpp
./common/widgets/TreeItemSelector/FramedTreeItemEditor.cpp \
./common/widgets/TreeItemSelector/TreeItemEditor.cpp \
./common/widgets/TreeItemSelector/TreeItemModel.cpp \
./common/widgets/GroupBoxWithAlertSign/GroupBoxWithAlertSign.cpp \
./common/widgets/GroupBoxWithAlertSign/StyleGroupBoxWithAlertSign.cpp \
./common/widgets/GroupBoxWithAlertSign/StyleOptionGroupBoxWithAlertSign.cpp \
./common/graphicsItems/GraphicsColumnAddCommand.cpp \
./common/graphicsItems/CommonGraphicsUndoCommands.cpp \
./common/graphicsItems/ComponentItem.cpp \
Expand Down Expand Up @@ -1687,8 +1690,5 @@ SOURCES += ./editors/ComponentEditor/busInterfaces/general/MasterModeEditor.cpp
./PythonAPI/FileChannel.cpp \
./PythonAPI/PythonInterpreter.cpp \
./PythonAPI/StdInputListener.cpp \
./PythonAPI/extensions/IOCatcher.cpp \
./common/widgets/GroupBoxWithAlertSign/StyleGroupBoxWithAlertSign.cpp \
./common/widgets/GroupBoxWithAlertSign/StyleOptionGroupBoxWithAlertSign.cpp \
./common/widgets/GroupBoxWithAlertSign/GroupBoxWithAlertSign.cpp
./PythonAPI/extensions/IOCatcher.cpp
RESOURCES += kactus.qrc
10 changes: 7 additions & 3 deletions KactusAPI/KactusAPI.pri
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# This file is generated by the Qt Visual Studio Tools.
# ------------------------------------------------------

# This is a reminder that you are using a generated .pro file.
# Remove it when you are finished editing this file.
message("You are running qmake on a generated .pro file. This may not work!")


HEADERS += ./KactusAPI.h \
./KactusAPIGlobal.h \
./include/AbstractionTypeInterface.h \
Expand Down Expand Up @@ -89,10 +94,9 @@ HEADERS += ./KactusAPI.h \
./include/ImportRunner.h \
./include/LibraryHandler.h \
./include/LibraryItem.h \
./include/LibraryLoader.h \
./include/LibraryTreeModel.h \
./include/ParameterCache.h \
./include/NullChannel.h
../../temp/31.07.24/ItemNamesGetterInterface.h
SOURCES += ./KactusAPI.cpp \
./expressions/AddressBlockExpressionsGatherer.cpp \
./expressions/AddressSpaceExpressionsGatherer.cpp \
Expand Down Expand Up @@ -163,4 +167,4 @@ SOURCES += ./KactusAPI.cpp \
./library/LibraryLoader.cpp \
./library/LibraryTreeModel.cpp \
./library/TagManager.cpp \
./utilities/NullChannel.cpp
../../temp/31.07.24/ItemNamesGetterInterface.cpp
2 changes: 2 additions & 0 deletions KactusAPI/KactusAPI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\ItemNamesGetterInterface.h" />
<ClInclude Include="include\AbstractionTypeInterface.h" />
<ClInclude Include="include\AbstractParameterInterface.h" />
<ClInclude Include="include\AccessPolicyInterface.h" />
Expand Down Expand Up @@ -104,6 +105,7 @@
<ClInclude Include="KactusAPIGlobal.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="interfaces\common\ItemNamesGetterInterface.cpp" />
<ClCompile Include="expressions\AddressBlockExpressionsGatherer.cpp" />
<ClCompile Include="expressions\AddressSpaceExpressionsGatherer.cpp" />
<ClCompile Include="expressions\ComponentAndInstantiationsParameterFinder.cpp" />
Expand Down
18 changes: 15 additions & 3 deletions KactusAPI/KactusAPI.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@
<ClInclude Include="include\ModeReferenceInterface.h">
<Filter>Header Files\include</Filter>
</ClInclude>
<ClInclude Include="include\LibraryLoader.h">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="include\NullChannel.h">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="include\ItemNamesGetterInterface.h">
<Filter>Header Files\include</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="utilities\ConsoleMediator.cpp">
Expand Down Expand Up @@ -503,6 +512,12 @@
<ClCompile Include="interfaces\component\AccessPolicyInterface.cpp">
<Filter>Source Files\interfaces\component</Filter>
</ClCompile>
<ClCompile Include="utilities\NullChannel.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="interfaces\common\ItemNamesGetterInterface.cpp">
<Filter>Source Files\interfaces\common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\ComponentInstanceInterface.h">
Expand Down Expand Up @@ -537,9 +552,6 @@
<QtMoc Include="include\LibraryItem.h">
<Filter>Header Files\include</Filter>
</QtMoc>
<QtMoc Include="include\LibraryLoader.h">
<Filter>Header Files\include</Filter>
</QtMoc>
<QtMoc Include="include\ComponentInstanceParameterFinder.h">
<Filter>Header Files\include</Filter>
</QtMoc>
Expand Down
9 changes: 6 additions & 3 deletions KactusAPI/include/CommonInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class KACTUS2_API CommonInterface
*/
CommonInterface() = default;

/*!
/*!
* The destructor.
*/
virtual ~CommonInterface() = default;
Expand Down Expand Up @@ -60,6 +60,8 @@ class KACTUS2_API CommonInterface
CommonInterface(const CommonInterface& other) = delete;
CommonInterface& operator=(const CommonInterface& other) = delete;

bool isNameUnique(std::string newName, std::string* previousName = nullptr) const;

protected:

/*!
Expand All @@ -86,11 +88,12 @@ class KACTUS2_API CommonInterface
/*!
* Check if the selected name is unique.
*
* @param [in] portName The selected name.
* @param [in] name The selected name.
* @param [in] reservedNames Names that are already in use
*
* @return True, if the selected name is unique, false otherwise.
*/
bool nameIsUnique(std::string_view name, std::vector<std::string> const& reservedNamed) const;
bool isNameUniqueInCollection(std::string_view name, std::vector<std::string> const& reservedNames) const;
};

#endif // COMMONINTERFACE_H
22 changes: 18 additions & 4 deletions KactusAPI/interfaces/common/CommonInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@

#include "CommonInterface.h"

bool CommonInterface::isNameUnique(std::string name, std::string* previousName) const
{
auto items = getItemNames();
if (previousName)
{
auto it = std::find(items.begin(), items.end(), *previousName);
if (it != items.end())
{
items.erase(it);
}
}
return isNameUniqueInCollection(name.c_str(), items);
}

//-----------------------------------------------------------------------------
// Function: CommonInterface::getUniqueName()
//-----------------------------------------------------------------------------
Expand All @@ -25,7 +39,7 @@ QString CommonInterface::getUniqueName(std::string const& newName, std::string c
std::string name = referenceName;
int runningNumber = 0;
auto const items = getItemNames();
while (!nameIsUnique(name, items))
while (!isNameUniqueInCollection(name, items))
{
name = referenceName + "_" + std::to_string(runningNumber);
runningNumber++;
Expand All @@ -43,9 +57,9 @@ bool CommonInterface::nameHasChanged(std::string const& newName, std::string con
}

//-----------------------------------------------------------------------------
// Function: CommonInterface::nameIsUnique()
// Function: CommonInterface::isNameUniqueInCollection()
//-----------------------------------------------------------------------------
bool CommonInterface::nameIsUnique(std::string_view name, std::vector<std::string> const& reservedNamed) const
bool CommonInterface::isNameUniqueInCollection(std::string_view name, std::vector<std::string> const& reservedNames) const
{
return std::find(reservedNamed.cbegin(), reservedNamed.cend(), name) == reservedNamed.cend();
return std::find(reservedNames.cbegin(), reservedNames.cend(), name) == reservedNames.cend();
}
42 changes: 39 additions & 3 deletions common/widgets/nameGroupEditor/namegroupeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include <QLabel>
#include <QGridLayout>
#include <CommonInterface.h>
#include "QMessageBox"
#include "QCoreApplication"

//-----------------------------------------------------------------------------
// Function: NameGroupEditor::NameGroupEditor()
Expand All @@ -30,9 +33,9 @@ QGroupBox(title, parent),
shortDescriptionEdit_.setVisible(docRevision == Document::Revision::Std22);
setupLayout(docRevision);

connect(&nameEdit_, SIGNAL(textEdited(QString const&)),
this, SLOT(onNameChanged(QString const&)), Qt::UniqueConnection);
connect(&nameEdit_, SIGNAL(editingFinished()), this, SIGNAL(nameChanged()), Qt::UniqueConnection);
connect(&nameEdit_, SIGNAL(editingFinished()),
this, SLOT(onNameEditingFinished()), Qt::UniqueConnection);
//connect(&nameEdit_, SIGNAL(editingFinished()), this, SIGNAL(nameChanged()), Qt::UniqueConnection);
connect(&displayNameEdit_, SIGNAL(textEdited(QString const&)),
this, SLOT(onDisplayNameChanged(QString const&)), Qt::UniqueConnection);
connect(&shortDescriptionEdit_, SIGNAL(textEdited(QString const&)),
Expand All @@ -41,6 +44,11 @@ QGroupBox(title, parent),
this, SLOT(onDescriptionChanged()), Qt::UniqueConnection);
}

NameGroupEditor::NameGroupEditor(QSharedPointer<NameGroup> nameGroup, Document::Revision docRevision, QWidget* parent, QSharedPointer <CommonInterface> interface, QString const& title) : NameGroupEditor(nameGroup,docRevision,parent,title)
{
interface_ = interface;
}

//-----------------------------------------------------------------------------
// Function: NameGroupEditor::~NameGroupEditor()
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -135,6 +143,34 @@ void NameGroupEditor::refresh()
connect(&descriptionEdit_, SIGNAL(textChanged()), this, SLOT(onDescriptionChanged()), Qt::UniqueConnection);
}

void NameGroupEditor::onNameEditingFinished()
{
QString newName = nameEdit_.text();
if (interface_)
{
std::string currentName = name().toStdString();
if (interface_->isNameUnique(newName.toStdString(), &currentName))
{
nameGroup_->setName(newName);
emit contentChanged();
emit nameChanged();
}
else
{
QMessageBox msgBox(QMessageBox::Critical, QCoreApplication::applicationName(),
tr("The name %1 is not unique. Do you want to continue editing?").arg(newName), QMessageBox::Ok, this);
msgBox.exec();
nameEdit_.setFocus();
}
}
else
{
nameGroup_->setName(newName);
emit contentChanged();
emit nameChanged();
}
}

//-----------------------------------------------------------------------------
// Function: NameGroupEditor::setupLayout()
//-----------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions common/widgets/nameGroupEditor/namegroupeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QString>
#include <CommonInterface.h>

/*! Editor to edit the details of a NameGroup-struct.
*
Expand All @@ -32,6 +33,12 @@ class NameGroupEditor : public QGroupBox {
QWidget *parent,
QString const& title = QString("Names"));

NameGroupEditor(QSharedPointer<NameGroup> nameGroup,
Document::Revision docRevision,
QWidget* parent,
QSharedPointer <CommonInterface> interface_,
QString const& title = QString("Names"));

//! The destructor
virtual ~NameGroupEditor();

Expand Down Expand Up @@ -107,6 +114,8 @@ private slots:
*/
void onDescriptionChanged();

void onNameEditingFinished();

private:
//! Setup the widget layout.
void setupLayout(Document::Revision docRevision);
Expand All @@ -125,6 +134,9 @@ private slots:

//! Editor to write the description.
QPlainTextEdit descriptionEdit_;

QSharedPointer<CommonInterface> interface_;

};

#endif // NAMEGROUPEDITOR_H
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <editors/ComponentEditor/parameters/ComponentParameterModel.h>

#include <KactusAPI/include/LibraryInterface.h>
#include <KactusAPI/include/ItemNamesGetterInterface.h>

#include <IPXACTmodels/Component/Component.h>
#include <IPXACTmodels/Design/Design.h>
Expand All @@ -40,7 +41,11 @@ DesignInstantiationEditor::DesignInstantiationEditor(QSharedPointer<Component> c
QSharedPointer<ParameterFinder> componentParameterFinder, QWidget* parent):
ItemEditor(component, libHandler, parent),
instantiation_(instantiation),
nameGroupEditor_(new NameGroupEditor(instantiation, component->getRevision(), this, tr("Design instance name and description"))),
nameGroupEditor_(new NameGroupEditor(instantiation,
component->getRevision(),
this,
QSharedPointer<ItemNamesGetterInterface<DesignInstantiation>>(new ItemNamesGetterInterface<DesignInstantiation>(component->getDesignInstantiations())),
tr("Design instance name and description"))),
designEditor_(0),
elementEditor_(0),
designParameterFinder_(new ListParameterFinder())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SingleMemoryMapEditor::SingleMemoryMapEditor(QSharedPointer<Component> component
QSharedPointer<ParameterFinder> parameterFinder, QSharedPointer<ExpressionParser> expressionParser,
MemoryMapInterface* mapInterface, bool isMemoryRemap, QWidget* parent):
ItemEditor(component, libHandler, parent),
nameEditor_(memoryRemap, component->getRevision(), this),
nameEditor_(memoryRemap, component->getRevision(), this, QSharedPointer<MemoryMapInterface>(mapInterface)),
addressBlockEditor_(new MemoryMapEditor(component, libHandler, parameterFinder, expressionParser,
mapInterface->getAddressBlockInterface(), memoryRemap->getMemoryBlocks(), this)),
subspaceMapEditor_(new SubspaceMapsEditor(component, parameterFinder, expressionParser,
Expand Down
16 changes: 8 additions & 8 deletions version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
#ifndef VERSIONNO__H
#define VERSIONNO__H

#define VERSION_FULL 3.13.537.0
#define VERSION_FULL 3.13.542.0

#define VERSION_BASEYEAR 0
#define VERSION_DATE "2024-07-15"
#define VERSION_TIME "23:00:17"
#define VERSION_DATE "2024-08-01"
#define VERSION_TIME "16:40:44"

#define VERSION_MAJOR 3
#define VERSION_MINOR 13
#define VERSION_BUILDNO 537
#define VERSION_BUILDNO 542
#define VERSION_EXTEND 0

#define VERSION_FILE 3,13,537,0
#define VERSION_PRODUCT 3,13,537,0
#define VERSION_FILESTR "3,13,537,0"
#define VERSION_PRODUCTSTR "3,13,537,0"
#define VERSION_FILE 3,13,542,0
#define VERSION_PRODUCT 3,13,542,0
#define VERSION_FILESTR "3,13,542,0"
#define VERSION_PRODUCTSTR "3,13,542,0"

#endif

0 comments on commit c521a21

Please sign in to comment.