diff --git a/CHANGELOG.md b/CHANGELOG.md index e169ab646133..efd72adc6d04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,9 +16,10 @@ All notable changes to this project will be documented in this file. * pin groups * added getter for lowest and highest index of pin group - * added column for pin index in pin tree shown in selection details - * added context menu entry to toggle between ascending and descending - * changed drag&drop behavior, allowing to drop pin on pin when ordering + * added column for pin index in GUI module pin tree + * added GUI module pin tree context menu entry to toggle between ascending and descending + * fixed GUI undo function for group delete + * changed GUI module pin tree drag'n drop behavior, allow drop pin(-group) on pin * fixed availability of "save as" so that does not required modifications to be enabaled * added feature to unzip and open hal project by dropping zipped file on welcome screen diff --git a/plugins/gui/include/gui/basic_tree_model/base_tree_item.h b/plugins/gui/include/gui/basic_tree_model/base_tree_item.h index 04df7bf683e5..048feec55c5d 100644 --- a/plugins/gui/include/gui/basic_tree_model/base_tree_item.h +++ b/plugins/gui/include/gui/basic_tree_model/base_tree_item.h @@ -87,7 +87,7 @@ namespace hal * @param index - The column to set the new data. * @param data - The new column data. */ - virtual void setDataAtIndex(int index, QVariant& data) = 0; + virtual void setDataAtColumn(int column, QVariant& data) = 0; /** * Appends a new column to the item. @@ -227,7 +227,7 @@ namespace hal * @param index - The column to set the new data. * @param data - The new column data. */ - void setDataAtIndex(int index, QVariant& data) override; + void setDataAtColumn(int column, QVariant& data) override; /** * Appends a new column to the item. diff --git a/plugins/gui/include/gui/context_manager_widget/models/context_tree_model.h b/plugins/gui/include/gui/context_manager_widget/models/context_tree_model.h index fdc57eb783cf..632780c25f1d 100644 --- a/plugins/gui/include/gui/context_manager_widget/models/context_tree_model.h +++ b/plugins/gui/include/gui/context_manager_widget/models/context_tree_model.h @@ -71,7 +71,7 @@ namespace hal ContextTreeItem(ContextDirectory* directory); QVariant getData(int column) const override; void setData(QList data) override; - void setDataAtIndex(int index, QVariant& data) override; + void setDataAtColumn(int column, QVariant& data) override; void appendData(QVariant data) override; int getColumnCount() const override; int row() const; diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_pin.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_pin.h index 6c82f08361f4..96492ec10e3f 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_pin.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_pin.h @@ -26,8 +26,6 @@ #pragma once #include "gatelibrary_tab_interface.h" -#include "gui/selection_details_widget/gate_details_widget/pin_tree_model.h" -#include "hal_core/defines.h" #include "hal_core/netlist/gate_library/gate_type.h" #include diff --git a/plugins/gui/include/gui/module_model/module_item.h b/plugins/gui/include/gui/module_model/module_item.h index f7f84cfab3dc..95470d62143e 100644 --- a/plugins/gui/include/gui/module_model/module_item.h +++ b/plugins/gui/include/gui/module_model/module_item.h @@ -66,7 +66,7 @@ namespace hal * @param index - The column to set the new data. Either 0 (name) or 2(type). Other columns will be ignored. * @param data - The new column data. */ - void setDataAtIndex(int index, QVariant& data) override; + void setDataAtColumn(int column, QVariant& data) override; /** * Unused dummy function overwritten from parent class. */ diff --git a/plugins/gui/include/gui/pin_model/pin_item.h b/plugins/gui/include/gui/pin_model/pin_item.h index 16987b45270e..04e6d8b09305 100644 --- a/plugins/gui/include/gui/pin_model/pin_item.h +++ b/plugins/gui/include/gui/pin_model/pin_item.h @@ -50,7 +50,7 @@ namespace hal enum class TreeItemType {PinGroup, Pin, GroupCreator, PinCreator, InvalidPinGroup, InvalidPin}; void setData(QList data) override; - void setDataAtIndex(int index, QVariant& data) override; + void setDataAtColumn(int column, QVariant& data) override; void appendData(QVariant data) override; int getColumnCount() const override; diff --git a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pin_tree.h b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pin_tree.h index 746eb58931e2..4a65590d37f7 100644 --- a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pin_tree.h +++ b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pin_tree.h @@ -33,7 +33,7 @@ namespace hal { class GatePinsTreeModel; class Gate; - class PinTreeItem; + class GatePinsTreeItem; class GraphNavigationWidget; /** @@ -98,8 +98,8 @@ namespace hal bool mClearSelection; //helper functions - void buildPythonMenuForPin(QMenu &menu, PinTreeItem* clickedPinItem); - void buildPythonMenuForPinGroup(QMenu &menu, PinTreeItem* clickedPinIGrouptem); + void buildPythonMenuForPin(QMenu &menu, GatePinsTreeItem* clickedPinItem); + void buildPythonMenuForPinGroup(QMenu &menu, GatePinsTreeItem* clickedPinIGrouptem); void addSourceOurDestinationToSelection(int netId, bool isInputPin); void handleNavigationCloseRequested(); void handleNavigationJumpRequested(const Node& origin, const u32 via_net, const QSet& to_gates, const QSet& to_modules); diff --git a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pins_tree_model.h similarity index 93% rename from plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h rename to plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pins_tree_model.h index e293a7ed820c..aabf65faaa20 100644 --- a/plugins/gui/include/gui/selection_details_widget/gate_details_widget/pin_tree_model.h +++ b/plugins/gui/include/gui/selection_details_widget/gate_details_widget/gate_pins_tree_model.h @@ -36,7 +36,7 @@ namespace hal class Gate; - class PinTreeItem : public BaseTreeItem + class GatePinsTreeItem : public BaseTreeItem { public: enum Type {None, Pin, Group}; @@ -51,11 +51,11 @@ namespace hal int mIndex; public: - PinTreeItem(const std::string& pinName, QString pinDirection, QString pinTypee, QString netName, int inx); - PinTreeItem(); + GatePinsTreeItem(const std::string& pinName, QString pinDirection, QString pinTypee, QString netName, int inx); + GatePinsTreeItem(); QVariant getData(int column) const override; void setData(QList data) override; - void setDataAtIndex(int index, QVariant& data) override; + void setDataAtColumn(int column, QVariant& data) override; void appendData(QVariant data) override; int getColumnCount() const override; void setType(Type tp) { mType = tp; } diff --git a/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_ports_tree.h b/plugins/gui/include/gui/selection_details_widget/module_details_widget/module_pins_tree.h similarity index 100% rename from plugins/gui/include/gui/selection_details_widget/module_details_widget/module_ports_tree.h rename to plugins/gui/include/gui/selection_details_widget/module_details_widget/module_pins_tree.h 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/module_pins_tree_model.h similarity index 85% rename from plugins/gui/include/gui/selection_details_widget/module_details_widget/port_tree_model.h rename to plugins/gui/include/gui/selection_details_widget/module_details_widget/module_pins_tree_model.h index 1e1867e02307..fb5ce32162ef 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/module_pins_tree_model.h @@ -38,7 +38,7 @@ namespace hal class Net; - class PortTreeItem : public BaseTreeItem + class ModulePinsTreeItem : public BaseTreeItem { public: enum Type {None, Pin, Group}; @@ -54,11 +54,11 @@ namespace hal public: - PortTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, int inx, QString netName = QString()); - PortTreeItem() : mItemType(None), mId(0) {;} + ModulePinsTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, int inx, QString netName = QString()); + ModulePinsTreeItem() : mItemType(None), mId(0) {;} QVariant getData(int column) const override; void setData(QList data) override; - void setDataAtIndex(int index, QVariant& data) override; + void setDataAtColumn(int column, QVariant& data) override; void appendData(QVariant data) override; int getColumnCount() const override; void setItemType(Type tp) { mItemType = tp; } @@ -127,7 +127,7 @@ namespace hal * @param item - The (port) item. * @return The net or nullptr. */ - Net* getNetFromItem(PortTreeItem* item); + Net* getNetFromItem(ModulePinsTreeItem* item); /** * Get the id of the module that is currently represented. @@ -162,18 +162,18 @@ namespace hal Module* mModule; //name is (hopefully) enough to identify QMap mNameToTreeItem; - QMap mIdToPinItem; - QMap mIdToGroupItem; + QMap mIdToPinItem; + QMap mIdToGroupItem; - void insertItem(PortTreeItem* item, BaseTreeItem* parent, int index); - void removeItem(PortTreeItem* item); - void updateGroupIndex(PortTreeItem* groupItem); + void insertItem(ModulePinsTreeItem* item, BaseTreeItem* parent, int index); + void removeItem(ModulePinsTreeItem* item); + void updateGroupIndex(ModulePinsTreeItem* groupItem); // helper functions for dnd for more clarity void dndGroupOnGroup(BaseTreeItem* droppedGroup, BaseTreeItem* onDroppedGroup, int row=-1); - void dndGroupBetweenGroup(PortTreeItem* droppedGroup, int row); - void dndPinOnGroup(PortTreeItem* droppedPin, BaseTreeItem* onDroppedGroup); - void dndPinBetweenPin(PortTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row); - void dndPinBetweenGroup(PortTreeItem* droppedPin, int row); + void dndGroupBetweenGroup(ModulePinsTreeItem* droppedGroup, int row); + void dndPinOnGroup(ModulePinsTreeItem* droppedPin, BaseTreeItem* onDroppedGroup); + void dndPinBetweenPin(ModulePinsTreeItem* droppedPin, BaseTreeItem* onDroppedParent, int row); + void dndPinBetweenGroup(ModulePinsTreeItem* droppedPin, int row); }; } diff --git a/plugins/gui/include/gui/user_action/action_pingroup.h b/plugins/gui/include/gui/user_action/action_pingroup.h index 29b1ebdf6314..67470e543ddb 100644 --- a/plugins/gui/include/gui/user_action/action_pingroup.h +++ b/plugins/gui/include/gui/user_action/action_pingroup.h @@ -46,14 +46,6 @@ namespace hal static bool useExistingPin(Type tp); }; - int pinGroupIndex(const Module* mod, const PinGroup* pgrp); - - int pinIndex2Row(const ModulePin* pin, int index); - - int pinRow2Index(const ModulePin* pin, int row); - - QString generateGroupName(const Module* mod, const ModulePin* pin); - void dumpPingroups(Module* m = nullptr); /** * @ingroup user_action @@ -66,8 +58,7 @@ namespace hal * negative ID: call constructor without ID, however, * ID will be used internally for subsequent commands related to crated group * name : name of group - * value : start index, assume ascending - * negative value: descending order starting with (-value-1) + * value : start index * 2, LSB : 0=descending 1=ascending * * GroupDelete * ID : ID of group to delete @@ -135,6 +126,7 @@ namespace hal QHash*> mPinGroups; QList mPinActions; + QList > mTempUndoActions; Module* mParentModule; QMap mGroupRestore; QSet mPinsMoved; @@ -144,7 +136,6 @@ namespace hal PinGroup* getGroup(int grpId) const; void prepareUndoAction(); void finalizeUndoAction(); - void addUndoAction(PinActionType::Type tp, int id = 0, const QString& name=QString(), int value=0); static int pinGroupRow(const Module *m, PinGroup* pgroup); public: ActionPingroup(PinActionType::Type tp = PinActionType::None, int id = 0, const QString& name=QString(), int value=0); @@ -163,6 +154,11 @@ namespace hal static ActionPingroup* deletePinGroup(const Module* m, u32 grpId); static ActionPingroup* toggleAscendingGroup(const Module* m, u32 grpId); static ActionPingroup* changePinGroupType(const Module* m, u32 grpId, int ptype); + + static int pinGroupIndex(const Module* mod, const PinGroup* pgrp); + static int pinIndex2Row(const ModulePin* pin, int index); + static int pinRow2Index(const ModulePin* pin, int row); + static QString generateGroupName(const Module* mod, const ModulePin* pin); }; /** diff --git a/plugins/gui/src/basic_tree_model/base_tree_item.cpp b/plugins/gui/src/basic_tree_model/base_tree_item.cpp index 17bc9a78d64c..2d7aad398509 100644 --- a/plugins/gui/src/basic_tree_model/base_tree_item.cpp +++ b/plugins/gui/src/basic_tree_model/base_tree_item.cpp @@ -114,11 +114,11 @@ namespace hal } } - void RootTreeItem::setDataAtIndex(int index, QVariant &data) + void RootTreeItem::setDataAtColumn(int column, QVariant &data) { - while (index >= mHeaderLabels.size()) + while (column >= mHeaderLabels.size()) mHeaderLabels << QString(); - mHeaderLabels[index] = data.toString(); + mHeaderLabels[column] = data.toString(); } void RootTreeItem::appendData(QVariant data) diff --git a/plugins/gui/src/basic_tree_model/base_tree_model.cpp b/plugins/gui/src/basic_tree_model/base_tree_model.cpp index 9066ac917f31..1292f6a31ab3 100644 --- a/plugins/gui/src/basic_tree_model/base_tree_model.cpp +++ b/plugins/gui/src/basic_tree_model/base_tree_model.cpp @@ -114,7 +114,7 @@ namespace hal else for (int i=0; isetDataAtIndex(i, qv); + mRootItem->setDataAtColumn(i, qv); } diff --git a/plugins/gui/src/context_manager_widget/models/context_tree_model.cpp b/plugins/gui/src/context_manager_widget/models/context_tree_model.cpp index a6c67300c199..38a4e94476d8 100644 --- a/plugins/gui/src/context_manager_widget/models/context_tree_model.cpp +++ b/plugins/gui/src/context_manager_widget/models/context_tree_model.cpp @@ -94,9 +94,9 @@ namespace hal } - void ContextTreeItem::setDataAtIndex(int index, QVariant &data) + void ContextTreeItem::setDataAtColumn(int column, QVariant &data) { - + // TODO: implement } void ContextTreeItem::appendData(QVariant data) diff --git a/plugins/gui/src/module_model/module_item.cpp b/plugins/gui/src/module_model/module_item.cpp index 9fadba89b7c5..f4a196a1e65e 100644 --- a/plugins/gui/src/module_model/module_item.cpp +++ b/plugins/gui/src/module_model/module_item.cpp @@ -106,9 +106,9 @@ ModuleItem::ModuleItem(const u32 id, const TreeItemType type, ModuleModel *model setModuleType(data.at(2).toString()); } - void ModuleItem::setDataAtIndex(int index, QVariant &data) + void ModuleItem::setDataAtColumn(int column, QVariant &data) { - switch (index) { + switch (column) { case 0: setName(data.toString()); return; diff --git a/plugins/gui/src/pin_model/pin_item.cpp b/plugins/gui/src/pin_model/pin_item.cpp index 2397626293d1..b6f2fb9d743f 100644 --- a/plugins/gui/src/pin_model/pin_item.cpp +++ b/plugins/gui/src/pin_model/pin_item.cpp @@ -73,9 +73,9 @@ namespace hal mId = newId; } - void PinItem::setDataAtIndex(int index, QVariant &data) + void PinItem::setDataAtColumn(int column, QVariant &data) { - + // TODO : implement ?! } QString PinItem::getName() const diff --git a/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pin_tree.cpp b/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pin_tree.cpp index 754770955ef8..7acd400108c9 100644 --- a/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pin_tree.cpp +++ b/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pin_tree.cpp @@ -1,5 +1,5 @@ #include "gui/selection_details_widget/gate_details_widget/gate_pin_tree.h" -#include "gui/selection_details_widget/gate_details_widget/pin_tree_model.h" +#include "gui/selection_details_widget/gate_details_widget/gate_pins_tree_model.h" //#include "gui/gui_globals.h" #include "hal_core/netlist/gate.h" #include @@ -69,8 +69,8 @@ namespace hal if(!idx.isValid()) return; - PinTreeItem* clickedItem = dynamic_cast(mPinModel->getItemFromIndex(idx)); - if(!clickedItem || clickedItem->type() != PinTreeItem::Pin) + GatePinsTreeItem* clickedItem = dynamic_cast(mPinModel->getItemFromIndex(idx)); + if(!clickedItem || clickedItem->type() != GatePinsTreeItem::Pin) return; auto netId = clickedItem->netIds().front(); @@ -96,7 +96,7 @@ namespace hal if(!idx.isValid()) return; - PinTreeItem* clickedItem = dynamic_cast(mPinModel->getItemFromIndex(idx)); + GatePinsTreeItem* clickedItem = dynamic_cast(mPinModel->getItemFromIndex(idx)); QMenu menu; bool isMiscSectionSet = false;//so that the misc-section is not set multiple times @@ -117,7 +117,7 @@ namespace hal }); //Check if jump to source or destination is possible - if(clickedItem->type() == PinTreeItem::Pin && clickedItem->netIds().size()==1) + if(clickedItem->type() == GatePinsTreeItem::Pin && clickedItem->netIds().size()==1) { auto netId = clickedItem->netIds().front(); auto clickedNet = gNetlist->get_net_by_id(netId); @@ -156,7 +156,7 @@ namespace hal //Add nets to selection if possible QList netIds; - if(clickedItem->type() == PinTreeItem::Pin) + if(clickedItem->type() == GatePinsTreeItem::Pin) { netIds = clickedItem->netIds(); } @@ -164,7 +164,7 @@ namespace hal { for(auto childItem : clickedItem->getChildren()) { - PinTreeItem* pti = dynamic_cast(childItem); + GatePinsTreeItem* pti = dynamic_cast(childItem); if (pti) netIds.append(pti->netIds()); } @@ -194,7 +194,7 @@ namespace hal menu.addSection("Python"); - if(clickedItem->type() == PinTreeItem::Pin) + if(clickedItem->type() == GatePinsTreeItem::Pin) buildPythonMenuForPin(menu, clickedItem); else buildPythonMenuForPinGroup(menu, clickedItem); @@ -204,7 +204,7 @@ namespace hal } - void GatePinTree::buildPythonMenuForPin(QMenu &menu, PinTreeItem *clickedPinItem) + void GatePinTree::buildPythonMenuForPin(QMenu &menu, GatePinsTreeItem *clickedPinItem) { // 1.) NET-OBJECT QList netIdsOfItem = clickedPinItem->netIds(); @@ -246,7 +246,7 @@ namespace hal } - void GatePinTree::buildPythonMenuForPinGroup(QMenu &menu, PinTreeItem *clickedPinIGrouptem) + void GatePinTree::buildPythonMenuForPinGroup(QMenu &menu, GatePinsTreeItem *clickedPinIGrouptem) { // 1. PYTHON LIST OF PIN GROUPS QString pythonList = "["; diff --git a/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp b/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pins_tree_model.cpp similarity index 85% rename from plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp rename to plugins/gui/src/selection_details_widget/gate_details_widget/gate_pins_tree_model.cpp index bde590548815..5fe6c5e021fb 100644 --- a/plugins/gui/src/selection_details_widget/gate_details_widget/pin_tree_model.cpp +++ b/plugins/gui/src/selection_details_widget/gate_details_widget/gate_pins_tree_model.cpp @@ -1,10 +1,9 @@ -#include "gui/selection_details_widget/gate_details_widget/pin_tree_model.h" +#include "gui/selection_details_widget/gate_details_widget/gate_pins_tree_model.h" #include "gui/gui_globals.h" #include "hal_core/netlist/gate.h" #include "hal_core/netlist/gate_library/gate_type.h" #include "hal_core/netlist/net.h" -#include "hal_core/utilities/enums.h" #include #include @@ -12,14 +11,14 @@ namespace hal { - PinTreeItem::PinTreeItem(const std::string &pinName, QString pinDirection, QString pinType, QString netName, int inx) + GatePinsTreeItem::GatePinsTreeItem(const std::string &pinName, QString pinDirection, QString pinType, QString netName, int inx) :mPinName(pinName), mPinDirection(pinDirection), mPinType(pinType), mNetName(netName), mIndex(inx) {;} - PinTreeItem::PinTreeItem() + GatePinsTreeItem::GatePinsTreeItem() {;} - QVariant PinTreeItem::getData(int index) const + QVariant GatePinsTreeItem::getData(int index) const { switch (index) { @@ -32,14 +31,14 @@ namespace hal case 3: return mNetName; case 4: - if (mType == PinTreeItem::Group) + if (mType == GatePinsTreeItem::Group) return (mIndex ? "descending" : "ascending"); return mIndex; } return QVariant(); } - void PinTreeItem::setData(QList data) + void GatePinsTreeItem::setData(QList data) { Q_ASSERT(data.size() >= 5); mPinName = data[0].toString().toStdString(); @@ -49,9 +48,9 @@ namespace hal mIndex = data[4].toInt(); } - void PinTreeItem::setDataAtIndex(int index, QVariant &data) + void GatePinsTreeItem::setDataAtColumn(int column, QVariant &data) { - switch (index) + switch (column) { case 0: mPinName = data.toString().toStdString(); @@ -73,9 +72,9 @@ namespace hal } - void PinTreeItem::appendData(QVariant data) {} + void GatePinsTreeItem::appendData(QVariant data) {} - int PinTreeItem::getColumnCount() const + int GatePinsTreeItem::getColumnCount() const { return 5; } @@ -114,7 +113,7 @@ namespace hal GateType* gateType = g->get_type(); for (auto pin : gateType->get_pins()) { - PinTreeItem* pinItem = new PinTreeItem(); + GatePinsTreeItem* pinItem = new GatePinsTreeItem(); //get all infos for that pin const PinGroup* pg = pin->get_group().first; const std::string& grpName = pg->get_name(); @@ -164,16 +163,16 @@ namespace hal } pinItem->setData(QList() << QString::fromStdString(pin->get_name()) << pinDirection << pinType << netName << inx); - pinItem->setType(PinTreeItem::Pin); + pinItem->setType(GatePinsTreeItem::Pin); pinItem->setNetIds(netIDs); if (!grpName.empty()) { - PinTreeItem* pingroupItem = dynamic_cast(mPinGroupToTreeItem.value(grpName, nullptr)); //since its a map, its okay + GatePinsTreeItem* pingroupItem = dynamic_cast(mPinGroupToTreeItem.value(grpName, nullptr)); //since its a map, its okay if (!pingroupItem) { //assume all items in the same grouping habe the same direction and type, so the grouping-item has also these types - pingroupItem = new PinTreeItem(grpName, pinDirection, pinType, "", iDescending); - pingroupItem->setType(PinTreeItem::Group); + pingroupItem = new GatePinsTreeItem(grpName, pinDirection, pinType, "", iDescending); + pingroupItem->setType(GatePinsTreeItem::Group); mRootItem->appendChild(pingroupItem); mPinGroupToTreeItem.insert(grpName, pingroupItem); } diff --git a/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp b/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp index bf04ac128067..94e133776ffa 100644 --- a/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_tab_widget.cpp @@ -2,7 +2,7 @@ #include "gui/selection_details_widget/details_frame_widget.h" #include "gui/selection_details_widget/module_details_widget/module_info_table.h" -#include "gui/selection_details_widget/module_details_widget/module_ports_tree.h" +#include "gui/selection_details_widget/module_details_widget/module_pins_tree.h" #include "gui/selection_details_widget/module_details_widget/module_elements_tree.h" #include "gui/comment_system/widgets/comment_widget.h" diff --git a/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp b/plugins/gui/src/selection_details_widget/module_details_widget/module_pins_tree.cpp similarity index 93% rename from plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp rename to plugins/gui/src/selection_details_widget/module_details_widget/module_pins_tree.cpp index dd23d18070cd..f4872f86f04f 100644 --- a/plugins/gui/src/selection_details_widget/module_details_widget/module_ports_tree.cpp +++ b/plugins/gui/src/selection_details_widget/module_details_widget/module_pins_tree.cpp @@ -1,11 +1,11 @@ -#include "gui/selection_details_widget/module_details_widget/module_ports_tree.h" +#include "gui/selection_details_widget/module_details_widget/module_pins_tree.h" #include "gui/gui_globals.h" #include "gui/input_dialog/combobox_dialog.h" #include "gui/input_dialog/input_dialog.h" #include "gui/input_dialog/pingroup_selector_dialog.h" #include "gui/python/py_code_provider.h" -#include "gui/selection_details_widget/module_details_widget/port_tree_model.h" +#include "gui/selection_details_widget/module_details_widget/module_pins_tree_model.h" #include "gui/user_action/action_pingroup.h" #include "hal_core/netlist/gate_library/enums/pin_type.h" #include "hal_core/utilities/enums.h" @@ -81,7 +81,7 @@ namespace hal return; //all relevant information - PortTreeItem* clickedItem = static_cast(mPortModel->getItemFromIndex(clickedIndex)); + ModulePinsTreeItem* clickedItem = static_cast(mPortModel->getItemFromIndex(clickedIndex)); Net* n = mPortModel->getNetFromItem(clickedItem); QString name = clickedItem->getData(ModulePinsTreeModel::sNameColumn).toString(); u32 modId = mPortModel->getRepresentedModuleId(); @@ -122,7 +122,7 @@ namespace hal return; for (auto item : selectedPins) { - auto* pin = mod->get_pin_by_id(static_cast(item)->id()); + auto* pin = mod->get_pin_by_id(static_cast(item)->id()); if (pin == nullptr) return; pins.append(pin->get_id()); @@ -133,7 +133,7 @@ namespace hal }); } - if (clickedItem->itemType() == PortTreeItem::Group) //group specific context, own helper function? (returns at the end) + if (clickedItem->itemType() == ModulePinsTreeItem::Group) //group specific context, own helper function? (returns at the end) { menu.addAction("Change name", [itemId, mod, name]() { PinGroup* pg = mod->get_pin_group_by_id(itemId); @@ -246,7 +246,7 @@ namespace hal menu.addAction("Remove selection from group", [selectedPins, mod /*, sameGroup*/]() { QList pins; for (auto item : selectedPins) - pins.append(static_cast(item)->id()); + pins.append(static_cast(item)->id()); ActionPingroup* act = ActionPingroup::removePinsFromGroup(mod, pins); if (act) act->exec(); @@ -258,7 +258,7 @@ namespace hal appendMultiSelectionEntries(menu, modId); menu.addSection("Python"); - if(clickedItem->itemType()==PortTreeItem::Pin) + if(clickedItem->itemType()==ModulePinsTreeItem::Pin) menu.addAction(QIcon(":/icons/python"), "Get pin", [modId, itemId]() { QApplication::clipboard()->setText(PyCodeProvider::pyCodeModulePinById(modId, itemId)); }); else menu.addAction(QIcon(":/icons/python"), "Get group", [modId, itemId]() { QApplication::clipboard()->setText(PyCodeProvider::pyCodeModulePinGroup(modId, itemId)); }); @@ -288,7 +288,7 @@ namespace hal Module* mod = gNetlist->get_module_by_id(modId); for (auto item : selectedPins) { - auto* pin = mod->get_pin_by_id(static_cast(item)->id()); + auto* pin = mod->get_pin_by_id(static_cast(item)->id()); if (pin == nullptr) return; pins.append(pin->get_id()); @@ -310,8 +310,8 @@ namespace hal int groupId = -1; for (auto index : selectionModel()->selectedRows()) { - PortTreeItem* item = static_cast(mPortModel->getItemFromIndex(index)); - if (item->itemType() == PortTreeItem::Pin) + ModulePinsTreeItem* item = static_cast(mPortModel->getItemFromIndex(index)); + if (item->itemType() == ModulePinsTreeItem::Pin) { if (!alreadyProcessedPins.contains(item)) { @@ -319,7 +319,7 @@ namespace hal alreadyProcessedPins.insert(item); } } - else if (item->itemType() == PortTreeItem::Group) + else if (item->itemType() == ModulePinsTreeItem::Group) { onlyPins = false; for (auto pinItem : item->getChildren()) @@ -336,11 +336,11 @@ namespace hal if (!selectedPins.isEmpty()) { auto mod = gNetlist->get_module_by_id(mModuleID); - auto* firstPin = mod->get_pin_by_id(static_cast(selectedPins.front())->id()); + auto* firstPin = mod->get_pin_by_id(static_cast(selectedPins.front())->id()); groupId = firstPin->get_group().first->get_id(); for (auto pinTreeItem : selectedPins) { - auto pin = mod->get_pin_by_id(static_cast(pinTreeItem)->id()); + auto pin = mod->get_pin_by_id(static_cast(pinTreeItem)->id()); if (groupId != (int)pin->get_group().first->get_id()) { sameGroup = false; 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/module_pins_tree_model.cpp similarity index 83% rename from plugins/gui/src/selection_details_widget/module_details_widget/port_tree_model.cpp rename to plugins/gui/src/selection_details_widget/module_details_widget/module_pins_tree_model.cpp index 7dd546b13851..202ec24693c0 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/module_pins_tree_model.cpp @@ -1,4 +1,4 @@ -#include "gui/selection_details_widget/module_details_widget/port_tree_model.h" +#include "gui/selection_details_widget/module_details_widget/module_pins_tree_model.h" #include "gui/basic_tree_model/base_tree_item.h" #include "gui/gui_globals.h" @@ -15,11 +15,11 @@ namespace hal { - PortTreeItem::PortTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, int inx, QString netName) + ModulePinsTreeItem::ModulePinsTreeItem(Type itype, u32 id_, QString pinName, PinDirection dir, PinType ptype, int inx, QString netName) : mItemType(itype), mId(id_), mPinName(pinName), mPinDirection(dir), mPinType(ptype), mNetName(netName), mIndex(inx) {;} - QVariant PortTreeItem::getData(int index) const + QVariant ModulePinsTreeItem::getData(int index) const { switch (index) { @@ -32,14 +32,14 @@ namespace hal case 3: return mNetName; case 4: - if (mItemType==PortTreeItem::Group) + if (mItemType==ModulePinsTreeItem::Group) return ( mIndex ? "descending" : "ascending"); return mIndex; } return QVariant(); } - void PortTreeItem::setData(QList data) + void ModulePinsTreeItem::setData(QList data) { Q_ASSERT(data.size() >= 5); mPinName = data[0].toString(); @@ -49,9 +49,9 @@ namespace hal mIndex = data[4].toInt(); } - void PortTreeItem::setDataAtIndex(int index, QVariant &data) + void ModulePinsTreeItem::setDataAtColumn(int column, QVariant &data) { - switch (index) + switch (column) { case 0: mPinName = data.toString(); @@ -71,12 +71,12 @@ namespace hal } } - void PortTreeItem::appendData(QVariant data) + void ModulePinsTreeItem::appendData(QVariant data) { Q_UNUSED(data) } - int PortTreeItem::getColumnCount() const + int ModulePinsTreeItem::getColumnCount() const { return 5; } @@ -142,12 +142,12 @@ namespace hal return new QMimeData(); QMimeData* data = new QMimeData(); - PortTreeItem* item = static_cast(getItemFromIndex(indexes.at(0))); + ModulePinsTreeItem* item = static_cast(getItemFromIndex(indexes.at(0))); QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); - QString type = item->itemType() == PortTreeItem::Pin ? "pin" : "group"; + QString type = item->itemType() == ModulePinsTreeItem::Pin ? "pin" : "group"; stream << type << item->id(); - data->setText(item->itemType() == PortTreeItem::Pin + data->setText(item->itemType() == ModulePinsTreeItem::Pin ? PyCodeProvider::pyCodeModulePinById(mModule->get_id(),item->id()) : PyCodeProvider::pyCodeModulePinGroup(mModule->get_id(),item->id())); data->setData("pintreemodel/item", encodedData); @@ -166,7 +166,7 @@ namespace hal // debug pingroup qDebug() << "dropMimeData" << encItem << row << column; dataStream >> type >> id; - auto droppedItem = (type == "group") ? static_cast(mIdToGroupItem.value(id)) : static_cast(mIdToPinItem.value(id)); + auto droppedItem = (type == "group") ? static_cast(mIdToGroupItem.value(id)) : static_cast(mIdToPinItem.value(id)); //auto droppedParentItem = droppedItem->getParent(); auto dropPositionItem = getItemFromIndex(parent); @@ -187,11 +187,11 @@ namespace hal } else { - PortTreeItem* pitem = dynamic_cast(dropPositionItem); - if (pitem && pitem->itemType() == PortTreeItem::Pin) + ModulePinsTreeItem* pitem = dynamic_cast(dropPositionItem); + if (pitem && pitem->itemType() == ModulePinsTreeItem::Pin) { // debug pingroup qDebug() << "group was dropped on a pin..."; - PortTreeItem* parentGroupItem = static_cast(pitem->getParent()); + ModulePinsTreeItem* parentGroupItem = static_cast(pitem->getParent()); row = getIndexFromItem(pitem).row(); dndGroupOnGroup(droppedItem, parentGroupItem, row); } @@ -214,11 +214,11 @@ namespace hal } else { - PortTreeItem* pitem = dynamic_cast(dropPositionItem); - if (pitem && pitem->itemType() == PortTreeItem::Pin) + ModulePinsTreeItem* pitem = dynamic_cast(dropPositionItem); + if (pitem && pitem->itemType() == ModulePinsTreeItem::Pin) { // debug pingroup qDebug() << "pin was dropped on a pin..."; - PortTreeItem* parentGroupItem = static_cast(pitem->getParent()); + ModulePinsTreeItem* parentGroupItem = static_cast(pitem->getParent()); row = getIndexFromItem(pitem).row(); dndPinBetweenPin(droppedItem, parentGroupItem, row); } @@ -242,7 +242,7 @@ namespace hal auto encItem = data->data("pintreemodel/item"); QDataStream dataStream(&encItem, QIODevice::ReadOnly); dataStream >> type >> id; - auto parentItem = static_cast(getItemFromIndex(parent)); + auto parentItem = static_cast(getItemFromIndex(parent)); // qDebug() << "type: " << type << ", id" << id << ", row: " << row; // construct a "drop-matrix" here, but only 4(5) things are NOT allowed (so check for these): @@ -252,10 +252,10 @@ namespace hal // 5: drop adjecent index to itself, must be at least 1 item apart if(type == "group") { - auto item = static_cast(mIdToGroupItem[id]); + auto item = static_cast(mIdToGroupItem[id]); if(parentItem) { - if(item->itemType() == PortTreeItem::Pin || (item->itemType() == PortTreeItem::Group && row != -1) || item == parentItem) + if(item->itemType() == ModulePinsTreeItem::Pin || (item->itemType() == ModulePinsTreeItem::Group && row != -1) || item == parentItem) return false; } else // here, only check for adjacent rows @@ -306,12 +306,12 @@ namespace hal continue; auto pinGroupName = QString::fromStdString(pinGroup->get_name()); - PortTreeItem* pinGroupItem = new PortTreeItem(PortTreeItem::Group, pinGroup->get_id(), pinGroupName, pinGroup->get_direction(), + ModulePinsTreeItem* pinGroupItem = new ModulePinsTreeItem(ModulePinsTreeItem::Group, pinGroup->get_id(), pinGroupName, pinGroup->get_direction(), pinGroup->get_type(), pinGroup->is_ascending() ? 0 : 1); mIdToGroupItem.insert(pinGroup->get_id(), pinGroupItem); for(ModulePin* pin : pinGroup->get_pins()) { - PortTreeItem* pinItem = new PortTreeItem(PortTreeItem::Pin, + ModulePinsTreeItem* pinItem = new ModulePinsTreeItem(ModulePinsTreeItem::Pin, pin->get_id(), QString::fromStdString(pin->get_name()), pin->get_direction(), @@ -326,6 +326,8 @@ namespace hal mRootItem->appendChild(pinGroupItem); } +// Keep old code for the time being to review whether all cases are covered +// // for (PinGroup* pinGroup : m->get_pin_groups()) // { // //ignore empty pingroups @@ -350,7 +352,7 @@ namespace hal // if (pinGroup->size() == 1) // { -// pinGroupItem->setDataAtIndex(sNetColumn, QString::fromStdString(firstPin->get_net()->get_name())); +// pinGroupItem->setDataAtColumn(sNetColumn, QString::fromStdString(firstPin->get_net()->get_name())); // pinGroupItem->setAdditionalData(keyType, QVariant::fromValue(itemType::pin)); // //since a single-pin pingroup represents the pin itself, take the pinid // pinGroupItem->setAdditionalData(keyId, firstPin->get_id()); @@ -380,12 +382,12 @@ namespace hal Q_EMIT numberOfPortsChanged(m->get_pins().size()); } - Net* ModulePinsTreeModel::getNetFromItem(PortTreeItem* item) + Net* ModulePinsTreeModel::getNetFromItem(ModulePinsTreeItem* item) { if (!mModule) //no current module = no represented net return nullptr; - if (item->itemType() == PortTreeItem::Group && item->getChildCount() > 1) + if (item->itemType() == ModulePinsTreeItem::Group && item->getChildCount() > 1) return nullptr; Module* m = gNetlist->get_module_by_id(mModule->get_id()); @@ -420,8 +422,8 @@ namespace hal if (m != mModule) return; // debug pingroups log_info("gui", "Handle pin_changed event {} ID={}", enum_to_string(pev), pgid); - PortTreeItem* ptiPin = nullptr; - PortTreeItem* ptiGroup = nullptr; + ModulePinsTreeItem* ptiPin = nullptr; + ModulePinsTreeItem* ptiGroup = nullptr; const PinGroup* pgroup = nullptr; const ModulePin* pin = nullptr; int pinRow = -1; @@ -465,7 +467,7 @@ namespace hal } auto pgPair = pin->get_group(); pgroup = pgPair.first; - pinRow = pinIndex2Row(pin,pgPair.second); + pinRow = ActionPingroup::pinIndex2Row(pin,pgPair.second); if (pgroup) ptiGroup = mIdToGroupItem.value(pgroup->get_id()); } @@ -477,20 +479,20 @@ namespace hal { case PinEvent::GroupCreate: { - ptiGroup = new PortTreeItem(PortTreeItem::Group, + ptiGroup = new ModulePinsTreeItem(ModulePinsTreeItem::Group, pgroup->get_id(), QString::fromStdString(pgroup->get_name()), pgroup->get_direction(), pgroup->get_type(), pgroup->is_ascending()?0:1); mIdToGroupItem.insert(ptiGroup->id(), ptiGroup); - int inx = pinGroupIndex(m,pgroup); + int inx = ActionPingroup::pinGroupIndex(m,pgroup); insertItem(ptiGroup, mRootItem, inx); break; } case PinEvent::GroupReorder: { - int inx = pinGroupIndex(m,pgroup); + int inx = ActionPingroup::pinGroupIndex(m,pgroup); removeItem(ptiGroup); insertItem(ptiGroup, mRootItem, inx); break; @@ -521,7 +523,7 @@ namespace hal QString netName; if (pin->get_net()) netName = QString::fromStdString(pin->get_net()->get_name()); - ptiPin = new PortTreeItem(PortTreeItem::Pin, + ptiPin = new ModulePinsTreeItem(ModulePinsTreeItem::Pin, pin->get_id(), QString::fromStdString(pin->get_name()), pin->get_direction(), @@ -554,7 +556,15 @@ namespace hal } removeItem(ptiPin); insertItem(ptiPin, ptiGroup, pinRow); - updateGroupIndex(ptiGroup); + + // Unfortunately the event does not tell us where the pin was assigned previously. We have to update all group indices. + for (BaseTreeItem* bti : mRootItem->getChildren()) + { + ModulePinsTreeItem* grpItem = static_cast(bti); + // check whether group still exists (might have been deleted when moving last pin) + if (mModule->get_pin_group_by_id(grpItem->id())) + updateGroupIndex(static_cast(grpItem)); + } break; } case PinEvent::PinRename: @@ -591,12 +601,12 @@ namespace hal // InputDialog ipd("Name of new group", "Name of new group:", onDroppedGroup->getData(sNameColumn).toString()); // if(ipd.exec() == QDialog::Rejected) return false; QList pins; - auto srcgroup = mModule->get_pin_group_by_id(static_cast(droppedGroup)->id()); + auto srcgroup = mModule->get_pin_group_by_id(static_cast(droppedGroup)->id()); for(const auto &pin : srcgroup->get_pins()) pins.append(pin->get_id()); if (pins.isEmpty()) return; // no pins to move - auto tgtgroup = mModule->get_pin_group_by_id(static_cast(onDroppedGroup)->id()); + auto tgtgroup = mModule->get_pin_group_by_id(static_cast(onDroppedGroup)->id()); ActionPingroup* act = ActionPingroup::addPinsToExistingGroup(mModule,tgtgroup->get_id(),pins,row); if (act) act->exec(); @@ -605,7 +615,7 @@ namespace hal // with many ActionAddItemsToObject that contain a single pin each -> set destroys order of pins in source pingroup } - void ModulePinsTreeModel::dndGroupBetweenGroup(PortTreeItem *droppedGroup, int row) + void ModulePinsTreeModel::dndGroupBetweenGroup(ModulePinsTreeItem *droppedGroup, int row) { int ownRow = droppedGroup->getOwnRow(); bool bottomEdge = row == mRootItem->getChildCount(); @@ -616,14 +626,14 @@ namespace hal act->exec(); } - void ModulePinsTreeModel::dndPinOnGroup(PortTreeItem *droppedPin, BaseTreeItem *onDroppedGroup) + void ModulePinsTreeModel::dndPinOnGroup(ModulePinsTreeItem *droppedPin, BaseTreeItem *onDroppedGroup) { - ActionPingroup* act = new ActionPingroup(PinActionType::PinAsignToGroup,droppedPin->id(),"",static_cast(onDroppedGroup)->id()); + ActionPingroup* act = new ActionPingroup(PinActionType::PinAsignToGroup,droppedPin->id(),"",static_cast(onDroppedGroup)->id()); act->setObject(UserActionObject(mModule->get_id(),UserActionObjectType::Module)); act->exec(); } - void ModulePinsTreeModel::dndPinBetweenPin(PortTreeItem *droppedPin, BaseTreeItem *onDroppedParent, int row) + void ModulePinsTreeModel::dndPinBetweenPin(ModulePinsTreeItem *droppedPin, BaseTreeItem *onDroppedParent, int row) { int desiredIdx = row; ActionPingroup* act = nullptr; @@ -637,14 +647,14 @@ namespace hal } else { - act = ActionPingroup::addPinToExistingGroup(mModule,static_cast(onDroppedParent)->id(),droppedPin->id(),desiredIdx); + act = ActionPingroup::addPinToExistingGroup(mModule,static_cast(onDroppedParent)->id(),droppedPin->id(),desiredIdx); if (!act) return; } act->setObject(UserActionObject(mModule->get_id(),UserActionObjectType::Module)); act->exec(); } - void ModulePinsTreeModel::dndPinBetweenGroup(PortTreeItem *droppedPin, int row) + void ModulePinsTreeModel::dndPinBetweenGroup(ModulePinsTreeItem *droppedPin, int row) { // row is needed for when groups can change its order within the module Q_UNUSED(row) @@ -652,20 +662,20 @@ namespace hal auto pinToMove = mModule->get_pin_by_id(droppedPin->id()); if (!pinToMove) return; - QString groupName = generateGroupName(mModule,pinToMove); + QString groupName = ActionPingroup::generateGroupName(mModule,pinToMove); ActionPingroup* act = ActionPingroup::addPinToNewGroup(mModule, groupName, droppedPin->id(),row); act->exec(); } - void ModulePinsTreeModel::updateGroupIndex(PortTreeItem* groupItem) + void ModulePinsTreeModel::updateGroupIndex(ModulePinsTreeItem* groupItem) { PinGroup* pg = mModule->get_pin_group_by_id(groupItem->id()); Q_ASSERT(pg); for (ModulePin* pin : pg->get_pins()) { int inx = pg->get_index(pin).get(); - PortTreeItem* pinItem = mIdToPinItem.value(pin->get_id()); + ModulePinsTreeItem* pinItem = mIdToPinItem.value(pin->get_id()); Q_ASSERT(pinItem); pinItem->setIndex(inx); } @@ -675,25 +685,25 @@ namespace hal Q_EMIT dataChanged(i0,i1); } - void ModulePinsTreeModel::insertItem(PortTreeItem* item, BaseTreeItem* parent, int index) + void ModulePinsTreeModel::insertItem(ModulePinsTreeItem* item, BaseTreeItem* parent, int index) { // fun fact: if an item is inserted above an item that is expanded, the tree collapses all indeces beginInsertRows(getIndexFromItem(parent), index, index); parent->insertChild(index, item); endInsertRows(); //mNameToTreeItem.insert(item->getData(sNameColumn).toString(), item); - item->itemType() == PortTreeItem::Pin ? mIdToPinItem.insert(item->id(), item) : mIdToGroupItem.insert(item->id(), item); + item->itemType() == ModulePinsTreeItem::Pin ? mIdToPinItem.insert(item->id(), item) : mIdToGroupItem.insert(item->id(), item); //mIdToPinItem.insert(getIdOfItem(item), item); } - void ModulePinsTreeModel::removeItem(PortTreeItem* item) + void ModulePinsTreeModel::removeItem(ModulePinsTreeItem* item) { beginRemoveRows(parent(getIndexFromItem(item)), item->getOwnRow(), item->getOwnRow()); item->getParent()->removeChild(item); endRemoveRows(); //mNameToTreeItem.remove(item->getData(sNameColumn).toString()); //for now, only ids of pin-items (since these functions are only relevant for dnd) - item->itemType() == PortTreeItem::Pin ? mIdToPinItem.remove(item->id()) : mIdToGroupItem.remove(item->id()); + item->itemType() == ModulePinsTreeItem::Pin ? mIdToPinItem.remove(item->id()) : mIdToGroupItem.remove(item->id()); //mIdToPinItem.remove(getIdOfItem(item)); //delete item; } diff --git a/plugins/gui/src/user_action/action_pingroup.cpp b/plugins/gui/src/user_action/action_pingroup.cpp index c7950f69102e..d63b29ff9e2e 100644 --- a/plugins/gui/src/user_action/action_pingroup.cpp +++ b/plugins/gui/src/user_action/action_pingroup.cpp @@ -7,7 +7,7 @@ namespace hal { - int pinGroupIndex(const Module* mod, const PinGroup* pgrp) + int ActionPingroup::pinGroupIndex(const Module* mod, const PinGroup* pgrp) { if (!mod || !pgrp) return -1; int inx = 0; @@ -29,14 +29,14 @@ namespace hal << " <" << pg->get_name() << ">\n"; for (ModulePin* pin : pg->get_pins()) std::cerr << " pin: " << pin->get_id() << " inx:" << pin->get_group().second << " row:" - << pinIndex2Row(pin,pin->get_group().second) << " <" << pin->get_name() << ">\n"; + << ActionPingroup::pinIndex2Row(pin,pin->get_group().second) << " <" << pin->get_name() << ">\n"; } std::cerr << "-------------" << std::endl; for (Module* sm : m->get_submodules()) dumpPingroups(sm); } - int pinIndex2Row(const ModulePin* pin, int index) + int ActionPingroup::pinIndex2Row(const ModulePin* pin, int index) { auto pg = pin->get_group(); if (pg.first->is_ascending()) @@ -44,7 +44,7 @@ namespace hal return pg.first->get_start_index() - index; } - int pinRow2Index(const ModulePin* pin, int row) + int ActionPingroup::pinRow2Index(const ModulePin* pin, int row) { auto pg = pin->get_group(); if (pg.first->is_ascending()) @@ -57,7 +57,7 @@ namespace hal return (uint) pev; } - QString generateGroupName(const Module* mod, const ModulePin* pin) + QString ActionPingroup::generateGroupName(const Module* mod, const ModulePin* pin) { QString baseName = QString::fromStdString(pin->get_name()); QSet existingGroups; @@ -184,22 +184,6 @@ namespace hal return mParentModule->get_pin_group_by_id(grpId); } - void ActionPingroup::addUndoAction(PinActionType::Type tp, int id, const QString& name, int value) - { - ActionPingroup* undo = nullptr; - if (mUndoAction) - { - undo = static_cast(mUndoAction); - undo->mPinActions.append(AtomicAction(tp,id,name,value)); - } - else - { - undo = new ActionPingroup(tp,id,name,value); - undo->setObject(object()); - } - mUndoAction = undo; - } - void ActionPingroup::prepareUndoAction() { @@ -238,32 +222,23 @@ namespace hal if (gr.mDirection != PinDirection::none) restoreActions.append(AtomicAction(PinActionType::GroupDirChange,gr.mId,"",(int)gr.mDirection)); } - if (!restoreActions.isEmpty()) + + for (auto it = mTempUndoActions.rbegin(); it != mTempUndoActions.rend(); ++it) { - if (mUndoAction) - { - ActionPingroup* act = static_cast(mUndoAction); - restoreActions += act->mPinActions; - act->mPinActions = restoreActions; - } - else - { - mUndoAction = new ActionPingroup(restoreActions); - } + for (const AtomicAction& aa : (*it)) + restoreActions.append(aa); } for (u32 grpId : mGroupToRemove) { - if (mUndoAction) - { - ActionPingroup* act = static_cast(mUndoAction); - act->mPinActions.append(AtomicAction(PinActionType::GroupDelete,grpId)); - } - else - mUndoAction = new ActionPingroup(PinActionType::GroupDelete,grpId); + restoreActions.append(AtomicAction(PinActionType::GroupDelete,grpId)); } - if (mUndoAction) mUndoAction->setObject(object()); + if (!restoreActions.isEmpty()) + { + mUndoAction = new ActionPingroup(restoreActions); + mUndoAction->setObject(object()); + } } int ActionPingroup::pinGroupRow(const Module *m, PinGroup* pgroup) @@ -283,6 +258,7 @@ namespace hal mGroupRestore.clear(); mPinsMoved.clear(); mGroupToRemove.clear(); + mTempUndoActions.clear(); if (mObject.type() != UserActionObjectType::Module) return false; @@ -304,7 +280,14 @@ namespace hal if (it == mPinGroups.end()) { pgroup = mParentModule->get_pin_group_by_id(aa.mId); - if (!pgroup) return false; + if (!pgroup) + { + // special case : the group delete command cannot be executed since the + // group was already deleted when re-assigning its last pin + if (aa.mType == PinActionType::GroupDelete) + continue; + return false; + } mPinGroups.insert(aa.mId,pgroup); } else @@ -320,13 +303,8 @@ namespace hal { case PinActionType::GroupCreate: { - int startIndex = aa.mValue; - bool ascending = true; - if (aa.mValue < 0) - { - ascending = false; - startIndex = -aa.mValue-1; - } + int startIndex = aa.mValue >> 1; + bool ascending = (aa.mValue & 1) > 0; if (aa.mId > 0) { if (auto res = mParentModule->create_pin_group(aa.mId, aa.mName.toStdString(), {}, PinDirection::none, PinType::none,ascending,startIndex); res.is_ok()) @@ -350,46 +328,51 @@ namespace hal } case PinActionType::GroupDelete: { - int v = pgroup->get_start_index(); - if (!pgroup->is_ascending()) v = -v-1; + int v = (pgroup->get_lowest_index() << 1) | (pgroup->is_ascending() ? 1 : 0); u32 id = pgroup->get_id(); int ptype = (int) pgroup->get_type(); int pdir = (int) pgroup->get_direction(); QString name = QString::fromStdString(pgroup->get_name()); if (!mParentModule->delete_pin_group(pgroup)) return false; - addUndoAction(PinActionType::GroupCreate,id,name,v); - addUndoAction(PinActionType::GroupTypeChange,id,"",ptype); - addUndoAction(PinActionType::GroupDirChange,id,"",pdir); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::GroupCreate,id,name,v), + AtomicAction(PinActionType::GroupTypeChange,id,"",ptype), + AtomicAction(PinActionType::GroupDirChange,id,"",pdir)})); break; } case PinActionType::GroupMoveToRow: { int inx = pinGroupRow(mParentModule,pgroup); if (inx < 0) return false; - addUndoAction(PinActionType::GroupMoveToRow,pgroup->get_id(),"",inx); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::GroupMoveToRow,pgroup->get_id(),"",inx)})); if (!mParentModule->move_pin_group(pgroup,aa.mValue)) return false; break; } case PinActionType::GroupRename: - addUndoAction(PinActionType::GroupRename,pgroup->get_id(),QString::fromStdString(pgroup->get_name())); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::GroupRename,pgroup->get_id(),QString::fromStdString(pgroup->get_name()))})); if (!mParentModule->set_pin_group_name(pgroup,aa.mName.toStdString())) return false; break; case PinActionType::GroupTypeChange: - addUndoAction(PinActionType::GroupTypeChange,pgroup->get_id(),"",(int)pgroup->get_type()); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::GroupTypeChange,pgroup->get_id(),"",(int)pgroup->get_type())})); if (!mParentModule->set_pin_group_type(pgroup, (PinType) aa.mValue)) return false; break; case PinActionType::GroupDirChange: - addUndoAction(PinActionType::GroupDirChange,pgroup->get_id(),"",(int)pgroup->get_direction()); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::GroupDirChange,pgroup->get_id(),"",(int)pgroup->get_direction())})); if (!mParentModule->set_pin_group_direction(pgroup, (PinDirection) aa.mValue)) return false; break; case PinActionType::PinAsignToGroup: - addUndoAction(PinActionType::PinAsignToGroup,aa.mId,"",pin->get_group().first->get_id()); - addUndoAction(PinActionType::PinMoveToRow,aa.mId,"",pinIndex2Row(pin,pin->get_group().second)); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::PinAsignToGroup,aa.mId,"",pin->get_group().first->get_id()), + AtomicAction(PinActionType::PinMoveToRow,aa.mId,"",ActionPingroup::pinIndex2Row(pin,pin->get_group().second))})); mPinsMoved.insert(aa.mId); pgroup = getGroup(aa.mValue); if (!pgroup) return false; @@ -401,20 +384,23 @@ namespace hal // dumpPingroups(); break; case PinActionType::PinRename: - addUndoAction(PinActionType::PinRename,aa.mId, QString::fromStdString(pin->get_name())); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::PinRename,aa.mId, QString::fromStdString(pin->get_name()))})); if (!mParentModule->set_pin_name(pin, aa.mName.toStdString())) return false; break; case PinActionType::PinTypeChange: - addUndoAction(PinActionType::PinTypeChange,aa.mId,"",(int)pin->get_type()); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::PinTypeChange,aa.mId,"",(int)pin->get_type())})); if (!mParentModule->set_pin_type(pin, (PinType) aa.mValue)) return false; break; case PinActionType::PinMoveToRow: if (!mPinsMoved.contains(aa.mId)) - addUndoAction(PinActionType::PinMoveToRow,aa.mId,"",pinIndex2Row(pin,pin->get_group().second)); + mTempUndoActions.append(QList({ + AtomicAction(PinActionType::PinMoveToRow,aa.mId,"",ActionPingroup::pinIndex2Row(pin,pin->get_group().second))})); pgroup = pin->get_group().first; - if (!mParentModule->move_pin_within_group(pgroup,pin,pinRow2Index(pin,aa.mValue))) + if (!mParentModule->move_pin_within_group(pgroup,pin,ActionPingroup::pinRow2Index(pin,aa.mValue))) { qDebug() << "move_pin_within_group failed"; return false; @@ -498,7 +484,11 @@ namespace hal bool doNotDelete = false; // if there is a pin with the same name as the int vid = -1; - for (ModulePin* pin : groupToDelete->get_pins()) + std::vector orderedPins = groupToDelete->get_pins(); + if (groupToDelete->is_descending()) + std::reverse(orderedPins.begin(), orderedPins.end()); + + for (ModulePin* pin : orderedPins) { if (pin->get_name() == groupToDelete->get_name()) doNotDelete = true; @@ -571,13 +561,14 @@ namespace hal PinGroup* pinGroup = m->get_pin_group_by_id(grpId); if (!pinGroup) return nullptr; bool toAscending = ! pinGroup->is_ascending(); + int val = (pinGroup->get_lowest_index() << 1) | (toAscending ? 1 : 0); std::vector pins = pinGroup->get_pins(); QString tempName = QUuid::createUuid().toString(); QString grpName = QString::fromStdString(pinGroup->get_name()); int grpRow = pinGroupRow(m, pinGroup); static int vid = -9; - ActionPingroup* retval = new ActionPingroup(PinActionType::GroupCreate,vid,tempName,toAscending ? 0 : -1); + ActionPingroup* retval = new ActionPingroup(PinActionType::GroupCreate,vid,tempName,val); if (toAscending) { for (auto it = pins.rbegin(); it != pins.rend(); ++it) @@ -615,10 +606,8 @@ namespace hal : mId(pgroup->get_id()), mName(QString::fromStdString(pgroup->get_name())), mRow(pinGroupRow(m,pgroup)), - mStartIndex(pgroup->get_start_index()), + mStartIndex( (pgroup->get_lowest_index() << 1) | (pgroup->is_ascending() ? 1 : 0)), mDirection(pgroup->get_direction()), mType(pgroup->get_type()) - { - if (!pgroup->is_ascending()) mStartIndex = -mStartIndex-1; - } + {;} }