本文章 详细讲解动态创建Chart并和目标对象(工位或其他)执行数据绑定的详细操作(含源代码)

本文章 详细讲解动态创建Chart并和目标对象(工位或其他)执行数据绑定的详细操作(含源代码)

功能就是 设定起始坐标 然后创建Chart 并对Chart的数据源进行绑定操作 创建Chart并绑定数据表

Var StartXPox,StartYPox,StepXPox,StepYpos:integer
var ChartRes:object:=.UserInterface.Chart
var CallerFrame:object:=?.RootFrame
----更新CHART颜色------
for var ColorNumer := -3 to 14
	ChartRes.setRGB(ColorNumer,CallerFrame.Chart.getRValue(ColorNumer),CallerFrame.Chart.getGValue(ColorNumer),CallerFrame.Chart.getBValue(ColorNumer))
next
StartXPox:=2260
if CallerFrame.name="GlobeValveWorkshop_NewVersion"
	StartYPox:=3545
else
	StartYPox:=3325
end
StepXPox:=100
StepYpos:=60
for var i := 1 to CallerFrame.StartPartDb.yDIM
	Var Mdb:object:=CallerFrame.StartPartDb["设备数据表",i]
	Mdb.MaxXdim:=Mdb.Xdim
	Mdb.MaxYdim:=Mdb.Ydim
	for var X := 1 to Mdb.Xdim
		var ProcessName:String:=Mdb[X,0]
		if  strlen(ProcessName)<1
			continue ---空位表直接跳过
		end
		---正对接管螺母及接管执行Chart名称区分-------------------------------------------------------------------------------------
		var PartName:string:=strCopy(Mdb.label,1,4)
		if  PartName="接管螺母"
			PartName:="螺母"
		else
			PartName:=strCopy(PartName,1,2)
		end
		---------------------------------------------------------------------------------------------------------------------------
		var ChartName:string:=to_str(PartName,"_",ProcessName)//获取当前产品系列设备工艺名称
		ChartName:=regex_replace(ChartName,"[+ - / ,]","_")
		var IsStoreFrame:boolean:=Strlen(Regex_search(ChartName,"库"))>0 --确认对象是否为库对象
		var ChartInputChannel:table
		if not IsStoreFrame
			---普通线体或者设备
			var KeyCheck:String:=regex_search(ProcessName,"整道|气平孔|主接")
			Var IsZPLLinee:boolean:=Strlen(KeyCheck)>0
			if  not IsZPLLinee
				ChartInputChannel:=CreateNwChart(CallerFrame,ChartName,StartXPox,StartYPox,StepXPox,StepYpos)---指定位置创建一个新的Chart
			else
				ChartInputChannel:=void
			end
			for var Y := 1 to Mdb.Ydim
				if  Mdb[X,Y]=void
					exitloop
				end
				var StationFrameName:string:=Mdb[X,Y].name
				if IsZPLLinee
					----如果是气平孔 及整道集成线体则按该图表建跟踪表
					---读取线体内的全部Station(Pice)对象并放置到Chart 上面进StationLocationFrame行跟踪
					var LineFrame:object:=str_to_obj(to_str(CallerFrame,".",StationFrameName))
					var ReCheckIsTargetLine:boolean:=strlen(regex_search(StationFrameName,"ZPL"))>0
					if ReCheckIsTargetLine
						var StationChartInputChannel:table:=CreateNwChart(CallerFrame,to_str(ChartName,"_",LineFrame.name),StartXPox,StartYPox,StepXPox,StepYpos)---指定位置创建一个新的Chart
						GetStaionFromNetWork(LineFrame,"Place",StationChartInputChannel)
					else
						---目标设备中存在孤立设备
						if ChartInputChannel=void
							---创建一个跟踪表进行集中存放
							ChartInputChannel:=CreateNwChart(CallerFrame,ChartName,StartXPox,StartYPox,StepXPox,StepYpos)---指定位置创建一个新的Chart
						end
						if not SetDataToChart(CallerFrame,StationFrameName,"Station",ChartInputChannel)----数据写入Chart
							debug //当前数据写入失败
						end
					end
				else
					if not SetDataToChart(CallerFrame,StationFrameName,"Station",ChartInputChannel)----数据写入Chart
						debug //当前数据写入失败
					end
					if ProcessName="火焰焊接"
						LineFrame:=str_to_obj(to_str(CallerFrame,".",StationFrameName))
						StationChartInputChannel:=CreateNwChart(CallerFrame,to_str(ChartName,"_",LineFrame.name),StartXPox,StartYPox,StepXPox,StepYpos)---指定位置创建一个新的Chart
						GetStaionFromNetWork(LineFrame,"Place",StationChartInputChannel)
					end
				end
			next
		else
			-------周转库 NutStore.LSB.Stock.FJ_04_87_DG10
			----主要跟踪实时出入库速度()及库存情况
			continue ---立库数据当前跟踪没有意义 执行跳过
		end
	next
	-----初始化产品组件首个图表位置
	StartYPox+=StepYpos
	StartXPox:=2260
