public override void process(Object dragTarget) { if (dragTarget is Diagram) { Diagram diagram = (Diagram)dragTarget; saveDrag = diagram; // save the diagram and instance reference for event below PolygonDrawingTool polyTool = new PolygonDrawingTool(diagram); diagram.Tool = polyTool; polyTool.PolygonCreatedWithPoints += new PolygonDrawingTool.OnPolygonCreatedWithPoints(polyTool_PolygonCreatedWithPoints); diagram.Tool.Start(); } }
public SensorNode(Diagram dg, List<String> actionValues, XPathNavigator nodeNav, ImageList globalIl, int nodeID, int linkID, String nodeName, String nodeType, List<Function> nodeFunctions, bool xyFromDB, ref int startX, ref int startY, Dictionary<int, DiagramNode> docNodes) { // for now, copy DiagramNode creation. String imagePath = nodeType; //String imagePath = String.Empty; //String paramValueForImage = FunctionHelper.GetParameterValue(actionValues[0], nodeNav); //try //{ // imagePath = FunctionHelper.UpdateImageList(nodeImages, paramValueForImage); //} //catch (Exception ex) //{ // //MessageBox.Show(ex.Message, "Image Load"); // // use type //} dg.LoadNode(nodeID, linkID, nodeName, nodeType, nodeFunctions, imagePath, xyFromDB, ref startX, ref startY, docNodes); // also lookup and add sensor information ComponentOptions options = new ComponentOptions(); options.LevelDown = 1; options.LinkParams = false; options.CompParams = false; String IDConstant = XmlSchemaConstants.Display.Component.Id; String ValueConstant = ConfigFileConstants.Value; XPathNavigator createEvent = null; IXPathNavigable navigable; XPathNavigator nav; // Event to CreateEvent navigable = dg.Controller.GetComponentAndChildren(nodeID, "EventID", options); nav = navigable.CreateNavigator(); createEvent = nav.SelectSingleNode("Components/Component/Component"); if (createEvent != null) { int createEventID = Int32.Parse(createEvent.GetAttribute(IDConstant, nav.NamespaceURI)); // CreateEvent to Species navigable = dg.Controller.GetComponentAndChildren(createEventID, "CreateEventKind", options); nav = navigable.CreateNavigator(); XPathNavigator species = nav.SelectSingleNode("Components/Component/Component"); if (species != null) { int speciesID = Int32.Parse(species.GetAttribute(IDConstant, nav.NamespaceURI)); // Species to FullyFunctional navigable = dg.Controller.GetComponentAndChildren(speciesID, "Scenario", options); nav = navigable.CreateNavigator(); XPathNavigator fullyFunctional = nav.SelectSingleNode("Components/Component/Component[@Name='FullyFunctional']"); if (fullyFunctional != null) { int ffID = Int32.Parse(fullyFunctional.GetAttribute(IDConstant, nav.NamespaceURI)); // Species to Sensor options.CompParams = true; navigable = dg.Controller.GetComponentAndChildren(ffID, "StateSensor", options); nav = navigable.CreateNavigator(); XPathNodeIterator allSensors = nav.Select("Components/Component/Component"); // Sensor.Attribute_Sensor // Sensor.Global_Sensor // Sensor.Attribute // Sensor.Range String globalSensor = String.Empty; String attributeSensor = String.Empty; String attribute = String.Empty; String range = String.Empty; int largestRange = 0; foreach (XPathNavigator sensor in allSensors) { int sensorID = Int32.Parse(sensor.GetAttribute(IDConstant, nav.NamespaceURI)); // is it global or attribute = location XPathNavigator globalNav = sensor.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='Sensor'][@displayedName='Global_Sensor']"); if (globalNav != null) { globalSensor = globalNav.GetAttribute(ValueConstant, globalNav.NamespaceURI); } XPathNavigator attributeSensorNav = sensor.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='Sensor'][@displayedName='Attribute_Sensor']"); if (attributeSensorNav != null) { attributeSensor = attributeSensorNav.GetAttribute(ValueConstant, attributeSensorNav.NamespaceURI); } XPathNavigator attributeNav = sensor.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='Sensor'][@displayedName='Attribute']"); if (attributeNav != null) { attribute = attributeNav.GetAttribute(ValueConstant, attributeNav.NamespaceURI); } XPathNavigator rangeNav = sensor.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='Sensor'][@displayedName='Range']"); if (rangeNav != null) { range = rangeNav.GetAttribute(ValueConstant, rangeNav.NamespaceURI); } if (globalSensor.Equals("true", StringComparison.CurrentCultureIgnoreCase) || (attributeSensor.Equals("true", StringComparison.CurrentCultureIgnoreCase) && attribute.Equals("Location")) ) { // use range int rangeInt = Int32.Parse(range); if (rangeInt > largestRange) { largestRange = rangeInt; } String srSpread = String.Empty; String srRange = String.Empty; // check sensor ranges navigable = dg.Controller.GetComponentAndChildren(sensorID, "Scenario", options); nav = navigable.CreateNavigator(); XPathNodeIterator srsNav = nav.Select("Components/Component/Component[@Type='SensorRange']"); foreach (XPathNavigator srNav in srsNav) { // check spread and range XPathNavigator spreadNav = srNav.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='SensorRange'][@displayedName='Spread']"); if (spreadNav != null) { srSpread = spreadNav.GetAttribute(ValueConstant, spreadNav.NamespaceURI); } XPathNavigator srRangeNav = srNav.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='SensorRange'][@displayedName='Range']"); if (srRangeNav != null) { srRange = srRangeNav.GetAttribute(ValueConstant, srRangeNav.NamespaceURI); } int spread = Int32.Parse(srSpread); if (spread == 360) { rangeInt = Int32.Parse(srRange); if (rangeInt > largestRange) { largestRange = rangeInt; } } } } } if (largestRange > 0) { // meters to pixels if (dg.CoordinateTransformer != null) { largestRange = (int)dg.CoordinateTransformer.RetrieveX(largestRange); } GoEllipse sensorEllipse = new GoEllipse(); sensorEllipse.Pen = new Pen(Color.Green, 2.0f); sensorEllipse.Position = new PointF(startX-(largestRange/2), startY-(largestRange/2)); sensorEllipse.Size = new SizeF(largestRange, largestRange); sensorEllipse.Movable = false; sensorEllipse.Selectable = false; dg.Document.Add(sensorEllipse); } } } } }
private void LoadDiagrams(IController aController, String[] linkTypes) { if (aController == null || linkTypes == null || linkTypes.Length == 0) { return; } List<String> linkTypesList = new List<String>(linkTypes); diagrams.Clear(); grids.Clear(); combos.Clear(); myController = aController; IXPathNavigable globalComponent = (myController).GetLinks(); if (globalComponent == null) { return; } XPathNavigator nav = globalComponent.CreateNavigator(); XPathNodeIterator diagramIterator = nav.Select("Link"); String name; String linkType; String description; String dynamicType; Diagram templateDiagram; DiagramGridPanel templateGrid; int index = tabControl1.TabPages.Count; foreach (XPathNavigator collectionNav in diagramIterator) { linkType = collectionNav.GetAttribute(ConfigFileConstants.Type, collectionNav.NamespaceURI); if (linkTypesList.Contains(linkType)) { name = collectionNav.GetAttribute(ConfigFileConstants.Name, collectionNav.NamespaceURI); description = collectionNav.GetAttribute(ConfigFileConstants.description, collectionNav.NamespaceURI); dynamicType = collectionNav.GetAttribute(ConfigFileConstants.dynamicType, collectionNav.NamespaceURI); //diagram templateDiagram = new Diagram(); templateDiagram.DiagramName = linkType; templateDiagram.Controller = myController; templateDiagram.Dock = DockStyle.Fill; templateDiagram.MouseMove += new MouseEventHandler(Diagram_MouseMove); templateDiagram.DragOver += new DragEventHandler(Diagram_DragOver); templateDiagram.PropertyChanged += new PropertyChangedEventHandler(templateDiagram_PropertyChanged); // turn off linking by default templateDiagram.ReplaceMouseTool(typeof(GoToolLinking), null); templateDiagram.ReplaceMouseTool(typeof(GoToolLinkingNew), null); templateDiagram.ReplaceMouseTool(typeof(GoToolRelinking), null); // diagrams.Add(index, templateDiagram); //grid templateGrid = new DiagramGridPanel(); templateGrid.LinkType = linkType; templateGrid.LinkName = name; templateGrid.Controller = myController; templateGrid.ParameterName = GetParameterName(collectionNav); templateGrid.Dock = DockStyle.Fill; grids.Add(index, templateGrid); // initialize tab name and place the diagram in the appropriate tab CustomTabPage tabPage = new CustomTabPage(); tabPage.Text = name; tabPage.Description = description; tabPage.Controls.Add(templateDiagram); tabControl1.TabPages.Add(tabPage); if (dynamicType != null && dynamicType.Length > 0) { CustomToolStrip toolStripAboveDiagram = new CustomToolStrip(); ToolStripLabel toolStripLabel = new ToolStripLabel(); ToolStripSeparator toolStripSeperator = new ToolStripSeparator(); CustomComboToolStripItem toolStripCombo = new CustomComboToolStripItem(); toolStripAboveDiagram.Dock = DockStyle.Top; foreach (Control c in tabPage.Controls) { if (c is Diagram) { c.Dock = DockStyle.None; // anchor instead of dock c.Location = new Point(0, 55); // move down c.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; Size set = new Size(); set.Width = tabPage.Width - 5; // 5 for buffer set.Height = tabPage.Height - 25 - 28 - 5; // 25 for the combo, 28 for the label, 5 for buffer c.Size = set; } } tabPage.Controls.Add(toolStripAboveDiagram); toolStripAboveDiagram.Controller = myController; toolStripAboveDiagram.Location = new Point(0, 0); toolStripAboveDiagram.Size = new System.Drawing.Size(tabControl1.Width, 25); toolStripLabel.Text = dynamicType; toolStripCombo.Controller = myController; toolStripCombo.Type = dynamicType; // Event EventTask toolStripCombo.LinkType = myController.ConfigurationLinkType; // e.g. Tree toolStripCombo.SelectedIDChangedEvent += new CustomComboToolStripItem.SelectedIDChanged(toolStripCombo_SelectedIDChangedEvent); toolStripAboveDiagram.Items.AddRange(new ToolStripItem[] { toolStripLabel, toolStripSeperator, toolStripCombo }); combos.Add(index, toolStripCombo); // update hashmap } index++; } } diagramList.Clear(); foreach (Diagram d in diagrams.Values) { diagramList.Add(d); } gridList.Clear(); foreach (DiagramGridPanel g in grids.Values) { gridList.Add(g); } // initialize filters for all diagrams if (filterTypes != null) { int filterCount = filterTypes.Length; if (filterCount > 0) { for (int i = 0; i < filterCount; i++) { String filterTypeString = filterTypes[i]; ToolStripButton filterButton = new ToolStripButton(filterTypeString); filterButton.Checked = true; // initially checked filterButton.Click += new EventHandler(filterButton_Click); foreach (Diagram d in diagramList) // initially, all types are shown { d.AddTypeFilter(filterButton.Text); d.AddTypeFilter("fill"); } filterToolStrip.Items.Add(filterButton); } } else { FilterStripVisible = false; } } else { FilterStripVisible = false; } }
public CustomCombo GetDynamicCombo(Diagram d) { int index = diagramList.IndexOf(d); if (index != -1) { if (combos.ContainsKey(index)) { return combos[index].CustomComboControl; } else { return null; } } else { return null; } }
private void ProcessHoverOrDragWithDocPoint(PointF docPoint, Diagram dg) { if (usingGeoReferenceUTM) { Double xGeo = Convert.ToDouble(this.easting) + docPoint.X * Convert.ToDouble(this.xPixel) + docPoint.Y * Convert.ToDouble(this.xRotation); Double yGeo = Convert.ToDouble(this.northing) + docPoint.Y * Convert.ToDouble(this.yPixel) + docPoint.X * Convert.ToDouble(this.yRotation); labelCoord.Text = String.Format("{0:0.00} E {1:0.00} N", xGeo, yGeo); } else { // use custom transform int printX = (int)docPoint.X; int printY = (int)docPoint.Y; if (dg != null && dg.CoordinateTransformer != null) { printX = (int)dg.CoordinateTransformer.StoreX(printX); printY = (int)dg.CoordinateTransformer.StoreY(printY); } labelCoord.Text = String.Format("X: {0} Y: {1}", printX, printY); } }