Skip to content

Commit 0effc2e

Browse files
committed
some small issues
1 parent 20571a9 commit 0effc2e

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

src/main/java/org/openmolecules/fx/viewer3d/V3DMolecule.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,15 @@ public V3DMolecule(StereoMolecule mol, int constructionMode, int hydrogenMode, i
199199
* @param hydrogenMode one of MoleculeArchitect.HYDROGEN_MODE_ options
200200
* @param ribbonMode one of Ribbon.MODE_ options
201201
* @param surfaceMode SURFACE_NONE, SURFACE_WIRES, or SURFACE_FILLED
202+
* @param surfaceColorMode one of SurfaceMesh.SURFACE_COLOR_...
203+
* @param surfaceColor null or color to be used for color modes PLAIN or ATOMIC_NO
204+
* @param surfaceTransparency SURFACE_NONE, SURFACE_WIRES, or SURFACE_FILLED
202205
* @param id
203206
*/
204-
public V3DMolecule(StereoMolecule protein, ArrayList<StereoMolecule> ligands, int constructionMode, int hydrogenMode, int ribbonMode, int surfaceMode, int id) {
205-
this(protein, constructionMode, hydrogenMode, ribbonMode, surfaceMode,
206-
DEFAULT_SURFACE_COLOR_MODE, null, DEFAULT_SURFACE_TRANSPARENCY, id, MoleculeRole.MACROMOLECULE, true, false, ligands);
207+
public V3DMolecule(StereoMolecule protein, ArrayList<StereoMolecule> ligands, int constructionMode, int hydrogenMode,
208+
int ribbonMode, int surfaceMode, int surfaceColorMode, Color surfaceColor, double surfaceTransparency, int id) {
209+
this(protein, constructionMode, hydrogenMode, ribbonMode, surfaceMode, surfaceColorMode, surfaceColor, surfaceTransparency,
210+
id, MoleculeRole.MACROMOLECULE, true, false, ligands);
207211
}
208212

209213
public V3DMolecule(StereoMolecule mol, int constructionMode, int hydrogenMode, int id, MoleculeRole role, boolean overrideHydrogen, boolean splitAllBonds) {
@@ -220,14 +224,14 @@ public V3DMolecule(StereoMolecule mol, int constructionMode, int hydrogenMode, i
220224
* @param surfaceMode SURFACE_NONE, SURFACE_WIRES, or SURFACE_FILLED
221225
* @param surfaceColorMode DEFAULT_SURFACE_COLOR_MODE or one of the SurfaceMesh.SURFACE_COLOR_xxx modes
222226
* @param surfaceColor null or explicit surface color used for some color modes
223-
* @param transparency
227+
* @param surfaceTransparency
224228
* @param id
225229
* @param role
226230
* @param overrideHydrogens whether hydrogen atoms are drawn in the molecule override color
227231
* @param splitAllBonds whether all bonds shall be constructed from two cylinders (allowing better selection coloring)
228232
*/
229-
public V3DMolecule(StereoMolecule mol, int constructionMode, int hydrogenMode, int ribbonMode, int surfaceMode,
230-
int surfaceColorMode, Color surfaceColor, double transparency,
233+
public V3DMolecule(StereoMolecule mol, int constructionMode, int hydrogenMode, int ribbonMode,
234+
int surfaceMode, int surfaceColorMode, Color surfaceColor, double surfaceTransparency,
231235
int id, MoleculeRole role, boolean overrideHydrogens, boolean splitAllBonds, ArrayList<StereoMolecule> ligands) {
232236
super(mol.getName());
233237
mMol = mol;
@@ -257,7 +261,7 @@ public V3DMolecule(StereoMolecule mol, int constructionMode, int hydrogenMode,
257261
mSurfaceMode[0] = surfaceMode;
258262
mSurfaceColor[0] = (surfaceColor == null) ? DEFAULT_SURFACE_COLOR : surfaceColor;
259263
mSurfaceColorMode[0] = surfaceColorMode;
260-
mSurfaceTransparency[0] = transparency;
264+
mSurfaceTransparency[0] = surfaceTransparency;
261265
mInitialCoordinates = new Coordinates[mol.getAllAtoms()];
262266
IntStream.range(0,mol.getAllAtoms()).forEach(i -> {
263267
mInitialCoordinates[i] = new Coordinates(mol.getCoordinates(i));
@@ -285,7 +289,7 @@ public V3DMolecule(StereoMolecule mol, int constructionMode, int hydrogenMode,
285289

286290
if (surfaceMode != SURFACE_MODE_NONE) {
287291
SurfaceCutter cutter = (role == MoleculeRole.MACROMOLECULE) ? createSurfaceCutter() : null;
288-
mSurfaceMesh[0] = new SurfaceMesh(mMol, 0, surfaceColorMode, getNeutralColor(0), 1.0 - transparency, cutter);
292+
mSurfaceMesh[0] = new SurfaceMesh(mMol, 0, surfaceColorMode, getNeutralColor(0), 1.0 - surfaceTransparency, cutter);
289293
updateSurfaceFromMesh(0);
290294
}
291295
}

src/main/java/org/openmolecules/fx/viewer3d/V3DMouseHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,7 @@ private void rotate(double dx, double dy, boolean aroundZAxis) {
475475
}
476476
else {
477477
// world center of gravity:
478-
Point3D cog = mScene.getCOGInGroup(mScene.getWorld());
479-
mScene.rotateWorld(new Rotate(d, cog.getX(), cog.getY(), cog.getZ(), p1));
480-
// mScene.rotateWorld(new Rotate(d, p1), mScene.getCOGInGroup(mScene.getWorld()));
478+
mScene.rotateWorld(new Rotate(d, p1), mScene.getCOGInGroup(mScene.getWorld()));
481479
}
482480

483481
if (!aroundZAxis)

src/main/java/org/openmolecules/fx/viewer3d/V3DScene.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ private void startAnimation() {
702702
value.addListener((observable, oldValue, newValue) -> {
703703
double angle = 0.5 * Math.cos(newValue.doubleValue());
704704
Point3D cog = getCOGInGroup(mWorld);
705-
mWorld.rotate(new Rotate(angle, cog.getX(), cog.getY(), cog.getZ(), new Point3D(0, 1, 0)));
705+
// mWorld.rotate(new Rotate(angle, cog.getX(), cog.getY(), cog.getZ(), new Point3D(0, 1, 0)));
706+
rotateWorldInternal(new Rotate(angle, new Point3D(0, 1, 0)), cog);
706707
});
707708
mAnimation = new Timeline(new KeyFrame(Duration.seconds(5), new KeyValue(value, 2*Math.PI)));
708709
mAnimation.setCycleCount(Animation.INDEFINITE);
@@ -726,17 +727,36 @@ public void rotateWorld(Rotate r) {
726727
mAnimationRevivalThread.start();
727728
}
728729
}
729-
730730
mPreviousManualRotationMillis = System.currentTimeMillis();
731+
731732
mWorld.rotate(r);
732733
}
733734

734-
/* public void rotateWorld(Rotate r, Point3D cog) { // we now put the pivot point into the Rotate
735-
if (mAnimation != null) {
735+
public void rotateWorld(Rotate r, Point3D cog) { // we now put the pivot point into the Rotate
736+
if (mAnimation != null && mAnimation.getStatus() != Animation.Status.STOPPED) {
736737
mAnimation.stop();
737-
// on manual rotate stop animation, but keep object for isAnimate() to return true
738+
if (mAnimationRevivalThread == null) {
739+
mAnimationRevivalThread = new Thread(() -> {
740+
while (System.currentTimeMillis()<mPreviousManualRotationMillis + 1500)
741+
try {
742+
Thread.sleep(200);
743+
} catch (InterruptedException ie) {
744+
}
745+
746+
if (Thread.currentThread() == mAnimationRevivalThread) {
747+
Platform.runLater(() -> reviveAnimation());
748+
mAnimationRevivalThread = null;
749+
}
750+
});
751+
mAnimationRevivalThread.start();
752+
}
738753
}
754+
mPreviousManualRotationMillis = System.currentTimeMillis();
755+
756+
rotateWorldInternal(r, cog);
757+
}
739758

759+
private void rotateWorldInternal(Rotate r, Point3D cog) { // we now put the pivot point into the Rotate
740760
Point3D p1 = mWorld.getRotation().transform(cog);
741761
Point3D p2 = r.transform(p1.getX(), p1.getY(), p1.getZ());
742762

@@ -745,7 +765,7 @@ public void rotateWorld(Rotate r) {
745765
mWorld.setTranslateX(mWorld.getTranslateX()+p1.getX()-p2.getX());
746766
mWorld.setTranslateY(mWorld.getTranslateY()+p1.getY()-p2.getY());
747767
mWorld.setTranslateZ(mWorld.getTranslateZ()+p1.getZ()-p2.getZ());
748-
} */
768+
}
749769

750770
/**
751771
* @param polygon

0 commit comments

Comments
 (0)