Skip to content

Commit 166f8e8

Browse files
committed
New Bond display property. Will eventually drop the IBond.Stereo all together but for now we just make sure if it's set the display is updated.
1 parent 78681bb commit 166f8e8

File tree

5 files changed

+166
-2
lines changed
  • base
    • core/src/main/java/org/openscience/cdk
    • data/src/main/java/org/openscience/cdk
    • interfaces/src/main/java/org/openscience/cdk/interfaces
    • isomorphism/src/main/java/org/openscience/cdk/isomorphism/matchers
    • silent/src/main/java/org/openscience/cdk/silent

5 files changed

+166
-2
lines changed

base/core/src/main/java/org/openscience/cdk/BondRef.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,23 @@ public void setStereo(Stereo stereo) {
226226
bond.setStereo(stereo);
227227
}
228228

229+
230+
/**
231+
* {@inheritDoc}
232+
*/
233+
@Override
234+
public Display getDisplay() {
235+
return bond.getDisplay();
236+
}
237+
238+
/**
239+
* {@inheritDoc}
240+
*/
241+
@Override
242+
public void setDisplay(Display display) {
243+
bond.setDisplay(display);
244+
}
245+
229246
/**
230247
* {@inheritDoc}
231248
*/

base/data/src/main/java/org/openscience/cdk/Bond.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public class Bond extends ElectronContainer implements IBond, Serializable, Clon
8181
*/
8282
protected IBond.Stereo stereo;
8383

