Skip to content

Commit

Permalink
epam#2748 reverse s group label if it appears on the left of the mole…
Browse files Browse the repository at this point in the history
…cule
  • Loading branch information
jblack-mestre committed Feb 4, 2025
1 parent 860d260 commit 3e5fb3b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/render2d/render_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace indigo
void _preparePseudoAtom(int aid, int color, bool highlighted);
void _prepareChargeLabel(int aid, int color, bool highlighted);
void _prepareLabelText(int aid);
void _reverseLabelText(const int aid);
void _prepareAAM();
int _pushTextItem(RenderItem::TYPE type, int color, bool highlighted);
int _pushTextItem(AtomDesc& ad, RenderItem::TYPE type, int color, bool highlighted);
Expand Down
38 changes: 38 additions & 0 deletions core/render2d/src/render_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2985,6 +2985,11 @@ void MoleculeRenderInternal::_prepareLabelText(int aid)
ad.boundBoxMin.set(0, 0);
ad.boundBoxMax.set(0, 0);

if (ad.label == 0 && ad.hydroPos == HYDRO_POS_LEFT)
{
_reverseLabelText(aid);
}

int color = ad.color;
bool highlighted = _vertexIsHighlighted(aid);

Expand Down Expand Up @@ -3477,6 +3482,39 @@ void MoleculeRenderInternal::_prepareLabelText(int aid)
}
}

void MoleculeRenderInternal::_reverseLabelText(const int aid)
{
AtomDesc& ad = _ad(aid);
std::stringstream stream;
std::vector<std::string> labels;
stream << ad.pseudo[0];
for (int i = 1; i < ad.pseudo.size() - 1; ++i)
{
if (ad.pseudo[i] >= 'A' && ad.pseudo[i] <= 'Z')
{
labels.push_back(stream.str());
stream.str(std::string());
stream.clear();
}
stream << ad.pseudo[i];
}
labels.push_back(stream.str());

int j = 0;
int size = ad.pseudo.size() - 1;
for (auto it = labels.crbegin(); it != labels.crend(); ++it)
{
for (const auto& ch : *it)
{
if (j < size)
{
ad.pseudo[j] = ch;
++j;
}
}
}
}

int MoleculeRenderInternal::_pushTextItem(RenderItem::TYPE ritype, int color, bool highlighted)
{
_data.textitems.push();
Expand Down

0 comments on commit 3e5fb3b

Please sign in to comment.