Esempio n. 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);
            }
        }
Esempio n. 2
0
        public static AXParametricObject pasteParametricObjectFromString(String json_string)
        {
            if (string.IsNullOrEmpty(json_string))
            {
                json_string = EditorGUIUtility.systemCopyBuffer;
            }

            if (string.IsNullOrEmpty(json_string))
            {
                return(null);
            }

            AXModel model = null;

            // 1. First choice is to use a selected model....
            if (ArchimatixEngine.currentModel != null)
            {
                model = ArchimatixEngine.currentModel;
            }

            bool doInstantiation = true;

            if (model == null)
            {
                // ok, are there other models in the scene that the user doesn't realize arene't selected?
                AXModel[] axModels = GameObject.FindObjectsOfType(typeof(AXModel)) as AXModel[];

                if (axModels != null)
                {
                    if (axModels.Length == 1)
                    {
                        // Offer this model as a button,  but also give opportunity to create a new one...
                        int option = EditorUtility.DisplayDialogComplex("Instantiating Library Item", "There is no AX model currently selected", "Cancel", "Add to " + axModels[0], "Create a new Model");


                        switch (option)
                        {
                        // Save Scene
                        case 0:
                            doInstantiation = false;
                            break;

                        // Save and Quit.
                        case 1:
                            model = axModels[0];
                            break;

                        case 2:
                            GameObject axgo = AXEditorUtilities.createNewModel();
                            model           = axgo.GetComponent <AXModel>();
                            doInstantiation = false;
                            break;

                        default:
                            doInstantiation = false;
                            break;
                        }
                    }

                    else if (axModels.Length > 1)
                    {
                        // Throw up a dialog to see if use wants to go select one of the existing models or create a new one.

                        if (EditorUtility.DisplayDialog("Instantiating Library Item", "There is no AX model currently selected", "Select and Existing Model", "Create a new Model"))
                        {
                            return(null);
                        }
                    }
                }
            }


            if (!doInstantiation)
            {
                return(null);
            }



            if (model == null)
            {                   // Well, then, we tried everything....
                GameObject axgo = AXEditorUtilities.createNewModel();
                model = axgo.GetComponent <AXModel>();
            }



            List <AXParametricObject> poList       = new List <AXParametricObject>();
            List <AXRelation>         relationList = new List <AXRelation>();

            AX.SimpleJSON.JSONNode json = null;
            try
            {
                json = AX.SimpleJSON.JSON.Parse(json_string);
            }
            catch
            {
                return(null);
            }
            if (json == null)
            {
                return(null);
            }

            if (json["parametric_objects"] != null)
            {
                foreach (AX.SimpleJSON.JSONNode poNode in json["parametric_objects"].AsArray)
                {
                    poList.Add(JSONSerializersAX.ParametricObjectFromJSON(poNode));
                }
            }

            foreach (AX.SimpleJSON.JSONNode rNode in json["relations"].AsArray)
            {
                relationList.Add(AXRelation.fromJSON(rNode));
            }

            //Debug.Log (rNode);



            // make sure there is a game object ready to instantiate this on



            if (model == null)
            {
                // check if the user really wants to create a new model...

                GameObject axgo = AXEditorUtilities.createNewModel();
                model = axgo.GetComponent <AXModel>();
            }

            Undo.RegisterCompleteObjectUndo(model, "Add Library Object");

            AXParametricObject head_po = poList[0];



            if (model.currentWorkingGroupPO != null && model.currentWorkingGroupPO.Name != head_po.Name)
            {
                head_po.grouperKey = model.currentWorkingGroupPO.Guid;
            }
            else
            {
                head_po.grouperKey = null;
            }



            // ADD AND RIGUP
            // !!! Actually add the library item (as a list of PO's and Relations) to the model
            model.addAndRigUp(poList, relationList);



            head_po.startStowInputs();
            //if (poList[0].is2D() && ArchimatixEngine.workingAxis != (int) Axis.NONE)
            //	poList[0].intValue ("Axis", ArchimatixEngine.workingAxis);


            model.setRenderMode(AXModel.RenderMode.GameObjects);
            model.generate();

            ArchimatixEngine.currentModel = model;
            Selection.activeGameObject    = model.gameObject;


            model.selectOnlyPO(head_po);
            head_po.focusMe = true;


            //AXParametricObject mostRecentPO = model.recentlySelectedPO;
            AXParametricObject mostRecentPO = model.recentlySelectedPO;            //getPOSelectedBefore(head_po);



            //Debug.Log ("model.focusPointInGraphEditor="+model.focusPointInGraphEditor);

            float pos_x = (model.focusPointInGraphEditor.x) + 100;          // + UnityEngine.Random.Range(-100, 300);
            float pos_y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0);

            if (mostRecentPO != null)
            {
                //pos_x =  mostRecentPO.rect.x + 200;
                //pos_y =  mostRecentPO.rect.y;
            }

            //Debug.Log (new Rect(pos_x, pos_y, 150, 100));
            head_po.rect = new Rect(pos_x, pos_y, 150, 500);


            //Debug.Log ("OK "+po.Name+".focusMe = " + po.focusMe);
            // make sure it is in view in the editor window....

            //model.startPanningToRect(head_po.rect);


            //model.cleanGraph();
            model.autobuild();
            head_po.generator.adjustWorldMatrices();


            model.selectOnlyPO(head_po);



            // Paste inside grouper?
            if (model.currentWorkingGroupPO != null && model.currentWorkingGroupPO.Name != head_po.Name)
            {
                model.currentWorkingGroupPO.addGroupee(head_po);
            }


            if (model.currentWorkingGroupPO != null && model.currentWorkingGroupPO.Name == head_po.Name)
            {
                model.currentWorkingGroupPO = model.currentWorkingGroupPO.grouper;
            }


            //model.beginPanningToRect(head_po.rect);
            //AXNodeGraphEditorWindow.zoomToRectIfOpen(head_po.rect);

            //Debug.Log(" 1 model.selectedPOs.Count="+model.selectedPOs.Count + " " + model.selectedPOs[0].Name );
            // EDITOR WINDOW
            ArchimatixEngine.repaintGraphEditorIfExistsAndOpen();



            // SCENEVIEW
            if (SceneView.lastActiveSceneView != null)
            {
                //Debug.Log("REPAINT");
                SceneView.lastActiveSceneView.Repaint();
            }

            //Debug.Log("--> ArchimatixEngine.currentModel=" + ArchimatixEngine.currentModel);


            return(head_po);
        }
