【发布时间】:2020-10-22 13:11:40
【问题描述】:
我正在尝试运行几年前开发的 AnyLogic 模型,但我无权联系编写它的人。我对Java的了解非常有限。该模型是基于从 XML 文件中读取的数据构建的。第一步是从 XML 文件中读取布局数据并绘制布局。它曾经可以正常工作,但随着 AnyLogic 版本的更改,它停止了工作。我收到以下错误:
" (RectangularNode) : 空间标记元素的创建没有完成,请使用initialize()函数。"
突出显示为错误源的代码是:
((Agent)temp).setLocation(shapeLayoutObj);
有趣的是,在此错误发生之前确实绘制了几个 RectangularNodes。周围的代码如下。上面在控制台窗口中标识为错误源的语句靠近下面提供的代码的底部。
/* Layout drawing */
//Initializing objects
int scale=30;
Layout layout= CMSDDocument.getDataSection().getLayout();
List<LayoutObject> layoutObj =CMSDDocument.getDataSection().getLayoutObject();
double xLoc, yLoc, width, depth;
double xOffset = 50.0;
double yOffset = 100.0;
String layoutName;
width = layout.getBoundary().getWidth().doubleValue()*scale;
depth = layout.getBoundary().getDepth().doubleValue()*scale;
RectangularNode shapeCellArea = new RectangularNode(this, SHAPE_DRAW_2D3D, true, xOffset, yOffset, 0.0, width, depth, 0, null, Color.red, 2.0, LINE_STYLE_SOLID, POSITION_CHOICE_RANDOM, new Attractor(0,0,0));
ShapeText text = new ShapeText(SHAPE_DRAW_2D3D,true,xOffset+width/2,yOffset-20,0.0,0.0,red,"SHOP FLOOR",new Font ("Calibri", Font.BOLD , 15),TextAlignment.ALIGNMENT_CENTER);
presentation.add(shapeCellArea);
presentation.add(text);
LinkedHashMap<String,RectangularNode> floorLayout=new LinkedHashMap<String,RectangularNode>();
boolean found;
int j;
//For every layout description
for(int i= 0; i<layout.getPlacement().size();i++){
//Getting the name and the description
layoutName = layout.getPlacement().get(i).getLayoutElementIdentifier();
xLoc = layout.getPlacement().get(i).getLocation().getX().doubleValue()*scale + xOffset;
yLoc = layout.getPlacement().get(i).getLocation().getY().doubleValue()*scale + yOffset;
found = false;
j = 0;
//Looking for the layout object with tthe same name as the layout description
while (!found && j<layoutObj.size()){
if (layoutName.equals(layoutObj.get(j).getIdentifier())) {
//Getting layou values
width = layoutObj.get(j).getBoundary().getWidth().doubleValue()*scale;
depth = layoutObj.get(j).getBoundary().getDepth().doubleValue()*scale;
RectangularNode shapeLayoutObj=null;
//Configure the shape
if(layoutName.contains("Mc")){
shapeLayoutObj = new RectangularNode(this, SHAPE_DRAW_2D3D, true, xLoc, yLoc, 0.0, width, depth, 0, null, Color.black, 2.0, LINE_STYLE_DASHED, POSITION_CHOICE_BY_ATTRACTORS,new Attractor(width/2,depth/2,0));
}
else{
shapeLayoutObj = new RectangularNode(this, SHAPE_DRAW_2D3D, true, xLoc, yLoc, 0.0, width, depth, 0, null, Color.black, 2.0, LINE_STYLE_DASHED, POSITION_CHOICE_RANDOM);
}
text = new ShapeText(SHAPE_DRAW_2D3D,true,xLoc+width/2,yLoc-15,0.0,0.0,black,layoutName,new Font ("Calibri", Font.PLAIN , 11),TextAlignment.ALIGNMENT_CENTER);
presentation.add(shapeLayoutObj);
presentation.add(text);
//Associate the shape with a machine or a delay
Iterator<ArrayList<Machine>> cell=machineList.iterator();
boolean foundAgent=false;
while(cell.hasNext()&&!foundAgent){
Iterator<Machine> machines=cell.next().iterator();
while(machines.hasNext()&&!foundAgent){
Machine temp=((Machine)machines.next());
if(temp.name.equals(layoutName)){
foundAgent=true;
((Agent)temp).setLocation(shapeLayoutObj);
ShapeButton button = new ShapeButton(Main.this, true, xLoc,yLoc+depth+5,40, 20.0,controlDefault, controlDefault,
true,new Font("Dialog", 0, 11 ),"Go to" ) {
public void action(){
getExperimentHost().setPresentable(temp);
}
};
presentation.add(button);
}
}
}
我从过去的交流中了解到 AnyLogic 从 Java Swing(在开发模型时的 AnyLogic7 中)切换到了基于 Web 的 UI,我想知道这个错误是否是由于该切换造成的。在 AnyLogic 帮助文件中,RectangularNode 函数被标识为“在 8.4 版本中已弃用,将在下一个版本中删除”。我现在使用的是 AnyLogic 8 Personal Learning Edition 8.5.2,因此我认为此功能已被删除。希望错误信息这么说!还希望帮助文件建议与不推荐使用的功能相对应的新功能。令人困惑的是,“矩形节点”在当前版本中继续显示为流程建模库选项板上的空间标记元素。猜猜那个元素的底层代码已经改变了。
我查看了 AnyLogic 的帮助,我认为“ShapeRectangle”可能是我应该用来替换“RectangularNode”函数但“ShapeRectangle”函数不允许定义吸引子的新函数。并且“ShapeRectangle”函数似乎对应于 Presentation Palette 中的 Rectangle 元素,而不是 Process Modeling Library 中的 Rectangular 节点。
请指点我正确的方向。我应该替换 RectangularNode 的所有实例还是错误是别的?如果我应该替换 RectangularNode 函数,我应该改用什么函数?
【问题讨论】:
标签: java deprecated anylogic