示例#1
0
        public void PopulateData(InstanceGroup selection)
        {
            if (selection == null || selection.Count == 0)
            {
                tDefinitionName.Text = "";
                tbInstance.Text      = "";
                tbX.Text             = "";
                tbY.Text             = "";
                tbWidth.Text         = "";
                tbHeight.Text        = "";
                tbXScale.Text        = "";
                tbYScale.Text        = "";
                tbRotation.Text      = "";
                tShear.Text          = "";
            }
            else
            {
                uint[]           ids = selection.SelectedIds;
                MatrixComponents mc  = selection.TransformMatrix.VexMatrix().GetMatrixComponents();
                if (selection.Count == 1)
                {
                    DesignInstance di = MainForm.CurrentInstanceManager[ids[0]];
                    tDefinitionName.Text = di.Definition.Name;
                    tbInstance.Text      = di.InstanceName;
                }
                else
                {
                }

                tbX.Text      = selection.Location.X.ToString("0.##");
                tbY.Text      = selection.Location.Y.ToString("0.##");
                tbWidth.Text  = (selection.UntransformedBounds.Width * mc.ScaleX).ToString("0.##");
                tbHeight.Text = (selection.UntransformedBounds.Height * mc.ScaleY).ToString("0.##");

                tbXScale.Text   = mc.ScaleX.ToString("0.##");
                tbYScale.Text   = mc.ScaleY.ToString("0.##");
                tbRotation.Text = mc.Rotation.ToString("0.##");
                tShear.Text     = mc.Shear.ToString("0.##");
            }

            if (MainForm.CurrentStage != null)
            {
                btStageColor.BackColor = MainForm.CurrentStage.BackgroundColor.SysColor();
                tbStageWidth.Text      = MainForm.CurrentStage.Width.ToString();
                tbStageHeight.Text     = MainForm.CurrentStage.Height.ToString();
            }
        }
示例#2
0
        public V2DGenericTransform[] TransformsConversion(V2DInstance obj, List <Transform> trs)
        {
            V2DGenericTransform[] result = new V2DGenericTransform[trs.Count];
            if (trs.Count > 0)
            {
                MatrixComponents firstMc    = trs[0].Matrix.GetMatrixComponents();
                float            firstAlpha = trs[0].Alpha;
                obj.X        += firstMc.TranslateX;
                obj.Y        += firstMc.TranslateY;
                obj.Rotation += (float)(firstMc.Rotation * Math.PI / 180);
                obj.ScaleX   *= firstMc.ScaleX;
                obj.ScaleY   *= firstMc.ScaleY;
                obj.Alpha    *= firstAlpha;

                for (int i = 0; i < trs.Count; i++)
                {
                    Transform tin = trs[i];

                    uint                sf   = (uint)Math.Round(tin.StartTime / (1000d / v2dWorld.FrameRate));
                    uint                ef   = (uint)Math.Round(tin.EndTime / (1000d / v2dWorld.FrameRate)) - 1;
                    MatrixComponents    mc   = tin.Matrix.GetMatrixComponents();
                    V2DGenericTransform tout = new V2DGenericTransform(
                        sf,
                        ef,
                        mc.ScaleX / firstMc.ScaleX,
                        mc.ScaleY / firstMc.ScaleY,
                        (float)(mc.Rotation * Math.PI / 180) - (float)(firstMc.Rotation * Math.PI / 180),
                        mc.TranslateX - firstMc.TranslateX,
                        mc.TranslateY - firstMc.TranslateY,
                        tin.Alpha / firstAlpha);

                    //V2DTransform tout = new V2DTransform(
                    //    (uint)Math.Floor(tin.StartTime / (1000d / v2dWorld.FrameRate)),
                    //    (uint)Math.Floor(tin.EndTime / (1000d / v2dWorld.FrameRate)),
                    //    new V2DMatrix(  tin.Matrix.ScaleX, tin.Matrix.Rotate0, tin.Matrix.Rotate1, tin.Matrix.ScaleX,
                    //                    tin.Matrix.TranslateX, tin.Matrix.TranslateY),
                    //    tin.Alpha);

                    tout.IsTweening = tin.IsTweening;

                    result[i] = tout;
                }
            }
            return(result);
        }
