Commit f2e08eac authored by Ivan Dages's avatar Ivan Dages
Browse files

mate : doc & isFlipped refactor

parent cbab27e6
package fr.ill.ics.n3d.io;
import java.io.File;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
......@@ -41,6 +42,8 @@ public class Nomad3DExporter {
*/
public void write(Model model, String xmlPath) {
try {
Logger.getLogger("nomad-3d").info("Writing model \"" + model.getName() + "\" to \"" + xmlPath + "\"...\n");
File outputFile = new File(xmlPath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
......@@ -63,6 +66,8 @@ public class Nomad3DExporter {
transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
transformer.transform(new DOMSource(doc), new StreamResult(outputFile));
Logger.getLogger("nomad-3d").info("Model \"" + model.getName() + "\" written.\n");
// TODO ZIP test
// File zipFile = new File(outputFile.getParent() + File.separator + outputFile.getName().substring(0, outputFile.getName().length()-4) + ".n3d");
// ZipUtil.pack(outputFile.getParentFile(), zipFile);
......@@ -101,6 +106,7 @@ public class Nomad3DExporter {
eComponent.setAttribute("name", comp.getName());
eComponent.setAttribute("fileName", comp.getFileName());
eComponent.setAttribute("wall", ((comp.isWall()) ? "True" : "False"));
for (ConfigParams config : comp.getConfigurations()) {
Element eConfig = writeConfigParams(config, doc);
......
......@@ -173,10 +173,14 @@ public class Nomad3DImporter {
private Component readComponent(Element eComponent, String dirPath) throws XMLParseException {
String name = eComponent.getAttribute("name");
String fileName = eComponent.getAttribute("fileName");
String wall = eComponent.getAttribute("wall");
Component component = new Component();
component.setName(name);
component.setFileName(fileName);
if (wall != null) {
component.setWall(wall.equals("True"));
}
readComponentConfigurations(eComponent, component);
......
/**
*
*/
package fr.ill.ics.n3d.model;
import java.util.logging.Logger;
import javafx.scene.transform.Transform;
/**
* Class representing a SolidWorks mate exported with the Nomad 3D addin.
* These mates are used to define cinematic constraints.
*
* @see
* <a href="http://help.solidworks.com/2015/English/SolidWorks/sldworks/c_Mates_Overview_Assemblies.htm?id=3d28cd3d7b384e6ea3e565c5db2ca24f#Pg0&ProductType=&ProductName=">
* SolidWorks documentation
* </a>
*
* @author dages
*
*/
public abstract class Mate {
/**
* Alignment of a mate.
* @author dages
*/
public enum Alignment {
/** Aligned mate. */
ALIGNED("Aligned"),
/** Anti-aligned mate, ie the mate is reversed. */
ANTI_ALIGNED("AntiAligned"),
/** Closest alignment. */
CLOSEST("Closest");
/** String representation of the alignment. */
private String name;
/**
* Constructor.
* @param name String representation of the alignment
*/
Alignment(String name) {
this.name = name;
}
/**
* Converts a string to an alignment.
* @param name Name of the alignment
* @return The designated alignment if it exists, null otherwise
*/
public static Alignment fromString(String name) {
switch (name) {
case "Aligned":
......@@ -31,25 +54,43 @@ public abstract class Mate {
case "Closest":
return Alignment.CLOSEST;
default:
System.err.println("Mate.Alignment.fromString : ERROR : unknown alignment \"" + name + "\"");
Logger.getLogger("nomad-3d").severe("Unknown alignment \"" + name + "\"\n");
return null;
}
}
/**
* String representation of the alignment.
* @return Name of the alignment
*/
@Override
public String toString() {
return this.name;
}
}
/** Threshold used for axis computation. */
protected static final double EPSILON = 1e-1;
/** Name of the mate. */
private String name;
/** Alignment of the mate. */
private Alignment alignment;
/** Minimum value of the mate. */
private double min;
/** Maximum value of the mate. */
private double max;
/** Whether the mate is flipped or not. */
private boolean flipped;
/** Entities of the mate. */
private MateEntity[] entities;
/** Number of mate entities for a mate. */
public static final int NB_ENTITIES = 2;
/**
......@@ -67,54 +108,110 @@ public abstract class Mate {
}
}
/**
* Gets the name.
* @return The name
*/
public String getName() {
return this.name;
}
/**
* Gets the alignment.
* @return The alignment
*/
public Alignment getAlignment() {
return alignment;
}
/**
* Gets the minimum value.
* @return The minimum value
*/
public double getMin() {
return this.min;
}
/**
* Gets the maximum value.
* @return The maximum value
*/
public double getMax() {
return this.max;
}
public boolean getFlipped() {
/**
* Gets the flipped status.
* @return true if the mate is flipped, false otherwise
*/
public boolean isFlipped() {
return this.flipped;
}
/**
* Gets an entity of this mate.
* @param i Entity index, must be between 0 and NB_ENTITIES-1
* @return The entity
*/
public MateEntity getEntity(int i) {
return this.entities[i];
}
/**
* Sets the name.
* @param name New name
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets the alignment.
* @param alignment New alignment
*/
public void setAlignment(Alignment alignment) {
this.alignment = alignment;
}
/**
* Sets the minimum value.
* @param min New minimum
*/
public void setMin(double min) {
this.min = min;
}
/**
* Sets the maximum value.
* @param max New maximum
*/
public void setMax(double max) {
this.max = max;
}
/**
* Set the flipped tag.
* @param flipped New flipped
*/
public void setFlipped(boolean flipped) {
this.flipped = flipped;
}
/**
* Sets an entity.
* @param i Entity index, must be between 0 and NB_ENTITIES-1
* @param entity New entity
*/
public void setEntity(int i, MateEntity entity) {
this.entities[i] = entity;
}
/**
* Applies the mate constraint to translational and rotational degrees of freedom.
* @param translation Translation axis, represents translational DOFs
* @param rotation Rotation axis, represents rotational DOFs
* @param rootToScene Root to scene transform
*/
public abstract void apply(Axis translation, Axis rotation, Transform rootToScene);
@Override
......
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