@@ -995,6 +995,48 @@ void DisplayControls::displayItemSelected(const QItemSelection& selection)
995995 }
996996}
997997
998+ std::tuple<QColor*, Qt::BrushStyle*, bool > DisplayControls::lookupColor (
999+ QStandardItem* item,
1000+ const QModelIndex* index)
1001+ {
1002+ if (item == misc_.background .swatch ) {
1003+ return {&background_color_, nullptr , false };
1004+ } else if (item == blockages_.blockages .swatch ) {
1005+ return {&placement_blockage_color_, &placement_blockage_pattern_, false };
1006+ } else if (item == misc_.regions .swatch ) {
1007+ return {®ion_color_, ®ion_pattern_, false };
1008+ } else if (item == instance_shapes_.names .swatch ) {
1009+ return {&instance_name_color_, nullptr , false };
1010+ } else if (item == instance_shapes_.iterm_labels .swatch ) {
1011+ return {&iterm_label_color_, nullptr , false };
1012+ } else if (item == rulers_.swatch ) {
1013+ return {&ruler_color_, nullptr , false };
1014+ } else {
1015+ QVariant tech_layer_data = item->data (user_data_item_idx_);
1016+ if (!tech_layer_data.isValid ()) {
1017+ return {nullptr , nullptr , false };
1018+ }
1019+ auto tech_layer = tech_layer_data.value <dbTechLayer*>();
1020+ auto site = tech_layer_data.value <odb::dbSite*>();
1021+ if (tech_layer != nullptr ) {
1022+ QColor* item_color = &layer_color_[tech_layer];
1023+ Qt::BrushStyle* item_pattern = &layer_pattern_[tech_layer];
1024+ if (tech_layer->getType () != dbTechLayerType::ROUTING ) {
1025+ if (index && index->row () != 0 ) {
1026+ // ensure if a via is the first layer, it can still be modified
1027+ return {item_color, item_pattern, false };
1028+ }
1029+ } else {
1030+ return {item_color, item_pattern, true };
1031+ }
1032+ } else if (site != nullptr ) {
1033+ return {&site_color_[site], nullptr , false };
1034+ }
1035+ }
1036+
1037+ return {nullptr , nullptr , false };
1038+ }
1039+
9981040void DisplayControls::displayItemDblClicked (const QModelIndex& index)
9991041{
10001042 if (index.column () == 0 ) {
@@ -1013,43 +1055,10 @@ void DisplayControls::displayItemDblClicked(const QModelIndex& index)
10131055 Qt::BrushStyle* item_pattern = nullptr ;
10141056 bool has_sibling = false ;
10151057
1016- // check if placement
1017- if (color_item == misc_.background .swatch ) {
1018- item_color = &background_color_;
1019- } else if (color_item == blockages_.blockages .swatch ) {
1020- item_color = &placement_blockage_color_;
1021- item_pattern = &placement_blockage_pattern_;
1022- } else if (color_item == misc_.regions .swatch ) {
1023- item_color = ®ion_color_;
1024- item_pattern = ®ion_pattern_;
1025- } else if (color_item == instance_shapes_.names .swatch ) {
1026- item_color = &instance_name_color_;
1027- } else if (color_item == instance_shapes_.iterm_labels .swatch ) {
1028- item_color = &iterm_label_color_;
1029- } else if (color_item == rulers_.swatch ) {
1030- item_color = &ruler_color_;
1031- } else {
1032- QVariant tech_layer_data = color_item->data (user_data_item_idx_);
1033- if (!tech_layer_data.isValid ()) {
1034- return ;
1035- }
1036- auto tech_layer = tech_layer_data.value <dbTechLayer*>();
1037- auto site = tech_layer_data.value <odb::dbSite*>();
1038- if (tech_layer != nullptr ) {
1039- item_color = &layer_color_[tech_layer];
1040- item_pattern = &layer_pattern_[tech_layer];
1041- if (tech_layer->getType () != dbTechLayerType::ROUTING ) {
1042- if (index.row () != 0 ) {
1043- // ensure if a via is the first layer, it can still be modified
1044- return ;
1045- }
1046- } else {
1047- has_sibling = true ;
1048- }
1049- } else if (site != nullptr ) {
1050- item_color = &site_color_[site];
1051- }
1052- }
1058+ const auto lookup = lookupColor (color_item, &index);
1059+ item_color = std::get<0 >(lookup);
1060+ item_pattern = std::get<1 >(lookup);
1061+ has_sibling = std::get<2 >(lookup);
10531062
10541063 if (item_color == nullptr ) {
10551064 return ;
@@ -1107,6 +1116,31 @@ void DisplayControls::setControlByPath(const std::string& path,
11071116 }
11081117}
11091118
1119+ // path is separated by "/", so setting Standard Cells, would be
1120+ // Instances/StdCells
1121+ void DisplayControls::setControlByPath (const std::string& path,
1122+ const QColor& color)
1123+ {
1124+ std::vector<QStandardItem*> items;
1125+ findControlsInItems (path, Swatch, items);
1126+
1127+ if (items.empty ()) {
1128+ logger_->error (utl::GUI , 40 , " Unable to find {} display control" , path);
1129+ } else {
1130+ for (auto * item : items) {
1131+ const auto & [item_color, item_style, sibling] = lookupColor (item);
1132+ if (sibling || item_color == nullptr ) {
1133+ continue ;
1134+ }
1135+ *item_color = color;
1136+ item->setIcon (makeSwatchIcon (color));
1137+ }
1138+ }
1139+ if (!items.empty ()) {
1140+ emit colorChanged ();
1141+ }
1142+ }
1143+
11101144// path is separated by "/", so setting Standard Cells, would be
11111145// Instances/StdCells
11121146bool DisplayControls::checkControlByPath (const std::string& path,
@@ -2033,8 +2067,11 @@ void DisplayControls::buildRestoreTclCommands(std::vector<std::string>& cmds,
20332067 if (item->hasChildren ()) {
20342068 buildRestoreTclCommands (cmds, item, name + " /" );
20352069 } else {
2036- bool visible = parent->child (r, Visible)->checkState () == Qt::Checked;
2037- cmds.push_back (fmt::format (FMT_RUNTIME (visible_restore), name, visible));
2070+ auto * visible = parent->child (r, Visible);
2071+ if (visible) {
2072+ bool vis = visible->checkState () == Qt::Checked;
2073+ cmds.push_back (fmt::format (FMT_RUNTIME (visible_restore), name, vis));
2074+ }
20382075 auto * selectable = parent->child (r, Selectable);
20392076 if (selectable != nullptr ) {
20402077 bool select = selectable->checkState () == Qt::Checked;
0 commit comments