HAL
gui_api.cpp
Go to the documentation of this file.
1 #include "gui/gui_api/gui_api.h"
2 
3 
4 #include "gui/gui_globals.h"
19 #include "hal_core/utilities/log.h"
20 
21 #include <algorithm>
22 
23 #include <QSet>
24 
25 namespace hal
26 {
28  {
29  gSelectionRelay->registerSender(this, "GUI API");
30  }
31 
32  std::vector<u32> GuiApi::getSelectedGateIds()
33  {
35  }
36 
37  std::vector<u32> GuiApi::getSelectedNetIds()
38  {
40  }
41 
42  std::vector<u32> GuiApi::getSelectedModuleIds()
43  {
45  }
46 
47  std::tuple<std::vector<u32>, std::vector<u32>, std::vector<u32>> GuiApi::getSelectedItemIds()
48  {
49  return std::make_tuple(getSelectedGateIds(), getSelectedNetIds(), getSelectedModuleIds());
50  }
51 
52  std::vector<Gate*> GuiApi::getSelectedGates()
53  {
54  std::vector<Gate*> gates;
56  gates.push_back(gNetlist->get_gate_by_id(id));
57  return gates;
58  }
59 
60  std::vector<Net*> GuiApi::getSelectedNets()
61  {
62  std::vector<Net*> nets;
64  nets.push_back(gNetlist->get_net_by_id(id));
65  return nets;
66  }
67 
68  std::vector<Module*> GuiApi::getSelectedModules()
69  {
70  std::vector<Module*> modules;
72  modules.push_back(gNetlist->get_module_by_id(id));
73  return modules;
74  }
75 
76  std::tuple<std::vector<Gate*>, std::vector<Net*>, std::vector<Module*>> GuiApi::getSelectedItems()
77  {
78  return std::make_tuple(getSelectedGates(), getSelectedNets(), getSelectedModules());
79  }
80 
81  void GuiApi::selectGate(Gate* gate, bool clear_current_selection, bool navigate_to_selection)
82  {
83  if(!gNetlist->is_gate_in_netlist(gate))
84  return;
85 
86  if(clear_current_selection)
88 
89  gSelectionRelay->addGate(gate->get_id());
92 
93  if(navigate_to_selection)
95  }
96 
97  void GuiApi::selectGate(u32 gate_id, bool clear_current_selection, bool navigate_to_selection)
98  {
99  selectGate(gNetlist->get_gate_by_id(gate_id), clear_current_selection, navigate_to_selection);
100  }
101 
102  void GuiApi::selectGate(const std::vector<Gate*>& gates, bool clear_current_selection, bool navigate_to_selection)
103  {
104  QSet<u32> gate_ids;
105 
106  for(auto gate : gates)
107  {
108  if(!gNetlist->is_gate_in_netlist(gate))
109  return;
110 
111  gate_ids.insert(gate->get_id());
112  }
113 
114  if(clear_current_selection)
116 
117  gate_ids.unite(gSelectionRelay->selectedGates());
120 
121  if(navigate_to_selection)
123  }
124 
125  void GuiApi::selectGate(const std::vector<u32>& gate_ids, bool clear_current_selection, bool navigate_to_selection)
126  {
127  std::vector<Gate*> gates(gate_ids.size());
128  std::transform(gate_ids.begin(), gate_ids.end(), gates.begin(), [](u32 gate_id){return gNetlist->get_gate_by_id(gate_id);});
129  selectGate(gates, clear_current_selection, navigate_to_selection);
130  }
131 
132  void GuiApi::selectNet(Net* net, bool clear_current_selection, bool navigate_to_selection)
133  {
135  return;
136 
137  if(clear_current_selection)
139 
140  gSelectionRelay->addNet(net->get_id());
143 
144  if(navigate_to_selection)
146  }
147 
148  void GuiApi::selectNet(u32 netId, bool clear_current_selection, bool navigate_to_selection)
149  {
150  selectNet(gNetlist->get_net_by_id(netId), clear_current_selection, navigate_to_selection);
151  }
152 
153  void GuiApi::selectNet(const std::vector<Net*>& nets, bool clear_current_selection, bool navigate_to_selection)
154  {
155  QSet<u32> net_ids;
156 
157  for(auto net : nets)
158  {
160  return;
161 
162  net_ids.insert(net->get_id());
163  }
164 
165  if(clear_current_selection)
167 
168  net_ids.unite(gSelectionRelay->selectedNets());
171 
172  if(navigate_to_selection)
174  }
175 
176  void GuiApi::selectNet(const std::vector<u32>& net_ids, bool clear_current_selection, bool navigate_to_selection)
177  {
178  std::vector<Net*> nets(net_ids.size());
179  std::transform(net_ids.begin(), net_ids.end(), nets.begin(), [](u32 mNetId){return gNetlist->get_net_by_id(mNetId);});
180  selectNet(nets, clear_current_selection, navigate_to_selection);
181  }
182 
183  void GuiApi::selectModule(Module* module, bool clear_current_selection, bool navigate_to_selection)
184  {
186  return;
187 
188  if(clear_current_selection)
190 
194 
195  if(navigate_to_selection)
197  }
198 
199  void GuiApi::selectModule(u32 module_id, bool clear_current_selection, bool navigate_to_selection)
200  {
201  selectModule(gNetlist->get_module_by_id(module_id), clear_current_selection, navigate_to_selection);
202  }
203 
204  void GuiApi::selectModule(const std::vector<Module*>& modules, bool clear_current_selection, bool navigate_to_selection)
205  {
206  QSet<u32> module_ids;
207 
208  for(auto module : modules)
209  {
211  return;
212 
213  module_ids.insert(module->get_id());
214  }
215 
216  if(clear_current_selection)
218 
219  module_ids.unite(gSelectionRelay->selectedModules());
220  gSelectionRelay->setSelectedModules(module_ids);
222 
223  if(navigate_to_selection)
225  }
226 
227  void GuiApi::selectModule(const std::vector<u32>& module_ids, bool clear_current_selection, bool navigate_to_selection)
228  {
229  std::vector<Module*> modules(module_ids.size());
230  std::transform(module_ids.begin(), module_ids.end(), modules.begin(), [](u32 g_id){return gNetlist->get_module_by_id(g_id);});
231  selectModule(modules, clear_current_selection, navigate_to_selection);
232  }
233 
234  void GuiApi::select(Gate* gate, bool clear_current_selection, bool navigate_to_selection)
235  {
236  selectGate(gate, clear_current_selection, navigate_to_selection);
237  }
238 
239  void GuiApi::select(Net* net, bool clear_current_selection, bool navigate_to_selection)
240  {
241  selectNet(net, clear_current_selection, navigate_to_selection);
242  }
243  void GuiApi::select(Module* module, bool clear_current_selection, bool navigate_to_selection)
244  {
245  selectModule(module, clear_current_selection, navigate_to_selection);
246  }
247 
248  void GuiApi::select(const std::vector<Gate*>& gates, bool clear_current_selection, bool navigate_to_selection)
249  {
250  selectGate(gates, clear_current_selection, navigate_to_selection);
251  }
252  void GuiApi::select(const std::vector<Net*>& nets, bool clear_current_selection, bool navigate_to_selection)
253  {
254  selectNet(nets, clear_current_selection, navigate_to_selection);
255  }
256 
257  void GuiApi::select(const std::vector<Module*>& modules, bool clear_current_selection, bool navigate_to_selection)
258  {
259  selectModule(modules, clear_current_selection, navigate_to_selection);
260  }
261 
262  void GuiApi::select(const std::vector<u32>& gate_ids, const std::vector<u32>& net_ids, const std::vector<u32>& module_ids, bool clear_current_selection, bool navigate_to_selection)
263  {
264  if(clear_current_selection)
266 
267  selectGate(gate_ids, false, false);
268  selectNet(net_ids, false, false);
269  selectModule(module_ids, false, false);
270 
271  if(navigate_to_selection)
273  }
274 
275  void GuiApi::select(const std::vector<Gate*>& gates, const std::vector<Net*>& nets, const std::vector<Module*>& modules, bool clear_current_selection, bool navigate_to_selection)
276  {
277  if(clear_current_selection)
279 
280  selectGate(gates, false, false);
281  selectNet(nets, false, false);
282  selectModule(modules, false, false);
283 
284  if(navigate_to_selection)
286  }
287 
289  {
290  if(!gNetlist->is_gate_in_netlist(gate))
291  return;
292 
295  }
296 
297  void GuiApi::deselectGate(u32 gate_id)
298  {
300  }
301 
302  void GuiApi::deselectGate(const std::vector<Gate*>& gates)
303  {
305 
306  for(Gate* gate : gates)
307  {
308  if(!gNetlist->is_gate_in_netlist(gate))
309  return;
310 
311  auto it = gate_ids.find(gate->get_id());
312  if (it != gate_ids.end()) gate_ids.erase(it);
313  }
314 
317  }
318 
319  void GuiApi::deselectGate(const std::vector<u32>& gate_ids)
320  {
321  std::vector<Gate*> gates(gate_ids.size());
322  std::transform(gate_ids.begin(), gate_ids.end(), gates.begin(), [](u32 gate_id){return gNetlist->get_gate_by_id(gate_id);});
323  deselectGate(gates);
324  }
325 
327  {
329  return;
330 
331  gSelectionRelay->removeNet(net->get_id());
333  }
334 
336  {
338  }
339 
340  void GuiApi::deselectNet(const std::vector<Net*>& nets)
341  {
343 
344  for(Net* net : nets)
345  {
347  return;
348 
349  auto it = net_ids.find(net->get_id());
350  if (it != net_ids.end()) net_ids.erase(it);
351  }
352 
355  }
356 
357  void GuiApi::deselectNet(const std::vector<u32>& net_ids)
358  {
359  std::vector<Net*> nets(net_ids.size());
360  std::transform(net_ids.begin(), net_ids.end(), nets.begin(), [](u32 mNetId){return gNetlist->get_net_by_id(mNetId);});
361  deselectNet(nets);
362  }
363 
365  {
367  return;
368 
371  }
372 
373  void GuiApi::deselectModule(u32 module_id)
374  {
376  }
377 
378  void GuiApi::deselectModule(const std::vector<Module*>& modules)
379  {
380  QSet<u32> module_ids = gSelectionRelay->selectedModules();
381 
382  for(Module* module : modules)
383  {
385  return;
386  auto it = module_ids.find(module->get_id());
387  if (it != module_ids.end()) module_ids.erase(it);
388  }
389 
390  gSelectionRelay->setSelectedModules(module_ids);
392  }
393 
394  void GuiApi::deselectModule(const std::vector<u32>& module_ids)
395  {
396  std::vector<Module*> modules(module_ids.size());
397  std::transform(module_ids.begin(), module_ids.end(), modules.begin(), [](u32 module_id){return gNetlist->get_module_by_id(module_id);});
398  deselectModule(modules);
399  }
400 
401  void GuiApi::deselect(Gate* gate)
402  {
403  deselectGate(gate);
404  }
405 
407  {
408  deselectNet(net);
409  }
411  {
413  }
414 
415  void GuiApi::deselect(const std::vector<Gate*>& gates)
416  {
417  deselectGate(gates);
418  }
419  void GuiApi::deselect(const std::vector<Net*>& nets)
420  {
421  deselectNet(nets);
422  }
423 
424  void GuiApi::deselect(const std::vector<Module*>& modules)
425  {
426  deselectModule(modules);
427  }
428 
429  void GuiApi::deselect(const std::vector<u32>& gate_ids, const std::vector<u32>& net_ids, const std::vector<u32>& module_ids)
430  {
431  deselectGate(gate_ids);
432  deselectNet(net_ids);
433  deselectModule(module_ids);
434  }
435 
436  void GuiApi::deselect(const std::vector<Gate*>& gates, const std::vector<Net*>& nets, const std::vector<Module*>& modules)
437  {
438  deselectGate(gates);
439  deselectNet(nets);
440  deselectModule(modules);
441  }
442 
444  {
446  }
447 
448 
449  int GuiApiClasses::View::isolateInNew(std::vector<Module*> modules, std::vector<Gate*> gates)
450  {
451  //check if the inputs are valid
452  for(Module* mod : modules)
453  {
454  if (mod == nullptr)
455  {
456  log_warning("gui","Null values not allowed in module argument");
457  return 0;
458  }
459  }
460 
461  for(Gate* gate : gates)
462  {
463  if (gate == nullptr)
464  {
465  log_warning("gui","Null values not allowed in gate argument");
466  return 0;
467  }
468  }
469  QString name;
470 
471  bool isModuleExclusive = false;
472 
473  //make sure that modules and gates are not empty
474  if(modules.empty() && gates.empty())
475  return 0;
476 
477  //Check if view should be bound exclusively to module
478  if(modules.size() == 1 && gates.empty() && modules[0]){
479  name = QString::fromStdString(modules[0]->get_name()) + QString(" (ID: %1)").arg(modules[0]->get_id());
480  isModuleExclusive = true;
481  //If the view already exists then return existing id
484  if(ctx->name() == name){
485  return ctx->id();
486  }
487  }
488  return 0;
489  }
490  }
491  else
492  {
493  //Get the number which has to be appended to name
494  name = gGraphContextManager->nextViewName("Isolated View");
495  }
497 
498  // Unpack return values and check if not empty
499  QSet<u32> moduleIds = pair.moduleIds;
500  QSet<u32> gateIds = pair.gateIds;
501 
502  if(moduleIds.isEmpty() && gateIds.isEmpty())
503  return 0;
504 
506  act->setUseCreatedObject();
508  act->addAction(new ActionAddItemsToObject(moduleIds, gateIds));
510 
511  if (isModuleExclusive){
513  context->setDirty(false);
514  context->setExclusiveModuleId(modules[0]->get_id());
515  }
516  return act->object().id();
517  }
518 
520  {
521  // check if id is valid
522  if(gGraphContextManager->getContextById(id) == nullptr)
523  {
524  return false;
525  }
526 
530  return true;
531  }
532 
533 
534  bool GuiApiClasses::View::addTo(int id, const std::vector<Module*> modules, const std::vector<Gate*> gates)
535  {
536  //check if the inputs are valid
537  for(Module* mod : modules)
538  {
539  if (mod == nullptr)
540  {
541  log_warning("gui","Null values not allowed in module argument");
542  return 0;
543  }
544  }
545 
546  for(Gate* gate : gates)
547  {
548  if (gate == nullptr)
549  {
550  log_warning("gui","Null values not allowed in gate argument");
551  return 0;
552  }
553  }
554 
555  if (!gGraphContextManager->getContextById(id)) return false; // context does not exist
556 
557 
559  return false; //context shows topmodule so we can not add anything to it
560 
562 
563  // Get ids from modules and gates
564  QSet<u32> moduleIds = pair.moduleIds;
565  QSet<u32> gateIds = pair.gateIds;
566 
567  ActionAddItemsToObject* act = new ActionAddItemsToObject(moduleIds,gateIds);
570  return true;
571  }
572 
573  bool GuiApiClasses::View::removeFrom(int id, const std::vector<Module*> modules, const std::vector<Gate*> gates)
574  {
575  //check if the inputs are valid
576  for(Module* mod : modules)
577  {
578  if (mod == nullptr)
579  {
580  log_warning("gui","Null values not allowed in module argument");
581  return 0;
582  }
583  }
584 
585  for(Gate* gate : gates)
586  {
587  if (gate == nullptr)
588  {
589  log_warning("gui","Null values not allowed in gate argument");
590  return 0;
591  }
592  }
593 
594  if (!gGraphContextManager->getContextById(id)) return false; // context does not exist
595 
596  QSet<u32> moduleIds;
597  QSet<u32> gateIds;
598 
599  for(Module* module : modules)
600  moduleIds.insert(module->get_id());
601  for(Gate* gate : gates)
602  gateIds.insert(gate->get_id());
603 
604  ActionRemoveItemsFromObject* act = new ActionRemoveItemsFromObject(moduleIds,gateIds);
607  return true;
608  }
609 
610  bool GuiApiClasses::View::setName(int id, const std::string& name)
611  {
612  if (!gGraphContextManager->getContextById(id)) return false; // context does not exist
613 
614  //check if name is occupied
616  return false;
617 
618  //check if view is exclusively bound to module
620  return false;
621 
622  //get context matching id and rename it
626  return true;
627  }
628 
629  int GuiApiClasses::View::getId(const std::string& name)
630  {
631  //check if there exists a context with the given name before we iterate over each of them
633  return 0;
634 
635  //find View related to the name
637  if(ctx->name() == QString::fromStdString(name)){
638  return ctx->id();
639  }
640  }
641  return 0;
642  }
643 
644  std::string GuiApiClasses::View::getName(int id)
645  {
647  if(ctx != nullptr){
648  return ctx->name().toStdString();
649  }
650  return {}; //
651  }
652 
653  std::vector<Module*> GuiApiClasses::View::getModules(int id)
654  {
656  if(ctx != nullptr){
657  std::vector<Module*> modules;
658  for(u32 id : ctx->modules()){
659  modules.push_back(gNetlist->get_module_by_id(id));
660  }
661  return modules;
662  }
663  return {};
664  }
665 
666  std::vector<Gate*> GuiApiClasses::View::getGates(int id)
667  {
669  if(ctx != nullptr){
670  std::vector<Gate*> gates;
671  for(u32 id : ctx->gates()){
672  gates.push_back(gNetlist->get_gate_by_id(id));
673  }
674  return gates;
675  }
676  return {};
677  }
678 
679  std::vector<u32> GuiApiClasses::View::getIds(const std::vector<Module*> modules, const std::vector<Gate*> gates)
680  {
681  //check if the inputs are valid
682  for(Module* mod : modules)
683  {
684  if (mod == nullptr)
685  {
686  log_warning("gui","Null values not allowed in module argument");
687  return {};
688  }
689  }
690 
691  for(Gate* gate : gates)
692  {
693  if (gate == nullptr)
694  {
695  log_warning("gui","Null values not allowed in gate argument");
696  return {};
697  }
698  }
699 
700  std::vector<u32> ids;
701 
702  QSet<u32> moduleIds;
703  QSet<u32> gateIds;
704 
705  //Get ids of given modules and gates
706  for(Module* module : modules)
707  {
708  if(module)
709  moduleIds.insert(module->get_id());
710  }
711  for(Gate* gate : gates)
712  {
713  if(gate)
714  gateIds.insert(gate->get_id());
715  }
716 
717  //iterate over each context and look if its showing modules
719  bool isCandidate = true;
720 
721  //Check if modules are in ctx
722  for(u32 moduleId : moduleIds){
723  if(ctx->modules().contains(moduleId))
724  continue;
725  isCandidate = false;
726  break;
727  }
728  //Only check modules if ctx still a valid candidate
729  if(isCandidate){
730  for(u32 gateId : gateIds){
731  if(ctx->gates().contains(gateId))
732  continue;
733  isCandidate = false;
734  break;
735  }
736  }
737 
738  //add it to ids if its a candidate
739  if(isCandidate)
740  ids.push_back(ctx->id());
741 
742  }
743  return ids;
744  }
746  {
747  if(!module)
748  {
749  log_warning("gui","module must not be null");
750  return false;
751  }
752  GraphContext* context = gGraphContextManager->getContextById(view_id);
753 
754  //check if the inputs are valid
755  if(context == nullptr) return false;
756 
757  if(!context->modules().contains(module->get_id())) return false;
758 
761  return true;
762  }
763 
765  {
766  if(!module)
767  {
768  log_warning("gui","module must not be null");
769  return false;
770  }
771  GraphContext* context = gGraphContextManager->getContextById(view_id);
772 
773  //check if the inputs are valid
774  if(context == nullptr) return false;
775 
776  //get gates and submodules that belong to the current module
777  std::vector<Module*> submodules = module->get_submodules();
778  std::vector<Gate*> gates = module->get_gates();
779 
780  bool isValidToFold = false;
781  //check if the view contains gates and submodules of the current module, return false if not
782  for(Gate* gate : gates)
783  if(context->gates().contains(gate->get_id())) {isValidToFold = true; break;}
784  for(Module* submodule : submodules)
785  if(context->modules().contains(submodule->get_id())) {isValidToFold = true; break;}
786  if (isValidToFold)
787  {
790  return true;
791  }
792  return false;
793  }
794 
795  GuiApiClasses::View::ModuleGateIdPair GuiApiClasses::View::getValidObjects(int viewId, const std::vector<Module*> mods, const std::vector<Gate*> gats)
796  {
797  Module* topModule = gNetlist->get_top_module();
798  //copy to prevent inplace operations
799  std::vector<Module*> modules = mods;
800  std::vector<Gate*> gates = gats;
801 
802  //set to store already existing mods and gates
803  QSet<u32> existingModules;
804  QSet<u32> existingGates;
805 
806  QSet<u32> Parents;
807  QSet<u32> modIds;
808  QSet<u32> gatIds;
809  //0) if its not a new view we have to check and remove all parents which have to be placed
810  if (viewId)
811  {
812  //put topmodule into parents because we dont iterate over it here
813  //Parents.insert(topModule->get_id());
814  std::vector<Module*> validMods;
815  //Add parents from the view modules to Parents
816  for (Module* mod : GuiApiClasses::View::getModules(viewId))
817  {
818  existingModules.insert(mod->get_id());
819  validMods.push_back(mod);
820  Module* itr = mod->get_parent_module();
821  while (itr != nullptr)
822  {
823  if (Parents.contains(itr->get_id()))
824  break;
825  Parents.insert(itr->get_id());
826  itr = itr->get_parent_module();
827  }
828 
829  }
830  //Add parents from gate to parents
831  for (Gate* gate : GuiApiClasses::View::getGates(viewId))
832  {
833  existingGates.insert(gate->get_id());
834  Module* itr = gate->get_module();
835  while (itr != nullptr)
836  {
837  if (Parents.contains(itr->get_id()))
838  break;
839  Parents.insert(itr->get_id());
840  itr = itr->get_parent_module();
841  }
842  }
843  //Delete every parent from the list if submodule is in the view
844  for (Module* mod : modules)
845  {
846  if (Parents.contains(mod->get_id()))
847  continue;
848  validMods.push_back(mod);
849  }
850  modules = validMods;
851  }
852  //get ids of modules
853  for (Module* mod : modules)
854  {
855  modIds.insert(mod->get_id());
856  }
857  //1) sort them by priority in DESCENDING order
858  std::sort(modules.begin(), modules.end(), [](const Module* a, const Module* b) -> bool
859  {
860  //sorting in DESCENDING order to check from lowest to highest priority
861  return a->get_submodule_depth() > b->get_submodule_depth();
862  }
863  );
864  //2) remove id if parent is in set
865  for(Module* mod : modules){
866  //check if top module
867  if(mod == topModule){
868  // only add the top module because it has highest priority
869  QSet<u32> temp;
870  temp.insert(topModule->get_id());
871  modIds = temp;
872  break;
873  }
874  //check if parent is in current set and if so remove current mod
875  Module* iterator = mod->get_parent_module();
876  while(iterator != nullptr){
877  if(modIds.contains(iterator->get_id()))
878  {
879  // parent is already in the set so remove mod and stop traversing parent tree
880  modIds.remove(mod->get_id());
881  break;
882  }
883  iterator = iterator->get_parent_module();
884  }
885  }
886  //3) remove all gates which has its ancestor in modIds
887  //check ancestors until topmodule or found in modIds
888  for (Gate* gate : gates)
889  {
890  Module* itr = gate->get_module();
891  bool shouldInsert = true;
892  while (itr != nullptr)
893  {
894  if (modIds.contains(itr->get_id()))
895  {
896  gatIds.remove(gate->get_id());
897  shouldInsert = false;
898  break;
899  }
900  itr = itr->get_parent_module();
901  }
902  if (shouldInsert)
903  gatIds.insert(gate->get_id());
904  }
905 
906  //remove duplicates
907  if (viewId)
908  {
909  modIds -= existingModules;
910  gatIds -= existingGates;
911  }
912  //create struct to return module and gate ID pairs
914  pair.moduleIds = modIds;
915  pair.gateIds = gatIds;
916 
917  return pair;
918 
919  }
920 
922  {
923  const GraphContext* context = gGraphContextManager->getContextById(viewId);
924  if (context == nullptr) return new GridPlacement();
925  return context->getLayouter()->gridPlacementFactory();
926  }
927 
929  {
930  ActionMoveNode* act = new ActionMoveNode(viewId, gp);
932  return true;
933  }
934 
936  {
937  auto currentDirectory = gGraphContextManager->getContextTreeModel()->getCurrentDirectory();
938  if(currentDirectory == nullptr)
939  return 0;
940  else
941  {
942  if(currentDirectory->directory() == nullptr)
943  return 0;
944  return currentDirectory->directory()->id();
945  }
946  }
947 
949  {
952  }
953 
955  {
958  auto id = act->object().id();
959  return id;
960  }
961 
963  {
964  /*ContextDirectory* directory = gGraphContextManager->getDirectoryById(id);
965  if(directory)
966  gGraphContextManager->deleteContextDirectory(directory);*/
970  }
971 
972  void GuiApiClasses::View::moveView(u32 viewId, std::optional<u32> destinationDirectoryId, std::optional<int> row)
973  {
975  if(!viewItem)
976  return;
977 
978  u32 parentId = 0;
979  BaseTreeItem* parentItem = viewItem->getParent();
980  if(parentItem && gGraphContextManager->getContextTreeModel()->getRootItem() != parentItem)
981  parentId = dynamic_cast<ContextTreeItem*>(parentItem)->getId();
982 
984  ActionMoveItem* act;
985  if(row.has_value())
986  act = new ActionMoveItem(destinationDirectoryId.value_or(getCurrentDirectory()), parentId, row.value());
987  else
988  act = new ActionMoveItem(destinationDirectoryId.value_or(getCurrentDirectory()), parentId);
989  act->setObject(uao);
990  act->exec();
991  }
992 
993  void GuiApiClasses::View::moveDirectory(u32 directoryId, std::optional<u32> destinationDirectoryId, std::optional<int> row)
994  {
995  BaseTreeItem* directoryItem = gGraphContextManager->getContextTreeModel()->getDirectory(directoryId);
996  if(!directoryItem)
997  return;
998 
999  u32 parentId = 0;
1000  BaseTreeItem* parentItem = directoryItem->getParent();
1001  if(parentItem && gGraphContextManager->getContextTreeModel()->getRootItem() != parentItem)
1002  parentId = dynamic_cast<ContextTreeItem*>(parentItem)->getId();
1003 
1004  u32 destId = destinationDirectoryId.value_or(getCurrentDirectory());
1006  while (destAnchestor)
1007  {
1008  if (destAnchestor == directoryItem)
1009  {
1010  log_warning("gui", "Invalid attempt to move directory ID={} into dependend directory.", directoryId);
1011  return;
1012  }
1013  destAnchestor = destAnchestor->getParent();
1014  }
1015 
1016 
1018  ActionMoveItem* act;
1019  if(row.has_value())
1020  act = new ActionMoveItem(destId, parentId, row.value());
1021  else
1022  act = new ActionMoveItem(destId, parentId);
1023  act->setObject(uao);
1024  act->exec();
1025  }
1026 
1027  std::optional<std::vector<u32>> GuiApiClasses::View::getChildDirectories(u32 directoryId)
1028  {
1029  ContextTreeItem* directoryItem = dynamic_cast<ContextTreeItem*>(gGraphContextManager->getContextTreeModel()->getDirectory(directoryId));
1030  // Id 0 is the root item. It does not exist as a directory object, but child items can still be retrieved from it.
1031  if(!directoryItem && directoryId != 0)
1032  return std::nullopt;
1034  }
1035 
1036  std::optional<std::vector<u32>> GuiApiClasses::View::getChildViews(u32 directoryId)
1037  {
1038  ContextTreeItem* directoryItem = dynamic_cast<ContextTreeItem*>(gGraphContextManager->getContextTreeModel()->getDirectory(directoryId));
1039  // Id 0 is the root item. It does not exist as a directory object, but child items can still be retrieved from it.
1040  if(!directoryItem && directoryId != 0)
1041  return std::nullopt;
1043  }
1044 }
Adds an item to a module or grouping.
bool exec() override
Removes an item from a Module or Grouping.
(Future) Base class for all tree models related to the details widget.
virtual BaseTreeItem * getParent() const
BaseTreeItem * getRootItem() const
ContextDirectory * directory() const
std::vector< u32 > getChildDirectoriesOf(u32 directoryId)
void setCurrentDirectory(ContextTreeItem *currentItem)
std::vector< u32 > getChildContextsOf(u32 directoryId)
BaseTreeItem * getDirectory(u32 directoryId) const
ContextTreeItem * getCurrentDirectory()
BaseTreeItem * getContext(u32 contextId) const
Definition: gate.h:58
u32 get_id() const
Definition: gate.cpp:95
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
u32 getExclusiveModuleId() const
bool isShowingModuleExclusively()
void setDirty(bool dty)
void setExclusiveModuleId(u32 id, bool emitSignal=true)
const QSet< u32 > & gates() const
const QSet< u32 > & modules() const
GraphLayouter * getLayouter() const
QString name() const
QString nextViewName(const QString &prefix) const
GraphContext * getContextById(u32 id) const
ContextTreeModel * getContextTreeModel() const
bool contextWithNameExists(const QString &name) const
QVector< GraphContext * > getContexts() const
GridPlacement * gridPlacementFactory() const
static bool foldModule(int view_id, Module *module)
Definition: gui_api.cpp:764
static void deleteDirectory(u32 id)
Definition: gui_api.cpp:962
static bool unfoldModule(int view_id, Module *module)
Definition: gui_api.cpp:745
static void moveDirectory(u32 directoryId, std::optional< u32 > destinationDirectoryId, std::optional< int > row)
Definition: gui_api.cpp:993
static int getId(const std::string &name)
Definition: gui_api.cpp:629
static bool removeFrom(int id, const std::vector< Module * > modules, const std::vector< Gate * > gates)
Definition: gui_api.cpp:573
static int isolateInNew(const std::vector< Module * > modules, const std::vector< Gate * > gates)
Definition: gui_api.cpp:449
static bool setName(int id, const std::string &name)
Definition: gui_api.cpp:610
static void moveView(u32 viewId, std::optional< u32 > destinationDirectoryId, std::optional< int > row)
Definition: gui_api.cpp:972
static std::string getName(int id)
Definition: gui_api.cpp:644
static GridPlacement * getGridPlacement(int viewId)
Definition: gui_api.cpp:921
static bool setGridPlacement(int viewId, GridPlacement *gp)
Definition: gui_api.cpp:928
static u32 createNewDirectory(const std::string &name)
Definition: gui_api.cpp:954
static std::vector< Gate * > getGates(int id)
Definition: gui_api.cpp:666
static std::optional< std::vector< u32 > > getChildDirectories(u32 directoryId)
Definition: gui_api.cpp:1027
static bool addTo(int id, const std::vector< Module * > modules, const std::vector< Gate * > gates)
Definition: gui_api.cpp:534
static std::optional< std::vector< u32 > > getChildViews(u32 directoryId)
Definition: gui_api.cpp:1036
static bool deleteView(int id)
Definition: gui_api.cpp:519
static std::vector< Module * > getModules(int id)
Definition: gui_api.cpp:653
static void setCurrentDirectory(u32 id)
Definition: gui_api.cpp:948
static std::vector< u32 > getIds(const std::vector< Module * > modules, const std::vector< Gate * > gates)
Definition: gui_api.cpp:679
static u32 getCurrentDirectory()
Definition: gui_api.cpp:935
static ModuleGateIdPair getValidObjects(int viewId, const std::vector< Module * >, const std::vector< Gate * >)
Definition: gui_api.cpp:795
void deselectNet(u32 netId)
Definition: gui_api.cpp:335
void deselectModule(u32 module_id)
Definition: gui_api.cpp:373
std::vector< u32 > getSelectedNetIds()
Definition: gui_api.cpp:37
std::tuple< std::vector< Gate * >, std::vector< Net * >, std::vector< Module * > > getSelectedItems()
Definition: gui_api.cpp:76
void deselectAllItems()
Definition: gui_api.cpp:443
std::vector< u32 > getSelectedModuleIds()
Definition: gui_api.cpp:42
std::vector< Gate * > getSelectedGates()
Definition: gui_api.cpp:52
std::vector< Net * > getSelectedNets()
Definition: gui_api.cpp:60
void deselect(Gate *gate)
Definition: gui_api.cpp:401
void selectNet(u32 netId, bool clear_current_selection=true, bool navigate_to_selection=true)
Definition: gui_api.cpp:148
void navigationRequested()
void select(Gate *gate, bool clear_current_selection=true, bool navigate_to_selection=true)
Definition: gui_api.cpp:234
std::vector< u32 > getSelectedGateIds()
Definition: gui_api.cpp:32
std::vector< Module * > getSelectedModules()
Definition: gui_api.cpp:68
std::tuple< std::vector< u32 >, std::vector< u32 >, std::vector< u32 > > getSelectedItemIds()
Definition: gui_api.cpp:47
void selectModule(u32 module_id, bool clear_current_selection=true, bool navigate_to_selection=true)
Definition: gui_api.cpp:199
void selectGate(u32 gate_id, bool clear_current_selection=true, bool navigate_to_selection=true)
Definition: gui_api.cpp:97
void deselectGate(u32 gate_id)
Definition: gui_api.cpp:297
Module * get_parent_module() const
Definition: module.cpp:125
const std::vector< Gate * > & get_gates() const
Definition: module.cpp:391
std::vector< Module * > get_submodules(const std::function< bool(Module *)> &filter=nullptr, bool recursive=false) const
Definition: module.cpp:259
u32 get_id() const
Definition: module.cpp:82
Definition: net.h:58
Module * get_top_module() const
Definition: netlist.cpp:608
bool is_gate_in_netlist(const Gate *gate) const
Definition: netlist.cpp:188
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
bool is_module_in_netlist(const Module *module) const
Definition: netlist.cpp:647
bool is_net_in_netlist(const Net *net) const
Definition: netlist.cpp:348
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
Net * get_net_by_id(u32 net_id) const
Definition: netlist.cpp:353
void setFocus(ItemType ftype, u32 fid, Subfocus sfoc=Subfocus::None, u32 sfinx=0)
const QSet< u32 > & selectedNets() const
void relaySelectionChanged(void *sender)
QList< u32 > selectedModulesList() const
const QSet< u32 > & selectedGates() const
QList< u32 > selectedNetsList() const
const QSet< u32 > & selectedModules() const
std::vector< u32 > selectedGatesVector() const
std::vector< u32 > selectedNetsVector() const
QList< u32 > selectedGatesList() const
void setSelectedGates(const QSet< u32 > &ids)
std::vector< u32 > selectedModulesVector() const
void setSelectedNets(const QSet< u32 > &ids)
void registerSender(void *sender, QString name)
void setSelectedModules(const QSet< u32 > &ids)
void addAction(UserAction *act)
virtual void setObject(const UserActionObject &obj)
Definition: user_action.cpp:32
virtual UserActionObject object() const
Definition: user_action.h:102
void executeActionBlockThread(UserAction *act)
static UserActionManager * instance()
The UserActionObject class represents a single object used in UserAction.
#define log_warning(channel,...)
Definition: log.h:76
const Module * module(const Gate *g, const NodeBoxes &boxes)
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:85
SelectionRelay * gSelectionRelay
Definition: plugin_gui.cpp:83
Netlist * gNetlist
Definition: plugin_gui.cpp:80
quint32 u32
Net * net
std::string name
i32 id
Q_EMITQ_EMIT
bool contains(const T &value) const const
QSet::iterator end()
QSet::iterator erase(QSet::iterator pos)
QSet::iterator find(const T &value)
QSet::iterator insert(const T &value)
bool isEmpty() const const
bool remove(const T &value)
QSet< T > & unite(const QSet< T > &other)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromStdString(const std::string &str)
std::string toStdString() const const