Exemplo n.º 1
0
        public void Load(string filename)
        {
            // We assume model is clear.

            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            BaseCurve.Points.Clear();
            XmlNode dictNode      = doc.SelectSingleNode("plist/dict");
            XmlNode baseCurveNode = dictNode.SelectSingleNode("base-curve");

            BaseCurve.Color = Color.FromArgb(int.Parse(
                                                 baseCurveNode.Attributes["color"].Value,
                                                 NumberStyles.HexNumber
                                                 ));

            XmlNode  startPointNode = dictNode.SelectSingleNode("startPoint");
            Vector2D startPoint     = new Vector2D(
                double.Parse(
                    startPointNode.Attributes["x"].Value,
                    CultureInfo.InvariantCulture
                    ),
                double.Parse(
                    startPointNode.Attributes["y"].Value,
                    CultureInfo.InvariantCulture
                    )
                );

            foreach (XmlNode pointNode in dictNode.SelectNodes("array/string"))
            {
                Vector2D vec = PointFromString(pointNode.InnerText);
                BaseCurve.Points.Add(vec + startPoint);
            }

            SelectedCurve = null;
            ReducedCurves.Clear();
            foreach (XmlNode reducedCurveNode in dictNode.SelectNodes("reduced-curve"))
            {
                ReducerRecord record = Reducers.Find(
                    r => r.XmlName == reducedCurveNode.Attributes["method"]
                    .Value
                    );
                Reducer reducer = record.Factory.Produce();
                reducer.ReadCustomAttributes(reducedCurveNode);
                ReducedBezierCurve curve = new ReducedBezierCurve(
                    BaseCurve, reducer);
                curve.Degree = int.Parse(
                    reducedCurveNode.Attributes["degree"].Value);
                curve.Color = Color.FromArgb(int.Parse(
                                                 reducedCurveNode.Attributes["color"].Value,
                                                 NumberStyles.HexNumber
                                                 ));
                ReducedCurves.Add(curve);
            }

            FileName = filename;
        }
        private void AddCurve(ReducedBezierCurve curve)
        {
            ReducedBezierCurvesViewItem item = new ReducedBezierCurvesViewItem();

            item.Curve  = curve;
            item.Click += item_Click;
            panel.Controls.Add(item);
            RearrangeItems(panel.Controls.Count - 1);
        }
Exemplo n.º 3
0
        private void addButton_Click(object sender, EventArgs e)
        {
            ReducedBezierCurve reducedCurve = new ReducedBezierCurve(
                Model.BaseCurve,
                new IteratedInverseElevationReducer()
                );
            Random random = new Random();

            reducedCurve.Color = Color.FromArgb(
                random.Next(256),
                random.Next(256),
                random.Next(256)
                );
            reducedCurve.ShapeChanged    += () => Canvas.Invalidate();
            reducedCurve.PropertyChanged += reducedCurve_PropertyChanged;
            int index = reducedCurvesBindingSource.Add(reducedCurve);

            reducedBezierCurvesView.Select(index);
        }