Skip to content

Commit

Permalink
2017-02-07 Jean Brefort <jean.brefort@normalesup.org>
Browse files Browse the repository at this point in the history
	* configure.ac: version bump (0.14.17).
	* libs/gcp/bond.cc: new properties for bonds crossing.
	* libs/gcu/objprops.h: ditto.
	* plugins/loaders/cdx/cdx.cc: fix import of generic fragments and crossing
	bonds. [50190]
	* plugins/loaders/cdxml/cdxml.cc: ditto.
	* programs/table/gchemtable.desktop.in.in: add missing line feed.
  • Loading branch information
jbrefort committed Feb 7, 2017
1 parent 4bc013e commit 1962f11
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 18 deletions.
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
##Text encoding: utf-8

2017-02-07 Jean Bréfort <jean.brefort@normalesup.org>
* configure.ac: version bump (0.14.17).
* libs/gcp/bond.cc: new properties for bonds crossing.
* libs/gcu/objprops.h: ditto.
* plugins/loaders/cdx/cdx.cc: fix import of generic fragments and crossing
bonds. [50190]
* plugins/loaders/cdxml/cdxml.cc: ditto.
* programs/table/gchemtable.desktop.in.in: add missing line feed.

2016-12-06 Julian Sikorski <belegdol@gmail.com>
* programs/table/gchemtable.desktop.in.in: re-added missing newline (rhbz #1402039)

Expand All @@ -9,6 +18,12 @@
* plugins/paint/bonds/plugin.cc: do not show unimplemented weak bond tool
button.

2016-11-23 Jean Bréfort <jean.brefort@normalesup.org>
* libs/gcp/application.cc: do not crash when a NULL tool is selected.

2016-11-23 Jean Bréfort <jean.brefort@normalesup.org>
* libs/gcp/application.cc: do not crash when a NULL tool is selected.

2016-10-31 Jean Bréfort <jean.brefort@normalesup.org>
* libs/gccv/text.cc: don't use the abs() function on unsigned numbers.
* programs/3d/gchem3d.appdata.xml.in: updated.
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 0.14.17:
GChemPaint:
* Fix import of generic fragments and crossing bonds from chemdraw
files. [50190]

Version 0.14.16:
GChemPaint:
* Do not show buttons for non yet implemented tools.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_PREREQ(2.64)

AC_INIT([gnome-chemistry-utils], [0.14.16], [http://savannah.nongnu.org/bugs/?group=gchemutils],[gnome-chemistry-utils],[http://gchemutils.nongnu.org/])
AC_INIT([gnome-chemistry-utils], [0.14.17], [http://savannah.nongnu.org/bugs/?group=gchemutils],[gnome-chemistry-utils],[http://gchemutils.nongnu.org/])
AC_CONFIG_SRCDIR([libs/gcugtk/gcuperiodic.c])
AM_INIT_AUTOMAKE([1.11.1 tar-ustar no-dist-gzip dist-bzip2 dist-xz])
AM_MAINTAINER_MODE([enable])
Expand Down
44 changes: 43 additions & 1 deletion libs/gcp/bond.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <glib/gi18n-lib.h>
#include <cmath>
#include <cstring>
#include <sstream>

using namespace gccv;
using namespace gcu;
Expand Down Expand Up @@ -964,8 +965,29 @@ bool Bond::SetProperty (unsigned property, char const *value)
m_DoublePosition = DoubleBondRight;
else
m_DoublePosition = DoubleBondAuto;
break;
case GCU_PROP_BOND_CROSSING: {
std::istringstream st (value);
std::string id;
Molecule *mol = static_cast < gcp::Molecule * > (GetMolecule ());
while (!st.eof ()) {
st >> id;
if (id[0] != 'b')
id = "b" + id;
gcu::Object *obj = mol->GetChild (id.c_str ());
if (obj != NULL) {
Bond *bond = dynamic_cast < Bond * > (obj);
if (bond == NULL)
return false;
if (m_Begin != NULL && m_End != NULL && bond->m_Begin != NULL && bond->m_End != NULL && IsCrossing (bond))
BringToFront ();
// Note: what should we do else? this means that bonds over need to be set last and with valid ends.
}
}
break;
}
default:
gcu::Bond::SetProperty (property, value);
return gcu::Bond::SetProperty (property, value);
}
return true;
}
Expand Down Expand Up @@ -1000,6 +1022,26 @@ string Bond::GetProperty (unsigned property) const
case DoubleBondRight:
return "right";
}
case GCU_PROP_BOND_CROSSING: {
std::ostringstream out;
if (m_Crossing.size () > 0) {
map<Bond*, BondCrossing>::const_iterator i, iend = m_Crossing.end ();
bool first = true;
for (i = m_Crossing.begin (); i != iend; i++) {
out << (*i).first->GetId();
if (first)
first = false;
else
out << ' ';
}
}
return out.str ();
}
case GCU_PROP_BOND_LEVEL: {
std::ostringstream out;
out << m_level;
return out.str ();
}
default:
return gcu::Bond::GetProperty (property);
}
Expand Down
10 changes: 9 additions & 1 deletion libs/gcu/objprops.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,22 @@ The bond order.
GCU_PROP_BOND_ORDER,
/*!
The bond type: normal, hash, wedge,...
*/
*/
GCU_PROP_BOND_TYPE, //normal, hash, wedge,...
/*!
The second line position of a double bond when seent from the start atom.
Legal values are auto, center, left and right. Anythin else is interpreted
as auto.
*/
GCU_PROP_BOND_DOUBLE_POSITION,
/*!
The list of Ids of the bonds crossing this one
*/
GCU_PROP_BOND_CROSSING,
/*!
The level of a crossing bond.
*/
GCU_PROP_BOND_LEVEL,
// Text properties
/*!
The position of a text object. For a simple text, it is equivalent to
Expand Down
85 changes: 81 additions & 4 deletions plugins/loaders/cdx/cdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,13 @@ bool CDXLoader::WriteBond (CDXLoader *loader, GsfOutput *out, Object const *obj,
{
gint16 n = kCDXObj_Bond;
WRITEINT16 (out, n);
loader->WriteId (obj, out);
// the id might already exist because of forward references for crossing bonds
std::string ids = obj->GetId ();
std::map < std::string, unsigned >::iterator it = loader->m_SavedIds.find (ids);
if (it == loader->m_SavedIds.end ())
loader->WriteId (obj, out);
else
WRITEINT32 (out, (*it).second);
AddInt16Property (out, kCDXProp_ZOrder, loader->m_Z++);
string prop = obj->GetProperty (GCU_PROP_BOND_BEGIN);
AddInt32Property (out, kCDXProp_Bond_Begin, loader->m_SavedIds[prop]);
Expand All @@ -891,6 +897,32 @@ bool CDXLoader::WriteBond (CDXLoader *loader, GsfOutput *out, Object const *obj,
AddInt16Property (out, kCDXProp_Bond_DoublePosition, 257);
else if (prop == "left")
AddInt16Property (out, kCDXProp_Bond_DoublePosition, 258);
prop = obj->GetProperty (GCU_PROP_BOND_CROSSING);
if (prop.length () > 0) {
std::istringstream is (prop);
std::set < unsigned > crossing;
std::set < unsigned >::iterator j, jend;
guint32 id;
while (!is.eof ()) {
is >> ids;
it = loader->m_SavedIds.find (ids);
if (it == loader->m_SavedIds.end ()) {
id = loader->m_MaxId++;
loader->m_SavedIds[ids] = id;
} else
id = loader->m_SavedIds[ids];
crossing.insert (id);
}
n = kCDXProp_Bond_CrossingBonds;
WRITEINT16 (out, n);
n = crossing.size () * 4;
WRITEINT16 (out, n);
jend = crossing.end ();
for (j = crossing.begin (); j != jend; j++) {
id = *j;
WRITEINT32 (out, id);
}
}
gsf_output_write (out, 2, reinterpret_cast <guint8 const *> ("\x00\x00")); // end of bond
return true;
}
Expand All @@ -902,6 +934,9 @@ bool CDXLoader::WriteMolecule (CDXLoader *loader, GsfOutput *out, Object const *
loader->WriteId (obj, out);
// save atoms
std::map <std::string, Object *>::const_iterator i;
std::map < int, std::set < gcu::Object const *> > crossing;
std::set < gcu::Object const *>::const_iterator j, jend;
int level, minl = G_MAXINT, maxl = G_MININT;
Object const *child = obj->GetFirstChild (i);
while (child) {
if (child->GetType () == AtomType && !loader->WriteObject (out, child, s))
Expand All @@ -915,13 +950,31 @@ bool CDXLoader::WriteMolecule (CDXLoader *loader, GsfOutput *out, Object const *
return false;
child = obj->GetNextChild (i);
}
// save bonds
// save non crossing bonds and sort others by level
child = obj->GetFirstChild (i);
while (child) {
if (child->GetType () == BondType && !loader->WriteObject (out, child, s))
return false;
if (child->GetType () == BondType) {
std::string prop (child->GetProperty (GCU_PROP_BOND_CROSSING));
if (prop.length () > 0) {
prop = child->GetProperty (GCU_PROP_BOND_LEVEL);
level = atoi (prop.c_str ());
if (level < minl)
minl = level;
if (level > maxl)
maxl = level;
crossing[level].insert (child);
} else if (!loader->WriteObject (out, child, s))
return false;
}
child = obj->GetNextChild (i);
}
// now save crossing bond starting with deeper ones.
for (level = minl; level <= maxl; level++) {
jend = crossing[level].end ();
for (j = crossing[level].begin (); j != jend; j++)
if (!loader->WriteObject (out, *j, s))
return false;
}
gsf_output_write (out, 2, reinterpret_cast <guint8 const *> ("\x00\x00")); // end of molecule
return true;
}
Expand Down Expand Up @@ -2035,7 +2088,16 @@ bool CDXLoader::ReadAtom (GsfInput *in, Object *parent)
break;
case 7: {
bool amb;
char saved;
int i = 0;
// remove modifiers like ' from the buffer
while (buf[i] >= 'A' && buf[i] < 'z')
i++;
saved = buf[i];
buf[i] = 0;
Residue const *res = parent->GetDocument ()->GetResidue (buf, &amb);
// restore the buffer
buf[i] = saved;
if (res != NULL && res->GetGeneric ()) {
string pos = Atom->GetProperty (GCU_PROP_POS2D);
Molecule *mol = dynamic_cast <Molecule *> (parent);
Expand Down Expand Up @@ -2237,6 +2299,21 @@ bool CDXLoader::ReadBond (GsfInput *in, Object *parent)
}
break;
}
case kCDXProp_Bond_CrossingBonds: {
std::ostringstream out;
bool first = true;
size /= 4;
for (int i = 0; i < size; i++) {
READINT32 (in, Id);
if (first)
first = false;
else
out << ' ';
out << Id;
}
Bond->SetProperty (GCU_PROP_BOND_CROSSING, out.str ().c_str ());
break;
}
default:
if (size && !gsf_input_read (in, size, (guint8*) buf))
return false;
Expand Down
Loading

0 comments on commit 1962f11

Please sign in to comment.