use of org.bimserver.models.ifc2x3tc1.IfcBoolean in project BIMserver by opensourceBIM.
the class TestCreateProperties method test.
@Test
public void test() {
try {
// New client
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
// Create a project
SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
// Look for a deserializer
SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
bimServerClient.checkinSync(project.getOid(), "test", deserializer.getOid(), false, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
// Refresh project
project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
// Load model without lazy loading (complete model at once)
IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, true);
String propertyName = "BooleanProperty";
int nrWindowsFirst = 0;
// Iterate over all projects, there should be 1
for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
nrWindowsFirst++;
createProperty(window, model, propertyName, "Description of property", true);
}
long newRoid = model.commit("Added boolean properties to " + nrWindowsFirst + " windows");
model = bimServerClient.getModel(project, newRoid, true, false);
int foundOke = 0;
int nrWindowsSecond = 0;
Set<Long> counted = new HashSet<Long>();
for (IfcWindow window : model.getAllWithSubTypes(IfcWindow.class)) {
nrWindowsSecond++;
for (IfcRelDefines ifcRelDefines : window.getIsDefinedBy()) {
if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
IfcRelDefinesByProperties ifcRelDefinesByProperties = (IfcRelDefinesByProperties) ifcRelDefines;
IfcPropertySetDefinition relatingPropertyDefinition = ifcRelDefinesByProperties.getRelatingPropertyDefinition();
if (relatingPropertyDefinition instanceof IfcPropertySet) {
IfcPropertySet ifcPropertySet = (IfcPropertySet) relatingPropertyDefinition;
for (IfcProperty ifcProperty : ifcPropertySet.getHasProperties()) {
if (ifcProperty instanceof IfcPropertySingleValue) {
IfcPropertySingleValue ifcPropertySingleValue = (IfcPropertySingleValue) ifcProperty;
if (ifcPropertySingleValue.getName().equals(propertyName)) {
IfcValue nominalValue = ifcPropertySingleValue.getNominalValue();
if (nominalValue instanceof IfcBoolean) {
if (((IfcBoolean) nominalValue).getWrappedValue() == Tristate.TRUE) {
if (!counted.contains(ifcPropertySingleValue.getOid())) {
foundOke++;
counted.add(ifcPropertySingleValue.getOid());
}
}
}
}
}
}
}
}
}
}
LOGGER.info("Windows first: " + nrWindowsFirst);
LOGGER.info("Windows second: " + nrWindowsSecond);
LOGGER.info("Found Oke: " + foundOke);
if (foundOke != nrWindowsFirst) {
fail(foundOke + " / " + nrWindowsFirst);
}
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.bimserver.models.ifc2x3tc1.IfcBoolean in project BIMserver by opensourceBIM.
the class TestCreateProperties method createProperty.
private void createProperty(IfcWindow window, IfcModelInterface model, String name, String description, Object value) throws IfcModelInterfaceException {
IfcRelDefinesByProperties ifcRelDefinesByProperties = model.create(IfcRelDefinesByProperties.class);
window.getIsDefinedBy().add(ifcRelDefinesByProperties);
IfcPropertySet propertySet = model.create(IfcPropertySet.class);
ifcRelDefinesByProperties.setRelatingPropertyDefinition(propertySet);
IfcPropertySingleValue property = model.create(IfcPropertySingleValue.class);
propertySet.getHasProperties().add(property);
property.setName(name);
property.setDescription(description);
if (value instanceof Boolean) {
IfcBoolean ifcValue = model.create(IfcBoolean.class);
ifcValue.setWrappedValue(((Boolean) value) ? Tristate.TRUE : Tristate.FALSE);
property.setNominalValue(ifcValue);
} else {
// Unimplemented
}
}
use of org.bimserver.models.ifc2x3tc1.IfcBoolean in project BIMserver by opensourceBIM.
the class TestSetWrappedBoolean method test.
@Test
public void test() {
try {
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
bimServerClient.getSettingsInterface().setCacheOutputFiles(false);
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
bimServerClient.checkinSync(newProject.getOid(), "initial", suggestedDeserializerForExtension.getOid(), false, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/revit_quantities.ifc"));
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test1.ifc"));
IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), false, false);
long tid = lowLevelInterface.startTransaction(newProject.getOid());
IfcPropertySingleValue ifcPropertySingleValue = model.getAll(IfcPropertySingleValue.class).iterator().next();
bimServerClient.getLowLevelInterface().setWrappedBooleanAttribute(tid, ifcPropertySingleValue.getOid(), "NominalValue", "IfcBoolean", true);
long roid = lowLevelInterface.commitTransaction(tid, "v2", false);
bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test2.ifc"));
bimServerClient.download(roid, serializer.getOid(), Paths.get("test3.ifc"));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.bimserver.models.ifc2x3tc1.IfcBoolean in project BIMserver by opensourceBIM.
the class IfcUtils method getBooleanProperty.
public static Tristate getBooleanProperty(IfcObject ifcObject, String propertyName) {
for (IfcRelDefines ifcRelDefines : ifcObject.getIsDefinedBy()) {
if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
IfcRelDefinesByProperties ifcRelDefinesByProperties = (IfcRelDefinesByProperties) ifcRelDefines;
IfcPropertySetDefinition propertySetDefinition = ifcRelDefinesByProperties.getRelatingPropertyDefinition();
if (propertySetDefinition instanceof IfcPropertySet) {
IfcPropertySet ifcPropertySet = (IfcPropertySet) propertySetDefinition;
for (IfcProperty ifcProperty : ifcPropertySet.getHasProperties()) {
if (ifcProperty instanceof IfcPropertySingleValue) {
IfcPropertySingleValue propertyValue = (IfcPropertySingleValue) ifcProperty;
if (ifcProperty.getName().equals(propertyName)) {
IfcBoolean label = (IfcBoolean) propertyValue.getNominalValue();
return label.getWrappedValue();
}
}
}
}
}
}
return null;
}
Aggregations