next
messageBox("已重新刷新并 定义完成!")

数据绑定操作 SetDataToChart

------------------------------------------------------------------------------------------------
---策略功能说明:将设备对象写入指定的Char的Chainner通道

---该程序段控制:
------------------------------------------------------------------------------------------------
---输入成员:

---内部成员:

---返回值:

---Called By :

---Calls  :

---Author: Support By YeChaocheng

---Date  : 01.11.2022
------------------------------------------------------------------------------------------------

---History:

---01.11.2022  KM  SimTalk 2.0

------------------------------------------------------------------------------------------------
//##############################################################################################
Param StationLocationFrame:object,StationFrameName:string,TargetStationName:string,byref ChartInputChannel:table->boolean
--var IsMainLine:boolean:=strlen(regex_search(StationFrameName,"ML"))>0 //包含ML则为主线
var StationFramePath:=to_str(StationLocationFrame,".",StationFrameName)
if  not existsobject(StationFramePath)
	return false
end
var StationFrame:object:=str_to_obj(StationFramePath)
------------------------------------------------------------------------------------------------
---检查目标对象是否存在
var ReadTargetObjectPath:string:=to_str(StationFrame,".",TargetStationName)
if  not existsobject(ReadTargetObjectPath)
	return false --目标对象不存在于指定Frame
end
if TargetStationName/="Station"
	StationFrameName:=TargetStationName --如果设备记录的不是Station则记录当前设备本身的名称
end
var TargetStation:object:=str_to_obj(ReadTargetObjectPath)
if  TargetStation/=void
	///当当前设备需要跟踪的信息写入到表中
	ChartInputChannel[ChartInputChannel.Xdimindex+1,0]:=StationFrameName //写入工位头
	///写入工位属性
	ChartInputChannel[ChartInputChannel.Xdimindex,1]:=to_str(TargetStation,".StatWorkingPortion")
	ChartInputChannel[ChartInputChannel.Xdimindex,2]:=to_str(TargetStation,".StatSetupPortion")
	ChartInputChannel[ChartInputChannel.Xdimindex,3]:=to_str(TargetStation,".StatWaitingPortion")
	ChartInputChannel[ChartInputChannel.Xdimindex,4]:=to_str(TargetStation,".StatBlockingPortion")
	ChartInputChannel[ChartInputChannel.Xdimindex,5]:=to_str(TargetStation,".StatPoweringUpDownPortion")
	ChartInputChannel[ChartInputChannel.Xdimindex,6]:=to_str(TargetStation,".StatFailPortion")
	ChartInputChannel[ChartInputChannel.Xdimindex,7]:=to_str(TargetStation,".StatStoppedPortion")
	ChartInputChannel[ChartInputChannel.Xdimindex,8]:=to_str(TargetStation,".StatPausingPortion")
	ChartInputChannel[ChartInputChannel.Xdimindex,9]:=to_str(TargetStation,".StatUnplannedPortion")
end
return true

你可能感兴趣的:(PlantSimulation,Chart,数据绑定,动态创建,标准化)