use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.
the class Intersect method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Intersect{regions=[");
for (Region region : this.regions) {
sb.append(region.toString()).append(",");
}
sb.append("]}");
return sb.toString();
}
use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.
the class LegacyRegionParser method parse.
public Region parse(Element el) throws InvalidXMLException {
Region region = this.parseDynamic(el);
String name = el.getAttributeValue("name");
if (name == null || el.getName().equalsIgnoreCase("region")) {
this.regionContext.add(region);
} else {
if (this.regionContext.get(name) == null) {
this.regionContext.add(name, region);
} else {
throw new InvalidXMLException("The region '" + name + "' already exists", el);
}
}
return region;
}
use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.
the class LegacyRegionParser method parseReference.
public Region parseReference(Attribute attr) throws InvalidXMLException {
String name = attr.getValue();
Region region = this.regionContext.get(name);
if (region == null) {
throw new InvalidXMLException("Unknown region '" + name + "'", attr);
} else {
return region;
}
}
use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.
the class RegionParser method parseRegionProperty.
@Nullable
public Region parseRegionProperty(Element rootElement, @Nullable FeatureValidation<RegionDefinition> validation, Region def, String... names) throws InvalidXMLException {
Attribute propertyAttribute = null;
Element propertyElement = null;
for (String name : names) {
if (rootElement.getAttribute(name) != null && rootElement.getChild(name) != null) {
throw new InvalidXMLException("Multiple defined region properties for " + name, rootElement);
}
if ((rootElement.getAttribute(name) != null || rootElement.getChild(name) != null) && (propertyAttribute != null || propertyElement != null)) {
throw new InvalidXMLException("Multiple defined region properties for " + Arrays.toString(names), rootElement);
}
if (rootElement.getAttribute(name) != null) {
propertyAttribute = rootElement.getAttribute(name);
} else if (rootElement.getChild(name) != null) {
propertyElement = rootElement.getChild(name);
}
}
Region region = def;
Node node = null;
if (propertyAttribute != null) {
region = this.parseReference(propertyAttribute);
node = new Node(propertyAttribute);
} else if (propertyElement != null) {
region = this.parseChildren(propertyElement);
node = new Node(propertyElement);
}
if (region != null && validation != null) {
validate(region, validation, node);
}
return region;
}
use of tc.oc.pgm.api.region.Region in project PGM by PGMDev.
the class RegionParser method parseHalves.
protected RegionDefinition parseHalves(Element el, double dir) throws InvalidXMLException {
Double x = XMLUtils.parseNumber(el.getAttribute("x"), Double.class, (Double) null);
Double y = XMLUtils.parseNumber(el.getAttribute("y"), Double.class, (Double) null);
Double z = XMLUtils.parseNumber(el.getAttribute("z"), Double.class, (Double) null);
List<HalfspaceRegion> halves = new ArrayList<>();
if (x != null)
halves.add(new HalfspaceRegion(new Vector(x, 0, 0), new Vector(dir, 0, 0)));
if (y != null)
halves.add(new HalfspaceRegion(new Vector(0, y, 0), new Vector(0, dir, 0)));
if (z != null)
halves.add(new HalfspaceRegion(new Vector(0, 0, z), new Vector(0, 0, dir)));
switch(halves.size()) {
case 0:
throw new InvalidXMLException("Expected at least one of x, y, or z attributes", el);
case 1:
return halves.get(0);
default:
return new Intersect((Region[]) halves.toArray());
}
}
Aggregations