Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
visualisation
Commits
e6d00af1
Commit
e6d00af1
authored
Nov 10, 2017
by
Manuel Schrick
Browse files
removed unused files, implemented test for SVGMain.java
parent
ab179b8f
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/montiarc/svggenerator/calculators/DrawingHelper.java
deleted
100644 → 0
View file @
ab179b8f
package
de.monticore.lang.montiarc.svggenerator.calculators
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol
;
import
de.monticore.lang.montiarc.svggenerator.calculators.symbols.ComponentLayoutSymbol
;
import
de.monticore.lang.montiarc.svggenerator.calculators.symbols.ConnectorRoutingSymbol
;
import
de.monticore.lang.montiarc.svggenerator.calculators.symbols.LayoutSymbol
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
/**
* Created by Peters Notebook on 13.05.2017.
*/
public
class
DrawingHelper
implements
DrawingConstants
{
public
static
int
getHorizontalConnectorSpacing
(
int
connectorCount
)
{
if
(
connectorCount
>
0
)
{
return
PORT_WIDTH
+
2
*
CONNECTOR_HANDLE_LENGTH
+
connectorCount
*
CONNECTOR_SPACING
;
}
else
{
return
COMPONENT_SPACING
;
}
}
public
static
int
getVerticalConnectorSpacing
(
int
connectorCount
)
{
return
connectorCount
*
CONNECTOR_SPACING
;
}
public
static
int
getColumnWidth
(
List
<
ExpandedComponentInstanceSymbol
>
componentsInColumn
)
{
int
maxComponentWidth
=
componentsInColumn
.
stream
()
.
mapToInt
(
DrawingHelper:
:
getComponentWidth
)
.
max
()
.
orElse
(
COMPONENT_MIN_WIDTH
);
return
maxComponentWidth
;
}
public
static
int
getRowHeight
(
List
<
ExpandedComponentInstanceSymbol
>
componentsInRow
)
{
int
maxComponentHeight
=
componentsInRow
.
stream
()
.
mapToInt
(
DrawingHelper:
:
getComponentHeight
)
.
max
()
.
orElse
(
COMPONENT_MIN_HEIGHT
);
return
maxComponentHeight
+
COMPONENT_SPACING
;
}
public
static
int
getComponentHeight
(
ExpandedComponentInstanceSymbol
inst
)
{
if
(!
inst
.
getTags
(
ComponentLayoutSymbol
.
KIND
).
isEmpty
())
{
ComponentLayoutSymbol
layoutSymbol
=
inst
.<
ComponentLayoutSymbol
>
getTags
(
ComponentLayoutSymbol
.
KIND
).
iterator
().
next
();
return
layoutSymbol
.
getHeight
();
}
int
requiredHeight
=
COMPONENT_MIN_HEIGHT
;
Collection
<
PortSymbol
>
ports
=
inst
.
getPorts
();
if
(
ports
!=
null
&&
!
ports
.
isEmpty
())
{
int
numOfInPorts
=
(
int
)
ports
.
stream
().
filter
(
PortSymbol:
:
isIncoming
).
count
();
int
numOfOutPorts
=
(
int
)
ports
.
stream
().
filter
(
PortSymbol:
:
isOutgoing
).
count
();
requiredHeight
+=
(
Math
.
max
(
numOfInPorts
,
numOfOutPorts
)
-
1
)
*
(
PORT_HEIGHT
+
PORT_SPACING
);
}
// Return calculated height
return
requiredHeight
;
}
public
static
int
getComponentWidth
(
ExpandedComponentInstanceSymbol
inst
)
{
return
COMPONENT_MIN_WIDTH
;
}
public
static
List
<
List
<
ExpandedComponentInstanceSymbol
>>
getColumns
(
ExpandedComponentInstanceSymbol
inst
)
{
Collection
<
ExpandedComponentInstanceSymbol
>
subComponents
=
inst
.
getSubComponents
();
HashMap
<
Integer
,
List
<
ExpandedComponentInstanceSymbol
>>
columns
=
new
HashMap
<>();
subComponents
.
stream
()
.
filter
(
subComponent
->
!
subComponent
.
getTags
(
LayoutSymbol
.
KIND
).
isEmpty
())
.
forEach
(
subComponent
->
{
LayoutSymbol
layoutSymbol
=
subComponent
.<
LayoutSymbol
>
getTags
(
LayoutSymbol
.
KIND
).
iterator
().
next
();
List
<
ExpandedComponentInstanceSymbol
>
column
=
columns
.
getOrDefault
(
layoutSymbol
.
getColumn
(),
new
ArrayList
<>());
column
.
add
(
subComponent
);
columns
.
put
(
layoutSymbol
.
getColumn
(),
column
);
});
int
maxColumn
=
columns
.
keySet
().
stream
().
mapToInt
(
Integer:
:
new
).
max
().
orElse
(
0
);
List
<
List
<
ExpandedComponentInstanceSymbol
>>
columnList
=
new
ArrayList
<>();
System
.
out
.
println
(
"found "
+
columns
.
size
()
+
"columns, maxColumn: "
+
maxColumn
);
for
(
int
i
=
0
;
i
<=
maxColumn
;
i
++)
{
columnList
.
add
(
columns
.
getOrDefault
(
i
,
new
ArrayList
<>()));
}
return
columnList
;
}
public
static
List
<
List
<
ExpandedComponentInstanceSymbol
>>
getRows
(
ExpandedComponentInstanceSymbol
inst
)
{
Collection
<
ExpandedComponentInstanceSymbol
>
subComponents
=
inst
.
getSubComponents
();
HashMap
<
Integer
,
List
<
ExpandedComponentInstanceSymbol
>>
rows
=
new
HashMap
<>();
subComponents
.
stream
()
.
filter
(
subComponent
->
!
subComponent
.
getTags
(
LayoutSymbol
.
KIND
).
isEmpty
())
.
forEach
(
subComponent
->
{
LayoutSymbol
layoutSymbol
=
subComponent
.<
LayoutSymbol
>
getTags
(
LayoutSymbol
.
KIND
).
iterator
().
next
();
List
<
ExpandedComponentInstanceSymbol
>
row
=
rows
.
getOrDefault
(
layoutSymbol
.
getRow
(),
new
ArrayList
<>());
row
.
add
(
subComponent
);
rows
.
put
(
layoutSymbol
.
getRow
(),
row
);
});
int
maxRow
=
rows
.
keySet
().
stream
().
mapToInt
(
Integer:
:
new
).
max
().
orElse
(
0
);
List
<
List
<
ExpandedComponentInstanceSymbol
>>
rowList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
maxRow
;
i
++)
{
rowList
.
add
(
rows
.
getOrDefault
(
i
,
new
ArrayList
<>()));
}
return
rowList
;
}
public
static
List
<
Integer
>
getConnectorCountsPerColumn
(
ExpandedComponentInstanceSymbol
inst
)
{
HashMap
<
Integer
,
Integer
>
connectorCountPerColumnMap
=
new
HashMap
<>();
inst
.
getConnectors
().
stream
()
.
filter
(
con
->
!
con
.
getTags
(
ConnectorRoutingSymbol
.
KIND
).
isEmpty
())
.
map
(
con
->
con
.<
ConnectorRoutingSymbol
>
getTags
(
ConnectorRoutingSymbol
.
KIND
).
iterator
().
next
())
.
forEach
(
routingSymbol
->
{
int
[]
connectorColumns
=
routingSymbol
.
getColumns
();
for
(
int
column
:
connectorColumns
)
{
int
connectorsInColumn
=
connectorCountPerColumnMap
.
getOrDefault
(
column
,
0
)
+
1
;
connectorCountPerColumnMap
.
put
(
column
,
connectorsInColumn
);
}
});
int
maxColumn
=
connectorCountPerColumnMap
.
keySet
().
stream
().
mapToInt
(
Integer:
:
new
).
max
().
orElse
(
0
);
List
<
Integer
>
connectorsPerColumn
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
maxColumn
;
i
++)
{
connectorsPerColumn
.
add
(
connectorCountPerColumnMap
.
getOrDefault
(
i
,
0
));
}
return
connectorsPerColumn
;
}
public
static
List
<
Integer
>
getConnectorCountsPerRow
(
ExpandedComponentInstanceSymbol
inst
)
{
HashMap
<
Integer
,
Integer
>
connectorsPerRowMap
=
new
HashMap
<>();
inst
.
getConnectors
().
stream
()
.
filter
(
con
->
!
con
.
getTags
(
ConnectorRoutingSymbol
.
KIND
).
isEmpty
())
.
map
(
con
->
con
.<
ConnectorRoutingSymbol
>
getTags
(
ConnectorRoutingSymbol
.
KIND
).
iterator
().
next
())
.
forEach
(
routingSymbol
->
{
int
[]
connectorRows
=
routingSymbol
.
getRows
();
for
(
int
row
:
connectorRows
)
{
int
connectorsInRow
=
connectorsPerRowMap
.
getOrDefault
(
row
,
0
)
+
1
;
connectorsPerRowMap
.
put
(
row
,
connectorsInRow
);
}
});
int
maxRow
=
connectorsPerRowMap
.
keySet
().
stream
().
mapToInt
(
Integer:
:
new
).
max
().
orElse
(
0
);
List
<
Integer
>
connectorCountsPerRow
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
maxRow
;
i
++)
{
connectorCountsPerRow
.
add
(
connectorsPerRowMap
.
getOrDefault
(
i
,
0
));
}
return
connectorCountsPerRow
;
}
}
src/main/java/de/monticore/lang/montiarc/svggenerator/calculators/SingletonDrawingHelper.java
deleted
100644 → 0
View file @
ab179b8f
package
de.monticore.lang.montiarc.svggenerator.calculators
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol
;
import
de.monticore.lang.montiarc.svggenerator.calculators.symbols.*
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
/**
* Created by Peters Notebook on 13.05.2017.
*/
public
class
SingletonDrawingHelper
implements
DrawingConstants
{
public
static
int
getHorizontalConnectorSpacing
(
int
connectorCount
)
{
if
(
connectorCount
>
0
)
{
return
PORT_WIDTH
+
2
*
CONNECTOR_HANDLE_LENGTH
+
connectorCount
*
CONNECTOR_SPACING
;
}
else
{
return
COMPONENT_SPACING
;
}
}
public
static
int
getVerticalConnectorSpacing
(
int
connectorCount
)
{
return
connectorCount
*
CONNECTOR_SPACING
;
}
public
static
int
getColumnWidth
(
List
<
ExpandedComponentInstanceSymbol
>
componentsInColumn
)
{
int
maxComponentWidth
=
componentsInColumn
.
stream
()
.
mapToInt
(
SingletonDrawingHelper:
:
getComponentWidth
)
.
max
()
.
orElse
(
COMPONENT_MIN_WIDTH
);
return
maxComponentWidth
;
}
public
static
int
getRowHeight
(
List
<
ExpandedComponentInstanceSymbol
>
componentsInRow
)
{
int
maxComponentHeight
=
componentsInRow
.
stream
()
.
mapToInt
(
SingletonDrawingHelper:
:
getComponentHeight
)
.
max
()
.
orElse
(
COMPONENT_MIN_HEIGHT
);
return
maxComponentHeight
+
COMPONENT_SPACING
;
}
public
static
int
getComponentHeight
(
ExpandedComponentInstanceSymbol
inst
)
{
if
(!
inst
.
getTags
(
SingletonComponentLayoutSymbol
.
KIND
).
isEmpty
())
{
SingletonComponentLayoutSymbol
layoutSymbol
=
inst
.<
SingletonComponentLayoutSymbol
>
getTags
(
SingletonComponentLayoutSymbol
.
KIND
).
iterator
().
next
();
return
layoutSymbol
.
getHeight
();
}
int
requiredHeight
=
COMPONENT_MIN_HEIGHT
;
Collection
<
PortSymbol
>
ports
=
inst
.
getPorts
();
if
(
ports
!=
null
&&
!
ports
.
isEmpty
())
{
List
<
PortSymbol
>
inPorts
=
new
ArrayList
<>();
List
<
PortSymbol
>
outPorts
=
new
ArrayList
<>();
ports
.
stream
()
.
filter
(
port
->
!
port
.
getTags
(
PortOrderSymbol
.
KIND
).
isEmpty
())
.
filter
(
port
->
port
.<
PortOrderSymbol
>
getTags
(
PortOrderSymbol
.
KIND
).
iterator
().
next
().
isVisibleInSingletonMode
())
.
forEach
(
port
->
{
if
(
port
.
isIncoming
())
{
inPorts
.
add
(
port
);
}
else
{
outPorts
.
add
(
port
);
}
});
requiredHeight
+=
(
Math
.
max
(
inPorts
.
size
(),
outPorts
.
size
())
-
1
)
*
(
PORT_HEIGHT
+
PORT_SPACING
);
}
// Return calculated height
return
requiredHeight
;
}
public
static
int
getComponentWidth
(
ExpandedComponentInstanceSymbol
inst
)
{
return
COMPONENT_MIN_WIDTH
;
}
public
static
List
<
List
<
ExpandedComponentInstanceSymbol
>>
getColumns
(
ExpandedComponentInstanceSymbol
inst
)
{
Collection
<
ExpandedComponentInstanceSymbol
>
subComponents
=
inst
.
getSubComponents
();
HashMap
<
Integer
,
List
<
ExpandedComponentInstanceSymbol
>>
columns
=
new
HashMap
<>();
subComponents
.
stream
()
.
filter
(
subComponent
->
!
subComponent
.
getTags
(
LayoutSymbol
.
KIND
).
isEmpty
())
.
forEach
(
subComponent
->
{
LayoutSymbol
layoutSymbol
=
subComponent
.<
LayoutSymbol
>
getTags
(
LayoutSymbol
.
KIND
).
iterator
().
next
();
List
<
ExpandedComponentInstanceSymbol
>
column
=
columns
.
getOrDefault
(
layoutSymbol
.
getColumn
(),
new
ArrayList
<>());
column
.
add
(
subComponent
);
columns
.
put
(
layoutSymbol
.
getColumn
(),
column
);
});
int
maxColumn
=
columns
.
keySet
().
stream
().
mapToInt
(
Integer:
:
new
).
max
().
orElse
(
0
);
List
<
List
<
ExpandedComponentInstanceSymbol
>>
columnList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
maxColumn
;
i
++)
{
columnList
.
add
(
columns
.
getOrDefault
(
i
,
new
ArrayList
<>()));
}
return
columnList
;
}
public
static
List
<
List
<
ExpandedComponentInstanceSymbol
>>
getRows
(
ExpandedComponentInstanceSymbol
inst
)
{
Collection
<
ExpandedComponentInstanceSymbol
>
subComponents
=
inst
.
getSubComponents
();
HashMap
<
Integer
,
List
<
ExpandedComponentInstanceSymbol
>>
rows
=
new
HashMap
<>();
subComponents
.
stream
()
.
filter
(
subComponent
->
!
subComponent
.
getTags
(
LayoutSymbol
.
KIND
).
isEmpty
())
.
forEach
(
subComponent
->
{
LayoutSymbol
layoutSymbol
=
subComponent
.<
LayoutSymbol
>
getTags
(
LayoutSymbol
.
KIND
).
iterator
().
next
();
List
<
ExpandedComponentInstanceSymbol
>
row
=
rows
.
getOrDefault
(
layoutSymbol
.
getRow
(),
new
ArrayList
<>());
row
.
add
(
subComponent
);
rows
.
put
(
layoutSymbol
.
getRow
(),
row
);
});
int
maxRow
=
rows
.
keySet
().
stream
().
mapToInt
(
Integer:
:
new
).
max
().
orElse
(
0
);
List
<
List
<
ExpandedComponentInstanceSymbol
>>
rowList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
maxRow
;
i
++)
{
rowList
.
add
(
rows
.
getOrDefault
(
i
,
new
ArrayList
<>()));
}
return
rowList
;
}
public
static
List
<
Integer
>
getConnectorCountsPerColumn
(
ExpandedComponentInstanceSymbol
inst
)
{
HashMap
<
Integer
,
Integer
>
connectorCountPerColumnMap
=
new
HashMap
<>();
inst
.
getConnectors
().
stream
()
.
filter
(
con
->
!
con
.
getTags
(
ConnectorRoutingSymbol
.
KIND
).
isEmpty
())
.
map
(
con
->
con
.<
ConnectorRoutingSymbol
>
getTags
(
ConnectorRoutingSymbol
.
KIND
).
iterator
().
next
())
.
filter
(
ConnectorRoutingSymbol:
:
isVisibleInSingletonMode
)
.
forEach
(
routingSymbol
->
{
int
[]
connectorColumns
=
routingSymbol
.
getColumns
();
for
(
int
column
:
connectorColumns
)
{
int
connectorsInColumn
=
connectorCountPerColumnMap
.
getOrDefault
(
column
,
0
)
+
1
;
connectorCountPerColumnMap
.
put
(
column
,
connectorsInColumn
);
}
});
int
maxColumn
=
connectorCountPerColumnMap
.
keySet
().
stream
().
mapToInt
(
Integer:
:
new
).
max
().
orElse
(
0
);
List
<
Integer
>
connectorsPerColumn
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
maxColumn
;
i
++)
{
connectorsPerColumn
.
add
(
connectorCountPerColumnMap
.
getOrDefault
(
i
,
0
));
}
return
connectorsPerColumn
;
}
public
static
List
<
Integer
>
getConnectorCountsPerRow
(
ExpandedComponentInstanceSymbol
inst
)
{
HashMap
<
Integer
,
Integer
>
connectorsPerRowMap
=
new
HashMap
<>();
inst
.
getConnectors
().
stream
()
.
filter
(
con
->
!
con
.
getTags
(
ConnectorRoutingSymbol
.
KIND
).
isEmpty
())
.
map
(
con
->
con
.<
ConnectorRoutingSymbol
>
getTags
(
ConnectorRoutingSymbol
.
KIND
).
iterator
().
next
())
.
filter
(
ConnectorRoutingSymbol:
:
isVisibleInSingletonMode
)
.
forEach
(
routingSymbol
->
{
int
[]
connectorRows
=
routingSymbol
.
getRows
();
for
(
int
row
:
connectorRows
)
{
int
connectorsInRow
=
connectorsPerRowMap
.
getOrDefault
(
row
,
0
)
+
1
;
connectorsPerRowMap
.
put
(
row
,
connectorsInRow
);
}
});
int
maxRow
=
connectorsPerRowMap
.
keySet
().
stream
().
mapToInt
(
Integer:
:
new
).
max
().
orElse
(
0
);
List
<
Integer
>
connectorCountsPerRow
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
maxRow
;
i
++)
{
connectorCountsPerRow
.
add
(
connectorsPerRowMap
.
getOrDefault
(
i
,
0
));
}
return
connectorCountsPerRow
;
}
}
src/test/java/de/monticore/lang/montiarc/svggenerator/SVGMainTest.java
0 → 100644
View file @
e6d00af1
package
de.monticore.lang.montiarc.svggenerator
;
import
org.junit.Test
;
import
java.io.File
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
* Created by Peters Notebook on 10.11.2017.
*/
public
class
SVGMainTest
{
@Test
public
void
testSVGMain
()
{
SVGMain
.
main
(
new
String
[]{
"--input"
,
"testManuelSchrick.bumperBot"
,
"--modelPath"
,
"src/test/resources/"
,
"--recursiveDrawing"
,
"true"
});
File
htmlFile
=
new
File
(
"output/testManuelSchrick.bumperBot.html"
);
assertTrue
(
htmlFile
.
exists
());
File
svgFile
=
new
File
(
"output/testManuelSchrick.bumperBot.svg"
);
assertTrue
(
svgFile
.
exists
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment