public void Translate(Vector _offset) { TranslateTransform transf = (TranslateTransform)this.RenderTransform; transf.X += _offset.X; transf.Y += _offset.Y; this.node_offset_hrzt += _offset.X; this.node_offset_vert += _offset.Y; this.RenderTransform = transf; this.Anchor += _offset; //var posTransf = this.TransformToAncestor(this.parent_canvas); //this.position = posTransf.Transform(new Point(0, 0)); this.position += _offset; this.Extents.SilentTranslation(_offset, true); foreach (NodeVisualization nvis in this.node_children) { nvis.Translate(_offset); } foreach (Polyline ncpl in this.node_connections_out) { NodeVisualization.TranslateUIElement(ncpl, _offset); } }
public void FitSize2Content() { // test for expansion foreach (object child in this.Children) { NodeVisualization nv = child as NodeVisualization; if (nv == null) { continue; } this.TestCanvasAgainstPointForExpansion(nv.Position, new Vector(nv.Width, nv.Height)); //this.TestCanvasAgainstPointForExpansion(nv.Extents.UpperLeft + nv.Extents.ParentTranslation, nv.Extents.LowerRight - nv.Extents.UpperLeft); } // test for contraction if (this.canvas_expand.X == 0 && this.canvas_expand.Y == 0) { this.canvas_expand = new Vector(this.Width, this.Height); foreach (object child in this.Children) { NodeVisualization nv = child as NodeVisualization; if (nv == null) { continue; } this.TestCanvasAgainstPointForContraction(nv.Position, new Vector(nv.Width, nv.Height)); //this.TestCanvasAgainstPointForContraction(nv.Extents.UpperLeft + nv.Extents.ParentTranslation, nv.Extents.LowerRight - nv.Extents.UpperLeft); } this.canvas_expand = -this.canvas_expand; } this.AdaptSize2Content(); }
protected Polyline Create2StepCalcToParamPolyline(Point _startP, Point _endP, double _node_start_H, double _node_end_H, bool _in) { if (this.parent_canvas == null) { return(null); } Polyline pline = new Polyline(); pline.Stroke = (_in) ? new SolidColorBrush(NodeVisualization.NODE_COLOR_CALC_IN) : new SolidColorBrush(NodeVisualization.NODE_COLOR_CALC_RET); pline.StrokeThickness = 1; pline.FillRule = FillRule.EvenOdd; // the offsets should allow subsequent polylines to avoid overlap double offset_size = 5 * NodeVisualization.NR_COMP_TO_PARAM_CONNECTION_CALLS; double offset_pos = 2 * NodeVisualization.NR_COMP_TO_PARAM_CONNECTION_CALLS; int arrow_dir = (_in) ? 1 : -1; PointCollection pointCollection = NodeVisualization.Create2StepPointCollectionWArrow(_startP + new Vector(0, offset_pos), _endP + new Vector(-0, offset_pos), _node_start_H + offset_size, _node_end_H + offset_size, new Vector(1, 1), arrow_dir); pline.Points = pointCollection; pline.Tag = new Point4D(_startP.X, _startP.Y, _endP.X, _endP.Y); string debug_1 = this.parent_canvas.CanvasConnectionInfo(); this.parent_canvas.Children.Add(pline); string debug_2 = this.parent_canvas.CanvasConnectionInfo(); // this can be reset, when needed NodeVisualization.NR_COMP_TO_PARAM_CONNECTION_CALLS++; return(pline); }
public void TranslateConnectionsIn(Vector _offset) { foreach (Polyline ncpl_in in this.node_connections_in) { // rebuild the polyline Point startP_new = ncpl_in.Points[0]; Point endP_old = ncpl_in.Points[ncpl_in.Points.Count - 1]; Point endP_new = new Point(endP_old.X + _offset.X, endP_old.Y + _offset.Y); ncpl_in.Points = NodeVisualization.CreateStepPointCollection(startP_new, endP_new); } }
protected static PointCollection Adapt2StepPointCollectionWArrow(PointCollection _points_old, Vector _offset, bool _affects_start, int _arrow_dir) { if (_points_old == null || _points_old.Count < 6) { return(_points_old); } Point startP_new, startP1_new, startP2_new, endP_new, endP1_new, endP2_new; if (_affects_start) { startP_new = _points_old[0] + _offset; startP1_new = _points_old[1] + _offset; startP2_new = _points_old[2] + _offset; endP_new = _points_old[_points_old.Count - 1]; endP1_new = _points_old[_points_old.Count - 2]; endP2_new = _points_old[_points_old.Count - 3]; } else { startP_new = _points_old[0]; startP1_new = _points_old[1]; startP2_new = _points_old[2]; endP_new = _points_old[_points_old.Count - 1] + _offset; endP1_new = _points_old[_points_old.Count - 2] + _offset; endP2_new = _points_old[_points_old.Count - 3] + _offset; } PointCollection points_new = new PointCollection(); points_new.Add(startP_new); points_new.Add(startP1_new); points_new.Add(startP2_new); // test if drawing an arrow is actually possible Vector test_dist = endP2_new - startP2_new; if (Math.Abs(test_dist.X) > NodeVisualization.NODE_MIN_LINE_LEN || Math.Abs(test_dist.Y) > NodeVisualization.NODE_MIN_LINE_LEN) { // draw the arrow PointCollection l_wArrow = NodeVisualization.CreateLinePointCollectionWArrow(startP2_new, endP2_new, _arrow_dir); foreach (Point p in l_wArrow) { points_new.Add(p); } } points_new.Add(endP2_new); points_new.Add(endP1_new); points_new.Add(endP_new); return(points_new); }
public void TranslateRefConnections(Vector _offset) { // REFERENCES foreach (Polyline ncpl_in in this.node_references_out) { // rebuild the polyline Point startP_old = ncpl_in.Points[0]; Point startP_new = new Point(startP_old.X + _offset.X, startP_old.Y + _offset.Y); Point endP_new = ncpl_in.Points[ncpl_in.Points.Count - 1]; ncpl_in.Points = NodeVisualization.Create2StepPointCollection(startP_new, endP_new, this.Height, this.Height, new Vector(1, -1)); } foreach (Polyline ncpl_in in this.node_references_in) { // rebuild the polyline Point startP_new = ncpl_in.Points[0]; Point endP_old = ncpl_in.Points[ncpl_in.Points.Count - 1]; Point endP_new = new Point(endP_old.X + _offset.X, endP_old.Y + _offset.Y); ncpl_in.Points = NodeVisualization.Create2StepPointCollection(startP_new, endP_new, this.Height, this.Height, new Vector(1, -1)); } // CONENCTIONS Calculation -> Parameter foreach (Polyline pl in this.node_param_calc_in) { // rebuild the polyline SolidColorBrush scb = pl.Stroke as SolidColorBrush; int arrow_dir = 0; if (scb != null) { arrow_dir = (scb.Color == NodeVisualization.NODE_COLOR_CALC_IN) ? 1 : -1; } pl.Points = NodeVisualization.Adapt2StepPointCollectionWArrow(pl.Points, _offset, false, arrow_dir); } foreach (Polyline pl in this.node_param_calc_out) { // rebuild the polyline SolidColorBrush scb = pl.Stroke as SolidColorBrush; int arrow_dir = 0; if (scb != null) { arrow_dir = (scb.Color == NodeVisualization.NODE_COLOR_CALC_IN) ? 1 : -1; } pl.Points = NodeVisualization.Adapt2StepPointCollectionWArrow(pl.Points, _offset, true, arrow_dir); } // recursion foreach (NodeVisualization nvis in this.node_children) { nvis.TranslateRefConnections(_offset); } }
protected Polyline Create2StepReferencePolyline(Point _startP, Point _endP, double _node_start_H, double _node_end_H, bool _direct = true) { if (this.parent_canvas == null) { return(null); } Polyline pline = new Polyline(); pline.Stroke = (_direct) ? new SolidColorBrush(NodeVisualization.NODE_COLOR_YES) : new SolidColorBrush(NodeVisualization.NODE_COLOR_MAYBE); pline.StrokeThickness = 2; pline.FillRule = FillRule.EvenOdd; PointCollection pointCollection = NodeVisualization.Create2StepPointCollection(_startP, _endP, _node_start_H, _node_end_H, new Vector(1, -1)); pline.Points = pointCollection; this.parent_canvas.Children.Add(pline); return(pline); }
protected Polyline CreateStepConnectingPolyline(Point _startP, Point _endP) { if (this.parent_canvas == null) { return(null); } Polyline pline = new Polyline(); pline.Stroke = new SolidColorBrush(NodeVisualization.NODE_COLOR_NO); pline.StrokeThickness = 2; pline.FillRule = FillRule.EvenOdd; PointCollection pointCollection = NodeVisualization.CreateStepPointCollection(_startP, _endP); pline.Points = pointCollection; this.parent_canvas.Children.Add(pline); return(pline); }
public void Highlight(List <Category> _cats, bool _or = true) { // reset this.UnHighlight(); List <NodeVisualization> to_highlight = new List <NodeVisualization>(); // gather information foreach (object child in this.Children) { NodeVisualization nv = child as NodeVisualization; if (nv == null) { continue; } bool take = !_or; foreach (Category cat in _cats) { if (_or) { take |= nv.VisCategory.HasFlag(cat); } else { take &= nv.VisCategory.HasFlag(cat); } } if (take) { to_highlight.Add(nv); } } // perform highlighting foreach (NodeVisualization nv in to_highlight) { nv.VisState |= NodeVisHighlight.Highlighted; } }
public void UnHighlight() { // gather information List <NodeVisualization> to_unhighlight = new List <NodeVisualization>(); foreach (object child in this.Children) { NodeVisualization nv = child as NodeVisualization; if (nv == null) { continue; } to_unhighlight.Add(nv); } // perform unhighlighting foreach (NodeVisualization nv in to_unhighlight) { nv.VisState &= ~NodeVisHighlight.Highlighted; } }
protected Polyline CreateBoundingBoxPolyline(BoundingBox _bb) { if (this.parent_canvas == null) { return(null); } if (_bb == null) { return(null); } Polyline pline = new Polyline(); pline.Stroke = new SolidColorBrush(NodeVisualization.NODE_COLOR_BB); pline.StrokeThickness = 2; pline.FillRule = FillRule.EvenOdd; PointCollection pointCollection = NodeVisualization.CreateBoundingBoxPointCollection(_bb.UpperLeft, _bb.LowerRight); pline.Points = pointCollection; this.parent_canvas.Children.Add(pline); return(pline); }