diff --git a/include/hal_core/netlist/gate_library/enums/pin_type.h b/include/hal_core/netlist/gate_library/enums/pin_type.h index 6f8b660ad07..9f595c660ad 100644 --- a/include/hal_core/netlist/gate_library/enums/pin_type.h +++ b/include/hal_core/netlist/gate_library/enums/pin_type.h @@ -72,4 +72,7 @@ namespace hal PinDirChange, PinDelete }; + + template<> + std::map EnumStrings::data; } // namespace hal diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h index 938f683caa0..52604b5dd51 100644 --- a/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h @@ -50,8 +50,6 @@ namespace hal PinType mPinType; QString mNetName; - void setPinType(const QString& type); - void setPinDirection(const QString& dir); public: PortTreeItem(Type itype, QString pinName, PinDirection dir, PinType ptype, QString netName = QString()); diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp index edaa73f4917..4263aea1c22 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp @@ -39,32 +39,12 @@ namespace hal return QVariant(); } - void PortTreeItem::setPinType(const QString& type) - { - mPinType = PinType::none; - for (int pt = 1; pt < (int) PinType::sum; ++pt) - { - if (QString::fromStdString(enum_to_string((PinType)pt)) == type) - mPinType = (PinType)pt; - } - } - - void PortTreeItem::setPinDirection(const QString& dir) - { - mPinDirection = PinDirection::none; - for (int pd = 1; pd <= (int) PinDirection::internal; ++pd) - { - if (QString::fromStdString(enum_to_string((PinDirection)pd)) == dir) - mPinDirection = (PinDirection)pd; - } - } - void PortTreeItem::setData(QList data) { - mPinName = data[0].toString(); - setPinDirection(data[1].toString()); - setPinType(data[2].toString()); - mNetName = data[3].toString(); + mPinName = data[0].toString(); + mPinDirection = enum_from_string(data[1].toString().toStdString()); + mPinType = enum_from_string(data[2].toString().toStdString()); + mNetName = data[3].toString(); } void PortTreeItem::setDataAtIndex(int index, QVariant &data) @@ -75,10 +55,10 @@ namespace hal mPinName = data.toString(); break;} case 1: { - setPinDirection(data.toString()); + mPinDirection = enum_from_string(data.toString().toStdString()); break;} case 2: { - setPinType(data.toString()); + mPinType = enum_from_string(data.toString().toStdString()); break;} case 3: { mNetName = data.toString(); @@ -361,7 +341,7 @@ namespace hal QDataStream dataStream(&encItem, QIODevice::ReadOnly); dataStream >> type >> id; auto parentItem = static_cast(getItemFromIndex(parent)); - qDebug() << "type: " << type << ", id" << id << ", row: " << row; + // qDebug() << "type: " << type << ", id" << id << ", row: " << row; // construct a "drop-matrix" here, but only 4(5) things are NOT allowed (so check for these): // 1: drop a pin on its OWN parent @@ -530,40 +510,50 @@ namespace hal Q_UNUSED(pgid); if ((int)m->get_id() != mModuleId) return; + log_info("gui", "Handle pin_changed event {} ID={}", enum_to_string(pev), pgid); PortTreeItem* ptiPin = nullptr; PortTreeItem* ptiGroup = nullptr; const PinGroup* pgroup = nullptr; const ModulePin* pin = nullptr; int pinRow = -1; + if (pev < PinEvent::PinCreate) { // group event ptiGroup = mIdToGroupItem.value(pgid); - pgroup = m->get_pin_group_by_id(pgid); - if (!pgroup) + if (pev != PinEvent::GroupDelete) { - log_warning("gui", "Cannot handle event for pin group ID={}, no such group.", pgid); - return; + pgroup = m->get_pin_group_by_id(pgid); + if (!pgroup) + { + log_warning("gui", "Cannot handle event for pin group ID={}, no such group.", pgid); + return; + } } } else { // pin event ptiPin = mIdToPinItem.value(pgid); - pin = m->get_pin_by_id(pgid); - if (!pin) + if (pev != PinEvent::PinDelete) { - log_warning("gui", "Cannot handle event for pin ID={}, no such pid.", pgid); - return; + pin = m->get_pin_by_id(pgid); + if (!pin) + { + log_warning("gui", "Cannot handle event for pin ID={}, no such pid.", pgid); + return; + } + auto pgPair = pin->get_group(); + pgroup = pgPair.first; + pinRow = pgPair.second; + if (pgroup) + ptiGroup = mIdToGroupItem.value(pgroup->get_id()); } - auto pgPair = pin->get_group(); - pgroup = pgPair.first; - pinRow = pgPair.second; - if (pgroup) - ptiGroup = mIdToGroupItem.value(pgroup->get_id()); } + QModelIndex dataChangedIndex; + switch (pev) { case PinEvent::GroupCreate: @@ -585,12 +575,15 @@ namespace hal } case PinEvent::GroupRename: ptiGroup->setName(QString::fromStdString(pgroup->get_name())); + dataChangedIndex = getIndexFromItem(ptiGroup); break; case PinEvent::GroupTypeChange: ptiGroup->setPinType(pgroup->get_type()); + dataChangedIndex = getIndexFromItem(ptiGroup); break; case PinEvent::GroupDirChange: ptiGroup->setPinDirection(pgroup->get_direction()); + dataChangedIndex = getIndexFromItem(ptiGroup); break; case PinEvent::GroupDelete: removeItem(ptiGroup); @@ -639,12 +632,15 @@ namespace hal } case PinEvent::PinRename: ptiPin->setName(QString::fromStdString(pin->get_name())); + dataChangedIndex = getIndexFromItem(ptiPin); break; case PinEvent::PinTypeChange: ptiPin->setPinType(pin->get_type()); + dataChangedIndex = getIndexFromItem(ptiPin); break; case PinEvent::PinDirChange: ptiPin->setPinDirection(pin->get_direction()); + dataChangedIndex = getIndexFromItem(ptiPin); break; case PinEvent::PinDelete: removeItem(ptiPin); @@ -653,6 +649,12 @@ namespace hal default: break; } + + if (dataChangedIndex.isValid()) + { + QModelIndex inxLastCol = createIndex(dataChangedIndex.row(),columnCount()-1,dataChangedIndex.internalPointer()); + Q_EMIT dataChanged(dataChangedIndex,inxLastCol); + } } void ModulePinsTreeModel::dndGroupOnGroup(BaseTreeItem *droppedGroup, BaseTreeItem *onDroppedGroup) @@ -684,24 +686,13 @@ namespace hal if(ownRow < row && !bottomEdge) desiredIdx--; ActionPingroup* act = new ActionPingroup(PinActionType::GroupMove,droppedGroup->id(),"",desiredIdx); act->setObject(UserActionObject(mModuleId,UserActionObjectType::Module)); - bool ok = act->exec(); - if(ok){ - removeItem(droppedGroup); - insertItem(droppedGroup, mRootItem, desiredIdx); - } + act->exec(); } void ModulePinsTreeModel::dndPinOnGroup(PortTreeItem *droppedPin, BaseTreeItem *onDroppedGroup) { ActionPingroup* act = new ActionPingroup(PinActionType::PinAsignGroup,droppedPin->id(),"",static_cast(onDroppedGroup)->id()); act->exec(); - auto oldParent = droppedPin->getParent(); - removeItem(droppedPin); - insertItem(droppedPin, onDroppedGroup, onDroppedGroup->getChildCount()); - if(!(oldParent->getChildCount())){ - removeItem(static_cast(oldParent)); - delete oldParent; - } } void ModulePinsTreeModel::dndPinBetweenPin(PortTreeItem *droppedPin, BaseTreeItem *onDroppedParent, int row) @@ -723,13 +714,6 @@ namespace hal } act->setObject(UserActionObject(mModuleId,UserActionObjectType::Module)); act->exec(); - auto oldParent = droppedPin->getParent(); - removeItem(droppedPin); - insertItem(droppedPin, onDroppedParent, desiredIdx); - if(!(oldParent->getChildCount())){ - removeItem(static_cast(oldParent)); - delete oldParent; - } } void ModulePinsTreeModel::dndPinBetweenGroup(PortTreeItem *droppedPin, int row) diff --git a/src/netlist/gate_library/enums/pin_type.cpp b/src/netlist/gate_library/enums/pin_type.cpp index e39bee1b366..b9e9c01a296 100644 --- a/src/netlist/gate_library/enums/pin_type.cpp +++ b/src/netlist/gate_library/enums/pin_type.cpp @@ -19,4 +19,22 @@ namespace hal {PinType::select, "select"}, {PinType::carry, "carry"}, {PinType::sum, "sum"}}; -} \ No newline at end of file + + template<> + std::map EnumStrings::data = { + {PinEvent::unknown, "unknown"}, + {PinEvent::GroupCreate, "GroupCreate"}, + {PinEvent::GroupReorder, "GroupReorder"}, + {PinEvent::GroupRename, "GroupRename"}, + {PinEvent::GroupTypeChange, "GroupTypeChange"}, + {PinEvent::GroupDirChange, "GroupDirChange"}, + {PinEvent::GroupDelete, "GroupDelete"}, + {PinEvent::PinCreate, "PinCreate"}, + {PinEvent::PinReorder, "PinReorder"}, + {PinEvent::PinAssignToGroup, "PinAssignToGroup"}, + {PinEvent::PinRename, "PinRename"}, + {PinEvent::PinTypeChange, "PinTypeChange"}, + {PinEvent::PinDirChange, "PinDirChange"}, + {PinEvent::PinDelete, "PinDelete"} + }; +} diff --git a/src/netlist/module.cpp b/src/netlist/module.cpp index f65fd5d8c54..5c9fc41aedd 100644 --- a/src/netlist/module.cpp +++ b/src/netlist/module.cpp @@ -1272,6 +1272,7 @@ namespace hal bool Module::delete_pin_group(PinGroup* pin_group) { + std::vector distribute_events; if (pin_group == nullptr) { log_warning("module", "could not delete pin group from module '{}' with ID {}: pin group is a 'nullptr'", m_name, m_id); @@ -1286,16 +1287,16 @@ namespace hal return false; } - bool removed_pins = false; - std::vector pins_copy = pin_group->get_pins(); for (ModulePin* pin : pins_copy) { - removed_pins = true; - if (auto res = create_pin_group(pin->get_name(), {pin}, pin->get_direction(), pin->get_type(), true, 0, false); res.is_error()) + auto res = create_pin_group(pin->get_name(), {pin}, pin->get_direction(), pin->get_type(), true, 0, false); + if (res.is_error()) { return false; } + distribute_events.push_back(pinevent_associated_data(PinEvent::GroupCreate,res.get()->get_id())); + distribute_events.push_back(pinevent_associated_data(PinEvent::PinAssignToGroup,pin->get_id())); } u32 pin_group_id_to_delete = pin_group->get_id(); @@ -1305,10 +1306,9 @@ namespace hal return false; } - if (removed_pins) - { - m_event_handler->notify(ModuleEvent::event::pin_changed, this, pinevent_associated_data(PinEvent::GroupDelete,pin_group_id_to_delete)); - } + for (u32 dist_ev : distribute_events) + m_event_handler->notify(ModuleEvent::event::pin_changed, this, dist_ev); + m_event_handler->notify(ModuleEvent::event::pin_changed, this, pinevent_associated_data(PinEvent::GroupDelete,pin_group_id_to_delete)); return true; } @@ -1399,7 +1399,7 @@ namespace hal if (delete_empty_groups && pg->empty()) { - pin_group_id_to_delete = pin_group->get_id(); + pin_group_id_to_delete = pg->get_id(); if (!delete_pin_group_internal(pg)) { log_warning("module",