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

component : doc

parent 4c563cc2
......@@ -46,7 +46,9 @@ public class Component {
DEFAULT_MATERIAL.setSpecularColor(Color.color(0, 0, 0, 0));
DEFAULT_MATERIAL.setSpecularPower(250);
}
/** Flag used to turn on the cursor selection. */
public static boolean selectOn = false;
/** Flag used to turn on the cursor unselection. */
public static boolean unselectOn = false;
/** Component currently moved by the user. Null if nothing moves. */
......@@ -92,7 +94,12 @@ public class Component {
/** Either the component is a wall or not. */
private boolean wall;
/** Initial axis of the component. Used internally. */
private Axis initialAxis;
/**
* List of the axes computed for each configuration of the component.
* These are used internally for axes computation.
*/
private ArrayList<Axis> computedAxes;
/**
......@@ -114,54 +121,116 @@ public class Component {
this.wall = false;
}
/**
* Gets the name of the component.
*
* This name is made of the file name of the component and an instance number, as follows : filename-1
*
* @return The name
*/
public String getName() {
return this.name;
}
/**
* Gets the file name of the component.
* @return The file name
*/
public String getFileName() {
return this.fileName;
}
/**
* gets the material of the component.
* @return The material
*/
public PhongMaterial getMaterial() {
return this.material;
}
/**
* Gets the scene node of the component.
*
* If the components is a leaf this node is a MeshView, otherwise it is a Group.
*
* @return The scene node.
*/
public Node getSceneNode() {
return this.sceneNode;
}
/**
* Gets the configurations of the component.
* @return Array of the configurations
*/
public ArrayList<ConfigParams> getConfigurations() {
return configurations;
}
/**
* Gets the children of the component.
* @return Array of the children
*/
public CopyOnWriteArrayList<Component> getChildren() {
return this.children;
}
/**
* Gets the parent of the component.
*
* If the component is the root, its parent is null.
*
* @return The parent
*/
public Component getParent() {
return this.parent;
}
/**
* Gets the axis of the component.
* @return The axis
*/
public Axis getAxis() {
return this.axis;
}
/**
* Gets the wall flag of the components
* @return true if the component is a wall
*/
public boolean isWall() {
return wall;
}
/**
* Get the tree item of the component.
* @return The tree item
*/
public CheckBoxTreeItem<Component> getTreeItem() {
return treeItem;
}
/**
* Sets the name of the component.
* @param name New name
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets the file name of the component.
* @param fileName New file name
*/
public void setFileName(String fileName) {
this.fileName = fileName;
}
/**
* Sets the material of the component and its descendants.
* @param material New material
* @param recurse true to set the material of all the sub-hierarchy, false to change this component only
*/
public void setMaterial(PhongMaterial material, boolean recurse) {
this.material = material;
if (this.sceneNode != null && this.isLeaf()) {
......@@ -175,14 +244,26 @@ public class Component {
}
}
/**
* Sets the material of the component.
* @param material New material
*/
public void setMaterial(PhongMaterial material) {
setMaterial(material, false);
}
/**
* Sets the scene node of the component.
* @param node New node
*/
public void setSceneNode(Node node) {
this.sceneNode = node;
}
/**
* Sets the axis of the component.
* @param axis New axis
*/
public void setAxis(Axis axis) {
this.axis = axis;
if (this.initialAxis == null) {
......@@ -191,6 +272,10 @@ public class Component {
resetAxisTransform(false);
}
/**
* Marks the component as a wall.
* @param wall New wall flag
*/
public void setWall(boolean wall) {
this.wall = wall;
}
......@@ -231,10 +316,18 @@ public class Component {
return this.children.remove(child);
}
/**
* Adds a configuration to this component.
* @param config New configuration
*/
public void addConfiguration(ConfigParams config) {
this.configurations.add(config);
}
/**
* Saves the current position of the component and its descendants in a new configuration.
* @param configName Name of the new configuration
*/
public void saveCurrentConfiguration(String configName) {
ConfigParams newConfig = new ConfigParams(this);
newConfig.setConfiguration(configName);
......@@ -292,6 +385,11 @@ public class Component {
}
}
/**
* Gets a specific configuration.
* @param configName Name of the configuration
* @return The configuration if it exists, null otherwise
*/
public ConfigParams getConfigurationByName(String configName) {
for (ConfigParams config : this.configurations) {
if (configName.equals(config.getConfiguration())) {
......@@ -317,16 +415,25 @@ public class Component {
}
/**
* Tests if the component if a leaf.
* @return true if this component is a leaf
*/
public boolean isLeaf() {
return this.children.isEmpty();
}
/**
* Tests if the component if the root.
* @return true if this component if the root
*/
public boolean isRoot() {
return (this.parent == null);
}
/**
* Computes the tree depth of the component.
* @return The tree depth
*/
public int treeDepth() {
if (this.parent == null) {
return 0;
......@@ -357,6 +464,10 @@ public class Component {
}
}
/**
* Set the component's axis as fixed.
* @param recursive true to fix the hierarchy
*/
public void fix(boolean recursive) {
this.setAxis(Axis.FIXED_AXIS.clone());
if (recursive) {
......@@ -365,7 +476,11 @@ public class Component {
}
}
}
/**
* Set the component's axis as free.
* @param recursive true to free the hierarchy
*/
public void free(boolean recursive) {
this.setAxis(Axis.FREE_AXIS.clone());
if (recursive) {
......@@ -375,6 +490,11 @@ public class Component {
}
}
/**
* Toggles the walls visibility.
* @param visible true to show the walls, false to hide them
* @param configName Name of the configuration to show
*/
public void setWallsVisible(boolean visible, String configName) {
if (this.isWall()) {
this.sceneNode.setVisible(visible && getConfigurationByName(configName).isVisible());
......@@ -384,6 +504,13 @@ public class Component {
}
}
/**
* Toggles the focus of the selection.
* @param selection The selection
* @param focusSelection true to see the selection only, false to see every component
* @param configName Name of the configuration to display
* @param recursive true to toggle the focus selection of the descendants
*/
public void focusSelection(CopyOnWriteArraySet<Component> selection, boolean focusSelection, String configName, boolean recursive) {
this.sceneNode.setVisible((!this.isLeaf()
|| (focusSelection && selection.contains(this))
......@@ -395,6 +522,12 @@ public class Component {
}
}
/**
* Sets the visibility of the component.
* @param visible New visibility
* @param configName Name of the configuration to display
* @param recursive true to apply the same visibility to the sub-hierarchy
*/
public void setVisible(boolean visible, String configName, boolean recursive) {
this.sceneNode.setVisible(visible && getConfigurationByName(configName).isVisible());
if (recursive) {
......@@ -415,6 +548,10 @@ public class Component {
return str;
}
/**
* Compact string representation of the component
* @return Info string of the component
*/
public String infoString() {
String str = "";
str += "Name : " + this.name + "\n";
......@@ -428,6 +565,11 @@ public class Component {
return str;
}
/**
* Size of the mesh(es) belonging to this component or its subhierarchy.
* @param recursive true to count the triangles of the descendants
* @return Triangle count of the component's mesh(es)
*/
public long meshesSize(boolean recursive) {
long size = 0;
try {
......@@ -445,6 +587,10 @@ public class Component {
return size;
}
/**
* Hierarchy size, inluding this component.
* @return Number of component of the sub-hierarchy
*/
public long hierarchySize() {
long size = 1;
for (Component child : this.children) {
......@@ -453,10 +599,20 @@ public class Component {
return size;
}
/**
* Number of translational or rotational axes in the component's sub-hierarchy.
* @return Axes count
*/
public long axesCount() {
return axesCount(true);
}
/**
* Number of translational or rotational axes of the component's.
* @param recursive true to count the axes of the descendants
* @return Axes count
*/
public long axesCount(boolean recursive) {
long count = (this.axis.getType() == Axis.Type.TRANSLATION || this.axis.getType() == Axis.Type.ROTATION) ? 1 : 0;
if (recursive) {
......@@ -467,6 +623,11 @@ public class Component {
return count;
}
/**
* Roots of a set of components, ie the components whose parent is not selected.
* @param components Set of components of a model
* @return Set of roots
*/
public static HashSet<Component> rootsOf(Set<Component> components) {
HashSet<Component> roots = new HashSet<>();
for (Component c : components) {
......@@ -477,6 +638,10 @@ public class Component {
return roots;
}
/**
* Computes the axes of this component and its sub-hierarchy for each configuration, merges the results and
* analyzes the configurations in order to set the min/median/max values.
*/
void computeAxes() {
if (!this.isRoot()) {
Logger.getLogger("nomad-3d").warning(this.name + " is not the root");
......@@ -492,6 +657,7 @@ public class Component {
/**
* Compute the scene tree of this component's hierarchy, for the specified configuration.
* @param model Model owning the component
* @param configName Name of the configuration
*/
void computeSceneHierarchy(Model model, String configName) {
......@@ -543,6 +709,12 @@ public class Component {
}
}
/**
* Imports the mesh of the component.
* @param model Model owning the component
* @param stlFile Path of the STL file containing the mesh
* @return The mesh view containing the imported mesh
*/
private MeshView importMesh(Model model, File stlFile) {
TriangleMesh mesh = null;
......@@ -649,6 +821,7 @@ public class Component {
/**
* Compute the scene tree of this component's hierarchy, for the first configuration in its configuration list.
* @param model Model owning the component
*/
void computeSceneHierarchy(Model model) {
computeSceneHierarchy(model, this.configurations.get(0).getConfiguration());
......@@ -666,6 +839,12 @@ public class Component {
this.axis.getVisualGroup().setVisible(enabled && selection.contains(this));
}
/**
* Set the component as selected
* @param selected true to select the component, false to not
* @param model Model owning the component
* @param recursive true to select the descendants, false to not
*/
void setSelected(boolean selected, Model model, boolean recursive) {
if (selected) {
model.addToSelection(this);
......@@ -679,6 +858,10 @@ public class Component {
}
}
/**
* Shows a specific configuration
* @param configName name of the configuration
*/
void showConfiguration(String configName) {
ConfigParams config = getConfigurationByName(configName);
this.axis.setValue(config.getAxisValue());
......@@ -733,7 +916,7 @@ public class Component {
}
/**
*
* Analyzes the configuration to get the min/median/max values of the axis.
* @return true if the analysis is successful, false in case of errors
*/
boolean configurationsAnalysis() {
......@@ -826,6 +1009,9 @@ public class Component {
return true;
}
/**
* resets the movement along the axis for this component and its sub-hierarchy.
*/
private void resetAxes() {
this.setAxis(this.initialAxis);
for (Component child : this.children) {
......@@ -833,6 +1019,9 @@ public class Component {
}
}
/**
* Store the axes of the hierarchy in the computed axes array of the components.
*/
private void storeAxes() {
this.computedAxes.add(this.axis);
for (Component child : this.children) {
......@@ -840,6 +1029,9 @@ public class Component {
}
}
/**
* Merges the computed axes into the final axis of the component, for each component of the hierarchy.
*/
private void mergeConfigsAxes() {
Axis finalAxis = null;
boolean fixed = false;
......@@ -865,6 +1057,7 @@ public class Component {
/**
* Computes the axes of this component and its hierarchy.
* @param configName Name of the configuration
*/
private void computeAxes(String configName) {
ConfigParams config = getConfigurationByName(configName);
......@@ -912,6 +1105,7 @@ public class Component {
/**
* Block pass of the axes computation.
* @param config Current configuration
*/
private void blockPass(ConfigParams config) {
HashSet<Component> rootBlock = computeRootBlock(config);
......@@ -932,6 +1126,7 @@ public class Component {
/**
* Axis pass of the axes computation.
* @param config Current configuration
*/
private void axisPass(ConfigParams config) {
Stack<Component> computedComponents = new Stack<Component>();
......@@ -976,6 +1171,7 @@ public class Component {
/**
* Computes the root block during the block pass.
* @param config Current configuration
* @return The root block
*/
private HashSet<Component> computeRootBlock(ConfigParams config) {
......@@ -998,8 +1194,9 @@ public class Component {
/**
* Computes the blocks, apart from the root block, during the block pass.
* @param rootBlock
* @return
* @param rootBlock Root block
* @param config Current configuration
* @return List of the blocks
*/
private LinkedList<HashSet<Component>> computeBlocks(HashSet<Component> rootBlock, ConfigParams config) {
LinkedList<HashSet<Component>> blocks = new LinkedList<HashSet<Component>>();
......@@ -1081,7 +1278,7 @@ public class Component {
}
/**
* Regroups the blocks in new components. These are inserted as children of this components.
* Regroup the blocks in new components. These are inserted as children of this components.
* @param blocks Computed blocks
*/
private void regroupBlocks(LinkedList<HashSet<Component>> blocks) {
......@@ -1095,6 +1292,12 @@ public class Component {
}
}
/**
* Inserts a block as a child of this component.
* @param block Block to insert
* @param fixedBlock true to set the block as fixed
* @return The inserted component
*/
public Component insertBlock(HashSet<Component> block, boolean fixedBlock) {
Component inserted = new Component();
......
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