/// <summary> /// 对Cassview中的控件进行打包和排序 /// </summary> /// <param name="curCas">需要排序的cassview</param> /// <param name="pageName">cassview页面的名称</param> /// <returns></returns> public List <string[]> PackOrderCtrl(CassView curCas, string[] pageNameInfo) { List <ControlInfo[]> CassInfo = new List <ControlInfo[]>(); List <List <ControlInfo> > alreadyPack = PackCtrls(curCas, pageNameInfo[0]); string pageName = getMark(pageNameInfo); foreach (List <ControlInfo> pack in alreadyPack) { CassInfo.Add(OrderCtrlsNum(curCas, pack, pageNameInfo[0])); } return(OrderPacksNum(curCas, CassInfo, pageName)); }
/// <summary> /// 从容器集合中获取控件的地址属性信息 /// </summary> /// <param name="CassInfos"></param> private void GetAddreesInfo(List <ArrayList> CassInfos) { int Count = 0;//数组序号 foreach (ArrayList node in CassInfos) { CassView curCass = (CassView)(node[1]); foreach (ControlInfo ctrl in curCass.ctrlsInfo) { if (ctrl.CodeInfo[2] != null && ctrl.VisibleFunctionProperty != null) {//有点名 if (ctrl.VisibleFunctionProperty.Count != 0) { foreach (XProp attribute in ctrl.VisibleFunctionProperty) { if (attribute.VarName != CassViewGenerator.portIndex) {//排除可见属性中的点名序号信息 string[] adresInfo = new string[7]; adresInfo[0] = ctrl.CodeInfo[2]; adresInfo[1] = attribute.Name; adresInfo[6] = attribute.VarName; if (Length4.Contains(attribute.ValueType)) { adresInfo[2] = Type4[Length4.IndexOf(attribute.ValueType)]; adresInfo[3] = "4"; } else if (Length1.Contains(attribute.ValueType)) {//bool和char类统一为uint8 20090621 adresInfo[2] = "uint8"; adresInfo[3] = "1"; } adresInfo[5] = "False";//初始时地址为空 所以设置可读可写为false this.AddressInfo.Add(adresInfo); } } } } } //获取模糊和解耦数据 List <string[]> tempList = GenerateCode.CatchArrayInfo(curCass, ref Count); foreach (string[] element in tempList) { this.AddressInfo.Add(ConvertInfo(element)); } } }
/// <summary> /// 更正模糊控件信息中数组属性的数组名并返回数组信息 /// </summary> /// <param name="curCas">控件所在CASSVIEW容器</param> /// <param name="curCtrl">控件</param> /// <param name="ArrayCount">当前所用到队列编号</param> /// <returns>数组信息</returns> static public string[] GetFuzzyArray(CassView curCas, Control curCtrl, ref int ArrayCount) { List <string> ArrayInfo = new List <string>(); PropertyDescriptor configurationProperty = TypeDescriptor.GetProperties(curCtrl)["Configuration"]; ControlTactic.SpecialControl.Fuzzy ConvertTool = new ControlTactic.SpecialControl.Fuzzy(); ControlTactic.SpecialControl.FuzzyStruct tempStruct = ConvertTool.ListToStruct((List <string>)configurationProperty.GetValue(curCtrl)); ControlInfo Fuzzy = curCas.FindControlInfo(curCtrl); string tempArray = null; for (int row = 0; row < tempStruct.RowNum * 2 + 1; row++) { for (int column = 0; column < tempStruct.ColumnNum * 2 + 1; column++) { tempArray += tempStruct.ControlTable[row, column]; if (row != tempStruct.RowNum * 2 || column != tempStruct.ColumnNum * 2) { tempArray += ","; } } if (row != tempStruct.RowNum - 1) { //tempArray += "\n";//去除每行回车符号 否则导致读取地址表出错BUG20090622 } } //创建模糊控制表参数的数组节点 for (int i = 0; i < Fuzzy.UnvisibleFunctionProperty.Count; i++) { if (Fuzzy.UnvisibleFunctionProperty[i].Name == "模糊控制表") {//ArrayInfo顺序依次为控件PortName、属性VarName、类型、数组名、长度、数组 Fuzzy.UnvisibleFunctionProperty[i].TheValue = "configuration" + CassViewGenerator.ProjectNum + "_array" + (ArrayCount++).ToString(); ArrayInfo.Add(Fuzzy.CodeInfo[2]); ArrayInfo.Add(Fuzzy.UnvisibleFunctionProperty[i].Name); ArrayInfo.Add("fp32"); ArrayInfo.Add(Fuzzy.UnvisibleFunctionProperty[i].TheValue.ToString()); ArrayInfo.Add(tempStruct.ControlTable.Length.ToString()); ArrayInfo.Add(tempArray); ArrayInfo.Add(Fuzzy.UnvisibleFunctionProperty[i].VarName); } } return(ArrayInfo.ToArray()); }
/// <summary> /// 通过控件的PortName和中文属性寻找英文属性 /// </summary> /// <returns></returns> private string GetVarName(string PortName, string Name) { foreach (ArrayList node in this.tabList) { CassView curCas = (CassView)node[1]; foreach (ControlInfo CtrlInfo in curCas.ctrlsInfo) { if (CtrlInfo.CodeInfo != null && CtrlInfo.CodeInfo.Length > 2 && CtrlInfo.CodeInfo[2] == PortName) { foreach (XProp element in CtrlInfo.VisibleFunctionProperty) { if (element.Name == Name) { return(element.VarName); } } } } } return(null); }
/// <summary> /// 获取对应Cassview中控件的数组信息 /// </summary> /// <param name="curCas"></param> /// <param name="count">数组起始序号</param> static public List <string[]> CatchArrayInfo(CassView curCass, ref int count) { List <string[]> Ainfos = new List <string[]>(); foreach (Control element in curCass.Controls) {//获取模糊和解耦的数组信息 string MS = TypeDescriptor.GetProperties(element)["ModuleSort"].GetValue(element).ToString(); if (MS == "模糊控制器") { string[] info = GenerateCode.GetFuzzyArray(curCass, element, ref count); Ainfos.Add(info); } else if (MS == "解耦补偿控制器") { List <string[]> tempInfos = GenerateCode.GetJieOuArray(curCass, element, ref count); foreach (string[] info in tempInfos) { Ainfos.Add(info); } } } return(Ainfos); }
/// <summary> /// ��ȡ��ӦCassview�пؼ���������Ϣ /// </summary> /// <param name="curCas"></param> /// <param name="count">������ʼ���</param> public static List<string[]> CatchArrayInfo(CassView curCass, ref int count) { List<string[]> Ainfos = new List<string[]>(); foreach (Control element in curCass.Controls) {//��ȡģ���ͽ����������Ϣ string MS = TypeDescriptor.GetProperties(element)["ModuleSort"].GetValue(element).ToString(); if (MS == "ģ��������") { string[] info = GenerateCode.GetFuzzyArray(curCass, element,ref count); Ainfos.Add(info); } else if (MS == "�����������") { List<string[]> tempInfos = GenerateCode.GetJieOuArray(curCass, element,ref count); foreach (string[] info in tempInfos) { Ainfos.Add(info); } } } return Ainfos; }
/// <summary> /// ���������ؼ���Ϣ���Ͻ��������뵽��������� /// </summary> /// <param name="GroupCtrl">δ�����һ���ؼ���</param> /// <returns>����һ���Ѿ�����Ŀؼ�����</returns> private ControlInfo[] OrderCtrlsNum(CassView curCas,List<ControlInfo> GroupCtrl, string pageName) { Stack<ControlInfo> TempStack = new Stack<ControlInfo>();//���������õ�����ʱ��ջ Stack<ControlInfo> OrderStack = new Stack<ControlInfo>();//�ѽ�������Ķ�ջ List<string> tempCode = new List<string>();//�Ե����ϱ���ʱ��˳������ʱ�����Ķ��� #region �ؼ�������� //�û������ߺ�ָ����ֻ������õ����������ؼ�Ŀ�� //�����������ӿڴ��ڣ��������Ӷ����������Ĭ��������ֵ����Ŀ�꣬������ʾ��ָ�����̬������ //���ṩ����λ��ʱ����ȫ��ʾ�������������Ŀ�� //��������ؼ�ʱ������Ƚ����ֵ��Ŀ���趨Ϊ��ʱ����������Ȼ���˳�����ȡ���ò������������� //������ؼ���������˳��Ϊ����20090608 //���������Ӧ������ʱ��ͬ��������ʱ���� //ͬһ�ؼ����ж������֧��û���ٻ�۵���������ݿؼ����������Ϻ��µĽ��з���20090805 #endregion #region ���� //����û��ܸĶ�ָ������ڿ�ֵ�����ƥ������ //�����������Ϣ�ж�����͵�����������������Ϣ�������� foreach (ControlInfo ElementCtrl in GroupCtrl) { if (CheckTipCtrl(ElementCtrl.OutputInfo)) {//β�˿ؼ�//δ������������ӵ�β�˿ؼ� ����NULL//��ʱ�ж�����ΪNULL������NULL TempStack.Push(ElementCtrl); } else if (ElementCtrl.OutputInfo.Count != 1 || ElementCtrl.OutputInfo[0][0].Split(',').Length != 1) {//������͵����������ؼ� for (int OPindex = 0; OPindex < ElementCtrl.OutputInfo.Count; OPindex++) { if (ElementCtrl.OutputInfo[OPindex][0] != null) { string[] tempArray = ElementCtrl.OutputInfo[OPindex][0].Split(','); //��ԭ�����Ϣ��ӣ��ؼ���_������� string tempOutInfo = null; if (ElementCtrl.CodeInfo[2] != null) { tempOutInfo = ElementCtrl.CodeInfo[2]; } else { tempOutInfo = ElementCtrl.CodeInfo[1]; } //������ʱ���� �ؼ���_�˿ں� tempOutInfo = //"configuration" + CassViewGenerator.ProjectNum + "_" + tempOutInfo + "_" + OPindex.ToString(); ElementCtrl.OutputInfo[OPindex][1] = tempOutInfo; //�ҵ�������ڶ�Ӧ�������,�������������Ϣ foreach (string IOinfo in tempArray) { for (int j = 0; j < GroupCtrl.Count; j++) { if (GroupCtrl[j].ControlName == IOinfo.Split('.')[0]) { GroupCtrl[j].InputInfo[Convert.ToInt32(IOinfo.Split('.')[1])][1] = tempOutInfo; break; } } } TempInfo.Add(tempOutInfo);//�����õ���ʱ�����������Ӧ���� } } } } if (GroupCtrl.Count != 0 && TempStack.Count == 0) { CassViewGenerator.SpecialErrors.Add(new string[] { null, "�����������·", "error", pageName }); ViewErrorinfo.Add(new string[] { pageName, null, "�����������·" }); } #region �Ե����Ͽؼ������㷨 if (TempStack.Count != 1) {//�ж��β�˿ؼ�ʱ��β�˿ؼ��������� TempStack = OrderEndCtrls(curCas,TempStack,GroupCtrl); } while (TempStack.Count != 0) { ControlInfo TopControl = TempStack.Pop(); GroupCtrl.Remove(TopControl);//��δ����ؼ�����ɾ����Ӧ�Ŀؼ���Ϣ //����ɾ�����������ٺ���������ͷ�ֹ������ؼ����ظ�ʹ�� //��ջ�������Ŀؼ���Ϣѹ���������ջ OrderStack.Push(TopControl); if (TopControl.ControlName != null && TopControl.InputInfo != null) {//����ؼ���ͷ�ؼ�(��������Ϣ)ֱ��ѹ�������ջ for (int x = 0; x < TopControl.InputInfo.Count; x++)//���Ҫ˳������Ҫ������� { string[] Input = TopControl.InputInfo[x]; if (TempInfo.Contains(Input[1])) {//�ؼ�������Ҫ����ʱ���� tempCode.Add(Input[1]); ControlInfo temp = new ControlInfo(); temp.ControlNum = -1;//����ؼ����ͳһΪ-1 temp.CodeInfo = new string[1]; temp.CodeInfo[0] = Input[1]; TempStack.Push(temp);//����ؼ�1 } else if (Input[0] != null) {//��ǰ������ؼ�ѹ���ջ for (int i = 0; i < GroupCtrl.Count; i++) { if (GroupCtrl[i].ControlName == Input[0].Split('.')[0]) { TempStack.Push(GroupCtrl[i]); break; } } } else if (Input[0] == null) {//�û����õ������//��Ҫ�ij�LDĬ�� ControlInfo temp = new ControlInfo(); if (Input[3] != null && Input[3] != "") { temp.ControlNum = -1;//����ؼ����ͳһΪ-1 temp.CodeInfo = new string[2] { Input[2], Input[3] }; TempStack.Push(temp);//����ؼ�2 } } } } if (TempStack.Count == 0 && GroupCtrl.Count != 0) {//���пؼ�û������,������Ϊ��ʱ������ԭ��ʹ��ջΪ�� for (int i = 0; i < GroupCtrl.Count; i++) {//��δ����ؼ������ҵ��Ѿ����Ա����õĿؼ�ѹ����ʱ��ջ if (TempInfo.Contains(GroupCtrl[i].OutputInfo[0][1]) || GroupCtrl[i].OutputInfo.Count != 1) { for (int j = 0; j < GroupCtrl[i].OutputInfo.Count; j++) { if (GroupCtrl[i].OutputInfo[j][0] != null && !tempCode.Contains(GroupCtrl[i].OutputInfo[j][1])) {//�����������ʹ�ù�����ʱ�����в����������� break; } if (j == GroupCtrl[i].OutputInfo.Count - 1) {//����������������Ҷ��Ѿ�ʹ�ù� TempStack.Push(GroupCtrl[i]); } } } } } } #endregion #endregion return OrderStack.ToArray(); }
/// <summary> /// ��Cassview�еĿؼ����д�������� /// </summary> /// <param name="curCas">��Ҫ�����cassview</param> /// <param name="pageName">cassviewҳ�������</param> /// <returns></returns> public List<string[]> PackOrderCtrl(CassView curCas, string[] pageNameInfo) { List<ControlInfo[]> CassInfo = new List<ControlInfo[]>(); List<List<ControlInfo>> alreadyPack = PackCtrls(curCas, pageNameInfo[0]); string pageName = getMark(pageNameInfo); foreach (List<ControlInfo> pack in alreadyPack) { //�Կؼ��������� CassInfo.Add(OrderCtrlsNum(curCas,pack,pageNameInfo[0])); } return OrderPacksNum(curCas, CassInfo, pageName); }
/// <summary> /// ��������ؼ���Ϣ���������Ե�������������������Ϣ /// </summary> /// <param name="curCas">�ؼ�����CASSVIEW����</param> /// <param name="curCtrl">�ؼ�</param> /// <param name="ArrayCount">��ǰ���õ����б��</param> /// <returns>������Ϣ</returns> public static List<string[]> GetJieOuArray(CassView curCas, Control curCtrl,ref int ArrayCount) { List<string[]> ArrayInfos = new List<string[]>();//������Ϣ���� int count = 2;//����·�� //������������Ҫ������������� List<string> NeedAddArray = new List<string>(new string[] { "����", "����", "��", "�趨ֵ", "�Զ�/�ֶ�", "����������", "����������", "���������", "�������IJ���" }); PropertyDescriptor configurationProperty = TypeDescriptor.GetProperties(curCtrl)["Configuration"]; ControlTactic.SpecialControl.JieOu ConvertTool = new ControlTactic.SpecialControl.JieOu(); ControlTactic.SpecialControl.JieOuStruct tempStruct = ConvertTool.ListToStruct((List<string>)configurationProperty.GetValue(curCtrl)); ControlInfo JieOu = curCas.FindControlInfo(curCtrl); for (int i = 0; i < JieOu.VisibleFunctionProperty.Count; i++) {//�ڿ����������ҵ����������и�ֵ if (JieOu.VisibleFunctionProperty[i].Name == "����·��") { JieOu.VisibleFunctionProperty[i].TheValue = tempStruct.JieOuNum; count = tempStruct.JieOuNum; break; } } //����Ϊ���������֡��֡��趨ֵ���Զ��ֶ������������ޡ����������ޡ�������������� List<string>[] Attributes = new List<string>[] { new List<string>(), new List<string>(), new List<string>(), new List<string>(), new List<string>(), new List<string>(), new List<string>(), new List<string>() }; foreach (List<string> attribute in tempStruct.JieOuAttribute) {//ÿ������ �����ɱ��������֡��֡��趨ֵ���Զ��ֶ������������ޡ����������ޡ������������� Attributes[0].Add(attribute[0]); Attributes[1].Add(attribute[1]); Attributes[2].Add(attribute[2]); Attributes[3].Add(attribute[3]); Attributes[4].Add(new List<string>(new string[] { "�Զ�", "�ֶ�" }).IndexOf(attribute[4]).ToString());//�Զ��ֶ���� Attributes[5].Add(attribute[5]); Attributes[6].Add(attribute[6]); Attributes[7].Add(attribute[7]); } for (int i = 0; i < JieOu.UnvisibleFunctionProperty.Count; i++) { int index = NeedAddArray.IndexOf(JieOu.UnvisibleFunctionProperty[i].Name); if (index != -1) {//ArrayInfo˳������Ϊ�ؼ�PortName������VarName�����͡������������ȡ����� List<string> ArrayInfo = new List<string>(); JieOu.UnvisibleFunctionProperty[i].TheValue = "configuration" + CassViewGenerator.ProjectNum + "_array" + (ArrayCount++).ToString(); ArrayInfo.Add(JieOu.CodeInfo[2]); ArrayInfo.Add(JieOu.UnvisibleFunctionProperty[i].Name); ArrayInfo.Add("fp32"); ArrayInfo.Add(JieOu.UnvisibleFunctionProperty[i].TheValue.ToString()); if (index == 8) { List<string> tempArray = new List<string>(); foreach (string element in tempStruct.JieOuTable) { tempArray.Add(element); } ArrayInfo.Add(tempArray.Count.ToString()); ArrayInfo.Add(String.Join(",", tempArray.ToArray())); } else { ArrayInfo.Add(Attributes[index].Count.ToString()); ArrayInfo.Add(String.Join(",", Attributes[index].ToArray())); } if (index == 4) {//�Զ�/�ֶ�Ϊchar�� ArrayInfo[2] = "uint8"; } ArrayInfo.Add(JieOu.UnvisibleFunctionProperty[i].VarName); ArrayInfos.Add(ArrayInfo.ToArray()); } else if (JOUnuseArray.Contains(JieOu.UnvisibleFunctionProperty[i].Name)) {//��ʹ�õ����鸳ֵ JieOu.UnvisibleFunctionProperty[i].TheValue = "configuration" + CassViewGenerator.ProjectNum + "_array" + (ArrayCount++).ToString(); List<string> tempValue = new List<string>();//���ɽ���·����ȫ0���� for (int k = 0; k < count; k++) { tempValue.Add("0"); } UnseeArray.Add(new string[] { null, null, "fp32", JieOu.UnvisibleFunctionProperty[i].TheValue.ToString(), count.ToString(), String.Join(",", tempValue.ToArray()) }); } } return ArrayInfos; }
/// <summary> /// ����ģ���ؼ���Ϣ���������Ե�������������������Ϣ /// </summary> /// <param name="curCas">�ؼ�����CASSVIEW����</param> /// <param name="curCtrl">�ؼ�</param> /// <param name="ArrayCount">��ǰ���õ����б��</param> /// <returns>������Ϣ</returns> public static string[] GetFuzzyArray(CassView curCas, Control curCtrl, ref int ArrayCount) { List<string> ArrayInfo = new List<string>(); PropertyDescriptor configurationProperty = TypeDescriptor.GetProperties(curCtrl)["Configuration"]; ControlTactic.SpecialControl.Fuzzy ConvertTool = new ControlTactic.SpecialControl.Fuzzy(); ControlTactic.SpecialControl.FuzzyStruct tempStruct = ConvertTool.ListToStruct((List<string>)configurationProperty.GetValue(curCtrl)); ControlInfo Fuzzy = curCas.FindControlInfo(curCtrl); string tempArray = null; for (int row = 0; row < tempStruct.RowNum * 2 + 1; row++) { for (int column = 0; column < tempStruct.ColumnNum * 2 + 1; column++) { tempArray += tempStruct.ControlTable[row, column]; if (row != tempStruct.RowNum * 2 || column != tempStruct.ColumnNum * 2) { tempArray += ","; } } if (row != tempStruct.RowNum - 1) { //tempArray += "\n";//ȥ��ÿ�лس����� �����¶�ȡ��ַ�����BUG20090622 } } //����ģ�����Ʊ����������ڵ� for (int i = 0; i < Fuzzy.UnvisibleFunctionProperty.Count; i++) { if (Fuzzy.UnvisibleFunctionProperty[i].Name == "ģ�����Ʊ�") {//ArrayInfo˳������Ϊ�ؼ�PortName������VarName�����͡������������ȡ����� Fuzzy.UnvisibleFunctionProperty[i].TheValue = "configuration" + CassViewGenerator.ProjectNum + "_array" + (ArrayCount++).ToString(); ArrayInfo.Add(Fuzzy.CodeInfo[2]); ArrayInfo.Add(Fuzzy.UnvisibleFunctionProperty[i].Name); ArrayInfo.Add("fp32"); ArrayInfo.Add(Fuzzy.UnvisibleFunctionProperty[i].TheValue.ToString()); ArrayInfo.Add(tempStruct.ControlTable.Length.ToString()); ArrayInfo.Add(tempArray); ArrayInfo.Add(Fuzzy.UnvisibleFunctionProperty[i].VarName); } } return ArrayInfo.ToArray(); }
private void OperateDoing(ref Operation Opt) { switch (Opt.Oname) { case "比例放大": { cassview.Scaling = Convert.ToSingle(Opt.Change[1]); break; } case "比例缩小": { cassview.Scaling = Convert.ToSingle(Opt.Change[1]); break; } case "控件删除": { for (int i = 0; i < cassview.Controls.Count; i++) { if (cassview.Controls[i].Site.Name == ((Control)Opt.Item).Tag.ToString()) { cassview.Controls.RemoveAt(i); break; } } break; } case "控件添加": { CreateControl(ref Opt); cassview.Controls.Add((Control)Opt.Item); cassview.ctrlsInfo.Add((ControlInfo)Opt.Change[2]); cassview.blocksInfo.Add((BlockInfo)Opt.Change[3]); if (Opt.Change.Length > 4) { for (int i = 4; i < Opt.Change.Length; i++) { Opt.Change[i] = AddnewLine((LineInfo)Opt.Change[i]); } } cassview.portReflash(); cassview.DrawBackgroundImage(); break; } case "控件移动": { BlockInfo tempBinfo = (BlockInfo)Opt.Change[1]; for (int i = 0; i < cassview.blocksInfo.Count; i++) { int x = cassview.Controls.Count; if (cassview.blocksInfo[i].BlockNum == ((BlockInfo)Opt.Change[0]).BlockNum) { foreach (Control element in cassview.Controls) { PropertyDescriptor Number = TypeDescriptor.GetProperties(element)["SerialNumber"]; if (Number != null && Number.GetValue(element).ToString() == cassview.blocksInfo[i].BlockNum.ToString()) { element.Location = new Point(tempBinfo.StartPoint.X + 5, tempBinfo.StartPoint.Y + 5); Opt.Item = element; break; } } } } break; } case "控件置前": { ((Control)Opt.Item).BringToFront(); break; } case "控件置后": { ((Control)Opt.Item).SendToBack(); break; } case "直线删除": { cassview.DeleteLine(GetLineinfoNum((LineInfo)Opt.Item), true); break; } case "直线添加": { Opt.Item = AddnewLine((LineInfo)Opt.Item); break; } case "属性修改": { if (Opt.Change[0].ToString() == "模块点名") { foreach (Control element in cassview.Controls) { if (element.Tag.ToString() == ((Control)Opt.Item).Tag.ToString()) { //找到删除后新建的控件 Opt.Item = element; break; } } string Cmname = TypeDescriptor.GetProperties((Control)Opt.Item)["ModuleName"].GetValue((Control)Opt.Item).ToString(); //当前控件模块名 CassView.ModifyPortName(Cmname, Opt.Change[1].ToString(), Opt.Change[2].ToString()); PropertyDescriptor portNameProperty = TypeDescriptor.GetProperties((Control)Opt.Item)["PortName"]; cassview.FindControlInfo((Control)Opt.Item).CodeInfo[2] = Cmname + Opt.Change[2].ToString(); portNameProperty.SetValue((Control)Opt.Item, Cmname + Opt.Change[2].ToString()); for (int i = 0; i < cassview.ctrlsInfo.Count; i++) { if (cassview.ctrlsInfo[i].ControlName == ((Control)Opt.Item).Site.Name && cassview.ctrlsInfo[i].VisibleFunctionProperty != null) { for (int j = 0; j < cassview.ctrlsInfo[i].VisibleFunctionProperty.Count; j++) { if (cassview.ctrlsInfo[i].VisibleFunctionProperty[j].Name == "模块点名") { cassview.ctrlsInfo[i].VisibleFunctionProperty[j].TheValue = Opt.Change[2]; } } break; } } } else { CassViewGenerator.SpecialValueChange(cassview, (Control)Opt.Item, Opt.Change[0].ToString(), Opt.Change[1], Opt.Change[2]); CassViewGenerator.SetCodeInfo(cassview, (Control)Opt.Item, Opt.Change[0].ToString(), Opt.Change[2].ToString()); } break; } } }
/// <summary> /// ��������XML�е������ؼ���Ϣ /// </summary> public static void ClearCtrlsInfo(CassView casv) { for (int i = casv.ctrlsInfo.Count - 1; i >= 0; i--) { if (casv.ctrlsInfo[i].ControlNum == -1) {//����ؼ����ͳһΪ-1 casv.ctrlsInfo.RemoveAt(i); } } }
/// <summary> /// ��ҳ��cassviewΪ��λ���пؼ���������� /// �������ؼ�������ؼ�����������б���ؼ�JMP��Ҫ��Ϣ�� /// �Լ�����ָ����б�Ϳؼ���������ƥ��� /// </summary> /// <param name="alreadyOrderInfo">������Ŀؼ�������</param> /// <param name="pageName">��ǰCASSVIEW��ҳ����</param> /// <returns></returns> private List<string[]> OrderPacksNum(CassView curCas, List<ControlInfo[]> alreadyOrderInfo, string pageName) { List<Point> OrderPoint = new List<Point>();//���ÿ���ؼ���������Сֵ,��Ϊ�ؼ������������� List<ControlInfo[]> OrderPack = new List<ControlInfo[]>();//�ؼ�������������б� List<string> Indexs = new List<string>();//ÿ���ؼ��Ŀؼ�������� List<string> PackName = new List<string>();//�ؼ������ļ��� GenerateCode.CtrlsList.Clear(); for (int Pindex = 0; Pindex < alreadyOrderInfo.Count; Pindex++) { List<string> CnumList = new List<string>();//ÿ���ؼ���ż��� Point minP = new Point(1200, 1000);//ÿ���ؼ���С���� //��һ����ȷ���ؼ����� //����ҳ��û��0������ if (Pindex == 0) { PackName.Add(pageName); } else { PackName.Add(pageName + Pindex.ToString());//����ҳ����+���������Ϊ���� } //�ڶ������ҵ�ÿ���ؼ���������Сֵ���ɴ˽��пؼ��������� for (int Cindex = 0; Cindex < alreadyOrderInfo[Pindex].Length; Cindex++) { if (alreadyOrderInfo[Pindex][Cindex].ControlNum != -1) { CnumList.Add(alreadyOrderInfo[Pindex][Cindex].ControlNum.ToString()); Point CurP = curCas.FindBlockInfo(alreadyOrderInfo[Pindex][Cindex]).StartPoint; if (CurP != new Point() && (CurP.Y < minP.Y || (CurP.Y == minP.Y && CurP.X < minP.X))) {//ȡYֵС�ĵ㣬��Y��ͬ��ȡX��ͬ�ĵ� minP = CurP; } } } //2014.1.15 // GenerateCode.ctrlsNum = CnumList; GenerateCode.CtrlsList.Add(CnumList); ////����ί�� //if (CnumList != null) //{ // this.myDeleSendCtrlsNum(CnumList); //} if (OrderPoint.Count == 0 || minP.Y > OrderPoint[OrderPoint.Count - 1].Y || (minP.Y == OrderPoint[OrderPoint.Count - 1].Y && minP.X >= OrderPoint[OrderPoint.Count - 1].X)) {//������Ϊ�� �� Yֵ���ڼ���βԪ��Y �� Y��ͬXֵ���ڵ��ڼ���βԪ��X OrderPoint.Add(minP); OrderPack.Add(alreadyOrderInfo[Pindex]); Indexs.Add(String.Join(",", CnumList.ToArray())); } else { for (int Gindex = 0; Gindex < OrderPoint.Count; Gindex++) { if (minP.Y < OrderPoint[Gindex].Y || (minP.Y == OrderPoint[Gindex].Y && minP.X < OrderPoint[Gindex].X)) {//�������� YֵС�ڵ�ǰ��Y �� Yֵ��ͬXС�ڵ�ǰ��X OrderPoint.Insert(Gindex, minP); OrderPack.Insert(Gindex, alreadyOrderInfo[Pindex]); Indexs.Insert(Gindex, String.Join(",", CnumList.ToArray())); break; } } } } //�������ֽ������Ŀؼ�����������봮���������� if (Indexs.Count == PackName.Count) { for (int i = 0; i < Indexs.Count; i++) { PackInfos.Add(new string[] { PackName[i], Indexs[i] }); } } //���IJ��ֽ��ؼ�����������������ɵ�ָ������������ϲ����� return InsertPackName(CreateCodeList(OrderPack), PackName); }
/// <summary> /// 逆向遍历找到尾端控件所关联的断层处(多输出)的连接口控件坐标 /// 以此为依据进行排序 /// </summary> /// <param name="endCtrls"></param> /// <returns></returns> private Stack <ControlInfo> OrderEndCtrls(CassView curCas, Stack <ControlInfo> endCtrls, List <ControlInfo> GroupCtrl) { List <ControlInfo> orderList = new List <ControlInfo>(); //控件排序用队列 List <Point> orderP = new List <Point>(); //点坐标排序队列 Stack <ControlInfo> returnStack = new Stack <ControlInfo>(); //返回用堆栈 foreach (ControlInfo ctrl in endCtrls) { Stack <ControlInfo> Findctrls = new Stack <ControlInfo>(); Findctrls.Push(ctrl); bool findPoint = false; while (!findPoint) { ControlInfo Topctrl = Findctrls.Pop(); for (int x = Topctrl.InputInfo.Count - 1; x >= 0; x--) {//逆向遍历上端口优先于下端口 string[] Input = Topctrl.InputInfo[x]; if (TempInfo.Contains(Input[1])) {//出现临时变量找到断层跳出循环 findPoint = true; //依据点的坐标以Y大的优先,Y相同X大的优先排序 Point sp = curCas.FindBlockInfo(Topctrl).StartPoint; if (orderList.Count == 0) { orderList.Add(ctrl); orderP.Add(sp); } else { for (int y = 0; y < orderP.Count; y++) { if (orderP[y].Y > sp.Y || (orderP[y].Y == sp.Y && orderP[y].X > sp.X)) { orderP.Insert(y, sp); orderList.Insert(y, ctrl); break; } if (y == orderList.Count - 1) { orderList.Add(ctrl); orderP.Add(sp); break; } } } break; } else if (Input[0] != null) {//将前级输出控件压入堆栈 for (int i = 0; i < GroupCtrl.Count; i++) { if (GroupCtrl[i].ControlName == Input[0].Split('.')[0]) { Findctrls.Push(GroupCtrl[i]); break; } } } } } } foreach (ControlInfo element in orderList) {//将排序末端控件压入返回堆栈 栈顶控件为Y最小X最小控件 returnStack.Push(element); } return(returnStack); }
/// <summary> /// 根据所给控件信息集合进行由输入到输出的排序 /// </summary> /// <param name="GroupCtrl">未排序的一个控件组</param> /// <returns>返回一个已经排序的控件集合</returns> private ControlInfo[] OrderCtrlsNum(CassView curCas, List <ControlInfo> GroupCtrl, string pageName) { Stack <ControlInfo> TempStack = new Stack <ControlInfo>(); //排序中所用到的临时堆栈 Stack <ControlInfo> OrderStack = new Stack <ControlInfo>(); //已进行排序的堆栈 List <string> tempCode = new List <string>(); //自底向上遍历时按顺序存放临时变量的队列 #region 控件排序规则 //用户在连线和指令中只需关心用到的输出输入控件目标 //当输入或输入接口存在,但无连接对象则程序中默认有输入值输入目标,并不显示在指令和组态操作中 //在提供给下位机时会完全显示数据流向和数据目标 //当多输出控件时则必须先将输出值的目标设定为临时变量,(当然如果顺序不错,可取消该操作(待定)) //多输出控件输出翻译的顺序为逆向20090608 //当单输出对应多输入时,同样采用临时变量 //同一控件串中多输出分支后没有再汇聚的情况下依据控件的坐标先上后下的进行翻译20090805 #endregion #region 排序方法 //如果用户能改动指令则对于空值会出现匹配问题 //将输入输出信息中多输出和单输出多输入两情况信息进行修正 foreach (ControlInfo ElementCtrl in GroupCtrl) { if (CheckTipCtrl(ElementCtrl.OutputInfo)) {//尾端控件//未处理非正常连接的尾端控件 两个NULL//暂时判断条件为NULL或所有NULL TempStack.Push(ElementCtrl); } else if (ElementCtrl.OutputInfo.Count != 1 || ElementCtrl.OutputInfo[0][0].Split(',').Length != 1) {//多输出和单输出多输入控件 for (int OPindex = 0; OPindex < ElementCtrl.OutputInfo.Count; OPindex++) { if (ElementCtrl.OutputInfo[OPindex][0] != null) { string[] tempArray = ElementCtrl.OutputInfo[OPindex][0].Split(','); //把原输出信息添加:控件名_出口序号 string tempOutInfo = null; if (ElementCtrl.CodeInfo[2] != null) { tempOutInfo = ElementCtrl.CodeInfo[2]; } else { tempOutInfo = ElementCtrl.CodeInfo[1]; } //创建临时变量 控件名_端口号 tempOutInfo = //"configuration" + CassViewGenerator.ProjectNum + "_" + tempOutInfo + "_" + OPindex.ToString(); ElementCtrl.OutputInfo[OPindex][1] = tempOutInfo; //找到该输出口对应的输入口,并修改其输入口信息 foreach (string IOinfo in tempArray) { for (int j = 0; j < GroupCtrl.Count; j++) { if (GroupCtrl[j].ControlName == IOinfo.Split('.')[0]) { GroupCtrl[j].InputInfo[Convert.ToInt32(IOinfo.Split('.')[1])][1] = tempOutInfo; break; } } } TempInfo.Add(tempOutInfo);//将所用的临时变量名加入对应队列 } } } } if (GroupCtrl.Count != 0 && TempStack.Count == 0) { CassViewGenerator.SpecialErrors.Add(new string[] { null, "出现无输出回路", "error", pageName }); ViewErrorinfo.Add(new string[] { pageName, null, "出现无输出回路" }); } #region 自底向上控件排序算法 if (TempStack.Count != 1) {//有多个尾端控件时对尾端控件进行排序 TempStack = OrderEndCtrls(curCas, TempStack, GroupCtrl); } while (TempStack.Count != 0) { ControlInfo TopControl = TempStack.Pop(); GroupCtrl.Remove(TopControl);//从未排序控件组中删除对应的控件信息 //必须删除,用来减少后面计算量和防止多输出控件的重复使用 //将栈顶弹出的控件信息压入已排序堆栈 OrderStack.Push(TopControl); if (TopControl.ControlName != null && TopControl.InputInfo != null) { //虚拟控件或头控件(无输入信息)直接压入排序堆栈 for (int x = 0; x < TopControl.InputInfo.Count; x++) //如果要顺序,则需要逆向遍历 { string[] Input = TopControl.InputInfo[x]; if (TempInfo.Contains(Input[1])) {//控件输入需要的临时变量 tempCode.Add(Input[1]); ControlInfo temp = new ControlInfo(); temp.ControlNum = -1;//虚拟控件序号统一为-1 temp.CodeInfo = new string[1]; temp.CodeInfo[0] = Input[1]; TempStack.Push(temp);//虚拟控件1 } else if (Input[0] != null) {//将前级输出控件压入堆栈 for (int i = 0; i < GroupCtrl.Count; i++) { if (GroupCtrl[i].ControlName == Input[0].Split('.')[0]) { TempStack.Push(GroupCtrl[i]); break; } } } else if (Input[0] == null) {//用户不用的输入口//需要改成LD默认 ControlInfo temp = new ControlInfo(); if (Input[3] != null && Input[3] != "") { temp.ControlNum = -1;//虚拟控件序号统一为-1 temp.CodeInfo = new string[2] { Input[2], Input[3] }; TempStack.Push(temp);//虚拟控件2 } } } } if (TempStack.Count == 0 && GroupCtrl.Count != 0) { //还有控件没有排序,但是因为临时变量的原因使堆栈为空 for (int i = 0; i < GroupCtrl.Count; i++) { //在未排序控件组中找到已经可以被调用的控件压入临时堆栈 if (TempInfo.Contains(GroupCtrl[i].OutputInfo[0][1]) || GroupCtrl[i].OutputInfo.Count != 1) { for (int j = 0; j < GroupCtrl[i].OutputInfo.Count; j++) { if (GroupCtrl[i].OutputInfo[j][0] != null && !tempCode.Contains(GroupCtrl[i].OutputInfo[j][1])) {//有输出对象且使用过的临时变量中不存在则跳出 break; } if (j == GroupCtrl[i].OutputInfo.Count - 1) {//遍历完所有输出口且都已经使用过 TempStack.Push(GroupCtrl[i]); } } } } } } #endregion #endregion return(OrderStack.ToArray()); }
/// <summary> /// 遍历curtcass下所有控件信息根据连接情况将其分块 /// </summary> /// <param name="curtcass">需要处理的Cassview</param> /// <param name="pageName">当前Cassview的页名</param> /// <returns>已分块好的控件信息组</returns> private List <List <ControlInfo> > PackCtrls(CassView curtcass, string pageName) { List <List <ControlInfo> > GroupCtrls = new List <List <ControlInfo> >(); List <string> UseCtrl = new List <string>();//保存已经使用过的控件名称 ////////////////////////////////////////////////////////////////////////////////需优化 foreach (ControlInfo ctrl in curtcass.ctrlsInfo) { if (UseCtrl.Contains(ctrl.ControlName)) { continue; } else if (ctrl.IsConnect) { //该控件是连接控件且没有被其他控件组容纳 Stack <ControlInfo> tempStack = new Stack <ControlInfo>(); //用于存放当前控件信息的相连接的控件信息的中转用堆栈 List <ControlInfo> Pack = new List <ControlInfo>(); //当前控件压入临时堆栈 tempStack.Push(ctrl); UseCtrl.Add(ctrl.ControlName); while (tempStack.Count != 0) { //取出栈顶控件 ControlInfo TopCtrl = tempStack.Pop(); //并将该控件所连接的且非遍历过的控件压入堆栈 if (TopCtrl.OutputInfo != null) { if (TopCtrl.OutputInfo.Count == 1 && TopCtrl.OutputInfo[0][0] != null && TopCtrl.OutputInfo[0][0].Split(',').Length == 1) {//单输出对应单输入情况 ControlInfo ConnectCtrl = curtcass.ctrlsInfo[curtcass.FindControlName(TopCtrl.OutputInfo[0][0].Split('.')[0])]; if (!UseCtrl.Contains(ConnectCtrl.ControlName)) { tempStack.Push(ConnectCtrl); UseCtrl.Add(ConnectCtrl.ControlName); } } else {//单输出对应多输入或则多输出情况 for (int i = TopCtrl.OutputInfo.Count - 1; i >= 0; i--) { if (TopCtrl.OutputInfo[i][0] != null) { string[] OputArray = TopCtrl.OutputInfo[i][0].Split(',');//一输出口对应多个控件以逗号分隔 for (int j = 0; j < OputArray.Length; j++) { ControlInfo ConnectCtrl = curtcass.ctrlsInfo[curtcass.FindControlName(OputArray[j].Split('.')[0])]; if (!UseCtrl.Contains(ConnectCtrl.ControlName)) { tempStack.Push(ConnectCtrl); UseCtrl.Add(ConnectCtrl.ControlName); } } } } } } if (TopCtrl.InputInfo != null) { for (int j = TopCtrl.InputInfo.Count - 1; j >= 0; j--) { if (TopCtrl.InputInfo[j][0] != null) { ControlInfo ConnectCtrl = curtcass.ctrlsInfo[curtcass.FindControlName(TopCtrl.InputInfo[j][0].Split('.')[0])]; if (!UseCtrl.Contains(ConnectCtrl.ControlName)) { tempStack.Push(ConnectCtrl); UseCtrl.Add(ConnectCtrl.ControlName); } } } } //将栈顶控件转入新的控件组 Pack.Add(TopCtrl); } GroupCtrls.Add(Pack); } if (!ctrl.IsConnect) { string warningInfo = "控件序号为" + ctrl.ControlNum.ToString() + "的" + ctrl.CodeInfo[0] + "控件没有连接"; CassViewGenerator.SpecialErrors.Add(new string[] { null, warningInfo, "warning", pageName }); ViewErrorinfo.Add(new string[] { pageName, ctrl.ControlNum.ToString(), warningInfo }); } } return(GroupCtrls); }
/// <summary> /// 以页面cassview为单位进行控件串间的排序 /// 并产生控件串名与控件串序号整合列表(控件JMP需要信息) /// 以及生成指令表列表和控件串名进行匹配后返回 /// </summary> /// <param name="alreadyOrderInfo">待排序的控件串集合</param> /// <param name="pageName">当前CASSVIEW的页面名</param> /// <returns></returns> private List <string[]> OrderPacksNum(CassView curCas, List <ControlInfo[]> alreadyOrderInfo, string pageName) { List <Point> OrderPoint = new List <Point>(); //存放每串控件中坐标最小值,作为控件串间排序依据 List <ControlInfo[]> OrderPack = new List <ControlInfo[]>(); //控件串间排序后存放列表 List <string> Indexs = new List <string>(); //每串控件的控件序号序列 List <string> PackName = new List <string>(); //控件串名的集合 for (int Pindex = 0; Pindex < alreadyOrderInfo.Count; Pindex++) { List <string> CnumList = new List <string>(); //每串控件序号集合 Point minP = new Point(1200, 1000); //每串控件最小坐标 //第一部分确定控件串名 //所有页面没有0块命名 if (Pindex == 0) { PackName.Add(pageName); } else { PackName.Add(pageName + Pindex.ToString());//所在页面名+数字序号作为块名 } //第二部分找到每串控件中坐标最小值并由此进行控件串间排序 for (int Cindex = 0; Cindex < alreadyOrderInfo[Pindex].Length; Cindex++) { if (alreadyOrderInfo[Pindex][Cindex].ControlNum != -1) { CnumList.Add(alreadyOrderInfo[Pindex][Cindex].ControlNum.ToString()); Point CurP = curCas.FindBlockInfo(alreadyOrderInfo[Pindex][Cindex]).StartPoint; if (CurP != new Point() && (CurP.Y < minP.Y || (CurP.Y == minP.Y && CurP.X < minP.X))) {//取Y值小的点,当Y相同则取X相同的点 minP = CurP; } } } if (OrderPoint.Count == 0 || minP.Y > OrderPoint[OrderPoint.Count - 1].Y || (minP.Y == OrderPoint[OrderPoint.Count - 1].Y && minP.X >= OrderPoint[OrderPoint.Count - 1].X)) {//点排序集合为空 或 Y值大于集合尾元素Y 或 Y相同X值大于等于集合尾元素X OrderPoint.Add(minP); OrderPack.Add(alreadyOrderInfo[Pindex]); Indexs.Add(String.Join(",", CnumList.ToArray())); } else { for (int Gindex = 0; Gindex < OrderPoint.Count; Gindex++) { if (minP.Y < OrderPoint[Gindex].Y || (minP.Y == OrderPoint[Gindex].Y && minP.X < OrderPoint[Gindex].X)) {//插入条件 Y值小于当前点Y 或 Y值相同X小于当前点X OrderPoint.Insert(Gindex, minP); OrderPack.Insert(Gindex, alreadyOrderInfo[Pindex]); Indexs.Insert(Gindex, String.Join(",", CnumList.ToArray())); break; } } } } //第三部分将产生的控件串序号依次与串名进行整合 if (Indexs.Count == PackName.Count) { for (int i = 0; i < Indexs.Count; i++) { PackInfos.Add(new string[] { PackName[i], Indexs[i] }); } } //第四部分将控件串名与排序完后生成的指令数组进行整合并返回 return(InsertPackName(CreateCodeList(OrderPack), PackName)); }
/// <summary> /// ������������̬�ڵ� /// </summary> /// <param name="curCas">�ؼ�����CASSVIEW����</param> /// <param name="curCtrl">�ؼ�</param> /// <returns>�ڵ�</returns> private XmlNode CreateCalculator(CassView curCas, Control curCtrl) { PropertyDescriptor configurationProperty = TypeDescriptor.GetProperties(curCtrl)["Configuration"]; ControlTactic.SpecialControl.Calculator ConvertTool = new ControlTactic.SpecialControl.Calculator(); List<List<string>> tempvalue = (List<List<string>>)configurationProperty.GetValue(curCtrl); XmlElement Calculator = document.CreateElement("Calculator"); ControlInfo currentCtrl = curCas.FindControlInfo(curCtrl); Calculator.SetAttribute("name", currentCtrl.CodeInfo[2]); if (tempvalue.Count != 0) { Calculator.SetAttribute("name", currentCtrl.CodeInfo[2]); foreach (List<string> express in tempvalue) { if (express[0] != null || express[1] != null || express[2] != null) { XmlElement newItem = document.CreateElement("item"); if (express[0] != null) { XmlElement condition = document.CreateElement("condition"); condition.InnerText = ChangeExpress(express[0], currentCtrl.CodeInfo[2]); newItem.AppendChild(condition); } if (express[1] != null && express[2] != null) { XmlElement expression = document.CreateElement("expression"); expression.InnerText = ChangeExpress(express[2] + "=" + express[1], currentCtrl.CodeInfo[2]); newItem.AppendChild(expression); } Calculator.AppendChild(newItem); } } } else { } return Calculator; }
public UndoOperation(TabPage curPage) { this.cassview = (CassView)(curPage.Controls[0].GetNextControl(curPage.Controls[0], false)); }
/// <summary> /// 处理解耦和模糊控件的组态属性修改 /// </summary> /// <param name="cassView"></param> /// <param name="control"></param> /// <param name="ChangeItem"></param> /// <param name="OldValue"></param> /// <param name="ChangeValue"></param> public static void SpecialValueChange(CassView cassView, Control control, string ChangeItem, object OldValue, object ChangeValue) { if (ChangeItem == "解耦路数") {//当修改解耦路数时修改组态属性对应的所有信息20090610 ModifyCLinfo(cassView, control, Convert.ToInt32(OldValue), Convert.ToInt32(ChangeValue)); } else if (ChangeItem == "解耦控制组态") {//对解耦路数赋值 ControlInfo JieOu = cassView.FindControlInfo(control); for (int i = 0; i < JieOu.VisibleFunctionProperty.Count; i++) { if (JieOu.VisibleFunctionProperty[i].Name == "解耦路数") {//解耦中可视属性第一个即序号[0]为解耦路数 ModifyCLinfo(cassView, control, Convert.ToInt32(JieOu.VisibleFunctionProperty[i].TheValue), Convert.ToInt32(((List<string>)ChangeValue)[0])); JieOu.VisibleFunctionProperty[i].TheValue = ((List<string>)ChangeValue)[0]; break; } } } if (ChangeItem == "偏差模糊论域" || ChangeItem == "偏差变化率模糊论域") {//当修改模糊论域时修改组态属性对应的所有信息20090708 SetFzConfigInfo(control, ChangeItem, Convert.ToInt32(OldValue), Convert.ToInt32(ChangeValue)); } else if (ChangeItem == "模糊控制表") { ControlInfo Fuzzy = cassView.FindControlInfo(control); for (int i = 0; i < Fuzzy.VisibleFunctionProperty.Count; i++) { if (Fuzzy.VisibleFunctionProperty[i].Name == "偏差模糊论域") {//更新不可见属性中的模糊论域(值为行数/2,位置为不可见属性第[1]位) Fuzzy.VisibleFunctionProperty[i].TheValue = ((List<string>)ChangeValue)[0]; } else if (Fuzzy.VisibleFunctionProperty[i].Name == "偏差变化率模糊论域") {//模糊变化域(值为列数/2,位置为不可见属性第[2]位)20090611 Fuzzy.VisibleFunctionProperty[i].TheValue = ((List<string>)ChangeValue)[1]; } } } }
/// <summary> /// ��������ҵ�β�˿ؼ��������Ķϲ㴦��������������ӿڿؼ����� /// �Դ�Ϊ���ݽ������� /// </summary> /// <param name="endCtrls"></param> /// <returns></returns> private Stack<ControlInfo> OrderEndCtrls(CassView curCas, Stack<ControlInfo> endCtrls, List<ControlInfo> GroupCtrl) { List<ControlInfo> orderList = new List<ControlInfo>();//�ؼ������ö��� List<Point> orderP = new List<Point>();//������������� Stack<ControlInfo> returnStack = new Stack<ControlInfo>();//�����ö�ջ foreach (ControlInfo ctrl in endCtrls) { Stack<ControlInfo> Findctrls = new Stack<ControlInfo>(); Findctrls.Push(ctrl); bool findPoint = false; while (!findPoint) { ControlInfo Topctrl = Findctrls.Pop(); for (int x = Topctrl.InputInfo.Count - 1; x >= 0; x--) {//��������϶˿��������¶˿� string[] Input = Topctrl.InputInfo[x]; if (TempInfo.Contains(Input[1])) {//������ʱ�����ҵ��ϲ�����ѭ�� findPoint = true; //���ݵ��������Y������ȣ�Y��ͬX����������� Point sp = curCas.FindBlockInfo(Topctrl).StartPoint; if (orderList.Count == 0) { orderList.Add(ctrl); orderP.Add(sp); } else { for (int y = 0; y < orderP.Count; y++) { if (orderP[y].Y > sp.Y || (orderP[y].Y == sp.Y && orderP[y].X > sp.X)) { orderP.Insert(y, sp); orderList.Insert(y, ctrl); break; } if (y == orderList.Count - 1) { orderList.Add(ctrl); orderP.Add(sp); break; } } } break; } else if (Input[0] != null) {//��ǰ������ؼ�ѹ���ջ for (int i = 0; i < GroupCtrl.Count; i++) { if (GroupCtrl[i].ControlName == Input[0].Split('.')[0]) { Findctrls.Push(GroupCtrl[i]); break; } } } } } } foreach (ControlInfo element in orderList) {//������ĩ�˿ؼ�ѹ�뷵�ض�ջ ջ���ؼ�ΪY��СX��С�ؼ� returnStack.Push(element); } return returnStack; }
/// <summary> /// 修改解耦路数时需要对应修改解耦控件相关的信息 /// </summary> /// <param name="cassView">控件所在容器</param> /// <param name="control">控件</param> /// <param name="oldValue">修改前解耦路数</param> /// <param name="newValue">修改后解耦路数</param> private static void ModifyCLinfo(CassView cassView, Control control, int oldValue, int newValue) { ControlInfo JieOu = cassView.FindControlInfo(control); if (newValue >= 2 && newValue <= 10) {//解耦路数必须大于等于2否则还原 //修改控件信息中解耦的输出输入端口数目 PropertyDescriptor configurationPropertyI = TypeDescriptor.GetProperties(control)["InputNum"]; PropertyDescriptor configurationPropertyO = TypeDescriptor.GetProperties(control)["OutputNum"]; configurationPropertyI.SetValue(control, newValue); configurationPropertyO.SetValue(control, newValue); JieOu.InputInfo = CassView.InitializeIOinfo(newValue, JieOu.InputInfo);//解耦控件没有端口初值20090616 JieOu.OutputInfo = CassView.InitializeIOinfo(newValue); for (int i = 0; i < cassView.ctrlsInfo.Count; i++) {//将修改后的控件信息覆盖原有的控件信息 if (cassView.ctrlsInfo[i].ControlNum == JieOu.ControlNum) { cassView.ctrlsInfo[i] = JieOu; } } if (oldValue > newValue) {//当修改后解耦路数小于原先,则删除缩减端口对应的直线 for (int i = cassView.linesInfo.Count - 1; i >= 0; i--)//从后往前删线信息 { if (((string)(control.Tag) == cassView.linesInfo[i].StartInfo.Split(';')[0] && (Convert.ToInt32(cassView.linesInfo[i].StartInfo.Split(',')[1]) >= newValue)) || (((string)(control.Tag) == cassView.linesInfo[i].EndInfo.Split(';')[0]) && Convert.ToInt32(cassView.linesInfo[i].EndInfo.Split(',')[1]) >= newValue)) {//直线的输入或输出信息对应当前控件且端口号大于修改后的值则删除 cassView.DeleteLine(i, false); } } } cassView.portReflash();//刷新端口及连线信息 cassView.DrawBackgroundImage();//刷新背景图 SetJoConfigInfo(control, Convert.ToInt32(oldValue), newValue);//修改控件端口外观 } else {//还原端口旧值 JieOu.VisibleFunctionProperty[0].TheValue = (oldValue); MessageBox.Show("解耦路数必须大于等于2小于等于10!"); } }
/// <summary> /// ����curtcass�����пؼ���Ϣ���������������ֿ� /// </summary> /// <param name="curtcass">��Ҫ�����Cassview</param> /// <param name="pageName">��ǰCassview��ҳ��</param> /// <returns>�ѷֿ�õĿؼ���Ϣ��</returns> private List<List<ControlInfo>> PackCtrls(CassView curtcass, string pageName) { List<List<ControlInfo>> GroupCtrls = new List<List<ControlInfo>>(); List<string> UseCtrl = new List<string>();//�����Ѿ�ʹ�ù��Ŀؼ����� ////////////////////////////////////////////////////////////////////////////////���Ż� foreach (ControlInfo ctrl in curtcass.ctrlsInfo) { if (UseCtrl.Contains(ctrl.ControlName)) { continue; } else if (ctrl.IsConnect) {//�ÿؼ������ӿؼ���û�б������ؼ������� Stack<ControlInfo> tempStack = new Stack<ControlInfo>();//���ڴ�ŵ�ǰ�ؼ���Ϣ�������ӵĿؼ���Ϣ����ת�ö�ջ List<ControlInfo> Pack = new List<ControlInfo>(); //��ǰ�ؼ�ѹ����ʱ��ջ tempStack.Push(ctrl); UseCtrl.Add(ctrl.ControlName); while (tempStack.Count != 0) { //ȡ��ջ���ؼ� ControlInfo TopCtrl = tempStack.Pop(); //�����ÿؼ������ӵ��ҷDZ������Ŀؼ�ѹ���ջ if (TopCtrl.OutputInfo != null) { if (TopCtrl.OutputInfo.Count == 1 && TopCtrl.OutputInfo[0][0] != null && TopCtrl.OutputInfo[0][0].Split(',').Length == 1) {//�������Ӧ��������� ControlInfo ConnectCtrl = curtcass.ctrlsInfo[curtcass.FindControlName(TopCtrl.OutputInfo[0][0].Split('.')[0])]; if (!UseCtrl.Contains(ConnectCtrl.ControlName)) { tempStack.Push(ConnectCtrl); UseCtrl.Add(ConnectCtrl.ControlName); } } else {//�������Ӧ���������������� for (int i = TopCtrl.OutputInfo.Count-1; i >=0; i--) { if (TopCtrl.OutputInfo[i][0] != null) { string[] OputArray = TopCtrl.OutputInfo[i][0].Split(',');//һ����ڶ�Ӧ����ؼ��Զ��ŷָ� for (int j = 0; j < OputArray.Length; j++) { ControlInfo ConnectCtrl = curtcass.ctrlsInfo[curtcass.FindControlName(OputArray[j].Split('.')[0])]; if (!UseCtrl.Contains(ConnectCtrl.ControlName)) { tempStack.Push(ConnectCtrl); UseCtrl.Add(ConnectCtrl.ControlName); } } } } } } if (TopCtrl.InputInfo != null) { for (int j = TopCtrl.InputInfo.Count - 1; j >= 0; j--) { if (TopCtrl.InputInfo[j][0] != null) { ControlInfo ConnectCtrl = curtcass.ctrlsInfo[curtcass.FindControlName(TopCtrl.InputInfo[j][0].Split('.')[0])]; if (!UseCtrl.Contains(ConnectCtrl.ControlName)) { tempStack.Push(ConnectCtrl); UseCtrl.Add(ConnectCtrl.ControlName); } } } } //��ջ���ؼ�ת���µĿؼ��� Pack.Add(TopCtrl); } GroupCtrls.Add(Pack); } if (!ctrl.IsConnect) { string warningInfo = "�ؼ����Ϊ" + ctrl.ControlNum.ToString() + "��" + ctrl.CodeInfo[0] + "�ؼ�û������"; CassViewGenerator.SpecialErrors.Add(new string[] { null, warningInfo, "warning", pageName }); ViewErrorinfo.Add(new string[] { pageName, ctrl.ControlNum.ToString(), warningInfo }); } if (ctrl.ControlName.ToUpper().Contains("FILEIN")) { if (ctrl.CodeInfo[1].Trim() == "FILEIN"||ctrl.CodeInfo[1].Trim() == "" || ctrl.CodeInfo[1] == null) { string errorInfo = "�ؼ����Ϊ" + ctrl.ControlNum.ToString() + "��'" + ctrl.CodeInfo[0] + " '�ؼ�ȱ���������"; CassViewGenerator.SpecialErrors.Add(new string[] { null, errorInfo, "error", pageName }); ViewErrorinfo.Add(new string[]{pageName,ctrl.ControlNum.ToString(),errorInfo}); } } } return GroupCtrls; }
/// <summary> /// 更正解耦控件信息中数组属性的数组名并返回数组信息 /// </summary> /// <param name="curCas">控件所在CASSVIEW容器</param> /// <param name="curCtrl">控件</param> /// <param name="ArrayCount">当前所用到队列编号</param> /// <returns>数组信息</returns> static public List <string[]> GetJieOuArray(CassView curCas, Control curCtrl, ref int ArrayCount) { List <string[]> ArrayInfos = new List <string[]>(); //返回信息数组 int count = 2; //解耦路数 //解耦属性中需要生成数组的属性 List <string> NeedAddArray = new List <string>(new string[] { "比例", "积分", "微分", "设定值", "自动/手动", "控制量上限", "控制量下限", "控制量输出", "解耦矩阵的参数" }); PropertyDescriptor configurationProperty = TypeDescriptor.GetProperties(curCtrl)["Configuration"]; ControlTactic.SpecialControl.JieOu ConvertTool = new ControlTactic.SpecialControl.JieOu(); ControlTactic.SpecialControl.JieOuStruct tempStruct = ConvertTool.ListToStruct((List <string>)configurationProperty.GetValue(curCtrl)); ControlInfo JieOu = curCas.FindControlInfo(curCtrl); for (int i = 0; i < JieOu.VisibleFunctionProperty.Count; i++) {//在可视属性中找到解耦数进行赋值 if (JieOu.VisibleFunctionProperty[i].Name == "解耦路数") { JieOu.VisibleFunctionProperty[i].TheValue = tempStruct.JieOuNum; count = tempStruct.JieOuNum; break; } } //依次为比例、积分、微分、设定值、自动手动、控制量上限、控制量下限、控制量输出数组 List <string>[] Attributes = new List <string>[] { new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>(), new List <string>() }; foreach (List <string> attribute in tempStruct.JieOuAttribute) {//每个属性 依次由比例、积分、微分、设定值、自动手动、控制量上限、控制量下限、控制量输出组成 Attributes[0].Add(attribute[0]); Attributes[1].Add(attribute[1]); Attributes[2].Add(attribute[2]); Attributes[3].Add(attribute[3]); Attributes[4].Add(new List <string>(new string[] { "自动", "手动" }).IndexOf(attribute[4]).ToString());//自动手动序号 Attributes[5].Add(attribute[5]); Attributes[6].Add(attribute[6]); Attributes[7].Add(attribute[7]); } for (int i = 0; i < JieOu.UnvisibleFunctionProperty.Count; i++) { int index = NeedAddArray.IndexOf(JieOu.UnvisibleFunctionProperty[i].Name); if (index != -1) {//ArrayInfo顺序依次为控件PortName、属性VarName、类型、数组名、长度、数组 List <string> ArrayInfo = new List <string>(); JieOu.UnvisibleFunctionProperty[i].TheValue = "configuration" + CassViewGenerator.ProjectNum + "_array" + (ArrayCount++).ToString(); ArrayInfo.Add(JieOu.CodeInfo[2]); ArrayInfo.Add(JieOu.UnvisibleFunctionProperty[i].Name); ArrayInfo.Add("fp32"); ArrayInfo.Add(JieOu.UnvisibleFunctionProperty[i].TheValue.ToString()); if (index == 8) { List <string> tempArray = new List <string>(); foreach (string element in tempStruct.JieOuTable) { tempArray.Add(element); } ArrayInfo.Add(tempArray.Count.ToString()); ArrayInfo.Add(String.Join(",", tempArray.ToArray())); } else { ArrayInfo.Add(Attributes[index].Count.ToString()); ArrayInfo.Add(String.Join(",", Attributes[index].ToArray())); } if (index == 4) {//自动/手动为char型 ArrayInfo[2] = "uint8"; } ArrayInfo.Add(JieOu.UnvisibleFunctionProperty[i].VarName); ArrayInfos.Add(ArrayInfo.ToArray()); } else if (JOUnuseArray.Contains(JieOu.UnvisibleFunctionProperty[i].Name)) {//不使用的数组赋值 JieOu.UnvisibleFunctionProperty[i].TheValue = "configuration" + CassViewGenerator.ProjectNum + "_array" + (ArrayCount++).ToString(); List <string> tempValue = new List <string>();//生成解耦路数个全0数组 for (int k = 0; k < count; k++) { tempValue.Add("0"); } UnseeArray.Add(new string[] { null, null, "fp32", JieOu.UnvisibleFunctionProperty[i].TheValue.ToString(), count.ToString(), String.Join(",", tempValue.ToArray()) }); } } return(ArrayInfos); }
/// <summary> /// 设置控件信息中的CodeInfo属性,用于指令生成 /// </summary> /// <param name="CurrentCass"></param> /// <param name="control"></param> /// <param name="ChangeItem"></param> /// <param name="ChangeValue"></param> public static void SetCodeInfo(CassView CurrentCass, Control control, string ChangeItem, string ChangeValue) { ControlInfo ctrlinfo = CurrentCass.ctrlsInfo[CurrentCass.FindControlName(control.Tag.ToString())]; //ControlInfo ctrlinfo = CurrentCass.FindControlInfo(control); if (ctrlinfo.CodeInfo[0] == "输入变量" || ctrlinfo.CodeInfo[0] == "输出变量" || ctrlinfo.CodeInfo[0] == "返回") {//特殊一类功能属性 if (ChangeItem == "选择点名") { ctrlinfo.CodeInfo[1] = ChangeValue; ctrlinfo.CodeInfo[2] = null;//更改了点名则清空属性信息 SetPropertyList(control); } else if (ChangeItem == "选择属性") { ctrlinfo.CodeInfo[2] = ChangeValue.Split('(')[0];//去掉末尾括号中的中文属性名 } } else if (ctrlinfo.CodeInfo[0] == "常数" || ctrlinfo.CodeInfo[0] == "系统变量" || ctrlinfo.CodeInfo[0] == "跳转" || ctrlinfo.CodeInfo[0] == "调用") {//特殊二类功能属性 if (ChangeItem == "数据类型" || ChangeItem == "变量类型")//常数控件的第二个属性||系统变量的第一个属性 { ctrlinfo.CodeInfo[2] = ChangeValue; } else if (ctrlinfo.CodeInfo[0] == "跳转" && ChangeItem == "所跳转目标" && ChangeValue.Contains(":")) {//跳转控件分别存放条件序号和序号名 string temp = ChangeValue.Split(':')[1];//BL:后的跳转序列 foreach (string[] valueArray in GenerateCode.PackInfos) { if (valueArray[1] == temp) {//找到序列对应的串名赋值 ctrlinfo.CodeInfo[1] = valueArray[0]; break; } } } else//此类其他控件的唯一属性和常数的第一个属性 { ctrlinfo.CodeInfo[1] = ChangeValue; } } else//其他功能属性 { for (int i = 0; i < CurrentCass.ctrlsInfo.Count; i++) { if (CurrentCass.ctrlsInfo[i].ControlName == control.Site.Name && CurrentCass.ctrlsInfo[i].VisibleFunctionProperty != null) { for (int j = 0; j < CurrentCass.ctrlsInfo[i].VisibleFunctionProperty.Count; j++) { if (CurrentCass.ctrlsInfo[i].VisibleFunctionProperty[j].Name == ChangeItem) { CurrentCass.ctrlsInfo[i].VisibleFunctionProperty[j].TheValue = ChangeValue; } } break; } } } }
/// <summary> /// ��������������ڵ� /// </summary> /// <param name="curCas">�ؼ�����CASSVIEW����</param> /// <param name="curCtrl">�ؼ�</param> /// <returns>�ڵ�</returns> private XmlNode CreateProcess(CassView curCas, Control curCtrl) { PropertyDescriptor configurationProperty = TypeDescriptor.GetProperties(curCtrl)["Configuration"]; ControlTactic.SpecialControl.Process ConvertTool = new ControlTactic.SpecialControl.Process(); ControlTactic.SpecialControl.ProcessStruct tempStruct = ConvertTool.ListToStruct((List<string>)configurationProperty.GetValue(curCtrl)); tempStruct = AddID(tempStruct); XmlElement Process = document.CreateElement("ConditionAction"); ControlInfo currentCtrl = curCas.FindControlInfo(curCtrl); Process.SetAttribute("name", currentCtrl.CodeInfo[2]); if (tempStruct.IsOnlyStart) { for (int i = 0; i < tempStruct.NumOfConditions; i++) {//�������������Ϣ���������� if (tempStruct.Conditions[i] == "") { continue; } XmlElement newItem = document.CreateElement("item"); XmlElement newCondition = document.CreateElement("condition"); newCondition.InnerText = tempStruct.Conditions[i]; newItem.AppendChild(newCondition); XmlElement newExpression = document.CreateElement("expression"); newExpression.InnerText = "condition[" + i.ToString() + "] = 1"; newItem.AppendChild(newExpression); Process.AppendChild(newItem); } } for (int Aindex = 0; Aindex < tempStruct.NumOfActions; Aindex++) { XmlElement newItem = document.CreateElement("item"); if (tempStruct.Actions[Aindex][0] == "" || (tempStruct.Actions[Aindex][1] == "" && tempStruct.Actions[Aindex][2] == "")) {//����Ϊ�ջ������ı��ʽΪ�� continue; } for (int Cindex = 0; Cindex < tempStruct.NumOfConditions; Cindex++) { string Condition = null; if (tempStruct.OrderBox[Cindex, Aindex] == "" || tempStruct.Conditions[Cindex] == "") {//���˳����ϵΪ�� ���Ӧ������Ϊ�������� continue; } else if (tempStruct.OrderBox[Aindex, Cindex] == "N") {//�ǹ�ϵ���ϣ� Condition = "!"; } if (tempStruct.IsOnlyStart) {//�������������趨�ж���ʾ�������黹�DZ��ʽ Condition += "condition[" + Cindex.ToString() + "]"; } else { Condition += "(" + tempStruct.Conditions[Cindex] + ")"; } XmlElement newCondition = document.CreateElement("condition"); newCondition.InnerText = Condition; newItem.AppendChild(newCondition); } if (newItem.ChildNodes.Count == 0) {//���û��������Ĭ��Ϊ1 �������"1"�����ӽڵ� XmlElement newCondition = document.CreateElement("condition"); newCondition.InnerText = "1"; newItem.AppendChild(newCondition); } XmlElement newExpression = document.CreateElement("expression"); if (tempStruct.Actions[Aindex][0] == "Evaluate") { newExpression = document.CreateElement("expression"); newExpression.InnerText = tempStruct.Actions[Aindex][1] + "=" + tempStruct.Actions[Aindex][2]; } else if (tempStruct.Actions[Aindex][0] == "Transfer") { newExpression = document.CreateElement("function"); newExpression.InnerText = Mid + tempStruct.Actions[Aindex][1] + Sid; } newItem.AppendChild(newExpression); Process.AppendChild(newItem); } return Process; }