Example #1
0
        public static void pasteFromJSONString(AXModel m, string json_string)
        {
            List <AXParametricObject> poList       = new List <AXParametricObject>();
            List <AXRelation>         relationList = new List <AXRelation>();


            AXParametricObject po = null;

            Debug.Log(json_string);

            AX.SimpleJSON.JSONNode jn = AX.SimpleJSON.JSON.Parse(json_string);

            if (jn == null || jn["parametric_objects"] == null)
            {
                return;
            }

            foreach (AX.SimpleJSON.JSONNode pn in jn["parametric_objects"].AsArray)
            {
                po      = JSONSerializersAX.ParametricObjectFromJSON(pn);
                po.rect = new Rect(po.rect.x + 125, po.rect.y + 125, po.rect.width, po.rect.height);
                poList.Add(po);
            }

            //Debug.Log ("TEST: " + poList.Count + " - " + poList[0].isHead() + " - " + poList[0].generator + " .... " + jn["model_guid"].Value + " - " + m.Guid);
            if (poList.Count == 1 && poList[0].isHead() && jn["model_guid"].Value == m.Guid)
            {
                // common case of copying and pasting a single palette which is a head into the same model
                // as the source po
                // Find the source and instance it.
                AXParametricObject        src_po   = m.getParametricObjectByGUID(poList[0].Guid);
                List <AXParametricObject> src_List = new List <AXParametricObject>();
                src_List.Add(src_po);

                m.instancePOsFromList(src_List);
            }

            else
            {
                foreach (AX.SimpleJSON.JSONNode rNode in jn["relations"].AsArray)
                {
                    relationList.Add(AXRelation.fromJSON(rNode));
                }
                Debug.Log("COPYINGING: " + poList.Count + ", " + relationList.Count);
                // really duplicate
                m.addAndRigUp(poList, relationList);
            }
        }