Author:赵志乾
Date:2024-06-18
Declaration:All Right Reserved!!!
1. 常用函数
辊道网络中可以包含多种元素,在动态生成辊道网络中,最常用到的是Conveyor元素和ConveyorCustomStation元素。本次示例仅说明Conveyor元素的动态生成,其内部对应的Java类为ConveyorPath;每个Conveyor可由若干段组成,段所对应的Java类为MarkupSegmentLine;这些类大部分都有多个构造函数,以下表格列举了常用的构造函数,其他已被官方标注为Deprecated;
函数 | 功能 |
---|---|
ConveyorNetwork(Agent owner, String name) | 构造函数,入参分别为网络的owner和网络名称; |
ConveyorPath() | 构造函数 |
MarkupSegmentLine(double sx, double sy, double sz, double ex,double ey, double ez) | 构造函数,入参分别为起始点坐标,单位为像素; |
2. 数据结构定义
{
"points": [
{
"code": "", // 点编码
"name": "", // 点名称
"x": 0.0, // 点坐标
"y": 0.0,
"z": 0.0
}
],
"conveyors": [
{
"code": "", // 辊道编码
"name": "", // 辊道名称
"pointCodes": [] // 辊道从起点至终点所经历的位置点编码列表
}
]
}
3. 代码实现
// 数据对象定义
public class PointDefinition implements Serializable {
private String code;
private String name;
private Double x;
private Double y;
private Double z;
// setter、getter
}
public class ConveyorDefinition implements Serializable {
private String code;
private String name;
// setter、getter
}
public class LayoutDefinition implements Serializable {
private List<PointDefinition> points;
private List<ConveyorDefinition> conveyors;
// setter、getter
}
// 辊道动态生成
// step1: 位置点定义转map,方便后续使用
Map<String,PointDefinition> codeToPointDefinitionMap = layoutDefinition.getPoints()
.stream()
.collect(Collectors.toMap(PointDefinition::getCode, Function.identity(), (a,b)->b));
// step2: 定义网络对象
ConveyorNetwork conveyorNetwork = new ConveyorNetwork(this,"conveyorNetwork");
// step3: 向网络添加conveyor
for(ConveyorDefinition conveyorDefinition : layoutDefinition.getConveyors()){
ConveyorPath conveyor = new ConveyorPath();
// 每个conveyor由若干段组成
for(int index=0; index<conveyorDefinition.getPointCodes().size()-1; index++){
PointDefinition startPoint = codeToPointDefinitionMap.get(conveyorDefinition.getPointCodes().get(index));
PointDefinition endPoint = codeToPointDefinitionMap.get(conveyorDefinition.getPointCodes().get(index+1));
double startX = scale.pixelsPerUnit(METER)*startPoint.getX();
double startY = scale.pixelsPerUnit(METER)*startPoint.getY();
double startZ = scale.pixelsPerUnit(METER)*startPoint.getZ();
double endX = scale.pixelsPerUnit(METER)*endPoint.getX();
double endY = scale.pixelsPerUnit(METER)*endPoint.getY();
double endZ = scale.pixelsPerUnit(METER)*endPoint.getZ();
MarkupSegmentLine segment = new MarkupSegmentLine(startX, startY, startZ, endX, endY, endZ);
conveyor.addSegment(segment);
}
conveyorNetwork.add(conveyor);
}
// step4: 将生成的网络添加到演示中
Level customLevel = new Level(this,"customLevel",SHAPE_DRAW_2D3D,0);
customLevel.add(conveyorNetwork);
customLevel.initialize();
presentation.add(customLevel);
标签:仿真,code,name,double,建模,private,anylogic,String,构造函数
From: https://blog.csdn.net/zhaoyaxuan001/article/details/139774443