BlockOperation.java
package com.varnernet.gerb4j.render;
import java.util.ArrayList;
import java.util.List;
/**
* Represents a Step-and-Repeat block (SR) that groups drawing operations and repeats them at
* regularly-spaced positions.
*
* <p>Aperture Blocks (AB) are handled separately via {@link com.varnernet.gerb4j.BlockAperture}.
*/
public final class BlockOperation implements GerberOperation {
/**
* Type-safe list of operations contained in this SR block.
*/
private final List<GerberOperation> operations;
// SR parameters
private Integer repeatX;
private Integer repeatY;
private Double offsetI;
private Double offsetJ;
/**
* Constructs a new BlockOperation.
*/
public BlockOperation() {
this.operations = new ArrayList<>();
}
/**
* Returns a defensive copy of the operation list.
*
* @return the list of operations
*/
public List<GerberOperation> getOperations() {
return new ArrayList<>(operations);
}
/**
* Adds an operation to the block.
*
* @param op the operation to add
*/
public void addOperation(final GerberOperation op) {
operations.add(op);
}
/**
* Sets the SR parameters.
*
* @param newRepeatX the repeat X
* @param newRepeatY the repeat Y
* @param newOffsetI the offset I
* @param newOffsetJ the offset J
*/
public void setSRParameters(final Integer newRepeatX, final Integer newRepeatY, final Double newOffsetI, final Double newOffsetJ) {
this.repeatX = newRepeatX;
this.repeatY = newRepeatY;
this.offsetI = newOffsetI;
this.offsetJ = newOffsetJ;
}
/**
* Returns the repeat X.
*
* @return the repeat X
*/
public Integer getRepeatX() {
return repeatX;
}
/**
* Returns the repeat Y.
*
* @return the repeat Y
*/
public Integer getRepeatY() {
return repeatY;
}
/**
* Returns the offset I.
*
* @return the offset I
*/
public Double getOffsetI() {
return offsetI;
}
/**
* Returns the offset J.
*
* @return the offset J
*/
public Double getOffsetJ() {
return offsetJ;
}
@Override
public String toString() {
return String.format(
"SR[%dx%d @ I%.3f J%.3f, %d ops]", repeatX, repeatY, offsetI, offsetJ, operations.size());
}
}