/// <summary> /// Select or unselect edge /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pictureBoxPreview_MouseClick(object sender, MouseEventArgs e) { if (m_activeElem == null || e.Button != MouseButtons.Left) { return; } ElementGeometry elemGeom = m_creationData.Creator.ElemGeomDic[m_activeElem]; foreach (Edge edge in m_creationData.Creator.SupportEdges[m_activeElem]) { if (elemGeom.EdgeBindingDic.ContainsKey(edge)) { if (elemGeom.EdgeBindingDic[edge].IsHighLighted) { bool isSelect = elemGeom.EdgeBindingDic[edge].IsSelected; elemGeom.EdgeBindingDic[edge].IsHighLighted = false; elemGeom.EdgeBindingDic[edge].IsSelected = !isSelect; TreeNode node = GetEdgeTreeNode(edge); CheckState state = isSelect ? CheckState.Unchecked : CheckState.Checked; UpdateNodeCheckStatus(node, state); pictureBoxPreview.Refresh(); treeViewHost.Refresh(); return; } } } }
/// <summary> /// Clear Highlighted status of all highlighted edges. /// </summary> private void ClearAllHighLight() { if (m_activeElem == null) { return; } ElementGeometry elemGeom = m_creationData.Creator.ElemGeomDic[m_activeElem]; foreach (Edge edge in m_creationData.Creator.SupportEdges[m_activeElem]) { elemGeom.EdgeBindingDic[edge].IsHighLighted = false; } }
/// <summary> /// Update tree node check status, it will impact its children and parents' status. /// </summary> /// <param name="node">Tree node to update</param> /// <param name="state">CheckState value</param> private void UpdateNodeCheckStatus(TreeNode node, CheckState state) { node.StateImageIndex = (int)state; if (node.Tag != null && node.Tag is Edge && m_activeElem != null) { Edge edge = node.Tag as Edge; Autodesk.Revit.DB.Element elem = node.Parent.Tag as Autodesk.Revit.DB.Element; ElementGeometry elemGeom = m_creationData.Creator.ElemGeomDic[elem]; elemGeom.EdgeBindingDic[edge].IsSelected = (node.StateImageIndex == (int)CheckState.Checked); } UpdateChildren(node); UpdateParent(node); }
/// <summary> /// Highlight the edge in the preview /// if mouse-over an edge tree-node. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeViewHost_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e) { TreeNode node = e.Node; treeViewHost.SelectedNode = e.Node; ClearAllHighLight(); ActiveNode(node); pictureBoxPreview.Refresh(); if (m_activeElem == null || node.Tag == null || !(node.Tag is Edge)) { return; } ElementGeometry elemGeom = m_creationData.Creator.ElemGeomDic[m_activeElem]; elemGeom.EdgeBindingDic[node.Tag as Edge].IsHighLighted = true; pictureBoxPreview.Refresh(); }
/// <summary> /// Draw the geometry. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pictureBoxPreview_Paint(object sender, PaintEventArgs e) { if (m_activeElem == null) { return; } ElementGeometry elemGeo = null; if (!m_creationData.Creator.ElemGeomDic.TryGetValue(m_activeElem, out elemGeo)) { return; } e.Graphics.Transform = m_centerMatrix; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; elemGeo.Draw(e.Graphics); }
/// <summary> /// Rotate or zoom the displayed geometry, or highlight the edge under the mouse location. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pictureBoxPreview_MouseMove(object sender, MouseEventArgs e) { if (m_activeElem == null) { return; } m_trackBall.OnMouseMove(e); if (e.Button == MouseButtons.Left) { m_creationData.Creator.ElemGeomDic[m_activeElem].Rotation *= m_trackBall.Rotation; pictureBoxPreview.Refresh(); } else if (e.Button == MouseButtons.Right) { m_creationData.Creator.ElemGeomDic[m_activeElem].Scale *= m_trackBall.Scale; pictureBoxPreview.Refresh(); } if (e.Button == MouseButtons.None) { ClearAllHighLight(); pictureBoxPreview.Refresh(); Matrix mat = (Matrix)m_centerMatrix.Clone(); mat.Invert(); PointF[] pts = new PointF[1] { e.Location }; mat.TransformPoints(pts); ElementGeometry elemGeom = m_creationData.Creator.ElemGeomDic[m_activeElem]; foreach (Edge edge in m_creationData.Creator.SupportEdges[m_activeElem]) { if (elemGeom.EdgeBindingDic.ContainsKey(edge)) { if (elemGeom.EdgeBindingDic[edge].HighLight(pts[0].X, pts[0].Y)) { pictureBoxPreview.Refresh(); } } } } }
/// <summary> /// Recursively update tree children's status to match its parent status. /// </summary> /// <param name="node">Parent node whose children will be updated</param> private void UpdateChildren(TreeNode node) { foreach (TreeNode child in node.Nodes) { if (child.StateImageIndex != node.StateImageIndex) { child.StateImageIndex = node.StateImageIndex; if (m_activeElem != null && child.Tag != null && child.Tag is Edge) { Edge edge = child.Tag as Edge; Autodesk.Revit.DB.Element elem = child.Parent.Tag as Autodesk.Revit.DB.Element; ElementGeometry elemGeom = m_creationData.Creator.ElemGeomDic[elem]; elemGeom.EdgeBindingDic[edge].IsSelected = (child.StateImageIndex == (int)CheckState.Checked); } } UpdateChildren(child); } }