private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return) { string[] split = textBox1.Text.Split(new string[] { "|ID:" }, StringSplitOptions.None); if (split.Length == 2) { id = split[1]; nc12 = split[0]; fullQrText = textBox1.Text; var gData = Graffiti.MST.ComponentsTools.GetDbData.GetComponentDataWithAttributes(new List <string> { textBox1.Text }); if (gData.Count() < 1) { MessageBox.Show("Brak danych o komponencie w bazie Graffiti"); return; } graffitiCompData = gData.First(); this.DialogResult = DialogResult.OK; } else { textBox1.Text = ""; } } }
// Extract the module network from the whole network public static void MPCCDSubGraph(List <List <int> > Modules, double[,] WeightMatrix, List <ComponentStruct> VerticeMatrix, int[,] RelativeMotionMatrix, out double[,] WMIntraModules, out List <double[, ]> SubGraphs, out List <List <ComponentStruct> > SubVerticeMs, out List <int[, ]> SubRelativeMs) { int NumOfModules = Modules.Count; int NumOfNode = WeightMatrix.GetLength(0); WMIntraModules = new double[NumOfNode, NumOfNode]; SubGraphs = new List <double[, ]>(); SubVerticeMs = new List <List <ComponentStruct> >(); SubRelativeMs = new List <int[, ]>(); for (int i = 0; i < NumOfModules; i++) { List <ComponentStruct> partList = new List <ComponentStruct>(); ComponentStruct part = new ComponentStruct(); int NumOfElements = Modules[i].Count; double[,] SubGraph = new double[NumOfElements, NumOfElements]; ComponentStruct SubVerticeM = new ComponentStruct(); int[,] SubRelativeM = new int[NumOfElements, NumOfElements]; for (int j = 0; j < NumOfElements; j++) { for (int k = 0; k < NumOfElements; k++) { if (j != k) { if (WeightMatrix[Modules[i].ElementAt(j) - 1, Modules[i].ElementAt(k) - 1] != 0) { SubGraph[j, k] = WeightMatrix[Modules[i].ElementAt(j) - 1, Modules[i].ElementAt(k) - 1]; SubGraph[k, j] = WeightMatrix[Modules[i].ElementAt(j) - 1, Modules[i].ElementAt(k) - 1]; WMIntraModules[Modules[i].ElementAt(j) - 1, Modules[i].ElementAt(k) - 1] = WeightMatrix[Modules[i].ElementAt(j) - 1, Modules[i].ElementAt(k) - 1]; WMIntraModules[Modules[i].ElementAt(k) - 1, Modules[i].ElementAt(j) - 1] = WeightMatrix[Modules[i].ElementAt(j) - 1, Modules[i].ElementAt(k) - 1]; } if (RelativeMotionMatrix[Modules[i].ElementAt(j) - 1, Modules[i].ElementAt(k) - 1] != 0) { SubRelativeM[j, k] = 1; } } else { SubGraph[j, k] = 1; WMIntraModules[Modules[i].ElementAt(j) - 1, Modules[i].ElementAt(k) - 1] = 1; WMIntraModules[Modules[i].ElementAt(k) - 1, Modules[i].ElementAt(j) - 1] = 1; } } SubVerticeM = new ComponentStruct { material = VerticeMatrix[Modules[i].ElementAt(j) - 1].material, MaintenanceFreq = VerticeMatrix[Modules[i].ElementAt(j) - 1].MaintenanceFreq, bdBox = VerticeMatrix[Modules[i].ElementAt(j) - 1].bdBox, IsStandard = VerticeMatrix[Modules[i].ElementAt(j) - 1].IsStandard }; partList.Add(SubVerticeM); } SubGraphs.Add(SubGraph); SubRelativeMs.Add(SubRelativeM); SubVerticeMs.Add(partList.ToList()); } }
static void serializeEngineComponent <T>(ref ComponentStruct component, ref T toSerialize, T defaultComponent) where T : Component { //Serialize the public properties of this engine component PropertyInfo[] info = GetAssemblyType(component.typeName).GetProperties(); component.enginePropertyNames = new List <string>(); component.enginePropertyValues = new List <string>(); for (int j = 0; j < info.Length; j++) { string json = serializeProperty(info[j], ref toSerialize); string defaultJson = serializeProperty(info[j], ref defaultComponent); if (json != "" && json != defaultJson) { component.enginePropertyNames.Add(info[j].Name); component.enginePropertyValues.Add(json); } } }
static void addTransform(Transform inObject, List <TransformStruct> transforms, Queue <Transform> transformQueue, ref Dictionary <Type, Component> defaultComponentDictionary, ref GameObject defaultComponentContainer, ref int index) { //Construct this transform as a TransformStruct TransformStruct thisTransform = new TransformStruct(); thisTransform.name = inObject.name; thisTransform.instanceID = inObject.GetInstanceID(); thisTransform.localPosition = inObject.position; thisTransform.localRotation = inObject.rotation; thisTransform.localScale = inObject.localScale; //Count up the valid components int validComponentIndex = 0; Component[] components = inObject.GetComponents <Component>(); for (int i = 0; i < components.Length; i++) { string typeName = components[i].GetType().ToString(); if (typeName != "SerializedGameObject" && typeName != "UnityEngine.Transform") { validComponentIndex++; } } //Add all of the valid components thisTransform.components = new ComponentStruct[validComponentIndex]; validComponentIndex = 0; for (int i = 0; i < components.Length; i++) { ComponentStruct component = new ComponentStruct(); component.typeName = components[i].GetType().ToString(); if (component.typeName != "SerializedGameObject" && component.typeName != "UnityEngine.Transform") { component.instanceID = components[i].GetInstanceID(); if (!component.typeName.StartsWith("UnityEngine.")) { component.sanitizedJson = JsonUtility.ToJson(components[i]); } else { Component defaultComponent; if (!defaultComponentDictionary.TryGetValue(components[i].GetType(), out defaultComponent)) { defaultComponent = defaultComponentContainer.AddComponent(components[i].GetType()); defaultComponentDictionary.Add(components[i].GetType(), defaultComponent); } serializeEngineComponent(ref component, ref components[i], defaultComponent); } thisTransform.components[validComponentIndex] = component; validComponentIndex++; } } //And all the children, too! thisTransform.children = new int[inObject.childCount]; for (int i = 0; i < thisTransform.children.Length; i++) { thisTransform.children[i] = ++index; transformQueue.Enqueue(inObject.GetChild(i)); } transforms.Add(thisTransform); }
static void deserializeEngineComponent <T>(ref ComponentStruct component, T toFill, ref Dictionary <int, Component> referenceDictionary) where T : Component { //Deserialize the properties of this engine component for (int i = 0; i < component.enginePropertyNames.Count; i++) { PropertyInfo info = toFill.GetType().GetProperty(component.enginePropertyNames[i]); try { object obj = info.GetValue(toFill, null); string componentJson = JsonUtility.ToJson(obj); if (componentJson != "{}") { try { info.SetValue(toFill, JsonUtility.FromJson(fixReferences(component.enginePropertyValues[i], referenceDictionary), obj.GetType()), null); } catch (NullReferenceException e) { try { Component referencedComponent; if (referenceDictionary.TryGetValue(JsonUtility.FromJson <PrimitiveWrapper <int> >(component.enginePropertyValues[i]).value__, out referencedComponent)) { info.SetValue(toFill, referencedComponent, null); } } catch { Debug.LogWarning(toFill.name + "'s " + info.Name + "'s reference failed to serialize with: \n" + e, toFill); } } } else { if (obj is System.Single) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <System.Single> >(component.enginePropertyValues[i]).value__, null); } else if (obj is System.Single[]) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <System.Single[]> >(component.enginePropertyValues[i]).value__, null); } else if (obj is System.Boolean) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <System.Boolean> >(component.enginePropertyValues[i]).value__, null); } else if (obj is System.Int32) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <System.Int32> >(component.enginePropertyValues[i]).value__, null); } else if (obj is System.String) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <System.String> >(component.enginePropertyValues[i]).value__, null); } else if (obj is Rect) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <Rect> >(component.enginePropertyValues[i]).value__, null); } else if (obj is Bounds) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <Bounds> >(component.enginePropertyValues[i]).value__, null); } else if (obj is UnityEngine.SceneManagement.Scene) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <UnityEngine.SceneManagement.Scene> >(component.enginePropertyValues[i]).value__, null); } else if (obj is Camera[]) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <Camera[]> >(fixReferences(component.enginePropertyValues[i], referenceDictionary)).value__, null); } else if (obj is Material[]) { info.SetValue(toFill, JsonUtility.FromJson <PrimitiveWrapper <Material[]> >(fixReferences(component.enginePropertyValues[i], referenceDictionary)).value__, null); } } } catch { } } }
public static void RegToLua(LuaState l) { l.LuaPushFunction(L => { object[] componentNames = l.GetTable("ecs.component.allcomponentnames").ToArray(); object[] propertyNameArrs = l.GetTable("ecs.component.allcomponentpropertys").ToArray(); List <string> componentSelectTextsList = new List <string>(); for (int i = 1; i <= componentNames.Length; i++) { ComponentStruct cstruct = new ComponentStruct(); cstruct.fullName = componentNames[i - 1].ToString(); cstruct.name = cstruct.fullName.Substring(cstruct.fullName.LastIndexOf('.') + 1); cstruct.id = i; object[] pnames = (propertyNameArrs[i - 1] as LuaTable).ToArray(); cstruct.propertyNames = new string[pnames.Length]; for (int j = 0; j < pnames.Length; j++) { cstruct.propertyNames[j] = pnames[j].ToString(); } componentSelectTextsList.Add(cstruct.fullName.Replace(".", "/")); componentSelectIds.Add(i); componentStructs.Add(cstruct); } componentSelectTexts = componentSelectTextsList.ToArray(); getEntityComponentIds = l.GetFunction("ecs.bridge.getentitycomponentids"); getEntityComponetnPropertyValue = l.GetFunction("ecs.bridge.getentitycomponetnpropertyvalue"); setEntityComponetnPropertyValue = l.GetFunction("ecs.bridge.setentitycomponetnpropertyvalue"); addComponent = l.GetFunction("ecs.bridge.addcomponent"); removeComponent = l.GetFunction("ecs.bridge.removecomponent"); getEntityOwners = l.GetFunction("ecs.bridge.getentityowners"); getEntityRetainCount = l.GetFunction("ecs.bridge.getentityretaincount"); isMatch = l.GetFunction("ecs.bridge.ismatch"); destroyEntity = l.GetFunction("ecs.bridge.destroyentity"); return(0); }); l.LuaSetGlobal("ECS_INIT_EDITOR_ENTITY"); l.LuaPushFunction(L => { LuaEntity entity = new GameObject().AddComponent <LuaEntity>(); entity.poolName = ToLua.CheckString(L, 1); entity.entityId = System.Convert.ToInt32(LuaDLL.luaL_checknumber(L, 2)); entity.transform.parent = LuaPool.Get(entity.poolName).transform; entity.name = "Entity_" + entity.entityId; entity.gameObject.hideFlags = HideFlags.HideInHierarchy; if (!entities.ContainsKey(entity.poolName)) { entities.Add(entity.poolName, new Dictionary <int, LuaEntity>()); } entities[entity.poolName].Add(entity.entityId, entity); return(0); }); l.LuaSetGlobal("ECS_POOL_ONENTITYCREATE"); l.LuaPushFunction(L => { string poolName = ToLua.CheckString(L, 1); int id = System.Convert.ToInt32(LuaDLL.luaL_checknumber(L, 2)); Destroy(entities[poolName][id].gameObject); entities[poolName].Remove(id); return(0); }); l.LuaSetGlobal("ECS_POOL_ONENTITYDESTROY"); }
// calculate button private void button3_Click(object sender, EventArgs e) { var watch = System.Diagnostics.Stopwatch.StartNew(); richTextBox1.Text = ""; string str = comboBox2.SelectedItem.ToString(); int NumOfNode = currProduct.parts.Count; WeightMatrix = new double[NumOfNode, NumOfNode]; VerticeMatrix = new List <ComponentStruct>(); RelativeMotionMatrix = new int [NumOfNode, NumOfNode]; NumOfPopulation = (int)(NumOfNode / 2) + 3; NumOfGeneration = 10 * NumOfNode; double[] BestFitness = new double[NumOfGeneration]; Alfa = Convert.ToDouble(textBox1.Text); Modules = new List <List <int> >(); FlagColor = 0; // assemble xml info into a weight matrix for (int i = 0; i < NumOfNode; i++) { Part part = currProduct.parts[i]; WeightMatrix[i, i] = 1; if (part.JointComponent.Count != 0) { for (int j = 0; j < part.JointComponent.Count; j++) { WeightMatrix[i, part.JointComponent[j] - 1] = part.Weight[j]; // Get relative motion matrix RelativeMotionMatrix[i, part.JointComponent[j] - 1] = part.RelativeMotion[j]; } } } // retrieve vertice matrix for (int i = 0; i < NumOfNode; i++) { Part part = currProduct.parts[i]; ComponentStruct CMPS = new ComponentStruct(); switch (part.material) { case "Steel": CMPS.material = 1; break; case "Plastic": CMPS.material = 2; break; case "Rubber": CMPS.material = 3; break; case "Aluminium": CMPS.material = 4; break; case "Ceramic": CMPS.material = 5; break; } CMPS.bdBox = part.bdBox; switch (part.IsStandard) { case "Y": CMPS.IsStandard = 1; break; case "N": CMPS.IsStandard = 0; break; } switch (part.MaintenanceFreq) { case "High": CMPS.MaintenanceFreq = 1; break; case "Low": CMPS.MaintenanceFreq = 0; break; } VerticeMatrix.Add(CMPS); } // get size limit SizeLimit[0] = vlm[0]; SizeLimit[1] = vlm[1]; SizeLimit[2] = vlm[2]; // get material list MaterialList = new int[Materials.Count]; for (int i = 0; i < Materials.Count; i++) { switch (Materials[i]) { case "Steel": MaterialList[i] = 1; break; case "Plastic": MaterialList[i] = 2;; break; case "Rubber": MaterialList[i] = 3;; break; case "Aluminum": MaterialList[i] = 4;; break; case "Ceramics": MaterialList[i] = 5;; break; } } GAModuleDiv.TransferMatrixToSym(WeightMatrix, out SymmWeightMatrix); if (str == "Product") { // module division GAModuleDiv.FindBestSolution_Multiple(SymmWeightMatrix, NumOfPopulation, NumOfGeneration, CrossOverRatio, MutationRatio, out Modules, out BestFitness); CPCCD.FindCommunity(Alfa, Modules, SymmWeightMatrix, VerticeMatrix, RelativeMotionMatrix, out Communities, out Modularity, out SubGraphs, out SubVerticeMs, out SubRelativeMs); CPCCD.CPCCDAllRules_R3(Alfa, Modules, Communities, Modularity, SubGraphs, SubVerticeMs, SubRelativeMs, SizeLimit, CFTypeCode, MaterialList, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); richTextBox1.AppendText("\nModule Info:\n"); foreach (List <int> x in Modules) { x.Sort(); foreach (int xx in x) { richTextBox1.AppendText(" "); richTextBox1.AppendText(string.Join(" ", xx.ToString())); } // Console.WriteLine("\n"); richTextBox1.AppendText("\n"); } richTextBox1.AppendText(string.Format("{0:0.000}", BestFitness.Max()) + "\n"); /*foreach (List<List<int>> X0 in Communities) * { * foreach (List<int> x in X0) * { * foreach (int xx in x) * { * richTextBox1.AppendText(" "); * richTextBox1.AppendText(string.Join(" ", xx.ToString())); * } * richTextBox1.AppendText("\n"); * } * richTextBox1.AppendText("\n\n"); * }*/ /* List<List<double>> StackUpSize; * // List<int> Module = new List<int>(); * // MPCCD.MPCCDGenerateModule(SymmWeightMatrix.GetLength(0), out Module); * * NPCCD.PCCDStackUpSize(NodeGroups, VerticeMatrix, out StackUpSize); * foreach (List<double> x in StackUpSize) * { * foreach (double xx in x) * { * richTextBox1.AppendText(" "); * richTextBox1.AppendText(string.Join(" ", string.Format("{0:0.0}", xx))); * } * richTextBox1.AppendText("\n"); * } */ Flag = 1; textBox2.Text = "CPCCD"; } else { // module division GAModuleDiv.FindBestSolution_Multiple(SymmWeightMatrix, NumOfPopulation, NumOfGeneration, CrossOverRatio, MutationRatio, out Modules, out BestFitness); if (BestFitness.Max() > Alfa) { Flag = 2; MPCCD.MPCCDAllRules_R3(Modules, SymmWeightMatrix, VerticeMatrix, RelativeMotionMatrix, SizeLimit, CFTypeCode, MaterialList, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); // List<List<double>> StackUpSize; // List<int> Module = new List<int>(); // MPCCD.MPCCDGenerateModule(SymmWeightMatrix.GetLength(0), out Module); /* NPCCD.PCCDStackUpSize(NodeGroups, VerticeMatrix, out StackUpSize); * foreach (List<double> x in StackUpSize) * { * foreach (double xx in x) * { * richTextBox1.AppendText(" "); * richTextBox1.AppendText(string.Join(" ", string.Format("{0:0.0}", xx))); * } * richTextBox1.AppendText("\n"); * }*/ richTextBox1.AppendText("\nModule Info:\n"); foreach (List <int> x in Modules) { x.Sort(); foreach (int xx in x) { richTextBox1.AppendText(" "); richTextBox1.AppendText(string.Join(" ", xx.ToString())); } // Console.WriteLine("\n"); richTextBox1.AppendText("\n"); } richTextBox1.AppendText(string.Format("{0:0.000}", BestFitness.Max())); textBox2.Text = "CPCCD"; } else { Flag = 3; // List<int> Module = new List<int>(); // MPCCD.MPCCDGenerateModule(SymmWeightMatrix.GetLength(0), out Module); NPCCD.NPCCDAllRules_R3(SymmWeightMatrix, VerticeMatrix, SizeLimit, MaterialList, RelativeMotionMatrix, CFTypeCode, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); /* List<List<double>> StackUpSize; * NPCCD.PCCDStackUpSize(NodeGroups, VerticeMatrix, out StackUpSize); * * foreach (List<double> x in StackUpSize) * { * foreach (double xx in x) * { * richTextBox1.AppendText(" "); * richTextBox1.AppendText(string.Join(" ", string.Format("{0:0.0}", xx))); * } * richTextBox1.AppendText("\n"); * }*/ textBox2.Text = "NPCCD"; } } richTextBox1.AppendText("\nNode Groups:\n"); foreach (List <int> x in NodeGroups) { x.Sort(); foreach (int xx in x) { richTextBox1.AppendText(" "); richTextBox1.AppendText(string.Join(" ", xx.ToString())); } richTextBox1.AppendText("\n"); } richTextBox2.Clear(); richTextBox2.AppendText("\nConflict Info:\n"); int Index = 0; foreach (List <int> x in TroubleNodeList) { foreach (int xx in x) { richTextBox2.AppendText(" "); richTextBox2.AppendText(string.Join(" ", xx.ToString())); } richTextBox2.AppendText("\t"); richTextBox2.AppendText(TroubleCode[Index].ToString()); Index++; richTextBox2.AppendText("\n"); } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; label14.Show(); label14.Text = elapsedMs.ToString(); }