HAL  v4.5.0-254-g8f9f6a423
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
pin_model.cpp
Go to the documentation of this file.
4 
5 namespace hal
6 {
8  {
9  // use root item to store header information
10  setHeaderLabels(QStringList() << "Name" << "Direction" << "Type");
11  mAssignedGroupNames = QSet<QString>();
12  mAssignedPinNames = QSet<QString>();
13  mEditable = false;
14 
15  //connect(this, &PinModel::dataChanged, this, &PinModel::handleInvalidGroupUpdate);
16  }
17 
18  PinModel::PinModel(QObject* parent, bool editable) : BaseTreeModel(parent)
19  {
20  // use root item to store header information
21  setHeaderLabels(QStringList() << "Name" << "Direction" << "Type");
22  mAssignedGroupNames = QSet<QString>();
23  mAssignedPinNames = QSet<QString>();
24  mEditable = editable;
25  }
26 
29  }
30 
31 
33  {
34  if(!index.isValid()) return Qt::ItemFlags();
35  if(!mEditable)
37 
39  }
40 
42 
43  //TODO change font of dummy entries
44  clear();
45 
46 
47  //get all pins of a given gate if it exists
48  /*if(gate){
49  for (auto pinGroup : gate->get_pin_groups())
50  {
51  PINGROUP* groupStruct = new PINGROUP;
52  groupStruct->name = QString::fromStdString(pinGroup->get_name());
53  groupStruct->id = pinGroup->get_id();
54  groupStruct->direction = pinGroup->get_direction();
55  groupStruct->type = pinGroup->get_type();
56  for (auto pin : pinGroup->get_pins())
57  {
58  PIN* pinStruct = new PIN;
59  pinStruct->name = QString::fromStdString(pin->get_name());
60  pinStruct->id = pin->get_id();
61  pinStruct->direction = pin->get_direction();
62  pinStruct->type = pin->get_type();
63  groupStruct->pins.append(pinStruct);
64  }
65  mPinGroups.append(groupStruct);
66  }
67  }*/
68 
69  QList<PinItem*> tempGroupList;
70 
71  if(gate){
72  for (auto pinGroup : gate->get_pin_groups())
73  {
75  groupStruct->setName(QString::fromStdString(pinGroup->get_name()));
76  groupStruct->setId(pinGroup->get_id());
77  groupStruct->setDirection(pinGroup->get_direction());
78  groupStruct->setType(pinGroup->get_type());
79  for (auto pin : pinGroup->get_pins())
80  {
81  PinItem* pinStruct = new PinItem(PinItem::TreeItemType::Pin);
82  pinStruct->setName(QString::fromStdString(pin->get_name()));
83  pinStruct->setId(pin->get_id());
84  pinStruct->setDirection(pin->get_direction());
85  pinStruct->setType(pin->get_type());
86  groupStruct->appendChild(pinStruct);
87  }
88  tempGroupList.append(groupStruct);
89  }
90  }
91 
93  for(auto group : tempGroupList){
94  auto groupItem = new PinItem(PinItem::TreeItemType::PinGroup);
95  //get all infos for that group
96  PinDirection groupDirection = group->getDirection();
97  PinType groupType = group->getPinType();
98 
99  //create group item
100  groupItem->setId(group->getId());
101  groupItem->setName(group->getName());
102  groupItem->setDirection(groupDirection);
103  groupItem->setType(groupType);
104  for (auto item : group->getChildren())
105  {
106  auto pinItem = new PinItem(PinItem::TreeItemType::Pin);
107  PinItem* pin = static_cast<PinItem*>(item);
108 
109  //get all infos for that pin
110  PinDirection pinDirection = pin->getDirection();
111  PinType pinType = pin->getPinType();
112 
113  pinItem->setName(pin->getName());
114  pinItem->setDirection(pinDirection);
115  pinItem->setType(pinType);
116 
117  groupItem->appendChild(pinItem);
118 
119  //add pinItem to the mapped name
120  mAssignedPinNames.insert(pinItem->getName());
121  }
122 
123  //add dummy to each group if model is editable
124  if(mEditable)
125  {
126  auto dummyPin = new PinItem(PinItem::TreeItemType::PinCreator);
127  dummyPin->setData(QList<QVariant>() << "create new pin ...");
128  groupItem->appendChild(dummyPin);
129  }
130 
131  mRootItem->appendChild(groupItem);
132 
133  //add groupItem to mapped name
134  //add pinItem to the mapped name
135  mAssignedGroupNames.insert(groupItem->getName());
136  }
137 
138  //create dummy for the group creator if model is editable
139  if(mEditable)
140  {
141  auto dummyGroup = new PinItem(PinItem::TreeItemType::GroupCreator);
142  dummyGroup->setData(QList<QVariant>() << "create new pingroup ...");
143  mRootItem->appendChild(dummyGroup);
144  }
145 
146  endResetModel();
147  }
148 
150  {
151  if(!index.isValid()) return;
152  //TODO handle text edited from PinDelegate
153  auto pinItem = static_cast<PinItem*>(index.internalPointer());
154  auto itemType = pinItem->getItemType();
155 
156  switch(itemType){
158  //qInfo() << "was Group: " << pinItem->getName();
159  if (renamePinGroup(pinItem, input))
160  pinItem->setName(input);
161 
162  break;
163  }
165  //qInfo() << "was Pin: " << pinItem->getName();
166  if(renamePin(pinItem, input))
167  pinItem->setName(input);
168  break;
169  }
171  //TODO also check pin names when a group is created - otherwise a group with e.g name I1 will create a pin with the same name but this one isnt checked
172 
173  //qInfo() << "was GroupCreator: " << pinItem->getName();
174  // creates a new pingroup with a pin which is not valid until edited
175 
176  if(!renamePinGroup(pinItem, input))
177  return;
178 
179  pinItem->setFields(input, getNextId(PinItem::TreeItemType::PinGroup), PinDirection::none, PinType::none);
180  pinItem->setItemType(PinItem::TreeItemType::InvalidPinGroup);
181  mInvalidGroups.append(pinItem);
182 
183  beginInsertRows(index.parent(), 0, 0);
184  // add initial pin to pingroup
185  auto initialPin = new PinItem(PinItem::TreeItemType::InvalidPin);
186  initialPin->setFields(input, 0, PinDirection::none, PinType::none);
187  pinItem->appendChild(initialPin);
188 
189  mAssignedPinNames.insert(input);
190 
191  //add new dummypin to the group
192  auto dummyPin = new PinItem(PinItem::TreeItemType::PinCreator);
193  //dummyPin->setData(QList<QVariant>() << "create new pin ...");
194  pinItem->appendChild(dummyPin);
195 
196  //add new dummygroup after entry
197  auto dummyGroup = new PinItem(PinItem::TreeItemType::GroupCreator);
198  //dummyGroup->setData(QList<QVariant>() << "create new group ...");
199  pinItem->getParent()->appendChild(dummyGroup);
200 
201 
202  //create new pinGroupStruct and add it to the list of pingroups
203  PinItem* newPinGroup = new PinItem(PinItem::TreeItemType::PinGroup);
204  newPinGroup->setId(pinItem->getId());
205  newPinGroup->setName(pinItem->getName());
206  newPinGroup->setDirection(pinItem->getDirection());
207  newPinGroup->setType(pinItem->getPinType());
208  endInsertRows();
209 
210  //add pin to group
211  //addPinToPinGroup(initialPin, pinItem);
212 
214  break;
215  }
217  //qInfo() << "was PinCreator: " << pinItem->getName();
218  // creates a new pin which is not valid until now nor created via gate->create_pin()
219  if(!renamePin(pinItem, input))
220  break;
221  PinItem* parentGroup = static_cast<PinItem*>(pinItem->getParent());
222  PinDirection pdir = parentGroup->getDirection();
223  PinType ptype = parentGroup->getPinType();
224  pinItem->setFields(input, getNextId(PinItem::TreeItemType::Pin), pdir, ptype);
225  if(pdir != PinDirection::none) pinItem->setItemType(PinItem::TreeItemType::Pin);
226  else pinItem->setItemType(PinItem::TreeItemType::InvalidPin);
227  mInvalidPins.append(pinItem);
228 
230  //add new dummy after entry
231  auto dummyPin = new PinItem(PinItem::TreeItemType::PinCreator);
232  //dummyPin->setData(QList<QVariant>() << "create new pin ...");
233  pinItem->getParent()->appendChild(dummyPin);
234  endInsertRows();
235 
236  //add pinItem to pinGroups
237  //auto pinGroup = static_cast<PinItem*>(pinItem->getParent());
238  //addPinToPinGroup(pinItem, pinGroup);
239 
241  break;
242  }
244  if(renamePin(pinItem, input))
245  pinItem->setName(input);
246  break;
247  }
248  }
249 
251  }
252 
254  {
255  if(!index.isValid()) return;
256  //TODO handle direction edited from PinDelegate
257  auto pinItem = static_cast<PinItem*>(index.internalPointer());
258  auto itemType = pinItem->getItemType();
259 
260  PinDirection oldDirection = pinItem->getDirection();
261  PinDirection pinDirection = enum_from_string<PinDirection>(directionString.toStdString());
262 
263  switch(itemType){
266  pinItem->setDirection(directionString);
267  for(auto child : pinItem->getChildren()) //set same direction for all pins of the pingroup
268  {
269  PinItem* pin = static_cast<PinItem*>(child);
271  pin->setDirection(directionString);
272  handleInvalidPinUpdate(pin);
273  }
274  }
275  handleInvalidGroupUpdate(pinItem);
276  break;
277  }
280  QMessageBox warning;
281  QPushButton* acceptBtn = warning.addButton(tr("Continue with changes"), QMessageBox::AcceptRole);
282  QPushButton* abortBtn = warning.addButton(QMessageBox::Abort);
283  PinItem* parentGroup = static_cast<PinItem*>(pinItem->getParent());
284  warning.setWindowTitle("New pin creation");
285  warning.setText(QString("You are about to create an %1 pin in an %2 pin group")
286  .arg(directionString)
287  .arg(parentGroup->getDirectionAsText()));
288  if(pinDirection != parentGroup->getDirection())
289  {
290  warning.exec();
291  if(warning.clickedButton() == acceptBtn){
292  pinItem->setDirection(pinDirection);
293  handleInvalidPinUpdate(pinItem);
294  }
295  }
296  else
297  {
298  pinItem->setDirection(pinDirection);
299  handleInvalidPinUpdate(pinItem);
300  }
301  break;
302  }
303  }
305  if (oldDirection == PinDirection::none)
307  }
308 
310  {
311  if(!index.isValid()) return;
312  auto pinItem = static_cast<PinItem*>(index.internalPointer());
313  auto itemType = pinItem->getItemType();
314 
315  PinType pinType = enum_from_string<PinType>(typeString.toStdString());
316 
317  switch (itemType)
318  {
320  pinItem->setType(pinType);
321  handleInvalidPinUpdate(pinItem);
322  break;
323  }
325  pinItem->setType(pinType);
326  break;
327  }
329  pinItem->setType(pinType);
330  for(auto child : pinItem->getChildren()) //set same type for all pins of the pingroup
331  {
332  PinItem* pin = static_cast<PinItem*>(child);
334  pin->setType(pinType);
335  handleInvalidPinUpdate(pin);
336  }
337  }
338  handleInvalidGroupUpdate(pinItem);
339  break;
340  }
342  pinItem->setType(pinType);
343  //PinModel::PINGROUP* pinGroup = static_cast<PinModel::PINGROUP*>(pinItem);
344 
345  /*for(auto child : pinItem->getChildren()) //set same type for all pins of the pingroup
346  {
347  PinItem* pin = static_cast<PinItem*>(child);
348  if(pin->getItemType() == PinItem::TreeItemType::Pin || pin->getItemType() == PinItem::TreeItemType::InvalidPin){
349  pin->setType(type);
350  }
351  }*/
352 
353  for(auto group : getPinGroups()){
354  if(group->getName() == pinItem->getName()){
355  for(auto item : group->getChildren()){
356  PinItem* pin = static_cast<PinItem*>(item);
357  pin->setType(pinType);
358  }
359  break;
360  }
361  }
362  }
363  }
365  }
366 
367 
368  void PinModel::addPinToPinGroup(PinItem* pinItem, PinItem* groupItem)
369  {
370  QModelIndex index = getIndexFromItem(groupItem);
371  if(!index.isValid()) return;
372  beginInsertRows(index, groupItem->getChildCount(), groupItem->getChildCount());
373  groupItem->appendChild(pinItem);
374  endInsertRows();
375  }
376 
377 
378  bool PinModel::renamePin(PinItem* pinItem, const QString& newName)
379  {
380  //TODO change pinItems name within function and not after its call
381 
382  QString name = newName;
383  QRegularExpression rx("^[A-Za-z]([A-Za-z]|\\d|_|\\(|\\))*$");
384  QValidator* val = new QRegularExpressionValidator(rx, this);
385  int pos = 0;
386  if(val->validate(name, pos) != QValidator::Acceptable) return false;
387 
388  //Check if name is already in use
389  if(isNameAvailable(newName, pinItem)){
390  //delete old name from being assigned and add new name
391  mAssignedPinNames.remove(pinItem->getName());
392  mAssignedPinNames.insert(newName);
393 
394  //rename PinItem
395  pinItem->setName(newName);
396 
397  return true;
398  }
399 
400  return false;
401  }
402 
403  bool PinModel::renamePinGroup(PinItem* groupItem, const QString& newName)
404  {
405  //TODO change pinItems name within function and not after its call
406 
407  QString name = newName;
408  QRegularExpression rx("^[A-Za-z]([A-Za-z]|\\d|_|\\(|\\))*$");
409  QValidator* val = new QRegularExpressionValidator(rx, this);
410  int pos = 0;
411  if(val->validate(name, pos) != QValidator::Acceptable) return false;
412  //Check if name is already in use
413  if(isNameAvailable(newName, groupItem)){
414  //delete old name from being assigned and add new name
415  mAssignedGroupNames.remove(groupItem->getName());
416  mAssignedGroupNames.insert(newName);
417 
418  //rename PinItem
419 
420  groupItem->setName(newName);
421 
422  //rename corresponding pinGroup
423  /*for(auto group : getPinGroups()){
424  if(group->getId() == groupItem->getId()){
425  //stop here
426  group->setName(newName);
427  break;
428  }
429  }*/
430  return true;
431  }
432 
433  return false;
434  }
435 
436  bool PinModel::isNameAvailable(const QString& newName, PinItem* treeItem){
437  //check if the new name is the same as the old one
438  if(newName == treeItem->getName())
439  return true;
440 
441  //get type of the pin item
442  PinItem::TreeItemType type = treeItem->getItemType();
444  if(isGroup){
445  if (mAssignedGroupNames.contains(newName))
446  {
447  log_warning("gui", "Pin group name '{}' not available, another group with that name exists.", newName.toStdString());
448  return false;
449  }
450  if (!mAssignedPinNames.contains(newName))
451  {
452  return true;
453  }
454  // Pin with intended new name exists. However, this is OK if pin is part of this group.
455  for (BaseTreeItem* bti : treeItem->getChildren())
456  {
457  if (static_cast<PinItem*>(bti)->getName() == newName)
458  return true;
459  }
460  log_warning("gui", "Pin group name '{}' not available, another group contains a pin with that name.", newName.toStdString());
461  return false;
462  }
463  else{
464  //get group name
465  QString groupName = static_cast<PinItem*>(treeItem->getParent())->getName();
466  //check if pin can be named after the group
467  if(groupName == newName && !mAssignedPinNames.contains(newName))
468  {
469  return true;
470  }
471  //check if other group or pin has the name
472  else{
473  return !(mAssignedGroupNames.contains(newName) || mAssignedPinNames.contains(newName));
474  }
475  }
476  }
477 
478  void PinModel::handleInvalidPinUpdate(PinItem* pinItem)
479  {
480  if(!isNameAvailable(pinItem->getName(), pinItem)
481  || pinItem->getDirection() == PinDirection::none)
482  return; // Pin is not valid
483 
484  //pin is valid
485  pinItem->setItemType(PinItem::TreeItemType::Pin);
486  mInvalidPins.removeAll(pinItem);
487 
488  //checks if the groups status is affected and if so it updates the group
489  auto pinGroup = static_cast<PinItem*>(pinItem->getParent());
490  handleInvalidGroupUpdate(pinGroup);
491  }
492 
493  void PinModel::handleInvalidGroupUpdate(PinItem* groupItem){
494  bool isValid = true;
495 
496  //calculate new direction
497  //handleGroupDirectionUpdate(groupItem);
498 
499  //check each pin in the group if its valid or not
500  QList<PinItem*> childs = QList<PinItem*>();
501  for(auto baseTreeItem : groupItem->getChildren()){
502  auto childPin = static_cast<PinItem*>(baseTreeItem);
503  //if the child is invalid then the group cant be valid
504  if(childPin->getItemType() == PinItem::TreeItemType::InvalidPin){
505  isValid = false;
506  break;
507  }
508  if(childPin->getItemType() != PinItem::TreeItemType::PinCreator)
509  childs.append(childPin);
510  }
511 
512  if(isValid){
513 
514  groupItem->setItemType(PinItem::TreeItemType::PinGroup);
515  /*
516  mInvalidGroups.removeAll(groupItem);
517  PINGROUP* pinGroup = new PINGROUP;
518  pinGroup->id = groupItem->id();
519  pinGroup->name = groupItem->getName();
520  pinGroup->direction = enum_from_string<PinDirection>(groupItem->getDirection().toStdString());
521  pinGroup->type = enum_from_string<PinType>(groupItem->getType().toStdString());
522 
523  //add children to pinGroup
524  for(auto pin : childs){
525  PIN* pinStruct = new PIN;
526  pinStruct->name = pin->getName();
527  pinStruct->id = pin->id();
528  pinStruct->direction = enum_from_string<PinDirection>(pin->getDirection().toStdString());
529  pinStruct->type = enum_from_string<PinType>(pin->getType().toStdString());
530  pinGroup->pins.append(pinStruct);
531  }
532  mPinGroups.append(pinGroup);*/
533  }
534  }
535 
536  void PinModel::handleGroupDirectionUpdate(PinItem* groupItem, PinDirection direction){
538  //direction was chosen manually
539  groupItem->setDirection(QString::fromStdString(enum_to_string(direction)));
540  return;
541  }
542 
543  //direction has to be calculated based on contained pins
544 
545  //bitmask with inout = 2³, out = 2², in = 2¹, internal = 2⁰
546  /*int directionMask = 0;
547 
548  for(BaseTreeItem* pin : groupItem->getChildren()){
549  QString dir = static_cast<PinItem*>(pin)->getDirection();
550  if(dir.toStdString() == enum_to_string(PinDirection::inout))
551  directionMask = directionMask | (1 << 3);
552  else if(dir.toStdString() == enum_to_string(PinDirection::output))
553  directionMask = directionMask | (1 << 2);
554  else if(dir.toStdString() == enum_to_string(PinDirection::input))
555  directionMask = directionMask | 1 << 1;
556  else if(dir.toStdString() == enum_to_string(PinDirection::internal))
557  directionMask = directionMask | 1;
558 
559  //if all bits are set then break
560  if(directionMask >= (1 << 4) - 1)
561  break;
562  }
563 
564 
565  PinDirection calcDir = enum_from_string<PinDirection>(groupItem->getDirection().toStdString());
566 
567  //inout or in and out was set
568  if(directionMask >= (1 << 3) || (directionMask & (1<<2) && directionMask & (1<<1))){
569  calcDir = PinDirection::inout;
570  }
571  //inout is not set and in and out are not set simultaneously
572  else if(directionMask >= 1<<2){
573  calcDir = PinDirection::output;
574  }
575  else if(directionMask > 1){
576  calcDir = PinDirection::input;
577  }
578  else if(directionMask > 0){
579  calcDir = PinDirection::internal;
580  }
581 
582  //else it should stay to what it was before
583 
584  //set calculated direction
585  groupItem->setDirection(QString::fromStdString(enum_to_string(calcDir)));*/
586  }
587 
588  void PinModel::printGateMember()
589  {
590  qInfo() << "Printing PinGroups and Pins";
591  for(auto pinGroup : getPinGroups()){
592  qInfo() << "PinGroup: " << pinGroup->getName() << " " << pinGroup->getId();
593  for(auto item : pinGroup->getChildren()){
594  PinItem* pin = static_cast<PinItem*>(item);
595  qInfo() << " Pin: " << pin->getName() << " " << pin->getId();
596  }
597  }
598  }
599 
600  u32 PinModel::getNextId(PinItem::TreeItemType type)
601  {
602  QSet<u32> takenGroupIds = QSet<u32>();
603  QSet<u32> takenPinIds = QSet<u32>();
604 
605  //get all currently taken ids
606  for(auto item : getPinGroups()){
607  PinItem* pinGroup = static_cast<PinItem*>(item);
608  takenGroupIds.insert(pinGroup->getId());
609  for(auto item : pinGroup->getChildren()){
610  PinItem* pin = static_cast<PinItem*>(item);
611  takenPinIds.insert(pin->getId());
612  }
613  }
614 
615  //find next available id
616  u32 counter = 1;
617  // can result in an endless loop if 2^32 ids are taken
618 
620  while(takenGroupIds.contains(counter)){
621  counter++;
622  }
623  }
624  else if(type == PinItem::TreeItemType::Pin){
625  while(takenPinIds.contains(counter)){
626  counter++;
627  }
628  }
629  else{
630  return 0;
631  }
632 
633  return counter;
634  }
635 
637  {
638  QList<PinItem*> retval;
639  for (BaseTreeItem* bti : mRootItem->getChildren())
640  {
641  PinItem* grp = static_cast<PinItem*>(bti);
642  if (grp->getItemType() != PinItem::TreeItemType::PinGroup) continue;
643  retval.append(grp);
644  }
645  return retval;
646  }
647 
649  {
650  //check index
651  if(!index.isValid()) return;
652  //get item from index
653  auto item = static_cast<PinItem*>(getItemFromIndex(index));
654 
655  if(!item)
656  return;
657 
658  //remove item from the PinItem list
659 
660  //check the type of the item
661  PinItem::TreeItemType type = item->getItemType();
663  //handle group deletion
664  beginRemoveRows(index, 0, 0);
665  //delete all pins of the pingroup
666  for(auto i : item->getChildren()){
667  item->removeChild(i);
668  }
669  //delete the group
670  getRootItem()->removeChild(item);
671 
672  /*for(auto item : getPinGroups()){
673  PinItem* group = static_cast<PinItem*>(item);
674  //delete all pins from the group and free group afterward
675  if(group->getId() == item->getId()){
676  for(auto pin : group->getChildren()){
677  delete(pin);
678  }
679  delete(group);
680  break;
681  }
682  }*/
683  //remove actual modelItem
684 
685  endRemoveRows();
686  handleItemRemoved(item);
687  }
689  //handle pin deletion
690 
691  //get the parent group of the pin
692  PinItem* parentGroup = static_cast<PinItem*>(item->getParent());
693  /*
694  for(auto item : getPinGroups()){
695  PinItem* group = static_cast<PinItem*>(item);
696  if(group->getId() == parentGroup->getId()){
697  //delete pin from the group
698  for(auto itemPin : group->getChildren()){
699  PinItem* pin = static_cast<PinItem*>(itemPin);
700  if(pin->getId() == item->getId()){
701  group->removeChild(pin);
702  delete(pin);
703  break;
704  }
705  }
706  break;
707  }
708  }*/
709  //remove actual modelItem
710  beginRemoveRows(index, 0, 0);
711  parentGroup->removeChild(item);
712  endRemoveRows();
713  handleItemRemoved(item);
714  }
715  }
716 
717  void PinModel::handleItemRemoved(PinItem* item)
718  {
719 
720  //TODO reorganize name handling
721  //remove name from assigned list
723  //name should be unique amongst pingroups so this can be deleted
724  mAssignedGroupNames.remove(item->getName());
725  mAssignedPinNames.remove(item->getName());
726  }
727  else{
728  //item was a pin so we have to check if the parent group is assigned to that name, otherwise it can be freed
729  mAssignedPinNames.remove(item->getName());
730  }
731  }
732 
734  {
735  QList<PinItem*> inputPins;
736  for(BaseTreeItem* pinGroup : mRootItem->getChildren())
737  {
738  if (static_cast<PinItem*>(pinGroup)->getItemType() != PinItem::TreeItemType::PinGroup) continue;
739  for(BaseTreeItem* item : pinGroup->getChildren()){
740  PinItem* pin = static_cast<PinItem*>(item);
741  if (pin->getItemType() != PinItem::TreeItemType::Pin) continue;
742  if (pin->getDirection() == PinDirection::input || pin->getDirection() == PinDirection::inout) inputPins.append(pin);
743  }
744  }
745  return inputPins;
746  }
747 
749  {
750  QList<PinItem*> outputPins;
751  for(BaseTreeItem* pinGroup : mRootItem->getChildren())
752  {
753  if (static_cast<PinItem*>(pinGroup)->getItemType() != PinItem::TreeItemType::PinGroup) continue;
754  for(BaseTreeItem* item : pinGroup->getChildren()){
755  PinItem* pin = static_cast<PinItem*>(item);
756  if (pin->getItemType() != PinItem::TreeItemType::Pin) continue;
757  if (pin->getDirection() == PinDirection::output || pin->getDirection() == PinDirection::inout) outputPins.append(pin);
758  }
759  }
760  return outputPins;
761  }
762 
764  {
765  QList<PinItem*> internalPins;
766  for(BaseTreeItem* pinGroup : mRootItem->getChildren())
767  {
768  if (static_cast<PinItem*>(pinGroup)->getItemType() != PinItem::TreeItemType::PinGroup) continue;
769  for(BaseTreeItem* item : pinGroup->getChildren()){
770  PinItem* pin = static_cast<PinItem*>(item);
771  if (pin->getItemType() != PinItem::TreeItemType::Pin) continue;
772  if (pin->getDirection() == PinDirection::internal) internalPins.append(pin);
773  }
774  }
775  return internalPins;
776  }
777 
778 }
(Future) Base class for all tree models related to the details widget.
virtual QList< BaseTreeItem * > getChildren() const
virtual bool removeChild(BaseTreeItem *child)
virtual int getChildCount() const
virtual void appendChild(BaseTreeItem *child)
The BaseTreeModel implements generic standard functions of a tree model.
QModelIndex getIndexFromItem(BaseTreeItem *item) const
RootTreeItem * mRootItem
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
virtual void clear()
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
BaseTreeItem * getRootItem() const
void setHeaderLabels(const QStringList &label)
BaseTreeItem * getItemFromIndex(QModelIndex index) const
std::vector< PinGroup< GatePin > * > get_pin_groups(const std::function< bool(PinGroup< GatePin > *)> &filter=nullptr) const
Definition: gate_type.cpp:548
An item in the PinModel.
Definition: pin_item.h:48
QString getName() const
Definition: pin_item.cpp:81
void setId(u32 newId)
Definition: pin_item.cpp:72
PinDirection getDirection() const
Definition: pin_item.cpp:96
TreeItemType getItemType() const
Definition: pin_item.cpp:132
PinType getPinType() const
Definition: pin_item.cpp:86
void setName(const QString &name)
Definition: pin_item.cpp:111
void setType(const QString &type)
Definition: pin_item.cpp:121
QString getDirectionAsText() const
Definition: pin_item.cpp:101
void setDirection(const QString &direction)
Definition: pin_item.cpp:116
QList< PinItem * > getInputPins()
Definition: pin_model.cpp:733
PinModel(QObject *parent=nullptr)
Definition: pin_model.cpp:7
QList< PinItem * > getOutputPins()
Definition: pin_model.cpp:748
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: pin_model.cpp:32
void handleEditDirection(QModelIndex index, const QString &directionString)
Definition: pin_model.cpp:253
QList< PinItem * > getPinGroups() const
Definition: pin_model.cpp:636
void setGate(GateType *gate)
Definition: pin_model.cpp:41
QList< PinItem * > getInternalPins()
Definition: pin_model.cpp:763
void handleEditName(QModelIndex index, const QString &input)
Definition: pin_model.cpp:149
void editNewDone(QModelIndex index)
void handleDeleteItem(QModelIndex index)
Definition: pin_model.cpp:648
void handleEditType(QModelIndex index, const QString &typeString)
Definition: pin_model.cpp:309
uint32_t u32
Definition: defines.h:41
#define log_warning(channel,...)
Definition: log.h:76
Definition: defines.h:45
PinDirection
Definition: pin_direction.h:36
PinType
Definition: pin_type.h:36
std::string enum_to_string(T e)
Definition: enums.h:53
PinType type
PinDirection direction
std::string name
void beginInsertRows(const QModelIndex &parent, int first, int last)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles)
void append(const T &value)
void addButton(QAbstractButton *button, QMessageBox::ButtonRole role)
QAbstractButton * clickedButton() const const
virtual int exec() override
void setWindowTitle(const QString &title)
void setText(const QString &text)
void * internalPointer() const const
bool isValid() const const
QModelIndex parent() const const
Q_EMITQ_EMIT
QString tr(const char *sourceText, const char *disambiguation, int n)
bool contains(const T &value) const const
QSet::iterator insert(const T &value)
bool remove(const T &value)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromStdString(const std::string &str)
std::string toStdString() const const
typedef ItemFlags
virtual QValidator::State validate(QString &input, int &pos) const const=0