Ejemplo n.º 1
0
 private void GenerateJointActionData(Joint2D jnt, Definition2D body)
 {
     foreach (string k in codeData.Keys)
     {
         if (jnt.Name == k)
         {
             Dictionary<string, string> d = codeData[k];
             foreach (string s in d.Keys)
             {
                 if (jnt.data.ContainsKey(s))
                 {
                     jnt.data[s] = d[s];
                 }
                 else
                 {
                     jnt.data.Add(s, d[s]);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void WriteJointData(List<V2DJoint> defJoints, Definition2D def)
        {
            Joint2D[] jts = new Joint2D[def.Joints.Count];
            def.Joints.Values.CopyTo(jts, 0);
            List<Joint2D> jList = new List<Joint2D>(jts);
            jList.Sort();

            foreach (Joint2D j in jList)
            {
                defJoints.Add(j.GetV2DJoint());
            }
        }
Ejemplo n.º 3
0
        private void EnsureBodyTags(Joint2D j)
        {
            bool hasB1 = j.data.ContainsKey("body1");
            bool hasB2 = j.data.ContainsKey("body2");
            bool b1FromCode = hasB1;

            if (!hasB1 || !hasB2)
            {
                List<Instance2D> hits = FindTargetUnderPoint(j.Locations[0]);
                if (!hasB1 && hits.Count > 0)
                {
                    j.data.Add("body1", hits[0].InstanceName);
                    hasB1 = true;
                }

                if (!hasB2)
                {
                    Instance2D b2 = null;
                    if (j.Locations.Count > 1)// && j.JointKind == JointKind.Distance)
                    {
                        List<Instance2D> b2L = FindTargetUnderPoint(j.Locations[1]);

                        if (b2L.Count > 0)
                        {
                            b2 = b2L[0];
                        }
                        else
                        {
                            // ground
                        }
                    }
                    else if (hits.Count > 1)
                    {
                        b2 = hits[1];
                    }
                    else if (b1FromCode && hits.Count > 0)
                    {
                        b2 = hits[0];
                    }

                    if (!hasB1)
                    {
                        j.data.Add("body1", V2D.ROOT_NAME);
                    }

                    if (b2 != null)
                    {
                        j.data.Add("body2", b2.InstanceName);
                        hasB2 = true;
                    }
                    else
                    {
                        j.data.Add("body2", V2D.ROOT_NAME);
                    }
                }
            }
            GenerateJointActionData(j, parentStack.Peek().Definition);

            // flip if a ground ref (I think all joints to ground use ground on body 1..?)
            if (j.data["body2"] == V2D.ROOT_NAME)
            {
                string temp = j.data["body2"];
                j.data["body2"] = j.data["body1"];
                j.data["body1"] = temp;
                if (j.Locations.Count > 1)
                {
                    Point temp2 = j.Locations[0];
                    j.Locations[0] = j.Locations[1];
                    j.Locations[1] = temp2;
                }
            }
        }