示例#3
0
        //public void DumpInstance(StringWriter sw, Dictionary<string, string> dict)
        //{
        //    MatrixComponents mc = this.Transforms[0].Matrix.GetMatrixComponents();
        //    Point p = new Point(mc.TranslateX, mc.TranslateY);
        //    float rot = (float)(mc.Rotation * Math.PI / 180);
        //    float sx = mc.ScaleX;
        //    float sy = mc.ScaleY;

        //    sw.Write("          {" +
        //        "instName:\"" + this.InstanceName + "\", " +
        //        "type:\"" + this.DefinitionName + "\", " +
        //        "location:" +  p.ToString()
        //        );

        //    if (rot != 0)
        //    {
        //        sw.Write(", rotation:" + rot);
        //    }
        //    if (Math.Abs(sx - 1) > .01)
        //    {
        //        sw.Write(", scaleX:" + sx);
        //    }
        //    if (Math.Abs(sy - 1) > .01)
        //    {
        //        sw.Write(", scaleY:" + sy);
        //    }
        //    if (!Transforms[0].ColorTransform.IsIdentity())
        //    {
        //        sw.Write(", colorTransform:" + Transforms[0].ColorTransform.ToString());
        //    }

        //    if (dict != null)
        //    {
        //        foreach (string k in dict.Keys)
        //        {
        //            sw.Write(", " + k + ":" + dict[k]);
        //        }
        //    }
        //    sw.Write("}");
        //}
        //public V2DInstance GetV2DInstance(Dictionary<string, string> dict)
        //{
        //    V2DInstance result = new V2DInstance();

        //    MatrixComponents mc = new MatrixComponents(1, 1, 0, 0, 0, 0);// this.Transforms[0].Matrix.GetMatrixComponents();
        //    Point p = new Point(mc.TranslateX, mc.TranslateY);
        //    float rot = (float)(mc.Rotation * Math.PI / 180);
        //    float sx = mc.ScaleX;
        //    float sy = mc.ScaleY;

        //    result.LikageName = LikageName;
        //    result.DefinitionName = DefinitionName;
        //    result.X = p.X;
        //    result.Y = p.Y;
        //    result.Depth = Depth;

        //    if (rot != 0)
        //    {
        //        result.Rotation = rot;
        //    }
        //    if (Math.Abs(sx - 1) > .01)
        //    {
        //        result.ScaleX = sx;
        //    }
        //    if (Math.Abs(sy - 1) > .01)
        //    {
        //        result.ScaleY = sy;
        //    }
        //    //if (!Transforms[0].ColorTransform.IsIdentity())
        //    //{
        //    //    // todo: color xform
        //    //}

        //    if (dict != null)
        //    {
        //        foreach (string k in dict.Keys)
        //        {
        //            Type t = result.GetType();
        //            FieldInfo fi = t.GetField(k, BindingFlags.IgnoreCase);
        //            if (fi != null)
        //            {
        //                Type ft = fi.FieldType;
        //                string val = dict[k];
        //                Object o = Convert.ChangeType(val, fi.FieldType);
        //                fi.SetValue(result, o);
        //            }
        //        }
        //    }
        //    return result;
        //}

        public void DumpInstance(XmlWriter xw, Dictionary <string, string> dict)
        {
            xw.WriteStartElement("V2DInstance");

            MatrixComponents mc  = new MatrixComponents(1, 1, 0, 0, 0, 0);// this.Transforms[0].Matrix.GetMatrixComponents();
            Point            p   = new Point(mc.TranslateX, mc.TranslateY);
            float            rot = (float)(mc.Rotation * Math.PI / 180);
            float            sx  = mc.ScaleX;
            float            sy  = mc.ScaleY;

            xw.WriteAttributeString("DefinitionName", DefinitionName);
            xw.WriteAttributeString("LinkageName", LinkageName);
            xw.WriteAttributeString("X", p.X.ToString());
            xw.WriteAttributeString("Y", p.Y.ToString());

            if (rot != 0)
            {
                xw.WriteAttributeString("Rotation", rot.ToString());
            }
            if (Math.Abs(sx - 1) > .01)
            {
                xw.WriteAttributeString("ScaleX", sx.ToString());
            }
            if (Math.Abs(sy - 1) > .01)
            {
                xw.WriteAttributeString("ScaleY", sy.ToString());
            }
            //if (!Transforms[0].ColorTransform.IsIdentity())
            //{
            //    //sw.Write(", colorTransform:" + Transforms[0].ColorTransform.ToString());
            //}

            if (dict != null)
            {
                foreach (string k in dict.Keys)
                {
                    xw.WriteAttributeString(k, dict[k]);
                }
            }
            xw.WriteEndElement(); // V2DInstance
        }