Esempio n. 3
0
        /* READ_LIBRARY FROM FILES
         * If the cache is there, use it.
         * Otherwise...
         * Parse all the files in the Library data folder
         * and, using the head object, extract meta data and build indices.
         */
        public void readLibraryFromFiles()
        {
            //Debug.Log("read library");
            //StopWatch sw = new StopWatch();

            /* Maintain a live list of all the files found
             * as head POs
             *
             */
            parametricObjects = new List <AXParametricObject>();
            libraryItems      = new List <LibraryItem>();

            DirectoryInfo info = new DirectoryInfo(Application.dataPath);

            FileInfo[] files = info.GetFiles("*.axobj", SearchOption.AllDirectories);

            //Debug.Log ("LIBRARY READ " + files.Length);

            try
            {
                //foreach (var filepathname in files)
                for (int i = 0; i < files.Length; i++)
                {
                    //Debug.Log ("file: " + files[i].ToString());
                    string filepathname = files[i].ToString();

                    AX.SimpleJSON.JSONNode jn = AX.SimpleJSON.JSON.Parse(File.ReadAllText(filepathname));


                    AXParametricObject head_po = null;


                    if (jn ["parametric_objects"] != null)
                    {
                        head_po = JSONSerializersAX.ParametricObjectFromJSON(jn ["parametric_objects"] [0]);
                    }
                    else
                    {
                        head_po = JSONSerializersAX.ParametricObjectFromJSON(jn [0]);
                    }

                    //head_po.readIntoLibraryFromPathname = filepathname;
                    head_po.readIntoLibraryFromRelativeAXOBJPath = ArchimatixUtils.getRelativeFilePath(filepathname);



                    parametricObjects.Add(head_po);


                    libraryItems.Add(new LibraryItem(head_po));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }



            rebuildTagListsFromExistingPOs();



            cacheLibraryItems();


            //Debug.Log ("LIBRARY READ IN "+sw.stop()+" MILLISECONDS " + parametricObjects.Count + " items.");
        }