use of org.bimserver.models.ifc2x3tc1.IfcStyledItem in project BIMserver by opensourceBIM.
the class ModelColorizer method createStyle.
private void createStyle(double[] color, float transparency, IfcStyledItem styledItem) throws IfcModelInterfaceException {
IfcPresentationStyleAssignment presentationStyleAssignment = null;
if (styledItem.getStyles().isEmpty()) {
presentationStyleAssignment = model.create(IfcPresentationStyleAssignment.class);
styledItem.getStyles().add(presentationStyleAssignment);
} else {
presentationStyleAssignment = styledItem.getStyles().get(0);
}
IfcSurfaceStyle surfaceStyle = null;
if (presentationStyleAssignment.getStyles().isEmpty()) {
surfaceStyle = model.create(IfcSurfaceStyle.class);
presentationStyleAssignment.getStyles().add(surfaceStyle);
} else {
if (presentationStyleAssignment.getStyles().get(0) instanceof IfcSurfaceStyle) {
surfaceStyle = (IfcSurfaceStyle) presentationStyleAssignment.getStyles().get(0);
} else {
surfaceStyle = model.create(IfcSurfaceStyle.class);
presentationStyleAssignment.getStyles().set(0, surfaceStyle);
}
}
IfcSurfaceStyleRendering surfaceStyleRendering = null;
if (surfaceStyle.getStyles().isEmpty()) {
surfaceStyleRendering = model.create(IfcSurfaceStyleRendering.class);
surfaceStyle.getStyles().add(surfaceStyleRendering);
} else {
if (surfaceStyle.getStyles().get(0) instanceof IfcSurfaceStyleRendering) {
surfaceStyleRendering = (IfcSurfaceStyleRendering) surfaceStyle.getStyles().get(0);
} else {
surfaceStyleRendering = model.create(IfcSurfaceStyleRendering.class);
surfaceStyle.getStyles().set(0, surfaceStyleRendering);
}
}
IfcColourRgb colourRgb = model.create(IfcColourRgb.class);
colourRgb.setRed(color[0]);
colourRgb.setGreen(color[1]);
colourRgb.setBlue(color[2]);
surfaceStyleRendering.setDiffuseColour(colourRgb);
surfaceStyleRendering.setReflectionColour(colourRgb);
surfaceStyleRendering.setSpecularColour(colourRgb);
surfaceStyleRendering.setSurfaceColour(colourRgb);
surfaceStyleRendering.setTransmissionColour(colourRgb);
surfaceStyleRendering.setTransparency(transparency);
}
use of org.bimserver.models.ifc2x3tc1.IfcStyledItem in project BIMserver by opensourceBIM.
the class GuidHighlighter method highlightGuids.
private void highlightGuids(IfcModelInterface model, Set<String> highlightedGuids) {
Set<IdEObject> newObjects = new HashSet<IdEObject>();
IfcColourRgb gray = Ifc2x3tc1Factory.eINSTANCE.createIfcColourRgb();
newObjects.add(gray);
gray.setRed(0.5f);
gray.setGreen(0.5f);
gray.setBlue(0.5f);
Set<IdEObject> toDelete = new HashSet<IdEObject>();
for (IdEObject object : model.getValues()) {
if (object instanceof IfcPresentationLayerAssignment) {
toDelete.add(object);
}
}
IfcPresentationLayerAssignment notSelectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
notSelectedLayer.setName("Not Selected");
notSelectedLayer.setIdentifier("Not Selected");
newObjects.add(notSelectedLayer);
IfcPresentationLayerAssignment selectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
selectedLayer.setName("Selected");
selectedLayer.setIdentifier("Selected");
newObjects.add(selectedLayer);
for (IdEObject idEObject : model.getValues()) {
if (idEObject instanceof IfcProduct) {
IfcProduct product = (IfcProduct) idEObject;
String guid = product.getGlobalId();
boolean hide = true;
if (guid != null) {
if (highlightedGuids.contains(guid)) {
hide = false;
}
}
if (hide) {
System.out.println("Hiding " + guid);
IfcProductRepresentation representation = product.getRepresentation();
if (representation != null) {
for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
notSelectedLayer.getAssignedItems().add(ifcRepresentation);
for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
notSelectedLayer.getAssignedItems().add(ifcRepresentationItem);
for (IfcStyledItem ifcStyledItem : ifcRepresentationItem.getStyledByItem()) {
for (IfcPresentationStyleAssignment ifcPresentationStyleAssignment : ifcStyledItem.getStyles()) {
for (IfcPresentationStyleSelect ifcPresentationStyleSelect : ifcPresentationStyleAssignment.getStyles()) {
if (ifcPresentationStyleSelect instanceof IfcSurfaceStyle) {
IfcSurfaceStyle ifcSurfaceStyle = (IfcSurfaceStyle) ifcPresentationStyleSelect;
for (IfcSurfaceStyleElementSelect ifcSurfaceStyleElementSelect : ifcSurfaceStyle.getStyles()) {
if (ifcSurfaceStyleElementSelect instanceof IfcSurfaceStyleRendering) {
IfcSurfaceStyleRendering ifcSurfaceStyleRendering = (IfcSurfaceStyleRendering) ifcSurfaceStyleElementSelect;
ifcSurfaceStyleRendering.setTransparency(0.98f);
ifcSurfaceStyleRendering.setDiffuseColour(gray);
ifcSurfaceStyleRendering.setReflectionColour(gray);
ifcSurfaceStyleRendering.setSpecularColour(gray);
ifcSurfaceStyleRendering.setSurfaceColour(gray);
ifcSurfaceStyleRendering.setTransmissionColour(gray);
}
}
}
}
}
}
}
}
}
} else {
System.out.println("Not hiding " + guid);
IfcProductRepresentation representation = product.getRepresentation();
if (representation != null) {
for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
selectedLayer.getAssignedItems().add(ifcRepresentation);
for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
selectedLayer.getAssignedItems().add(ifcRepresentationItem);
}
}
}
}
}
}
for (IdEObject toDeleteObject : toDelete) {
model.remove(toDeleteObject);
}
for (IdEObject newObject : newObjects) {
try {
model.add(model.getHighestOid() + 1, newObject);
} catch (IfcModelInterfaceException e) {
e.printStackTrace();
}
}
}
use of org.bimserver.models.ifc2x3tc1.IfcStyledItem in project BIMserver by opensourceBIM.
the class ModelColorizer method setColor.
public void setColor(IfcProduct product, double[] color, float transparency) throws IfcModelInterfaceException {
if (!productToStyledItem.containsKey(product) || productToStyledItem.get(product).isEmpty()) {
// There is no style, let's construct a path to a new one
System.out.println("No style for " + product + " " + product.getGlobalId());
IfcProductRepresentation productRepresentation = product.getRepresentation();
if (product.getRepresentation() == null) {
productRepresentation = model.create(IfcProductRepresentation.class);
product.setRepresentation(productRepresentation);
}
IfcRepresentation representation = null;
if (productRepresentation.getRepresentations().isEmpty()) {
representation = model.create(IfcRepresentation.class);
productRepresentation.getRepresentations().add(representation);
} else {
representation = productRepresentation.getRepresentations().get(0);
}
IfcRepresentationItem representationItem = null;
if (representation.getItems().isEmpty()) {
representationItem = model.create(IfcRepresentationItem.class);
representation.getItems().add(representationItem);
} else {
representationItem = representation.getItems().get(0);
}
IfcStyledItem styledItem = model.create(IfcStyledItem.class);
representationItem.getStyledByItem().clear();
representationItem.getStyledByItem().add(styledItem);
createStyle(color, transparency, styledItem);
} else if (productToStyledItem.get(product).size() == 1) {
// There is one style, we can work with that
IfcStyledItem styledItem = productToStyledItem.get(product).iterator().next();
Set<IfcProduct> products = styledItemToProduct.get(styledItem);
if (products.isEmpty()) {
// That's weird, inconsistent with other map
} else if (products.size() == 1) {
// That's probably us, we can alter the Style safely
createStyle(color, transparency, styledItem);
} else {
// Multiple objects are using this style, we have to do some magic
}
} else {
// There are multiple styles, that's a bit much...
System.out.println(productToStyledItem.get(product).size() + " styles for " + product);
}
}
Aggregations