// 点击“开始”按钮 void startBT_Click(object sender, EventArgs e) { buildCacheAction.SaveFilename = ConstValue.CacheFilename; buildCacheAction.RootPath = buildCacheForm.rootPathTB.Text; Constrain.NotEmptyString(buildCacheAction.RootPath); buildCacheAction.Start(); }
private void ClutterWithLoops(Gaussian meanPrior, Gaussian noiseDist, double[] data) { bool evidence = Factor.Random(new Bernoulli(0.5)); if (evidence) { double prec = 1; double mixWeight = 0.5; double mean = Factor.Random(meanPrior); bool[] b = new bool[data.Length]; for (int i = 0; i < data.Length; i++) { b[i] = Factor.Bernoulli(mixWeight); double x; if (b[i]) { x = Factor.Gaussian(mean, prec); } else { x = Factor.Random(noiseDist); } Constrain.Equal(x, data[i]); } InferNet.Infer(mean, nameof(mean)); InferNet.Infer(b, nameof(b)); } InferNet.Infer(evidence, nameof(evidence)); }
public BuildCacheFormLogic(BuildCacheForm buildCacheForm) { Constrain.NotNull(buildCacheForm); this.buildCacheForm = buildCacheForm; initListener(); initAction(); }
private void findUser1_FoundUser(Account account, User user, object sender, EventArgs e) { datagridFixedDep.Rows.Clear(); acc = account; lblAccountNames.Text = acc.Names; lblBalance.Text = "" + acc.Balance; lblDateCreated.Text = DateTime.Parse(acc.DateCreated).ToLongDateString() + " ," + DateTime.Parse(acc.DateCreated).ToLongTimeString(); txtAccType.Text = account.Type.Name; if (account.Type.Type == 0) { //current panel6.Visible = false; } else if (account.Type.Type == 1) { //fixedDep panel6.Visible = true; Constrain constrain = API.Controllers.AccountConstrains.FindConstrain(account); if (constrain != null) { datagridFixedDep.Rows.Add(constrain.Time, constrain.Amount); } } dgvRecentTransactions.DataSource = Client.database.SelectForDataGridView ( "SELECT * FROM v_account_recent_transaction WHERE `#` = @AccountNumber order by `DateStamp` desc LIMIT 5 ;" + " ", new Client.SQL().ParameterRange("AccountNumber"), new Client.SQL().ValuesRange(account.Number) ); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var enumAsIndexAttribute = (EnumAsIndexAttribute)attribute; var enumType = enumAsIndexAttribute.Type; var names = Enum.GetNames(enumType); EditorGUI.BeginChangeCheck(); EnsureSize(property, names.Length); if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); property.serializedObject.UpdateIfRequiredOrScript(); } EditorGUI.BeginProperty(position, label, property); var labelRect = Constrain.To(position) .Width.Absolute(EditorGUIUtility.labelWidth) .ToRect(); var contentRect = Constrain.To(position) .Left.Relative(EditorGUIUtility.labelWidth) .ToRect(); int index = Convert.ToInt32(property.propertyPath.Split('[', ']')[1]); EditorGUI.Popup(labelRect, index, names); EditorGUI.PropertyField(contentRect, property, GUIContent.none); EditorGUI.EndProperty(); }
private void BossPredictorModel(bool isRaining) { bool raining = Factor.Random(new Bernoulli(0.8)); bool coffee = Factor.Random(new Bernoulli(0.6)); bool notRaining = Factor.Not(raining); bool temp = Factor.Or(coffee, notRaining); bool goodMood; bool approvesTrip; if (temp) { goodMood = Factor.Bernoulli(0.9); } else { goodMood = Factor.Bernoulli(0.2); } if (goodMood) { approvesTrip = Factor.Bernoulli(0.9); } else { approvesTrip = Factor.Bernoulli(0.4); } Constrain.Equal(raining, isRaining); InferNet.Infer(approvesTrip, nameof(approvesTrip)); }
private static Constrain CompareRulesForConstrainRedundancy (List <SimpleTree> firstList, List <SimpleTree> secoundList, GatheredBases bases) { //Function check if firstList is a part of secoundList int count = 0; var returnedConstrain = new Constrain(); if (firstList.Count == secoundList.Count) { var newFirstList = firstList.OrderBy(p => p.rule.Conclusion); var newSecoundList = secoundList.OrderBy(tree => tree.rule.Conclusion); var secoundListAdd = newSecoundList.ToList(); var firstListAdd = newFirstList.ToList(); var firstElement = new SimpleTree(); var secoundElement = new SimpleTree(); for (int i = 0; i < firstList.Count; i++) { if (secoundListAdd[i].rule.Conclusion != firstListAdd[i].rule.Conclusion) { firstElement = firstListAdd[i]; secoundElement = secoundListAdd[i]; count++; } } if (count == 1) { foreach (var constrain in bases.ConstrainBase.ConstrainList) { int licz = 0; foreach (var condition in constrain.ConstrainConditions) { if (firstElement.rule.Conclusion == condition) { licz++; } if (secoundElement.rule.Conclusion == condition) { licz++; } } if (licz == 2) { returnedConstrain = constrain; } } return(returnedConstrain); } } return(returnedConstrain); }
public static void Create(Constrain constrain) { Client.Logger.Log(" Creating Constrain : " + constrain.Account + ", Constrains : {" + constrain.Amount + "," + constrain.Time ); database.NewExecute( "INSERT INTO `fixed_dep_constrains` (`AccountNumber`,`Time`,`Amount`) VALUES (@accNo,@time,@amount)" , new SQL().ParameterRange("@accNo", "@time", "@amount") , new SQL().ValuesRange(constrain.Account.Number, constrain.Time, constrain.Amount)); }
public void AskForConstrainValue(Constrain constrain) { viewModel.AskedConstrain = constrain; var window = new AskConstrain(viewModel); window.ShowDialog(); SetConstrainValue(viewModel.ValueFromConstrain, viewModel.AskedConstrain); }
void buildCacheForm_FormClosing(object sender, FormClosingEventArgs e) { Constrain.NotNull(buildCacheAction); if (buildCacheAction.IsWorking) { MessageBox.Show("正在构建缓存,如果要退出,请先取消,或者等待任务完成"); e.Cancel = true; } }
private static void ReportRedundancyInConstrains (List <SimpleTree> firstSimpleTree, List <SimpleTree> secoundSimpleTree, Constrain value) { var firstRuleDescription = ConclusionClass.GetFlatteredRuleDescription(firstSimpleTree); var secoundRuleDescription = ConclusionClass.GetFlatteredRuleDescription(secoundSimpleTree); MessageBox.Show("Mamy nadmiarowość z ograniczeniem \n" + firstRuleDescription + secoundRuleDescription + "z ograniczeniem numer" + value.NumberOfConstrain); }
private void ClippedGaussianModel(double threshold) { double x = Factor.Random(new Gaussian(0, 1)); //Attrib.Var(x, new Algorithm(new VariationalMessagePassing())); double diff = Factor.Difference(x, threshold); InferNet.Infer(x, nameof(x)); bool h = Factor.IsPositive(diff); Constrain.Equal(true, h); }
public void AskingConstrainValueMethod(Constrain conclusion) { var window = new AskConstrain(this); window.ShowDialog(); // TODO:Może wystapić bug związany z zamkniciem okna x w lewym górnym rogu bases.FactBase.FactList.Add(new Fact() { FactName = CheckedRuleName, FactValue = CheckedRuleVal }); }
private void SimpleGaussianModel() { double mean = Factor.Random(new Gaussian(0, 100)); double precision = Factor.Random(Gamma.FromShapeAndScale(1, 1)); double x1 = Gaussian.Sample(mean, precision); double x2 = Gaussian.Sample(mean, precision); Constrain.Equal(x1, 5.0); Constrain.Equal(x2, 7.0); InferNet.Infer(mean, nameof(mean)); InferNet.Infer(precision, nameof(precision)); }
string getFilepath(ListViewItem lvi) { Constrain.NotNull(lvi); try { const int filepathIndex = 1; return(lvi.SubItems[filepathIndex].Text); } catch (System.Exception ex) { Constrain.UnreachableCode("出现 BUG,请调试!错误:" + ex.Message); return(null); } }
public override IGrabableItem ExchangeItems(IGrabableItem item) { if (Activated && Constrain.IsAcceptable(item)) { //TODO how to disable eating stuffs when job is done ??? //Active = false; SendMessageAsync(activated: true); return(DestroyItem ? null : item); } else { return(item); } }
public void TestConstrainRegex() { const string Querystring = "constrain=100,200"; const int ExpectedWidth = 100; const int ExpectedHeight = 200; Constrain contrast = new Constrain(); contrast.MatchRegexIndex(Querystring); int actualWidth = contrast.DynamicParameter.Width; int actualHeight = contrast.DynamicParameter.Height; Assert.AreEqual(ExpectedWidth, actualWidth); Assert.AreEqual(ExpectedHeight, actualHeight); }
public static Constrain FormatConstrain(MySqlDataReader reader) { Constrain constrain = null; while (reader.Read()) { constrain = new Constrain { Amount = reader.GetDouble("Amount"), Id = reader["Id"].ToString(), Time = reader.GetInt32("Time") }; } reader.Close(); return(constrain); }
internal void ClickModel( Gaussian inputScoreMean, Gamma inputScorePrec, Gamma inputJudgePrec, Gamma inputClickPrec, Gaussian inputLowerThreshMean, Gaussian inputUpperThreshMean, Gaussian[] clickObservations) // Click observations for this label { int n = clickObservations.Length; // Add variables outside plate - all variables outside the plate should // be marked as outputs because we will be communicating their messages // across labels double scoreMean = Factor.Random(inputScoreMean); double scorePrec = Factor.Random(inputScorePrec); double judgePrec = Factor.Random(inputJudgePrec); double clickPrec = Factor.Random(inputClickPrec); double lowerThresh = Factor.Random(inputLowerThreshMean); double upperThresh = Factor.Random(inputUpperThreshMean); // Now set up the plate double[] scores = new double[n]; double[] scoresJ = new double[n]; double[] scoresC = new double[n]; bool b = true; for (int i = 0; i < n; i++) { scores[i] = Factor.Gaussian(scoreMean, 2.0); // click-based score scoresC[i] = Factor.Gaussian(scores[i], clickPrec); Constrain.EqualRandom(scoresC[i], clickObservations[i]); // judged score scoresJ[i] = Factor.Gaussian(scores[i], judgePrec); b = Factor.IsBetween(scoresJ[i], lowerThresh, upperThresh); } InferNet.Infer(scoreMean, nameof(scoreMean)); InferNet.Infer(scorePrec, nameof(scorePrec)); InferNet.Infer(judgePrec, nameof(judgePrec)); InferNet.Infer(clickPrec, nameof(clickPrec)); InferNet.Infer(lowerThresh, nameof(lowerThresh)); InferNet.Infer(upperThresh, nameof(upperThresh)); }
private void initControls(Account a) { txtAccBal.Text = "" + a.Balance; txtAccName.Text = a.Names; txtAccType.Text = a.Type.Name; txtUAddr.Text = user.Address; txtUEmail.Text = user.Email; txtUN.Text = user.Names; txtUNId.Text = user.NationalId; txtUP.Text = user.Phone; picDS.Image = API.ImageFromByte(user.DigitalSignature); picUserPic.Image = API.ImageFromByte(user.UserPhoto); txtAccountNumber.Text = "" + account.Number; dgvRecentTransactions.DataSource = Client. database. SelectForDataGridView( "SELECT * FROM `v_account_recent_transaction` WHERE `#` = @AccountNumber LIMIT 10; " , new List <string>(new String[] { "@AccountNumber" }) , new List <Object>(new String[] { account.Number })); if (dgvRecentTransactions.Rows.Count == 0) { //No recent Transactions dgvRecentTransactions.Visible = false; lblNoAccountMessage.Visible = true; } else { //Available Recent Transactions dgvRecentTransactions.Visible = true; lblNoAccountMessage.Visible = false; } if (a.Type.Type == 1) { panel6.Visible = true; Constrain constrain = API.Controllers.AccountConstrains.FindConstrain(a); if (constrain != null) { datagridFixedDep.Rows.Add(constrain.Time, constrain.Amount); } } else { panel6.Visible = false; } }
public override void Start() { Constrain.NotEmptyString(this.RootPath); Constrain.NotEmptyString(this.SaveFilename); if (thread != null && thread.IsAlive) { Trace.WriteLine("本 Action 已经启动,但是又尝试重入,已经忽略该请求"); return; } // 清除之前残留的信息 ErrorInfo = null; CurrentWorkingDirectory = null; // 开始新的征程 :) thread = new Thread(_start); thread.Start(); fireStarted(this); }
public MainFormLogic(MainForm targetForm) { Constrain.NotNull(targetForm); this.targetForm = targetForm; // 订阅整个窗体的 Shown 事件和 searchBT 点击事件 targetForm.Shown += new EventHandler(targetForm_Shown); targetForm.searchBT.Click += new EventHandler(searchBT_Click); // 订阅窗体中 clearCacheLL 的点击事件 targetForm.clearCacheLL.Click += new EventHandler(clearCacheLL_Click); // 将 BuildCacheFormLogic 类的对象附加到缓存生成窗体上 BuildCacheFormLogic buildCacheFormLogic = new BuildCacheFormLogic(targetForm.BuildCacheForm); // 订阅 BuildCacheForm 窗体的 Shown 和 FormClosed 事件 // 用于判断用户是否又重新构建了缓存,以便重新加载 targetForm.BuildCacheForm.Shown += new EventHandler(BuildCacheForm_Shown); targetForm.BuildCacheForm.FormClosed += new FormClosedEventHandler(BuildCacheForm_FormClosed); }
/// <summary> /// Constrains the current image, resizing it to fit within the given dimensions whilst keeping its aspect ratio. /// </summary> /// <param name="size"> /// The <see cref="T:System.Drawing.Size"/> containing the maximum width and height to set the image to. /// </param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public ImageFactory Constrain(Size size) { if (this.ShouldProcess) { int width = size.Width; int height = size.Height; var constrainSettings = new Dictionary <string, string> { { "MaxWidth", width.ToString("G") }, { "MaxHeight", height.ToString("G") } }; Constrain constrain = new Constrain { DynamicParameter = new Size(width, height), Settings = constrainSettings }; this.Image = constrain.ProcessImage(this); } return(this); }
/// <summary>Computations that do not depend on observed values</summary> private void Constant() { if (this.Constant_isDone) { return; } // Create array for 'vdouble__0_uses' Backwards messages. this.vdouble__0_uses_B = new DistributionStructArray <Gaussian, double> [2]; // Create array for 'vdouble__0_uses' Backwards messages. this.vdouble__0_uses_B[0] = new DistributionStructArray <Gaussian, double>(5); // Create array for 'vdouble__0_uses' Backwards messages. this.vdouble__0_uses_B[1] = new DistributionStructArray <Gaussian, double>(5); // Create array for 'vdouble__0_itemvint__1_index0_' Backwards messages. this.vdouble__0_itemvint__1_index0__B = new DistributionStructArray <Gaussian, double>(6); // Create array for 'vdouble__0_itemvint__0_index0_' Backwards messages. this.vdouble__0_itemvint__0_index0__B = new DistributionStructArray <Gaussian, double>(6); bool vbool0_reduced = default(bool); vbool0_reduced = true; Constrain.Equal <bool>(true, vbool0_reduced); this.Constant_isDone = true; }
public override IGrabableItem ExchangeItems(IGrabableItem item) { if (OnceOnly && used) { return(item); } if (item == null || Constrain.IsAcceptable(item)) { var res = Storage; Storage = item; UpdateDecoration(); used = true; return(res); } else { return(item); } }
private static void Clutter(Gaussian meanPrior, Gaussian noiseDist, double data1, double data2) { double prec = 1; double mixWeight = 0.5; bool evidence = Factor.Random(new Bernoulli(0.5)); if (evidence) { double mean = Factor.Random(meanPrior); bool b1 = Factor.Bernoulli(mixWeight); double x1; if (b1) { x1 = Factor.Gaussian(mean, prec); } else { x1 = Factor.Random(noiseDist); } Constrain.Equal(x1, data1); bool b2 = Factor.Bernoulli(mixWeight); double x2; if (b2) { x2 = Factor.Gaussian(mean, prec); } else { x2 = Factor.Random(noiseDist); } Constrain.Equal(x2, data2); InferNet.Infer(mean, nameof(mean)); InferNet.Infer(b1, nameof(b1)); InferNet.Infer(b2, nameof(b2)); } InferNet.Infer(evidence, nameof(evidence)); }
private void SetConstrainValue(string valueFromConstrain, Constrain askedConstrain) { if (valueFromConstrain != "") { foreach (var constrain in askedConstrain.ConstrainConditions) { if (constrain == valueFromConstrain) { bases.FactBase.FactList.Add(new Fact() { FactName = constrain, FactValue = true }); } else { bases.FactBase.FactList.Add(new Fact() { FactName = constrain, FactValue = false }); } } } viewModel.ValueFromConstrain = ""; }
void Extract() { ExtractedBin = new List <int>(NumBins); RemovedBin = new List <int>(NumBins); double dif = (Max - Min) / NumBins; var dicconstrains = Selector.Constrains(Table); var constrains = dicconstrains[Column]; int count = 0; for (int i = 1; i <= NumBins; ++i) { ExtractedBin.Add(0); RemovedBin.Add(0); double binMax = Min + dif * i; if (i == NumBins) { binMax = Max; } for (; count < Target.Count && Target[count] <= binMax; ++count) { bool remove = false; foreach (var constrain in constrains) { if (constrain == Origin || !constrain.Not) { continue; } if (!constrain.Evaluate(Target[count])) { remove = true; break; } } if (Constrain.Not && !Constrain.Evaluate(Target[count])) { remove = true; } if (!remove) { remove = true; int counttemp = 0; foreach (var constrain in constrains) { if (constrain == Origin || constrain.Not) { continue; } ++counttemp; if (constrain.Evaluate(Target[count])) { remove = false; break; } } if (counttemp == 0) { remove = false; } if (!Constrain.Not) { remove = true; if (Constrain.Evaluate(Target[count])) { remove = false; } } } if (remove) { RemovedBin[i - 1] = RemovedBin[i - 1] + 1; } else { ExtractedBin[i - 1] = ExtractedBin[i - 1] + 1; } } } MainChart.Series[0].Points.Clear(); MainChart.Series[1].Points.Clear(); MainChart.Series[2].Points.Clear(); for (int i = 0; i < NumBins; ++i) { var expoint = new DataPoint(i * dif + dif / 2 + Min, ExtractedBin[i]); var nexpoint = new DataPoint(i * dif + dif / 2 + Min, RemovedBin[i]); MainChart.Series[1].Points.Add(expoint); MainChart.Series[2].Points.Add(nexpoint); } if (Constrain.Not) { MainChart.Series[0].Points.Add(new DataPoint(Min, Highest)); MainChart.Series[0].Points.Add(new DataPoint(Constrain.Min, Highest)); MainChart.Series[0].Points.Add(new DataPoint(Constrain.Min, 0)); MainChart.Series[0].Points.Add(new DataPoint(Constrain.Max, 0)); MainChart.Series[0].Points.Add(new DataPoint(Constrain.Max, Highest)); MainChart.Series[0].Points.Add(new DataPoint(Max, Highest)); } else { MainChart.Series[0].Points.Add(new DataPoint(Min, 0)); MainChart.Series[0].Points.Add(new DataPoint(Constrain.Min, 0)); MainChart.Series[0].Points.Add(new DataPoint(Constrain.Min, Highest)); MainChart.Series[0].Points.Add(new DataPoint(Constrain.Max, Highest)); MainChart.Series[0].Points.Add(new DataPoint(Constrain.Max, 0)); MainChart.Series[0].Points.Add(new DataPoint(Max, 0)); } }
void OnSceneGUI() { float s = 40f; float s2 = s / 2f; //float sb = 30f; //float sb2 = sb/2f; float d = 160f; currentPath = (Path)target; e = Event.current; if (!editing) { } else { if (e.type == EventType.Layout) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } const int buttonWidth = 60; const int buttonHeight = 40; Handles.BeginGUI(); if (mode == Mode.Normal) { if (GUI.Button(new Rect(0, 0, buttonWidth, buttonHeight), "Add")) { mode = Mode.Add; } if (GUI.Button(new Rect(buttonWidth * 1, 0, buttonWidth, buttonHeight), "Rem")) { mode = Mode.Remove; } if (GUI.Button(new Rect(buttonWidth * 2, 0, buttonWidth, buttonHeight), "AvgX")) { mode = Mode.AvgX; } if (GUI.Button(new Rect(buttonWidth * 3, 0, buttonWidth, buttonHeight), "AvgY")) { mode = Mode.AvgY; } if (GUI.Button(new Rect(buttonWidth * 4, 0, buttonWidth, buttonHeight), "Recntr")) { Recenter(); } if (GUI.Button(new Rect(buttonWidth * 5, 0, buttonWidth, buttonHeight), "X")) { editing = false; } } else if (mode == Mode.Add) { if (GUI.Button(new Rect(0, 0, buttonWidth, buttonHeight), "X")) { mode = Mode.Normal; } Vector3 pos = Vector3.zero; for (int i = 0; i < currentPath.nodes.Length - 1; i++) { Vector3 p1 = currentPath.nodes[i].point; Vector3 p2 = currentPath.nodes[i + 1].point; Vector3 p = (p2 - p1) * .5f + p1; pos = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(currentPath.transform.TransformPoint(p)); if (GUI.Button(new Rect(pos.x - s2, Screen.height - pos.y - s2 - d * .25f, s, s), "Add")) { Undo.RegisterCompleteObjectUndo(currentPath, "Add Point"); ArrayUtility.Insert(ref currentPath.nodes, i + 1, new Path.Node(p)); break; } } // add buttons to beginning + end if (currentPath.nodes.Length > 1) { //const float maxDistance = 2f; //const float minDistance = .25f; { Vector3 p1 = currentPath.nodes[0].point; Vector3 p2 = currentPath.nodes[1].point; Vector3 p = p1 - (p2 - p1).normalized * .5f; pos = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(currentPath.transform.TransformPoint(p)); if (GUI.Button(new Rect(pos.x - s2, Screen.height - pos.y - s2 - d * .25f, s, s), "Add")) { Undo.RegisterCompleteObjectUndo(currentPath, "Add Point"); ArrayUtility.Insert(ref currentPath.nodes, 0, new Path.Node(p)); } } { Vector3 p1 = currentPath.nodes[currentPath.nodes.Length - 2].point; Vector3 p2 = currentPath.nodes[currentPath.nodes.Length - 1].point; Vector3 p = p2 + (p2 - p1).normalized * .5f; pos = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(currentPath.transform.TransformPoint(p)); /* * Vector3 pdiff = pos - entity.transform.TransformPoint(p1); * if (pdiff.sqrMagnitude > maxDistance * maxDistance) * { * pos = pdiff.normalized * maxDistance + entity.transform.TransformPoint(p1); * } * else if (pdiff.sqrMagnitude < minDistance * minDistance) * { * pos = pdiff.normalized * minDistance + entity.transform.TransformPoint(p1); * } */ if (GUI.Button(new Rect(pos.x - s2, Screen.height - pos.y - s2 - d * .25f, s, s), "Add")) { Undo.RegisterCompleteObjectUndo(currentPath, "Add Point"); ArrayUtility.Insert(ref currentPath.nodes, currentPath.nodes.Length, new Path.Node(p)); } } } else { } } else if (mode == Mode.Remove) { if (GUI.Button(new Rect(0, 0, buttonWidth, buttonHeight), "X")) { mode = Mode.Normal; } Vector3 pos = Vector3.zero; for (int i = 0; i < currentPath.nodes.Length; i++) { pos = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(currentPath.transform.TransformPoint(currentPath.nodes[i].point)); if (GUI.Button(new Rect(pos.x - s2, Screen.height - pos.y - s2, s, s), "Rem")) { Undo.RegisterCompleteObjectUndo(currentPath, "Remove Point"); ArrayUtility.RemoveAt(ref currentPath.nodes, i); break; } } } else if (mode == Mode.AvgX) { if (GUI.Button(new Rect(0, 0, buttonWidth, buttonHeight), "X")) { mode = Mode.Normal; } Vector3 pos = Vector3.zero; for (int i = 0; i < currentPath.nodes.Length - 1; i++) { Vector3 p1 = currentPath.nodes[i].point; Vector3 p2 = currentPath.nodes[i + 1].point; Vector3 p = (p2 - p1) * .5f + p1; pos = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(currentPath.transform.TransformPoint(p)); if (GUI.Button(new Rect(pos.x - s2, Screen.height - pos.y - s2 - d * .25f, s, s), "AvgX")) { Undo.RegisterCompleteObjectUndo(currentPath, "AvgX"); float avgX = (currentPath.nodes[i].point.x + currentPath.nodes[i + 1].point.x) * .5f; currentPath.nodes[i].point.x = currentPath.nodes[i + 1].point.x = avgX; break; } } } else if (mode == Mode.AvgY) { if (GUI.Button(new Rect(0, 0, buttonWidth, buttonHeight), "X")) { mode = Mode.Normal; } Vector3 pos = Vector3.zero; for (int i = 0; i < currentPath.nodes.Length - 1; i++) { Vector3 p1 = currentPath.nodes[i].point; Vector3 p2 = currentPath.nodes[i + 1].point; Vector3 p = (p2 - p1) * .5f + p1; pos = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(currentPath.transform.TransformPoint(p)); if (GUI.Button(new Rect(pos.x - s2, Screen.height - pos.y - s2 - d * .25f, s, s), "AvgY")) { Undo.RegisterCompleteObjectUndo(currentPath, "AvgY"); float avgY = (currentPath.nodes[i].point.y + currentPath.nodes[i + 1].point.y) * .5f; currentPath.nodes[i].point.y = currentPath.nodes[i + 1].point.y = avgY; break; } } } Handles.EndGUI(); } leftShift = e.shift; if (editing && currentPath.nodes != null && currentPath.nodes.Length > 0) { //Quit if panning or no camera exists if (Tools.current == Tool.View || (e.isMouse && e.button > 0) || Camera.current == null || e.type == EventType.ScrollWheel) { return; } //Quit if laying out if (e.type == EventType.Layout) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); return; } Vector3 screenMousePosition = new Vector3(e.mousePosition.x, Camera.current.pixelHeight - e.mousePosition.y); var plane = new Plane(-currentPath.transform.forward, currentPath.transform.position); var ray = Camera.current.ScreenPointToRay(screenMousePosition); float hit; if (plane.Raycast(ray, out hit)) { mousePosition = currentPath.transform.worldToLocalMatrix.MultiplyPoint(ray.GetPoint(hit)); } else { return; } if (state == State.Hover) { if (e.type == EventType.MouseDown) { for (int i = 0; i < currentPath.nodes.Length; i++) { if (IsHovering(currentPath.nodes[i].point)) { Undo.RegisterCompleteObjectUndo(currentPath, "Move Point"); //Undo.RecordObject(entity, "Move Point"); e.Use(); originalPoint = currentPath.nodes[i].point; dragOffset = currentPath.nodes[i].point - mousePosition; dragIndex = i; state = State.Drag; break; } } } } else if (state == State.Drag) { if (leftShift) { if (constrain == Constrain.None) { Vector3 moveDiff = mousePosition - originalPoint; if (moveDiff.sqrMagnitude > 0f) { if (Mathf.Abs(moveDiff.x) > Mathf.Abs(moveDiff.y)) { constrain = Constrain.Y; } else { constrain = Constrain.X; } } } } else { constrain = Constrain.None; } if (e.type == EventType.MouseUp) { state = State.Hover; e.Use(); } else if (e.type == EventType.MouseDown) { } else { Vector3 wantPosition = mousePosition + dragOffset; if (constrain == Constrain.None) { currentPath.nodes[dragIndex].point = wantPosition; } else if (constrain == Constrain.X) { currentPath.nodes[dragIndex].point = new Vector3(originalPoint.x, wantPosition.y, 0f); } else if (constrain == Constrain.Y) { currentPath.nodes[dragIndex].point = new Vector3(wantPosition.x, originalPoint.y, 0f); } } } Handles.matrix = currentPath.transform.localToWorldMatrix; for (int i = 0; i < currentPath.nodes.Length; i++) { if (i < currentPath.nodes.Length - 1) { Handles.DrawLine(currentPath.nodes[i].point, currentPath.nodes[i + 1].point); /* * if (currentPath.boxExtrude != 0f) * { * Vector3 diff = currentPath.points[i+1] - currentPath.points[i]; * diff.Normalize(); * diff = new Vector3(diff.y, -diff.x, 0f); * Handles.DrawLine(currentPath.points[i] + diff * currentPath.boxExtrude, * currentPath.points[i+1] + diff * currentPath.boxExtrude); * } */ } Handles.CircleCap(0, currentPath.nodes[i].point, Quaternion.identity, HandleUtility.GetHandleSize(currentPath.nodes[i].point) * 0.1f); } HandleUtility.Repaint(); if (GUI.changed) { EditorUtility.SetDirty(target); } } }
private void btnProceed_Click(object sender, EventArgs e) { if (txtDepositAmount.Text.Trim().Equals(String.Empty)) { } else if (Convert.ToDouble(txtDepositAmount.Text) < fee.Amount) { API.Message("You Have to Pay Opening Account Fee", MessageBoxIcon.Warning); } else { try { Account account = new Account { Names = txtAccNames.Text, PIN = txtPIN.Text, Balance = 0.0, Type = AccountType, UserId = Convert.ToInt32(User.Id) }; API.Controllers.Accounts.CreateAccount(account); account = API.Controllers.Accounts.FetchNewUserAccount(Convert.ToInt32(User.Id), account.Names); //process the deposit transaction //1.create a Transaction Object with Unique GUID //2.Create a TransactionDescription with unique GUID //3.Create a CreditDebit Object //{use the Transaction.GUID to find the Transaction.Id and //The TransactionDescription GUID to find the TransactionDescription.Id } Constrain constrain = new Constrain { Account = account, Amount = Convert.ToDouble(textBox2.Text), Time = getTimeRangeFromIndex(comboBox1.SelectedIndex) }; API.Controllers.AccountConstrains.Create(constrain); Transaction Transaction = new Transaction { TransationGUId = Guid.NewGuid().ToString(), TransationType = Transaction.TransactionTypes.DEPOSIT }; TransactionDescription TransactionDescription = new TransactionDescription { Description = "First Deposit", CreditAccount = account, DebitAccount = account, GUID = Guid.NewGuid().ToString() }; CreditDebit CreditDebit = new CreditDebit { Account = account, PrevBalance = 0.0, Credit = Convert.ToDouble(txtDepositAmount.Text) - fee.Amount, Transaction = Transaction, TransactionDescription = TransactionDescription, TransactionType = Models.Transaction.TransactionTypes.DEPOSIT }; Account systemAcc = API.Controllers.Accounts.FetchByAccountNumber(0); TransactionDescription TransactionOpeningFeeDescription = new TransactionDescription { Description = "Opening Fee : " + fee.Amount, CreditAccount = systemAcc, DebitAccount = account, GUID = Guid.NewGuid().ToString() }; CreditDebit creditFee = new CreditDebit { Account = systemAcc, Credit = fee.Amount, Transaction = Transaction, TransactionDescription = TransactionOpeningFeeDescription, TransactionType = Models.Transaction.TransactionTypes.ACCOUNT_CREATION_FEE }; try { API.Controllers.Transaction.Create(Transaction); Transaction = API.Controllers.Transaction.FindByGUID(Transaction.TransationGUId); CreditDebit.Transaction = Transaction; creditFee.Transaction = Transaction; API.Controllers.TransactionDescription.Create(TransactionOpeningFeeDescription); TransactionOpeningFeeDescription = API.Controllers.TransactionDescription.FindByGUID(TransactionOpeningFeeDescription.GUID); creditFee.TransactionDescription = TransactionOpeningFeeDescription; API.Controllers.TransactionDescription.Create(TransactionDescription); TransactionDescription = API.Controllers.TransactionDescription.FindByGUID(TransactionDescription.GUID); CreditDebit.TransactionDescription = TransactionDescription; API.Controllers.CreditDebit.Create(CreditDebit); API.Controllers.CreditDebit.Create(creditFee); CreditDebit = API.Controllers.CreditDebit.FindByTransactionId(Transaction.TransactionId); API.Message("Transaction Processed Successfully", MessageBoxIcon.Information); AccountDetails AccDetails = new AccountDetails(account); AccDetails.ShowDialog(); } catch (Exception ex) { API.Message(ex.Message, MessageBoxIcon.Error); return; } } catch (Exception ex) { API.Message(ex.Message, MessageBoxIcon.Error); return; } } }