public override GH_ObjectResponse RespondToMouseUp(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if (_drawing) { _drawing = false; sender.CanvasPostPaintObjects -= CanvasPostPaintObjects; GH_Document doc = sender.Document; if (doc != null) { IGH_Attributes att = doc.FindAttribute(e.CanvasLocation, true); if (att != null) { if (att.DocObject is IModifiable) { Owner.RecordUndoEvent("Add Modifier"); Owner.AddTarget(att.DocObject.InstanceGuid); IGH_ActiveObject obj = att.DocObject as IGH_ActiveObject; if (obj != null) { obj.ExpireSolution(true); } } } } sender.Invalidate(); return(GH_ObjectResponse.Release); } return(base.RespondToMouseUp(sender, e)); }
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); }
public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { System.Drawing.Rectangle rec = ButtonBounds; if (rec.Contains((int)e.CanvasLocation.X, (int)e.CanvasLocation.Y)) { MessageBox.Show("Still under Development", "Refresh", MessageBoxButton.OK); System.Drawing.Graphics g = null; button.Render(g, Color.Blue); return(GH_ObjectResponse.Handled); } } return(base.RespondToMouseDown(sender, e)); }
public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { _drawing = false; _drawingBox = InnerBounds; if (e.Button == System.Windows.Forms.MouseButtons.Left) { // If on outer disc, but not in inner disc.. then start a wire drawing process. bool onOuterDisc = Grasshopper.GUI.GH_GraphicsUtil.IsPointInEllipse(Bounds, e.CanvasLocation); bool onInnerDisc = Grasshopper.GUI.GH_GraphicsUtil.IsPointInEllipse(InnerBounds, e.CanvasLocation); if (onOuterDisc && !onInnerDisc) { // Begin arrow drawing behaviour. _drawing = true; sender.CanvasPostPaintObjects += CanvasPostPaintObjects; return(GH_ObjectResponse.Capture); } } // Otherwise revert to default behaviour. return(base.RespondToMouseDown(sender, e)); }
public override GH_ObjectResponse RespondToMouseMove(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if (_drawing) { _drawingBox = new RectangleF(e.CanvasLocation, new SizeF(0, 0)); GH_Document doc = sender.Document; if (doc != null) { IGH_Attributes att = doc.FindAttribute(e.CanvasLocation, true); if (att != null) { if (att.DocObject is IModifiable) { _drawingBox = att.Bounds; } } } sender.Invalidate(); return(GH_ObjectResponse.Handled); } return(base.RespondToMouseMove(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { // Convert orthogonal matrix to list numLevels = MyComponent.numLevels; numObj = MyComponent.numObjs; //Three level matrices int[,] EffectIndicesOpt1 = new int[, ] { { 0, 0, 0, 0 }, { 0, 1, 1, 1 }, { 0, 2, 2, 2 }, { 1, 0, 1, 2 }, { 1, 1, 2, 0 }, { 1, 2, 0, 1 }, { 2, 0, 2, 1 }, { 2, 1, 0, 2 }, { 2, 2, 1, 0 } }; int[,] EffectIndicesOpt2 = new int[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, { 0, 1, 1, 1, 0, 0, 0, 1, 2, 1, 2, 1, 2 }, { 0, 1, 1, 1, 1, 1, 1, 2, 0, 2, 0, 2, 0 }, { 0, 1, 1, 1, 2, 2, 2, 0, 1, 0, 1, 0, 1 }, { 0, 2, 2, 2, 0, 0, 0, 2, 1, 2, 1, 2, 1 }, { 0, 2, 2, 2, 1, 1, 1, 0, 2, 0, 2, 0, 2 }, { 0, 2, 2, 2, 2, 2, 2, 1, 0, 1, 0, 1, 0 }, { 1, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 2, 1 }, { 1, 0, 1, 2, 1, 2, 0, 1, 1, 2, 0, 0, 2 }, { 1, 0, 1, 2, 2, 0, 1, 2, 2, 0, 1, 1, 0 }, { 1, 1, 2, 0, 0, 1, 2, 1, 2, 2, 1, 0, 0 }, { 1, 1, 2, 0, 1, 2, 0, 2, 0, 0, 2, 1, 1 }, { 1, 1, 2, 0, 2, 0, 1, 0, 1, 1, 0, 2, 2 }, { 1, 2, 0, 1, 0, 1, 2, 2, 1, 0, 0, 1, 2 }, { 1, 2, 0, 1, 1, 2, 0, 0, 2, 1, 1, 2, 0 }, { 1, 2, 0, 1, 2, 0, 1, 1, 0, 2, 2, 0, 1 }, { 2, 0, 2, 1, 0, 2, 1, 0, 0, 2, 1, 1, 2 }, { 2, 0, 2, 1, 1, 0, 2, 1, 1, 0, 2, 2, 0 }, { 2, 0, 2, 1, 2, 1, 0, 2, 2, 1, 0, 0, 1 }, { 2, 1, 0, 2, 0, 2, 1, 1, 2, 0, 0, 2, 1 }, { 2, 1, 0, 2, 1, 0, 2, 2, 0, 1, 1, 0, 2 }, { 2, 1, 0, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0 }, { 2, 2, 1, 0, 0, 2, 1, 2, 1, 1, 2, 0, 0 }, { 2, 2, 1, 0, 1, 0, 2, 0, 2, 2, 0, 1, 1 }, { 2, 2, 1, 0, 2, 1, 0, 1, 0, 0, 1, 2, 2 } }; //2 level matrices int[,] EffectIndicesOpt3 = new int[, ] { { 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 1, 1, 1 }, { 0, 1, 1, 0, 0, 1, 1 }, { 0, 1, 1, 1, 1, 0, 0 }, { 1, 0, 1, 0, 1, 0, 1 }, { 1, 0, 1, 1, 0, 1, 0 }, { 1, 1, 0, 0, 1, 1, 0 }, { 1, 1, 0, 1, 0, 0, 1 } }; int[,] EffectIndicesOpt4 = new int[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 }, { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, { 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }, { 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0 }, { 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 }, { 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1 }, { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }, { 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 }, { 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0 }, { 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 }, { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0 }, { 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1 }, { 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1 }, { 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 } }; if (MyComponent.numLevels == 2) { if (MyComponent.numVars < 7) { EffectIndices = EffectIndicesOpt3; numFactors = MyComponent.numVars; numRows = 8; } else { EffectIndices = EffectIndicesOpt4; numFactors = MyComponent.numVars; numRows = 16; } } if (MyComponent.numLevels == 3) { if (MyComponent.numVars < 5) { EffectIndices = EffectIndicesOpt1; numFactors = MyComponent.numVars; numRows = 9; } else { EffectIndices = EffectIndicesOpt2; numFactors = MyComponent.numVars; numRows = 27; } } for (int i = 0; i < numRows; i++) { EffectIndicesList.Add(new List <int>()); } for (int i = 1; i < numRows + 1; i++) { for (int j = 1; j < numFactors + 1; j++) { EffectIndicesList[i - 1].Add(EffectIndices[i - 1, j - 1]); } } // Create Design Map of levels samples for (int i = 0; i < numRows; i++) { DesignMapEffects.Add(new List <double>()); } for (int k = 0; k < numRows; k++) { for (int j = 0; j < MyComponent.numVars; j++) { double setting = MyComponent.MinVals[j] + (MyComponent.LevelSettings[EffectIndices[k, j]] * (MyComponent.MaxVals[j] - MyComponent.MinVals[j])); DesignMapEffects[k].Add(setting); } } // Reset list of objective values MyComponent.ObjValues = new List <List <double> >(); MyComponent.Iterating = true; this.Iterate(); MyComponent.Iterating = false; // Calculate overall averages for (int i = 0; i < numObj; i++) { double objSum = 0; int count = 0; for (int j = 0; j < numRows; j++) { objSum = objSum + MyComponent.ObjValues[j][i]; count++; } OverallAvg.Add(objSum / (double)count); } // Calculate effects averages for each variable for (int i = 0; i < MyComponent.numObjs; i++) { IndEffectsSum.Add(new List <List <List <double> > >()); for (int j = 0; j < MyComponent.numVars; j++) { IndEffectsSum[i].Add(new List <List <double> >()); for (int k = 0; k < MyComponent.numLevels; k++) { IndEffectsSum[i][j].Add(new List <double>()); } } } // Create list of objective values for each variable level for (int l = 0; l < MyComponent.numObjs; l++) { for (int i = 0; i < MyComponent.numVars; i++) { for (int j = 0; j < numLevels; j++) { for (int k = 0; k < numRows; k++) { if (EffectIndices[k, i] == j) { IndEffectsSum[l][i][j].Add(MyComponent.ObjValues[k][l]); } else { }; } } } } // Calculate raw effects // Create list of objective values for each variable level for (int l = 0; l < MyComponent.numObjs; l++) { IndEffectsAvg.Add(new List <List <double> >()); for (int i = 0; i < MyComponent.numVars; i++) { IndEffectsAvg[l].Add(new List <double>()); } } for (int l = 0; l < MyComponent.numObjs; l++) { for (int i = 0; i < MyComponent.numVars; i++) { for (int j = 0; j < numLevels; j++) { IndEffectsAvg[l][i].Add(IndEffectsSum[l][i][j].Average() - OverallAvg[l]); } } } //Calculate Average effect of each variable for (int i = 0; i < MyComponent.numObjs; i++) { OverallEff.Add(new List <double>()); } for (int i = 0; i < MyComponent.numObjs; i++) { for (int j = 0; j < MyComponent.numVars; j++) { double effsum = 0; int count = 0; for (int k = 0; k < IndEffectsAvg[i][j].Count; k++) { effsum = effsum + Math.Abs(IndEffectsAvg[i][j][k]); count++; } OverallEff[i].Add(effsum / (double)count); } } MyComponent.EffectsDone = true; Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { MyComponent.WriterDone = true; Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { return(c.SelectFolderDialog()); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if (MyComponent.Seed != 0) { MyComponent.MyRand = new Random(MyComponent.Seed); } // reset Random to give same result each time. MyComponent.Util.Sample(); if (MyComponent.Dir != "None") { PrintAllSolutions(); MyComponent.FilesWritten = "Yes"; } Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if (MyComponent.SlidersList.Count != MyComponent.DesignMap[MyComponent.Index].Count) { throw new Exception("Error: Number of sliders and number of target values must be equal."); } for (int i = 0; i < MyComponent.SlidersList.Count; i++) { Grasshopper.Kernel.Special.GH_NumberSlider s = MyComponent.SlidersList[i]; double d = MyComponent.DesignMap[MyComponent.Index][i]; s.SetSliderValue((decimal)d); } Grasshopper.Instances.ActiveCanvas.Document.NewSolution(false, GH_SolutionMode.Default); //Grasshopper.Instances.ActiveCanvas.Document.NewSolution(false); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { // Read in Cluster number slider List <IGH_Param> sliderListClust = new List <IGH_Param>(); foreach (IGH_Param src2 in MyComponent.Params.Input[4].Sources) { sliderListClust.Add(src2); } Grasshopper.Kernel.Special.GH_NumberSlider clusterSlider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderListClust[0]; if (!MyComponent.ClusterDone) { //run clustering process KMeans kmeans = new KMeans(MyComponent.numClusters); double[][] data = MyComponent.DesignMap.Select(a => a.ToArray()).ToArray(); double[] weights = null; // int[] labels = kmeans.Learn(data,weights); for (int i = 0; i < data.Count(); i++) { data[i] = data[i].Take(data[i].Count() - MyComponent.numObjs).ToArray(); } int[] labels = kmeans.Compute(data); LabelsList = labels.OfType <int>().ToList(); // Set cluster slider bounds, values to default while clustering is run clusterSlider.TrySetSliderValue((decimal)0); clusterSlider.Slider.Minimum = ((decimal)0); clusterSlider.Slider.Maximum = ((decimal)MyComponent.numClusters); // list management this.DesignMap = MyComponent.DesignMap; this.numVars = MyComponent.numVars; // create Sorted list for (int i = 0; i < MyComponent.numClusters; i++) { DesignMapSorted.Add(new List <List <double> >()); for (int j = 0; j < DesignMap.Count; j++) { if (LabelsList[j] == i) { DesignMapSorted[i].Add(DesignMap[j]); } } } for (int i = 0; i < MyComponent.numClusters; i++) { ClusterAves.Add(new List <double>()); ClusterMaxs.Add(new List <double>()); ClusterMins.Add(new List <double>()); double[] sum = new double[numVars]; double[] average = new double[numVars]; double[] max = new double[numVars]; double[] min = new double[numVars]; for (int l = 0; l < numVars; l++) { sum[l] = 0; max[l] = double.MinValue; min[l] = double.MaxValue; } for (int j = 0; j < DesignMapSorted[i].Count; j++) { for (int k = 0; k < numVars; k++) { sum[k] = sum[k] + DesignMapSorted[i][j][k]; if (DesignMapSorted[i][j][k] > max[k]) { max[k] = DesignMapSorted[i][j][k]; } else if (DesignMapSorted[i][j][k] < min[k]) { min[k] = DesignMapSorted[i][j][k]; } average[k] = sum[k] / DesignMapSorted[i].Count; } } for (int k = 0; k < numVars; k++) { ClusterAves[i].Add(average[k]); ClusterMaxs[i].Add(max[k]); ClusterMins[i].Add(min[k]); } } ClusterAves.Insert(0, MyComponent.VarsVals); ClusterMaxs.Insert(0, MyComponent.MaxVals); ClusterMins.Insert(0, MyComponent.MinVals); //for (int i = 0; i < DesignMapSorted.Count; i++) //{ //LabelsList[i] = LabelsList[i] + 1; //} } 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.index != 0) { Grasshopper.Kernel.Special.GH_NumberSlider nslider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderList[i]; double adjmin = ClusterMins[MyComponent.index][i] + (1 - MyComponent.flexibility) * (ClusterAves[MyComponent.index][i] - ClusterMins[MyComponent.index][i]); double adjmax = ClusterMaxs[MyComponent.index][i] - (1 - MyComponent.flexibility) * (ClusterMaxs[MyComponent.index][i] - ClusterAves[MyComponent.index][i]); nslider.TrySetSliderValue((decimal)ClusterAves[MyComponent.index][i]); nslider.Slider.Minimum = ((decimal)adjmin); nslider.Slider.Maximum = ((decimal)adjmax); } else { Grasshopper.Kernel.Special.GH_NumberSlider nslider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderList[i]; nslider.TrySetSliderValue((decimal)ClusterAves[MyComponent.index][i]); nslider.Slider.Minimum = ((decimal)ClusterMins[MyComponent.index][i]); nslider.Slider.Maximum = ((decimal)ClusterMaxs[MyComponent.index][i]); } } MyComponent.ClusterDone = true; Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { if (MyComponent.Seed != 0) { MyComponent.MyRand = new Random(MyComponent.Seed); } // reset Random to give same result each time. // Reset list of objective values MyComponent.ObjValues = new List <List <double> >(); MyComponent.ObjValues = new List <List <double> >(); variablesSliders = MyComponent.readSlidersList(); NSGAIIProblem problem = new NSGAIIProblem("ArrayReal", MyComponent, solutionsCounter); NSGAIIRunner runner = new NSGAIIRunner(null, problem, null, MyComponent); allSolutionsTrack = problem.allSolutions; problem.PrintAllSolutions(); problem.PrintLogFile(); solutionsCounter++; MyComponent.MooDone = true; Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); MessageBox.Show("Finished"); //System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\New folder\123d.txt"); //file.WriteLine("" + problem.allSolutions.Count); //file.Close(); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { // Reset list of objective values MyComponent.ObjValues = new List <List <double> >(); MyComponent.PropertyValues = new List <List <double> >(); MyComponent.FirstRead = true; MyComponent.Iterating = true; this.Iterate(); MyComponent.Iterating = false; Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true, GH_SolutionMode.Silent); 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); }
//[STAThread] public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { //Prevent opening of multiple windows at once if (!MyComponent.IsWindowOpen && MyComponent.InputsSatisfied) { MyComponent.IsWindowOpen = true; Design design = new Design(MyComponent); Thread viewerThread = new Thread(delegate() { RadicalVM radVM = new RadicalVM(design, this.MyComponent); Window viewer = new RadicalWindow(radVM); viewer.Show(); System.Windows.Threading.Dispatcher.Run(); }); viewerThread.SetApartmentState(ApartmentState.STA); // needs to be STA or throws exception viewerThread.Start(); } return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { GHUtilities.ChangeSliders(MyComponent.SlidersList, MyComponent.DesignMap[MyComponent.Index]); Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { ((ToObjTextComponent)Owner).OnExport(this, EventArgs.Empty); return(base.RespondToMouseDoubleClick(sender, e)); }
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> >(); 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)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { // Read in Cluster number slider List <IGH_Param> sliderListClust = new List <IGH_Param>(); foreach (IGH_Param src2 in MyComponent.Params.Input[4].Sources) { sliderListClust.Add(src2); } Grasshopper.Kernel.Special.GH_NumberSlider clusterSlider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderListClust[0]; //Set all cluster values if (MyComponent.ClusterDone) { DesignMapSorted = MyComponent.DesignMapSorted; ClusterAves = MyComponent.ClusterAves; ClusterMaxs = MyComponent.ClusterMaxs; ClusterMins = MyComponent.ClusterMins; ClusterLabelsList = MyComponent.ClusterLabelsList; int numVars = MyComponent.numVars; 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 input is not zero, reset sliders based on clusters properties if (MyComponent.index != 0) { Grasshopper.Kernel.Special.GH_NumberSlider nslider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderList[i]; double adjmin = ClusterMins[MyComponent.index][i] + (1 - MyComponent.flexibility) * (ClusterAves[MyComponent.index][i] - ClusterMins[MyComponent.index][i]); double adjmax = ClusterMaxs[MyComponent.index][i] - (1 - MyComponent.flexibility) * (ClusterMaxs[MyComponent.index][i] - ClusterAves[MyComponent.index][i]); nslider.Slider.Minimum = ((decimal)adjmin); nslider.Slider.Maximum = ((decimal)adjmax); nslider.TrySetSliderValue((decimal)ClusterAves[MyComponent.index][i]); } else { Grasshopper.Kernel.Special.GH_NumberSlider nslider = (Grasshopper.Kernel.Special.GH_NumberSlider)sliderList[i]; nslider.Slider.Minimum = ((decimal)ClusterMins[MyComponent.index][i]); nslider.Slider.Maximum = ((decimal)ClusterMaxs[MyComponent.index][i]); nslider.TrySetSliderValue((decimal)ClusterAves[MyComponent.index][i]); } } } Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { this.MyComponent.modelType = "Test"; this.buildModel(); this.MyComponent.modelCreated = true; Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { ((MaterialEditor)Owner).ShowEditor(); return(Grasshopper.GUI.Canvas.GH_ObjectResponse.Handled); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { //Prevent opening of multiple windows at once if (!MyComponent.IsWindowOpen) { MyComponent.IsWindowOpen = true; StepperVM VM = new StepperVM(this.MyComponent); Thread viewerThread = new Thread(delegate() { System.Windows.Window viewer = new StepperWindow(VM); viewer.Show(); System.Windows.Threading.Dispatcher.Run(); }); viewerThread.SetApartmentState(ApartmentState.STA); // needs to be STA or throws exception viewerThread.Start(); } //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> >(); //TO TEST OUTPUTS test.Add(new List <double>()); test[0].Add(248.0); numVars = MyComponent.numVars; numObjs = MyComponent.numObjs; //Set Finite Differences step size FDstep = 0.01; // 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 * FDstep * (MyComponent.MaxVals[i] - MyComponent.MinVals[i]); double right = MyComponent.VarsVals[i] + 0.5 * FDstep * (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) / (FDstep); //* (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 matrixGrad = MathNet.Numerics.LinearAlgebra.Double.Matrix.Abs(14.0); //var matrixGradT = matrixGrad.Transpose(); var nullspace = matrixGrad.Kernel(); // Convert array to List of nullspace vectors if (numVars > numObjs) { for (int i = 0; i < numVars - numObjs; i++) { IsoPerf.Add(new List <double>()); double[] IsoPerfDir = nullspace[i].ToArray(); IsoPerf[i].AddRange(IsoPerfDir); } } // Randomly pick an isoperformance direction Random rnd = new Random(); int dir = new int(); int testrand = new int(); testrand = rnd.Next(numVars - numObjs); dir = testrand; // Ensure that direction is "interesting" //for (int i = testrand; i < numVars - numObjs - 1; i++) //{ // dir = i; // List<double> IsoVecAbs = IsoPerf[i].Select(x => Math.Abs(x)).ToList(); // IsoVecAbs.Sort(); // double a = IsoVecAbs[numVars - 1]; // double b = IsoVecAbs[numVars - 2]; // double c = a / b; // if (c < 3) { break; } // else { dir = dir + 1; } //} //for (int i = 0; i < numVars - numObjs; i++) //{ // for (int j = 0; j < IsoPerf[i].Count; j++) // { // IsoPerf.Add(new List<double>()); // double[] IsoPerfDir = nullspace[i].ToArray(); // } //} List <double> IsoPerfDirList = IsoPerf[dir]; // 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 * (MyComponent.MaxVals[i] - MyComponent.MinVals[i]); 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 * (MyComponent.MaxVals[i] - MyComponent.MinVals[i]); 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] + IsoPerfDirList[i] * MyComponent.StepSize * MyComponent.numVars; nslider.TrySetSliderValue((decimal)SteppedSlider); } } stepped = true; Grasshopper.Instances.ActiveCanvas.Document.NewSolution(true); return(base.RespondToMouseDoubleClick(sender, e)); }
public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(Grasshopper.GUI.Canvas.GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e) { MyComponent.DesignView.InitialDesign = new DesignVM(MyComponent.DesignLines, MyComponent.DesignCurves, MyComponent.DesignMeshes, MyComponent.DesignBreps, false, true, MyComponent.Score, MyComponent.Design); Window w = new StormCloudWindow(MyComponent.DesignView, MyComponent); w.Show(); 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> >(); 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) { 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); }