Skip to content

Commit

Permalink
Bugfixes and implementation of dndPinBetweenGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Sep 29, 2023
1 parent 05890be commit bcaca5d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace hal

public:

PortTreeItem(Type itype, QString pinName, PinDirection dir, PinType ptype, QString netName = QString());
PortTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, QString netName = QString());
PortTreeItem() : mItemType(None), mId(0) {;}
QVariant getData(int column) const override;
void setData(QList<QVariant> data) override;
Expand All @@ -61,7 +61,6 @@ namespace hal
int getColumnCount() const override;
void setItemType(Type tp) { mItemType = tp; }
Type itemType() const { return mItemType; }
void setId(u32 id_) { mId = id_; }
QString name() const { return mPinName; }
void setName(const QString& nam) { mPinName = nam; }
void setPinType(PinType ptype) { mPinType = ptype; }
Expand Down
10 changes: 6 additions & 4 deletions plugins/gui/include/gui/user_action/action_pingroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace hal

int pinRow2Index(const ModulePin* pin, int row);

QString generateGroupName(const Module* mod, const ModulePin* pin);

void dumpPingroups(Module* m = nullptr);
/**
* @ingroup user_action
Expand Down Expand Up @@ -154,10 +156,10 @@ namespace hal
void readFromXml(QXmlStreamReader& xmlIn) override;
void addToHash(QCryptographicHash& cryptoHash) const override;

static ActionPingroup* addPinsToExistingGroup(const Module* m, u32 grpId, QList<u32> pinIds, int irow = -1);
static ActionPingroup* addPinToExistingGroup(const Module* m, u32 grpId, u32 pinId, int irow = -1);
static ActionPingroup* addPinsToNewGroup(const Module* m, const QString& name, QList<u32> pinIds);
static ActionPingroup* addPinToNewGroup(const Module* m, const QString& name, u32 pinId);
static ActionPingroup* addPinsToExistingGroup(const Module* m, u32 grpId, QList<u32> pinIds, int pinRow = -1);
static ActionPingroup* addPinToExistingGroup(const Module* m, u32 grpId, u32 pinId, int pinRow = -1);
static ActionPingroup* addPinsToNewGroup(const Module* m, const QString& name, QList<u32> pinIds, int grpRow = -1);
static ActionPingroup* addPinToNewGroup(const Module* m, const QString& name, u32 pinId, int grpRow = -1);
static ActionPingroup* removePinsFromGroup(const Module* m, QList<u32> pinIds);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

namespace hal
{
PortTreeItem::PortTreeItem(Type itype, QString pinName, PinDirection dir, PinType ptype, QString netName)
: mItemType(itype), mPinName(pinName), mPinDirection(dir), mPinType(ptype), mNetName(netName)
PortTreeItem::PortTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, QString netName)
: mItemType(itype), mId(id_), mPinName(pinName), mPinDirection(dir), mPinType(ptype), mNetName(netName)
{;}

QVariant PortTreeItem::getData(int index) const
Expand Down Expand Up @@ -145,6 +145,7 @@ namespace hal
data->setData("pintreemodel/item", encodedData);
return data;
}

bool ModulePinsTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
{
Q_UNUSED(action)
Expand All @@ -154,6 +155,7 @@ namespace hal
int id;
QByteArray encItem = data->data("pintreemodel/item");
QDataStream dataStream(&encItem, QIODevice::ReadOnly);
qDebug() << "dropMimeData" << encItem << row << column;
dataStream >> type >> id;

auto droppedItem = (type == "group") ? static_cast<PortTreeItem*>(mIdToGroupItem.value(id)) : static_cast<PortTreeItem*>(mIdToPinItem.value(id));
Expand Down Expand Up @@ -405,17 +407,16 @@ namespace hal
continue;

auto pinGroupName = QString::fromStdString(pinGroup->get_name());
PortTreeItem* pinGroupItem = new PortTreeItem(PortTreeItem::Group,pinGroupName, pinGroup->get_direction(), pinGroup->get_type());
pinGroupItem->setId(pinGroup->get_id());
PortTreeItem* pinGroupItem = new PortTreeItem(PortTreeItem::Group, pinGroup->get_id(), pinGroupName, pinGroup->get_direction(), pinGroup->get_type());
mIdToGroupItem.insert(pinGroup->get_id(), pinGroupItem);
for(ModulePin* pin : pinGroup->get_pins())
{
PortTreeItem* pinItem = new PortTreeItem(PortTreeItem::Pin,
pin->get_id(),
QString::fromStdString(pin->get_name()),
pin->get_direction(),
pin->get_type(),
QString::fromStdString(pin->get_net()->get_name()));
pinItem->setId(pin->get_id());
pinGroupItem->appendChild(pinItem);
mNameToTreeItem.insert(QString::fromStdString(pin->get_name()), pinItem);
mIdToPinItem.insert(pin->get_id(), pinItem);
Expand Down Expand Up @@ -559,9 +560,11 @@ namespace hal
case PinEvent::GroupCreate:
{
ptiGroup = new PortTreeItem(PortTreeItem::Group,
pgroup->get_id(),
QString::fromStdString(pgroup->get_name()),
pgroup->get_direction(),
pgroup->get_type());
mIdToGroupItem.insert(ptiGroup->id(), ptiGroup);
int inx = pinGroupIndex(m,pgroup);
insertItem(ptiGroup, mRootItem, inx);
break;
Expand Down Expand Up @@ -600,11 +603,12 @@ namespace hal
if (pin->get_net())
netName = QString::fromStdString(pin->get_net()->get_name());
ptiPin = new PortTreeItem(PortTreeItem::Pin,
pin->get_id(),
QString::fromStdString(pin->get_name()),
pin->get_direction(),
pin->get_type(),
netName);

mIdToPinItem.insert(ptiPin->id(), ptiPin);
insertItem(ptiPin, ptiGroup, pinRow);
break;
}
Expand Down Expand Up @@ -726,39 +730,10 @@ namespace hal
auto pinToMove = mModule->get_pin_by_id(droppedPin->id());
if (!pinToMove) return;

QString groupName = QString::fromStdString(pinToMove->get_name());
QString baseName = groupName;
int cnt = 2;
while (mModule->get_pin_group_by_name(groupName.toStdString()))
// pin group name already exists
groupName = QString("%1_%2").arg(baseName).arg(cnt++);
/*
ActionPingroup* actMovePin = new ActionPingroup(pinToMove->get_id(),0,0,groupName);
actMovePin->setObject(UserActionObject(mModuleId, UserActionObjectType::Module));
bool ok = actMovePin->exec();
if (ok && actMovePin->targetGroupId())
{
ActionPingroup* actMoveGroup = new ActionPingroup(PinAction::MoveGroup,actMovePin->targetGroupId());
actMoveGroup->setObject(UserActionObject(mModuleId, UserActionObjectType::Module));
actMoveGroup->setPinOrderNo(row);
actMoveGroup->exec();
auto newGroup = mModule->get_pin_by_id(getIdOfItem(droppedPin))->get_group().first;
auto pinGroupName = QString::fromStdString(newGroup->get_name());
auto pinGroupDirection = QString::fromStdString(enum_to_string((newGroup->get_direction())));
auto pinGroupType = QString::fromStdString(enum_to_string(newGroup->get_type()));
QString groupName = generateGroupName(mModule,pinToMove);

PortTreeItem* pinGroupItem = new PortTreeItem(pinGroupName, pinGroupDirection, pinGroupType, "");
pinGroupItem->setAdditionalData(keyType, QVariant::fromValue(itemType::group));
pinGroupItem->setAdditionalData(keyId, newGroup->get_id());
int pos = mRootItem->getChildCount(); // or query current index
insertItem(pinGroupItem, mRootItem, pos);
removeItem(droppedPin);
insertItem(droppedPin, pinGroupItem, 0);
}
*/
ActionPingroup* act = ActionPingroup::addPinToNewGroup(mModule, groupName, droppedPin->id(),row);
act->exec();
}

