Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label editor to create custom labels #740

Merged
merged 5 commits into from Aug 31, 2021

Conversation

serk12
Copy link
Collaborator

@serk12 serk12 commented Aug 19, 2021

  • Label editor
  • fix transparent labels

Signed-off-by: Marc Prat Masó marc.prat.maso@estudiantat.upc.edu

Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

Signed-off-by: Marc Prat Masó <marc.prat.maso@estudiantat.upc.edu>
Rendering::TextProperties::VCenter);
tprop.setFontFamily(Rendering::TextProperties::SansSerif);

tprop.setColorRgb(255, 255, 255);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we definitely want to let people pick colors for the labels. (Not per-label.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only in the label edit mode not the render display. But maybe white could be annoying if the background is white?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The white can be annoying for light-colored atoms (e.g., hydrogen)


void LabelEditor::save()
{
m_molecule->beginMergeMode(tr("write Label"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Write Label" or maybe "Set Label" or "Create Label"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to "Create Label"

m_selected = (clickedObject.type == Rendering::AtomType);
if (m_selected) {
m_selectedAtom = m_molecule->atom(clickedObject.index);
m_text = QString::fromUtf8(m_selectedAtom.label().c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QString::fromStdString() should also work, I think...

@ghutchis
Copy link
Member

This Ubuntu failure just seems to be a timeout. (The test set seems to be failing on bond tests #735.)

@ghutchis
Copy link
Member

I'll test the UI on this.

In the previous version, if you were showing the label display, it would look like you'd put a new label on top of the label display, which was weird. I think a user would expect clicking would offer a default (e.g., the "H3" or "C1" from the label display if nothing is set) so that text could be changed.

The label engine probably needs to offer a popup menu / QComboBox with a few alternatives including "Custom Labels Only".

@github-actions
Copy link
Contributor

Here are the build results
macOS.dmg
Win64.exe
Artifacts will only be retained for 90 days.

@avo-bot
Copy link

avo-bot commented Aug 19, 2021

This pull request has been mentioned on Avogadro Discussion. There might be relevant details there:

https://discuss.avogadro.cc/t/atom-label-numbering-in-xyz-files/3608/3

Signed-off-by: Marc Prat Masó <marc.prat.maso@estudiantat.upc.edu>
@serk12
Copy link
Collaborator Author

serk12 commented Aug 20, 2021

Something like this? I will change the checbox with the QComboBox and add the same options to the residues.
image

@ghutchis
Copy link
Member

Yes, I think the checkboxes are types of atom labels. So you could probably have something like:

Atom Labels: (as a combo box)

  • None
  • Atom Index
  • Element Symbol
  • Symbol & Number in Group
  • Custom

(and "Custom" => atom.label())

(Sorry, the font is weird in Avo1 on my Mac now.)
Screen Shot 2021-08-20 at 2 50 29 PM

@ghutchis
Copy link
Member

We never had residue labels, but probably:

Residue Labels:

  • None
  • Residue Name
  • Residue ID
  • Residue Name + ID

I've definitely seen cases where people annotate 2-3 particular residues with labels.

@github-actions
Copy link
Contributor

Here are the build results
macOS.dmg
Ubuntu-2004.tar.gz
Win64.exe
Artifacts will only be retained for 90 days.

@ghutchis
Copy link
Member

Let me know when you think this is ready to merge. The code looks good - just trying to get the UI / UX right. 😄

Signed-off-by: Marc Prat Masó <marc.prat.maso@estudiantat.upc.edu>
@github-actions
Copy link
Contributor

Here are the build results
macOS.dmg
Ubuntu-2004.tar.gz
Win64.exe
Artifacts will only be retained for 90 days.

SLOT(residueLabelType(int)));
index = residue->findData(int(residueOptions));
residue->model()->sort(0, Qt::AscendingOrder);
form->addRow(QObject::tr("residue label:"), residue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tr("Residue Label:")

SLOT(atomLabelType(int)));
int index = atom->findData(int(atomOptions));
atom->model()->sort(0, Qt::AscendingOrder);
form->addRow(QObject::tr("Atom label:"), atom);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tr("Atom Label:")

@ghutchis
Copy link
Member

I think there are two minor issues with the latest version.

  • I don't think we need to offer so many options - many users are students. For now, I think I'd stick to the options I mentioned above (Add label editor to create custom labels #740 (comment)). It's obviously easy to add more, but I suspect these are the most common.
  • For translation / i18n doing programmatic assembly is bad. European languages work like tr("Element") + tr("Index") but it's much better to translate each assembled string as a literal. (I learned this lesson the hard way .. one benefit of 25+ translations of Avo1.)

if (i == 0) {
atom->addItem(QObject::tr("None"), QVariant(LabelOptions::None));
} else {
char val = 0x00;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use a string list. I know this works in English, but it won't work for translation in many languages.

QStringList options;
options << tr("None") << tr("Index") << tr("Element Symbol") << tr("Symbol + Index"); // etc

text += (text == "" ? "" : " / ") + atom.label();
}
if (interface.atomOptions & LayerLabel::LabelOptions::Index) {
text += (text == "" ? "" : " / ") + std::to_string(atom.index());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atom.index() + 1 // most users expect Atom 1, Atom 2, etc. rather than starting at zero...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the "Select by Atom Index" is indexed at 0. I can change both elements to indexed at 1 if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think most users expect atom numbers to start at 1.

Signed-off-by: Marc Prat Masó <marc.prat.maso@estudiantat.upc.edu>
@serk12
Copy link
Collaborator Author

serk12 commented Aug 25, 2021

Though adding all the combinations looks noisy, if a user needs any of them it will be complex (and probably ugly). I can try a custom sort so it's more appealing or just remove them.

@github-actions
Copy link
Contributor

Here are the build results
macOS.dmg
Ubuntu-2004.tar.gz
Win64.exe
Artifacts will only be retained for 90 days.

@ghutchis
Copy link
Member

I can try a custom sort so it's more appealing or just remove them.

Yes, I'd just remove them from the list. If users ask later, it's easy enough to add a few. But I'd rather go for "the most common" list now. It's the 80/20 or 90/10 rule .. maybe 20% of the options are used 80% of the time.

It's always a challenge with our UI because it's used both by experts doing research as well as students doing molecular visualization. I figure most of the users are on the student end (so keep things simple).

Signed-off-by: Marc Prat Masó <marc.prat.maso@estudiantat.upc.edu>
@github-actions
Copy link
Contributor

Here are the build results
macOS.dmg
Ubuntu-2004.tar.gz
Win64.exe
Artifacts will only be retained for 90 days.

@ghutchis
Copy link
Member

I think it's a great start. I might tweak the icon a bit (e.g., a letter in front of an atom).

There's a lot of interest in scripts adding labels to atoms, so this is great. Need to add the atom labels to the property table too.

@ghutchis ghutchis added enhancement feature changes / API changes rendering labels Aug 31, 2021
@ghutchis ghutchis changed the title label editor and fix transparent label Add label editor to create custom labels Aug 31, 2021
@ghutchis ghutchis merged commit 6de14ab into OpenChemistry:master Aug 31, 2021
@serk12 serk12 deleted the label_editor branch September 9, 2021 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature changes / API changes rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants