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

Disables the lock when the camera is dynamic #353

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions gama.core/src/gama/core/outputs/LayeredDisplayData.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,12 @@ public void setZFar(final Double zF) {
public void update(final IScope scope, final Facets facets) {

if (cameraNameExpression != null) {
boolean isLocked = camera == null ? false : camera.isLocked();

Choose a reason for hiding this comment

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

❌ New issue: Bumpy Road Ahead
update has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function

Suppress

setCameraNameFromGaml(Cast.asString(scope, cameraNameExpression.value(scope)));
if (camera != null) {
// camera.reset();
camera.setLocked(isLocked);
}
}

if (camera != null) { camera.refresh(scope); }
Expand Down Expand Up @@ -885,15 +890,17 @@ public void setCameraTarget(final GamaPoint point) {
* the disable cam interact
*/
public void setCameraLocked(final boolean disableCamInteract) {
camera.setInteractive(!disableCamInteract);
camera.setLocked(disableCamInteract);
}

/**
* Camera interaction disabled.
*
* @return true, if successful
*/
public boolean isCameraLocked() { return !camera.isInteractive(); }
public boolean isCameraLocked() { return camera.isLocked(); }

public boolean isCameraDynamic() { return camera.isDynamic(); }

// ************************************************************************************************
// ************************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*******************************************************************************************************
*
* CameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform
* .
* CameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform .
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
Expand Down Expand Up @@ -95,7 +94,7 @@
if (temp instanceof String pos) {
// If it is a symbolic position
double coeff = 1.4;
if ((scope instanceof GraphicsScope gs) && (gs.getGraphics() != null)) {
if (scope instanceof GraphicsScope gs && gs.getGraphics() != null) {
coeff = gs.getGraphics().getSurface().getData().getCameraDistanceCoefficient();
}
double w = scope.getSimulation().getWidth();
Expand Down Expand Up @@ -144,7 +143,7 @@
*/
@Override
public boolean setLocation(final GamaPoint loc) {
if (!isInteractive() || loc == null) return false;
if (isLocked() || isDynamic() || loc == null) return false;

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
setLocation has 1 complex conditionals with 2 branches, threshold = 2

Suppress

locationAttribute = new ConstantAttribute<>(loc.yNegated());
return current.setLocation(loc);
}
Expand All @@ -159,7 +158,7 @@
*/
@Override
public boolean setTarget(final GamaPoint loc) {
if (!isInteractive() || loc == null) return false;
if (isLocked() || isDynamic() || loc == null) return false;

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
setTarget has 1 complex conditionals with 2 branches, threshold = 2

Suppress

targetAttribute = new ConstantAttribute<>(loc.yNegated());
return current.setTarget(loc);
}
Expand All @@ -180,7 +179,7 @@
public Integer getLens() { return lens.get(); }

@Override
public Boolean isInteractive() { return !locked.get() && !isDynamic(); }
public Boolean isLocked() { return locked.get(); }

/**
* Sets the interactive.
Expand All @@ -189,11 +188,11 @@
* the new interactive
*/
@Override
public void setInteractive(final Boolean b) { this.locked = new ConstantAttribute<>(b == null ? false : !b); }
public void setLocked(final Boolean b) { this.locked = new ConstantAttribute<>(b == null ? false : b); }

Check warning on line 191 in gama.core/src/gama/core/outputs/layers/properties/CameraDefinition.java

View workflow job for this annotation

GitHub Actions / SpotBugs

BX_UNBOXING_IMMEDIATELY_REBOXED

Boxed value is unboxed and then immediately reboxed in gama.core.outputs.layers.properties.CameraDefinition.setLocked(Boolean)
Raw output
A boxed value is unboxed and then immediately reboxed.

@Override
public boolean setDistance(final Double d) {
if (!isInteractive() || d == null) return false;
if (isLocked() || isDynamic() || d == null) return false;

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
setDistance has 1 complex conditionals with 2 branches, threshold = 2

Suppress

distanceAttribute = new ConstantAttribute<>(d);
return current.setDistance(d);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*******************************************************************************************************
*
* GenericCameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation
* platform .
* GenericCameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform .
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
Expand All @@ -28,7 +27,7 @@ public class GenericCameraDefinition implements ICameraDefinition {
Integer lens = 45;

/** The is interactive. */
Boolean isInteractive = true;
Boolean isLocked = false;

/** The name. */
final String name;
Expand Down Expand Up @@ -83,11 +82,14 @@ public GenericCameraDefinition(final String name, final GamaPoint target, final
public Integer getLens() { return lens; }

@Override
public Boolean isInteractive() { return isInteractive; }
public Boolean isLocked() { return isLocked; }

@Override
public void setInteractive(final Boolean b) {
isInteractive = b;
public Boolean isDynamic() { return false; }

@Override
public void setLocked(final Boolean b) {
isLocked = b;

}

Expand All @@ -112,6 +114,7 @@ public boolean setTarget(final GamaPoint point) {
public void reset() {
currentLocation.setLocation(initialLocation);
currentTarget.setLocation(initialTarget);
isLocked = false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*******************************************************************************************************
*
* ICameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform
* .
* ICameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform .
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
Expand All @@ -12,9 +11,9 @@

import java.util.List;

import gama.annotations.precompiler.IOperatorCategory;
import gama.annotations.precompiler.GamlAnnotations.constant;
import gama.annotations.precompiler.GamlAnnotations.doc;
import gama.annotations.precompiler.IOperatorCategory;
import gama.core.metamodel.shape.GamaPoint;
import gama.core.runtime.IScope;
import gama.gaml.interfaces.INamed;
Expand Down Expand Up @@ -111,15 +110,15 @@ public interface ICameraDefinition extends INamed {
*
* @return the boolean
*/
Boolean isInteractive();
Boolean isLocked();

/**
* Sets the interactive.
*
* @param b
* the new interactive
*/
void setInteractive(Boolean b);
void setLocked(Boolean b);

/**
* Sets the location.
Expand Down Expand Up @@ -206,4 +205,6 @@ default GamaPoint computeLocation(final String pos, final GamaPoint target, fina
};
}

Boolean isDynamic();

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public boolean is2D() {
}

@Override
public boolean isLocked() { return getDisplaySurface().isLocked(); }
public boolean isCameraLocked() { return getDisplaySurface().isCameraLocked(); }

@Override
public boolean isCameraDynamic() { return getDisplaySurface().isCameraDynamic(); }

}
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ public void toggleLock() {
*
* @return true, if is locked
*/
public boolean isLocked() { return isLocked; }
public boolean isCameraLocked() { return isLocked; }

public boolean isCameraDynamic() { return false; }

/**
* Checks if is image edge in panel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,6 @@ public GamaPoint getWorldPositionFrom(final GamaPoint mouse, final GamaPoint res
return result.setLocation(result.x * distance + camLoc.x, result.y * distance + camLoc.y, 0);
}


/**
* Gets the mouse position.
*
Expand Down Expand Up @@ -1164,16 +1163,21 @@ public void setCameraName(final String p) {
public boolean isCameraLocked() { return data.isCameraLocked(); }

@Override
public void toggleCamera() {
public boolean isCameraDynamic() { return data.isCameraDynamic(); }

@Override
public void toggleCameraLock() {
data.setCameraLocked(!data.isCameraLocked());
}

@Override
public String getCameraDefinition() {
StringBuilder text = new StringBuilder(IKeyword.CAMERA).append(" 'default' ").append(IKeyword.LOCATION)
.append(": ").append(new GamaPoint(data.getCameraPos()).yNegated().withPrecision(4).serializeToGaml(false));
StringBuilder text =
new StringBuilder(IKeyword.CAMERA).append(" 'default' ").append(IKeyword.LOCATION).append(": ")
.append(new GamaPoint(data.getCameraPos()).yNegated().withPrecision(4).serializeToGaml(false));
text.append(" ").append(IKeyword.TARGET).append(": ")
.append(new GamaPoint(data.getCameraTarget()).yNegated().withPrecision(4).serializeToGaml(false)).append(";");
.append(new GamaPoint(data.getCameraTarget()).yNegated().withPrecision(4).serializeToGaml(false))
.append(";");
return text.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* OpenGLDisplayView.java, in gama.ui.display.opengl, is part of the source code of the
* GAMA modeling and simulation platform (v.2024-06).
* OpenGLDisplayView.java, in gama.ui.display.opengl, is part of the source code of the GAMA modeling and simulation
* platform (v.2024-06).
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, ESPACE-DEV, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package gama.ui.display.opengl.view;

Expand Down Expand Up @@ -132,6 +132,8 @@ public boolean is2D() {
}

@Override
public boolean isLocked() { return getCameraHelper().isCameraLocked(); }
public boolean isCameraLocked() { return getCameraHelper().isCameraLocked(); }

@Override
public boolean isCameraDynamic() { return getCameraHelper().isCameraDynamic(); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void zoomFit() {

@Override
public void toggleLock() {
renderer.getCameraHelper().toggleCamera();
renderer.getCameraHelper().toggleCameraLock();
}

/**
Expand Down
Loading