use of org.kie.workbench.common.stunner.svg.gen.translator.SVGTranslatorContext in project kie-wb-common by kiegroup.
the class SVGGeneratorImpl method translate.
private ViewDefinitionImpl translate(final String viewId, final String svgPath, final Document document, final StyleSheetDefinition styleSheetDefinition) throws Exception {
final Path path = Paths.get(svgPath);
final String relativePath = path.getNameCount() > 1 ? path.subpath(0, path.getNameCount() - 1).toString() : "";
final SVGTranslatorContext context = new SVGTranslatorContext(document, relativePath, styleSheetDefinition);
if (null != viewId) {
context.setViewId(viewId);
}
final ViewDefinitionImpl viewDefinition = (ViewDefinitionImpl) translator.translate(context);
viewDefinition.setPath(svgPath);
viewDefinition.getStaticFields().putAll(context.getStaticStringMembers());
return viewDefinition;
}
use of org.kie.workbench.common.stunner.svg.gen.translator.SVGTranslatorContext in project kie-wb-common by kiegroup.
the class SVGDocumentTranslatorTest method testTranslate.
@Test
public void testTranslate() throws Exception {
final ViewDefinition<SVGShapeView> viewDefinition = translator.translate(new SVGTranslatorContext(svgTest, "", styleSheetDefinition));
assertNotNull(viewDefinition);
assertEquals("svg-test-file", viewDefinition.getId());
// View definition's viewBox.
final ViewDefinition.ViewBoxDefinition viewBox = viewDefinition.getViewBox();
assertNotNull(viewBox);
final double minX = viewBox.getMinX();
final double minY = viewBox.getMinY();
final double width = viewBox.getWidth();
final double height = viewBox.getHeight();
assertEquals(minX, 0d, 0d);
assertEquals(minY, 0d, 0d);
assertEquals(width, 448d, 0d);
assertEquals(height, 448d, 0d);
// View definition's main shape.
final PrimitiveDefinition mainShapeDef = viewDefinition.getMain();
assertNotNull(mainShapeDef);
assertTrue(mainShapeDef instanceof MultiPathDefinition);
final MultiPathDefinition mainPathDef = (MultiPathDefinition) mainShapeDef;
SVGTranslationTestAssertions.assertPath(mainPathDef);
assertTrue(mainPathDef.isListening());
// View definition's child shapes.
final List<PrimitiveDefinition> childrenDefs = viewDefinition.getChildren();
assertNotNull(childrenDefs);
assertTrue(childrenDefs.size() == 3);
final RectDefinition rectDefinition = (RectDefinition) childrenDefs.get(0);
SVGTranslationTestAssertions.assertRectangle(rectDefinition);
assertFalse(rectDefinition.isListening());
final CircleDefinition circleDefinition = (CircleDefinition) childrenDefs.get(1);
SVGTranslationTestAssertions.assertCircle(circleDefinition);
assertFalse(circleDefinition.isListening());
// Assert other svg reference elements.
final GroupDefinition groupDefinition = (GroupDefinition) childrenDefs.get(2);
assertFalse(groupDefinition.isListening());
SVGTranslationTestAssertions.assertGroupRef(groupDefinition);
final List<ViewRefDefinition> svgViewRefs = viewDefinition.getSVGViewRefs();
assertNotNull(svgViewRefs);
assertTrue(svgViewRefs.size() == 1);
final ViewRefDefinition viewRefDef = svgViewRefs.get(0);
SVGTranslationTestAssertions.assertViewRef(viewRefDef);
}
Aggregations