void ModulePinsTreeModel::insertItem(PortTreeItem* item, BaseTreeItem* parent, int index)
Expand Down
32 changes: 24 additions & 8 deletions plugins/gui/src/user_action/action_pingroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ namespace hal
return pg.first->get_start_index() - row;
}

QString generateGroupName(const Module* mod, const ModulePin* pin)
{
QString baseName = QString::fromStdString(pin->get_name());
QSet<QString> existingGroups;
for (auto g : mod->get_pin_groups())
existingGroups.insert(QString::fromStdString(g->get_name()));
QString retval = baseName;
int count = 1;
while (existingGroups.contains(retval))
retval = QString("%1_%2").arg(baseName).arg(++count);
return retval;
}

QString PinActionType::toString(PinActionType::Type tp)
{
QMetaEnum me = QMetaEnum::fromType<Type>();
Expand Down Expand Up @@ -412,7 +425,7 @@ namespace hal
return UserAction::exec();
}

ActionPingroup* ActionPingroup::addPinsToExistingGroup(const Module *m, u32 grpId, QList<u32> pinIds, int irow)
ActionPingroup* ActionPingroup::addPinsToExistingGroup(const Module *m, u32 grpId, QList<u32> pinIds, int pinRow)
{
ActionPingroup* retval = nullptr;
for (u32 pinId : pinIds)
Expand All @@ -421,21 +434,21 @@ namespace hal
retval->mPinActions.append(AtomicAction(PinActionType::PinAsignGroup,pinId,"",grpId));
else
retval = new ActionPingroup(PinActionType::PinAsignGroup,pinId,"",grpId);
if (irow >= 0)
retval->mPinActions.append(AtomicAction(PinActionType::PinSetindex,pinId,"",irow++));
if (pinRow >= 0)
retval->mPinActions.append(AtomicAction(PinActionType::PinSetindex,pinId,"",pinRow++));
}
retval->setObject(UserActionObject(m->get_id(),UserActionObjectType::Module));
return retval;
}

