mirror of https://github.com/KLayout/klayout.git
WIP: text edit feature for layer mapping edit widget.
This commit is contained in:
parent
91de370901
commit
0fddf7f389
|
|
@ -604,7 +604,7 @@ void GenericReaderOptions::set_layer_map (const std::string &lm)
|
|||
|
||||
int l = 0;
|
||||
while (! ex.at_end ()) {
|
||||
m_layer_map.map_expr (ex, l);
|
||||
m_layer_map.add_expr (ex, l);
|
||||
ex.test ("//");
|
||||
++l;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -738,6 +738,7 @@ LayerMap::unmap (const LDPair &p1, const LDPair &p2)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LayerMap::unmap_expr (const std::string &expr)
|
||||
{
|
||||
|
|
@ -838,6 +839,26 @@ LayerMap::to_string_file_format () const
|
|||
return os.str ();
|
||||
}
|
||||
|
||||
void
|
||||
LayerMap::add_expr (const std::string &expr, unsigned int l)
|
||||
{
|
||||
tl::Extractor ex (expr.c_str ());
|
||||
add_expr (ex, l);
|
||||
ex.expect_end ();
|
||||
}
|
||||
|
||||
void
|
||||
LayerMap::add_expr (tl::Extractor &ex, unsigned int l)
|
||||
{
|
||||
if (ex.test ("+")) {
|
||||
mmap_expr (ex, l);
|
||||
} else if (ex.test ("-")) {
|
||||
unmap_expr (ex);
|
||||
} else {
|
||||
map_expr (ex, l);
|
||||
}
|
||||
}
|
||||
|
||||
db::LayerMap
|
||||
LayerMap::from_string_file_format (const std::string &s)
|
||||
{
|
||||
|
|
@ -860,13 +881,7 @@ LayerMap::from_string_file_format (const std::string &s)
|
|||
} else {
|
||||
|
||||
if (! ex.at_end ()) {
|
||||
if (ex.test ("+")) {
|
||||
lm.mmap_expr (ex, l);
|
||||
} else if (ex.test ("-")) {
|
||||
lm.unmap_expr (ex);
|
||||
} else {
|
||||
lm.map_expr (ex, l);
|
||||
}
|
||||
lm.add_expr (ex, l);
|
||||
if (ex.test ("#") || ex.test ("//")) {
|
||||
// ignore comments
|
||||
} else {
|
||||
|
|
@ -901,7 +916,7 @@ namespace tl
|
|||
while (! ex.test (")") && ! ex.at_end ()) {
|
||||
std::string m;
|
||||
ex.read_word_or_quoted (m);
|
||||
t.map_expr (m, l);
|
||||
t.add_expr (m, l);
|
||||
++l;
|
||||
ex.test (";");
|
||||
}
|
||||
|
|
@ -921,7 +936,7 @@ namespace tl
|
|||
while (! ex.test (")") && ! ex.at_end ()) {
|
||||
std::string m;
|
||||
ex.read_word_or_quoted (m);
|
||||
t.map_expr (m, l);
|
||||
t.add_expr (m, l);
|
||||
++l;
|
||||
ex.test (";");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -521,6 +521,22 @@ public:
|
|||
*/
|
||||
void unmap_expr (tl::Extractor &ex);
|
||||
|
||||
/**
|
||||
* @brief Generic expression mapping
|
||||
*
|
||||
* This generic mapping function takes a mapping expression. If it starts with "+",
|
||||
* "mmap" is used, if it starts with "-", "unmap" is used. Otherwise, "map" is used.
|
||||
*/
|
||||
void add_expr (const std::string &expr, unsigned int l);
|
||||
|
||||
/**
|
||||
* @brief Generic expression mapping
|
||||
*
|
||||
* This generic mapping function takes a mapping expression. If it starts with "+",
|
||||
* "mmap" is used, if it starts with "-", "unmap" is used. Otherwise, "map" is used.
|
||||
*/
|
||||
void add_expr (tl::Extractor &ex, unsigned int l);
|
||||
|
||||
/**
|
||||
* @brief Prepares a layer mapping object for reading
|
||||
*
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>446</width>
|
||||
<height>205</height>
|
||||
<width>536</width>
|
||||
<height>290</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
@ -29,6 +29,19 @@
|
|||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="load_pb">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="help_label">
|
||||
<property name="sizePolicy">
|
||||
|
|
@ -45,103 +58,114 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="load_pb">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" rowspan="6" colspan="2">
|
||||
<widget class="QListWidget" name="layer_lv">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QToolButton" name="add_pb">
|
||||
<property name="toolTip">
|
||||
<string>Add a new layer to the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../lay/layResources.qrc">
|
||||
<normaloff>:/add.png</normaloff>:/add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QToolButton" name="delete_pb">
|
||||
<property name="toolTip">
|
||||
<string>Delete the selected layers from the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../lay/layResources.qrc">
|
||||
<normaloff>:/clear.png</normaloff>:/clear.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2" rowspan="3">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>5</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QToolButton" name="edit_pb">
|
||||
<property name="toolTip">
|
||||
<string>Edit the current layer</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../lay/layResources.qrc">
|
||||
<normaloff>:/edit.png</normaloff>:/edit.png</iconset>
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="QTabWidget" name="tabs">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>List</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" rowspan="4">
|
||||
<widget class="QListWidget" name="layer_lv">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QToolButton" name="add_pb">
|
||||
<property name="toolTip">
|
||||
<string>Add a new layer to the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../lay/lay/layResources.qrc">
|
||||
<normaloff>:/add.png</normaloff>:/add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QToolButton" name="delete_pb">
|
||||
<property name="toolTip">
|
||||
<string>Delete the selected layers from the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../lay/lay/layResources.qrc">
|
||||
<normaloff>:/clear.png</normaloff>:/clear.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QToolButton" name="edit_pb">
|
||||
<property name="toolTip">
|
||||
<string>Edit the current layer</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../lay/lay/layResources.qrc">
|
||||
<normaloff>:/edit.png</normaloff>:/edit.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>5</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Text</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPlainTextEdit" name="text_edit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../lay/layResources.qrc"/>
|
||||
<include location="../../lay/lay/layResources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ LayerMappingWidget::LayerMappingWidget (QWidget *parent)
|
|||
|
||||
mp_ui->layer_lv->viewport ()->acceptDrops ();
|
||||
|
||||
connect (mp_ui->tabs, SIGNAL (currentChanged (int)), this, SLOT (current_tab_changed (int)));
|
||||
|
||||
mp_layer_table_file_dialog = new lay::FileDialog (this,
|
||||
tl::to_string (QObject::tr ("Load Layer Table")),
|
||||
tl::to_string (QObject::tr ("Layer properties and text files (*.lyp *.txt);;Layer properties files (*.lyp);;Text files (*.txt);;All files (*)")));
|
||||
|
|
@ -72,6 +74,8 @@ LayerMappingWidget::set_layer_map (const db::LayerMap &lm)
|
|||
{
|
||||
std::vector<unsigned int> layer_ids = lm.get_layers ();
|
||||
|
||||
mp_ui->text_edit->setPlainText (tl::to_qstring (lm.to_string_file_format ()));
|
||||
|
||||
mp_ui->layer_lv->reset ();
|
||||
mp_ui->layer_lv->clear ();
|
||||
|
||||
|
|
@ -88,16 +92,31 @@ LayerMappingWidget::set_layer_map (const db::LayerMap &lm)
|
|||
|
||||
db::LayerMap
|
||||
LayerMappingWidget::get_layer_map () const
|
||||
{
|
||||
return get_layer_map_from_tab (mp_ui->tabs->currentIndex ());
|
||||
}
|
||||
|
||||
db::LayerMap
|
||||
LayerMappingWidget::get_layer_map_from_tab (int tab) const
|
||||
{
|
||||
db::LayerMap lm;
|
||||
for (int i = 0; i < mp_ui->layer_lv->count (); ++i) {
|
||||
std::string t = tl::to_string (mp_ui->layer_lv->item (i)->data (Qt::DisplayRole).toString ());
|
||||
try {
|
||||
lm.map_expr (t, (unsigned int) i);
|
||||
} catch (...) {
|
||||
mp_ui->layer_lv->setCurrentItem (mp_ui->layer_lv->item (i));
|
||||
throw;
|
||||
|
||||
if (tab == 0) {
|
||||
|
||||
for (int i = 0; i < mp_ui->layer_lv->count (); ++i) {
|
||||
std::string t = tl::to_string (mp_ui->layer_lv->item (i)->data (Qt::DisplayRole).toString ());
|
||||
try {
|
||||
lm.add_expr (t, (unsigned int) i);
|
||||
} catch (...) {
|
||||
mp_ui->layer_lv->setCurrentItem (mp_ui->layer_lv->item (i));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
lm = db::LayerMap::from_string_file_format (tl::to_string (mp_ui->text_edit->toPlainText ()));
|
||||
|
||||
}
|
||||
|
||||
return lm;
|
||||
|
|
@ -128,17 +147,19 @@ LayerMappingWidget::load_button_pressed ()
|
|||
mp_ui->layer_lv->reset ();
|
||||
mp_ui->layer_lv->clear ();
|
||||
|
||||
db::LayerMap lm;
|
||||
|
||||
// use those layers which have cellview index 0
|
||||
unsigned int n = 0;
|
||||
for (LayerPropertiesConstIterator lay_iter = props.begin_const_recursive (); ! lay_iter.at_end (); ++lay_iter) {
|
||||
if (! lay_iter->has_children () && lay_iter->source (true /*=real*/).cv_index () == 0) {
|
||||
db::LayerProperties db_lp = lay_iter->source (true /*=real*/).layer_props ();
|
||||
QListWidgetItem *item = new QListWidgetItem (mp_ui->layer_lv);
|
||||
item->setData (Qt::DisplayRole, tl::to_qstring (db_lp.to_string ()));
|
||||
item->setFlags (item->flags () | Qt::ItemIsEditable);
|
||||
mp_ui->layer_lv->addItem (item);
|
||||
lm.map (db_lp, (unsigned int) n++);
|
||||
}
|
||||
}
|
||||
|
||||
set_layer_map (lm);
|
||||
|
||||
// if successful, stop now.
|
||||
success = true;
|
||||
|
||||
|
|
@ -230,5 +251,11 @@ LayerMappingWidget::edit_button_pressed ()
|
|||
END_PROTECTED
|
||||
}
|
||||
|
||||
void
|
||||
LayerMappingWidget::current_tab_changed (int index)
|
||||
{
|
||||
set_layer_map (get_layer_map_from_tab (1 - index));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,11 +84,14 @@ private slots:
|
|||
void add_button_pressed ();
|
||||
void delete_button_pressed ();
|
||||
void edit_button_pressed ();
|
||||
void current_tab_changed (int tab);
|
||||
|
||||
private:
|
||||
lay::FileDialog *mp_layer_table_file_dialog;
|
||||
std::string m_layer_table_file;
|
||||
Ui::LayerMappingWidget *mp_ui;
|
||||
|
||||
db::LayerMap get_layer_map_from_tab (int tab) const;
|
||||
};
|
||||
|
||||
} // namespace lay
|
||||
|
|
|
|||
Loading…
Reference in New Issue