/// <summary> /// Gets the links connecting to the given LinkNode. /// </summary> /// <param name="linkNode">The given LinkNode.</param> /// <returns>The links collection which connects to the given LinkNode.</returns> public GOMLib.GOM_Links GetLinks(GOMLib.GOM_Object_LinkNode linkNode) { GOMLib.GOM_Links links = new GOMLib.GOM_Links(); for( int i=0; i<m_rgLinks.Count; i++ ) { if ( m_rgLinks[i].m_startPt == linkNode.LinkPoint || m_rgLinks[i].m_endPt == linkNode.LinkPoint ) { links.Add(m_rgLinks[i]); } } return links; }
/// <summary> /// Merge two links into one. /// </summary> /// <param name="link1">The first link.</param> /// <param name="link2">The second link.</param> /// <param name="linkNode">The LinkNode between these two given links.</param> /// <returns>The new link.</returns> public GOMLib.GOM_Link MergeLinks(GOMLib.GOM_Link link1, GOMLib.GOM_Link link2, GOMLib.GOM_Object_LinkNode linkNode) { GOMLib.GOM_Link link; if ( link1.m_startPt == link2.m_endPt ) { link = GOMLib.GOM_Default_Values.CreateLink(link2.m_endObj, link2.m_endPt, link1.m_startObj, link1.m_startPt); } else if ( link1.m_endPt == link2.m_startPt ) { link = GOMLib.GOM_Default_Values.CreateLink(link1.m_startObj, link1.m_startPt, link2.m_endObj, link2.m_endPt); } else { GOMLib.GOM_Point pt1 = (link1.m_startPt==linkNode.LinkPoint) ? link1.m_endPt : link1.m_startPt; GOMLib.GOM_Point pt2 = (link2.m_startPt==linkNode.LinkPoint) ? link2.m_endPt : link2.m_startPt; GOMLib.GOM_Interface_Graphic_Object obj1 = (link1.m_startPt==linkNode.LinkPoint) ? link1.m_endObj : link1.m_startObj; GOMLib.GOM_Interface_Graphic_Object obj2 = (link2.m_startPt==linkNode.LinkPoint) ? link2.m_endObj : link2.m_startObj; link = GOMLib.GOM_Default_Values.CreateLink(obj1, pt1, obj2, pt2); } m_rgLinks.Remove(link1); m_rgLinks.Remove(link2); m_rgObjects.Remove(linkNode); m_rgLinks.Add(link); return link; }
public bool cRestriction(GOMLib.GOM_Link link) { string id1 = link.m_startObj.id; string id2 = link.m_endObj.id; //get the two class for checking by their id GOMLib.GOM_Object_Primitive obj1 = null; GOMLib.GOM_Object_Primitive obj2 = null; try { for (int i = 0; i < m_rgObjects.Count; i++) { if (m_rgObjects[i].id == id1) obj1 = (GOMLib.GOM_Object_Primitive)m_rgObjects[i] ; if (m_rgObjects[i].id == id2) obj2 = (GOMLib.GOM_Object_Primitive)m_rgObjects[i]; if (obj1 != null && obj2 != null) break; } } catch { return true; } if (obj1 == null || obj2 == null) return true; //Start Checking bool check1, check2; check1 = check_Start(obj1, obj2, link); check2 = check_Start(obj2, obj1, link); return (check1 && check2); }
/// <summary> /// Gets LinkNode by the given point. /// </summary> /// <param name="point">The given point.</param> /// <returns>The LinkNode. If there is no LinkNode under the given point, return null.</returns> public GOMLib.GOM_Object_LinkNode GetLinkNode(GOMLib.GOM_Point point) { for( int i=0; i<m_rgObjects.Count; i++ ) { GOMLib.GOM_Object_LinkNode linkNode = m_rgObjects[i] as GOMLib.GOM_Object_LinkNode; if ( linkNode != null ) { if ( linkNode.LinkPoint == point ) { return linkNode; } } } return null; }
public void PushSketchAndWait(GOMLib.GOM_Object_Sketch sketchObj, System.Collections.ArrayList sketch) { m_Mutex.WaitOne(); m_curSketchObj = sketchObj; HandlePreprocessResult(m_preprocess.RecognizeStroke(EncodeSketchToXML(sketch))); m_Mutex.ReleaseMutex(); }
private void ReloadStrokesFromXML(GOMLib.GOM_Object_Sketch sketchObj, string strokeXML) { System.Xml.XmlDocument doc; System.Xml.XmlNode rootNode; System.Xml.XmlNode strokesNode; System.Xml.XmlNode candidateNode; doc = new System.Xml.XmlDocument(); doc.LoadXml(strokeXML); rootNode = doc.DocumentElement; if (rootNode != null) { //Look for <output> if (System.String.Compare(rootNode.Name, "output", true) == 0) { sketchObj.rgDrawings.Clear(); for (int i = 0; i < rootNode.ChildNodes.Count; i++) { //Look for <strokes> if (System.String.Compare(rootNode.ChildNodes[i].Name, "strokes", true) == 0) { strokesNode = rootNode.ChildNodes[i]; //Look for <candidate> with maximum similarity for (int j = 0; j < strokesNode.ChildNodes.Count; j++) { if (System.String.Compare(strokesNode.ChildNodes[j].Name, "candidate", true) == 0) { candidateNode = strokesNode.ChildNodes[j]; for (int k = 0; k < candidateNode.ChildNodes.Count; k++) { if (System.String.Compare(candidateNode.ChildNodes[k].Name, "line", true) == 0) { sketchObj.rgDrawings.Add(DecodeXMLToLine(candidateNode.ChildNodes[k])); } if (System.String.Compare(candidateNode.ChildNodes[k].Name, "arc", true) == 0) { sketchObj.rgDrawings.Add(DecodeXMLToArc(candidateNode.ChildNodes[k])); } } } } } } } } }
/// <summary> /// Add a link. When the link needs to be merged, the mergemence occurs. /// </summary> /// <param name="link"></param> public void AddLinkWithMergemence(GOMLib.GOM_Link link) { GOMLib.GOM_Object_LinkNode startLinkNode = GetLinkNode(link.m_startPt); GOMLib.GOM_Object_LinkNode endLinkNode = GetLinkNode(link.m_endPt); //Restriction check if (!cRestriction(link)) { System.Windows.Forms.MessageBox.Show("One of the devices reach to the maxmium connection limit or null connection is used."); return; } if ( startLinkNode == null && endLinkNode == null ) { m_rgLinks.Add(link); return; } bool needAddLink = false; bool merged = false; if ( startLinkNode != null ) { GOMLib.GOM_Links startLinks = GetLinks(startLinkNode); if ( startLinks.Count == 0 ) { GOMLib.GOM_Link splittedLink = GetLinkByPoint(link.m_startPt.x, link.m_startPt.y); if ( splittedLink !=null ) { SplitLink(splittedLink, startLinkNode); } needAddLink = true; } else if ( startLinks.Count == 1 ) { MergeLinks(startLinks[0], link, startLinkNode); merged = true; } else { needAddLink = true; } } if ( endLinkNode != null && !merged ) { GOMLib.GOM_Links endLinks = GetLinks(endLinkNode); if ( endLinks.Count == 0 ) { GOMLib.GOM_Link splittedLink = GetLinkByPoint(link.m_endPt.x, link.m_endPt.y); if ( splittedLink !=null ) { SplitLink(splittedLink, endLinkNode); } needAddLink = true; } else if ( endLinks.Count == 1 ) { MergeLinks(endLinks[0], link, endLinkNode); } else { needAddLink = true; } } if ( needAddLink ) { m_rgLinks.Add(link); } }
//show the name of device and info in diagram public void Show_info(Graphics canvas, GOMLib.GOM_Objects m_rgObjects) { ArrayList templist = getDeviceList(); IEnumerator enumtmp = templist.GetEnumerator(); Font myFont = new Font("Times New Roman", 10); RectangleF m_boundingBox = new System.Drawing.RectangleF(0, 0, 10, 10); System.Drawing.Drawing2D.LinearGradientBrush myBrush = new System.Drawing.Drawing2D.LinearGradientBrush(m_boundingBox, Color.Black, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.Horizontal); try { while (enumtmp.MoveNext()) { for (int i = 0; i < m_rgObjects.Count; i++) { string tname, tvalue, tunit; if (m_rgObjects[i].id.ToString() == ((EEDomain.Device)enumtmp.Current).GetID().ToString()) { try { tname = ((EEDomain.Device)enumtmp.Current).GetQName(); if (tname == null) { return; } } catch (Exception) { tname = "D" + ((EEDomain.Device)enumtmp.Current).GetName(); } //tvalue = ((EEDomain.Device)enumtmp.Current).GetMainValue(); tvalue = ""; tunit = ((EEDomain.Device)enumtmp.Current).GetUnit(); canvas.DrawString(tname + " = " + tvalue + tunit, myFont, myBrush, m_rgObjects[i].xOffset - 5, m_rgObjects[i].yOffset - 20); break; } } } } catch { } }
private void m_frmLink_LinkStyleChanged(GOMLib.GOM_Link link) { DrawObjectsOnCanvas(); }
private void m_frmLink_RemoveLink(GOMLib.GOM_Link link) { m_rgLinks.Remove(link); tagLink.HideTagWindow(); m_selectedLink = null; DrawObjectsOnCanvas(); }
private void m_frmColor_FillingStyleChanged(GOMLib.GOM_Object_Primitive primitive, GOMLib.GOM_Style_Filling style) { DrawObjectsOnCanvas(); }
private void SetLinkStyle(GOMLib.GOM_Link link) { SetDrawingStyle(link.m_drawingStyle); bUnderSettingStyle = true; cbPoints_SelectedIndexChanged(null, null); bUnderSettingStyle = false; }
private void SetDrawingStyle(GOMLib.GOM_Style_Drawing style) { bUnderSettingStyle = true; bond_ini(); switch (style.drawingStyle.DashStyle) { case System.Drawing.Drawing2D.DashStyle.Solid: { rbpSolid.Checked = true; break; } case System.Drawing.Drawing2D.DashStyle.Dot: { rbpDot.Checked = true; break; } case System.Drawing.Drawing2D.DashStyle.Dash: { rbpDash.Checked = true; break; } case System.Drawing.Drawing2D.DashStyle.DashDot: { rbpDashDot.Checked = true; break; } case System.Drawing.Drawing2D.DashStyle.DashDotDot: { rbpDashDotDot.Checked = true; break; } } drawingColor.Color = style.drawingStyle.Color; edtWidth.Value = (decimal)style.drawingStyle.Width; bUnderSettingStyle = false; }
/// <summary> /// Split the link into two links by a LinkNode. /// </summary> /// <param name="splittedLink">The link which will be splitted.</param> /// <param name="splitNode">The LinkNode.</param> public void SplitLink(GOMLib.GOM_Link splittedLink, GOMLib.GOM_Object_LinkNode splitNode) { GOMLib.GOM_Link firstPart = GOMLib.GOM_Default_Values.CreateLink(splittedLink.m_startObj, splittedLink.m_startPt, splitNode, splitNode.LinkPoint); GOMLib.GOM_Link secondPart = GOMLib.GOM_Default_Values.CreateLink(splitNode, splitNode.LinkPoint, splittedLink.m_endObj, splittedLink.m_endPt); m_rgLinks.Remove(splittedLink); m_rgLinks.Add(firstPart); m_rgLinks.Add(secondPart); }
public void PushSketch(GOMLib.GOM_Object_Sketch sketchObj, System.Collections.ArrayList sketch) { m_Mutex.WaitOne(); m_rgSketchObj.Add(sketchObj); m_rgSketch.Add(sketch); m_QueueNotEmpty.Set(); m_Mutex.ReleaseMutex(); }
//check restriction private bool check_Start(GOMLib.GOM_Object_Primitive obj_check, GOMLib.GOM_Object_Primitive obj_temp, GOMLib.GOM_Link link) { for (int i = 0; i < obj_check.res_list.varlist.Count; i++) { GOMLib.XMLline templine = (GOMLib.XMLline)obj_check.res_list.varlist[i]; switch (templine.type) { case "connect_notallow": #region "function" string temps = templine.access("point"); if (temps == ".self") { if (obj_check.id == obj_temp.id) return false; } else { if (temps != "") { string[] words = temps.Split(','); string tempname = obj_temp.var_list.access("info", "name"); //get the name of the obj_temp for (int j = 0; j < words.Length; j++) { if (words[j] == tempname) return false; } } } break; #endregion case "connect_max": #region "function" try { int maxno = int.Parse(templine.access("value")); int tempcount = 0; for (int j = 0; j < m_rgLinks.Count; j++) { if (m_rgLinks[j].m_endObj.id == obj_check.id) tempcount = tempcount + 1; else if (m_rgLinks[j].m_startObj.id == obj_check.id) tempcount = tempcount + 1; if (tempcount == maxno) return false; } break; } catch { return true; } #endregion case "connect_point": #region "function" return true; break; #endregion }//end main switch } return true; }
private void frmStencil_TemplateSelected(GOMLib.GOM_Template template) { DrawingForm frmDrawing; if (this.ActiveMdiChild != null) { frmDrawing = (DrawingForm)this.ActiveMdiChild; if (frmDrawing.status.Action == UserActions.Sketching) { frmDrawing.FinishCurrentSketchObject(); } frmDrawing.status.Action = UserActions.InsertObject; frmDrawing.status.Template = template; } }