示例#4
0
        private void WriteTransformsDefs(IDefinition s, Instance inst, string fullName)
        {
            //<Canvas.RenderTransform>
            //<TransformGroup>
            //  <RotateTransform x:Name="inst_rt_0r" Angle="0" />
            //  <SkewTransform x:Name="inst_rt_0k" AngleX="0" AngleY="0"/>
            //  <ScaleTransform x:Name="inst_rt_0s" ScaleX="1" ScaleY="1" />
            //  <TranslateTransform x:Name="inst_rt_0t" X="35" Y="26" />
            //</TransformGroup>
            //</Canvas.RenderTransform>

            IDefinition def = v.Definitions[s.Id];
            //string defName = instancePrefix + GetInstanceName(inst);

            Rectangle        r  = s.StrokeBounds;
            Matrix           m  = inst.Transformations[0].Matrix;
            MatrixComponents mt = m.GetMatrixComponents();

            bool multiTransform = true;            // inst.Transformations.Count > 1;
            bool hasRot         = !(mt.Rotation == 0);
            bool hasSkew        = !(mt.Shear == 0);
            bool hasScale       = !(mt.ScaleX == 1 && mt.ScaleY == 1);
            bool hasTranslate   = !(mt.TranslateX == 0 && mt.TranslateY == 0 && r.Point.X == 0 && r.Point.Y == 0);

            if (multiTransform || hasRot || hasSkew || hasScale || hasTranslate)
            {
                xw.WriteStartElement("Canvas.RenderTransform");
                xw.WriteStartElement("TransformGroup");

                if (multiTransform || hasRot)
                {
                    xw.WriteStartElement("RotateTransform");
                    xw.WriteStartAttribute("x:Name");
                    xw.WriteValue(fullName + "r");
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("Angle");
                    //xw.WriteValue(mt.Rotation);
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteEndElement();
                }

                if (multiTransform || hasSkew)
                {
                    xw.WriteStartElement("SkewTransform");
                    xw.WriteStartAttribute("x:Name");
                    xw.WriteValue(fullName + "k");
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("AngleX");
                    //xw.WriteValue(mt.Shear);
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("AngleY");
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteEndElement();
                }

                if (multiTransform || hasScale)
                {
                    xw.WriteStartElement("ScaleTransform");
                    xw.WriteStartAttribute("x:Name");
                    xw.WriteValue(fullName + "s");
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("ScaleX");
                    //xw.WriteValue(mt.ScaleX);
                    xw.WriteValue(1);
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("ScaleY");
                    //xw.WriteValue(mt.ScaleY);
                    xw.WriteValue(1);
                    xw.WriteEndAttribute();
                    xw.WriteEndElement();
                }

                if (multiTransform || hasTranslate)
                {
                    xw.WriteStartElement("TranslateTransform");
                    xw.WriteStartAttribute("x:Name");
                    xw.WriteValue(fullName + "t");
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("X");
                    //xw.WriteValue(mt.TranslateX + r.Point.X);
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteStartAttribute("Y");
                    //xw.WriteValue(mt.TranslateY + r.Point.Y);
                    xw.WriteValue(0);
                    xw.WriteEndAttribute();
                    xw.WriteEndElement();
                }

                xw.WriteEndElement();                 //TransformGroup
                xw.WriteEndElement();                 //Canvas.RenderTransform
            }
        }