RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if (ContentBox.Contains(e.CanvasLocation)) { NelderMeadClass sc = Owner as NelderMeadClass; ((NelderMeadClass)this.Owner).ShowForm(); sc.ExpireSolution(true); return(Grasshopper.GUI.Canvas.GH_ObjectResponse.Handled); } return(Grasshopper.GUI.Canvas.GH_ObjectResponse.Ignore); }
/// <summary> /// RENDERING LAYOUT /// </summary> /// <param name="canvas"></param> /// <param name="graphics"></param> /// <param name="channel"></param> protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, System.Drawing.Graphics graphics, Grasshopper.GUI.Canvas.GH_CanvasChannel channel) { base.Render(canvas, graphics, channel); if (channel == Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects) { button = GH_Capsule.CreateTextCapsule(ButtonBounds, ButtonBounds, GH_Palette.Transparent, "", new int[] { 0, 0, 0, 5 }, 0); button.Render(graphics, Selected, Owner.Locked, false); button.Render(graphics, Color.FromArgb(255, 50, 100, 150)); button2 = GH_Capsule.CreateTextCapsule(ButtonBounds2, ButtonBounds2, GH_Palette.Transparent, "", new int[] { 0, 0, 5, 0 }, 0); button2.Render(graphics, Selected, Owner.Locked, false); button2.Render(graphics, Color.FromArgb(255, 230, 200, 10)); if (Globals.OpenThisShell[thisIndex2] == true) { System.Drawing.Drawing2D.LinearGradientBrush lgb = new System.Drawing.Drawing2D.LinearGradientBrush( rec0.Location, pythonRect.Location, System.Drawing.Color.FromArgb(255, 0, 200, 0), // Opaque red System.Drawing.Color.FromArgb(255, 0, 200, 0)); // Opaque blue); System.Drawing.Pen p = new System.Drawing.Pen(Color.Black, 1); p.DashCap = System.Drawing.Drawing2D.DashCap.Round; p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; Rectangle r5 = rec0; r5.Inflate(5, 5); // graphics.DrawLine(p, rec0.Location, pythonRect.Location); graphics.DrawPath(p, RoundedRect(r5, 3)); //graphics.DrawRectangle(p, rec0); } StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; Brush gg = new SolidBrush(Color.FromArgb(255, 50, 100, 150)); graphics.DrawString(Owner.NickName, GH_FontServer.Standard, gg, new PointF(rec0.Left, rec0.Bottom + 5)); button.Dispose(); } }
public override GH.GUI.Canvas.GH_ObjectResponse RespondToMouseDown(GH.GUI.Canvas.GH_Canvas sender, GH.GUI.GH_CanvasMouseEvent e) { if (link1.Contains(e.CanvasLocation)) { System.Diagnostics.Process.Start("https://strusoft.freshdesk.com/"); return(GH.GUI.Canvas.GH_ObjectResponse.Handled); } else if (link2.Contains(e.CanvasLocation)) { System.Diagnostics.Process.Start("https://wiki.fem-design.strusoft.com/"); return(GH.GUI.Canvas.GH_ObjectResponse.Handled); } else if (link3.Contains(e.CanvasLocation)) { System.Diagnostics.Process.Start("https://github.com/strusoft/femdesign-api"); return(GH.GUI.Canvas.GH_ObjectResponse.Handled); } return(GH.GUI.Canvas.GH_ObjectResponse.Ignore); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) //public override GH_ObjectResponse RespondToKeyDown(GH_Canvas sender, KeyEventArgs e) { //reset relevant lists this.Gradient = new List <List <double> >(); this.DifOne = new List <List <double> >(); this.DifTwo = new List <List <double> >(); this.DesignMapStepperOne = new List <List <double> >(); this.DesignMapStepperTwo = new List <List <double> >(); this.DesignMapStepperCombined = new List <List <double> >(); this.ObjValsOne = new List <List <double> >(); this.ObjValsTwo = new List <List <double> >(); numVars = MyComponent.numVars; numObjs = MyComponent.numObjs; // create design map stepper, which is the list of new points to be tested for (int i = 0; i < numVars; i++) { DesignMapStepperOne.Add(new List <double>()); DesignMapStepperTwo.Add(new List <double>()); } for (int i = 0; i < numVars; i++) { for (int j = 0; j < numVars; j++) { DesignMapStepperOne[i].Add(MyComponent.VarsVals[j]); DesignMapStepperTwo[i].Add(MyComponent.VarsVals[j]); } } for (int i = 0; i < numVars; i++) { double left = MyComponent.VarsVals[i] - 0.5 * MyComponent.StepSize * (MyComponent.MaxVals[i] - MyComponent.MinVals[i]); double right = MyComponent.VarsVals[i] + 0.5 * MyComponent.StepSize * (MyComponent.MaxVals[i] - MyComponent.MinVals[i]); DesignMapStepperOne[i][i] = left; DesignMapStepperTwo[i][i] = right; } // combine lists DesignMapStepperCombined.AddRange(DesignMapStepperOne); DesignMapStepperCombined.AddRange(DesignMapStepperTwo); // Add dummy at end to resent sliders DesignMapStepperCombined.Add(MyComponent.VarsVals); // run through both design maps, gather objective values on left and right for each variable MyComponent.ObjValues = new List <List <double> >(); MyComponent.Iterating = true; this.Iterate(); MyComponent.Iterating = false; for (int j = 0; j < numObjs; j++) { ObjValsOne.AddRange(MyComponent.ObjValues); } double maxObj = double.MinValue; double minObj = double.MaxValue; // find the gradient for each objective by taking finite differences of every variable for (int j = 0; j < numObjs; j++) { Gradient.Add(new List <double>()); for (int i = 0; i < numVars; i++) { double left = ObjValsOne[i][j]; double right = ObjValsOne[numVars + i][j]; double difference = (right - left) / (MyComponent.StepSize * (MyComponent.MaxVals[i] - MyComponent.MinVals[i])); if (difference > maxObj) { maxObj = difference; } if (difference < minObj) { minObj = difference; } Gradient[j].Add((double)difference); //Gradient[j].Add((double) maxObj); } //Normalize by max/min difference double maxAbs = double.MinValue; double vecLength = 0; if (Math.Abs(maxObj) > maxAbs) { maxAbs = Math.Abs(maxObj); } if (Math.Abs(minObj) > maxAbs) { maxAbs = Math.Abs(minObj); } for (int i = 0; i < numVars; i++) { Gradient[j][i] = (Gradient[j][i] / maxAbs); vecLength = vecLength + Gradient[j][i] * Gradient[j][i]; } for (int i = 0; i < numVars; i++) { Gradient[j][i] = (Gradient[j][i] / Math.Sqrt(vecLength)); } } //// FIND THE ORTHOGONAL VECTORS ////double[][] gradientArray = Gradient.Select(a => a.ToArray()).ToArray(); List <List <string> > lst = new List <List <string> >(); double[,] gradientArray = new double[Gradient.Count, Gradient[0].Count]; for (int j = 0; j < Gradient.Count; j++) { for (int i = 0; i < Gradient[j].Count; i++) { gradientArray[j, i] = Gradient[j][i]; } } var matrixGrad = MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.OfArray(gradientArray); var matrixGradT = matrixGrad.Transpose(); var nullspace = matrixGradT.Kernel(); // STRATEGY 1: Direct to Array double[] nullspaceArray; for (int i = 1; i < 2; i++) { nullspaceArray = nullspace[i].ToArray(); } // STRATEGY 2: One Line to Array //double[] IsoPerfDir = nullspace.ToArray()[1].ToArray(); double[] IsoPerfDir2 = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; //STRATEGY 3: STRING IN THE MIDDLE //string IsoPerfDir = nullspace.ToArray()[0].ToString(); //List<double> IsoPerfDir3 = (List<double>)StringToDoubleList(IsoPerfDir); //var IsoPerfMatrix = nullspace; //IsoPerf.Add(IsoPerfMatrix[1]); //// Randomly assign coefficient, create isoperformance direction //Random rnd = new Random(); //int isoDir = rnd.Next(0, numVars - 1); //// Convert array to List for (int i = 0; i < numVars; i++) { IsoPerf.Add(IsoPerfDir2[i]); } // step in the right direction based on the gradient vector List <IGH_Param> sliderlist = new List <IGH_Param>(); foreach (IGH_Param src in MyComponent.Params.Input[0].Sources) { sliderlist.Add(src); } for (int i = 0; i < numVars; i++) { if (MyComponent.Direction > 0) { Grasshopper.Kernel.Special.GH_NumberSlider nslider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderlist[i]; double SteppedSlider = MyComponent.VarsVals[i] + Gradient[MyComponent.ObjNum][i] * MyComponent.StepSize; nslider.TrySetSliderValue((decimal)SteppedSlider); } if (MyComponent.Direction < 0) { Grasshopper.Kernel.Special.GH_NumberSlider nslider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderlist[i]; double SteppedSlider = MyComponent.VarsVals[i] - Gradient[MyComponent.ObjNum][i] * MyComponent.StepSize; nslider.TrySetSliderValue((decimal)SteppedSlider); } /// TAKE STEP IN ORTHOGONAL DIRECTION //if (MyComponent.Direction == 0) //{ //Grasshopper.Kernel.Special.GH_NumberSlider nslider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderlist[i]; //double SteppedSlider = MyComponent.VarsVals[i] - IsoPerf[i] * MyComponent.StepSize; //nslider.TrySetSliderValue((decimal)SteppedSlider); //} } Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); //return base.RespondToKeyDown(sender, e); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) //public override GH_ObjectResponse RespondToKeyDown(GH_Canvas sender, KeyEventArgs e) { //reset relevant lists this.Gradient = new List <List <double> >(); this.DifOne = new List <List <double> >(); this.DifTwo = new List <List <double> >(); this.DesignMapStepperOne = new List <List <double> >(); this.DesignMapStepperTwo = new List <List <double> >(); this.DesignMapStepperCombined = new List <List <double> >(); this.ObjValsOne = new List <List <double> >(); this.ObjValsTwo = new List <List <double> >(); this.IsoPerf = new List <List <double> >(); this.GradLengths = new List <double>(); this.deltaSlider = new List <double>(); numVars = MyComponent.numVars; numObjs = MyComponent.numObjs; //Set Finite Differences step size FDstep = 0.01; angle = 0; double iterationlimit = 0; while (iterationlimit < 1000) { TakeStep(); iterationlimit++; if (angle > MyComponent.threshold) { stepped = true; break; } } return(base.RespondToMouseDoubleClick(sender, e)); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <returns></returns> public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if (!Globals.OpenThisShell.ContainsKey(thisIndex2)) { Globals.OpenThisShell.Add(thisIndex2, true); shellOpened = true; Owner.ExpirePreview(false); //Owner.ExpireSolution(true); } else { Globals.OpenThisShell[thisIndex2] = true; shellOpened = true; Owner.ExpirePreview(false); //Owner.ExpireSolution(true); } return(Grasshopper.GUI.Canvas.GH_ObjectResponse.Handled); }
protected override void PrepareForRender(Grasshopper.GUI.Canvas.GH_Canvas canvas) { base.PrepareForRender(canvas); LayoutMenuCollection(); }
// this function takes care of the drawing routines protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics, Grasshopper.GUI.Canvas.GH_CanvasChannel channel) { if (channel != Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects) { return; } // render of original component //Bounds = _baseBounds; base.Render(canvas, graphics, channel); //Bounds = _thisBounds; int width = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard); PointF p = new PointF(this.Pivot.X + width + 19, this.Pivot.Y - 7); List <double> probs = own.probabilities; PointF[] pts = getHistoPts(own.probabilities); if (own.draw_flag == "s") { pts = getPts(probs); } PointF maxPt = new PointF(0, 0); float ptY = pts[0].Y; int index_max = 0; for (int i = 0; i < pts.Length; i++) { if (pts[i].Y < ptY) { ptY = pts[i].Y; index_max = i; } } maxPt = pts[index_max]; // Create Pens System.Drawing.Pen pen2 = new System.Drawing.Pen(Brushes.Red, 2); System.Drawing.Pen pen = new System.Drawing.Pen(Brushes.Black, 2); System.Drawing.Pen pen3 = new System.Drawing.Pen(Brushes.GhostWhite, 1); // Create Gradient Brush System.Drawing.Drawing2D.LinearGradientBrush lb = new System.Drawing.Drawing2D.LinearGradientBrush (new PointF(maxPt.X, maxPt.Y), new PointF(maxPt.X, this.Pivot.Y), Color.FromArgb(255, 0, 0), Color.FromArgb(255, 255, 255)); System.Drawing.SolidBrush sb = new System.Drawing.SolidBrush(Color.FromArgb(70, 255, 255, 255)); // Rui // render background bins RectangleF[] backgroundBins = getBackgroundBins(own.probabilities); graphics.DrawRectangles(pen3, backgroundBins); graphics.FillRectangles(sb, backgroundBins); backgroundBinBounds = backgroundBins; //Draw Polygon ouline and fill graphics.DrawPolygon(pen, pts); graphics.FillPolygon(lb, pts); //Owner.NickName = "Variable"; // Draw probability value // string evidence = "Y<5 string s = "P(MINIMIZE Y)=" + (this.bins((float)Owner.CurrentValue) * 100).ToString() + "%"; //string s = (Owner.CurrentValue + 1).ToString(); //double cv = Owner.CurrentValue; graphics.DrawString(s, GH_FontServer.Standard, Brushes.Black, pts[1].X + 15, (int)(this.Pivot.Y - 8 - glob.max_ht)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if ((ContentBox.Contains(e.CanvasLocation))) { CurrentOwner.SOLVE = true; // hit the export straight away, where we handle the folder selection! CurrentOwner.Export(); CurrentOwner.ExpireSolution(true); return(Grasshopper.GUI.Canvas.GH_ObjectResponse.Handled); } return(Grasshopper.GUI.Canvas.GH_ObjectResponse.Ignore); }