Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
695fd2a
Add geometry transformers
yoshi-ya Oct 8, 2025
d629808
Add tests
yoshi-ya Oct 8, 2025
5f2106e
Replace vector transformer with converter and add dedicated packages
yoshi-ya Oct 9, 2025
e15a8e0
Add util class for coordinates and warning for dimension mismatch
yoshi-ya Oct 9, 2025
e1d7024
Add license headers and update snapshot
yoshi-ya Oct 9, 2025
d327e87
Add dimension detection mechanism and logging
yoshi-ya Oct 9, 2025
31bf152
Add tests for util classes
yoshi-ya Oct 9, 2025
588e29f
Use context logger
yoshi-ya Oct 10, 2025
7510d85
Extend tests
yoshi-ya Oct 14, 2025
456caea
Use wrapper function
yoshi-ya Oct 14, 2025
d94e6c3
Remove redundant default properties and reference system
yoshi-ya Oct 16, 2025
5b97441
Relocate geometry package
yoshi-ya Oct 16, 2025
33af697
Refactor util class to be general
yoshi-ya Oct 16, 2025
11d925c
Refactor GeometryDimensionDetector
yoshi-ya Oct 16, 2025
a69ffe4
Add transformer for HarnessGeometry
yoshi-ya Oct 20, 2025
e66d7e6
Rename package
yoshi-ya Oct 20, 2025
8e3e7fb
Add tests
yoshi-ya Oct 20, 2025
4af3b27
Add license headers
yoshi-ya Oct 20, 2025
9386d24
Add logs and conditionally skip transformation
yoshi-ya Oct 20, 2025
b0927f4
Adapt tests
yoshi-ya Oct 20, 2025
2703fdd
Relocate file
yoshi-ya Oct 20, 2025
87d91e5
Add DimensionDetector instance variables
yoshi-ya Oct 20, 2025
7fa00d7
Prevent util class from being inherited or initialized
yoshi-ya Oct 20, 2025
7914334
Improve logging messages
yoshi-ya Oct 20, 2025
9e38cd6
Set identification attribute
yoshi-ya Oct 20, 2025
a1e2195
Update snapshots
yoshi-ya Oct 20, 2025
8b7d769
Add linker for TopologySegment & TopologyNode
yoshi-ya Oct 20, 2025
a41d1a6
Update snapshots
yoshi-ya Oct 20, 2025
cc6e6cb
Fix tests
yoshi-ya Oct 20, 2025
f118182
Add identifications
yoshi-ya Oct 22, 2025
e2d9a90
Improve warning log for malformed data
yoshi-ya Oct 22, 2025
725078c
Update snapshots
yoshi-ya Oct 22, 2025
96dff61
Add alias id transformations
yoshi-ya Oct 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ConverterRegistry {
private final StringToColorConverter stringToColorConverter;
private final StringToWireTypeConverter stringToWireTypeConverter;
private final StringToMaterialConverter stringToMaterialConverter;
private final DoublesToCartesianVector2DConverter doublesToCartesianVector2DConverter;
private final DoublesToCartesianVector3DConverter doublesToCartesianVector3DConverter;

public ConverterRegistry(final ConversionProperties conversionProperties) {
Objects.requireNonNull(conversionProperties);
Expand All @@ -47,6 +49,8 @@ public ConverterRegistry(final ConversionProperties conversionProperties) {
conversionProperties.getDefaultWireTypeReferenceSystem());
stringToMaterialConverter = new StringToMaterialConverter(
conversionProperties.getDefaultMaterialReferenceSystem());
doublesToCartesianVector2DConverter = new DoublesToCartesianVector2DConverter();
doublesToCartesianVector3DConverter = new DoublesToCartesianVector3DConverter();
}

public Converter<String, Optional<VecLocalizedString>> getStringToLocalizedString() {
Expand All @@ -64,4 +68,12 @@ public StringToWireTypeConverter getStringToWireTypeConverter() {
public StringToMaterialConverter getStringToMaterialConverter() {
return stringToMaterialConverter;
}

public DoublesToCartesianVector2DConverter getDoublesToCartesianVector2DConverter() {
return doublesToCartesianVector2DConverter;
}

public DoublesToCartesianVector3DConverter getDoublesToCartesianVector3DConverter() {
return doublesToCartesianVector3DConverter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*-
* ========================LICENSE_START=================================
* KBL to VEC Converter
* %%
* Copyright (C) 2025 4Soft GmbH
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* =========================LICENSE_END==================================
*/
package com.foursoft.harness.kbl2vec.convert;

import com.foursoft.harness.vec.v2x.VecCartesianVector2D;

import java.util.List;
import java.util.Optional;

import static com.foursoft.harness.kbl2vec.utils.ListUtils.getElementOrDefault;

public class DoublesToCartesianVector2DConverter implements Converter<List<Double>, Optional<VecCartesianVector2D>> {

@Override
public Optional<VecCartesianVector2D> convert(final List<Double> source) {
if (source == null || source.isEmpty()) {
return Optional.empty();
}
final VecCartesianVector2D destination = new VecCartesianVector2D();
destination.setX(getElementOrDefault(source, 0, 0.0));
destination.setY(getElementOrDefault(source, 1, 0.0));
return Optional.of(destination);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*-
* ========================LICENSE_START=================================
* KBL to VEC Converter
* %%
* Copyright (C) 2025 4Soft GmbH
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* =========================LICENSE_END==================================
*/
package com.foursoft.harness.kbl2vec.convert;

import com.foursoft.harness.vec.v2x.VecCartesianVector3D;

import java.util.List;
import java.util.Optional;

import static com.foursoft.harness.kbl2vec.utils.ListUtils.getElementOrDefault;

public class DoublesToCartesianVector3DConverter implements Converter<List<Double>, Optional<VecCartesianVector3D>> {

@Override
public Optional<VecCartesianVector3D> convert(final List<Double> source) {
if (source == null || source.isEmpty()) {
return Optional.empty();
}
final VecCartesianVector3D destination = new VecCartesianVector3D();
destination.setX(getElementOrDefault(source, 0, 0.0));
destination.setY(getElementOrDefault(source, 1, 0.0));
destination.setZ(getElementOrDefault(source, 2, 0.0));
return Optional.of(destination);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*-
* ========================LICENSE_START=================================
* KBL to VEC Converter
* %%
* Copyright (C) 2025 4Soft GmbH
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* =========================LICENSE_END==================================
*/
package com.foursoft.harness.kbl2vec.transform.geometry;

import com.foursoft.harness.kbl.v25.KblCartesianPoint;

import java.util.List;

public class GeometryDimensionDetector {
public static final int GEO_2D = 2;
public static final int GEO_3D = 3;

private GeometryDimensionDetector() {
}

public static boolean hasDimensions(final KblCartesianPoint vector, final int numOfDimensions) {
return hasDimensions(vector.getCoordinates(), numOfDimensions);
}

public static boolean hasDimensions(final List<?> vectors, final int numOfDimensions) {
if (vectors == null || vectors.isEmpty()) {
return false;
}
final Object first = vectors.get(0);
if (first instanceof Double) {
return vectors.size() == numOfDimensions;
} else if (first instanceof final KblCartesianPoint cartesianPoint) {
return hasDimensions(cartesianPoint, numOfDimensions);
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*-
* ========================LICENSE_START=================================
* KBL to VEC Converter
* %%
* Copyright (C) 2025 4Soft GmbH
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* =========================LICENSE_END==================================
*/
package com.foursoft.harness.kbl2vec.transform.geometry.geo_2d;

import com.foursoft.harness.kbl.v25.KblHarness;
import com.foursoft.harness.kbl2vec.core.Query;
import com.foursoft.harness.kbl2vec.core.TransformationContext;
import com.foursoft.harness.kbl2vec.core.TransformationResult;
import com.foursoft.harness.kbl2vec.core.Transformer;
import com.foursoft.harness.vec.v2x.VecBuildingBlockPositioning2D;
import com.foursoft.harness.vec.v2x.VecBuildingBlockSpecification2D;

public class BuildingBlockPositioning2DTransformer implements Transformer<KblHarness, VecBuildingBlockPositioning2D> {

@Override
public TransformationResult<VecBuildingBlockPositioning2D> transform(final TransformationContext context,
final KblHarness source) {
final VecBuildingBlockPositioning2D destination = new VecBuildingBlockPositioning2D();

return TransformationResult.from(destination)
.withLinker(Query.of(source), VecBuildingBlockSpecification2D.class,
VecBuildingBlockPositioning2D::setReferenced2DBuildingBlock)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*-
* ========================LICENSE_START=================================
* KBL to VEC Converter
* %%
* Copyright (C) 2025 4Soft GmbH
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* =========================LICENSE_END==================================
*/
package com.foursoft.harness.kbl2vec.transform.geometry.geo_2d;

import com.foursoft.harness.kbl.v25.KblCartesianPoint;
import com.foursoft.harness.kbl.v25.KblHarness;
import com.foursoft.harness.kbl.v25.KblNode;
import com.foursoft.harness.kbl.v25.KblSegment;
import com.foursoft.harness.kbl2vec.core.Query;
import com.foursoft.harness.kbl2vec.core.TransformationContext;
import com.foursoft.harness.kbl2vec.core.TransformationResult;
import com.foursoft.harness.kbl2vec.core.Transformer;
import com.foursoft.harness.kbl2vec.transform.geometry.GeometryDimensionDetector;
import com.foursoft.harness.vec.v2x.VecBuildingBlockSpecification2D;
import com.foursoft.harness.vec.v2x.VecCartesianPoint2D;
import com.foursoft.harness.vec.v2x.VecGeometryNode2D;
import com.foursoft.harness.vec.v2x.VecGeometrySegment2D;

public class BuildingBlockSpecification2DTransformer
implements Transformer<KblHarness, VecBuildingBlockSpecification2D> {

@Override
public TransformationResult<VecBuildingBlockSpecification2D> transform(final TransformationContext context,
final KblHarness source) {
final VecBuildingBlockSpecification2D destination = new VecBuildingBlockSpecification2D();

if (!GeometryDimensionDetector.hasDimensions(source.getParentKBLContainer().getCartesianPoints(),
GeometryDimensionDetector.GEO_2D)) {
return TransformationResult.noResult();
}
context.getLogger().info("Detected 2D data. Creating 2D building block specification.");

return TransformationResult.from(destination)
.withDownstream(KblNode.class, VecGeometryNode2D.class,
Query.fromLists(source.getParentKBLContainer().getNodes()),
VecBuildingBlockSpecification2D::getGeometryNodes)
.withDownstream(KblCartesianPoint.class, VecCartesianPoint2D.class,
Query.fromLists(source.getParentKBLContainer().getCartesianPoints()),
VecBuildingBlockSpecification2D::getCartesianPoints)
.withDownstream(KblSegment.class, VecGeometrySegment2D.class,
Query.fromLists(source.getParentKBLContainer().getSegments()),
VecBuildingBlockSpecification2D::getGeometrySegments)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*-
* ========================LICENSE_START=================================
* KBL to VEC Converter
* %%
* Copyright (C) 2025 4Soft GmbH
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* =========================LICENSE_END==================================
*/
package com.foursoft.harness.kbl2vec.transform.geometry.geo_2d;

import com.foursoft.harness.kbl.v25.KblCartesianPoint;
import com.foursoft.harness.kbl2vec.core.TransformationContext;
import com.foursoft.harness.kbl2vec.core.TransformationResult;
import com.foursoft.harness.kbl2vec.core.Transformer;
import com.foursoft.harness.kbl2vec.transform.geometry.GeometryDimensionDetector;
import com.foursoft.harness.vec.v2x.VecCartesianPoint2D;

import java.util.List;

import static com.foursoft.harness.kbl2vec.utils.ListUtils.getElementOrDefault;

public class CartesianPoint2DTransformer implements Transformer<KblCartesianPoint, VecCartesianPoint2D> {

@Override
public TransformationResult<VecCartesianPoint2D> transform(final TransformationContext context,
final KblCartesianPoint source) {
final VecCartesianPoint2D destination = new VecCartesianPoint2D();

final List<Double> coordinates = source.getCoordinates();
if (source.getCoordinates().isEmpty()) {
return TransformationResult.noResult();
}

if (!GeometryDimensionDetector.hasDimensions(source, GeometryDimensionDetector.GEO_2D)) {
context.getLogger().warn(
"Unexpected format for KblCartesianPoint (xmlId: {}). Expected 2 coordinates for 2D " +
"transformation, but found {}: {}",
source.getXmlId(), source.getCoordinates().size(), source.getCoordinates());
}

destination.setX(getElementOrDefault(coordinates, 0, 0.0));
destination.setY(getElementOrDefault(coordinates, 1, 0.0));

return TransformationResult.of(destination);
}
}
Loading