Commit a4ced4fc authored by legoc's avatar legoc
Browse files

Saving zero position and move all axes to zero position

parent 8fa082ae
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fr.ill.ics</groupId>
<artifactId>nomad-3d-commons</artifactId>
<version>0.0.1</version>
<version>0.0.2-SNAPSHOT</version>
<distributionManagement>
<repository>
......
......@@ -84,7 +84,7 @@ public class Nomad3DExporter {
Logger.getLogger("nomad-3d").info("Model \"" + model.getName() + "\" written.\n");
// TODO ZIP test
// ZIP test
// File zipFile = new File(outputFile.getParent() + File.separator + outputFile.getName().substring(0, outputFile.getName().length()-4) + ".n3d");
// ZipUtil.pack(outputFile.getParentFile(), zipFile);
} catch (Exception e) {
......@@ -243,6 +243,10 @@ public class Nomad3DExporter {
+ " " + axis.getPosition().getY()
+ " " + axis.getPosition().getZ());
eAxis.appendChild(ePos);
Element eZero = doc.createElement("ZeroValue");
eZero.setTextContent(Double.toString(axis.getZeroValue()));
eAxis.appendChild(eZero);
Element eMin = doc.createElement("MinValue");
eMin.setTextContent(Double.toString(axis.getMinValue()));
......@@ -260,8 +264,6 @@ public class Nomad3DExporter {
eController.setAttribute("name", controller.getName());
// TODO export controller values ? should be useless
return eController;
}
......
......@@ -194,7 +194,6 @@ public class Nomad3DImporter {
component.setWall(wall.equals("True"));
}
// TODO test
AsciiStringConverter asciiConverter = new AsciiStringConverter();
if (name.contains("&")) {
System.out.println("ASCII converter : " + name + " --> " + asciiConverter.convert(name));
......@@ -222,8 +221,6 @@ public class Nomad3DImporter {
}
}
/* TODO do this if model.state == EXPORTED
*/
if (model.getState() == State.EXPORTED) {
if (component.isLeaf()) {
File stlFile = new File(dirPath, fileName + ".STL");
......@@ -404,11 +401,19 @@ public class Nomad3DImporter {
scanner = new Scanner(nPosition.getTextContent());
Point3D position = new Point3D(scanner.nextDouble(), scanner.nextDouble(), scanner.nextDouble());
scanner.close();
Node nZeroValue = eAxis.getElementsByTagName("ZeroValue").item(0);
if (nZeroValue != null) {
double zeroValue = Double.parseDouble(nZeroValue.getTextContent());
axis.setZeroValue(zeroValue);
}
Node nMinValue = eAxis.getElementsByTagName("MinValue").item(0);
if (nMinValue != null) {
double minValue = Double.parseDouble(nMinValue.getTextContent());
axis.setMinValue(minValue);
}
Node nMaxValue = eAxis.getElementsByTagName("MaxValue").item(0);
if (nMaxValue != null) {
double maxValue = Double.parseDouble(nMaxValue.getTextContent());
......
......@@ -33,7 +33,6 @@ public class AngleMate extends Mate {
rootToScene.transform(this.getEntity(1).getAxis()).subtract(rootOrigin).normalize()
};
// TODO angle
Logger.getLogger("nomad-3d").warning("Angle mate entities " + this.getEntity(0).getType() + " - " + this.getEntity(1).getType() + " not handled");
}
......
......@@ -176,10 +176,9 @@ public class Axis {
private double maxValue;
/**
* Median value of the axis.
* @deprecated The median value is always 0 now, setting this value applies an offset to the current, min and max values
* Zero value of the axis, set while calibrating.
*/
private double medianValue;
private double zeroValue;
/** Transform applied by the user when moving the component along its axis. */
private Affine movementTransform;
......@@ -204,7 +203,7 @@ public class Axis {
this.value = 0;
this.minValue = Double.NEGATIVE_INFINITY;
this.maxValue = Double.POSITIVE_INFINITY;
this.medianValue = 0;
this.zeroValue = 0;
this.movementTransform = new Affine();
this.visualGroup = new Group();
this.visualGroup.setVisible(false);
......@@ -223,7 +222,7 @@ public class Axis {
this.value = a.value;
this.minValue = a.minValue;
this.maxValue = a.maxValue;
this.medianValue = a.medianValue;
this.zeroValue = a.zeroValue;
this.movementTransform = a.movementTransform.clone();
this.visualGroup = new Group();
this.visualGroup.setVisible(false);
......@@ -288,12 +287,11 @@ public class Axis {
}
/**
* Gets the median value of the axis
* @return The median value
* @deprecated The median value is always 0 now, setting this value applies an offset to the current, min and max values
* Gets the zero value of the axis, set while calibrating the axis.
* @return The zero value
*/
public double getMedianValue() {
return medianValue;
public double getZeroValue() {
return zeroValue;
}
/**
......@@ -381,14 +379,11 @@ public class Axis {
}
/**
* Sets the median value of the axis.
* @param medianValue New median value
* Sets the zero value of the axis.
* @param zeroValue New zero value
*/
public void setMedianValue(double medianValue) {
this.value -= medianValue;
this.minValue -= medianValue;
this.maxValue -= medianValue;
this.medianValue = 0;
public void setZeroValue(double zeroValue) {
this.zeroValue = zeroValue;
}
/**
......@@ -553,12 +548,21 @@ public class Axis {
}
/**
* Resets the movement.
* Resets the movement to the initial position.
*/
public void resetMovement() {
this.value = 0;
this.movementTransform.setToIdentity();
this.move(this.medianValue);
this.move(0);
}
/**
* Resets the movement.
*/
public void setToZeroMovement() {
this.value = zeroValue;
this.movementTransform.setToIdentity();
this.move(zeroValue);
}
/**
......
......@@ -390,7 +390,7 @@ public class Component {
public void saveMedianConfiguration(String configSourceName) {
double oldAxisValue = this.axis.getValue();
this.axis.moveTo(this.axis.getMedianValue());
this.axis.moveTo(this.axis.getZeroValue());
saveCurrentConfiguration("median", configSourceName, false);
for (Component child : this.children) {
......@@ -406,7 +406,7 @@ public class Component {
if (!Double.isInfinite(this.axis.getMinValue()) && !Double.isNaN(this.axis.getMinValue())) {
this.axis.moveTo(this.axis.getMinValue());
} else {
this.axis.moveTo(this.axis.getMedianValue());
this.axis.moveTo(this.axis.getZeroValue());
}
saveCurrentConfiguration("min", configSourceName, false);
if (Double.isInfinite(this.axis.getMinValue()) || Double.isNaN(this.axis.getMinValue())) {
......@@ -426,7 +426,7 @@ public class Component {
if (!Double.isInfinite(this.axis.getMaxValue()) && !Double.isNaN(this.axis.getMaxValue())) {
this.axis.moveTo(this.axis.getMaxValue());
} else {
this.axis.moveTo(this.axis.getMedianValue());
this.axis.moveTo(this.axis.getZeroValue());
}
saveCurrentConfiguration("max", configSourceName, false);
if (Double.isInfinite(this.axis.getMaxValue()) || Double.isNaN(this.axis.getMaxValue())) {
......@@ -599,6 +599,19 @@ public class Component {
}
}
/**
* Sets the axis transform of this component and its hierarchy. Used to set the movement to zero.
* @param recurse true to reset the movement of the sub-hierarchy
*/
public void setToZeroAxisTransform(boolean recurse) {
this.axis.setToZeroMovement();
if (recurse) {
for (Component child : this.children) {
child.setToZeroAxisTransform(recurse);
}
}
}
/**
* Set the component's axis as fixed.
* @param recursive true to fix the hierarchy
......@@ -1155,7 +1168,7 @@ public class Component {
}
this.axis.setMinValue(aa[MIN].getAngle());
this.axis.setMaxValue(aa[MAX].getAngle());
this.axis.setMedianValue(aa[MEDIAN].getAngle());
this.axis.setZeroValue(aa[MEDIAN].getAngle());
break;
case TRANSLATION:
Point3D med = new Point3D(configs[MEDIAN].getTranslation().getTx(), configs[MEDIAN].getTranslation().getTy(), configs[MEDIAN].getTranslation().getTz());
......@@ -1173,7 +1186,7 @@ public class Component {
}
this.axis.setMinValue(min.dotProduct(this.axis.getDirection()));
this.axis.setMaxValue(max.dotProduct(this.axis.getDirection()));
this.axis.setMedianValue(med.dotProduct(this.axis.getDirection()));
this.axis.setZeroValue(med.dotProduct(this.axis.getDirection()));
break;
default:
// Nothing to do
......
......@@ -397,11 +397,20 @@ public class Model {
* Resets the movement of every component along its axis.
*/
public void resetMovement() {
Logger.getLogger("nomad-3d").info("Reseting movement of the model \"" + this.name + "\"...");
Logger.getLogger("nomad-3d").info("Resetting movement of the model \"" + this.name + "\"...");
this.root.resetAxisTransform(true);
Logger.getLogger("nomad-3d").info("Movement reset.");
}
/**
* Sets the movement of every component along its axis to the zero position.
*/
public void setToZeroAxisTransform() {
Logger.getLogger("nomad-3d").info("Setting movement of the model \"" + this.name + "\" to zero...");
this.root.setToZeroAxisTransform(true);
Logger.getLogger("nomad-3d").info("Movement set to zero.");
}
@Override
public String toString() {
String str = "Model [\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment