private void theCanvas_MouseLeave(object sender, MouseEventArgs e) { theCanvas.Background = new SolidColorBrush(Colors.Gray); ModuleAttention parent = (ModuleAttention)base.ParentModule; parent.SetEnable(true); }
private void theCanvas_MouseEnter(object sender, MouseEventArgs e) { theCanvas.Background = new SolidColorBrush(Colors.LightSteelBlue); ModuleAttention parent = (ModuleAttention)base.ParentModule; parent.SetEnable(false); }
private void Poly_MouseDown(object sender, MouseButtonEventArgs e) { if (sender is Polygon poly) { Thing t = (Thing)poly.GetValue(AttentionObjectProperty); ModuleAttention parent = (ModuleAttention)base.ParentModule; parent.SetAttention(t); } }
public override bool Draw(bool checkDrawTimer) { if (!base.Draw(checkDrawTimer)) { return(false); } //this has a timer so that no matter how often you might call draw, the dialog //only updates 10x per second ModuleAttention parent = (ModuleAttention)base.ParentModule; theCanvas.Children.Clear(); Point windowSize = new Point(theCanvas.ActualWidth, theCanvas.ActualHeight); ModuleView naSource = MainWindow.theNeuronArray.FindModuleByLabel("UKS"); if (naSource == null) { return(false); } uks = (ModuleUKS)naSource.TheModule; Thing mentalModel = uks.GetOrAddThing("MentalModel", "Visual"); if (mentalModel == null || mentalModel.Children.Count == 0) { return(false); } Thing attn = uks.Labeled("ATTN"); if (attn == null || attn.References.Count == 0) { return(false); } Thing attnTarget = attn.GetReferenceWithAncestor(uks.Labeled("Visual")); var values = uks.GetValues(attnTarget); HSLColor c1 = new HSLColor(values["Hue+"], values["Sat+"], values["Lum+"]); Color fillColor = c1.ToColor(); try { double largest = 0; foreach (Thing area in mentalModel.Children) { var areaValues = uks.GetValues(area); Thing theShape = area.Children[0]; var shapeValues = uks.GetValues(theShape); PointPlus pOffset = new PointPlus(areaValues["CtrX+"] - shapeValues["CtrX+"], areaValues["CtrY+"] - shapeValues["CtrY+"]); foreach (Thing corner in theShape.Children) { Point p = (Point)corner.Children[0].V; p = p + pOffset; largest = Math.Max(largest, p.X); largest = Math.Max(largest, p.Y); } } largest += 10; //a little margin float scale = (float)Math.Min(windowSize.X, windowSize.Y) / (float)largest; if (scale == 0) { return(false); } theCanvas.Children.Clear(); foreach (Thing area in mentalModel.Children) { PointCollection pts = new PointCollection(); var areaValues = uks.GetValues(area); Thing theShape = area.Children[0]; var shapeValues = uks.GetValues(theShape); //These corrections are needed because known objects are stored at the location and size when they were first seen //now the viewed object will have a different size and location PointPlus pAreaCtr = new PointPlus(areaValues["CtrX+"], areaValues["CtrY+"]); PointPlus pShapeCtr = new PointPlus(shapeValues["CtrX+"], shapeValues["CtrY+"]); float areaSize = areaValues["Siz+"]; float shapeSize = shapeValues["Siz+"]; Angle areaAngle = areaValues["Ang+"]; Angle shapeAngle = shapeValues["Ang+"]; Angle rotation = areaAngle - shapeAngle; foreach (Thing corner in theShape.Children) { PointPlus p = new PointPlus((Point)corner.Children[0].V); p = p - pShapeCtr; p.Theta += rotation; float ratio = areaSize / shapeSize; p.X *= ratio; p.Y *= ratio; p = p + pAreaCtr; p.X *= scale; p.Y *= scale; pts.Add(p); } Polygon poly = new Polygon { Points = pts, Stroke = new SolidColorBrush(Colors.AliceBlue) }; poly.ToolTip = area.Label; poly.Fill = this.Background; if (attnTarget == area) { poly.Fill = new SolidColorBrush(fillColor); poly.Stroke = new SolidColorBrush(fillColor); poly.Fill.Opacity = 1; } poly.MouseDown += Poly_MouseDown; poly.SetValue(AttentionObjectProperty, area); theCanvas.Children.Add(poly); } } #pragma warning disable 168 catch (Exception e) //sometimes useful for debugging #pragma warning restore 168 { } return(true); }
//fill this method in with code which will execute //once for each cycle of the engine public override void Fire() { Init(); //be sure to leave this here ModuleView naSource = theNeuronArray.FindModuleByLabel("UKS"); if (naSource == null) { return; } uks = (ModuleUKS)naSource.TheModule; ModuleView attnSource = theNeuronArray.FindModuleByLabel("Attention"); if (attnSource == null) { return; } ModuleAttention m = (ModuleAttention)attnSource.TheModule; Thing mentalModelParent = uks.GetOrAddThing("MentalModel", "Visual"); Thing wordParent = uks.GetOrAddThing("Word", "Audible"); Thing attn = uks.GetOrAddThing("ATTN", "Thing"); if (words.Count > 0) { if (currentWord != "") { attn.RemoveReferencesWithAncestor(wordParent); } currentWord = words[0]; //is this a reference to a visible object? does it contain a digit? if (words[0].IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) != -1) { Thing t = uks.Labeled(words[0], mentalModelParent.Children); if (t != null) { if (naSource != null) { m.SetAttention(t, -1); } } } else { //process a single word & add it to the current phrase currentWord = char.ToUpper(currentWord[0]) + currentWord.Substring(1); Thing theWord = uks.GetOrAddThing("w" + currentWord, wordParent); attn.AddReference(theWord); } //delete the word from the top of the list words.RemoveAt(0); } else { if (attn.HasReferenceWithParent(wordParent) != null) { attn.RemoveReferencesWithAncestor(wordParent); m.SetAttention(null, 0); } } InnerMonologue(); //if you want the dlg to update, use the following code whenever any parameter changes UpdateDialog(); }