84+
protected IBond.Display display = Display.Solid;
85+
8486
/**
8587
* Constructs an empty bond.
8688
*/
@@ -408,6 +410,39 @@ public IBond.Stereo getStereo() {
408410
@Override
409411
public void setStereo(IBond.Stereo stereo) {
410412
this.stereo = stereo;
413+
switch (stereo) {
414+
case UP:
415+
display = Display.WedgeBegin;
416+
break;
417+
case DOWN:
418+
display = Display.WedgedHashBegin;
419+
break;
420+
case UP_INVERTED:
421+
display = Display.WedgeEnd;
422+
break;
423+
case DOWN_INVERTED:
424+
display = Display.WedgedHashEnd;
425+
break;
426+
case UP_OR_DOWN:
427+
case UP_OR_DOWN_INVERTED:
428+
display = Display.Wavy;
429+
break;
430+
}
431+
notifyChanged();
432+
}
433+
434+
/**
435+
* {@inheritDoc}
436+
*/
437+
public IBond.Display getDisplay() {
438+
return display;
439+
}
440+
441+
/**
442+
* {@inheritDoc}
443+
*/
444+
public void setDisplay(IBond.Display display) {
445+
this.display = display;
411446
notifyChanged();
412447
}
413448

base/interfaces/src/main/java/org/openscience/cdk/interfaces/IBond.java

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum Order {
4444

4545
private final Integer bondedElectronPairs;
4646

47-
private Order(Integer bondedElectronPairs) {
47+
Order(Integer bondedElectronPairs) {
4848
this.bondedElectronPairs = bondedElectronPairs;
4949
}
5050

@@ -131,6 +131,54 @@ enum Stereo {
131131
E_Z_BY_COORDINATES
132132
}
133133

134+
/**
135+
* Bond display style, controlling how bonds appear in a 2D depiction.
136+
*/
137+
enum Display {
138+
/** Display as a solid line (default). */
139+
Solid,
140+
/** Display as a dashed line. */
141+
Dash,
142+
/** Display as a hashed line. */
143+
Hash,
144+
/** Display as a bold line. */
145+
Bold,
146+
/** Display as a wavy line. */
147+
Wavy,
148+
/** Display as a dotted line. */
149+
Dot,
150+
/**
151+
* Display as a hashed wedge, with the narrow end
152+
* towards the begin atom of the bond ({@link IBond#getBegin()}).
153+
*/
154+
WedgedHashBegin,
155+
/**
156+
* Display as a hashed wedge, with the narrow end
157+
* towards the end atom of the bond ({@link IBond#getEnd()}).
158+
*/
159+
WedgedHashEnd,
160+
/**
161+
* Display as a bold wedge, with the narrow end
162+
* towards the begin atom of the bond ({@link IBond#getBegin()}).
163+
*/
164+
WedgeBegin,
165+
/**
166+
* Display as a bold wedge, with the narrow end
167+
* towards the end atom of the bond ({@link IBond#getEnd()}).
168+
*/
169+
WedgeEnd,
170+
/**
171+
* Display as an arrow (e.g. coordination bond), the arrow points
172+
* to the begin ({@link IBond#getBegin()}) atom.
173+
*/
174+
ArrowBeg,
175+
/**
176+
* Display as an arrow (e.g. coordination bond), the arrow points
177+
* to the end ({@link IBond#getEnd()}) atom.
178+
*/
179+
ArrowEnd
180+
}
181+
134182
/**
135183
* Returns the Iterable to atoms making up this bond.
136184
*
@@ -270,13 +318,27 @@ enum Stereo {
270318
IBond.Stereo getStereo();
271319

272320
/**
273-
* Sets the stereo descriptor for this bond.
321+
* Sets the stereo descriptor for this bond. Note this function will
322+
* also modify the bond display style.
274323
*
275324
* @param stereo The stereo descriptor to be assigned to this bond.
276325
* @see #getStereo
326+
* @see #setDisplay(Display)
277327
*/
278328
void setStereo(IBond.Stereo stereo);
279329

330+
/**
331+
* Access the bond display style.
332+
* @return the bond display
333+
*/
334+
IBond.Display getDisplay();
335+
336+
/**
337+
* Set the bond display style.
338+
* @param display the display
339+
*/
340+
void setDisplay(IBond.Display display);
341+
280342
/**
281343
* Returns the geometric 2D center of the bond.
282344
*

base/isomorphism/src/main/java/org/openscience/cdk/isomorphism/matchers/QueryBond.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,22 @@ public void setStereo(IQueryBond.Stereo stereo) {
417417
notifyChanged();
418418
}
419419

420+
/**
421+
* Not used for query bonds. {@inheritDoc}
422+
*/
423+
@Override
424+
public Display getDisplay() {
425+
return null;
426+
}
427+
428+
/**
429+
* Not used for query bonds. {@inheritDoc}
430+
*/
431+
@Override
432+
public void setDisplay(Display display) {
433+
434+
}
435+
420436
/**
421437
* Returns the geometric 2D center of the query bond.
422438
*

base/silent/src/main/java/org/openscience/cdk/silent/Bond.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public class Bond extends ElectronContainer implements IBond, Serializable, Clon
8484
*/
8585
protected IBond.Stereo stereo;
8686

87+
protected IBond.Display display = Display.Solid;
88+
8789
/**
8890
* Constructs an empty bond.
8991
*/
@@ -402,6 +404,38 @@ public IBond.Stereo getStereo() {
402404
@Override
403405
public void setStereo(IBond.Stereo stereo) {
404406
this.stereo = stereo;
407+
switch (stereo) {
408+
case UP:
409+
display = Display.WedgeBegin;
410+
break;
411+
case DOWN:
412+
display = Display.WedgedHashBegin;
413+
break;
414+
case UP_INVERTED:
415+
display = Display.WedgeEnd;
416+
break;
417+
case DOWN_INVERTED:
418+
display = Display.WedgedHashEnd;
419+
break;
420+
case UP_OR_DOWN:
421+
case UP_OR_DOWN_INVERTED:
422+
display = Display.Wavy;
423+
break;
424+
}
425+
}
426+
427+
/**
428+
* {@inheritDoc}
429+
*/
430+
public IBond.Display getDisplay() {
431+
return display;
432+
}
433+
434+
/**
435+
* {@inheritDoc}
436+
*/
437+
public void setDisplay(IBond.Display display) {
438+
this.display = display;
405439
}
406440

407441
/**

0 commit comments

Comments
 (0)