ActionPingroup* ActionPingroup::addPinToExistingGroup(const Module* m, u32 grpId, u32 pinId, int irow)
ActionPingroup* ActionPingroup::addPinToExistingGroup(const Module* m, u32 grpId, u32 pinId, int pinRow)
{
QList<u32> pinIds;
pinIds << pinId;
return addPinsToExistingGroup(m,grpId,pinIds,irow);
return addPinsToExistingGroup(m,grpId,pinIds,pinRow);
}

ActionPingroup* ActionPingroup::addPinsToNewGroup(const Module* m, const QString& name, QList<u32> pinIds)
ActionPingroup* ActionPingroup::addPinsToNewGroup(const Module* m, const QString& name, QList<u32> pinIds, int grpRow)
{
static int vid = -9;
ActionPingroup* retval = new ActionPingroup(PinActionType::GroupCreate,vid,name);
Expand All @@ -450,15 +463,18 @@ namespace hal
}
for (u32 pinId : pinIds)
retval->mPinActions.append(AtomicAction(PinActionType::PinAsignGroup,pinId,"",vid));

if (grpRow >= 0)
retval->mPinActions.append(AtomicAction(PinActionType::GroupMove,vid,"",grpRow));
retval->setObject(UserActionObject(m->get_id(),UserActionObjectType::Module));
return retval;
}

ActionPingroup* ActionPingroup::addPinToNewGroup(const Module *m, const QString& name, u32 pinId)
ActionPingroup* ActionPingroup::addPinToNewGroup(const Module *m, const QString& name, u32 pinId, int grpRow)
{
QList<u32> pinIds;
pinIds << pinId;
return addPinsToNewGroup(m,name,pinIds);
return addPinsToNewGroup(m,name,pinIds, grpRow);
}

ActionPingroup* ActionPingroup::removePinsFromGroup(const Module* m, QList<u32> pinIds)
Expand Down

0 comments on commit bcaca5d

Please sign in to comment.